[PATCH] D60179: [clangd] Return clangd::TextEdit in ClangdServer::rename. NFC

2019-04-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added reviewers: hokein, ioeric, sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Instead of tooling::Replacement. To avoid the need to have contents of
the file at the caller site. This also aligns better with other methods
in ClangdServer, majority of those already return LSP-specific data
types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60179

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

Index: clang-tools-extra/unittests/clangd/SyncAPI.h
===
--- clang-tools-extra/unittests/clangd/SyncAPI.h
+++ clang-tools-extra/unittests/clangd/SyncAPI.h
@@ -38,7 +38,7 @@
 llvm::Expected>
 runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos);
 
-llvm::Expected>
+llvm::Expected>
 runRename(ClangdServer &Server, PathRef File, Position Pos, StringRef NewName);
 
 std::string runDumpAST(ClangdServer &Server, PathRef File);
Index: clang-tools-extra/unittests/clangd/SyncAPI.cpp
===
--- clang-tools-extra/unittests/clangd/SyncAPI.cpp
+++ clang-tools-extra/unittests/clangd/SyncAPI.cpp
@@ -98,10 +98,10 @@
   return std::move(*Result);
 }
 
-llvm::Expected>
-runRename(ClangdServer &Server, PathRef File, Position Pos,
-  llvm::StringRef NewName) {
-  llvm::Optional>> Result;
+llvm::Expected> runRename(ClangdServer &Server,
+PathRef File, Position Pos,
+llvm::StringRef NewName) {
+  llvm::Optional>> Result;
   Server.rename(File, Pos, NewName, capture(Result));
   return std::move(*Result);
 }
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -217,7 +217,7 @@
   /// Rename all occurrences of the symbol at the \p Pos in \p File to
   /// \p NewName.
   void rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  Callback> CB);
+  Callback> CB);
 
   struct TweakRef {
 std::string ID;/// ID to pass for applyTweak.
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -280,9 +280,9 @@
 }
 
 void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  Callback> CB) {
+  Callback> CB) {
   auto Action = [Pos](Path File, std::string NewName,
-  Callback> CB,
+  Callback> CB,
   llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
@@ -306,7 +306,7 @@
 if (!ResultCollector.Result.getValue())
   return CB(ResultCollector.Result->takeError());
 
-std::vector Replacements;
+std::vector Replacements;
 for (const tooling::AtomicChange &Change : ResultCollector.Result->get()) {
   tooling::Replacements ChangeReps = Change.getReplacements();
   for (const auto &Rep : ChangeReps) {
@@ -320,7 +320,8 @@
 //   * rename globally in project
 //   * rename in open files
 if (Rep.getFilePath() == File)
-  Replacements.push_back(Rep);
+  Replacements.push_back(
+  replacementToEdit(InpAST->Inputs.Contents, Rep));
   }
 }
 return CB(std::move(Replacements));
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -541,19 +541,13 @@
   Server->rename(
   File, Params.position, Params.newName,
   Bind(
-  [File, Code, Params](
-  decltype(Reply) Reply,
-  llvm::Expected> Replacements) {
-if (!Replacements)
-  return Reply(Replacements.takeError());
-
-// Turn the replacements into the format specified by the Language
-// Server Protocol. Fuse them into one big JSON array.
-std::vector Edits;
-for (const auto &R : *Replacements)
-  Edits.push_back(replacementToEdit(*Code, R));
+  [File, Code, Params](decltype(Reply) Reply,
+   llvm::Expected> Edits) {
+if (!Edits)
+  return Reply(Edits.takeError());
+
 WorkspaceEdit WE;
-WE.changes = {{Params.textDocument.uri.uri(), Edits}};
+WE.changes = {{Params.textDocument.uri.uri(), 

[PATCH] D58121: [analyzer][WIP] Attempt to fix traversing bindings of non-base regions in ClusterAnalysis

2019-04-02 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In D58121#1452483 , @NoQ wrote:

> Mmm. I'm also pretty pinned down (it's seasonal), so i'm thinking of 
> temporarily reverting :( until one of us gets to fixing the accidental effect 
> on escaping, 'cause it just keeps biting us. Like, i wholeheartedly 
> appreciate the work and i have already noticed a few times how it makes 
> things better and loved it, it just seems to accidentally have something 
> missing that nobody could predict, and i'll be super eager to get it back in.


Sounds perfectly reasonable. I was also thinking about suggesting a temporary 
revert.


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

https://reviews.llvm.org/D58121



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


[PATCH] D57435: [clang-tidy] Add abseil-wrap-unique check

2019-04-02 Thread Ryan Piantedosi via Phabricator via cfe-commits
Dosi-Dough updated this revision to Diff 193421.
Dosi-Dough marked 2 inline comments as done.
Dosi-Dough added a comment.

added minor style changes and removed unnecessary inline comments.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D57435

Files:
  clang-tidy/abseil/AbseilTidyModule.cpp
  clang-tidy/abseil/CMakeLists.txt
  clang-tidy/abseil/WrapUniqueCheck.cpp
  clang-tidy/abseil/WrapUniqueCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/abseil-wrap-unique.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/abseil-wrap-unique.cpp

Index: test/clang-tidy/abseil-wrap-unique.cpp
===
--- /dev/null
+++ test/clang-tidy/abseil-wrap-unique.cpp
@@ -0,0 +1,87 @@
+// RUN: %check_clang_tidy %s abseil-wrap-unique %t
+
+namespace std {
+
+template 
+class default_delete {};
+
+template >
+class unique_ptr {
+public:
+  unique_ptr() {}
+  unique_ptr(type *ptr) {}
+  unique_ptr(const unique_ptr &t) = delete;
+  unique_ptr(unique_ptr &&t) {}
+  ~unique_ptr() {}
+  type &operator*() { return *ptr; }
+  type *operator->() { return ptr; }
+  type *release() { return ptr; }
+  void reset() {}
+  void reset(type *pt) {}
+  void reset(type pt) {}
+  unique_ptr &operator=(unique_ptr &&) { return *this; }
+  template 
+  unique_ptr &operator=(unique_ptr &&) { return *this; }
+
+private:
+  type *ptr;
+};
+}  // namespace std
+
+class A {
+ public:
+  static A* NewA() {
+return new A();
+  }
+
+ private:
+  A() {}
+};
+
+class B {
+ public:
+  static B* NewB(int bIn) {
+return new B();
+  }
+
+ private:
+  B() {}
+};
+
+struct C {
+  int x;
+  int y;
+};
+/*
+std::unique_ptr returnPointer() {
+  return std::unique_ptr(A::NewA());
+}
+*/
+void positives() {
+  std::unique_ptr a;
+  a.reset(A::NewA());
+  //CHECK-MESSAGE: :[[@LINE-1]]:3: warning: prefer absl::WrapUnique for resetting unique_ptr [abseil-wrap-unique]
+  //CHECK-FIXES: a = absl::WrapUnique(A::NewA())
+  
+  std::unique_ptr b(A::NewA());
+  //CHECK-MESSAGE: :[[@LINE-1]]:3: warning: Perfer absl::WrapUnique to constructing unique_ptr [abseil-wrap-unique]
+  //CHECK-FIXES: auto b = absl::WrapUnique(A::NewA())
+
+  int cIn;
+  std::unique_ptr c(B::NewB(cIn));
+  //CHECK-MESSAGE: :[[@LINE-1]]:3: warning: Perfer absl::WrapUnique to constructing unique_ptr [abseil-wrap-unique]
+  //CHECK-FIXES: auto c = absl::WrapUnique(B::NewB(cIn))
+
+  int dIn;
+  std::unique_ptr d;
+  d.reset(B::NewB(dIn));
+  //CHECK-MESSAGE: :[[@LINE-1]]:3: warning: prefer absl::WrapUnique for resetting unique_ptr [abseil-wrap-unique]
+  //CHECK-FIXES: d = absl::WrapUnique(B::NewB(dIn))
+  
+  auto e = std::unique_ptr(A::NewA());
+  //CHECK-MESSAGE: :[[@LINE-1]]:3: warning: prefer absl::WrapUnique for resetting unique_ptr [abseil-wrap-unique]
+  //CHECK-FIXES: e = absl::WrapUnique(A::NewA())
+
+  //std::unique_ptr e(new int[2] {1,2});
+}
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -20,6 +20,7 @@
abseil-string-find-startswith
abseil-time-subtraction
abseil-upgrade-duration-conversions
+   abseil-wrap-unique
android-cloexec-accept
android-cloexec-accept4
android-cloexec-creat
Index: docs/clang-tidy/checks/abseil-wrap-unique.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/abseil-wrap-unique.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - abseil-wrap-unique
+
+abseil-wrap-unique
+==
+Looks for instances of factory functions which uses a non-public constructor
+that returns a ``std::unqiue_ptr`` then recommends using 
+``absl::wrap_unique(new T(...))``.
+
+.. code-block:: c++
+ 
+  class A {
+  public:
+static A* NewA() { return new A(); }
+
+  private:
+A() = default; 
+  };
+
+  std::unique_ptr a;
+
+  // Original - reset called with a static function returning a std::unqiue_ptr
+  a.reset(A::NewA());
+
+  // Suggested - reset ptr with absl::WrapUnique
+  a = absl::WrapUnique(A::NewA());
+
+  // Original - std::unique_ptr initialized with static function
+  std::unique_ptr b(A::NewA());
+
+  // Suggested - initialize with absl::WrapUnique instead
+  auto b = absl::WrapUnique(A::NewA())
+
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -91,6 +91,13 @@
   Finds and fixes ``absl::Time`` subtraction expressions to do subtraction
   in the Time domain instead of the numeric domain.
 
+- New :doc:`abseil-wrap-unique
+  ` check.
+
+  Looks for instances of factory functions which uses a non-public constructor
+  that returns a ``std::unqiue_ptr`` then recommends using 
+  ``absl::wrap_unique(new T(...))``.
+
 - New :doc:`google-readability-avoid-underscore-in-googletest-name
   `
   check.
Index: 

[PATCH] D58121: [analyzer][WIP] Attempt to fix traversing bindings of non-base regions in ClusterAnalysis

2019-04-02 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Mmm. I'm also pretty pinned down (it's seasonal), so i'm thinking of 
temporarily reverting :( until one of us gets to fixing the accidental effect 
on escaping, 'cause it just keeps biting us. Like, i wholeheartedly appreciate 
the work and i have already noticed a few times how it makes things better and 
loved it, it just seems to accidentally have something missing that nobody 
could predict, and i'll be super eager to get it back in.


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

https://reviews.llvm.org/D58121



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


[PATCH] D60110: [analyzer] When failing to evaluate a __builtin_constant_p, presume it's false.

2019-04-02 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL357557: [analyzer] When failing to evaluate a 
__builtin_constant_p, presume it's false. (authored by dergachev, 
committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60110?vs=193225&id=193412#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60110

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
  cfe/trunk/test/Analysis/builtin-functions.cpp


Index: cfe/trunk/test/Analysis/builtin-functions.cpp
===
--- cfe/trunk/test/Analysis/builtin-functions.cpp
+++ cfe/trunk/test/Analysis/builtin-functions.cpp
@@ -65,19 +65,20 @@
   }
 }
 
-void test_constant_p() {
+void test_constant_p(void *ptr) {
   int i = 1;
   const int j = 2;
   constexpr int k = 3;
   clang_analyzer_eval(__builtin_constant_p(42) == 1); // expected-warning 
{{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning 
{{UNKNOWN}}
+  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning 
{{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(j) == 1); // expected-warning 
{{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k) == 1); // expected-warning 
{{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning 
{{UNKNOWN}}
+  clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning 
{{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(j + 42) == 1); // expected-warning 
{{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k + 42) == 1); // expected-warning 
{{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(" ") == 1); // expected-warning 
{{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // 
expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // 
expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k - 3) == 0); // expected-warning 
{{FALSE}}
   clang_analyzer_eval(__builtin_constant_p(k - 3) == 1); // expected-warning 
{{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(ptr == 0)); // expected-warning 
{{FALSE}}
 }
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
@@ -100,17 +100,25 @@
   case Builtin::BI__builtin_constant_p: {
 // This must be resolvable at compile time, so we defer to the constant
 // evaluator for a value.
+SValBuilder &SVB = C.getSValBuilder();
 SVal V = UnknownVal();
 Expr::EvalResult EVResult;
 if (CE->EvaluateAsInt(EVResult, C.getASTContext(), 
Expr::SE_NoSideEffects)) {
   // Make sure the result has the correct type.
   llvm::APSInt Result = EVResult.Val.getInt();
-  SValBuilder &SVB = C.getSValBuilder();
   BasicValueFactory &BVF = SVB.getBasicValueFactory();
   BVF.getAPSIntType(CE->getType()).apply(Result);
   V = SVB.makeIntVal(Result);
 }
 
+if (FD->getBuiltinID() == Builtin::BI__builtin_constant_p) {
+  // If we didn't manage to figure out if the value is constant or not,
+  // it is safe to assume that it's not constant and unsafe to assume
+  // that it's constant.
+  if (V.isUnknown())
+V = SVB.makeIntVal(0, CE->getType());
+}
+
 C.addTransition(state->BindExpr(CE, LCtx, V));
 return true;
   }


Index: cfe/trunk/test/Analysis/builtin-functions.cpp
===
--- cfe/trunk/test/Analysis/builtin-functions.cpp
+++ cfe/trunk/test/Analysis/builtin-functions.cpp
@@ -65,19 +65,20 @@
   }
 }
 
-void test_constant_p() {
+void test_constant_p(void *ptr) {
   int i = 1;
   const int j = 2;
   constexpr int k = 3;
   clang_analyzer_eval(__builtin_constant_p(42) == 1); // expected-warning {{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(j) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k) == 1); // expected-warning {{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(j + 42) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k + 42) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(" ") == 1); // expected-warning {{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // expected-warn

r357557 - [analyzer] When failing to evaluate a __builtin_constant_p, presume it's false.

2019-04-02 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Tue Apr  2 18:53:40 2019
New Revision: 357557

URL: http://llvm.org/viewvc/llvm-project?rev=357557&view=rev
Log:
[analyzer] When failing to evaluate a __builtin_constant_p, presume it's false.

__builtin_constant_p(x) is a compiler builtin that evaluates to 1 when
its argument x is a compile-time constant and to 0 otherwise. In CodeGen
it is simply lowered to the respective LLVM intrinsic. In the Analyzer
we've been trying to delegate modeling to Expr::EvaluateAsInt, which is
allowed to sometimes fail for no apparent reason.

When it fails, let's conservatively return false. Modeling it as false
is pretty much never wrong, and it is only required to return true
on a best-effort basis, which every user should expect.

Fixes VLAChecker false positives on code that tries to emulate
static asserts in C by constructing a VLA of dynamic size -1 under the
assumption that this dynamic size is actually a constant
in the sense of __builtin_constant_p.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
cfe/trunk/test/Analysis/builtin-functions.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp?rev=357557&r1=357556&r2=357557&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp Tue Apr  2 
18:53:40 2019
@@ -100,17 +100,25 @@ bool BuiltinFunctionChecker::evalCall(co
   case Builtin::BI__builtin_constant_p: {
 // This must be resolvable at compile time, so we defer to the constant
 // evaluator for a value.
+SValBuilder &SVB = C.getSValBuilder();
 SVal V = UnknownVal();
 Expr::EvalResult EVResult;
 if (CE->EvaluateAsInt(EVResult, C.getASTContext(), 
Expr::SE_NoSideEffects)) {
   // Make sure the result has the correct type.
   llvm::APSInt Result = EVResult.Val.getInt();
-  SValBuilder &SVB = C.getSValBuilder();
   BasicValueFactory &BVF = SVB.getBasicValueFactory();
   BVF.getAPSIntType(CE->getType()).apply(Result);
   V = SVB.makeIntVal(Result);
 }
 
+if (FD->getBuiltinID() == Builtin::BI__builtin_constant_p) {
+  // If we didn't manage to figure out if the value is constant or not,
+  // it is safe to assume that it's not constant and unsafe to assume
+  // that it's constant.
+  if (V.isUnknown())
+V = SVB.makeIntVal(0, CE->getType());
+}
+
 C.addTransition(state->BindExpr(CE, LCtx, V));
 return true;
   }

Modified: cfe/trunk/test/Analysis/builtin-functions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/builtin-functions.cpp?rev=357557&r1=357556&r2=357557&view=diff
==
--- cfe/trunk/test/Analysis/builtin-functions.cpp (original)
+++ cfe/trunk/test/Analysis/builtin-functions.cpp Tue Apr  2 18:53:40 2019
@@ -65,19 +65,20 @@ void g(int i) {
   }
 }
 
-void test_constant_p() {
+void test_constant_p(void *ptr) {
   int i = 1;
   const int j = 2;
   constexpr int k = 3;
   clang_analyzer_eval(__builtin_constant_p(42) == 1); // expected-warning 
{{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning 
{{UNKNOWN}}
+  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning 
{{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(j) == 1); // expected-warning 
{{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k) == 1); // expected-warning 
{{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning 
{{UNKNOWN}}
+  clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning 
{{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(j + 42) == 1); // expected-warning 
{{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k + 42) == 1); // expected-warning 
{{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(" ") == 1); // expected-warning 
{{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // 
expected-warning {{UNKNOWN}}
+  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // 
expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k - 3) == 0); // expected-warning 
{{FALSE}}
   clang_analyzer_eval(__builtin_constant_p(k - 3) == 1); // expected-warning 
{{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(ptr == 0)); // expected-warning 
{{FALSE}}
 }


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


[PATCH] D59797: [COFF] Reduce the size of Chunk and SectionChunk, NFC

2019-04-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> this reduces the sum of heap allocations ... These numbers exclude memory 
> mapped files

May I ask how you counted the memory usage minus memory mapped files?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59797



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


[PATCH] D56924: Special case ObjCPropertyDecl for printing

2019-04-02 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Sorry, I missed the pings. It LGTM.


Repository:
  rC Clang

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

https://reviews.llvm.org/D56924



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


[PATCH] D59628: Add support for __attribute__((objc_class_stub))

2019-04-02 Thread Slava Pestov via Phabricator via cfe-commits
slavapestov updated this revision to Diff 193407.

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

https://reviews.llvm.org/D59628

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/ObjCRuntime.h
  lib/CodeGen/CGObjCMac.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaDeclObjC.cpp
  test/CodeGenObjC/class-stubs.m
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/SemaObjC/class-stub-attr-unsupported.m
  test/SemaObjC/class-stub-attr.m
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -1969,10 +1969,15 @@
  << ", /*IsSupported=*/";
   if (!LangOpts.empty()) {
 for (auto I = LangOpts.begin(), E = LangOpts.end(); I != E; ++I) {
-  const StringRef Part = (*I)->getValueAsString("Name");
   if ((*I)->getValueAsBit("Negated"))
 OS << "!";
-  OS << "LangOpts." << Part;
+  const StringRef Code = (*I)->getValueAsString("CustomCode");
+  if (!Code.empty()) {
+OS << Code;
+  } else {
+const StringRef Name = (*I)->getValueAsString("Name");
+OS << "LangOpts." << Name;
+  }
   if (I + 1 != E)
 OS << " || ";
 }
@@ -2957,15 +2962,15 @@
 OS << "case AttrSyntax::" << Variety << ": {\n";
 // C++11-style attributes are further split out based on the Scope.
 for (auto I = List.cbegin(), E = List.cend(); I != E; ++I) {
-  if (I != List.cbegin())
-OS << " else ";
-  if (I->first.empty())
-OS << "if (ScopeName == \"\") {\n";
-  else
-OS << "if (ScopeName == \"" << I->first << "\") {\n";
-  OS << "  return llvm::StringSwitch(Name)\n";
-  GenerateHasAttrSpellingStringSwitch(I->second, OS, Spelling, I->first);
-  OS << "}";
+  if (I != List.cbegin())
+OS << " else ";
+  if (I->first.empty())
+OS << "if (ScopeName == \"\") {\n";
+  else
+OS << "if (ScopeName == \"" << I->first << "\") {\n";
+  OS << "  return llvm::StringSwitch(Name)\n";
+  GenerateHasAttrSpellingStringSwitch(I->second, OS, Spelling, I->first);
+  OS << "}";
 }
 OS << "\n} break;\n";
   };
@@ -3426,16 +3431,22 @@
   // codegen efficiency).
   std::string FnName = "check", Test;
   for (auto I = LangOpts.begin(), E = LangOpts.end(); I != E; ++I) {
-const StringRef Part = (*I)->getValueAsString("Name");
 if ((*I)->getValueAsBit("Negated")) {
   FnName += "Not";
   Test += "!";
 }
-Test += "S.LangOpts.";
-Test +=  Part;
+const StringRef Name = (*I)->getValueAsString("Name");
+FnName += Name;
+const StringRef Code = (*I)->getValueAsString("CustomCode");
+if (!Code.empty()) {
+  Test += "S.";
+  Test += Code;
+} else {
+  Test += "S.LangOpts.";
+  Test += Name;
+}
 if (I + 1 != E)
   Test += " || ";
-FnName += Part;
   }
   FnName += "LangOpts";
 
Index: test/SemaObjC/class-stub-attr.m
===
--- /dev/null
+++ test/SemaObjC/class-stub-attr.m
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-apple-darwin -fsyntax-only -Xclang -verify %s
+// RUN: %clang -target x86_64-apple-darwin -x objective-c++ -fsyntax-only -Xclang -verify %s
+
+@interface NSObject
+@end
+
+__attribute__((objc_class_stub))
+@interface MissingSubclassingRestrictedAttribute : NSObject // expected-error {{'objc_class_stub' attribute cannot be specified on a class that does not have the 'objc_subclassing_restricted' attribute}}
+@end
+
+__attribute__((objc_class_stub))
+__attribute__((objc_subclassing_restricted))
+@interface ValidClassStubAttribute : NSObject
+@end
+
+@implementation ValidClassStubAttribute // expected-error {{cannot declare implementation of a class declared with the 'objc_class_stub' attribute}}
+@end
+
+@implementation ValidClassStubAttribute (MyCategory)
+@end
+
+__attribute__((objc_class_stub(123))) // expected-error {{'objc_class_stub' attribute takes no arguments}}
+@interface InvalidClassStubAttribute : NSObject
+@end
+
+__attribute__((objc_class_stub)) // expected-error {{'objc_class_stub' attribute only applies to Objective-C interfaces}}
+int cannotHaveObjCClassStubAttribute() {}
Index: test/SemaObjC/class-stub-attr-unsupported.m
===
--- /dev/null
+++ test/SemaObjC/class-stub-attr-unsupported.m
@@ -0,0 +1,10 @@
+// RUN: %clang -target i386-apple-darwin -fsyntax-only -Xclang -verify %s
+// RUN: %clang -target i386-apple-darwin -x objective-c++ -fsyntax-only -Xclang -verify %s
+
+@interface NSObject
+@end
+
+__attribute__((objc_class_stub)) // expected-warning {{'objc_class_stub' attribute ignored}}
+__attribute__((objc_su

r357552 - [WebAssembly] Add Emscripten OS definition + small_printf

2019-04-02 Thread Alon Zakai via cfe-commits
Author: azakai
Date: Tue Apr  2 18:08:35 2019
New Revision: 357552

URL: http://llvm.org/viewvc/llvm-project?rev=357552&view=rev
Log:
[WebAssembly] Add Emscripten OS definition + small_printf

The Emscripten OS provides a definition of __EMSCRIPTEN__, and also that it
supports iprintf optimizations.

Also define small_printf optimizations, which is a printf with float support
but not long double (which in wasm can be useful since long doubles are 128
bit and force linking of float128 emulation code). This part is based on
sunfish's https://reviews.llvm.org/D57620 (which can't land yet since
the WASI integration isn't ready yet).

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

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Basic/Targets/OSTargets.h

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=357552&r1=357551&r2=357552&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Tue Apr  2 18:08:35 2019
@@ -576,6 +576,8 @@ TargetInfo *AllocateTarget(const llvm::T
 switch (Triple.getOS()) {
   case llvm::Triple::WASI:
 return new WASITargetInfo(Triple, Opts);
+  case llvm::Triple::Emscripten:
+return new EmscriptenTargetInfo(Triple, Opts);
   case llvm::Triple::UnknownOS:
 return new WebAssemblyOSTargetInfo(Triple, 
Opts);
   default:
@@ -589,6 +591,8 @@ TargetInfo *AllocateTarget(const llvm::T
 switch (Triple.getOS()) {
   case llvm::Triple::WASI:
 return new WASITargetInfo(Triple, Opts);
+  case llvm::Triple::Emscripten:
+return new EmscriptenTargetInfo(Triple, Opts);
   case llvm::Triple::UnknownOS:
 return new WebAssemblyOSTargetInfo(Triple, 
Opts);
   default:

Modified: cfe/trunk/lib/Basic/Targets/OSTargets.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/OSTargets.h?rev=357552&r1=357551&r2=357552&view=diff
==
--- cfe/trunk/lib/Basic/Targets/OSTargets.h (original)
+++ cfe/trunk/lib/Basic/Targets/OSTargets.h Tue Apr  2 18:08:35 2019
@@ -848,6 +848,21 @@ public:
   : WebAssemblyOSTargetInfo(Triple, Opts) {}
 };
 
+// Emscripten target
+template 
+class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo
+: public WebAssemblyOSTargetInfo {
+  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
+MacroBuilder &Builder) const final {
+WebAssemblyOSTargetInfo::getOSDefines(Opts, Triple, Builder);
+Builder.defineMacro("__EMSCRIPTEN__");
+  }
+
+public:
+  explicit EmscriptenTargetInfo(const llvm::Triple &Triple, const 
TargetOptions &Opts)
+  : WebAssemblyOSTargetInfo(Triple, Opts) {}
+};
+
 } // namespace targets
 } // namespace clang
 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H


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


[PATCH] D59467: [clang] Adding the Likelihood Attribute from C++2a

2019-04-02 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/Analysis/CFG.cpp:2208
+}
+
 CFGBlock *CFGBuilder::VisitStmt(Stmt *S, AddStmtChoice asc) {

Tyker wrote:
> NoQ wrote:
> > Tyker wrote:
> > > NoQ wrote:
> > > > Tyker wrote:
> > > > > riccibruno wrote:
> > > > > > I don't understand why this is needed. Can you explain it ? Also I 
> > > > > > think that someone familiar with this code should comment on this 
> > > > > > (maybe @NoQ ?)
> > > > > the detail of why are complicated and i don't have them all in head 
> > > > > but without this edit in cases like 
> > > > > 
> > > > > ```
> > > > > switch (...) {
> > > > > [[likely]] case 1:
> > > > > ...
> > > > > [[fallthrough]];
> > > > > default:
> > > > > ...
> > > > > }
> > > > > ```
> > > > > the fallthrough attribute emitted a diagnostic because is wasn't 
> > > > > handling attributed case statement. the edit i performed is probably 
> > > > > not the optimal way to solve the issue as it only solves the issue 
> > > > > for likelihood attribute. but i don't know any other attribute that 
> > > > > can be applied on a case statement but if they were others they would 
> > > > > probably have the same issue. but the code is quite hard to follow 
> > > > > and i didn't wanted to break anything. so this is what i came up with.
> > > > > i am going to look into it to find a better solution.
> > > > The [[likely]] attribute should not affect the overall topology of the 
> > > > CFG. It might be a nice piece of metadata to add to a CFG edge or to a 
> > > > CFG terminator, but for most consumers of the CFG (various static 
> > > > analyses such as analysis-based warnings or the Static Analyzer) the 
> > > > attribute should have little to no effect - the tool would still need 
> > > > to explore both branches. I don't know how exactly the fallthrough 
> > > > warning operates, but i find it likely (no pun intended) that the 
> > > > fallthrough warning itself should be updated, not the CFG.
> > > > 
> > > > It is probable that for compiler warnings it'll only cause false 
> > > > negatives, which is not as bad as false positives, but i wouldn't rely 
> > > > on that. Additionally, false negatives in such rare scenarios will be 
> > > > very hard to notice later. So i'm highly in favor of aiming for the 
> > > > correct solution in this patch.
> > > > 
> > > > 
> > > i think we all agree that the CFG structure shouldn't be affected by the 
> > > presence or absence of the likely attribute. but in the current state(no 
> > > changes to the CFG) it does for example. 
> > > 
> > > the CFG were obtained without the edit in CFG.cpp but with the added 
> > > likely attribute
> > > using: clang -cc1 -analyze test.cpp -analyzer-checker=debug.DumpCFG
> > > 
> > > input:
> > > 
> > > ```
> > > int f(int i) {
> > > switch (i) {
> > > [[likely]] case 1:
> > > return 1;
> > > }
> > > return i;
> > > }
> > > 
> > > ```
> > > outputs:
> > > 
> > > ```
> > >  [B5 (ENTRY)]
> > >Succs (1): B2
> > > 
> > >  [B1]
> > >1: i
> > >2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
> > >3: return [B1.2];
> > >Preds (2): B3 B2
> > >Succs (1): B0
> > > 
> > >  [B2]
> > >1: i
> > >2: [B2.1] (ImplicitCastExpr, LValueToRValue, int)
> > >T: switch [B2.2]
> > >Preds (1): B5
> > >Succs (2): B4 B1
> > > 
> > >  [B3]
> > >1:  [[likely]]case 1:
> > > [B4.2]   Succs (1): B1
> > > 
> > >  [B4]
> > >   case 1:
> > >1: 1
> > >2: return [B4.1];
> > >Preds (1): B2
> > >Succs (1): B0
> > > 
> > >  [B0 (EXIT)]
> > >Preds (2): B1 B4
> > > 
> > > ```
> > > and
> > > input:
> > > 
> > > ```
> > > int f(int i) {
> > > switch (i) {
> > >  case 1:
> > > return 1;
> > > }
> > > return i;
> > > }
> > > 
> > > ```
> > > outputs:
> > > 
> > > ```
> > >  [B4 (ENTRY)]
> > >Succs (1): B2
> > > 
> > >  [B1]
> > >1: i
> > >2: [B1.1] (ImplicitCastExpr, LValueToRValue, int)
> > >3: return [B1.2];
> > >Preds (1): B2
> > >Succs (1): B0
> > > 
> > >  [B2]
> > >1: i
> > >2: [B2.1] (ImplicitCastExpr, LValueToRValue, int)
> > >T: switch [B2.2]
> > >Preds (1): B4
> > >Succs (2): B3 B1
> > > 
> > >  [B3]
> > >   case 1:
> > >1: 1
> > >2: return [B3.1];
> > >Preds (1): B2
> > >Succs (1): B0
> > > 
> > >  [B0 (EXIT)]
> > >Preds (2): B1 B3
> > > ```
> > > i think think this is the underlying issue. the false diagnostic from 
> > > fallthrough previously mentioned is a consequence of this
> > Hmm, i see. I got it all wrong. Please forgive me!
> > 
> > You're just trying to make `CFGBuilder` support `AttributedStmt` correctly 
> > in general. And the logic you're writing says "support it as any other 
> > generic Stmt that doesn't have any control flow in it, unless it's a 
> > `[[likely]]`-attributed `AttributedStmt`, in which case jump straight to 
> > c

LLVM buildmaster will be updated and restarted tonight

2019-04-02 Thread Galina Kistanova via cfe-commits
 Hello everyone,

LLVM buildmaster will be updated and restarted after 7PM Pacific time today.

Thanks

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


[PATCH] D60104: [libcxx] [test] Use ptrdiff_t rather than int in splice_after_range.pass.cpp to avoid narrowing from pointer subtraction to int warnings.

2019-04-02 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal closed this revision.
BillyONeal added a comment.

Committed r357546


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

https://reviews.llvm.org/D60104



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


[PATCH] D60023: [libcxx] [test] Fix test bugs in string.cons/copy_alloc.pass.cpp.

2019-04-02 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal updated this revision to Diff 193393.
BillyONeal retitled this revision from "[libcxx] [test] Fix inability to rebind 
poca_alloc in string.cons/copy_alloc.pass.cpp." to "[libcxx] [test] Fix test 
bugs in string.cons/copy_alloc.pass.cpp.".
BillyONeal edited the summary of this revision.

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

https://reviews.llvm.org/D60023

Files:
  test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp


Index: test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
===
--- test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
+++ test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
@@ -18,12 +18,12 @@
 #include "min_allocator.h"
 
 #ifndef TEST_HAS_NO_EXCEPTIONS
-template 
 struct alloc_imp {
 bool active;
 
 alloc_imp() : active(true) {}
 
+template 
 T* allocate(std::size_t n)
 {
 if (active)
@@ -32,6 +32,7 @@
 throw std::bad_alloc();
 }
 
+template 
 void deallocate(T* p, std::size_t) { std::free(p); }
 void activate  ()  { active = true; }
 void deactivate()  { active = false; }
@@ -42,14 +43,14 @@
 typedef T value_type;
 typedef std::true_type propagate_on_container_copy_assignment;
 
-alloc_imp *imp;
+alloc_imp *imp;
 
-poca_alloc(alloc_imp *imp_) : imp (imp_) {}
+poca_alloc(alloc_imp *imp_) : imp (imp_) {}
 
 template 
 poca_alloc(const poca_alloc& other) : imp(other.imp) {}
 
-T*   allocate  (std::size_t n)   { return imp->allocate(n);}
+T*   allocate  (std::size_t n)   { return imp->allocate(n);}
 void deallocate(T* p, std::size_t n) { imp->deallocate(p, n); }
 };
 
@@ -112,8 +113,8 @@
 const char * p1 = "This is my first string";
 const char * p2 = "This is my second string";
 
-alloc_imp imp1;
-alloc_imp imp2;
+alloc_imp imp1;
+alloc_imp imp2;
 S s1(p1, A(&imp1));
 S s2(p2, A(&imp2));
 


Index: test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
===
--- test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
+++ test/std/strings/basic.string/string.cons/copy_alloc.pass.cpp
@@ -18,12 +18,12 @@
 #include "min_allocator.h"
 
 #ifndef TEST_HAS_NO_EXCEPTIONS
-template 
 struct alloc_imp {
 bool active;
 
 alloc_imp() : active(true) {}
 
+template 
 T* allocate(std::size_t n)
 {
 if (active)
@@ -32,6 +32,7 @@
 throw std::bad_alloc();
 }
 
+template 
 void deallocate(T* p, std::size_t) { std::free(p); }
 void activate  ()  { active = true; }
 void deactivate()  { active = false; }
@@ -42,14 +43,14 @@
 typedef T value_type;
 typedef std::true_type propagate_on_container_copy_assignment;
 
-alloc_imp *imp;
+alloc_imp *imp;
 
-poca_alloc(alloc_imp *imp_) : imp (imp_) {}
+poca_alloc(alloc_imp *imp_) : imp (imp_) {}
 
 template 
 poca_alloc(const poca_alloc& other) : imp(other.imp) {}
 
-T*   allocate  (std::size_t n)   { return imp->allocate(n);}
+T*   allocate  (std::size_t n)   { return imp->allocate(n);}
 void deallocate(T* p, std::size_t n) { imp->deallocate(p, n); }
 };
 
@@ -112,8 +113,8 @@
 const char * p1 = "This is my first string";
 const char * p2 = "This is my second string";
 
-alloc_imp imp1;
-alloc_imp imp2;
+alloc_imp imp1;
+alloc_imp imp2;
 S s1(p1, A(&imp1));
 S s2(p2, A(&imp2));
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60023: [libcxx] [test] Fix test bugs in string.cons/copy_alloc.pass.cpp.

2019-04-02 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal closed this revision.
BillyONeal added a comment.

Committed r357545


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

https://reviews.llvm.org/D60023



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


[PATCH] D60018: [codeview] Remove Type member from CVRecord

2019-04-02 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea accepted this revision.
aganea added a comment.
This revision is now accepted and ready to land.

LGTM. With a few minor comments:




Comment at: llvm/include/llvm/DebugInfo/CodeView/TypeDeserializer.h:122
   ~FieldListDeserializer() override {
-CVType FieldList;
-FieldList.Type = TypeLeafKind::LF_FIELDLIST;
+RecordPrefix Pre;
+Pre.RecordLen = 2;

`RecordPrefix Pre(TypeLeafKind::LF_FIELDLIST);` like the other places? And 
above.



Comment at: llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp:40
+  static CVSymbol Tombstone(
+  ArrayRef(DenseMapInfo::getTombstoneKey(), 1));
   return Tombstone;

rnk wrote:
> aganea wrote:
> > I suppose you've chosen 1 because that's a invalid record size? Comment 
> > maybe?
> Actually, the reason I did this was to avoid ambiguity between the `T* begin, 
> T* end` ctor and the `T* base, size_t count` ctor. If I use zero, it's 
> ambiguous. Implicit null strikes again. :)
Oh I see. Why not `static CVSymbol 
Tombstone(DenseMapInfo>::getTombstoneKey());` then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60018



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


[PATCH] D60023: [libcxx] [test] Fix inability to rebind poca_alloc in string.cons/copy_alloc.pass.cpp.

2019-04-02 Thread Billy Robert O'Neal III via Phabricator via cfe-commits
BillyONeal added a comment.

Tim Song suggests that http://eel.is/c++draft/string.require#2 indicates that 
basic_string actually does need to provide the strong guarantee here. While I 
think that wording is a mess I think I'll fix our basic_string to do that 
instead of that part of this change.


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

https://reviews.llvm.org/D60023



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


[PATCH] D60018: [codeview] Remove Type member from CVRecord

2019-04-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: llvm/include/llvm/DebugInfo/CodeView/CVRecord.h:29
+/// Carrying the size separately instead of trusting the size stored in the
+/// record prefix provides some extra safety and flexibility.
 template  class CVRecord {

aganea wrote:
> aganea wrote:
> > To add to what you said in a comment above, do you think that if we could 
> > add `assert(Data.size() == ((RecordPrefix 
> > *)RecordData.data())->RecordPrefix + 2)` at relevant places below; and then 
> > after a while we could simply switch to `RecordPrefix *`, once issues are 
> > ironed out?
> I didn't mean now.
Eventually, yes, I think it's possible.



Comment at: llvm/include/llvm/DebugInfo/CodeView/SymbolSerializer.h:56
+RecordPrefix *Prefix = reinterpret_cast(&PreBytes[0]);
+Prefix->RecordLen = 0;
+Prefix->RecordKind = uint16_t(Sym.Kind);

aganea wrote:
> rnk wrote:
> > aganea wrote:
> > > Should be 2.
> > I could say 2, but this is the seralizer, so really it just gets 
> > overwritten. Do you think I should leave it uninitialized, 2, -1, 0?
> I'd say "2" because you want as much as possible to keep data coherent in 
> time. Regardless of what comes after. I think the code should be correct 
> before being optimal. If someone looks for `RecordPrefix` and then tries to 
> understand how it works, it'd be nice if the code displays the same, correct, 
> behavior everywhere.
> 
> But then, you can argue that `RecordPrefix.RecordLen` is simply a constrait, 
> tied to the amount data that comes after. And maybe the calculation logic for 
> that `.RecordLen` field should be hidden inside the `RecordPrefix` class. In 
> that case, to avoid screwing the init order, ideally you could simply say:
> ```
> RecordPrefix Prefix{uint16_t(Sym.Kind)};
> CVSymbol Result(&Prefix);
> ```
> ...and let `RecordPrefix` (or `CVSymbol`) handle sizing?
Makes sense. I'll try to standardize on 2, and I like the logic that the data 
becomes trustworthy.



Comment at: llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp:40
+  static CVSymbol Tombstone(
+  ArrayRef(DenseMapInfo::getTombstoneKey(), 1));
   return Tombstone;

aganea wrote:
> I suppose you've chosen 1 because that's a invalid record size? Comment maybe?
Actually, the reason I did this was to avoid ambiguity between the `T* begin, 
T* end` ctor and the `T* base, size_t count` ctor. If I use zero, it's 
ambiguous. Implicit null strikes again. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60018



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


[PATCH] D60018: [codeview] Remove Type member from CVRecord

2019-04-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 193390.
rnk marked an inline comment as done.
rnk added a comment.

- one more change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60018

Files:
  lld/COFF/PDB.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
  llvm/include/llvm/DebugInfo/CodeView/CVRecord.h
  llvm/include/llvm/DebugInfo/CodeView/RecordSerialization.h
  llvm/include/llvm/DebugInfo/CodeView/SymbolSerializer.h
  llvm/include/llvm/DebugInfo/CodeView/TypeDeserializer.h
  llvm/lib/DebugInfo/CodeView/AppendingTypeTableBuilder.cpp
  llvm/lib/DebugInfo/CodeView/CVSymbolVisitor.cpp
  llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
  llvm/lib/DebugInfo/CodeView/ContinuationRecordBuilder.cpp
  llvm/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp
  llvm/lib/DebugInfo/CodeView/MergingTypeTableBuilder.cpp
  llvm/lib/DebugInfo/CodeView/SimpleTypeSerializer.cpp
  llvm/lib/DebugInfo/CodeView/SymbolDumper.cpp
  llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp
  llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp
  llvm/lib/DebugInfo/CodeView/TypeTableCollection.cpp
  llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
  llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
  llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
  llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
  llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
  llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp

Index: llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
===
--- llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
+++ llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
@@ -42,8 +42,6 @@
 }
 
 inline bool operator==(const CVType &R1, const CVType &R2) {
-  if (R1.Type != R2.Type)
-return false;
   if (R1.RecordData != R2.RecordData)
 return false;
   return true;
@@ -107,7 +105,7 @@
   GlobalState->Records.push_back(AR);
   GlobalState->Indices.push_back(Builder.writeLeafType(AR));
 
-  CVType Type(TypeLeafKind::LF_ARRAY, Builder.records().back());
+  CVType Type(Builder.records().back());
   GlobalState->TypeVector.push_back(Type);
 
   GlobalState->AllOffsets.push_back(
@@ -369,11 +367,10 @@
   TypeIndex IndexOne = Builder.writeLeafType(Modifier);
 
   // set up a type stream that refers to the above two serialized records.
-  std::vector TypeArray;
-  TypeArray.push_back(
-  CVType(static_cast(Class.Kind), Builder.records()[0]));
-  TypeArray.push_back(
-  CVType(static_cast(Modifier.Kind), Builder.records()[1]));
+  std::vector TypeArray = {
+  {Builder.records()[0]},
+  {Builder.records()[1]},
+  };
   BinaryItemStream ItemStream(llvm::support::little);
   ItemStream.setItems(TypeArray);
   VarStreamArray TypeStream(ItemStream);
Index: llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
===
--- llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
+++ llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
@@ -224,7 +224,7 @@
   // append to the existing line.
   P.formatLine("{0} | {1} [size = {2}",
fmt_align(Index, AlignStyle::Right, Width),
-   formatTypeLeafKind(Record.Type), Record.length());
+   formatTypeLeafKind(Record.kind()), Record.length());
   if (Hashes) {
 std::string H;
 if (Index.toArrayIndex() >= HashValues.size()) {
Index: llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
===
--- llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
+++ llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
@@ -331,7 +331,7 @@
   // append to the existing line.
   P.formatLine("{0} | {1} [size = {2}]",
fmt_align(Offset, AlignStyle::Right, 6),
-   formatSymbolKind(Record.Type), Record.length());
+   formatSymbolKind(Record.kind()), Record.length());
   P.Indent();
   return Error::success();
 }
Index: llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
===
--- llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
+++ llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
@@ -98,7 +98,7 @@
 
   CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const override {
 TS.writeLeafType(Record);
-return CVType(Kind, TS.records().back());
+return CVType(TS.records().back());
   }
 
   mutable T Record;
@@ -496,7 +496,7 @@
 Member.Member->writeTo(CRB);
   }
   TS.insertRecord(CRB);
-  return CVType(Kind, TS.records().back());
+  return CVType(TS.records().back());
 }
 
 void MappingTraits::mapping(IO &io, OneMethodRecord &Record) {
Index: llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
===
--- llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
+++ llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
@@ -248,7 +248,7 @@
 uint8_t *Buffer = Allocator.Al

[PATCH] D60018: [codeview] Remove Type member from CVRecord

2019-04-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 193388.
rnk marked 4 inline comments as done.
rnk added a comment.

- Add RecordPrefix ctor, remove all dummy RecordLen assignments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60018

Files:
  lld/COFF/PDB.cpp
  lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
  llvm/include/llvm/DebugInfo/CodeView/CVRecord.h
  llvm/include/llvm/DebugInfo/CodeView/RecordSerialization.h
  llvm/include/llvm/DebugInfo/CodeView/SymbolSerializer.h
  llvm/include/llvm/DebugInfo/CodeView/TypeDeserializer.h
  llvm/lib/DebugInfo/CodeView/AppendingTypeTableBuilder.cpp
  llvm/lib/DebugInfo/CodeView/CVSymbolVisitor.cpp
  llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
  llvm/lib/DebugInfo/CodeView/ContinuationRecordBuilder.cpp
  llvm/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp
  llvm/lib/DebugInfo/CodeView/MergingTypeTableBuilder.cpp
  llvm/lib/DebugInfo/CodeView/SimpleTypeSerializer.cpp
  llvm/lib/DebugInfo/CodeView/SymbolDumper.cpp
  llvm/lib/DebugInfo/CodeView/TypeDumpVisitor.cpp
  llvm/lib/DebugInfo/CodeView/TypeRecordMapping.cpp
  llvm/lib/DebugInfo/CodeView/TypeTableCollection.cpp
  llvm/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
  llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
  llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
  llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
  llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
  llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp

Index: llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
===
--- llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
+++ llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
@@ -42,8 +42,6 @@
 }
 
 inline bool operator==(const CVType &R1, const CVType &R2) {
-  if (R1.Type != R2.Type)
-return false;
   if (R1.RecordData != R2.RecordData)
 return false;
   return true;
@@ -107,7 +105,7 @@
   GlobalState->Records.push_back(AR);
   GlobalState->Indices.push_back(Builder.writeLeafType(AR));
 
-  CVType Type(TypeLeafKind::LF_ARRAY, Builder.records().back());
+  CVType Type(Builder.records().back());
   GlobalState->TypeVector.push_back(Type);
 
   GlobalState->AllOffsets.push_back(
@@ -369,11 +367,10 @@
   TypeIndex IndexOne = Builder.writeLeafType(Modifier);
 
   // set up a type stream that refers to the above two serialized records.
-  std::vector TypeArray;
-  TypeArray.push_back(
-  CVType(static_cast(Class.Kind), Builder.records()[0]));
-  TypeArray.push_back(
-  CVType(static_cast(Modifier.Kind), Builder.records()[1]));
+  std::vector TypeArray = {
+  {Builder.records()[0]},
+  {Builder.records()[1]},
+  };
   BinaryItemStream ItemStream(llvm::support::little);
   ItemStream.setItems(TypeArray);
   VarStreamArray TypeStream(ItemStream);
Index: llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
===
--- llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
+++ llvm/tools/llvm-pdbutil/MinimalTypeDumper.cpp
@@ -224,7 +224,7 @@
   // append to the existing line.
   P.formatLine("{0} | {1} [size = {2}",
fmt_align(Index, AlignStyle::Right, Width),
-   formatTypeLeafKind(Record.Type), Record.length());
+   formatTypeLeafKind(Record.kind()), Record.length());
   if (Hashes) {
 std::string H;
 if (Index.toArrayIndex() >= HashValues.size()) {
Index: llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
===
--- llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
+++ llvm/tools/llvm-pdbutil/MinimalSymbolDumper.cpp
@@ -331,7 +331,7 @@
   // append to the existing line.
   P.formatLine("{0} | {1} [size = {2}]",
fmt_align(Offset, AlignStyle::Right, 6),
-   formatSymbolKind(Record.Type), Record.length());
+   formatSymbolKind(Record.kind()), Record.length());
   P.Indent();
   return Error::success();
 }
Index: llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
===
--- llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
+++ llvm/lib/ObjectYAML/CodeViewYAMLTypes.cpp
@@ -98,7 +98,7 @@
 
   CVType toCodeViewRecord(AppendingTypeTableBuilder &TS) const override {
 TS.writeLeafType(Record);
-return CVType(Kind, TS.records().back());
+return CVType(TS.records().back());
   }
 
   mutable T Record;
@@ -496,7 +496,7 @@
 Member.Member->writeTo(CRB);
   }
   TS.insertRecord(CRB);
-  return CVType(Kind, TS.records().back());
+  return CVType(TS.records().back());
 }
 
 void MappingTraits::mapping(IO &io, OneMethodRecord &Record) {
Index: llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
===
--- llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
+++ llvm/lib/ObjectYAML/CodeViewYAMLSymbols.cpp
@@ -248,7

[PATCH] D59673: [Driver] Allow setting the DWO name DWARF attribute separately

2019-04-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D59673#143 , @aaronpuchert 
wrote:

> In D59673#1438716 , @dblaikie wrote:
>
> > Use llvm-dwarfdump rather than llvm-objdump to dump the contents of the 
> > debug_info section and test the dwo_name there (rather than dumping hex)
>
>
> I didn't know about llvm-dwarfdump, I wondered why llvm-objdump wouldn't 
> pretty-print the debug info as objdump does. That makes a lot of sense then.
>
> > probably the objdump part of the test isn't needed?
>
> Actually I only need to check that the DWO file is there (under the proper 
> file name). Any ideas?


Ah, fair. You could actually test the dwo_name is accurate in the .dwo file (I 
added the dwo_name to the .dwo file so that multi-level dwp error messages 
could be more informative)

>> (& I guess there's an LLVM patch to add the rest of this functionality?)
> 
> What do we have to do there? Should we add the option to `llc` as well?

Yep - pretty much anything in MCOptions should be surfaced through llc for 
llvm-level testing.


Repository:
  rC Clang

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

https://reviews.llvm.org/D59673



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


[PATCH] D60163: [ThinLTO] Handle -fno-builtin* options for distributed backends

2019-04-02 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added a reviewer: pcc.
Herald added subscribers: kristina, dexonsmith, steven_wu, eraman, inglorion, 
mehdi_amini.
Herald added a project: clang.

Without this patch, we were ignoring the -fno-builtin* options for clang
invocations performing ThinLTO distributed backends. Create and pass
down to LTO a TargetLibraryInfoImpl. A separate llvm-side patch will be
sent to add the new Config field and its necessary handling.

Depends on D60162 .


Repository:
  rC Clang

https://reviews.llvm.org/D60163

Files:
  lib/CodeGen/BackendUtil.cpp
  test/CodeGen/thinlto_backend_nobuiltin.ll


Index: test/CodeGen/thinlto_backend_nobuiltin.ll
===
--- /dev/null
+++ test/CodeGen/thinlto_backend_nobuiltin.ll
@@ -0,0 +1,30 @@
+; Make sure that -fno-builtin* is passed down and handled properly in
+; the ThinLTO distributed backend.
+; REQUIRES: x86-registered-target
+
+; RUN: opt -module-summary -o %t.o %s
+; RUN: llvm-lto -thinlto -o %t %t.o
+
+; By default the optimizer will convert memset call to intinsic
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t2.o -x ir %t.o -c 
-fthinlto-index=%t.thinlto.bc -save-temps=obj
+; RUN: llvm-dis %t.s.4.opt.bc -o - | FileCheck %s --check-prefix=BUILTIN
+
+; With -fno-builtin-memset it should not
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t2.o -x ir %t.o -c 
-fthinlto-index=%t.thinlto.bc -save-temps=obj -fno-builtin-memset
+; RUN: llvm-dis %t.s.4.opt.bc -o - | FileCheck %s --check-prefix=NOBUILTIN
+
+; Similarly, with -fno-builtin it should not
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t2.o -x ir %t.o -c 
-fthinlto-index=%t.thinlto.bc -save-temps=obj -fno-builtin
+; RUN: llvm-dis %t.s.4.opt.bc -o - | FileCheck %s --check-prefix=NOBUILTIN
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare i8* @memset(i8*, i8, i64)
+
+define i8* @test(i8* %mem, i8 %val, i64 %size) {
+  ; BUILTIN: call void @llvm.memset.p0i8.i64
+  ; NOBUILTIN: call i8* @memset
+  %ret = call i8* @memset(i8* %mem, i8 %val, i64 %size)
+  ret i8* %ret
+}
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -1327,6 +1327,9 @@
   Conf.CGOptLevel = getCGOptLevel(CGOpts);
   initTargetOptions(Conf.Options, CGOpts, TOpts, LOpts, HeaderOpts);
   Conf.SampleProfile = std::move(SampleProfile);
+  Triple TargetTriple(M->getTargetTriple());
+  std::unique_ptr TLII(createTLII(TargetTriple, 
CGOpts));
+  Conf.TLII = std::move(TLII);
 
   // Context sensitive profile.
   if (CGOpts.hasProfileCSIRInstr()) {


Index: test/CodeGen/thinlto_backend_nobuiltin.ll
===
--- /dev/null
+++ test/CodeGen/thinlto_backend_nobuiltin.ll
@@ -0,0 +1,30 @@
+; Make sure that -fno-builtin* is passed down and handled properly in
+; the ThinLTO distributed backend.
+; REQUIRES: x86-registered-target
+
+; RUN: opt -module-summary -o %t.o %s
+; RUN: llvm-lto -thinlto -o %t %t.o
+
+; By default the optimizer will convert memset call to intinsic
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t2.o -x ir %t.o -c -fthinlto-index=%t.thinlto.bc -save-temps=obj
+; RUN: llvm-dis %t.s.4.opt.bc -o - | FileCheck %s --check-prefix=BUILTIN
+
+; With -fno-builtin-memset it should not
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t2.o -x ir %t.o -c -fthinlto-index=%t.thinlto.bc -save-temps=obj -fno-builtin-memset
+; RUN: llvm-dis %t.s.4.opt.bc -o - | FileCheck %s --check-prefix=NOBUILTIN
+
+; Similarly, with -fno-builtin it should not
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t2.o -x ir %t.o -c -fthinlto-index=%t.thinlto.bc -save-temps=obj -fno-builtin
+; RUN: llvm-dis %t.s.4.opt.bc -o - | FileCheck %s --check-prefix=NOBUILTIN
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare i8* @memset(i8*, i8, i64)
+
+define i8* @test(i8* %mem, i8 %val, i64 %size) {
+  ; BUILTIN: call void @llvm.memset.p0i8.i64
+  ; NOBUILTIN: call i8* @memset
+  %ret = call i8* @memset(i8* %mem, i8 %val, i64 %size)
+  ret i8* %ret
+}
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -1327,6 +1327,9 @@
   Conf.CGOptLevel = getCGOptLevel(CGOpts);
   initTargetOptions(Conf.Options, CGOpts, TOpts, LOpts, HeaderOpts);
   Conf.SampleProfile = std::move(SampleProfile);
+  Triple TargetTriple(M->getTargetTriple());
+  std::unique_ptr TLII(createTLII(TargetTriple, CGOpts));
+  Conf.TLII = std::move(TLII);
 
   // Context sensitive profile.
   if (CGOpts.hasProfileCSIRInstr()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://list

[PATCH] D60161: Expose non-trivial struct helpers for Swift.

2019-04-02 Thread Tony Allevato via Phabricator via cfe-commits
allevato created this revision.
allevato added a reviewer: rjmccall.
Herald added subscribers: cfe-commits, jdoerfert.
Herald added a project: clang.

This change exposes the helper functions that generate ctors/dtors
for non-trivial structs so that they can be called from the Swift
compiler (see https://github.com/apple/swift/pull/23405) to
enable it to import such C records.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60161

Files:
  clang/include/clang/CodeGen/CodeGenABITypes.h
  clang/lib/CodeGen/CGNonTrivialStruct.cpp

Index: clang/lib/CodeGen/CGNonTrivialStruct.cpp
===
--- clang/lib/CodeGen/CGNonTrivialStruct.cpp
+++ clang/lib/CodeGen/CGNonTrivialStruct.cpp
@@ -14,6 +14,7 @@
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "clang/AST/NonTrivialTypeVisitor.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include 
 
@@ -907,3 +908,71 @@
   callSpecialFunction(GenMoveAssignment(getContext()), FuncName, QT, IsVolatile,
   *this, std::array({{DstPtr, SrcPtr}}));
 }
+
+void clang::CodeGen::callNonTrivialCStructDefaultConstructor(
+CodeGenModule &CGM, llvm::BasicBlock *BB,
+llvm::BasicBlock::iterator InsertPoint, llvm::Value *Dst,
+CharUnits DstAlignment, QualType QT) {
+  CodeGenFunction CGF(CGM, true);
+  CGF.Builder.SetInsertPoint(BB, InsertPoint);
+  LValue DstLValue = CGF.MakeAddrLValue(Dst, QT, DstAlignment);
+  CGF.callCStructDefaultConstructor(DstLValue);
+}
+
+void clang::CodeGen::callNonTrivialCStructCopyConstructor(
+CodeGenModule &CGM, llvm::BasicBlock *BB,
+llvm::BasicBlock::iterator InsertPoint, llvm::Value *Dst,
+CharUnits DstAlignment, llvm::Value *Src, CharUnits SrcAlignment,
+QualType QT) {
+  CodeGenFunction CGF(CGM, true);
+  CGF.Builder.SetInsertPoint(BB, InsertPoint);
+  LValue DstLValue = CGF.MakeAddrLValue(Dst, QT, DstAlignment);
+  LValue SrcLValue = CGF.MakeAddrLValue(Src, QT, SrcAlignment);
+  CGF.callCStructCopyConstructor(DstLValue, SrcLValue);
+}
+
+void clang::CodeGen::callNonTrivialCStructMoveConstructor(
+CodeGenModule &CGM, llvm::BasicBlock *BB,
+llvm::BasicBlock::iterator InsertPoint, llvm::Value *Dst,
+CharUnits DstAlignment, llvm::Value *Src, CharUnits SrcAlignment,
+QualType QT) {
+  CodeGenFunction CGF(CGM, true);
+  CGF.Builder.SetInsertPoint(BB, InsertPoint);
+  LValue DstLValue = CGF.MakeAddrLValue(Dst, QT, DstAlignment);
+  LValue SrcLValue = CGF.MakeAddrLValue(Src, QT, SrcAlignment);
+  CGF.callCStructMoveConstructor(DstLValue, SrcLValue);
+}
+
+void clang::CodeGen::callNonTrivialCStructCopyAssignmentOperator(
+CodeGenModule &CGM, llvm::BasicBlock *BB,
+llvm::BasicBlock::iterator InsertPoint, llvm::Value *Dst,
+CharUnits DstAlignment, llvm::Value *Src, CharUnits SrcAlignment,
+QualType QT) {
+  CodeGenFunction CGF(CGM, true);
+  CGF.Builder.SetInsertPoint(BB, InsertPoint);
+  LValue DstLValue = CGF.MakeAddrLValue(Dst, QT, DstAlignment);
+  LValue SrcLValue = CGF.MakeAddrLValue(Src, QT, SrcAlignment);
+  CGF.callCStructCopyAssignmentOperator(DstLValue, SrcLValue);
+}
+
+void clang::CodeGen::callNonTrivialCStructMoveAssignmentOperator(
+CodeGenModule &CGM, llvm::BasicBlock *BB,
+llvm::BasicBlock::iterator InsertPoint, llvm::Value *Dst,
+CharUnits DstAlignment, llvm::Value *Src, CharUnits SrcAlignment,
+QualType QT) {
+  CodeGenFunction CGF(CGM, true);
+  CGF.Builder.SetInsertPoint(BB, InsertPoint);
+  LValue DstLValue = CGF.MakeAddrLValue(Dst, QT, DstAlignment);
+  LValue SrcLValue = CGF.MakeAddrLValue(Src, QT, SrcAlignment);
+  CGF.callCStructMoveAssignmentOperator(DstLValue, SrcLValue);
+}
+
+void clang::CodeGen::callNonTrivialCStructDestructor(
+CodeGenModule &CGM, llvm::BasicBlock *BB,
+llvm::BasicBlock::iterator InsertPoint, llvm::Value *Dst,
+CharUnits Alignment, QualType QT) {
+  CodeGenFunction CGF(CGM, true);
+  CGF.Builder.SetInsertPoint(BB, InsertPoint);
+  LValue lvalue = CGF.MakeAddrLValue(Dst, QT, Alignment);
+  CGF.callCStructDestructor(lvalue);
+}
Index: clang/include/clang/CodeGen/CodeGenABITypes.h
===
--- clang/include/clang/CodeGen/CodeGenABITypes.h
+++ clang/include/clang/CodeGen/CodeGenABITypes.h
@@ -26,12 +26,14 @@
 #include "clang/AST/CanonicalType.h"
 #include "clang/AST/Type.h"
 #include "clang/CodeGen/CGFunctionInfo.h"
+#include "llvm/IR/BasicBlock.h"
 
 namespace llvm {
   class DataLayout;
   class Module;
   class FunctionType;
   class Type;
+  class Value;
 }
 
 namespace clang {
@@ -83,6 +85,52 @@
 unsigned getLLVMFieldNumber(CodeGenModule &CGM,
 const RecordDecl *RD, const FieldDecl *FD);
 
+/// Generates a call to the default constructor for a C struct with
+/// non-trivially copyable fields.
+void callNonTrivialCStructDefaultConstructor(
+CodeGenModule &GCM, llvm::BasicBlock *BB,
+ll

[PATCH] D59802: [clang-tidy] Add new checker: llvm-prefer-isa-or-dyn-cast-in-conditionals

2019-04-02 Thread Don Hinton via Phabricator via cfe-commits
hintonda updated this revision to Diff 193379.
hintonda added a comment.

- Remove spaces in docs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59802

Files:
  clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
  clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
  clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvm-prefer-isa-or-dyn-cast-in-conditionals.rst
  
clang-tools-extra/test/clang-tidy/llvm-prefer-isa-or-dyn-cast-in-conditionals.cpp

Index: clang-tools-extra/test/clang-tidy/llvm-prefer-isa-or-dyn-cast-in-conditionals.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/llvm-prefer-isa-or-dyn-cast-in-conditionals.cpp
@@ -0,0 +1,118 @@
+// RUN: %check_clang_tidy %s llvm-prefer-isa-or-dyn-cast-in-conditionals %t
+
+struct X;
+struct Y;
+struct Z {
+  int foo();
+  X *bar();
+};
+
+template 
+bool isa(Y *);
+template 
+X *cast(Y *);
+template 
+X *dyn_cast(Y *);
+template 
+X *dyn_cast_or_null(Y *);
+
+bool foo(Y *y, Z *z) {
+  if (auto x = cast(y))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: cast<> in conditional will assert rather than return a null pointer [llvm-prefer-isa-or-dyn-cast-in-conditionals]
+  // CHECK-FIXES: if (auto x = dyn_cast(y))
+
+  while (auto x = cast(y))
+break;
+  // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: cast<> in conditional
+  // CHECK-FIXES: while (auto x = dyn_cast(y))
+
+  if (cast(y))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: cast<> in conditional
+  // CHECK-FIXES: if (isa(y))
+
+  while (cast(y))
+break;
+  // CHECK-MESSAGES: :[[@LINE-2]]:10: warning: cast<> in conditional
+  // CHECK-FIXES: while (isa(y))
+
+  do {
+break;
+  } while (cast(y));
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: cast<> in conditional
+  // CHECK-FIXES: while (isa(y));
+
+  if (dyn_cast(y))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: return value from dyn_cast<> not used [llvm-prefer-isa-or-dyn-cast-in-conditionals]
+  // CHECK-FIXES: if (isa(y))
+
+  while (dyn_cast(y))
+break;
+  // CHECK-MESSAGES: :[[@LINE-2]]:10: warning: return value from dyn_cast<> not used
+  // CHECK-FIXES: while (isa(y))
+
+  do {
+break;
+  } while (dyn_cast(y));
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: return value from dyn_cast<> not used
+  // CHECK-FIXES: while (isa(y));
+
+  if (z->bar() && isa(z->bar()))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning:  method '{{.*}}' is called twice and could be expensive [llvm-prefer-isa-or-dyn-cast-in-conditionals]
+  // CHECK-FIXES: if (dyn_cast_or_null(z->bar()))
+
+  if (z->bar() && cast(z->bar()))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: method {{'.*'}} is called twice
+  // CHECK-FIXES: if (dyn_cast_or_null(z->bar()))
+
+  if (z->bar() && dyn_cast(z->bar()))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: method {{'.*'}} is called twice
+  // CHECK-FIXES: if (dyn_cast_or_null(z->bar()))
+
+  if (z->bar() && dyn_cast_or_null(z->bar()))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: method {{'.*'}} is called twice
+  // CHECK-FIXES: if (dyn_cast_or_null(z->bar()))
+
+  bool b = z->bar() && cast(z->bar());
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: method {{'.*'}} is called twice
+  // CHECK-FIXES: bool b = dyn_cast_or_null(z->bar());
+
+  // These don't trigger a warning.
+  if (auto x = cast(y)->foo())
+return true;
+  while (auto x = cast(y)->foo())
+break;
+  if (cast(y)->foo())
+return true;
+  while (cast(y)->foo())
+break;
+  if (y && isa(y))
+return true;
+  if (y && cast(z->bar()))
+return true;
+  if (z && cast(y)->foo())
+return true;
+  bool b2 = y && cast(z);
+
+#define CAST(T, Obj) cast(Obj)
+#define AUTO_VAR_CAST(X, Y, Z) auto X = cast(Z)
+#define ISA(T, Obj) isa(Obj)
+#define ISA_OR_NULL(T, Obj) Obj &&isa(Obj)
+
+  if (auto x = CAST(X, y))
+return true;
+  if (AUTO_VAR_CAST(x, X, z))
+return true;
+  if (z->bar() && ISA(Y, z->bar()))
+return true;
+  if (ISA_OR_NULL(Y, z->bar()))
+return true;
+
+  return false;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/llvm-prefer-isa-or-dyn-cast-in-conditionals.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvm-prefer-isa-or-dyn-cast-in-conditionals.rst
@@ -0,0 +1,33 @@
+.. title:: clang-tidy - llvm-prefer-isa-or-dyn-cast-in-conditionals
+
+llvm-prefer-isa-or-dyn-cast-in-conditionals
+===
+
+Looks at conditionals and finds cases of ``cast<>``, which will assert
+rather than 

[PATCH] D59802: [clang-tidy] Add new checker: llvm-prefer-isa-or-dyn-cast-in-conditionals

2019-04-02 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/llvm-prefer-isa-or-dyn-cast-in-conditionals.rst:6
+
+  Looks at conditionals and finds cases of ``cast<>``, which will
+  assert rather than return a null pointer, and ``dyn_cast<>`` where

Indentation is not needed here. Same for following lines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59802



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


[PATCH] D59802: [clang-tidy] Add new checker: llvm-avoid-cast-in-conditional

2019-04-02 Thread Don Hinton via Phabricator via cfe-commits
hintonda updated this revision to Diff 193376.
hintonda added a comment.

- Renamed and updated docs.
- Fix formatting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59802

Files:
  clang-tools-extra/clang-tidy/llvm/CMakeLists.txt
  clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
  clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
  clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/llvm-prefer-isa-or-dyn-cast-in-conditionals.rst
  
clang-tools-extra/test/clang-tidy/llvm-prefer-isa-or-dyn-cast-in-conditionals.cpp

Index: clang-tools-extra/test/clang-tidy/llvm-prefer-isa-or-dyn-cast-in-conditionals.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/llvm-prefer-isa-or-dyn-cast-in-conditionals.cpp
@@ -0,0 +1,118 @@
+// RUN: %check_clang_tidy %s llvm-prefer-isa-or-dyn-cast-in-conditionals %t
+
+struct X;
+struct Y;
+struct Z {
+  int foo();
+  X *bar();
+};
+
+template 
+bool isa(Y *);
+template 
+X *cast(Y *);
+template 
+X *dyn_cast(Y *);
+template 
+X *dyn_cast_or_null(Y *);
+
+bool foo(Y *y, Z *z) {
+  if (auto x = cast(y))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:16: warning: cast<> in conditional will assert rather than return a null pointer [llvm-prefer-isa-or-dyn-cast-in-conditionals]
+  // CHECK-FIXES: if (auto x = dyn_cast(y))
+
+  while (auto x = cast(y))
+break;
+  // CHECK-MESSAGES: :[[@LINE-2]]:19: warning: cast<> in conditional
+  // CHECK-FIXES: while (auto x = dyn_cast(y))
+
+  if (cast(y))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: cast<> in conditional
+  // CHECK-FIXES: if (isa(y))
+
+  while (cast(y))
+break;
+  // CHECK-MESSAGES: :[[@LINE-2]]:10: warning: cast<> in conditional
+  // CHECK-FIXES: while (isa(y))
+
+  do {
+break;
+  } while (cast(y));
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: cast<> in conditional
+  // CHECK-FIXES: while (isa(y));
+
+  if (dyn_cast(y))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: return value from dyn_cast<> not used [llvm-prefer-isa-or-dyn-cast-in-conditionals]
+  // CHECK-FIXES: if (isa(y))
+
+  while (dyn_cast(y))
+break;
+  // CHECK-MESSAGES: :[[@LINE-2]]:10: warning: return value from dyn_cast<> not used
+  // CHECK-FIXES: while (isa(y))
+
+  do {
+break;
+  } while (dyn_cast(y));
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: return value from dyn_cast<> not used
+  // CHECK-FIXES: while (isa(y));
+
+  if (z->bar() && isa(z->bar()))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning:  method '{{.*}}' is called twice and could be expensive [llvm-prefer-isa-or-dyn-cast-in-conditionals]
+  // CHECK-FIXES: if (dyn_cast_or_null(z->bar()))
+
+  if (z->bar() && cast(z->bar()))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: method {{'.*'}} is called twice
+  // CHECK-FIXES: if (dyn_cast_or_null(z->bar()))
+
+  if (z->bar() && dyn_cast(z->bar()))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: method {{'.*'}} is called twice
+  // CHECK-FIXES: if (dyn_cast_or_null(z->bar()))
+
+  if (z->bar() && dyn_cast_or_null(z->bar()))
+return true;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: method {{'.*'}} is called twice
+  // CHECK-FIXES: if (dyn_cast_or_null(z->bar()))
+
+  bool b = z->bar() && cast(z->bar());
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: method {{'.*'}} is called twice
+  // CHECK-FIXES: bool b = dyn_cast_or_null(z->bar());
+
+  // These don't trigger a warning.
+  if (auto x = cast(y)->foo())
+return true;
+  while (auto x = cast(y)->foo())
+break;
+  if (cast(y)->foo())
+return true;
+  while (cast(y)->foo())
+break;
+  if (y && isa(y))
+return true;
+  if (y && cast(z->bar()))
+return true;
+  if (z && cast(y)->foo())
+return true;
+  bool b2 = y && cast(z);
+
+#define CAST(T, Obj) cast(Obj)
+#define AUTO_VAR_CAST(X, Y, Z) auto X = cast(Z)
+#define ISA(T, Obj) isa(Obj)
+#define ISA_OR_NULL(T, Obj) Obj &&isa(Obj)
+
+  if (auto x = CAST(X, y))
+return true;
+  if (AUTO_VAR_CAST(x, X, z))
+return true;
+  if (z->bar() && ISA(Y, z->bar()))
+return true;
+  if (ISA_OR_NULL(Y, z->bar()))
+return true;
+
+  return false;
+}
Index: clang-tools-extra/docs/clang-tidy/checks/llvm-prefer-isa-or-dyn-cast-in-conditionals.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/llvm-prefer-isa-or-dyn-cast-in-conditionals.rst
@@ -0,0 +1,33 @@
+.. title:: clang-tidy - llvm-prefer-isa-or-dyn-cast-in-conditionals
+
+llvm-prefer-isa-or-dyn-cast-in-conditionals
+===
+
+  Looks at conditionals and finds cases of ``cast<>``, which wi

[PATCH] D49863: [istream] Fix error flags and exceptions propagated from input stream operations

2019-04-02 Thread Louis Dionne via Phabricator via cfe-commits
ldionne reopened this revision.
ldionne added a comment.
This revision is now accepted and ready to land.

In D49863#1452126 , @aprantl wrote:

> It looks like this may have broken some LLDB data formatters:
>  http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/22934/
>
> http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/22934/testReport/junit/lldb-Suite/functionalities_data-formatter_data-formatter-stl_libcxx_optional/TestDataFormatterLibcxxOptional_py/
>  
> http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/22934/testReport/junit/lldb-Suite/functionalities_data-formatter_data-formatter-stl_libcxx_unordered/TestDataFormatterUnordered_py/


I reverted in r357536 to give some time to figure what the problem is.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D49863



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


[PATCH] D59797: [COFF] Reduce the size of Chunk and SectionChunk, NFC

2019-04-02 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL357535: [COFF] Reduce the size of Chunk and SectionChunk, 
NFC (authored by rnk, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D59797?vs=193371&id=193373#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59797

Files:
  lld/trunk/COFF/Chunks.cpp
  lld/trunk/COFF/Chunks.h
  lld/trunk/COFF/ICF.cpp
  lld/trunk/COFF/MarkLive.cpp
  llvm/trunk/include/llvm/BinaryFormat/COFF.h

Index: lld/trunk/COFF/Chunks.cpp
===
--- lld/trunk/COFF/Chunks.cpp
+++ lld/trunk/COFF/Chunks.cpp
@@ -30,8 +30,8 @@
 namespace coff {
 
 SectionChunk::SectionChunk(ObjFile *F, const coff_section *H)
-: Chunk(SectionKind), Repl(this), Header(H), File(F),
-  Relocs(File->getCOFFObj()->getRelocations(Header)) {
+: Chunk(SectionKind), File(F), Header(H),
+  Relocs(File->getCOFFObj()->getRelocations(Header)), Repl(this) {
   // Initialize SectionName.
   File->getCOFFObj()->getSectionName(Header, SectionName);
 
@@ -44,6 +44,11 @@
   Live = !Config->DoGC || !isCOMDAT();
 }
 
+// SectionChunk is one of the most frequently allocated classes, so it is
+// important to keep it as compact as possible. As of this writing, the number
+// below is the size of this class on x64 platforms.
+static_assert(sizeof(SectionChunk) <= 128, "SectionChunk grew unexpectedly");
+
 static void add16(uint8_t *P, int16_t V) { write16le(P, read16le(P) + V); }
 static void add32(uint8_t *P, int32_t V) { write32le(P, read32le(P) + V); }
 static void add64(uint8_t *P, int64_t V) { write64le(P, read64le(P) + V); }
@@ -394,7 +399,11 @@
 }
 
 void SectionChunk::addAssociative(SectionChunk *Child) {
-  AssocChildren.push_back(Child);
+  // Insert this child at the head of the list.
+  assert(Child->AssocChildren == nullptr &&
+ "associated sections cannot have their own associated children");
+  Child->AssocChildren = AssocChildren;
+  AssocChildren = Child;
 }
 
 static uint8_t getBaserelType(const coff_relocation &Rel) {
Index: lld/trunk/COFF/MarkLive.cpp
===
--- lld/trunk/COFF/MarkLive.cpp
+++ lld/trunk/COFF/MarkLive.cpp
@@ -64,8 +64,8 @@
 AddSym(B);
 
 // Mark associative sections if any.
-for (SectionChunk *C : SC->children())
-  Enqueue(C);
+for (SectionChunk &C : SC->children())
+  Enqueue(&C);
   }
 }
 
Index: lld/trunk/COFF/ICF.cpp
===
--- lld/trunk/COFF/ICF.cpp
+++ lld/trunk/COFF/ICF.cpp
@@ -129,10 +129,10 @@
 bool ICF::assocEquals(const SectionChunk *A, const SectionChunk *B) {
   auto ChildClasses = [&](const SectionChunk *SC) {
 std::vector Classes;
-for (const SectionChunk *C : SC->children())
-  if (!C->SectionName.startswith(".debug") &&
-  C->SectionName != ".gfids$y" && C->SectionName != ".gljmp$y")
-Classes.push_back(C->Class[Cnt % 2]);
+for (const SectionChunk &C : SC->children())
+  if (!C.SectionName.startswith(".debug") &&
+  C.SectionName != ".gfids$y" && C.SectionName != ".gljmp$y")
+Classes.push_back(C.Class[Cnt % 2]);
 return Classes;
   };
   return ChildClasses(A) == ChildClasses(B);
Index: lld/trunk/COFF/Chunks.h
===
--- lld/trunk/COFF/Chunks.h
+++ lld/trunk/COFF/Chunks.h
@@ -50,7 +50,7 @@
 // doesn't even have actual data (if common or bss).
 class Chunk {
 public:
-  enum Kind { SectionKind, OtherKind };
+  enum Kind : uint8_t { SectionKind, OtherKind };
   Kind kind() const { return ChunkKind; }
   virtual ~Chunk() = default;
 
@@ -107,6 +107,12 @@
   Chunk(Kind K = OtherKind) : ChunkKind(K) {}
   const Kind ChunkKind;
 
+public:
+  // Whether this section needs to be kept distinct from other sections during
+  // ICF. This is set by the driver using address-significance tables.
+  bool KeepUnique = false;
+
+protected:
   // The RVA of this chunk in the output. The writer sets a value.
   uint64_t RVA = 0;
 
@@ -116,10 +122,6 @@
 public:
   // The offset from beginning of the output section. The writer sets a value.
   uint64_t OutputSectionOff = 0;
-
-  // Whether this section needs to be kept distinct from other sections during
-  // ICF. This is set by the driver using address-significance tables.
-  bool KeepUnique = false;
 };
 
 // A chunk corresponding a section of an input file.
@@ -192,8 +194,34 @@
 symbol_iterator(File, Relocs.end()));
   }
 
+  // Single linked list iterator for associated comdat children.
+  class AssociatedIterator
+  : public llvm::iterator_facade_base<
+AssociatedIterator, std::forward_iterator_tag, SectionChunk> {
+  public:
+AssociatedIterato

[PATCH] D49863: [istream] Fix error flags and exceptions propagated from input stream operations

2019-04-02 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

It looks like this may have broken some LLDB data formatters:
http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/22934/

http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/22934/testReport/junit/lldb-Suite/functionalities_data-formatter_data-formatter-stl_libcxx_optional/TestDataFormatterLibcxxOptional_py/
http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/22934/testReport/junit/lldb-Suite/functionalities_data-formatter_data-formatter-stl_libcxx_unordered/TestDataFormatterUnordered_py/


Repository:
  rL LLVM

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

https://reviews.llvm.org/D49863



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


[PATCH] D59797: [COFF] Reduce the size of Chunk and SectionChunk, NFC

2019-04-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 193371.
rnk added a comment.

- last update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59797

Files:
  lld/COFF/Chunks.cpp
  lld/COFF/Chunks.h
  lld/COFF/ICF.cpp
  lld/COFF/MarkLive.cpp
  llvm/include/llvm/BinaryFormat/COFF.h

Index: llvm/include/llvm/BinaryFormat/COFF.h
===
--- llvm/include/llvm/BinaryFormat/COFF.h
+++ llvm/include/llvm/BinaryFormat/COFF.h
@@ -402,7 +402,7 @@
   IMAGE_REL_ARM64_REL32 = 0x0011,
 };
 
-enum COMDATType : unsigned {
+enum COMDATType : uint8_t {
   IMAGE_COMDAT_SELECT_NODUPLICATES = 1,
   IMAGE_COMDAT_SELECT_ANY,
   IMAGE_COMDAT_SELECT_SAME_SIZE,
Index: lld/COFF/MarkLive.cpp
===
--- lld/COFF/MarkLive.cpp
+++ lld/COFF/MarkLive.cpp
@@ -64,8 +64,8 @@
 AddSym(B);
 
 // Mark associative sections if any.
-for (SectionChunk *C : SC->children())
-  Enqueue(C);
+for (SectionChunk &C : SC->children())
+  Enqueue(&C);
   }
 }
 
Index: lld/COFF/ICF.cpp
===
--- lld/COFF/ICF.cpp
+++ lld/COFF/ICF.cpp
@@ -129,10 +129,10 @@
 bool ICF::assocEquals(const SectionChunk *A, const SectionChunk *B) {
   auto ChildClasses = [&](const SectionChunk *SC) {
 std::vector Classes;
-for (const SectionChunk *C : SC->children())
-  if (!C->SectionName.startswith(".debug") &&
-  C->SectionName != ".gfids$y" && C->SectionName != ".gljmp$y")
-Classes.push_back(C->Class[Cnt % 2]);
+for (const SectionChunk &C : SC->children())
+  if (!C.SectionName.startswith(".debug") &&
+  C.SectionName != ".gfids$y" && C.SectionName != ".gljmp$y")
+Classes.push_back(C.Class[Cnt % 2]);
 return Classes;
   };
   return ChildClasses(A) == ChildClasses(B);
Index: lld/COFF/Chunks.h
===
--- lld/COFF/Chunks.h
+++ lld/COFF/Chunks.h
@@ -50,7 +50,7 @@
 // doesn't even have actual data (if common or bss).
 class Chunk {
 public:
-  enum Kind { SectionKind, OtherKind };
+  enum Kind : uint8_t { SectionKind, OtherKind };
   Kind kind() const { return ChunkKind; }
   virtual ~Chunk() = default;
 
@@ -107,6 +107,12 @@
   Chunk(Kind K = OtherKind) : ChunkKind(K) {}
   const Kind ChunkKind;
 
+public:
+  // Whether this section needs to be kept distinct from other sections during
+  // ICF. This is set by the driver using address-significance tables.
+  bool KeepUnique = false;
+
+protected:
   // The RVA of this chunk in the output. The writer sets a value.
   uint64_t RVA = 0;
 
@@ -116,10 +122,6 @@
 public:
   // The offset from beginning of the output section. The writer sets a value.
   uint64_t OutputSectionOff = 0;
-
-  // Whether this section needs to be kept distinct from other sections during
-  // ICF. This is set by the driver using address-significance tables.
-  bool KeepUnique = false;
 };
 
 // A chunk corresponding a section of an input file.
@@ -192,8 +194,34 @@
 symbol_iterator(File, Relocs.end()));
   }
 
+  // Single linked list iterator for associated comdat children.
+  class AssociatedIterator
+  : public llvm::iterator_facade_base<
+AssociatedIterator, std::forward_iterator_tag, SectionChunk> {
+  public:
+AssociatedIterator() = default;
+AssociatedIterator(SectionChunk *Head) : Cur(Head) {}
+AssociatedIterator &operator=(const AssociatedIterator &R) {
+  Cur = R.Cur;
+  return *this;
+}
+bool operator==(const AssociatedIterator &R) const { return Cur == R.Cur; }
+const SectionChunk &operator*() const { return *Cur; }
+SectionChunk &operator*() { return *Cur; }
+AssociatedIterator &operator++() {
+  Cur = Cur->AssocChildren;
+  return *this;
+}
+
+  private:
+SectionChunk *Cur = nullptr;
+  };
+
   // Allow iteration over the associated child chunks for this section.
-  ArrayRef children() const { return AssocChildren; }
+  llvm::iterator_range children() const {
+return llvm::make_range(AssociatedIterator(AssocChildren),
+AssociatedIterator(nullptr));
+  }
 
   // The section ID this chunk belongs to in its Obj.
   uint32_t getSectionNumber() const;
@@ -208,35 +236,37 @@
 
   bool isHotPatchable() const override { return File->HotPatchable; }
 
-  // A pointer pointing to a replacement for this chunk.
-  // Initially it points to "this" object. If this chunk is merged
-  // with other chunk by ICF, it points to another chunk,
-  // and this chunk is considered as dead.
-  SectionChunk *Repl;
-
-  // The CRC of the contents as described in the COFF spec 4.5.5.
-  // Auxiliary Format 5: Section Definitions. Used for ICF.
-  uint32_t Checksum = 0;
-
-  const coff_section *Header;
-
   // The file that this chunk was created from.
   ObjFi

r357532 - [HIP-Clang] Fat binary should not be produced for non GPU code

2019-04-02 Thread Aaron Enye Shi via cfe-commits
Author: aaronenyeshi
Date: Tue Apr  2 14:54:41 2019
New Revision: 357532

URL: http://llvm.org/viewvc/llvm-project?rev=357532&view=rev
Log:
[HIP-Clang] Fat binary should not be produced for non GPU code

clang-format the changes to CUDA and HIP fat binary.

Reviewers: yaxunl, tra

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

Modified:
cfe/trunk/lib/CodeGen/CGCUDANV.cpp

Modified: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCUDANV.cpp?rev=357532&r1=357531&r2=357532&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp Tue Apr  2 14:54:41 2019
@@ -473,8 +473,8 @@ llvm::Function *CGNVCUDARuntime::makeMod
   StringRef CudaGpuBinaryFileName = CGM.getCodeGenOpts().CudaGpuBinaryFileName;
   if (CudaGpuBinaryFileName.empty() && !IsHIP)
 return nullptr;
-  if ( (IsHIP || (IsCUDA && !RelocatableDeviceCode) )
-   && EmittedKernels.empty() && DeviceVars.empty())
+  if ((IsHIP || (IsCUDA && !RelocatableDeviceCode)) && EmittedKernels.empty() 
&&
+  DeviceVars.empty())
 return nullptr;
 
   // void __{cuda|hip}_register_globals(void* handle);


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


[PATCH] D60141: [HIP-Clang] Fat binary should not be produced for non GPU code

2019-04-02 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D60141#1452019 , @ashi1 wrote:

> Hi Artem, I had just committed the change. IS this change OK or should I 
> revert it?


The `if` condition could use some clang-formatting, but other than that the 
patch still looks OK to me.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D60141



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


[PATCH] D60112: [analyzer] Treat write into a top-level parameter variable with destructor as escape.

2019-04-02 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ marked an inline comment as done.
NoQ added a comment.

In D60112#1451198 , @Szelethus wrote:

> Woah, the code looks amazing, cheers on the refactoring! I'll be honest, I'm 
> struggling a bit with the sentence "we're now in the top frame". In order, I 
> don't understand what does
>
> - we
> - now
> - in the top frame mean. "Top-level argument" is another one -- Do we have 
> **precise** definitions for there terms?


Cf. `LocationContext::inTopFrame()`.

The top frame is the `StackFrameContext` whose parent context is `nullptr`. 
There is only one such context and it is the root of the location context tree. 
It corresponds to the stack frame from which the current Analysis begins. That 
is, each such context corresponds to a path-sensitive analysis line in the 
`-analyzer-display-progress` dump. Other stack frame contexts (with non-null 
parents) correspond to function calls *during* analysis. They usually 
correspond to stack frames of inlined calls (since D49443 
 we sometimes create stack frame contexts for 
calls that will never be inlined, but the rough idea is still the same).

So this patch talks about the situation when we start analysis from function, 
say, `test(A a) { ... }`, and its argument `a` exists throughout the whole 
analysis: its constructor was called before the analysis has started, and its 
destructor will be called after the analysis has ended. Having no parent 
context means that we don't know anything about the caller or the call site of 
`test(a)` - the information we usually do have for inlined calls.

The phrase "We are now in the top frame" therefore roughly translates to "The 
`CoreEngine` worklist item that the `ExprEngine` is currently processing 
corresponds to an `ExplodedNode` that has a `ProgramPoint` with a 
`LocationContext` whose nearest `StackFrameContext` is the top frame". When i'm 
talking about top-level variables, i mean "A `VarRegion` whose parent region is 
a `StackArgumentsSpaceRegion` whose identity is a top-frame 
`StackFrameContext`".

Do you think i should document it somehow?




Comment at: clang/test/Analysis/malloc.cpp:151
+  char *getName() {
+if (!name) {
+  name = static_cast(malloc(10));

Szelethus wrote:
> Is this relevant? `name` will never be null.
Not really, just makes the code look a bit more sensible and idiomatic and less 
warning-worthy-anyway, to make it as clear as possible that the positive here 
is indeed false. We don't really have a constructor in this class, but we can 
imagine that it zero-initializes name. Without this check calling `getName()` 
multiple times would immediately result in a leak.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60112



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


[PATCH] D60151: [clang-tidy] Add using SmallSet to LLVM.h to fix bug in typedef in llvm checkers.

2019-04-02 Thread Don Hinton via Phabricator via cfe-commits
hintonda created this revision.
hintonda added a reviewer: alexfh.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.

Fixed ambiguous namespace bug in llvm checkers that add the
llvm namespace to clang::tidy, by adding using declaration for
SmallSet.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60151

Files:
  clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.h
  clang/include/clang/Basic/LLVM.h


Index: clang/include/clang/Basic/LLVM.h
===
--- clang/include/clang/Basic/LLVM.h
+++ clang/include/clang/Basic/LLVM.h
@@ -31,6 +31,7 @@
   template class ArrayRef;
   template class MutableArrayRef;
   template class OwningArrayRef;
+  template class SmallSet;
   template class SmallString;
   template class SmallVector;
   template class SmallVectorImpl;
@@ -66,6 +67,7 @@
   using llvm::Optional;
   using llvm::OwningArrayRef;
   using llvm::SaveAndRestore;
+  using llvm::SmallSet;
   using llvm::SmallString;
   using llvm::SmallVector;
   using llvm::SmallVectorImpl;
Index: clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.h
===
--- clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.h
+++ clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.h
@@ -18,7 +18,7 @@
 namespace tidy {
 namespace utils {
 
-typedef llvm::SmallSet HeaderFileExtensionsSet;
+using HeaderFileExtensionsSet = SmallSet;
 
 /// \brief Checks whether expansion location of \p Loc is in header file.
 bool isExpansionLocInHeaderFile(


Index: clang/include/clang/Basic/LLVM.h
===
--- clang/include/clang/Basic/LLVM.h
+++ clang/include/clang/Basic/LLVM.h
@@ -31,6 +31,7 @@
   template class ArrayRef;
   template class MutableArrayRef;
   template class OwningArrayRef;
+  template class SmallSet;
   template class SmallString;
   template class SmallVector;
   template class SmallVectorImpl;
@@ -66,6 +67,7 @@
   using llvm::Optional;
   using llvm::OwningArrayRef;
   using llvm::SaveAndRestore;
+  using llvm::SmallSet;
   using llvm::SmallString;
   using llvm::SmallVector;
   using llvm::SmallVectorImpl;
Index: clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.h
===
--- clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.h
+++ clang-tools-extra/clang-tidy/utils/HeaderFileExtensionsUtils.h
@@ -18,7 +18,7 @@
 namespace tidy {
 namespace utils {
 
-typedef llvm::SmallSet HeaderFileExtensionsSet;
+using HeaderFileExtensionsSet = SmallSet;
 
 /// \brief Checks whether expansion location of \p Loc is in header file.
 bool isExpansionLocInHeaderFile(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60141: [HIP-Clang] Fat binary should not be produced for non GPU code

2019-04-02 Thread Aaron Enye Shi via Phabricator via cfe-commits
ashi1 added a comment.

Hi Artem, I had just committed the change. IS this change OK or should I revert 
it?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D60141



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


[PATCH] D60141: [HIP-Clang] Fat binary should not be produced for non GPU code

2019-04-02 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL357526: [HIP-Clang] Fat binary should not be produced for 
non GPU code 2 (authored by aaronenyeshi, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60141?vs=193328&id=193360#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60141

Files:
  cfe/trunk/lib/CodeGen/CGCUDANV.cpp
  cfe/trunk/test/CodeGenCUDA/device-stub.cu


Index: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
===
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp
@@ -468,11 +468,13 @@
 /// \endcode
 llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
   bool IsHIP = CGM.getLangOpts().HIP;
+  bool IsCUDA = CGM.getLangOpts().CUDA;
   // No need to generate ctors/dtors if there is no GPU binary.
   StringRef CudaGpuBinaryFileName = CGM.getCodeGenOpts().CudaGpuBinaryFileName;
   if (CudaGpuBinaryFileName.empty() && !IsHIP)
 return nullptr;
-  if (IsHIP && EmittedKernels.empty() && DeviceVars.empty())
+  if ( (IsHIP || (IsCUDA && !RelocatableDeviceCode) )
+   && EmittedKernels.empty() && DeviceVars.empty())
 return nullptr;
 
   // void __{cuda|hip}_register_globals(void* handle);
Index: cfe/trunk/test/CodeGenCUDA/device-stub.cu
===
--- cfe/trunk/test/CodeGenCUDA/device-stub.cu
+++ cfe/trunk/test/CodeGenCUDA/device-stub.cu
@@ -227,20 +227,14 @@
 // There should be no __[[PREFIX]]_register_globals if we have no
 // device-side globals, but we still need to register GPU binary.
 // Skip GPU binary string first.
-// CUDANOGLOBALS: @{{.*}} = private constant{{.*}}
+// CUDANOGLOBALS-NOT: @{{.*}} = private constant{{.*}}
 // HIPNOGLOBALS-NOT: @{{.*}} = internal constant{{.*}}
 // NOGLOBALS-NOT: define internal void @__{{.*}}_register_globals
-// CUDANOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
-// CUDANOGLOBALS: 
call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
+// NOGLOBALS-NOT: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
+// NOGLOBALS-NOT: 
call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
 // NOGLOBALS-NOT: call void @__[[PREFIX]]_register_globals
-// CUDANOGLOBALS: define internal void @__[[PREFIX]]_module_dtor
-// CUDANOGLOBALS: call void @__[[PREFIX]]UnregisterFatBinary
-
-// There should be no fat binary functions when no device-code is found for 
HIP.
-// HIPNOGLOBALS-NOT: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
-// HIPNOGLOBALS-NOT: 
call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
-// HIPNOGLOBALS-NOT: define internal void @__[[PREFIX]]_module_dtor
-// HIPNOGLOBALS-NOT: call void @__[[PREFIX]]UnregisterFatBinary
+// NOGLOBALS-NOT: define internal void @__[[PREFIX]]_module_dtor
+// NOGLOBALS-NOT: call void @__[[PREFIX]]UnregisterFatBinary
 
 // There should be no constructors/destructors if we have no GPU binary.
 // NOGPUBIN-NOT: define internal void @__[[PREFIX]]_register_globals


Index: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
===
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp
@@ -468,11 +468,13 @@
 /// \endcode
 llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
   bool IsHIP = CGM.getLangOpts().HIP;
+  bool IsCUDA = CGM.getLangOpts().CUDA;
   // No need to generate ctors/dtors if there is no GPU binary.
   StringRef CudaGpuBinaryFileName = CGM.getCodeGenOpts().CudaGpuBinaryFileName;
   if (CudaGpuBinaryFileName.empty() && !IsHIP)
 return nullptr;
-  if (IsHIP && EmittedKernels.empty() && DeviceVars.empty())
+  if ( (IsHIP || (IsCUDA && !RelocatableDeviceCode) )
+   && EmittedKernels.empty() && DeviceVars.empty())
 return nullptr;
 
   // void __{cuda|hip}_register_globals(void* handle);
Index: cfe/trunk/test/CodeGenCUDA/device-stub.cu
===
--- cfe/trunk/test/CodeGenCUDA/device-stub.cu
+++ cfe/trunk/test/CodeGenCUDA/device-stub.cu
@@ -227,20 +227,14 @@
 // There should be no __[[PREFIX]]_register_globals if we have no
 // device-side globals, but we still need to register GPU binary.
 // Skip GPU binary string first.
-// CUDANOGLOBALS: @{{.*}} = private constant{{.*}}
+// CUDANOGLOBALS-NOT: @{{.*}} = private constant{{.*}}
 // HIPNOGLOBALS-NOT: @{{.*}} = internal constant{{.*}}
 // NOGLOBALS-NOT: define internal void @__{{.*}}_register_globals
-// CUDANOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
-// CUDANOGLOBALS: call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
+// NOGLOBALS-NOT: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
+// NOGLOBALS-NOT: call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PR

r357526 - [HIP-Clang] Fat binary should not be produced for non GPU code 2

2019-04-02 Thread Aaron Enye Shi via cfe-commits
Author: aaronenyeshi
Date: Tue Apr  2 13:49:41 2019
New Revision: 357526

URL: http://llvm.org/viewvc/llvm-project?rev=357526&view=rev
Log:
[HIP-Clang] Fat binary should not be produced for non GPU code 2

Also for CUDA, we need to disable producing these fat binary functions when 
there is no GPU code.

Reviewers: yaxunl, tra

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

Modified:
cfe/trunk/lib/CodeGen/CGCUDANV.cpp
cfe/trunk/test/CodeGenCUDA/device-stub.cu

Modified: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCUDANV.cpp?rev=357526&r1=357525&r2=357526&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp Tue Apr  2 13:49:41 2019
@@ -468,11 +468,13 @@ llvm::Function *CGNVCUDARuntime::makeReg
 /// \endcode
 llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() {
   bool IsHIP = CGM.getLangOpts().HIP;
+  bool IsCUDA = CGM.getLangOpts().CUDA;
   // No need to generate ctors/dtors if there is no GPU binary.
   StringRef CudaGpuBinaryFileName = CGM.getCodeGenOpts().CudaGpuBinaryFileName;
   if (CudaGpuBinaryFileName.empty() && !IsHIP)
 return nullptr;
-  if (IsHIP && EmittedKernels.empty() && DeviceVars.empty())
+  if ( (IsHIP || (IsCUDA && !RelocatableDeviceCode) )
+   && EmittedKernels.empty() && DeviceVars.empty())
 return nullptr;
 
   // void __{cuda|hip}_register_globals(void* handle);

Modified: cfe/trunk/test/CodeGenCUDA/device-stub.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCUDA/device-stub.cu?rev=357526&r1=357525&r2=357526&view=diff
==
--- cfe/trunk/test/CodeGenCUDA/device-stub.cu (original)
+++ cfe/trunk/test/CodeGenCUDA/device-stub.cu Tue Apr  2 13:49:41 2019
@@ -227,20 +227,14 @@ void hostfunc(void) { kernelfunc<<<1, 1>
 // There should be no __[[PREFIX]]_register_globals if we have no
 // device-side globals, but we still need to register GPU binary.
 // Skip GPU binary string first.
-// CUDANOGLOBALS: @{{.*}} = private constant{{.*}}
+// CUDANOGLOBALS-NOT: @{{.*}} = private constant{{.*}}
 // HIPNOGLOBALS-NOT: @{{.*}} = internal constant{{.*}}
 // NOGLOBALS-NOT: define internal void @__{{.*}}_register_globals
-// CUDANOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
-// CUDANOGLOBALS: 
call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
+// NOGLOBALS-NOT: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
+// NOGLOBALS-NOT: 
call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
 // NOGLOBALS-NOT: call void @__[[PREFIX]]_register_globals
-// CUDANOGLOBALS: define internal void @__[[PREFIX]]_module_dtor
-// CUDANOGLOBALS: call void @__[[PREFIX]]UnregisterFatBinary
-
-// There should be no fat binary functions when no device-code is found for 
HIP.
-// HIPNOGLOBALS-NOT: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
-// HIPNOGLOBALS-NOT: 
call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
-// HIPNOGLOBALS-NOT: define internal void @__[[PREFIX]]_module_dtor
-// HIPNOGLOBALS-NOT: call void @__[[PREFIX]]UnregisterFatBinary
+// NOGLOBALS-NOT: define internal void @__[[PREFIX]]_module_dtor
+// NOGLOBALS-NOT: call void @__[[PREFIX]]UnregisterFatBinary
 
 // There should be no constructors/destructors if we have no GPU binary.
 // NOGPUBIN-NOT: define internal void @__[[PREFIX]]_register_globals


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


[PATCH] D60141: [HIP-Clang] Fat binary should not be produced for non GPU code

2019-04-02 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added inline comments.



Comment at: lib/CodeGen/CGCUDANV.cpp:475-476
 return nullptr;
+  if (IsHIP && EmittedKernels.empty() && DeviceVars.empty())
+return nullptr;
   // void __{cuda|hip}_register_globals(void* handle);

yaxunl wrote:
> tra wrote:
> > I think this would make sense for CUDA, too. 
> https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGCUDANV.cpp#L482
> 
> CUDA generates a dummy register function call for -fgpu-rdc. So probably only 
> do this when RelocatableDeviceCode is false for CUDA?
Good point. Off the top of my head I can't tell why -fcudardc needs this. 
Keeping the change HIP-only is fine.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60141



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


[PATCH] D60141: [HIP-Clang] Fat binary should not be produced for non GPU code

2019-04-02 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/CodeGen/CGCUDANV.cpp:475-476
 return nullptr;
+  if (IsHIP && EmittedKernels.empty() && DeviceVars.empty())
+return nullptr;
   // void __{cuda|hip}_register_globals(void* handle);

tra wrote:
> I think this would make sense for CUDA, too. 
https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGCUDANV.cpp#L482

CUDA generates a dummy register function call for -fgpu-rdc. So probably only 
do this when RelocatableDeviceCode is false for CUDA?


Repository:
  rC Clang

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

https://reviews.llvm.org/D60141



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


[PATCH] D49863: [istream] Fix error flags and exceptions propagated from input stream operations

2019-04-02 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.

I'm OK with this.  I think, strictly speaking, that libc++ is following the 
standard, and everyone else is not - but what everyone else is doing makes 
sense.




Comment at: libcxx/include/istream:365
 __input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
-#ifndef _LIBCPP_NO_EXCEPTIONS
-try
+ios_base::iostate __state = ios_base::goodbit;
+typename basic_istream<_CharT, _Traits>::sentry __s(__is);

lichray wrote:
> I like `auto` just FYI :)
You may like `auto`, but C++03 does not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D49863



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


[PATCH] D60141: [HIP-Clang] Fat binary should not be produced for non GPU code

2019-04-02 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

General nit: please use diffs with very large context when you submit patches 
with  Phabricator.
https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface




Comment at: lib/CodeGen/CGCUDANV.cpp:475-476
 return nullptr;
+  if (IsHIP && EmittedKernels.empty() && DeviceVars.empty())
+return nullptr;
   // void __{cuda|hip}_register_globals(void* handle);

I think this would make sense for CUDA, too. 


Repository:
  rC Clang

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

https://reviews.llvm.org/D60141



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


r357520 - [HIP-Clang] Fat binary should not be produced for non GPU code

2019-04-02 Thread Aaron Enye Shi via cfe-commits
Author: aaronenyeshi
Date: Tue Apr  2 13:10:18 2019
New Revision: 357520

URL: http://llvm.org/viewvc/llvm-project?rev=357520&view=rev
Log:
[HIP-Clang] Fat binary should not be produced for non GPU code

Skip producing the fat binary functions for HIP when no device code is present.

Reviewers: yaxunl

Differential Review: https://reviews.llvm.org/D60141


Modified:
cfe/trunk/lib/CodeGen/CGCUDANV.cpp
cfe/trunk/test/CodeGenCUDA/device-stub.cu

Modified: cfe/trunk/lib/CodeGen/CGCUDANV.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCUDANV.cpp?rev=357520&r1=357519&r2=357520&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCUDANV.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCUDANV.cpp Tue Apr  2 13:10:18 2019
@@ -472,6 +472,8 @@ llvm::Function *CGNVCUDARuntime::makeMod
   StringRef CudaGpuBinaryFileName = CGM.getCodeGenOpts().CudaGpuBinaryFileName;
   if (CudaGpuBinaryFileName.empty() && !IsHIP)
 return nullptr;
+  if (IsHIP && EmittedKernels.empty() && DeviceVars.empty())
+return nullptr;
 
   // void __{cuda|hip}_register_globals(void* handle);
   llvm::Function *RegisterGlobalsFunc = makeRegisterGlobalsFn();

Modified: cfe/trunk/test/CodeGenCUDA/device-stub.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCUDA/device-stub.cu?rev=357520&r1=357519&r2=357520&view=diff
==
--- cfe/trunk/test/CodeGenCUDA/device-stub.cu (original)
+++ cfe/trunk/test/CodeGenCUDA/device-stub.cu Tue Apr  2 13:10:18 2019
@@ -228,13 +228,19 @@ void hostfunc(void) { kernelfunc<<<1, 1>
 // device-side globals, but we still need to register GPU binary.
 // Skip GPU binary string first.
 // CUDANOGLOBALS: @{{.*}} = private constant{{.*}}
-// HIPNOGLOBALS: @{{.*}} = internal constant{{.*}}
+// HIPNOGLOBALS-NOT: @{{.*}} = internal constant{{.*}}
 // NOGLOBALS-NOT: define internal void @__{{.*}}_register_globals
-// NOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
-// NOGLOBALS: 
call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
+// CUDANOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
+// CUDANOGLOBALS: 
call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
 // NOGLOBALS-NOT: call void @__[[PREFIX]]_register_globals
-// NOGLOBALS: define internal void @__[[PREFIX]]_module_dtor
-// NOGLOBALS: call void @__[[PREFIX]]UnregisterFatBinary
+// CUDANOGLOBALS: define internal void @__[[PREFIX]]_module_dtor
+// CUDANOGLOBALS: call void @__[[PREFIX]]UnregisterFatBinary
+
+// There should be no fat binary functions when no device-code is found for 
HIP.
+// HIPNOGLOBALS-NOT: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
+// HIPNOGLOBALS-NOT: 
call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
+// HIPNOGLOBALS-NOT: define internal void @__[[PREFIX]]_module_dtor
+// HIPNOGLOBALS-NOT: call void @__[[PREFIX]]UnregisterFatBinary
 
 // There should be no constructors/destructors if we have no GPU binary.
 // NOGPUBIN-NOT: define internal void @__[[PREFIX]]_register_globals


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


[PATCH] D60141: [HIP-Clang] Fat binary should not be produced for non GPU code

2019-04-02 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!


Repository:
  rC Clang

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

https://reviews.llvm.org/D60141



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


[PATCH] D60101: [Sema] Fix a use-after-deallocate of a ParsedAttr

2019-04-02 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC357516: [Sema] Fix a use-after-deallocate of a ParsedAttr 
(authored by epilk, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60101?vs=193185&id=193348#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D60101

Files:
  include/clang/Sema/ParsedAttr.h
  lib/Sema/SemaType.cpp
  test/SemaObjC/arc-property-decl-attrs.m


Index: test/SemaObjC/arc-property-decl-attrs.m
===
--- test/SemaObjC/arc-property-decl-attrs.m
+++ test/SemaObjC/arc-property-decl-attrs.m
@@ -287,3 +287,7 @@
 @synthesize collision = _collision; // expected-note {{property synthesized 
here}}
 
 @end
+
+// This used to crash because we'd temporarly store the weak attribute on the
+// declaration specifier, then deallocate it when clearing the declarator.
+id i1, __weak i2, i3;
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -534,8 +534,8 @@
   // attribute from being applied multiple times and gives
   // the source-location-filler something to work with.
   state.saveDeclSpecAttrs();
-  moveAttrFromListToList(attr, declarator.getAttributes(),
- declarator.getMutableDeclSpec().getAttributes());
+  declarator.getMutableDeclSpec().getAttributes().takeOneFrom(
+  declarator.getAttributes(), &attr);
   return;
 }
   }
Index: include/clang/Sema/ParsedAttr.h
===
--- include/clang/Sema/ParsedAttr.h
+++ include/clang/Sema/ParsedAttr.h
@@ -659,6 +659,7 @@
 
 class AttributePool {
   friend class AttributeFactory;
+  friend class ParsedAttributes;
   AttributeFactory &Factory;
   llvm::TinyPtrVector Attrs;
 
@@ -892,6 +893,13 @@
 pool.takeAllFrom(attrs.pool);
   }
 
+  void takeOneFrom(ParsedAttributes &Attrs, ParsedAttr *PA) {
+Attrs.getPool().remove(PA);
+Attrs.remove(PA);
+getPool().add(PA);
+addAtEnd(PA);
+  }
+
   void clear() {
 clearListOnly();
 pool.clear();


Index: test/SemaObjC/arc-property-decl-attrs.m
===
--- test/SemaObjC/arc-property-decl-attrs.m
+++ test/SemaObjC/arc-property-decl-attrs.m
@@ -287,3 +287,7 @@
 @synthesize collision = _collision; // expected-note {{property synthesized here}}
 
 @end
+
+// This used to crash because we'd temporarly store the weak attribute on the
+// declaration specifier, then deallocate it when clearing the declarator.
+id i1, __weak i2, i3;
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -534,8 +534,8 @@
   // attribute from being applied multiple times and gives
   // the source-location-filler something to work with.
   state.saveDeclSpecAttrs();
-  moveAttrFromListToList(attr, declarator.getAttributes(),
- declarator.getMutableDeclSpec().getAttributes());
+  declarator.getMutableDeclSpec().getAttributes().takeOneFrom(
+  declarator.getAttributes(), &attr);
   return;
 }
   }
Index: include/clang/Sema/ParsedAttr.h
===
--- include/clang/Sema/ParsedAttr.h
+++ include/clang/Sema/ParsedAttr.h
@@ -659,6 +659,7 @@
 
 class AttributePool {
   friend class AttributeFactory;
+  friend class ParsedAttributes;
   AttributeFactory &Factory;
   llvm::TinyPtrVector Attrs;
 
@@ -892,6 +893,13 @@
 pool.takeAllFrom(attrs.pool);
   }
 
+  void takeOneFrom(ParsedAttributes &Attrs, ParsedAttr *PA) {
+Attrs.getPool().remove(PA);
+Attrs.remove(PA);
+getPool().add(PA);
+addAtEnd(PA);
+  }
+
   void clear() {
 clearListOnly();
 pool.clear();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60099: [CodeGen] Fix a regression by emitting lambda expressions in EmitLValue

2019-04-02 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC357515: [CodeGen] Fix a regression by emitting lambda 
expressions in EmitLValue (authored by epilk, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60099?vs=193179&id=193347#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D60099

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenObjCXX/property-lvalue-lambda.mm


Index: test/CodeGenObjCXX/property-lvalue-lambda.mm
===
--- test/CodeGenObjCXX/property-lvalue-lambda.mm
+++ test/CodeGenObjCXX/property-lvalue-lambda.mm
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -fblocks -disable-llvm-passes -triple x86_64-apple-darwin10 
-std=c++17 -emit-llvm -o - %s | FileCheck %s
+
+typedef void (^blk_t)();
+typedef void (*fnptr_t)();
+
+@interface X
+@property blk_t blk;
+@property fnptr_t fnptr;
+@end
+
+template 
+blk_t operator+(blk_t lhs, T) { return lhs; }
+
+template 
+fnptr_t operator+(fnptr_t lhs, T) { return lhs; }
+
+// CHECK-LABEL: define void @_Z2t1P1X
+void t1(X *x) {
+  // Check that we call lambda.operator blk_t(), and that we send that result 
to
+  // the setter.
+
+  // CHECK: [[CALL:%.*]] = call void ()* 
@"_ZZ2t1P1XENK3$_0cvU13block_pointerFvvEEv"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} void ()* [[CALL]])
+  x.blk = [] {};
+
+  // CHECK: [[CALL2:%.*]] = call void ()* @"_ZZ2t1P1XENK3$_1cvPFvvEEv"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} void ()* [[CALL2]])
+  x.fnptr = [] {};
+}
+
+// CHECK-LABEL: define void @_Z2t2P1X
+void t2(X *x) {
+  // Test the case when the lambda isn't unique. (see 
OpaqueValueExpr::isUnique)
+  // FIXME: This asserts if the lambda isn't trivially copy/movable.
+
+  // [x setBlk: operator+([x blk], [] {})]
+
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}
+  // CHECK: [[PLUS:%.*]] = call void ()* 
@"_ZplIZ2t2P1XE3$_2EU13block_pointerFvvES4_T_"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} [[PLUS]])
+  x.blk += [] {};
+
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}
+  // CHECK: [[PLUS:%.*]] = call void ()* @"_ZplIZ2t2P1XE3$_3EPFvvES4_T_"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} [[PLUS]])
+  x.fnptr += [] {};
+}
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1294,6 +1294,8 @@
 return EmitCXXBindTemporaryLValue(cast(E));
   case Expr::CXXUuidofExprClass:
 return EmitCXXUuidofLValue(cast(E));
+  case Expr::LambdaExprClass:
+return EmitAggExprToLValue(E);
 
   case Expr::ExprWithCleanupsClass: {
 const auto *cleanups = cast(E);


Index: test/CodeGenObjCXX/property-lvalue-lambda.mm
===
--- test/CodeGenObjCXX/property-lvalue-lambda.mm
+++ test/CodeGenObjCXX/property-lvalue-lambda.mm
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -fblocks -disable-llvm-passes -triple x86_64-apple-darwin10 -std=c++17 -emit-llvm -o - %s | FileCheck %s
+
+typedef void (^blk_t)();
+typedef void (*fnptr_t)();
+
+@interface X
+@property blk_t blk;
+@property fnptr_t fnptr;
+@end
+
+template 
+blk_t operator+(blk_t lhs, T) { return lhs; }
+
+template 
+fnptr_t operator+(fnptr_t lhs, T) { return lhs; }
+
+// CHECK-LABEL: define void @_Z2t1P1X
+void t1(X *x) {
+  // Check that we call lambda.operator blk_t(), and that we send that result to
+  // the setter.
+
+  // CHECK: [[CALL:%.*]] = call void ()* @"_ZZ2t1P1XENK3$_0cvU13block_pointerFvvEEv"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} void ()* [[CALL]])
+  x.blk = [] {};
+
+  // CHECK: [[CALL2:%.*]] = call void ()* @"_ZZ2t1P1XENK3$_1cvPFvvEEv"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} void ()* [[CALL2]])
+  x.fnptr = [] {};
+}
+
+// CHECK-LABEL: define void @_Z2t2P1X
+void t2(X *x) {
+  // Test the case when the lambda isn't unique. (see OpaqueValueExpr::isUnique)
+  // FIXME: This asserts if the lambda isn't trivially copy/movable.
+
+  // [x setBlk: operator+([x blk], [] {})]
+
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}
+  // CHECK: [[PLUS:%.*]] = call void ()* @"_ZplIZ2t2P1XE3$_2EU13block_pointerFvvES4_T_"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} [[PLUS]])
+  x.blk += [] {};
+
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}
+  // CHECK: [[PLUS:%.*]] = call void ()* @"_ZplIZ2t2P1XE3$_3EPFvvES4_T_"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} [[PLUS]])
+  x.fnptr += [] {};
+}
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1294,6 +1294,8 @@
 return EmitCXXBindTemporaryLValue(cast(E));
   case Expr::CXXUuidofExprClass:
 return EmitCXXUuidofLValue(cast(E));
+  case Expr::LambdaExprClass:
+return EmitAggExprToLValue(E);
 
   case Expr::ExprWithCleanupsClass: {
 const auto *c

r357515 - [CodeGen] Fix a regression by emitting lambda expressions in EmitLValue

2019-04-02 Thread Erik Pilkington via cfe-commits
Author: epilk
Date: Tue Apr  2 12:48:07 2019
New Revision: 357515

URL: http://llvm.org/viewvc/llvm-project?rev=357515&view=rev
Log:
[CodeGen] Fix a regression by emitting lambda expressions in EmitLValue

This ability was removed in r351487, but it's needed when a lambda appears as an
OpaqueValueExpr subexpression of a PseudoObjectExpr.

rdar://49030379

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

Added:
cfe/trunk/test/CodeGenObjCXX/property-lvalue-lambda.mm
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=357515&r1=357514&r2=357515&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Apr  2 12:48:07 2019
@@ -1294,6 +1294,8 @@ LValue CodeGenFunction::EmitLValue(const
 return EmitCXXBindTemporaryLValue(cast(E));
   case Expr::CXXUuidofExprClass:
 return EmitCXXUuidofLValue(cast(E));
+  case Expr::LambdaExprClass:
+return EmitAggExprToLValue(E);
 
   case Expr::ExprWithCleanupsClass: {
 const auto *cleanups = cast(E);

Added: cfe/trunk/test/CodeGenObjCXX/property-lvalue-lambda.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/property-lvalue-lambda.mm?rev=357515&view=auto
==
--- cfe/trunk/test/CodeGenObjCXX/property-lvalue-lambda.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/property-lvalue-lambda.mm Tue Apr  2 12:48:07 
2019
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -fblocks -disable-llvm-passes -triple x86_64-apple-darwin10 
-std=c++17 -emit-llvm -o - %s | FileCheck %s
+
+typedef void (^blk_t)();
+typedef void (*fnptr_t)();
+
+@interface X
+@property blk_t blk;
+@property fnptr_t fnptr;
+@end
+
+template 
+blk_t operator+(blk_t lhs, T) { return lhs; }
+
+template 
+fnptr_t operator+(fnptr_t lhs, T) { return lhs; }
+
+// CHECK-LABEL: define void @_Z2t1P1X
+void t1(X *x) {
+  // Check that we call lambda.operator blk_t(), and that we send that result 
to
+  // the setter.
+
+  // CHECK: [[CALL:%.*]] = call void ()* 
@"_ZZ2t1P1XENK3$_0cvU13block_pointerFvvEEv"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} void ()* [[CALL]])
+  x.blk = [] {};
+
+  // CHECK: [[CALL2:%.*]] = call void ()* @"_ZZ2t1P1XENK3$_1cvPFvvEEv"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} void ()* [[CALL2]])
+  x.fnptr = [] {};
+}
+
+// CHECK-LABEL: define void @_Z2t2P1X
+void t2(X *x) {
+  // Test the case when the lambda isn't unique. (see 
OpaqueValueExpr::isUnique)
+  // FIXME: This asserts if the lambda isn't trivially copy/movable.
+
+  // [x setBlk: operator+([x blk], [] {})]
+
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}
+  // CHECK: [[PLUS:%.*]] = call void ()* 
@"_ZplIZ2t2P1XE3$_2EU13block_pointerFvvES4_T_"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} [[PLUS]])
+  x.blk += [] {};
+
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}
+  // CHECK: [[PLUS:%.*]] = call void ()* @"_ZplIZ2t2P1XE3$_3EPFvvES4_T_"
+  // CHECK: call void{{.*}}@objc_msgSend{{.*}}({{.*}} [[PLUS]])
+  x.fnptr += [] {};
+}


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


r357516 - [Sema] Fix a use-after-deallocate of a ParsedAttr

2019-04-02 Thread Erik Pilkington via cfe-commits
Author: epilk
Date: Tue Apr  2 12:48:11 2019
New Revision: 357516

URL: http://llvm.org/viewvc/llvm-project?rev=357516&view=rev
Log:
[Sema] Fix a use-after-deallocate of a ParsedAttr

moveAttrFromListToList only makes sense when moving an attribute to a list with
a pool that's either equivalent, or has a shorter lifetime. Therefore, using it
to move a ParsedAttr from a declarator to a declaration specifier doesn't make
sense, since the declaration specifier's pool outlives the declarator's. The
patch adds a new function, ParsedAttributes::takeOneFrom, which transfers the
attribute from one pool to another, fixing the use-after-deallocate.

rdar://49175426

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

Modified:
cfe/trunk/include/clang/Sema/ParsedAttr.h
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m

Modified: cfe/trunk/include/clang/Sema/ParsedAttr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ParsedAttr.h?rev=357516&r1=357515&r2=357516&view=diff
==
--- cfe/trunk/include/clang/Sema/ParsedAttr.h (original)
+++ cfe/trunk/include/clang/Sema/ParsedAttr.h Tue Apr  2 12:48:11 2019
@@ -659,6 +659,7 @@ public:
 
 class AttributePool {
   friend class AttributeFactory;
+  friend class ParsedAttributes;
   AttributeFactory &Factory;
   llvm::TinyPtrVector Attrs;
 
@@ -892,6 +893,13 @@ public:
 pool.takeAllFrom(attrs.pool);
   }
 
+  void takeOneFrom(ParsedAttributes &Attrs, ParsedAttr *PA) {
+Attrs.getPool().remove(PA);
+Attrs.remove(PA);
+getPool().add(PA);
+addAtEnd(PA);
+  }
+
   void clear() {
 clearListOnly();
 pool.clear();

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=357516&r1=357515&r2=357516&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Apr  2 12:48:11 2019
@@ -534,8 +534,8 @@ static void distributeObjCPointerTypeAtt
   // attribute from being applied multiple times and gives
   // the source-location-filler something to work with.
   state.saveDeclSpecAttrs();
-  moveAttrFromListToList(attr, declarator.getAttributes(),
- declarator.getMutableDeclSpec().getAttributes());
+  declarator.getMutableDeclSpec().getAttributes().takeOneFrom(
+  declarator.getAttributes(), &attr);
   return;
 }
   }

Modified: cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m?rev=357516&r1=357515&r2=357516&view=diff
==
--- cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m (original)
+++ cfe/trunk/test/SemaObjC/arc-property-decl-attrs.m Tue Apr  2 12:48:11 2019
@@ -287,3 +287,7 @@ __attribute__((objc_root_class))
 @synthesize collision = _collision; // expected-note {{property synthesized 
here}}
 
 @end
+
+// This used to crash because we'd temporarly store the weak attribute on the
+// declaration specifier, then deallocate it when clearing the declarator.
+id i1, __weak i2, i3;


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


r357514 - [OPENMP]Add codegen for private vars with allocate clause.

2019-04-02 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Apr  2 12:44:46 2019
New Revision: 357514

URL: http://llvm.org/viewvc/llvm-project?rev=357514&view=rev
Log:
[OPENMP]Add codegen for private vars with allocate clause.

Added codegen/test for the privatized variables with the allocate
clause.

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

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=357514&r1=357513&r2=357514&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Apr  2 12:44:46 2019
@@ -9761,13 +9761,9 @@ Address CGOpenMPRuntime::getAddressOfLoc
 return Address::invalid();
   const auto *AA = CVD->getAttr();
   // Use the default allocation.
-  if (AA->getAllocatorType() == OMPAllocateDeclAttr::OMPDefaultMemAlloc)
+  if (AA->getAllocatorType() == OMPAllocateDeclAttr::OMPDefaultMemAlloc &&
+  !AA->getAllocator())
 return Address::invalid();
-  auto &Elem = OpenMPLocThreadIDMap.FindAndConstruct(CGF.CurFn);
-  if (!Elem.second.ServiceInsertPt)
-setLocThreadIdInsertPt(CGF);
-  CGBuilderTy::InsertPointGuard IPG(CGF.Builder);
-  CGF.Builder.SetInsertPoint(Elem.second.ServiceInsertPt);
   llvm::Value *Size;
   CharUnits Align = CGM.getContext().getDeclAlign(CVD);
   if (CVD->getType()->isVariablyModifiedType()) {

Modified: cfe/trunk/test/OpenMP/parallel_private_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_private_codegen.cpp?rev=357514&r1=357513&r2=357514&view=diff
==
--- cfe/trunk/test/OpenMP/parallel_private_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/parallel_private_codegen.cpp Tue Apr  2 12:44:46 2019
@@ -13,6 +13,16 @@
 // expected-no-diagnostics
 #ifndef HEADER
 #define HEADER
+typedef void **omp_allocator_handle_t;
+extern const omp_allocator_handle_t omp_default_mem_alloc;
+extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
+extern const omp_allocator_handle_t omp_const_mem_alloc;
+extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
+extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
+extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
+extern const omp_allocator_handle_t omp_pteam_mem_alloc;
+extern const omp_allocator_handle_t omp_thread_mem_alloc;
+
 template 
 struct S {
   T f;
@@ -54,7 +64,7 @@ template
 struct SST {
   T a;
   SST() : a(T()) {
-#pragma omp parallel private(a)
+#pragma omp parallel private(a) allocate(omp_large_cap_mem_alloc:a)
 #ifdef LAMBDA
 [&]() {
   [&]() {
@@ -343,12 +353,18 @@ int main() {
 // CHECK: ret
 
 // CHECK: define internal void [[SST_MICROTASK]](i{{[0-9]+}}* noalias 
[[GTID_ADDR:%.+]], i{{[0-9]+}}* noalias %{{.+}}, [[SST_TY]]* %{{.+}})
-// CHECK: [[A_PRIV:%.+]] = alloca i{{[0-9]+}},
+// CHECK: [[GTID_ADDR_PTR:%.+]] = alloca i32*,
+// CHECK: [[GTID_ADDR:%.+]] = load i32*, i32** [[GTID_ADDR_PTR]],
+// CHECK: [[GTID:%.+]] = load i32, i32* [[GTID_ADDR]],
+// CHECK: [[LARGE_CAP_ALLOC:%.+]] = load i8**, i8*** @omp_large_cap_mem_alloc,
+// CHECK: [[A_VOID_PTR:%.+]] = call i8* @__kmpc_alloc(i32 [[GTID]], i64 4, 
i8** [[LARGE_CAP_ALLOC]])
+// CHECK: [[A_PRIV:%.+]] = bitcast i8* [[A_VOID_PTR]] to i32*
 // CHECK: store i{{[0-9]+}}* [[A_PRIV]], i{{[0-9]+}}** [[REF:%.+]],
 // CHECK-NEXT: [[A_PRIV:%.+]] = load i{{[0-9]+}}*, i{{[0-9]+}}** [[REF]],
 // CHECK-NEXT: [[A_VAL:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[A_PRIV]],
 // CHECK-NEXT: [[INC:%.+]] = add nsw i{{[0-9]+}} [[A_VAL]], 1
 // CHECK-NEXT: store i{{[0-9]+}} [[INC]], i{{[0-9]+}}* [[A_PRIV]],
+// CHECK-NEXT: call void @__kmpc_free(i32 [[GTID]], i8* [[A_VOID_PTR]], i8** 
[[LARGE_CAP_ALLOC]])
 // CHECK-NEXT: ret void
 
 #endif


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


[PATCH] D59806: [clang-tidy] Add a check for [super self] in initializers 🔍

2019-04-02 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added inline comments.



Comment at: clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp:112
+  << Message->getMethodDecl()
+  << FixItHint::CreateReplacement(Message->getSourceRange(),
+  StringRef("[super init]"));

aaron.ballman wrote:
> stephanemoore wrote:
> > stephanemoore wrote:
> > > aaron.ballman wrote:
> > > > This could be dangerous if the `[super self]` construct is in a macro, 
> > > > couldn't it? e.g.,
> > > > ```
> > > > #define DERP self
> > > > 
> > > > [super DERP];
> > > > ```
> > > Good point. Let me add some test cases and make sure this is handled 
> > > properly.
> > Added some test cases where `[super self]` is expanded from macros.
> You missed the test case I was worried about -- where the macro is mixed into 
> the expression. I don't think we want to try to add a fix-it in that case.
Added a test case though at the moment it generates a fixit.

Before I investigate modifying the check to avoid generating a fixit in this 
case, I think it would be helpful for me to understand your concerns in that 
scenario better. Is your concern that a proper fix might involve fixing the 
macro itself rather than the message expression?

```
#if FLAG
#define INVOCATION self
#else
#define INVOCATION init
#endif

- (instancetype)init {
  return [super INVOCATION];
}
```



Comment at: clang-tools-extra/test/clang-tidy/objc-super-self.m:41
+  INITIALIZER_IMPL();
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: suspicious invocation of 'self' in 
initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+}

aaron.ballman wrote:
> Are you missing a `CHECK-FIXES` here?
> 
> Personally, I don't think we should try to generate a fixit for this case, so 
> I would expect a CHECK-FIXES that ensures this doesn't get modified.
No fix is currently generated for this case which is why there is no 
`CHECK-FIXES`. I also agree that no fix should be generated for this case.

I must confess that I have yet to fully understand why the fix for this case is 
discarded (though I am grateful for the behavior). Let me dig around to try to 
better understand why no fixit is generated for this case and assess adding a 
condition for emitting the fixit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59806



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


[PATCH] D59806: [clang-tidy] Add a check for [super self] in initializers 🔍

2019-04-02 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore updated this revision to Diff 193340.
stephanemoore marked an inline comment as done.
stephanemoore added a comment.

Add a test case where a macro emits just `self` in the message expression.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59806

Files:
  clang-tools-extra/clang-tidy/objc/CMakeLists.txt
  clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp
  clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp
  clang-tools-extra/clang-tidy/objc/SuperSelfCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/objc-super-self.rst
  clang-tools-extra/test/clang-tidy/objc-super-self.m

Index: clang-tools-extra/test/clang-tidy/objc-super-self.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/objc-super-self.m
@@ -0,0 +1,77 @@
+// RUN: %check_clang_tidy %s objc-super-self %t
+
+@interface NSObject
+- (instancetype)init;
+- (instancetype)self;
+@end
+
+@interface NSObjectDerivedClass : NSObject
+@end
+
+@implementation NSObjectDerivedClass
+
+- (instancetype)init {
+  return [super self];
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+// CHECK-FIXES: return [super init];
+}
+
+- (instancetype)initWithObject:(NSObject *)obj {
+  self = [super self];
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+// CHECK-FIXES: self = [super init];
+  if (self) {
+// ...
+  }
+  return self;
+}
+
+#define INITIALIZE() [super self]
+
+- (instancetype)initWithObject:(NSObject *)objc a:(int)a {
+  return INITIALIZE();
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+// CHECK-FIXES: return [super init];
+}
+
+#define INITIALIZER_IMPL() return [super self]
+
+- (instancetype)initWithObject:(NSObject *)objc b:(int)b {
+  INITIALIZER_IMPL();
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+}
+
+#define INITIALIZER_METHOD self
+
+- (instancetype)initWithObject:(NSObject *)objc c:(int)c {
+  return [super INITIALIZER_METHOD];
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: suspicious invocation of 'self' in initializer; did you mean to invoke a superclass initializer? [objc-super-self]
+// CHECK-FIXES: return [super init];
+}
+
+- (instancetype)foo {
+  return [super self];
+}
+
+- (instancetype)bar {
+  return [self self];
+}
+
+@end
+
+@interface RootClass
+- (instancetype)init;
+- (instancetype)self;
+@end
+
+@interface NotNSObjectDerivedClass : RootClass
+@end
+
+@implementation NotNSObjectDerivedClass
+
+- (instancetype)init {
+  return [super self];
+}
+
+@end
+
Index: clang-tools-extra/docs/clang-tidy/checks/objc-super-self.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/objc-super-self.rst
@@ -0,0 +1,13 @@
+.. title:: clang-tidy - objc-super-self
+
+objc-super-self
+===
+
+Finds invocations of ``-self`` on super instances in initializers of subclasses
+of ``NSObject`` and recommends calling a superclass initializer instead.
+
+Invoking ``-self`` on super instances in initializers is a common programmer
+error when the programmer's original intent is to call a superclass
+initializer. Failing to call a superclass initializer breaks initializer
+chaining and can result in invalid object initialization.
+
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -227,6 +227,7 @@
objc-avoid-spinlock
objc-forbidden-subclassing
objc-property-declaration
+   objc-super-self
openmp-exception-escape
openmp-use-default-none
performance-faster-string-find
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -108,6 +108,12 @@
   Checks whether there are underscores in googletest test and test case names in
   test macros, which is prohibited by the Googletest FAQ.
 
+- New :doc:`objc-super-self ` check.
+
+  Finds invocations of ``-self`` on super instances in initializers of
+  subclasses of ``NSObject`` and recommends calling a superclass initializer
+  instead.
+
 - New alias :doc:`cppcoreguidelines-explicit-virtual-functions
   ` to
   :doc:`modernize-use-override
Index: clang-tools-extra/cla

[PATCH] D56924: Special case ObjCPropertyDecl for printing

2019-04-02 Thread David Goldman via Phabricator via cfe-commits
dgoldman added a comment.
Herald added a subscriber: dexonsmith.

ping


Repository:
  rC Clang

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

https://reviews.llvm.org/D56924



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


[PATCH] D59797: [COFF] Reorder fields in Chunk and SectionChunk to reduce their size

2019-04-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I think I've addressed all the comments, and I know that @ruiu is currently 
travelling or recovering from travel to Japan, so I'll go ahead and land this. 
Feel free to provide post-commit feedback.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59797



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


[PATCH] D60139: [clang-tidy] Add misc-placement-new-target-size check

2019-04-02 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tidy/misc/PlacementNewTargetSizeCheck.cpp:10
+#include 
+
+#include "PlacementNewTargetSizeCheck.h"

Unnecessary empty line. Please run Clang-format after fixing.



Comment at: clang-tidy/misc/PlacementNewTargetSizeCheck.cpp:23
+namespace {
+CharUnits getSizeOfType(clang::ASTContext *const Context, const QualType& 
type) {
+  CharUnits TypeSize;

Please use static instead of anonymous namespaces. See LLVM Coding Guidelines.



Comment at: clang-tidy/misc/PlacementNewTargetSizeCheck.cpp:26
+  if (type->isRecordType()) {
+const auto *CXXRecordDecl = type->getAsRecordDecl();
+assert(CXXRecordDecl && "type->getAsRecordDecl() failed");

Please don't use auto where type could not be easily deduced.



Comment at: clang-tidy/misc/PlacementNewTargetSizeCheck.cpp:28
+assert(CXXRecordDecl && "type->getAsRecordDecl() failed");
+const auto &CXXDeclLayout =
+CXXRecordDecl->getASTContext().getASTRecordLayout(CXXRecordDecl);

Please don't use auto where type could not be easily deduced.



Comment at: clang-tidy/misc/PlacementNewTargetSizeCheck.cpp:47
+const MatchFinder::MatchResult &Result) {
+  const CXXNewExpr *Alloc = Result.Nodes.getNodeAs("Alloc");
+  assert(Alloc && "Matched node bound by 'Alloc' shoud be a 'CXXNewExpr'");

auto could be used here, because of cast.



Comment at: clang-tidy/misc/PlacementNewTargetSizeCheck.cpp:50
+
+  auto numPlacementArgs = Alloc->getNumPlacementArgs();
+  if (0 == numPlacementArgs) {

Please don't use auto where type could not be easily deduced.



Comment at: clang-tidy/misc/PlacementNewTargetSizeCheck.cpp:55
+
+  auto type = Alloc->getAllocatedType();
+  CharUnits TypeSize = getSizeOfType(Result.Context, type);

Please don't use auto where type could not be easily deduced.



Comment at: clang-tidy/misc/PlacementNewTargetSizeCheck.cpp:62
+  // get ptr type of implicit cast
+  const ImplicitCastExpr *Cast = 
Result.Nodes.getNodeAs("Cast");
+  auto CastType = Cast->getSubExpr()->getType();

auto could be used here, because of cast.



Comment at: clang-tidy/misc/PlacementNewTargetSizeCheck.cpp:63
+  const ImplicitCastExpr *Cast = 
Result.Nodes.getNodeAs("Cast");
+  auto CastType = Cast->getSubExpr()->getType();
+  if (CastType->isPointerType()) {

Please don't use auto where type could not be easily deduced.



Comment at: clang-tidy/misc/PlacementNewTargetSizeCheck.cpp:65
+  if (CastType->isPointerType()) {
+   CharUnits CastSize = getSizeOfType(Result.Context, 
CastType->getPointeeType());
+if ((TypeSize - CastSize).isPositive()) {

Please run Clang-format.



Comment at: clang-tidy/misc/PlacementNewTargetSizeCheck.cpp:73
+  }
+
+}

Unnecessary empty line.



Comment at: docs/ReleaseNotes.rst:135
+  ` check.
+
 - New :doc:`openmp-exception-escape

Please add one sentence description. Should be same as in documentation.



Comment at: docs/clang-tidy/checks/misc-placement-new-target-size.rst:5
+==
+
+

Unnecessary empty line.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D60139



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


r357506 - [driver][mips] Check both `gnuabi64` and `gnu` suffixes in `getMultiarchTriple`

2019-04-02 Thread Simon Atanasyan via cfe-commits
Author: atanasyan
Date: Tue Apr  2 11:03:31 2019
New Revision: 357506

URL: http://llvm.org/viewvc/llvm-project?rev=357506&view=rev
Log:
[driver][mips] Check both `gnuabi64` and `gnu` suffixes in `getMultiarchTriple`

In case of N64 ABI toolchain paths migth have `mips-linux-gnuabi64`
or `mips-linux-gnu` directory regardless of selected environment.
Check both variants while detecting a multiarch triple.

Fix for the bug https://bugs.llvm.org/show_bug.cgi?id=41204

Modified:
cfe/trunk/lib/Driver/ToolChains/Linux.cpp
cfe/trunk/test/Driver/linux-ld.c

Modified: cfe/trunk/lib/Driver/ToolChains/Linux.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Linux.cpp?rev=357506&r1=357505&r2=357506&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Linux.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Linux.cpp Tue Apr  2 11:03:31 2019
@@ -44,6 +44,7 @@ static std::string getMultiarchTriple(co
   TargetTriple.getEnvironment();
   bool IsAndroid = TargetTriple.isAndroid();
   bool IsMipsR6 = TargetTriple.getSubArch() == llvm::Triple::MipsSubArch_r6;
+  bool IsMipsN32Abi = TargetTriple.getEnvironment() == llvm::Triple::GNUABIN32;
 
   // For most architectures, just use whatever we have rather than trying to be
   // clever.
@@ -102,33 +103,37 @@ static std::string getMultiarchTriple(co
   return "aarch64_be-linux-gnu";
 break;
   case llvm::Triple::mips: {
-std::string Arch = IsMipsR6 ? "mipsisa32r6" : "mips";
-if (D.getVFS().exists(SysRoot + "/lib/" + Arch + "-linux-gnu"))
-  return Arch + "-linux-gnu";
+std::string MT = IsMipsR6 ? "mipsisa32r6-linux-gnu" : "mips-linux-gnu";
+if (D.getVFS().exists(SysRoot + "/lib/" + MT))
+  return MT;
 break;
   }
   case llvm::Triple::mipsel: {
 if (IsAndroid)
   return "mipsel-linux-android";
-std::string Arch = IsMipsR6 ? "mipsisa32r6el" : "mipsel";
-if (D.getVFS().exists(SysRoot + "/lib/" + Arch + "-linux-gnu"))
-  return Arch + "-linux-gnu";
+std::string MT = IsMipsR6 ? "mipsisa32r6el-linux-gnu" : "mipsel-linux-gnu";
+if (D.getVFS().exists(SysRoot + "/lib/" + MT))
+  return MT;
 break;
   }
   case llvm::Triple::mips64: {
-std::string Arch = IsMipsR6 ? "mipsisa64r6" : "mips64";
-std::string ABI = llvm::Triple::getEnvironmentTypeName(TargetEnvironment);
-if (D.getVFS().exists(SysRoot + "/lib/" + Arch + "-linux-" + ABI))
-  return Arch + "-linux-" + ABI;
+std::string MT = std::string(IsMipsR6 ? "mipsisa64r6" : "mips64") +
+ "-linux-" + (IsMipsN32Abi ? "gnuabin32" : "gnuabi64");
+if (D.getVFS().exists(SysRoot + "/lib/" + MT))
+  return MT;
+if (D.getVFS().exists(SysRoot + "/lib/mips64-linux-gnu"))
+  return "mips64-linux-gnu";
 break;
   }
   case llvm::Triple::mips64el: {
 if (IsAndroid)
   return "mips64el-linux-android";
-std::string Arch = IsMipsR6 ? "mipsisa64r6el" : "mips64el";
-std::string ABI = llvm::Triple::getEnvironmentTypeName(TargetEnvironment);
-if (D.getVFS().exists(SysRoot + "/lib/" + Arch + "-linux-" + ABI))
-  return Arch + "-linux-" + ABI;
+std::string MT = std::string(IsMipsR6 ? "mipsisa64r6el" : "mips64el") +
+ "-linux-" + (IsMipsN32Abi ? "gnuabin32" : "gnuabi64");
+if (D.getVFS().exists(SysRoot + "/lib/" + MT))
+  return MT;
+if (D.getVFS().exists(SysRoot + "/lib/mips64el-linux-gnu"))
+  return "mips64el-linux-gnu";
 break;
   }
   case llvm::Triple::ppc:

Modified: cfe/trunk/test/Driver/linux-ld.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/linux-ld.c?rev=357506&r1=357505&r2=357506&view=diff
==
--- cfe/trunk/test/Driver/linux-ld.c (original)
+++ cfe/trunk/test/Driver/linux-ld.c Tue Apr  2 11:03:31 2019
@@ -1660,6 +1660,11 @@
 // CHECK-DEBIAN-ML-MIPS64EL-N32: "-L[[SYSROOT]]/usr/lib"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=mips64-unknown-linux-gnu \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/debian_6_mips64_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-DEBIAN-ML-MIPS64-GNUABI %s
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: --target=mips64-linux-gnuabi64 -mabi=n64 \
 // RUN: --gcc-toolchain="" \
 // RUN: --sysroot=%S/Inputs/debian_6_mips64_tree \
@@ -1680,6 +1685,11 @@
 // CHECK-DEBIAN-ML-MIPS64-GNUABI: 
"{{.*}}/usr/lib/gcc/mips64-linux-gnuabi64/4.9/../../../mips64-linux-gnuabi64{{/|}}crtn.o"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=mips64el-unknown-linux-gnu \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/debian_6_mips64_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-DEBIAN-ML-MIPS64EL-GNUABI %s
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: 

r357505 - [driver] clang-format. Fix indentation, split long lines. NFC

2019-04-02 Thread Simon Atanasyan via cfe-commits
Author: atanasyan
Date: Tue Apr  2 11:03:15 2019
New Revision: 357505

URL: http://llvm.org/viewvc/llvm-project?rev=357505&view=rev
Log:
[driver] clang-format. Fix indentation, split long lines. NFC

Modified:
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/lib/Driver/ToolChains/Linux.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=357505&r1=357504&r2=357505&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Apr  2 11:03:15 2019
@@ -246,8 +246,9 @@ InputArgList Driver::ParseArgStrings(Arr
   : diag::err_drv_unknown_argument;
   Diags.Report(DiagID) << ArgString;
 } else {
-  DiagID = IsCLMode() ? 
diag::warn_drv_unknown_argument_clang_cl_with_suggestion
-  : diag::err_drv_unknown_argument_with_suggestion;
+  DiagID = IsCLMode()
+   ? diag::warn_drv_unknown_argument_clang_cl_with_suggestion
+   : diag::err_drv_unknown_argument_with_suggestion;
   Diags.Report(DiagID) << ArgString << Nearest;
 }
 ContainsError |= Diags.getDiagnosticLevel(DiagID, SourceLocation()) >
@@ -1417,11 +1418,13 @@ void Driver::generateCompilationDiagnost
 }
 
 void Driver::setUpResponseFiles(Compilation &C, Command &Cmd) {
-  // Since commandLineFitsWithinSystemLimits() may underestimate system's 
capacity
-  // if the tool does not support response files, there is a chance/ that 
things
-  // will just work without a response file, so we silently just skip it.
+  // Since commandLineFitsWithinSystemLimits() may underestimate system's
+  // capacity if the tool does not support response files, there is a chance/
+  // that things will just work without a response file, so we silently just
+  // skip it.
   if (Cmd.getCreator().getResponseFilesSupport() == Tool::RF_None ||
-  llvm::sys::commandLineFitsWithinSystemLimits(Cmd.getExecutable(), 
Cmd.getArguments()))
+  llvm::sys::commandLineFitsWithinSystemLimits(Cmd.getExecutable(),
+   Cmd.getArguments()))
 return;
 
   std::string TmpName = GetTemporaryPath("response", "txt");
@@ -2030,7 +2033,8 @@ void Driver::BuildInputs(const ToolChain
 
 Arg *Previous = nullptr;
 bool ShowNote = false;
-for (Arg *A : Args.filtered(options::OPT__SLASH_TC, 
options::OPT__SLASH_TP)) {
+for (Arg *A :
+ Args.filtered(options::OPT__SLASH_TC, options::OPT__SLASH_TP)) {
   if (Previous) {
 Diag(clang::diag::warn_drv_overriding_flag_option)
   << Previous->getSpelling() << A->getSpelling();
@@ -4260,8 +4264,8 @@ const char *Driver::GetNamedOutputPath(C
   SmallString<128> CrashDirectory(A->getValue());
   llvm::sys::path::append(CrashDirectory, Split.first);
   const char *Middle = Suffix ? "-%%." : "-%%";
-  std::error_code EC =
-  llvm::sys::fs::createUniqueFile(CrashDirectory + Middle + Suffix, 
TmpName);
+  std::error_code EC = llvm::sys::fs::createUniqueFile(
+  CrashDirectory + Middle + Suffix, TmpName);
   if (EC) {
 Diag(clang::diag::err_unable_to_make_temp) << EC.message();
 return "";
@@ -4764,7 +4768,8 @@ bool Driver::GetReleaseVersion(StringRef
   return false;
 }
 
-std::pair Driver::getIncludeExcludeOptionFlagMasks(bool 
IsClCompatMode) const {
+std::pair
+Driver::getIncludeExcludeOptionFlagMasks(bool IsClCompatMode) const {
   unsigned IncludedFlagsBitmask = 0;
   unsigned ExcludedFlagsBitmask = options::NoDriverOption;
 

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=357505&r1=357504&r2=357505&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Tue Apr  2 11:03:15 2019
@@ -464,7 +464,7 @@ void tools::gnutools::Linker::ConstructJ
 
   if (HasCRTBeginEndFiles)
 CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(crtbegin)));
-   }
+}
 
 // Add crtfastmath.o if available and fast math is enabled.
 ToolChain.AddFastMathRuntimeIfAvailable(Args, CmdArgs);
@@ -675,14 +675,16 @@ void tools::gnutools::Assembler::Constru
   case llvm::Triple::sparcel: {
 CmdArgs.push_back("-32");
 std::string CPU = getCPUName(Args, getToolChain().getTriple());
-CmdArgs.push_back(sparc::getSparcAsmModeForCPU(CPU, 
getToolChain().getTriple()));
+CmdArgs.push_back(
+sparc::getSparcAsmModeForCPU(CPU, getToolChain().getTriple()));
 AddAssemblerKPIC(getToolChain(), Args, CmdArgs);
 break;
   }
   case llvm::Triple::sparcv9: {
 CmdArgs.push_back("-64");
 std::string CPU = getCPUName(Args, getToolChain().getTriple())

[PATCH] D60141: [HIP-Clang] Fat binary should not be produced for non GPU code

2019-04-02 Thread Aaron Enye Shi via Phabricator via cfe-commits
ashi1 created this revision.
ashi1 added a reviewer: yaxunl.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Do not produce Fat binary functions for HIP when no device code is present.


Repository:
  rC Clang

https://reviews.llvm.org/D60141

Files:
  lib/CodeGen/CGCUDANV.cpp
  test/CodeGenCUDA/device-stub.cu


Index: test/CodeGenCUDA/device-stub.cu
===
--- test/CodeGenCUDA/device-stub.cu
+++ test/CodeGenCUDA/device-stub.cu
@@ -228,14 +228,21 @@
 // device-side globals, but we still need to register GPU binary.
 // Skip GPU binary string first.
 // CUDANOGLOBALS: @{{.*}} = private constant{{.*}}
-// HIPNOGLOBALS: @{{.*}} = internal constant{{.*}}
+// HIPNOGLOBALS-NOT: @{{.*}} = internal constant{{.*}}
 // NOGLOBALS-NOT: define internal void @__{{.*}}_register_globals
-// NOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
-// NOGLOBALS: 
call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
+// CUDANOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
+// CUDANOGLOBALS: 
call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
 // NOGLOBALS-NOT: call void @__[[PREFIX]]_register_globals
-// NOGLOBALS: define internal void @__[[PREFIX]]_module_dtor
-// NOGLOBALS: call void @__[[PREFIX]]UnregisterFatBinary
+// CUDANOGLOBALS: define internal void @__[[PREFIX]]_module_dtor
+// CUDANOGLOBALS: call void @__[[PREFIX]]UnregisterFatBinary
+
+// There should be no fat binary functions when no device-code is found for 
HIP.
+// HIPNOGLOBALS-NOT: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
+// HIPNOGLOBALS-NOT: 
call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
+// HIPNOGLOBALS-NOT: define internal void @__[[PREFIX]]_module_dtor
+// HIPNOGLOBALS-NOT: call void @__[[PREFIX]]UnregisterFatBinary
+

 // There should be no constructors/destructors if we have no GPU binary.
 // NOGPUBIN-NOT: define internal void @__[[PREFIX]]_register_globals
 // NOGPUBIN-NOT: define internal void @__[[PREFIX]]_module_ctor
Index: lib/CodeGen/CGCUDANV.cpp
===
--- lib/CodeGen/CGCUDANV.cpp
+++ lib/CodeGen/CGCUDANV.cpp
@@ -472,13 +472,15 @@
   StringRef CudaGpuBinaryFileName = CGM.getCodeGenOpts().CudaGpuBinaryFileName;
   if (CudaGpuBinaryFileName.empty() && !IsHIP)
 return nullptr;
+  if (IsHIP && EmittedKernels.empty() && DeviceVars.empty())
+return nullptr;

   // void __{cuda|hip}_register_globals(void* handle);
   llvm::Function *RegisterGlobalsFunc = makeRegisterGlobalsFn();
   // We always need a function to pass in as callback. Create a dummy
   // implementation if we don't need to register anything.
   if (RelocatableDeviceCode && !RegisterGlobalsFunc)
 RegisterGlobalsFunc = makeDummyFunction(getRegisterGlobalsFnTy());

   // void ** __{cuda|hip}RegisterFatBinary(void *);
   llvm::FunctionCallee RegisterFatbinFunc = CGM.CreateRuntimeFunction(


Index: test/CodeGenCUDA/device-stub.cu
===
--- test/CodeGenCUDA/device-stub.cu
+++ test/CodeGenCUDA/device-stub.cu
@@ -228,14 +228,21 @@
 // device-side globals, but we still need to register GPU binary.
 // Skip GPU binary string first.
 // CUDANOGLOBALS: @{{.*}} = private constant{{.*}}
-// HIPNOGLOBALS: @{{.*}} = internal constant{{.*}}
+// HIPNOGLOBALS-NOT: @{{.*}} = internal constant{{.*}}
 // NOGLOBALS-NOT: define internal void @__{{.*}}_register_globals
-// NOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
-// NOGLOBALS: call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
+// CUDANOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
+// CUDANOGLOBALS: call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
 // NOGLOBALS-NOT: call void @__[[PREFIX]]_register_globals
-// NOGLOBALS: define internal void @__[[PREFIX]]_module_dtor
-// NOGLOBALS: call void @__[[PREFIX]]UnregisterFatBinary
+// CUDANOGLOBALS: define internal void @__[[PREFIX]]_module_dtor
+// CUDANOGLOBALS: call void @__[[PREFIX]]UnregisterFatBinary
+
+// There should be no fat binary functions when no device-code is found for HIP.
+// HIPNOGLOBALS-NOT: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
+// HIPNOGLOBALS-NOT: call{{.*}}[[PREFIX]]RegisterFatBinary{{.*}}__[[PREFIX]]_fatbin_wrapper
+// HIPNOGLOBALS-NOT: define internal void @__[[PREFIX]]_module_dtor
+// HIPNOGLOBALS-NOT: call void @__[[PREFIX]]UnregisterFatBinary
+

 // There should be no constructors/destructors if we have no GPU binary.
 // NOGPUBIN-NOT: define internal void @__[[PREFIX]]_register_globals
 // NOGPUBIN-NOT: define internal void @__[[PREFIX]]_module_ctor
Index: lib/CodeGen/CGCUDANV.cpp
===
--- lib/CodeGen/CGCUDANV.cpp
+++ lib/CodeGen/CGCUDANV.cpp
@@ -472,13 +472,15 @@
   StringRef CudaGpuBinaryFileName =

Re: Default -fomit-frame-pointer for PowerPC

2019-04-02 Thread Finkel, Hal J. via cfe-commits
On 4/2/19 12:31 PM, Roman Lebedev via cfe-commits wrote:
> Best to submit patches to phabricator https://reviews.llvm.org/


Please follow the instructions here:
http://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface
- This will make it much easier for us to track this.

Thanks!

 -Hal

>
> On Tue, Apr 2, 2019 at 8:30 PM George Koehler via cfe-commits
>  wrote:
>> Hello cfe-commits,
>>
>> The attached patch is for clang to use -fomit-frame-pointer by default
>> for all PowerPC targets when optimizing code.  Right now, clang uses
>> -fomit-frame-pointer for PowerPC Linux and NetBSD but not for other
>> targets.  I have been running `clang -target powerpc-openbsd`.
>>
>> The patch is for llvm-project.git master.  I previously posted this
>> patch to https://bugs.llvm.org/show_bug.cgi?id=41094 , but the patch
>> in this email is for a newer revision of master.
>>
>> In most functions, the frame pointer in r31 is an unnecessary extra
>> copy of the stack pointer in r1.  GCC is using -fomit-frame-pointer by
>> default (in my PowerPC machine running OpenBSD/macppc); I want Clang
>> to be at least as good as GCC.  Also, this patch helps me to compare
>> the output of `clang -target powerpc-openbsd -O2 -S` with the output
>> for Linux or NetBSD.  In bug 41094, I showed how -fomit-frame-pointer
>> simplifies the C function `void nothing(void) {}`.
>>
>> This is my first mail to cfe-commits; I'm using the instructions at
>> http://llvm.org/docs/DeveloperPolicy.html#making-and-submitting-a-patch
>>
>> --
>> George Koehler 
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory

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


[PATCH] D60108: [os_log] Mark os_log_helper `nounwind`

2019-04-02 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC357501: [os_log] Mark os_log_helper `nounwind` (authored by 
vedantk, committed by ).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D60108?vs=193217&id=193322#toc

Repository:
  rC Clang

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

https://reviews.llvm.org/D60108

Files:
  lib/CodeGen/CGBuiltin.cpp
  test/CodeGenObjCXX/os_log.mm


Index: test/CodeGenObjCXX/os_log.mm
===
--- test/CodeGenObjCXX/os_log.mm
+++ test/CodeGenObjCXX/os_log.mm
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc \
+// RUN:   -fexceptions -fcxx-exceptions -O1 | FileCheck %s
+
+// Check that no EH cleanup is emitted around the call to __os_log_helper.
+namespace no_eh_cleanup {
+  void release(int *lock);
+
+  // CHECK-LABEL: define {{.*}} @_ZN13no_eh_cleanup3logERiPcS1_(
+  void log(int &i, char *data, char *buf) {
+  int lock __attribute__((cleanup(release)));
+  // CHECK: call void @__os_log_helper_1_2_2_4_0_8_34(
+  // CHECK-NEXT: call void @_ZN13no_eh_cleanup7releaseEPi
+  __builtin_os_log_format(buf, "%d %{public}s", i, data);
+  }
+
+  // CHECK: define {{.*}} @__os_log_helper_1_2_2_4_0_8_34({{.*}} 
[[NUW:#[0-9]+]]
+}
+
+// CHECK: attributes [[NUW]] = { {{.*}}nounwind
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -1138,6 +1138,7 @@
   Fn->setVisibility(llvm::GlobalValue::HiddenVisibility);
   CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, Fn);
   CGM.SetLLVMFunctionAttributesForDefinition(nullptr, Fn);
+  Fn->setDoesNotThrow();
 
   // Attach 'noinline' at -Oz.
   if (CGM.getCodeGenOpts().OptimizeSize == 2)


Index: test/CodeGenObjCXX/os_log.mm
===
--- test/CodeGenObjCXX/os_log.mm
+++ test/CodeGenObjCXX/os_log.mm
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc \
+// RUN:   -fexceptions -fcxx-exceptions -O1 | FileCheck %s
+
+// Check that no EH cleanup is emitted around the call to __os_log_helper.
+namespace no_eh_cleanup {
+  void release(int *lock);
+
+  // CHECK-LABEL: define {{.*}} @_ZN13no_eh_cleanup3logERiPcS1_(
+  void log(int &i, char *data, char *buf) {
+  int lock __attribute__((cleanup(release)));
+  // CHECK: call void @__os_log_helper_1_2_2_4_0_8_34(
+  // CHECK-NEXT: call void @_ZN13no_eh_cleanup7releaseEPi
+  __builtin_os_log_format(buf, "%d %{public}s", i, data);
+  }
+
+  // CHECK: define {{.*}} @__os_log_helper_1_2_2_4_0_8_34({{.*}} [[NUW:#[0-9]+]]
+}
+
+// CHECK: attributes [[NUW]] = { {{.*}}nounwind
Index: lib/CodeGen/CGBuiltin.cpp
===
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -1138,6 +1138,7 @@
   Fn->setVisibility(llvm::GlobalValue::HiddenVisibility);
   CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, Fn);
   CGM.SetLLVMFunctionAttributesForDefinition(nullptr, Fn);
+  Fn->setDoesNotThrow();
 
   // Attach 'noinline' at -Oz.
   if (CGM.getCodeGenOpts().OptimizeSize == 2)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r357501 - [os_log] Mark os_log_helper `nounwind`

2019-04-02 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Tue Apr  2 10:42:38 2019
New Revision: 357501

URL: http://llvm.org/viewvc/llvm-project?rev=357501&view=rev
Log:
[os_log] Mark os_log_helper `nounwind`

Allow the optimizer to remove unnecessary EH cleanups surrounding calls
to os_log_helper, to save some code size.

As a follow-up, it might be worthwhile to add a BasicNoexcept exception
spec to os_log_helper, and to then teach CGCall to emit direct calls for
callees which can't throw. This could save some compile-time.

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

Added:
cfe/trunk/test/CodeGenObjCXX/os_log.mm
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=357501&r1=357500&r2=357501&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Apr  2 10:42:38 2019
@@ -1138,6 +1138,7 @@ llvm::Function *CodeGenFunction::generat
   Fn->setVisibility(llvm::GlobalValue::HiddenVisibility);
   CGM.SetLLVMFunctionAttributes(GlobalDecl(), FI, Fn);
   CGM.SetLLVMFunctionAttributesForDefinition(nullptr, Fn);
+  Fn->setDoesNotThrow();
 
   // Attach 'noinline' at -Oz.
   if (CGM.getCodeGenOpts().OptimizeSize == 2)

Added: cfe/trunk/test/CodeGenObjCXX/os_log.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/os_log.mm?rev=357501&view=auto
==
--- cfe/trunk/test/CodeGenObjCXX/os_log.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/os_log.mm Tue Apr  2 10:42:38 2019
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc \
+// RUN:   -fexceptions -fcxx-exceptions -O1 | FileCheck %s
+
+// Check that no EH cleanup is emitted around the call to __os_log_helper.
+namespace no_eh_cleanup {
+  void release(int *lock);
+
+  // CHECK-LABEL: define {{.*}} @_ZN13no_eh_cleanup3logERiPcS1_(
+  void log(int &i, char *data, char *buf) {
+  int lock __attribute__((cleanup(release)));
+  // CHECK: call void @__os_log_helper_1_2_2_4_0_8_34(
+  // CHECK-NEXT: call void @_ZN13no_eh_cleanup7releaseEPi
+  __builtin_os_log_format(buf, "%d %{public}s", i, data);
+  }
+
+  // CHECK: define {{.*}} @__os_log_helper_1_2_2_4_0_8_34({{.*}} 
[[NUW:#[0-9]+]]
+}
+
+// CHECK: attributes [[NUW]] = { {{.*}}nounwind


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


Re: Default -fomit-frame-pointer for PowerPC

2019-04-02 Thread Roman Lebedev via cfe-commits
Best to submit patches to phabricator https://reviews.llvm.org/

On Tue, Apr 2, 2019 at 8:30 PM George Koehler via cfe-commits
 wrote:
>
> Hello cfe-commits,
>
> The attached patch is for clang to use -fomit-frame-pointer by default
> for all PowerPC targets when optimizing code.  Right now, clang uses
> -fomit-frame-pointer for PowerPC Linux and NetBSD but not for other
> targets.  I have been running `clang -target powerpc-openbsd`.
>
> The patch is for llvm-project.git master.  I previously posted this
> patch to https://bugs.llvm.org/show_bug.cgi?id=41094 , but the patch
> in this email is for a newer revision of master.
>
> In most functions, the frame pointer in r31 is an unnecessary extra
> copy of the stack pointer in r1.  GCC is using -fomit-frame-pointer by
> default (in my PowerPC machine running OpenBSD/macppc); I want Clang
> to be at least as good as GCC.  Also, this patch helps me to compare
> the output of `clang -target powerpc-openbsd -O2 -S` with the output
> for Linux or NetBSD.  In bug 41094, I showed how -fomit-frame-pointer
> simplifies the C function `void nothing(void) {}`.
>
> This is my first mail to cfe-commits; I'm using the instructions at
> http://llvm.org/docs/DeveloperPolicy.html#making-and-submitting-a-patch
>
> --
> George Koehler 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Default -fomit-frame-pointer for PowerPC

2019-04-02 Thread George Koehler via cfe-commits
Hello cfe-commits,

The attached patch is for clang to use -fomit-frame-pointer by default
for all PowerPC targets when optimizing code.  Right now, clang uses
-fomit-frame-pointer for PowerPC Linux and NetBSD but not for other
targets.  I have been running `clang -target powerpc-openbsd`.

The patch is for llvm-project.git master.  I previously posted this
patch to https://bugs.llvm.org/show_bug.cgi?id=41094 , but the patch
in this email is for a newer revision of master.

In most functions, the frame pointer in r31 is an unnecessary extra
copy of the stack pointer in r1.  GCC is using -fomit-frame-pointer by
default (in my PowerPC machine running OpenBSD/macppc); I want Clang
to be at least as good as GCC.  Also, this patch helps me to compare
the output of `clang -target powerpc-openbsd -O2 -S` with the output
for Linux or NetBSD.  In bug 41094, I showed how -fomit-frame-pointer
simplifies the C function `void nothing(void) {}`.

This is my first mail to cfe-commits; I'm using the instructions at
http://llvm.org/docs/DeveloperPolicy.html#making-and-submitting-a-patch

-- 
George Koehler 
From a7906214c4751b4c181546ae48ecd05c8f84f07b Mon Sep 17 00:00:00 2001
From: George Koehler 
Date: Tue, 2 Apr 2019 11:29:19 -0400
Subject: [PATCH] Use -fomit-frame-pointer when optimizing PowerPC code

This enables -fomit-frame-pointer when optimizing code for all PowerPC
targets, instead of only Linux and NetBSD.
---
 clang/lib/Driver/ToolChains/Clang.cpp | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index a5b98aad54d..6bfca0a5f15 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -523,8 +523,12 @@ static bool useFramePointerForTargetByDefault(const 
ArgList &Args,
 // XCore never wants frame pointers, regardless of OS.
 // WebAssembly never wants frame pointers.
 return false;
+  case llvm::Triple::ppc:
+  case llvm::Triple::ppc64:
+  case llvm::Triple::ppc64le:
   case llvm::Triple::riscv32:
   case llvm::Triple::riscv64:
+// PowerPC's frame pointer is often an extra copy of the stack pointer.
 return !areOptimizationsEnabled(Args);
   default:
 break;
@@ -542,9 +546,6 @@ static bool useFramePointerForTargetByDefault(const ArgList 
&Args,
 case llvm::Triple::mips64el:
 case llvm::Triple::mips:
 case llvm::Triple::mipsel:
-case llvm::Triple::ppc:
-case llvm::Triple::ppc64:
-case llvm::Triple::ppc64le:
 case llvm::Triple::systemz:
 case llvm::Triple::x86:
 case llvm::Triple::x86_64:
-- 
2.19.1

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


[PATCH] D60108: [os_log] Mark os_log_helper `nounwind`

2019-04-02 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D60108



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


[PATCH] D60139: Add clang-tidy/checks/misc-placement-new-target-size check

2019-04-02 Thread Dennis Luxen via Phabricator via cfe-commits
DennisL created this revision.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.

Finds placement-new calls where the size of the pointee type of the placement 
parameter is smaller than the size of the constructed type and the pointer is 
implicitly cast to ``void *``


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D60139

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/PlacementNewTargetSizeCheck.cpp
  clang-tidy/misc/PlacementNewTargetSizeCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-placement-new-target-size.rst
  test/clang-tidy/misc-placement-new-target-size.cpp

Index: test/clang-tidy/misc-placement-new-target-size.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-placement-new-target-size.cpp
@@ -0,0 +1,14 @@
+// RUN: %check_clang_tidy %s misc-placement-new-target-size %t
+
+void f() {
+  struct Dummy {
+int a;
+int b;
+  };
+  int * ptr = new int;
+  new (ptr) Dummy;
+  delete ptr;
+
+}
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'f' is insufficiently awesome [misc-placement-new-target-size]
+
Index: docs/clang-tidy/checks/misc-placement-new-target-size.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-placement-new-target-size.rst
@@ -0,0 +1,10 @@
+.. title:: clang-tidy - misc-placement-new-target-size
+
+misc-placement-new-target-size
+==
+
+
+Finds placement-new calls where the size of the pointee type of the placement 
+parameter is smaller than the size of the constructed type and the pointer is
+implicitly cast to ``void *``.
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -184,6 +184,7 @@
misc-new-delete-overloads
misc-non-copyable-objects
misc-non-private-member-variables-in-classes
+   misc-placement-new-target-size
misc-redundant-expression
misc-static-assert
misc-throw-by-value-catch-by-reference
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -130,6 +130,9 @@
   ` now supports `OverrideSpelling`
   and `FinalSpelling` options.
 
+- New :doc:`misc-placement-new-target-size
+  ` check.
+
 - New :doc:`openmp-exception-escape
   ` check.
 
Index: clang-tidy/misc/PlacementNewTargetSizeCheck.h
===
--- /dev/null
+++ clang-tidy/misc/PlacementNewTargetSizeCheck.h
@@ -0,0 +1,36 @@
+//===--- PlacementNewTargetSizeCheck.h - clang-tidy -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_PLACEMENTNEWTARGETSIZECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_PLACEMENTNEWTARGETSIZECHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+/// This checker finds placement new statements that construct objects into allocated
+/// space where the pointer to that allocated space is of a type smaller than the
+/// constructed object and the pointer is implicitly cast to void *.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/misc-placement-new-target-size.html
+class PlacementNewTargetSizeCheck : public ClangTidyCheck {
+public:
+  PlacementNewTargetSizeCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace misc
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_PLACEMENTNEWTARGETSIZECHECK_H
Index: clang-tidy/misc/PlacementNewTargetSizeCheck.cpp
===
--- /dev/null
+++ clang-tidy/misc/PlacementNewTargetSizeCheck.cpp
@@ -0,0 +1,78 @@
+//===--- PlacementNewTargetSizeCheck.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include 
+
+#include "PlacementNewTargetSizeCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/RecordLayout.h"
+#include "clang/ASTMatch

[PATCH] D55463: Introduce a source minimizer that reduces source to directives that might affect the dependency list for a compilation

2019-04-02 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In D55463#1451166 , @tschuett wrote:

> Are you planning to do this recursively?
>  The minimizer does not help much for the following example, while Sema.h 
> contains 10,000 lines of useless code.
>
>   #include "clang/Sema/Sema.h"
>  
>   int foo() {}
>


Not recursively, but on each file *independently* by intercepting `stat` and 
`open` in a custom VFS layer.  The old patch at https://reviews.llvm.org/D53354 
(which Alex points to above) might give you more context.


Repository:
  rC Clang

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

https://reviews.llvm.org/D55463



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


[PATCH] D60130: gn build: Add build files for clangd xpc framework code

2019-04-02 Thread Nico Weber via Phabricator via cfe-commits
thakis updated this revision to Diff 193313.
thakis added a comment.

Use {{source_file_part}} in bundle_data where possible.


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

https://reviews.llvm.org/D60130

Files:
  clang-tools-extra/clangd/xpc/framework/CMakeLists.txt
  clang-tools-extra/clangd/xpc/test-client/ClangdXPCTestClient.cpp
  llvm/utils/gn/build/symlink_or_copy.py
  llvm/utils/gn/build/toolchain/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/framework/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/test-client/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
@@ -1,3 +1,4 @@
+import("//clang-tools-extra/clangd/xpc/enable.gni")
 import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
 import("//llvm/triples.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
@@ -35,9 +36,14 @@
 "LLVM_LIT_TOOLS_DIR=",  # Intentionally empty, matches cmake build.
 "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),
 "PYTHON_EXECUTABLE=$python_path",
-"CLANGD_BUILD_XPC_SUPPORT=0",  # FIXME
   ]
 
+  if (clangd_build_xpc) {
+extra_values += [ "CLANGD_BUILD_XPC_SUPPORT=1" ]
+  } else {
+extra_values += [ "CLANGD_BUILD_XPC_SUPPORT=0" ]
+  }
+
   if (clang_enable_static_analyzer) {
 extra_values += [ "CLANG_ENABLE_STATIC_ANALYZER=1" ]
   } else {
@@ -83,6 +89,10 @@
 "//llvm/utils/llvm-lit",
 "//llvm/utils/not",
   ]
+  if (clangd_build_xpc) {
+deps +=
+[ "//clang-tools-extra/clangd/xpc/test-client:clangd-xpc-test-client" ]
+  }
 
   # FIXME: dep on dexp once it exist
   testonly = true
Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/test-client/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/test-client/BUILD.gn
@@ -0,0 +1,20 @@
+executable("clangd-xpc-test-client") {
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang-tools-extra/clangd",
+"//clang-tools-extra/clangd/xpc:conversions",
+"//clang-tools-extra/clangd/xpc/framework:ClangdXPC.framework",
+"//clang/lib/Basic",
+"//clang/lib/Format",
+"//clang/lib/Frontend",
+"//clang/lib/Sema",
+"//clang/lib/Tooling",
+"//clang/lib/Tooling/Core",
+"//llvm/lib/Support",
+  ]
+
+  include_dirs = [ "../.." ]
+  sources = [
+"ClangdXPCTestClient.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/framework/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/framework/BUILD.gn
@@ -0,0 +1,154 @@
+import("//llvm/utils/gn/build/symlink_or_copy.gni")
+import("//llvm/utils/gn/build/write_cmake_config.gni")
+
+# create_clangd_xpc_framework() in cmake creates both the ClangdXPC.framework
+# bundle and the clangd.xpc bundle within it in a single action.
+# Since GN has some native support for macOS bundles, it's more natural
+# to have one create_bundle() each for both ClangdXPC.framework and clangd.xpc.
+# See `llvm/utils/gn/gn.py help create_bundle` and ../cmake/modules.
+
+##
+# clangd.xpc bundle
+
+write_cmake_config("XPCServiceInfo.plist") {
+  input = "../cmake/XPCServiceInfo.plist.in"
+  output = "$target_gen_dir/XPCServiceInfo.plist"
+  service_name = "clangd"
+  values = [
+"CLANGD_XPC_SERVICE_NAME=$service_name",
+"CLANGD_XPC_SERVICE_BUNDLE_NAME=org.llvm.$service_name",
+  ]
+}
+
+bundle_data("clangxpc_bundle_xpc_service_info_plist") {
+  public_deps = [
+":XPCServiceInfo.plist",
+  ]
+  sources = [
+"$target_gen_dir/XPCServiceInfo.plist",
+  ]
+  outputs = [
+"{{bundle_contents_dir}}/Info.plist",
+  ]
+}
+
+bundle_data("clangxpc_bundle_xpc_service_executable") {
+  public_deps = [
+"//clang-tools-extra/clangd/tool:clangd",
+  ]
+  sources = [
+"$root_out_dir/bin/clangd",
+  ]
+  outputs = [
+"{{bundle_executable_dir}}/{{source_file_part}}",
+  ]
+}
+
+create_bundle("clangd.xpc") {
+  # .app directory structure.
+  # Since this target only exists to be copied into ClangdXPC.framework,
+  # put it in $target_gen_dir, not $root_out_dir.
+  bundle_root_dir = "$target_gen_dir/$target_name"
+  bundle_contents_dir = "$bundle_root_dir/Contents"
+  bundle_executable_dir = "$bundle_contents_dir/MacOS"
+
+  deps = [
+":clangxpc_bundle_xpc_service_executable",
+":clangxpc_bundle_xpc_service_info_plist",
+  ]
+}
+
+##
+# ClangdXPC.framework
+
+write_cmake_config("Info.plist") {
+  input = "../cmake/Info.plist.in"
+  output = "$target_gen_dir/Info.plis

[PATCH] D53633: [AArch64] Implement FP16FML intrinsics

2019-04-02 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

FYI: a new ACLE version has been published, please find it here:   
https://developer.arm.com/architectures/system-architectures/software-standards/acle

The "Neon Intrinsics" section contains these new intrinsics.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D53633



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


r357488 - [OPENMP]Fix mapping of the pointers captured by reference.

2019-04-02 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Apr  2 09:03:40 2019
New Revision: 357488

URL: http://llvm.org/viewvc/llvm-project?rev=357488&view=rev
Log:
[OPENMP]Fix mapping of the pointers captured by reference.

If the pointer is captured by reference, it must be mapped as
_PTR_AND_OBJ kind of mapping to correctly translate the pointer address
on the device.

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

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=357488&r1=357487&r2=357488&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Apr  2 09:03:40 2019
@@ -7347,6 +7347,9 @@ private:
   Cap.getCaptureKind() == CapturedStmt::VCK_ByRef)
 return MappableExprsHandler::OMP_MAP_ALWAYS |
MappableExprsHandler::OMP_MAP_TO;
+  if (Cap.getCapturedVar()->getType()->isAnyPointerType())
+return MappableExprsHandler::OMP_MAP_TO |
+   MappableExprsHandler::OMP_MAP_PTR_AND_OBJ;
   return MappableExprsHandler::OMP_MAP_PRIVATE |
  MappableExprsHandler::OMP_MAP_TO;
 }
@@ -7992,14 +7995,20 @@ public:
 CGF.Builder.CreateMemCpy(
 CGF.MakeNaturalAlignAddrLValue(Addr, ElementType).getAddress(),
 Address(CV, CGF.getContext().getTypeAlignInChars(ElementType)),
-CurSizes.back(),
-/*isVolatile=*/false);
+CurSizes.back(), /*isVolatile=*/false);
 // Use new global variable as the base pointers.
 CurBasePointers.push_back(Addr);
 CurPointers.push_back(Addr);
   } else {
 CurBasePointers.push_back(CV);
-CurPointers.push_back(CV);
+if (FirstPrivateDecls.count(VD) && ElementType->isAnyPointerType()) {
+  Address PtrAddr = CGF.EmitLoadOfReference(CGF.MakeAddrLValue(
+  CV, ElementType, CGF.getContext().getDeclAlign(VD),
+  AlignmentSource::Decl));
+  CurPointers.push_back(PtrAddr.getPointer());
+} else {
+  CurPointers.push_back(CV);
+}
   }
 }
 // Every default map produces a single argument which is a target 
parameter.

Modified: cfe/trunk/test/OpenMP/target_firstprivate_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_firstprivate_codegen.cpp?rev=357488&r1=357487&r2=357488&view=diff
==
--- cfe/trunk/test/OpenMP/target_firstprivate_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_firstprivate_codegen.cpp Tue Apr  2 09:03:40 
2019
@@ -53,8 +53,8 @@ struct TT {
 // TCHECK-DAG:  [[S1:%.+]] = type { double }
 
 // CHECK-DAG:  [[FP_E:@__omp_offloading_firstprivate_.+_e_l76]] = internal 
global [[TTII]] zeroinitializer
-// CHECK-DAG:  [[SIZET:@.+]] = private unnamed_addr constant [1 x i{{32|64}}] 
[i[[SZ:32|64]] 4]
-// CHECK-DAG:  [[MAPT:@.+]] = private unnamed_addr constant [1 x i64] [i64 800]
+// CHECK-DAG:  [[SIZET:@.+]] = private unnamed_addr constant [2 x i{{32|64}}] 
[i[[SZ:32|64]] 4, i{{64|32}} {{8|4}}]
+// CHECK-DAG:  [[MAPT:@.+]] = private unnamed_addr constant [2 x i64] [i64 
800, i64 561]
 // CHECK-DAG:  [[MAPT2:@.+]] = private unnamed_addr constant [9 x i64] [i64 
800, i64 673, i64 288, i64 673, i64 673, i64 288, i64 288, i64 673, i64 673]
 // CHECK-DAG:  [[SIZET3:@.+]] = private unnamed_addr constant [2 x i{{32|64}}] 
[i{{32|64}} 0, i{{32|64}} 8]
 // CHECK-DAG:  [[MAPT3:@.+]] = private unnamed_addr constant [2 x i64] [i64 
544, i64 549]
@@ -74,8 +74,9 @@ int foo(int n, double *ptr) {
   double cn[5][n];
   TT d;
   const TT e = {n, n};
+  int *p __attribute__ ((aligned (64))) = &a;
 
-#pragma omp target firstprivate(a)
+#pragma omp target firstprivate(a, p)
   {
   }
 
@@ -88,9 +89,10 @@ int foo(int n, double *ptr) {
   // CHECK:  [[SSTACK:%.+]] = alloca i8*,
   // CHECK:  [[C:%.+]] = alloca [5 x [10 x double]],
   // CHECK:  [[D:%.+]] = alloca [[TT]],
+  // CHECK:  [[P:%.+]] = alloca i32*, align 64
   // CHECK:  [[ACAST:%.+]] = alloca i{{[0-9]+}},
-  // CHECK:  [[BASE_PTR_ARR:%.+]] = alloca [1 x i8*],
-  // CHECK:  [[PTR_ARR:%.+]] = alloca [1 x i8*],
+  // CHECK:  [[BASE_PTR_ARR:%.+]] = alloca [2 x i8*],
+  // CHECK:  [[PTR_ARR:%.+]] = alloca [2 x i8*],
   // CHECK:  [[A2CAST:%.+]] = alloca i{{[0-9]+}},
   // CHECK:  [[BASE_PTR_ARR2:%.+]] = alloca [9 x i8*],
   // CHECK:  [[PTR_ARR2:%.+]] = alloca [9 x i8*],
@@ -113,20 +115,30 @@ int foo(int n, double *ptr) {
   // CHECK-64:  store i{{[0-9]+}} [[AVAL]], i{{[0-9]+}}* [[CONV]],
   // CHECK-32:  store i{{[0-9]+}} [[AVAL]], i{{[0-9]+}}* [[ACAST]],
   // CHECK:  [[ACAST_VAL:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[ACAST]],
-  // CHECK:  [[BASE_PTR_GEP:%.+]] = getelementptr inbounds [1 x i8*], [1 x 
i8*]* [[BASE_PTR_ARR]], i{{

[PATCH] D59376: [LibTooling] Add Transformer, a library for source-to-source transformations.

2019-04-02 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

I've removed the dependency on NodeIds given our (off thread) discussions 
regarding their overall value and appropriateness in clang::tooling vs 
clang::ast_matchers. PTAL.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59376



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


[PATCH] D59376: [LibTooling] Add Transformer, a library for source-to-source transformations.

2019-04-02 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 193306.
ymandel added a comment.

Remove dependency on NodeIds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59376

Files:
  clang/include/clang/Tooling/Refactoring/Transformer.h
  clang/lib/Tooling/Refactoring/CMakeLists.txt
  clang/lib/Tooling/Refactoring/Transformer.cpp
  clang/unittests/Tooling/CMakeLists.txt
  clang/unittests/Tooling/TransformerTest.cpp

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -0,0 +1,389 @@
+//===- unittest/Tooling/TransformerTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Refactoring/Transformer.h"
+
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace tooling {
+namespace {
+using ast_matchers::anyOf;
+using ast_matchers::argumentCountIs;
+using ast_matchers::callee;
+using ast_matchers::callExpr;
+using ast_matchers::cxxMemberCallExpr;
+using ast_matchers::cxxMethodDecl;
+using ast_matchers::cxxRecordDecl;
+using ast_matchers::declRefExpr;
+using ast_matchers::expr;
+using ast_matchers::functionDecl;
+using ast_matchers::hasAnyName;
+using ast_matchers::hasArgument;
+using ast_matchers::hasDeclaration;
+using ast_matchers::hasElse;
+using ast_matchers::hasName;
+using ast_matchers::hasType;
+using ast_matchers::ifStmt;
+using ast_matchers::member;
+using ast_matchers::memberExpr;
+using ast_matchers::namedDecl;
+using ast_matchers::on;
+using ast_matchers::pointsTo;
+using ast_matchers::to;
+using ast_matchers::unless;
+
+using llvm::StringRef;
+
+constexpr char KHeaderContents[] = R"cc(
+  struct string {
+string(const char*);
+char* c_str();
+int size();
+  };
+  int strlen(const char*);
+
+  namespace proto {
+  struct PCFProto {
+int foo();
+  };
+  struct ProtoCommandLineFlag : PCFProto {
+PCFProto& GetProto();
+  };
+  }  // namespace proto
+)cc";
+
+static ast_matchers::internal::Matcher
+isOrPointsTo(const clang::ast_matchers::DeclarationMatcher &TypeMatcher) {
+  return anyOf(hasDeclaration(TypeMatcher), pointsTo(TypeMatcher));
+}
+
+static std::string format(StringRef Code) {
+  const std::vector Ranges(1, Range(0, Code.size()));
+  auto Style = format::getLLVMStyle();
+  const auto Replacements = format::reformat(Style, Code, Ranges);
+  auto Formatted = applyAllReplacements(Code, Replacements);
+  if (!Formatted) {
+ADD_FAILURE() << "Could not format code: "
+  << llvm::toString(Formatted.takeError());
+return std::string();
+  }
+  return *Formatted;
+}
+
+static void compareSnippets(StringRef Expected,
+ const llvm::Optional &MaybeActual) {
+  ASSERT_TRUE(MaybeActual) << "Rewrite failed. Expecting: " << Expected;
+  auto Actual = *MaybeActual;
+  std::string HL = "#include \"header.h\"\n";
+  auto I = Actual.find(HL);
+  if (I != std::string::npos)
+Actual.erase(I, HL.size());
+  EXPECT_EQ(format(Expected), format(Actual));
+}
+
+// FIXME: consider separating this class into its own file(s).
+class ClangRefactoringTestBase : public testing::Test {
+protected:
+  void appendToHeader(StringRef S) { FileContents[0].second += S; }
+
+  void addFile(StringRef Filename, StringRef Content) {
+FileContents.emplace_back(Filename, Content);
+  }
+
+  llvm::Optional rewrite(StringRef Input) {
+std::string Code = ("#include \"header.h\"\n" + Input).str();
+auto Factory = newFrontendActionFactory(&MatchFinder);
+if (!runToolOnCodeWithArgs(
+Factory->create(), Code, std::vector(), "input.cc",
+"clang-tool", std::make_shared(),
+FileContents)) {
+  return None;
+}
+auto ChangedCodeOrErr =
+applyAtomicChanges("input.cc", Code, Changes, ApplyChangesSpec());
+if (auto Err = ChangedCodeOrErr.takeError()) {
+  llvm::errs() << "Change failed: " << llvm::toString(std::move(Err))
+   << "\n";
+  return None;
+}
+return *ChangedCodeOrErr;
+  }
+
+  void testRule(RewriteRule Rule, StringRef Input, StringRef Expected) {
+Transformer T(std::move(Rule),
+  [this](const AtomicChange &C) { Changes.push_back(C); });
+T.registerMatchers(&MatchFinder);
+compareSnippets(Expected, rewrite(Input));
+  }
+
+  clang::ast_matchers::MatchFinder MatchFinder;
+  AtomicChanges Changes;
+
+private:
+  FileContentMappings FileContents = {{"header.h", ""}};
+};
+
+class TransformerTest : public ClangRefactoringTestBase {
+pro

[PATCH] D59815: [Driver] Enable -fsanitize-address-globals-dead-stripping by default on PS4.

2019-04-02 Thread pierre gousseau via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC357480: [Driver] Enable 
-fsanitize-address-globals-dead-stripping by default on PS4. (authored by 
pgousseau, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D59815

Files:
  lib/Driver/SanitizerArgs.cpp
  test/Driver/fsanitize.c


Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -768,6 +768,7 @@
 // See https://sourceware.org/bugzilla/show_bug.cgi?id=19002
 AsanGlobalsDeadStripping =
 !TC.getTriple().isOSBinFormatELF() || TC.getTriple().isOSFuchsia() ||
+TC.getTriple().isPS4() ||
 Args.hasArg(options::OPT_fsanitize_address_globals_dead_stripping);
 
 AsanUseOdrIndicator =
Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -221,6 +221,7 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-NO-ASAN-GLOBALS
 // RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address 
-fsanitize-address-globals-dead-stripping -### -- %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-ASAN-GLOBALS
 // RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -### -- %s 
2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
+// RUN: %clang -target x86_64-scei-ps4  -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
 // CHECK-ASAN-GLOBALS: -cc1{{.*}}-fsanitize-address-globals-dead-stripping
 // CHECK-NO-ASAN-GLOBALS-NOT: 
-cc1{{.*}}-fsanitize-address-globals-dead-stripping
 


Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -768,6 +768,7 @@
 // See https://sourceware.org/bugzilla/show_bug.cgi?id=19002
 AsanGlobalsDeadStripping =
 !TC.getTriple().isOSBinFormatELF() || TC.getTriple().isOSFuchsia() ||
+TC.getTriple().isPS4() ||
 Args.hasArg(options::OPT_fsanitize_address_globals_dead_stripping);
 
 AsanUseOdrIndicator =
Index: test/Driver/fsanitize.c
===
--- test/Driver/fsanitize.c
+++ test/Driver/fsanitize.c
@@ -221,6 +221,7 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ASAN-GLOBALS
 // RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -fsanitize-address-globals-dead-stripping -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
 // RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -### -- %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
+// RUN: %clang -target x86_64-scei-ps4  -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
 // CHECK-ASAN-GLOBALS: -cc1{{.*}}-fsanitize-address-globals-dead-stripping
 // CHECK-NO-ASAN-GLOBALS-NOT: -cc1{{.*}}-fsanitize-address-globals-dead-stripping
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r357480 - [Driver] Enable -fsanitize-address-globals-dead-stripping by default on PS4.

2019-04-02 Thread Pierre Gousseau via cfe-commits
Author: pgousseau
Date: Tue Apr  2 08:20:26 2019
New Revision: 357480

URL: http://llvm.org/viewvc/llvm-project?rev=357480&view=rev
Log:
[Driver] Enable -fsanitize-address-globals-dead-stripping by default on PS4.

Can be safely enabled on PS4.

Reviewed By: probinson

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

Modified:
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=357480&r1=357479&r2=357480&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue Apr  2 08:20:26 2019
@@ -768,6 +768,7 @@ SanitizerArgs::SanitizerArgs(const ToolC
 // See https://sourceware.org/bugzilla/show_bug.cgi?id=19002
 AsanGlobalsDeadStripping =
 !TC.getTriple().isOSBinFormatELF() || TC.getTriple().isOSFuchsia() ||
+TC.getTriple().isPS4() ||
 Args.hasArg(options::OPT_fsanitize_address_globals_dead_stripping);
 
 AsanUseOdrIndicator =

Modified: cfe/trunk/test/Driver/fsanitize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=357480&r1=357479&r2=357480&view=diff
==
--- cfe/trunk/test/Driver/fsanitize.c (original)
+++ cfe/trunk/test/Driver/fsanitize.c Tue Apr  2 08:20:26 2019
@@ -221,6 +221,7 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-NO-ASAN-GLOBALS
 // RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address 
-fsanitize-address-globals-dead-stripping -### -- %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-ASAN-GLOBALS
 // RUN: %clang_cl --target=x86_64-windows-msvc -fsanitize=address -### -- %s 
2>&1 | FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
+// RUN: %clang -target x86_64-scei-ps4  -fsanitize=address %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-ASAN-GLOBALS
 // CHECK-ASAN-GLOBALS: -cc1{{.*}}-fsanitize-address-globals-dead-stripping
 // CHECK-NO-ASAN-GLOBALS-NOT: 
-cc1{{.*}}-fsanitize-address-globals-dead-stripping
 


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


[PATCH] D60120: check-clang-tools: Actually build and run XPC test

2019-04-02 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

(I noticed this while working on D60130 )


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

https://reviews.llvm.org/D60120



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


[PATCH] D60099: [CodeGen] Fix a regression by emitting lambda expressions in EmitLValue

2019-04-02 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

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

https://reviews.llvm.org/D60099



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


[PATCH] D60130: gn build: Add build files for clangd xpc framework code

2019-04-02 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added reviewers: mbonadei, sdefresne.
Herald added subscribers: jdoerfert, kadircet, arphaman, jkorous, MaskRay, 
ioeric, ilya-biryukov, mgorny.
Herald added a project: LLVM.
thakis edited the summary of this revision.

This is a bit of a larger change since this is the first (and as far as I can 
tell only) place where the LLVM build produces macOS framework bundles.

GN has some built-in support for this, so use that. `gn help create_bundle` has 
a terse description (but it's a bit outdated: `deps` must be `public_deps` and 
the conditionals in the example in the help aren't quite right on non-iOS).

We need a new 'copy_bundle_data' tool, and since we copy the clangd.xpc bundle 
as bundle_data into ClangdXPC.framework it needs to be able to handle 
directories in addition to files.

GN also insists we have a compile_xcassets tool even though it's not used. I 
just made that run `false`.

Despite GN's support for bundles, we still need to manually create the expected 
symlink structure in the .framework bundle. Since this code never runs on 
Windows, it's safe to create the symlinks before the symlink targets exist, so 
we can just make the bundle depend on the steps that create the symlinks. For 
this to work, change the symlink script to create the symlink's containing 
directory if it doesn't yet exist.

I locally verified that CMake and GN build create the same bundle structure. (I 
noticed that both builds set LC_ID_DYLIB to the pre-copy libClangdXPCLib.dylib 
name, but that seems to not cause any issues and it happens in the CMake build 
too.)

(Also add an error message to clangd-xpc-test-client for when loading the dylib 
fails – this was useful while locally debugging this.)


https://reviews.llvm.org/D60130

Files:
  clang-tools-extra/clangd/xpc/framework/CMakeLists.txt
  clang-tools-extra/clangd/xpc/test-client/ClangdXPCTestClient.cpp
  llvm/utils/gn/build/symlink_or_copy.py
  llvm/utils/gn/build/toolchain/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/framework/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/test-client/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/test/BUILD.gn
@@ -1,3 +1,4 @@
+import("//clang-tools-extra/clangd/xpc/enable.gni")
 import("//clang/lib/StaticAnalyzer/Frontend/enable.gni")
 import("//llvm/triples.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
@@ -35,9 +36,14 @@
 "LLVM_LIT_TOOLS_DIR=",  # Intentionally empty, matches cmake build.
 "LLVM_TOOLS_DIR=" + rebase_path("$root_out_dir/bin"),
 "PYTHON_EXECUTABLE=$python_path",
-"CLANGD_BUILD_XPC_SUPPORT=0",  # FIXME
   ]
 
+  if (clangd_build_xpc) {
+extra_values += [ "CLANGD_BUILD_XPC_SUPPORT=1" ]
+  } else {
+extra_values += [ "CLANGD_BUILD_XPC_SUPPORT=0" ]
+  }
+
   if (clang_enable_static_analyzer) {
 extra_values += [ "CLANG_ENABLE_STATIC_ANALYZER=1" ]
   } else {
@@ -83,6 +89,10 @@
 "//llvm/utils/llvm-lit",
 "//llvm/utils/not",
   ]
+  if (clangd_build_xpc) {
+deps +=
+[ "//clang-tools-extra/clangd/xpc/test-client:clangd-xpc-test-client" ]
+  }
 
   # FIXME: dep on dexp once it exist
   testonly = true
Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/test-client/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/test-client/BUILD.gn
@@ -0,0 +1,20 @@
+executable("clangd-xpc-test-client") {
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang-tools-extra/clangd",
+"//clang-tools-extra/clangd/xpc:conversions",
+"//clang-tools-extra/clangd/xpc/framework:ClangdXPC.framework",
+"//clang/lib/Basic",
+"//clang/lib/Format",
+"//clang/lib/Frontend",
+"//clang/lib/Sema",
+"//clang/lib/Tooling",
+"//clang/lib/Tooling/Core",
+"//llvm/lib/Support",
+  ]
+
+  include_dirs = [ "../.." ]
+  sources = [
+"ClangdXPCTestClient.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/framework/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/framework/BUILD.gn
@@ -0,0 +1,154 @@
+import("//llvm/utils/gn/build/symlink_or_copy.gni")
+import("//llvm/utils/gn/build/write_cmake_config.gni")
+
+# create_clangd_xpc_framework() in cmake creates both the ClangdXPC.framework
+# bundle and the clangd.xpc bundle within it in a single action.
+# Since GN has some native support for macOS bundles, it's more natural
+# to have one create_bundle() each for both ClangdXPC.framework and clangd.xpc.
+# See `llvm/utils/gn/gn.py help create_bundle` and ../cmake/modules.
+
+#

[PATCH] D60123: [AST] Forbid copy/move of statements/types.

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

LGTM


Repository:
  rC Clang

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

https://reviews.llvm.org/D60123



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


[PATCH] D60101: [Sema] Fix a use-after-deallocate of a ParsedAttr

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

LGTM aside from some minor nits. Thanks for this!




Comment at: clang/include/clang/Sema/ParsedAttr.h:896
 
+  void takeOneFrom(ParsedAttributes &attrs, ParsedAttr *attr) {
+attrs.getPool().remove(attr);

How about `Attrs` and `PA` to fit with usual naming conventions?



Comment at: clang/test/SemaObjC/arc-property-decl-attrs.m:291
+
+id i1, __weak i2, i3;

Can you add a comment here that explains what this test is intending to cover?


Repository:
  rC Clang

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

https://reviews.llvm.org/D60101



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


[PATCH] D60124: gn build: Add build files for non-framework xpc clangd bits

2019-04-02 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL357476: gn build: Add build files for non-framework xpc 
clangd bits (authored by nico, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60124?vs=193264&id=193290#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60124

Files:
  llvm/trunk/utils/gn/build/sync_source_lists_from_cmake.py
  llvm/trunk/utils/gn/secondary/clang-tools-extra/clangd/tool/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang-tools-extra/clangd/xpc/enable.gni
  llvm/trunk/utils/gn/secondary/clang-tools-extra/unittests/BUILD.gn
  llvm/trunk/utils/gn/secondary/clang-tools-extra/unittests/clangd/xpc/BUILD.gn

Index: llvm/trunk/utils/gn/secondary/clang-tools-extra/clangd/tool/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang-tools-extra/clangd/tool/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang-tools-extra/clangd/tool/BUILD.gn
@@ -1,10 +1,6 @@
+import("//clang-tools-extra/clangd/xpc/enable.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
 
-declare_args() {
-  # Whether to build clangd's XPC components.
-  clangd_build_xpc = false
-}
-
 write_cmake_config("features") {
   # FIXME: Try moving Features.inc.in to tools, seems like a better location.
   input = "../Features.inc.in"
@@ -33,6 +29,12 @@
 "//clang/lib/Tooling/Core",
 "//llvm/lib/Support",
   ]
+  if (clangd_build_xpc) {
+deps += [
+  "//clang-tools-extra/clangd/xpc:conversions",
+  "//clang-tools-extra/clangd/xpc:transport",
+]
+  }
 
   include_dirs = [
 "..",
@@ -43,8 +45,4 @@
   sources = [
 "ClangdMain.cpp",
   ]
-
-  if (clangd_build_xpc) {
-# FIXME: Depend on clangdXpcJsonConversions, clangdXpcTransport
-  }
 }
Index: llvm/trunk/utils/gn/secondary/clang-tools-extra/clangd/xpc/enable.gni
===
--- llvm/trunk/utils/gn/secondary/clang-tools-extra/clangd/xpc/enable.gni
+++ llvm/trunk/utils/gn/secondary/clang-tools-extra/clangd/xpc/enable.gni
@@ -0,0 +1,4 @@
+declare_args() {
+  # Whether to build clangd's XPC components.
+  clangd_build_xpc = current_os == "mac"
+}
Index: llvm/trunk/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn
@@ -0,0 +1,26 @@
+static_library("conversions") {
+  output_name = "clangdXpcJsonConversions"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang-tools-extra/clangd",
+"//llvm/lib/Support",
+  ]
+  include_dirs = [ ".." ]
+  sources = [
+"Conversion.cpp",
+  ]
+}
+
+static_library("transport") {
+  output_name = "clangdXpcTransport"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+":conversions",
+"//clang-tools-extra/clangd",
+"//llvm/lib/Support",
+  ]
+  include_dirs = [ ".." ]
+  sources = [
+"XPCTransport.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/clang-tools-extra/unittests/clangd/xpc/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang-tools-extra/unittests/clangd/xpc/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang-tools-extra/unittests/clangd/xpc/BUILD.gn
@@ -0,0 +1,15 @@
+import("//llvm/utils/unittest/unittest.gni")
+
+unittest("ClangdXpcTests") {
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang-tools-extra/clangd",
+"//clang-tools-extra/clangd/xpc:conversions",
+"//llvm/lib/Support",
+"//llvm/lib/Testing/Support",
+  ]
+  include_dirs = [ "//clang-tools-extra/clangd" ]
+  sources = [
+"ConversionTests.cpp",
+  ]
+}
Index: llvm/trunk/utils/gn/secondary/clang-tools-extra/unittests/BUILD.gn
===
--- llvm/trunk/utils/gn/secondary/clang-tools-extra/unittests/BUILD.gn
+++ llvm/trunk/utils/gn/secondary/clang-tools-extra/unittests/BUILD.gn
@@ -1,3 +1,5 @@
+import("//clang-tools-extra/clangd/xpc/enable.gni")
+
 group("unittests") {
   deps = [
 "clang-apply-replacements:ClangApplyReplacementsTests",
@@ -10,6 +12,8 @@
 "clang-tidy:ClangTidyTests",
 "clangd:ClangdTests",
   ]
-  # FIXME: dep on clangd/xpc:ClangdXpcTests once it exists
+  if (clangd_build_xpc) {
+deps += [ "clangd/xpc:ClangdXpcTests" ]
+  }
   testonly = true
 }
Index: llvm/trunk/utils/gn/build/sync_source_lists_from_cmake.py
===
--- llvm/trunk/utils/gn/build/sync_source_lists_from_cmake.py
+++ llvm/trunk/utils/gn/build/sync_source_lists_from_cmake.py
@@ -61,8 +61,7 @@
 # Matches e.g. |add_llvm_unittest_with_input_files|.

[PATCH] D60124: gn build: Add build files for non-framework xpc clangd bits

2019-04-02 Thread Nico Weber via Phabricator via cfe-commits
thakis marked 2 inline comments as done.
thakis added inline comments.



Comment at: llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn:17
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang-tools-extra/clangd",

mbonadei wrote:
> Missing ":conversions" in deps.
Thanks! Done.



Comment at: llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/enable.gni:3
+  # Whether to build clangd's XPC components.
+  clangd_build_xpc = current_os == "mac"
+}

mbonadei wrote:
> Is it ok to keep this ` = current_os == "mac"`, from the CL description I had 
> the feeling that xpc tests were still disabled.
Yes, because clang-tools/extra/test/BUILD.gn still has 
`CLANGD_BUILD_XPC_SUPPORT=0`, so lit thinks xpc support isn't available and 
doesn't run the xpc lit tests. And the xpc unit tests pass, so they run after 
this change.


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

https://reviews.llvm.org/D60124



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


[PATCH] D60029: Add const children() accessors to all AST nodes.

2019-04-02 Thread Nicolas Manichon via Phabricator via cfe-commits
nicolas updated this revision to Diff 193288.
nicolas retitled this revision from "Add const children() accessors to Stmts" 
to "Add const children() accessors to all AST nodes.".
nicolas edited the summary of this revision.
nicolas added a comment.

Added children() const to all AST nodes.


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

https://reviews.llvm.org/D60029

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/ExprObjC.h
  clang/include/clang/AST/ExprOpenMP.h
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/StmtCXX.h
  clang/include/clang/AST/StmtObjC.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/ExprObjC.cpp
  clang/lib/AST/Stmt.cpp

Index: clang/lib/AST/Stmt.cpp
===
--- clang/lib/AST/Stmt.cpp
+++ clang/lib/AST/Stmt.cpp
@@ -1254,6 +1254,10 @@
   return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
 }
 
+Stmt::const_child_range CapturedStmt::children() const {
+  return const_child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
+}
+
 CapturedDecl *CapturedStmt::getCapturedDecl() {
   return CapDeclAndKind.getPointer();
 }
Index: clang/lib/AST/ExprObjC.cpp
===
--- clang/lib/AST/ExprObjC.cpp
+++ clang/lib/AST/ExprObjC.cpp
@@ -377,6 +377,11 @@
  reinterpret_cast(getArgs() + getNumArgs()));
 }
 
+Stmt::const_child_range ObjCMessageExpr::children() const {
+  auto Children = const_cast(this)->children();
+  return const_child_range(Children.begin(), Children.end());
+}
+
 StringRef ObjCBridgedCastExpr::getBridgeKindName() const {
   switch (getBridgeKind()) {
   case OBC_Bridge:
Index: clang/include/clang/AST/StmtOpenMP.h
===
--- clang/include/clang/AST/StmtOpenMP.h
+++ clang/include/clang/AST/StmtOpenMP.h
@@ -256,6 +256,14 @@
 return child_range(ChildStorage, ChildStorage + 1);
   }
 
+  const_child_range children() const {
+if (!hasAssociatedStmt())
+  return const_child_range(const_child_iterator(), const_child_iterator());
+Stmt **ChildStorage = reinterpret_cast(
+const_cast(this)->getClauses().end());
+return const_child_range(ChildStorage, ChildStorage + 1);
+  }
+
   ArrayRef clauses() { return getClauses(); }
 
   ArrayRef clauses() const {
Index: clang/include/clang/AST/StmtObjC.h
===
--- clang/include/clang/AST/StmtObjC.h
+++ clang/include/clang/AST/StmtObjC.h
@@ -67,6 +67,10 @@
   child_range children() {
 return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
   }
+
+  const_child_range children() const {
+return const_child_range(&SubExprs[0], &SubExprs[END_EXPR]);
+  }
 };
 
 /// Represents Objective-C's \@catch statement.
@@ -113,6 +117,10 @@
   }
 
   child_range children() { return child_range(&Body, &Body + 1); }
+
+  const_child_range children() const {
+return const_child_range(&Body, &Body + 1);
+  }
 };
 
 /// Represents Objective-C's \@finally statement
@@ -147,6 +155,10 @@
   child_range children() {
 return child_range(&AtFinallyStmt, &AtFinallyStmt+1);
   }
+
+  const_child_range children() const {
+return const_child_range(&AtFinallyStmt, &AtFinallyStmt + 1);
+  }
 };
 
 /// Represents Objective-C's \@try ... \@catch ... \@finally statement.
@@ -248,6 +260,10 @@
 return child_range(getStmts(),
getStmts() + 1 + NumCatchStmts + HasFinally);
   }
+
+  const_child_range children() const {
+return const_child_range(const_cast(this)->children());
+  }
 };
 
 /// Represents Objective-C's \@synchronized statement.
@@ -306,6 +322,10 @@
   child_range children() {
 return child_range(&SubStmts[0], &SubStmts[0]+END_EXPR);
   }
+
+  const_child_range children() const {
+return const_child_range(&SubStmts[0], &SubStmts[0] + END_EXPR);
+  }
 };
 
 /// Represents Objective-C's \@throw statement.
@@ -338,6 +358,10 @@
   }
 
   child_range children() { return child_range(&Throw, &Throw+1); }
+
+  const_child_range children() const {
+return const_child_range(&Throw, &Throw + 1);
+  }
 };
 
 /// Represents Objective-C's \@autoreleasepool Statement
@@ -369,6 +393,10 @@
   }
 
   child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
+
+  const_child_range children() const {
+return const_child_range(&SubStmt, &SubStmt + 1);
+  }
 };
 
 }  // end namespace clang
Index: clang/include/clang/AST/StmtCXX.h
===
--- clang/include/clang/AST/StmtCXX.h
+++ clang/include/clang/AST/StmtCXX.h
@@ -56,6 +56,10 @@
 
   child_range children() { return child_range(&HandlerBlock, &HandlerBlock+1); }
 
+  const_child_range children() const {
+return const_child_range(&HandlerBlock, &HandlerBlock + 1);
+  }
+

[PATCH] D60128: Add const children accessors to all nodes.

2019-04-02 Thread Nicolas Manichon via Phabricator via cfe-commits
nicolas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add const children accessors to all AST nodes where non const accessors
exist.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60128

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/ExprObjC.h
  clang/include/clang/AST/ExprOpenMP.h
  clang/include/clang/AST/OpenMPClause.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/StmtCXX.h
  clang/include/clang/AST/StmtObjC.h
  clang/include/clang/AST/StmtOpenMP.h
  clang/lib/AST/ExprObjC.cpp
  clang/lib/AST/Stmt.cpp

Index: clang/lib/AST/Stmt.cpp
===
--- clang/lib/AST/Stmt.cpp
+++ clang/lib/AST/Stmt.cpp
@@ -1254,6 +1254,10 @@
   return child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
 }
 
+Stmt::const_child_range CapturedStmt::children() const {
+  return const_child_range(getStoredStmts(), getStoredStmts() + NumCaptures);
+}
+
 CapturedDecl *CapturedStmt::getCapturedDecl() {
   return CapDeclAndKind.getPointer();
 }
Index: clang/lib/AST/ExprObjC.cpp
===
--- clang/lib/AST/ExprObjC.cpp
+++ clang/lib/AST/ExprObjC.cpp
@@ -377,6 +377,11 @@
  reinterpret_cast(getArgs() + getNumArgs()));
 }
 
+Stmt::const_child_range ObjCMessageExpr::children() const {
+  auto Children = const_cast(this)->children();
+  return const_child_range(Children.begin(), Children.end());
+}
+
 StringRef ObjCBridgedCastExpr::getBridgeKindName() const {
   switch (getBridgeKind()) {
   case OBC_Bridge:
Index: clang/include/clang/AST/StmtOpenMP.h
===
--- clang/include/clang/AST/StmtOpenMP.h
+++ clang/include/clang/AST/StmtOpenMP.h
@@ -256,6 +256,14 @@
 return child_range(ChildStorage, ChildStorage + 1);
   }
 
+  const_child_range children() const {
+if (!hasAssociatedStmt())
+  return const_child_range(const_child_iterator(), const_child_iterator());
+Stmt **ChildStorage = reinterpret_cast(
+const_cast(this)->getClauses().end());
+return const_child_range(ChildStorage, ChildStorage + 1);
+  }
+
   ArrayRef clauses() { return getClauses(); }
 
   ArrayRef clauses() const {
Index: clang/include/clang/AST/StmtObjC.h
===
--- clang/include/clang/AST/StmtObjC.h
+++ clang/include/clang/AST/StmtObjC.h
@@ -67,6 +67,10 @@
   child_range children() {
 return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
   }
+
+  const_child_range children() const {
+return const_child_range(&SubExprs[0], &SubExprs[END_EXPR]);
+  }
 };
 
 /// Represents Objective-C's \@catch statement.
@@ -113,6 +117,10 @@
   }
 
   child_range children() { return child_range(&Body, &Body + 1); }
+
+  const_child_range children() const {
+return const_child_range(&Body, &Body + 1);
+  }
 };
 
 /// Represents Objective-C's \@finally statement
@@ -147,6 +155,10 @@
   child_range children() {
 return child_range(&AtFinallyStmt, &AtFinallyStmt+1);
   }
+
+  const_child_range children() const {
+return const_child_range(&AtFinallyStmt, &AtFinallyStmt + 1);
+  }
 };
 
 /// Represents Objective-C's \@try ... \@catch ... \@finally statement.
@@ -248,6 +260,10 @@
 return child_range(getStmts(),
getStmts() + 1 + NumCatchStmts + HasFinally);
   }
+
+  const_child_range children() const {
+return const_child_range(const_cast(this)->children());
+  }
 };
 
 /// Represents Objective-C's \@synchronized statement.
@@ -306,6 +322,10 @@
   child_range children() {
 return child_range(&SubStmts[0], &SubStmts[0]+END_EXPR);
   }
+
+  const_child_range children() const {
+return const_child_range(&SubStmts[0], &SubStmts[0] + END_EXPR);
+  }
 };
 
 /// Represents Objective-C's \@throw statement.
@@ -338,6 +358,10 @@
   }
 
   child_range children() { return child_range(&Throw, &Throw+1); }
+
+  const_child_range children() const {
+return const_child_range(&Throw, &Throw + 1);
+  }
 };
 
 /// Represents Objective-C's \@autoreleasepool Statement
@@ -369,6 +393,10 @@
   }
 
   child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
+
+  const_child_range children() const {
+return const_child_range(&SubStmt, &SubStmt + 1);
+  }
 };
 
 }  // end namespace clang
Index: clang/include/clang/AST/StmtCXX.h
===
--- clang/include/clang/AST/StmtCXX.h
+++ clang/include/clang/AST/StmtCXX.h
@@ -56,6 +56,10 @@
 
   child_range children() { return child_range(&HandlerBlock, &HandlerBlock+1); }
 
+  const_child_range children() const {
+return const_child_range(&HandlerBlock, &HandlerBlock + 1);
+  }
+
   friend class ASTStmtReader;
 };
 
@@ -114,6 +118,10 @@
   child_range children() {
 return child_range(getStmts(), getStmts() + ge

[PATCH] D59467: [clang] Adding the Likelihood Attribute from C++2a

2019-04-02 Thread Gauthier via Phabricator via cfe-commits
Tyker updated this revision to Diff 193284.

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

https://reviews.llvm.org/D59467

Files:
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/StmtCXX.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Scope.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Stmt.cpp
  clang/lib/AST/StmtCXX.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Analysis/CFG.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/Scope.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/CodeGenCXX/cxx2a-likelihood-attr.cpp
  clang/test/PCH/cxx2a-likelihood-attr.cpp
  clang/test/SemaCXX/cxx17-compat.cpp
  clang/test/SemaCXX/cxx2a-likelihood-attr.cpp

Index: clang/test/SemaCXX/cxx2a-likelihood-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-likelihood-attr.cpp
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify -std=c++2a
+
+// formating this file will break the test
+// clang-format off
+
+int f(int i) {
+  if (i == 1)
+[[unlikely]] { f(i); }
+  else if (i == 2)
+[[likely]] return f(i);
+  else
+[[unlikely]] { return f(i + 1); }
+  return i;
+}
+
+[[likely]] typedef int n1;
+// expected-error@-1 {{'likely' attribute cannot be applied to a declaration}}
+typedef int [[likely]] n2;
+// expected-error@-1 {{'likely' attribute cannot be applied to types}}
+typedef int n3 [[likely]];
+// expected-error@-1 {{'likely' attribute cannot be applied to a declaration}}
+
+enum [[likely]] E{One};
+// expected-error@-1 {{'likely' attribute cannot be applied to a declaration}}
+
+[[likely]]
+// expected-error@-1 {{'likely' attribute cannot be applied to a declaration}}
+
+void test(int i) {
+  [[likely]]
+  // expected-warning@-1 {{attribute 'likely' is not associated with a branch and is ignored}}
+  if (f(i)) [[likely, likely]] {
+// expected-error@-1 {{likely attribute cannot be repeated}}
+// expected-note@-2 {{previous attribute is here}}
+[[unlikely]] return;
+// expected-warning@-1 {{attribute 'unlikely' is not associated with a branch and is ignored}}
+  }
+  else [[unlikely]] if (f(i)) {
+while (f(i))
+  [[likely]] {
+switch (i) {
+  [[likely]] case 1 : default : [[likely]];
+  // expected-warning@-1 {{attribute 'likely' is not associated with a branch and is ignored}}
+  [[unlikely]] case 3 : f(i);
+  [[fallthrough]];
+case 4:
+  return;
+}
+  }
+for (;;)
+  [[likely, unlikely]]
+  // expected-error@-1 {{unlikely and likely attributes are not compatible}}
+  // expected-note@-2 {{previous attribute is here}}
+  [[likely]] return;
+// expected-error@-1 {{likely attribute cannot be repeated}}
+// expected-note@-5 {{previous attribute is here}}
+  }
+  try { // expected-error {{cannot use 'try' with exceptions disabled}}
+[[likely]];
+// expected-warning@-1 {{attribute 'likely' is not associated with a branch and is ignored}}
+  } catch (int) {
+[[likely]] test :
+// expected-error@-1 {{'likely' attribute cannot be applied to a declaration}}
+[[unlikely]] return;
+  }
+}
Index: clang/test/SemaCXX/cxx17-compat.cpp
===
--- clang/test/SemaCXX/cxx17-compat.cpp
+++ clang/test/SemaCXX/cxx17-compat.cpp
@@ -63,3 +63,23 @@
 // expected-warning@-4 {{range-based for loop initialization statements are incompatible with C++ standards before C++2a}}
 #endif
 }
+
+//clang-format off
+
+int f(int i) {
+  if (i == 1)
+[[unlikely]]
+#if __cplusplus <= 201703L
+// expected-warning@-2 {{use of the 'unlikely' attribute is a C++2a extension}}
+#endif
+{
+  f(i);
+}
+  else if (i == 2)
+[[likely]]
+#if __cplusplus <= 201703L
+// expected-warning@-2 {{use of the 'likely' attribute is a C++2a extension}}
+#endif
+return f(i);
+  return i;
+}
Index: clang/test/PCH/cxx2a-likelihood-attr.cpp
===
--- /dev/null
+++ clang/test/PCH/cxx2a-likelihood-attr.cpp
@@ -0,0 +1,57 @@
+// Test this without pch.
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -verify %s -ast-dump | FileCheck %s
+
+// Test with pch. Use '-ast-dump' to force deserialization of function bodies.
+// RUN: %clang_cc1 -x c++-header -std=c++2a -emit-pch -o %t %s
+// RUN: %clang_cc1 -std=c++2a -include-pch %t -fsyntax-only -verify %s
+// -ast-dump-all | FileCheck %s
+
+// expected-no-diagnost

[PATCH] D60124: gn build: Add build files for non-framework xpc clangd bits

2019-04-02 Thread Mirko Bonadei via Phabricator via cfe-commits
mbonadei accepted this revision.
mbonadei added a comment.
This revision is now accepted and ready to land.

LGTM, just a couple of comments.




Comment at: llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn:17
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang-tools-extra/clangd",

Missing ":conversions" in deps.



Comment at: llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/enable.gni:3
+  # Whether to build clangd's XPC components.
+  clangd_build_xpc = current_os == "mac"
+}

Is it ok to keep this ` = current_os == "mac"`, from the CL description I had 
the feeling that xpc tests were still disabled.


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

https://reviews.llvm.org/D60124



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


[PATCH] D59988: [PR41276] Generate address space cast of 'this' for objects attributed by an address space in C++

2019-04-02 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 193281.
Anastasia added a comment.

- Use `AggValueSlot` in the constructor call generation to store/retrieve 
address space of 'this'.
- Fixed detecting the address space conversion while performing qualification 
conversion.


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

https://reviews.llvm.org/D59988

Files:
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Sema/SemaInit.cpp
  test/CodeGenCXX/address-space-of-this.cpp

Index: test/CodeGenCXX/address-space-of-this.cpp
===
--- /dev/null
+++ test/CodeGenCXX/address-space-of-this.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -std=c++14 -triple=spir -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 %s -std=c++17 -triple=spir -emit-llvm -o - | FileCheck %s
+
+struct MyType {
+  MyType(int i) : i(i) {}
+  int i;
+};
+//CHECK: call void @_ZN6MyTypeC1Ei(%struct.MyType* addrspacecast (%struct.MyType addrspace(10)* @m to %struct.MyType*), i32 123)
+MyType __attribute__((address_space(10))) m = 123;
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -7321,9 +7321,19 @@
 ExprResult Sema::PerformQualificationConversion(Expr *E, QualType Ty,
 ExprValueKind VK,
 CheckedConversionKind CCK) {
-  CastKind CK = (Ty.getAddressSpace() != E->getType().getAddressSpace())
-? CK_AddressSpaceConversion
-: CK_NoOp;
+
+  CastKind CK = CK_NoOp;
+
+  if (VK == VK_RValue) {
+auto PointeeTy = Ty->getPointeeType();
+auto ExprPointeeTy = E->getType()->getPointeeType();
+if (!PointeeTy.isNull() &&
+PointeeTy.getAddressSpace() != ExprPointeeTy.getAddressSpace())
+  CK = CK_AddressSpaceConversion;
+  } else if (Ty.getAddressSpace() != E->getType().getAddressSpace()) {
+CK = CK_AddressSpaceConversion;
+  }
+
   return ImpCastExprToType(E, Ty, CK, VK, /*BasePath=*/nullptr, CCK);
 }
 
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -2503,16 +2503,13 @@
 
   void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type,
   bool ForVirtualBase, bool Delegating,
-  Address This, const CXXConstructExpr *E,
-  AggValueSlot::Overlap_t Overlap,
-  bool NewPointerIsChecked);
+  AggValueSlot ThisAVS, const CXXConstructExpr *E);
 
   void EmitCXXConstructorCall(const CXXConstructorDecl *D, CXXCtorType Type,
   bool ForVirtualBase, bool Delegating,
   Address This, CallArgList &Args,
   AggValueSlot::Overlap_t Overlap,
-  SourceLocation Loc,
-  bool NewPointerIsChecked);
+  SourceLocation Loc, bool NewPointerIsChecked);
 
   /// Emit assumption load for all bases. Requires to be be called only on
   /// most-derived class and not under construction of the object.
Index: lib/CodeGen/CGExprCXX.cpp
===
--- lib/CodeGen/CGExprCXX.cpp
+++ lib/CodeGen/CGExprCXX.cpp
@@ -617,12 +617,10 @@
 
  case CXXConstructExpr::CK_NonVirtualBase:
   Type = Ctor_Base;
-}
+ }
 
-// Call the constructor.
-EmitCXXConstructorCall(CD, Type, ForVirtualBase, Delegating,
-   Dest.getAddress(), E, Dest.mayOverlap(),
-   Dest.isSanitizerChecked());
+ // Call the constructor.
+ EmitCXXConstructorCall(CD, Type, ForVirtualBase, Delegating, Dest, E);
   }
 }
 
Index: lib/CodeGen/CGClass.cpp
===
--- lib/CodeGen/CGClass.cpp
+++ lib/CodeGen/CGClass.cpp
@@ -1970,10 +1970,14 @@
   pushRegularPartialArrayCleanup(arrayBegin, cur, type, eltAlignment,
  *destroyer);
 }
-
+auto currAVS = AggValueSlot::forAddr(
+curAddr, type.getQualifiers(), AggValueSlot::IsDestructed,
+AggValueSlot::DoesNotNeedGCBarriers, AggValueSlot::IsNotAliased,
+AggValueSlot::DoesNotOverlap, AggValueSlot::IsNotZeroed,
+NewPointerIsChecked ? AggValueSlot::IsSanitizerChecked
+: AggValueSlot::IsNotSanitizerChecked);
 EmitCXXConstructorCall(ctor, Ctor_Complete, /*ForVirtualBase=*/false,
-   /*Delegating=*/false, curAddr, E,
-   AggValueSlot::DoesNotOverlap, NewPointerIsChecked);
+   /*Delegating=*/false, currAVS, E);
   }
 
   // Go to

[PATCH] D59887: [Syntax] Introduce TokenBuffer, start clangToolingSyntax library

2019-04-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Not sure what the implications of design changes are, so will defer reviewing 
details of tokencollector (which generally looks good, but is of course highly 
coupled to lexer/pp) and range mapping (which I suspect could be simplified, 
but depends heavily on the model).




Comment at: clang/lib/Tooling/Syntax/TokenBuffer.cpp:61
+
+class TokenCollector::Callbacks : public PPCallbacks {
+public:

I'm afraid this really needs a class comment describing what this is supposed 
to do (easy!) and the implementation strategy (hard!)

In particular, it looks like macros like this:
 - we expect to see the tokens making up the macro invocation first (... FOO ( 
42 ))
 - then we see MacroExpands which allows us to recognize the last N tokens are 
a macro invocation. We create a MacroInvocation object, and remember where the 
invocation ends
 - then we see the tokens making up the macro expansion
 - finally, once we see the next token after the invocation, we finalize the 
MacroInvocation.



Comment at: clang/lib/Tooling/Syntax/TokenBuffer.cpp:285
+std::tie(File, Offset) = SM.getDecomposedLoc(L);
+if (File != MacroInvocationFile || Offset <= ExpansionEndOffset)
+  return;

is there a problem if we never see another token in that file after the 
expansion?
(or do we see the eof token in this case?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59887



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


[PATCH] D59870: [clang-tidy] Add MagnitudeBitsUpperLimit option to bugprone-too-small-loop-variable

2019-04-02 Thread Tamás Zolnai via Phabricator via cfe-commits
ztamas marked 3 inline comments as done.
ztamas added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone-too-small-loop-variable.rst:33
+
+  Upper limit for the magnitue bits of the loop variable. If it's set the check
+  filters out those catches in which the loop variable's type has more 
magnitude

JonasToth wrote:
> typo `magnitude`
> 
> The commit you reference to the project fixing the "bugs" stated, that the 
> version without conversions is more efficient (by one instruction :)). I 
> think this might be worth a note, that even though the
> code is not a bug in itself it might still be preferable to remove those code 
> locations in the long run.
Typo is fixed

The referenced commit message mentions 32 bit system, where changing integer 
types was a bit faster. I'm not sure how general this is. I'm not familiar with 
the low level implementation of integer comparison, so I would not mention 
something, that I don't actually understand how it works.


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

https://reviews.llvm.org/D59870



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


[PATCH] D59811: [clangd] Add fallback mode for code completion when compile command or preamble is not ready.

2019-04-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Leaving a few first comments, have to run.
Will take another look later, sorry about the delay today (also feel free to 
add more reviewers in case this is urgent).




Comment at: clangd/ClangdServer.cpp:197
   return CB(llvm::make_error());
+if (!IP->Preamble) {
+  vlog("File {0} is not ready for code completion. Enter fallback mode.",

ioeric wrote:
> ilya-biryukov wrote:
> > This way we don't distinguish between the failure to build a preamble and 
> > the fallback mode.
> > Have you considered introducing a different callback instead to clearly 
> > separate two cases for the clients?
> > The code handling those would hardly have any similarities anyway, given 
> > that the nature of those two cases is so different.
> > 
> > Would look something like this:
> > ```
> > /// When \p FallbackAction is not null, it would be called instead of \p 
> > Action in cases when preamble is 
> > /// not yet ready.
> > void runWithPreamble(… Callback Action, Callback 
> > FallbackAction);
> > ```
> > void runWithPreamble(… Callback Action, Callback 
> > FallbackAction);
> This is what I started with in the first iteration. The main problem is that 
> we would need to bind `CB` to both actions; however, `CB` is not 
> copyable/shareable by design, I think. This seems to leave us with the only 
> option to handle everything in the same action. I thought this was fine 
> because an parameter `AllowFallback` seems to be clear as well. I'm open to 
> suggestions ;)
> 
> > This way we don't distinguish between the failure to build a preamble and 
> > the fallback mode.
> I am assuming that a fallback for `runWithPreamble` is either compile command 
> is missing/broken or preamble fails to be built. And in both cases, fallback 
> mode could be useful. Do you think we should have more distinctions made here?
Ah, right, I did not realize that design of `Callback` makes it hard for two 
callbacks to own the same data.
And that's what we technically need for this. I'll have to think about this 
two, maybe there's a better way to express this in the code (`AllowFallback` 
looks like the option with least amount of friction so far).



Comment at: clangd/TUScheduler.cpp:186
 
   std::shared_ptr getPossiblyStalePreamble() const;
+

ioeric wrote:
> ilya-biryukov wrote:
> > Could we put the preamble and compile command into a single function?
> > Getting them in the lock-step would mean they're always consistent, which 
> > is a good thing.
> Could you elaborate the advantages of keeping them consistent?
> 
> They seem to be updated and used relatively independently. Grouping them into 
> one function seems to add more work to the call sites.  And it seems 
> inevitable that we would some inconsistency between the two.
I was originally thinking about consistency between the provided compile 
command and the one used to build the preamble.
Now I realize that they are set at different times, so we can't really make 
them consistent (unless we decide to delay the update of the compile command, 
but I don't see why it's useful).

You approach looks legit, but could you please document in these getters (maybe 
more importantly in the public callback interfaces?) that preamble and compile 
commands might be out of sync (command can be newer) and clients should handle 
that gracefully.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D59811



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


[PATCH] D60126: [clangd] Use identifiers in file as completion candidates when build is not ready.

2019-04-02 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: sammccall.
Herald added subscribers: cfe-commits, jdoerfert, kadircet, arphaman, jkorous, 
MaskRay, ilya-biryukov.
Herald added a project: clang.

o Lex the code to get the identifiers and put them into a "symbol" index.
o Adds a new completion mode without compilation/sema into code completion 
workflow.
o Make IncludeInserter work even when no compile command is present, by avoiding
inserting non-verbatim headers.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D60126

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdUnit.cpp
  clangd/CodeComplete.cpp
  clangd/CodeComplete.h
  clangd/Headers.cpp
  clangd/Headers.h
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/HeadersTests.cpp

Index: unittests/clangd/HeadersTests.cpp
===
--- unittests/clangd/HeadersTests.cpp
+++ unittests/clangd/HeadersTests.cpp
@@ -90,7 +90,7 @@
 
 IncludeInserter Inserter(MainFile, /*Code=*/"", format::getLLVMStyle(),
  CDB.getCompileCommand(MainFile)->Directory,
- Clang->getPreprocessor().getHeaderSearchInfo());
+ &Clang->getPreprocessor().getHeaderSearchInfo());
 for (const auto &Inc : Inclusions)
   Inserter.addExisting(Inc);
 auto Declaring = ToHeaderFile(Original);
@@ -110,7 +110,7 @@
 
 IncludeInserter Inserter(MainFile, /*Code=*/"", format::getLLVMStyle(),
  CDB.getCompileCommand(MainFile)->Directory,
- Clang->getPreprocessor().getHeaderSearchInfo());
+ &Clang->getPreprocessor().getHeaderSearchInfo());
 auto Edit = Inserter.insert(VerbatimHeader);
 Action.EndSourceFile();
 return Edit;
@@ -252,6 +252,24 @@
   EXPECT_TRUE(StringRef(Edit->newText).contains(""));
 }
 
+TEST(Headers, NoHeaderSearchInfo) {
+  std::string MainFile = testPath("main.cpp");
+  IncludeInserter Inserter(MainFile, /*Code=*/"", format::getLLVMStyle(),
+   /*BuildDir=*/"", /*HeaderSearchInfo=*/nullptr);
+
+  auto HeaderPath = testPath("sub/bar.h");
+  auto Declaring = HeaderFile{HeaderPath, /*Verbatim=*/false};
+  auto Inserting = HeaderFile{HeaderPath, /*Verbatim=*/false};
+  auto Verbatim = HeaderFile{"", /*Verbatim=*/true};
+
+  EXPECT_EQ(Inserter.calculateIncludePath(Declaring, Inserting),
+"\"" + HeaderPath + "\"");
+  EXPECT_EQ(Inserter.shouldInsertInclude(Declaring, Inserting), false);
+
+  EXPECT_EQ(Inserter.calculateIncludePath(Declaring, Verbatim), "");
+  EXPECT_EQ(Inserter.shouldInsertInclude(Declaring, Verbatim), true);
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -32,7 +32,6 @@
 using ::llvm::Failed;
 using ::testing::AllOf;
 using ::testing::Contains;
-using ::testing::Each;
 using ::testing::ElementsAre;
 using ::testing::Field;
 using ::testing::HasSubstr;
@@ -139,6 +138,25 @@
  FilePath);
 }
 
+// Builds a server and runs code completion.
+// If IndexSymbols is non-empty, an index will be built and passed to opts.
+CodeCompleteResult completionsNoCompile(llvm::StringRef Text,
+std::vector IndexSymbols = {},
+clangd::CodeCompleteOptions Opts = {},
+PathRef FilePath = "foo.cpp") {
+  std::unique_ptr OverrideIndex;
+  if (!IndexSymbols.empty()) {
+assert(!Opts.Index && "both Index and IndexSymbols given!");
+OverrideIndex = memIndex(std::move(IndexSymbols));
+Opts.Index = OverrideIndex.get();
+  }
+
+  MockFSProvider FS;
+  Annotations Test(Text);
+  return codeCompleteNoCompile(FilePath, Test.code(), Test.point(),
+   FS.getFileSystem(), Opts);
+}
+
 Symbol withReferences(int N, Symbol S) {
   S.References = N;
   return S;
@@ -2366,6 +2384,33 @@
   UnorderedElementsAre(AllOf(Qualifier(""), Named("XYZ";
 }
 
+TEST(NoCompileCompletionTest, Basic) {
+  auto Results = completionsNoCompile(R"cpp(
+void func() {
+  int xyz;
+  int abc;
+  ^
+}
+  )cpp");
+  EXPECT_THAT(Results.Completions,
+  UnorderedElementsAre(Named("void"), Named("func"), Named("int"),
+   Named("xyz"), Named("abc")));
+}
+
+TEST(NoCompileCompletionTest, WithFilter) {
+  auto Results = completionsNoCompile(R"cpp(
+void func() {
+  int sym1;
+  int sym2;
+  int xyz1;
+  int xyz2;
+  sy^
+}
+  )cpp");
+  EXPECT_THAT(Results.Completions,
+  UnorderedElementsAre(Named("sym1"), Named("sym2")));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace cla

[PATCH] D60123: [AST] Forbid copy/move of statements/types.

2019-04-02 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 193271.
riccibruno retitled this revision from "[AST] Forbid copy/move of 
statements/declarations/types." to "[AST] Forbid copy/move of 
statements/types.".

Repository:
  rC Clang

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

https://reviews.llvm.org/D60123

Files:
  include/clang/AST/Stmt.h
  include/clang/AST/Type.h


Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -1813,7 +1813,9 @@
   friend class ASTWriter;
 
   Type(const Type &) = delete;
+  Type(Type &&) = delete;
   Type &operator=(const Type &) = delete;
+  Type &operator=(Type &&) = delete;
 
   TypeClass getTypeClass() const { return static_cast(TypeBits.TC); 
}
 
Index: include/clang/AST/Stmt.h
===
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -1042,6 +1042,11 @@
 return static_cast(StmtBits.sClass);
   }
 
+  Stmt(const Stmt &) = delete;
+  Stmt(Stmt &&) = delete;
+  Stmt &operator=(const Stmt &) = delete;
+  Stmt &operator=(Stmt &&) = delete;
+
   const char *getStmtClassName() const;
 
   bool isOMPStructuredBlock() const { return StmtBits.IsOMPStructuredBlock; }


Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -1813,7 +1813,9 @@
   friend class ASTWriter;
 
   Type(const Type &) = delete;
+  Type(Type &&) = delete;
   Type &operator=(const Type &) = delete;
+  Type &operator=(Type &&) = delete;
 
   TypeClass getTypeClass() const { return static_cast(TypeBits.TC); }
 
Index: include/clang/AST/Stmt.h
===
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -1042,6 +1042,11 @@
 return static_cast(StmtBits.sClass);
   }
 
+  Stmt(const Stmt &) = delete;
+  Stmt(Stmt &&) = delete;
+  Stmt &operator=(const Stmt &) = delete;
+  Stmt &operator=(Stmt &&) = delete;
+
   const char *getStmtClassName() const;
 
   bool isOMPStructuredBlock() const { return StmtBits.IsOMPStructuredBlock; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59870: [clang-tidy] Add MagnitudeBitsUpperLimit option to bugprone-too-small-loop-variable

2019-04-02 Thread Tamás Zolnai via Phabricator via cfe-commits
ztamas updated this revision to Diff 193277.
ztamas added a comment.

Fixed typo.
Mentioned the default value in release notes.


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

https://reviews.llvm.org/D59870

Files:
  clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone-too-small-loop-variable.rst
  
clang-tools-extra/test/clang-tidy/bugprone-too-small-loop-variable-magniute-bits-upper-limit.cpp
  clang-tools-extra/test/clang-tidy/bugprone-too-small-loop-variable.cpp

Index: clang-tools-extra/test/clang-tidy/bugprone-too-small-loop-variable.cpp
===
--- clang-tools-extra/test/clang-tidy/bugprone-too-small-loop-variable.cpp
+++ clang-tools-extra/test/clang-tidy/bugprone-too-small-loop-variable.cpp
@@ -1,4 +1,8 @@
-// RUN: %check_clang_tidy %s bugprone-too-small-loop-variable %t -- -- --target=x86_64-linux
+// RUN: %check_clang_tidy %s bugprone-too-small-loop-variable %t -- \
+// RUN:   -config="{CheckOptions: \
+// RUN: [{key: bugprone-too-small-loop-variable.MagnitudeBitsUpperLimit, \
+// RUN:   value: 1024}]}" \
+// RUN:   -- --target=x86_64-linux
 
 long size() { return 294967296l; }
 
Index: clang-tools-extra/test/clang-tidy/bugprone-too-small-loop-variable-magniute-bits-upper-limit.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/bugprone-too-small-loop-variable-magniute-bits-upper-limit.cpp
@@ -0,0 +1,23 @@
+// RUN: %check_clang_tidy %s bugprone-too-small-loop-variable %t -- -- --target=x86_64-linux
+
+// MagnitudeBitsUpperLimit = 16 (default value)
+
+unsigned long size() { return 294967296l; }
+
+void voidFilteredOutForLoop1() {
+  for (long i = 0; i < size(); ++i) {
+// no warning
+  }
+}
+
+void voidCaughtForLoop1() {
+  for (int i = 0; i < size(); ++i) {
+// no warning
+  }
+}
+
+void voidCaughtForLoop2() {
+  for (short i = 0; i < size(); ++i) {
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: loop variable has narrower type 'short' than iteration's upper bound 'unsigned long' [bugprone-too-small-loop-variable]
+  }
+}
Index: clang-tools-extra/docs/clang-tidy/checks/bugprone-too-small-loop-variable.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/bugprone-too-small-loop-variable.rst
+++ clang-tools-extra/docs/clang-tidy/checks/bugprone-too-small-loop-variable.rst
@@ -27,3 +27,20 @@
 
 This algorithm works for small amount of objects, but will lead to freeze for a
 a larger user input.
+
+.. option:: MagnitudeBitsUpperLimit
+
+  Upper limit for the magnitude bits of the loop variable. If it's set the check
+  filters out those catches in which the loop variable's type has more magnitude
+  bits as the specified upper limit. The default value is 16.
+  For example, if the user sets this option to 31 (bits), then a 32-bit ``unsigend int``
+  is ignored by the check, however a 32-bit ``int`` is not (A 32-bit ``signed int``
+  has 31 magnitude bits).
+
+.. code-block:: c++
+
+  int main() {
+long size = 294967296l;
+for (unsigned i = 0; i < size; ++i) {} // no warning with MagnitudeBitsUpperLimit = 31 on a system where unsigned is 32-bit
+for (int i = 0; i < size; ++i) {} // warning with MagnitudeBitsUpperLimit = 31 on a system where int is 32-bit
+  }
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -119,6 +119,12 @@
   `CommentUserDefiniedLiterals`, `CommentStringLiterals`,
   `CommentCharacterLiterals` & `CommentNullPtrs` options.
 
+- The :doc:`bugprone-too-small-loop-variable
+  ` now supports
+  `MagnitudeBitsUpperLimit` option. The default value is to 16,
+  which greatly reduces warnings related to loops which are unlikely to
+  cause an actual functional bug.
+
 - The :doc:`google-runtime-int `
   check has been disabled in Objective-C++.
 
Index: clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.h
===
--- clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.h
@@ -29,10 +29,14 @@
 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-too-small-loop-variable.html
 class TooSmallLoopVariableCheck : public ClangTidyCheck {
 public:
-  TooSmallLoopVariableCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  TooSmallLoopVariableCheck(StringRef Name, ClangTidyContext *Context);
+
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder)

[PATCH] D60123: [AST] Forbid copy/move of statements/declarations/types.

2019-04-02 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

In D60123#1451307 , @riccibruno wrote:

> In D60123#1451303 , @lebedev.ri 
> wrote:
>
> > Probably `Decl` too?
>
>
> Yep. I though it was already done but after checking it seems I remembered 
> incorrectly.


Huh, never mind. It seems that at least `ImplicitParamDecl`s are used in a 
`SmallVector`, and this requires the copy-constructor to be usable.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60123



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


[PATCH] D59932: [clang-tidy] **Prototype**: Add fix description to clang-tidy checks.

2019-04-02 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked an inline comment as done.
hokein added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidyCheck.h:109
+  /// not supported.
+  virtual llvm::StringRef fixDescription() { return ""; }
+

alexfh wrote:
> Checks can provide different fixes with different semantics depending on the 
> context. It seems incorrect to assume that there can be one reasonable 
> description for all of them.
Yes, as mentioned in the comment, this is the limitation of this approach -- I 
assume we don't have a large number of these checks, most checks are providing 
a  single fix.

Another alternative is to use some heuristic mechanisms to do a translation 
from the `Replacement`, like we do in clangd, 
https://github.com/llvm-mirror/clang-tools-extra/blob/master/clangd/Diagnostics.cpp#L350.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59932



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


[PATCH] D59467: [clang] Adding the Likelihood Attribute from C++2a

2019-04-02 Thread Gauthier via Phabricator via cfe-commits
Tyker updated this revision to Diff 193269.
Tyker added a comment.

fixed the CFG issue is an proper way


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

https://reviews.llvm.org/D59467

Files:
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/StmtCXX.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Scope.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Stmt.cpp
  clang/lib/AST/StmtCXX.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Analysis/CFG.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/Scope.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/CodeGenCXX/cxx2a-likelihood-attr.cpp
  clang/test/PCH/cxx2a-likelihood-attr.cpp
  clang/test/SemaCXX/cxx17-compat.cpp
  clang/test/SemaCXX/cxx2a-likelihood-attr.cpp

Index: clang/test/SemaCXX/cxx2a-likelihood-attr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-likelihood-attr.cpp
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify -std=c++2a
+
+// formating this file will break the test
+// clang-format off
+
+int f(int i) {
+  if (i == 1)
+[[unlikely]] { f(i); }
+  else if (i == 2)
+[[likely]] return f(i);
+  else
+[[unlikely]] { return f(i + 1); }
+  return i;
+}
+
+[[likely]] typedef int n1;
+// expected-error@-1 {{'likely' attribute cannot be applied to a declaration}}
+typedef int [[likely]] n2;
+// expected-error@-1 {{'likely' attribute cannot be applied to types}}
+typedef int n3 [[likely]];
+// expected-error@-1 {{'likely' attribute cannot be applied to a declaration}}
+
+enum [[likely]] E{One};
+// expected-error@-1 {{'likely' attribute cannot be applied to a declaration}}
+
+[[likely]]
+// expected-error@-1 {{'likely' attribute cannot be applied to a declaration}}
+
+void test(int i) {
+  [[likely]]
+  // expected-warning@-1 {{attribute 'likely' is not associated with a branch and is ignored}}
+  if (f(i)) [[likely, likely]] {
+// expected-error@-1 {{likely attribute cannot be repeated}}
+// expected-note@-2 {{previous attribute is here}}
+[[unlikely]] return;
+// expected-warning@-1 {{attribute 'unlikely' is not associated with a branch and is ignored}}
+  }
+  else [[unlikely]] if (f(i)) {
+while (f(i))
+  [[likely]] {
+switch (i) {
+  [[likely]] case 1 : default : [[likely]];
+  // expected-warning@-1 {{attribute 'likely' is not associated with a branch and is ignored}}
+  [[unlikely]] case 3 : f(i);
+  [[fallthrough]];
+case 4:
+  return;
+}
+  }
+for (;;)
+  [[likely, unlikely]]
+  // expected-error@-1 {{unlikely and likely attributes are not compatible}}
+  // expected-note@-2 {{previous attribute is here}}
+  [[likely]] return;
+// expected-error@-1 {{likely attribute cannot be repeated}}
+// expected-note@-5 {{previous attribute is here}}
+  }
+  try { // expected-error {{cannot use 'try' with exceptions disabled}}
+[[likely]];
+// expected-warning@-1 {{attribute 'likely' is not associated with a branch and is ignored}}
+  } catch (int) {
+[[likely]] test :
+// expected-error@-1 {{'likely' attribute cannot be applied to a declaration}}
+[[unlikely]] return;
+  }
+}
Index: clang/test/SemaCXX/cxx17-compat.cpp
===
--- clang/test/SemaCXX/cxx17-compat.cpp
+++ clang/test/SemaCXX/cxx17-compat.cpp
@@ -63,3 +63,23 @@
 // expected-warning@-4 {{range-based for loop initialization statements are incompatible with C++ standards before C++2a}}
 #endif
 }
+
+//clang-format off
+
+int f(int i) {
+  if (i == 1)
+[[unlikely]]
+#if __cplusplus <= 201703L
+// expected-warning@-2 {{use of the 'unlikely' attribute is a C++2a extension}}
+#endif
+{
+  f(i);
+}
+  else if (i == 2)
+[[likely]]
+#if __cplusplus <= 201703L
+// expected-warning@-2 {{use of the 'likely' attribute is a C++2a extension}}
+#endif
+return f(i);
+  return i;
+}
Index: clang/test/PCH/cxx2a-likelihood-attr.cpp
===
--- /dev/null
+++ clang/test/PCH/cxx2a-likelihood-attr.cpp
@@ -0,0 +1,57 @@
+// Test this without pch.
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only -verify %s -ast-dump | FileCheck %s
+
+// Test with pch. Use '-ast-dump' to force deserialization of function bodies.
+// RUN: %clang_cc1 -x c++-header -std=c++2a -emit-pch -o %t %s
+// RUN: %clang_cc1 -std=c++2a -include-pch %t -fsyntax-only -verify 

[PATCH] D60123: [AST] Forbid copy/move of statements/declarations/types.

2019-04-02 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno updated this revision to Diff 193267.
riccibruno retitled this revision from "[AST] Forbid copy/move of Stmt." to 
"[AST] Forbid copy/move of statements/declarations/types.".
riccibruno edited the summary of this revision.
riccibruno added a reviewer: lebedev.ri.

Repository:
  rC Clang

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

https://reviews.llvm.org/D60123

Files:
  include/clang/AST/DeclBase.h
  include/clang/AST/Stmt.h
  include/clang/AST/Type.h


Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -1813,7 +1813,9 @@
   friend class ASTWriter;
 
   Type(const Type &) = delete;
+  Type(Type &&) = delete;
   Type &operator=(const Type &) = delete;
+  Type &operator=(Type &&) = delete;
 
   TypeClass getTypeClass() const { return static_cast(TypeBits.TC); 
}
 
Index: include/clang/AST/Stmt.h
===
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -1042,6 +1042,11 @@
 return static_cast(StmtBits.sClass);
   }
 
+  Stmt(const Stmt &) = delete;
+  Stmt(Stmt &&) = delete;
+  Stmt &operator=(const Stmt &) = delete;
+  Stmt &operator=(Stmt &&) = delete;
+
   const char *getStmtClassName() const;
 
   bool isOMPStructuredBlock() const { return StmtBits.IsOMPStructuredBlock; }
Index: include/clang/AST/DeclBase.h
===
--- include/clang/AST/DeclBase.h
+++ include/clang/AST/DeclBase.h
@@ -386,6 +386,11 @@
 if (StatisticsEnabled) add(DK);
   }
 
+  Decl(const Decl &) = delete;
+  Decl(Decl &&) = delete;
+  Decl &operator=(const Decl &) = delete;
+  Decl &operator=(Decl &&) = delete;
+
   virtual ~Decl();
 
   /// Update a potentially out-of-date declaration.


Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -1813,7 +1813,9 @@
   friend class ASTWriter;
 
   Type(const Type &) = delete;
+  Type(Type &&) = delete;
   Type &operator=(const Type &) = delete;
+  Type &operator=(Type &&) = delete;
 
   TypeClass getTypeClass() const { return static_cast(TypeBits.TC); }
 
Index: include/clang/AST/Stmt.h
===
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -1042,6 +1042,11 @@
 return static_cast(StmtBits.sClass);
   }
 
+  Stmt(const Stmt &) = delete;
+  Stmt(Stmt &&) = delete;
+  Stmt &operator=(const Stmt &) = delete;
+  Stmt &operator=(Stmt &&) = delete;
+
   const char *getStmtClassName() const;
 
   bool isOMPStructuredBlock() const { return StmtBits.IsOMPStructuredBlock; }
Index: include/clang/AST/DeclBase.h
===
--- include/clang/AST/DeclBase.h
+++ include/clang/AST/DeclBase.h
@@ -386,6 +386,11 @@
 if (StatisticsEnabled) add(DK);
   }
 
+  Decl(const Decl &) = delete;
+  Decl(Decl &&) = delete;
+  Decl &operator=(const Decl &) = delete;
+  Decl &operator=(Decl &&) = delete;
+
   virtual ~Decl();
 
   /// Update a potentially out-of-date declaration.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59811: [clangd] Add fallback mode for code completion when compile command or preamble is not ready.

2019-04-02 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 193268.
ioeric added a comment.

- Rebase


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D59811

Files:
  clangd/ClangdServer.cpp
  clangd/CodeComplete.h
  clangd/TUScheduler.cpp
  clangd/TUScheduler.h
  clangd/Threading.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/TUSchedulerTests.cpp

Index: unittests/clangd/TUSchedulerTests.cpp
===
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -15,14 +15,13 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
+#include 
 #include 
 
 namespace clang {
 namespace clangd {
 namespace {
 
-using ::testing::_;
-using ::testing::AllOf;
 using ::testing::AnyOf;
 using ::testing::Each;
 using ::testing::ElementsAre;
@@ -35,13 +34,18 @@
 
 class TUSchedulerTests : public ::testing::Test {
 protected:
-  ParseInputs getInputs(PathRef File, std::string Contents) {
+  FileUpdateInputs getInputs(PathRef File, std::string Contents) {
 ParseInputs Inputs;
-Inputs.CompileCommand = *CDB.getCompileCommand(File);
 Inputs.FS = buildTestFS(Files, Timestamps);
 Inputs.Contents = std::move(Contents);
 Inputs.Opts = ParseOptions();
-return Inputs;
+FileUpdateInputs UpdateInputs;
+UpdateInputs.InputSansCommand = std::move(Inputs);
+std::string FilePath = File;
+UpdateInputs.GetCompileCommand = [this, FilePath]() {
+  return *CDB.getCompileCommand(FilePath);
+};
+return UpdateInputs;
   }
 
   void updateWithCallback(TUScheduler &S, PathRef File,
@@ -72,7 +76,7 @@
   /// Schedule an update and call \p CB with the diagnostics it produces, if
   /// any. The TUScheduler should be created with captureDiags as a
   /// DiagsCallback for this to work.
-  void updateWithDiags(TUScheduler &S, PathRef File, ParseInputs Inputs,
+  void updateWithDiags(TUScheduler &S, PathRef File, FileUpdateInputs Inputs,
WantDiagnostics WD,
llvm::unique_function)> CB) {
 Path OrigFile = File.str();
@@ -245,7 +249,7 @@
 
 S.runWithPreamble("StaleRead", Path, TUScheduler::Stale,
   [&](Expected Pre) {
-ASSERT_TRUE(bool(Pre));
+EXPECT_TRUE((bool)Pre);
 assert(bool(Pre));
 EXPECT_THAT(includes(Pre->Preamble),
 ElementsAre(""));
@@ -397,8 +401,9 @@
 EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce));
 
 ASSERT_TRUE((bool)AST);
-EXPECT_EQ(AST->Inputs.FS, Inputs.FS);
-EXPECT_EQ(AST->Inputs.Contents, Inputs.Contents);
+EXPECT_EQ(AST->Inputs.FS, Inputs.InputSansCommand.FS);
+EXPECT_EQ(AST->Inputs.Contents,
+  Inputs.InputSansCommand.Contents);
 
 std::lock_guard Lock(Mut);
 ++TotalASTReads;
@@ -415,7 +420,7 @@
 EXPECT_THAT(Context::current().get(NonceKey), Pointee(Nonce));
 
 ASSERT_TRUE((bool)Preamble);
-EXPECT_EQ(Preamble->Contents, Inputs.Contents);
+EXPECT_EQ(Preamble->Contents, Inputs.InputSansCommand.Contents);
 
 std::lock_guard Lock(Mut);
 ++TotalPreambleReads;
@@ -504,6 +509,7 @@
   )cpp";
   auto WithEmptyPreamble = R"cpp(int main() {})cpp";
   S.update(Foo, getInputs(Foo, WithPreamble), WantDiagnostics::Auto);
+
   S.runWithPreamble(
   "getNonEmptyPreamble", Foo, TUScheduler::Stale,
   [&](Expected Preamble) {
Index: unittests/clangd/ClangdTests.cpp
===
--- unittests/clangd/ClangdTests.cpp
+++ unittests/clangd/ClangdTests.cpp
@@ -13,8 +13,10 @@
 #include "Matchers.h"
 #include "SyncAPI.h"
 #include "TestFS.h"
+#include "Threading.h"
 #include "URI.h"
 #include "clang/Config/config.h"
+#include "clang/Sema/CodeCompleteConsumer.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/Errc.h"
@@ -36,7 +38,6 @@
 namespace {
 
 using ::testing::ElementsAre;
-using ::testing::Eq;
 using ::testing::Field;
 using ::testing::Gt;
 using ::testing::IsEmpty;
@@ -1058,6 +1059,55 @@
   EXPECT_NE(Result, "");
 }
 
+TEST_F(ClangdVFSTest, FallbackWhenPreambleIsNotReady) {
+  MockFSProvider FS;
+  ErrorCheckingDiagConsumer DiagConsumer;
+  // Returns compile command only when notified.
+  class DelayedCompilationDatabase : public GlobalCompilationDatabase {
+  public:
+DelayedCompilationDatabase(Notification &CanReturnCommand)
+: CanReturnCommand(CanReturnCommand) {}
+
+llvm::Optional
+getCompileCommand(PathRef File, ProjectInfo * = nullptr) const override {
+  CanReturnCommand.wait();
+  auto FileName = llvm::sys::

[PATCH] D59887: [Syntax] Introduce TokenBuffer, start clangToolingSyntax library

2019-04-02 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/TokenBuffer.h:1
+//===- TokenBuffer.h - store tokens of preprocessed files -*- C++ 
-*-=//
+//

ilya-biryukov wrote:
> sammccall wrote:
> > are you sure TokenBuffer is the central concept in this file, rather than 
> > just the thing with the most code? Token.h might end up being a better name 
> > for users.
> I don't mind changing this to `Token.h`, although I'd personally expect that 
> a file with this name only contains a definition for the token class.
> `Tokens.h` would be a better fit from my POV. WDYT?
Sure, Tokens.h SGTM.



Comment at: clang/include/clang/Tooling/Syntax/TokenBuffer.h:66
+///macroTokens = {'BAR', '(', '1', ')'}.
+class MacroInvocation {
+public:

I'd suggest a more natural order is token -> tokenbuffer -> macroinvocation. 
Forward declare?

This is because the token buffer exposes token streams, which are probably the 
second-most important concept in the file (after tokens)



Comment at: clang/include/clang/Tooling/Syntax/TokenBuffer.h:92
+
+/// A list of tokens obtained by lexing and preprocessing a text buffer and a
+/// set of helpers to allow mapping the tokens after preprocessing to the

ilya-biryukov wrote:
> sammccall wrote:
> > Warning, braindump follows - let's discuss further.
> > We talked a bunch offline about the logical and concrete data model here.
> > 
> > As things stand:
> >  - #includes are not expanded, but will refer to a file ID with its own 
> > buffer: `map` is the whole structure
> >  - no information is captured about other PP interactions (PP directives 
> > that generate no tokens, skipped sections
> >  - the spelled sequence of tokens is not directly available (but expanded + 
> > macro invocations may be enough to reconstruct it)
> > 
> > If we keep this model, I think we should spell both of these out in the 
> > comment.
> > But there's another fairly natural model we could consider:
> > 
> >  - we have a single TokenBuffer with a flat list of all expanded tokens in 
> > the TU, rather than for the file 
> >  - one FileID corresponds to a contiguous range of *transitive* symbols, 
> > these ranges nest
> >  - the TokenBuffer also stores the original tokens as `map > vector>`
> >  - spelled -> expanded token mapping: spelled tokens for a file are 
> > partitioned into ranges (types: literal, include, macro invocation, other 
> > pp directive, pp skipped region). each range maps onto a range of expanded 
> > tokens (empty for e.g. pp directive or skipped region)
> >  - expanded -> spelled token is similar. (It's almost the inverse of the of 
> > the other mapping, we drop the "include" mapping ranges)
> >  - This can naturally handle comments, preprocessor directives, pp skipped 
> > sections, etc - these are in the spelled stream but not the expanded stream.
> > 
> > e.g. for this code
> > ```
> > // foo.cpp
> > int a;
> > #include "foo.h"
> > int b =  FOO(42);
> > // foo.h
> > #define FOO(X) X*X
> > int c;
> > ```
> > 
> > we'd have this buffer:
> > ```
> > expandedTokens = [int a ; int c ; int b = 42 * 42 ;]
> > spelledTokens = {
> >   "foo.cpp" => [int a; # include "foo.h" int b = FOO ( 42 ) ;],
> >   "foo.h" => [# define FOO ( X ) X * X int c ;]
> > }
> > 
> > expandedToSpelling = {
> >   int => int (foo.cpp), type = literal
> >   a => a
> >   ; => ;
> > 
> >   [] => [# define FOO ( X ) X * X](foo.h), type=preprocessor directive
> >   int => int (foo.h)
> >   c => c
> >   ; => ;
> > 
> >   int => int (foo.cpp)
> >   b => b
> >   = => =
> >   [42 * 42] => [FOO ( 42 ) ](foo.cpp), type=macro invocation
> >   ; => ; (foo.cpp)
> > }
> > 
> > spellingToExpanded = {
> >   // foo.cpp
> >   int => int, type=literal
> >   a => a
> >   ; => ;
> >   [# include "foo.h"] => [int c ;], type=include
> >   int => int
> >   b => b
> >   = => =
> >   [FOO ( X )] => [42 * 42], type=macro invocation
> >   ; => ;
> > 
> >   // foo.h
> >   [# define FOO ( X ) X] => [], type=preprocessor directive
> >   int => int
> >   c => c
> >   ; => ;
> > }
> > ```
> > 
> > Various implementation strategies possible here, one obvious one is to use 
> > a flat sorted list, and include a sequence of literal tokens as a single 
> > entry. 
> > 
> > ```
> > struct ExpandedSpellingMapping {
> >   unsigned ExpandedStart, ExpandedEnd;
> >   FileID SpellingFile; // redundant for illustration: can actually derive 
> > from SpellingTokens[SpellingStart].location()
> >   unsigned SpellingStart, SpellingEnd;
> >   enum { LiteralSequence, MacroInvocation, Preprocessor, PPSkipped, 
> > Inclusion } Kind;
> > }
> > vector ExpandedToSpelling; // bsearchable
> > vector> Inclusions; // for spelling 
> > -> expanded mapping. redundant: much can be taken from SourceManager.
> > ```
> > 
> > A delta-encoded representation with chunks for bsearch will likely be much 
> > more compact, if th

[PATCH] D60123: [AST] Forbid copy/move of Stmt.

2019-04-02 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

In D60123#1451303 , @lebedev.ri wrote:

> Probably `Decl` too?


Yep. I though it was already done but after checking it seems I remembered 
incorrectly.


Repository:
  rC Clang

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

https://reviews.llvm.org/D60123



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


[PATCH] D60123: [AST] Forbid copy/move of Stmt.

2019-04-02 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Probably `Decl` too?


Repository:
  rC Clang

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

https://reviews.llvm.org/D60123



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


[PATCH] D60124: gn build: Add build files for non-framework xpc clangd bits

2019-04-02 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: mbonadei.
Herald added subscribers: jdoerfert, kadircet, arphaman, jkorous, MaskRay, 
ioeric, ilya-biryukov, mgorny.
Herald added a project: LLVM.

With this, check-clang-tools unit tests are complete, but the lit tests still 
don't run the one XPC test since this is still missing build files for the xpc 
framework.


https://reviews.llvm.org/D60124

Files:
  llvm/utils/gn/build/sync_source_lists_from_cmake.py
  llvm/utils/gn/secondary/clang-tools-extra/clangd/tool/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/enable.gni
  llvm/utils/gn/secondary/clang-tools-extra/unittests/BUILD.gn
  llvm/utils/gn/secondary/clang-tools-extra/unittests/clangd/xpc/BUILD.gn

Index: llvm/utils/gn/secondary/clang-tools-extra/unittests/clangd/xpc/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang-tools-extra/unittests/clangd/xpc/BUILD.gn
@@ -0,0 +1,15 @@
+import("//llvm/utils/unittest/unittest.gni")
+
+unittest("ClangdXpcTests") {
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang-tools-extra/clangd",
+"//clang-tools-extra/clangd/xpc:conversions",
+"//llvm/lib/Support",
+"//llvm/lib/Testing/Support",
+  ]
+  include_dirs = [ "//clang-tools-extra/clangd" ]
+  sources = [
+"ConversionTests.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang-tools-extra/unittests/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/unittests/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/unittests/BUILD.gn
@@ -1,3 +1,5 @@
+import("//clang-tools-extra/clangd/xpc/enable.gni")
+
 group("unittests") {
   deps = [
 "clang-apply-replacements:ClangApplyReplacementsTests",
@@ -10,6 +12,8 @@
 "clang-tidy:ClangTidyTests",
 "clangd:ClangdTests",
   ]
-  # FIXME: dep on clangd/xpc:ClangdXpcTests once it exists
+  if (clangd_build_xpc) {
+deps += [ "clangd/xpc:ClangdXpcTests" ]
+  }
   testonly = true
 }
Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/enable.gni
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/enable.gni
@@ -0,0 +1,4 @@
+declare_args() {
+  # Whether to build clangd's XPC components.
+  clangd_build_xpc = current_os == "mac"
+}
Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn
===
--- /dev/null
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/xpc/BUILD.gn
@@ -0,0 +1,25 @@
+static_library("conversions") {
+  output_name = "clangdXpcJsonConversions"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang-tools-extra/clangd",
+"//llvm/lib/Support",
+  ]
+  include_dirs = [ ".." ]
+  sources = [
+"Conversion.cpp",
+  ]
+}
+
+static_library("transport") {
+  output_name = "clangdXpcTransport"
+  configs += [ "//llvm/utils/gn/build:clang_code" ]
+  deps = [
+"//clang-tools-extra/clangd",
+"//llvm/lib/Support",
+  ]
+  include_dirs = [ ".." ]
+  sources = [
+"XPCTransport.cpp",
+  ]
+}
Index: llvm/utils/gn/secondary/clang-tools-extra/clangd/tool/BUILD.gn
===
--- llvm/utils/gn/secondary/clang-tools-extra/clangd/tool/BUILD.gn
+++ llvm/utils/gn/secondary/clang-tools-extra/clangd/tool/BUILD.gn
@@ -1,10 +1,6 @@
+import("//clang-tools-extra/clangd/xpc/enable.gni")
 import("//llvm/utils/gn/build/write_cmake_config.gni")
 
-declare_args() {
-  # Whether to build clangd's XPC components.
-  clangd_build_xpc = false
-}
-
 write_cmake_config("features") {
   # FIXME: Try moving Features.inc.in to tools, seems like a better location.
   input = "../Features.inc.in"
@@ -33,6 +29,12 @@
 "//clang/lib/Tooling/Core",
 "//llvm/lib/Support",
   ]
+  if (clangd_build_xpc) {
+deps += [
+  "//clang-tools-extra/clangd/xpc:conversions",
+  "//clang-tools-extra/clangd/xpc:transport",
+]
+  }
 
   include_dirs = [
 "..",
@@ -43,8 +45,4 @@
   sources = [
 "ClangdMain.cpp",
   ]
-
-  if (clangd_build_xpc) {
-# FIXME: Depend on clangdXpcJsonConversions, clangdXpcTransport
-  }
 }
Index: llvm/utils/gn/build/sync_source_lists_from_cmake.py
===
--- llvm/utils/gn/build/sync_source_lists_from_cmake.py
+++ llvm/utils/gn/build/sync_source_lists_from_cmake.py
@@ -61,8 +61,7 @@
 # Matches e.g. |add_llvm_unittest_with_input_files|.
 unittest_re = re.compile(r'^add_\S+_unittest', re.MULTILINE)
 
-# FIXME: Add 'clang-tools-extra'.
-checked = [ 'clang', 'lld', 'llvm' ]
+checked = [ 'clang', 'clang-tools-extra', 'lld', 'llvm' ]
 for c in checked:
 for root, _, _ in os.walk(os.path.join(c, 'unittests')):
 cmake_file = os

[PATCH] D60123: [AST] Forbid copy/move of Stmt.

2019-04-02 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno created this revision.
riccibruno added a reviewer: aaron.ballman.
riccibruno added a project: clang.
Herald added a subscriber: cfe-commits.

Statements and expressions are not supposed to be moved, and trying to do so is 
only going to result in tears. Someone tripped on this a few days ago on the 
mailing list. NFC.


Repository:
  rC Clang

https://reviews.llvm.org/D60123

Files:
  include/clang/AST/Stmt.h


Index: include/clang/AST/Stmt.h
===
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -1042,6 +1042,11 @@
 return static_cast(StmtBits.sClass);
   }
 
+  Stmt(const Stmt &) = delete;
+  Stmt(Stmt &&) = delete;
+  Stmt &operator=(const Stmt &) = delete;
+  Stmt &operator=(Stmt &&) = delete;
+
   const char *getStmtClassName() const;
 
   bool isOMPStructuredBlock() const { return StmtBits.IsOMPStructuredBlock; }


Index: include/clang/AST/Stmt.h
===
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -1042,6 +1042,11 @@
 return static_cast(StmtBits.sClass);
   }
 
+  Stmt(const Stmt &) = delete;
+  Stmt(Stmt &&) = delete;
+  Stmt &operator=(const Stmt &) = delete;
+  Stmt &operator=(Stmt &&) = delete;
+
   const char *getStmtClassName() const;
 
   bool isOMPStructuredBlock() const { return StmtBits.IsOMPStructuredBlock; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59376: [LibTooling] Add Transformer, a library for source-to-source transformations.

2019-04-02 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Thank you for the extremely helpful and detailed review!!




Comment at: clang/include/clang/Tooling/Refactoring/Transformer.h:110
+  // constructed with the builder class.
+  static constexpr char RootId[] = "___root___";
+};

ilya-biryukov wrote:
> NIT: `llvm::StringLiteral` is a vocabulary type with compile-time size that 
> could be used here.
> Although I don't think it has any actual benefits over char array, so leaving 
> as is also looks good.
Went with StringLiteral -- given that we always wrap RootId in a stringref to 
use it, seems better just to define it that way to begin with.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D59376



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


  1   2   >