[PATCH] D42995: [ThinLTO] Ignore object files with empty ThinLTO index

2018-02-15 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 134385.
vitalybuka added a comment.
Herald added a subscriber: hiraditya.

Don't use empty index file


https://reviews.llvm.org/D42995

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/Inputs/thinlto-distributed-backend-skip.bc
  clang/test/CodeGen/thinlto-distributed-backend-skip.ll
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/tools/gold/X86/v1.12/thinlto_emit_linked_objects.ll
  llvm/tools/gold/gold-plugin.cpp

Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ llvm/tools/gold/gold-plugin.cpp
@@ -811,9 +811,12 @@
 // final link. Frequently the distributed build system will want to
 // confirm that all expected outputs are created based on all of the
 // modules provided to the linker.
+// If SkipModule is true write empty .thinlto.bc with the flag which
+// request backend to skip corresponding object file.
 static void writeEmptyDistributedBuildOutputs(const std::string &ModulePath,
   const std::string &OldPrefix,
-  const std::string &NewPrefix) {
+  const std::string &NewPrefix,
+  bool Skip) {
   std::string NewModulePath =
   getThinLTOOutputFile(ModulePath, OldPrefix, NewPrefix);
   std::error_code EC;
@@ -823,6 +826,12 @@
 if (EC)
   message(LDPL_FATAL, "Failed to write '%s': %s",
   (NewModulePath + ".thinlto.bc").c_str(), EC.message().c_str());
+
+if (Skip) {
+  ModuleSummaryIndex Index(false);
+  Index.setSkipModule();
+  WriteIndexToFile(Index, OS, nullptr);
+}
   }
   if (options::thinlto_emit_imports_files) {
 raw_fd_ostream OS(NewModulePath + ".imports", EC,
@@ -878,6 +887,10 @@
 assert(ObjFilename.second);
 if (const void *View = getSymbolsAndView(F))
   addModule(*Lto, F, View, ObjFilename.first->first());
+else {
+  ObjFilename.first->second = true;
+  writeEmptyDistributedBuildOutputs(Identifier, OldPrefix, NewPrefix, true);
+}
   }
 
   SmallString<128> Filename;
@@ -920,7 +933,7 @@
 for (auto &Identifier : ObjectToIndexFileState)
   if (!Identifier.getValue())
 writeEmptyDistributedBuildOutputs(Identifier.getKey(), OldPrefix,
-  NewPrefix);
+  NewPrefix, false);
 
   if (options::TheOutputType == options::OT_DISABLE ||
   options::TheOutputType == options::OT_BC_ONLY)
Index: llvm/test/tools/gold/X86/v1.12/thinlto_emit_linked_objects.ll
===
--- llvm/test/tools/gold/X86/v1.12/thinlto_emit_linked_objects.ll
+++ llvm/test/tools/gold/X86/v1.12/thinlto_emit_linked_objects.ll
@@ -31,6 +31,22 @@
 ; RUN: ls %t2.o.imports
 ; RUN: ls %t3.o.imports
 
+; Regular *thinlto.bc file. "SkipModule" flags (0x2) should not be set.
+; RUN: llvm-bcanalyzer --dump %t1.o.thinlto.bc | FileCheck %s -check-prefixes=CHECK-BC1
+; CHECK-BC1: 
+; CHECK-BC1: 
+; CHECK-BC2: &1 | FileCheck %s -check-prefixes=CHECK-BC3
+; CHECK-BC3: LLVM ERROR: Unexpected end of file
+
 ; RUN: cat %t.index | FileCheck %s
 ; CHECK: thinlto_emit_linked_objects.ll.tmp1.o
 ; CHECK-NOT: thinlto_emit_linked_objects.ll.tmp2.o
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -3604,10 +3604,13 @@
   Stream.EnterSubblock(bitc::GLOBALVAL_SUMMARY_BLOCK_ID, 3);
   Stream.EmitRecord(bitc::FS_VERSION, ArrayRef{INDEX_VERSION});
 
-  // Write the index flags. Currently we only write a single flag, the value of
-  // withGlobalValueDeadStripping, which only applies to the combined index.
-  Stream.EmitRecord(bitc::FS_FLAGS,
-ArrayRef{Index.withGlobalValueDeadStripping()});
+  // Write the index flags.
+  uint64_t Flags = 0;
+  if (Index.withGlobalValueDeadStripping())
+Flags |= 0x1;
+  if (Index.skipModule())
+Flags |= 0x2;
+  Stream.EmitRecord(bitc::FS_FLAGS, ArrayRef{Flags});
 
   for (const auto &GVI : valueIds()) {
 Stream.EmitRecord(bitc::FS_VALUE_GUID,
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -5186,11 +5186,14 @@
 case bitc::FS_FLAGS: {  // [flags]
   uint64_t Flags = Record[0];
   // Scan flags (set only on the combined index).
-  assert(Flags <= 1 && "Unexpected bits in flag");
+  assert(Flags <= 0x3 && "Unexpected bits in flag");
 
   // 1 bit: WithGlobalValueDeadStripping flag.
   if (Flags & 0x1)

[libcxx] r325219 - Merging r325147:

2018-02-15 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Thu Feb 15 00:22:12 2018
New Revision: 325219

URL: http://llvm.org/viewvc/llvm-project?rev=325219&view=rev
Log:
Merging r325147:

r325147 | marshall | 2018-02-14 19:05:25 +0100 (Wed, 14 Feb 2018) | 3 lines

Add a catch for std::length_error for the case where the string can't handle 
2GB. (like say 32-bit big-endian)




Modified:
libcxx/branches/release_60/   (props changed)

libcxx/branches/release_60/test/std/input.output/stream.buffers/streambuf/streambuf.protected/streambuf.put.area/pbump2gig.pass.cpp

Propchange: libcxx/branches/release_60/
--
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Feb 15 00:22:12 2018
@@ -1,2 +1,2 @@
 /libcxx/branches/apple:136569-137939
-/libcxx/trunk:321963,324153,324855
+/libcxx/trunk:321963,324153,324855,325147

Modified: 
libcxx/branches/release_60/test/std/input.output/stream.buffers/streambuf/streambuf.protected/streambuf.put.area/pbump2gig.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/branches/release_60/test/std/input.output/stream.buffers/streambuf/streambuf.protected/streambuf.put.area/pbump2gig.pass.cpp?rev=325219&r1=325218&r2=325219&view=diff
==
--- 
libcxx/branches/release_60/test/std/input.output/stream.buffers/streambuf/streambuf.protected/streambuf.put.area/pbump2gig.pass.cpp
 (original)
+++ 
libcxx/branches/release_60/test/std/input.output/stream.buffers/streambuf/streambuf.protected/streambuf.put.area/pbump2gig.pass.cpp
 Thu Feb 15 00:22:12 2018
@@ -32,12 +32,13 @@ int main()
 #ifndef TEST_HAS_NO_EXCEPTIONS
 try {
 #endif
-   std::string str(2147483648, 'a');
-   SB sb;
-   sb.str(str);
-   assert(sb.pubpbase() <= sb.pubpptr());
+std::string str(2147483648, 'a');
+SB sb;
+sb.str(str);
+assert(sb.pubpbase() <= sb.pubpptr());
 #ifndef TEST_HAS_NO_EXCEPTIONS
-   }
-   catch (const std::bad_alloc &) {}
+}
+catch (const std::length_error &) {} // maybe the string can't take 2GB
+catch (const std::bad_alloc&) {} // maybe we don't have enough RAM
 #endif
 }


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


[PATCH] D43272: [clangd] Fix tracing now that spans lifetimes can overlap on a thread.

2018-02-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 134386.
sammccall added a comment.

address review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43272

Files:
  clangd/Trace.cpp
  clangd/Trace.h
  test/clangd/trace.test
  unittests/clangd/TraceTests.cpp

Index: unittests/clangd/TraceTests.cpp
===
--- unittests/clangd/TraceTests.cpp
+++ unittests/clangd/TraceTests.cpp
@@ -114,12 +114,10 @@
 ASSERT_NE(++Event, Events->end()) << "Expected thread name";
 EXPECT_TRUE(VerifyObject(*Event, {{"ph", "M"}, {"name", "thread_name"}}));
   }
-  ASSERT_NE(++Event, Events->end()) << "Expected span start";
-  EXPECT_TRUE(VerifyObject(*Event, {{"ph", "B"}, {"name", "A"}}));
   ASSERT_NE(++Event, Events->end()) << "Expected log message";
   EXPECT_TRUE(VerifyObject(*Event, {{"ph", "i"}, {"name", "Log"}}));
   ASSERT_NE(++Event, Events->end()) << "Expected span end";
-  EXPECT_TRUE(VerifyObject(*Event, {{"ph", "E"}}));
+  EXPECT_TRUE(VerifyObject(*Event, {{"ph", "X"}, {"name", "A"}}));
   ASSERT_EQ(++Event, Events->end());
   ASSERT_EQ(++Prop, Root->end());
 }
Index: test/clangd/trace.test
===
--- test/clangd/trace.test
+++ test/clangd/trace.test
@@ -2,18 +2,22 @@
 {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---
 {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"void main() {}"}}}
-#  CHECK: {"displayTimeUnit":"ns","traceEvents":[
-# Start opening the doc.
-#  CHECK: "name": "textDocument/didOpen"
-#  CHECK: "ph": "B"
-# Start building the preamble.
-#  CHECK: "name": "Preamble"
-#  CHECK: },
-# Finish building the preamble, with filename.
-#  CHECK: "File": "{{.*(/|\\)}}foo.c"
-# CHECK-NEXT: },
-# CHECK-NEXT: "ph": "E"
-# Start building the file.
-#  CHECK: "name": "Build"
+# These assertions are a bit loose, to avoid brittleness.
+# CHECK: {"displayTimeUnit":"ns","traceEvents":[
+# CHECK: {
+# CHECK:   "args": {
+# CHECK: "File": "{{.*(/|\\)}}foo.c"
+# CHECK:   },
+# CHECK:   "name": "Preamble",
+# CHECK:   "ph": "X",
+# CHECK: }
+# CHECK: {
+# CHECK:   "args": {
+# CHECK: "File": "{{.*(/|\\)}}foo.c"
+# CHECK:   },
+# CHECK:   "name": "Build",
+# CHECK:   "ph": "X",
+# CHECK: }
+# CHECK: },
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
Index: clangd/Trace.h
===
--- clangd/Trace.h
+++ clangd/Trace.h
@@ -40,6 +40,12 @@
   /// whose destructor records the end of the event.
   /// The args are *Args, only complete when the event ends.
   virtual Context beginSpan(llvm::StringRef Name, json::obj *Args) = 0;
+  // Called when a Span is destroyed (it may still be active on other threads).
+  // beginSpan() and endSpan() will always form a proper stack on each thread.
+  // The Context returned by beginSpan is active, but Args is not ready.
+  // Tracers should not override this unless they need to observe strict
+  // per-thread nesting. Instead they should observe context destruction.
+  virtual void endSpan() {};
 
   /// Called for instant events.
   virtual void instant(llvm::StringRef Name, json::obj &&Args) = 0;
@@ -77,6 +83,7 @@
 class Span {
 public:
   Span(llvm::StringRef Name);
+  ~Span();
 
   /// Mutable metadata, if this span is interested.
   /// Prefer to use SPAN_ATTACH rather than accessing this directly.
Index: clangd/Trace.cpp
===
--- clangd/Trace.cpp
+++ clangd/Trace.cpp
@@ -16,6 +16,7 @@
 #include "llvm/Support/FormatProviders.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Threading.h"
+#include 
 #include 
 
 namespace clang {
@@ -46,40 +47,103 @@
 Out.flush();
   }
 
+  // We stash a Span object in the context. It will record the start/end,
+  // and this also allows us to look up the parent Span's information.
   Context beginSpan(llvm::StringRef Name, json::obj *Args) override {
-jsonEvent("B", json::obj{{"name", Name}});
-return Context::current().derive(make_scope_exit([this, Args] {
-  jsonEvent("E", json::obj{{"args", std::move(*Args)}});
-}));
+return Context::current().derive(SpanKey,
+ make_unique(this, Name, Args));
+  }
+
+  // Trace viewer requires each thread to properly stack events.
+  // So we need to mark only duration that the span was active on the thread.
+  // (Hopefully any off-thread activity will be connected by a flow event).
+  // Record the end time here, but don't write the event: Args aren't ready yet.
+  void endSpan() override {
+Context::current().getExisting(SpanKey)->markEnded();
   }
 
   void instant(llvm::StringRef Name, json::obj &&Args) override {
+captureThreadMetadata();
 jsonEvent("i", jso

[PATCH] D43272: [clangd] Fix tracing now that spans lifetimes can overlap on a thread.

2018-02-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/Trace.cpp:133
+std::atomic EndTime; // Filled in by endSpan().
+std::string Name;
+const uint64_t TID;

ilya-biryukov wrote:
> Maybe make all fields except `EndTime` const?
Good idea - what's safe to read vs write wasn't clear.
Ended up just making this a class and encapsulating EndTime instead though.



Comment at: clangd/Trace.h:46
+  // The Context returned by beginSpan is active, but Args is not ready.
+  virtual void endSpan() {};
 

ilya-biryukov wrote:
> It feels awkward that `endSpan()` does not have any parameters explicitly 
> connecting it to `beginSpan()`.
> We could change `beginSpan()` to return a callback that would be called when 
> `Span` ends instead, that would make the connection clear, albeit it's not 
> very useful for `JSONTracer`.
> 
> Not sure we should change it, just thinking out loud :-)
So destructor-of-context is still the preferred way of observing the end of an 
event. endSpan() is kind of an attractive nuisance that we need for chrome 
tracing.

Added comments to explain this.

Given that, I think we want a signature that:
 - you basically can't use without first implementing and understanding the 
primary interface
 - can be defaulted to do nothing without interfering with the primary 
interface (this also gives us backwards compatibility).

I'm not sure think it's a problem that this is a bit obscure...


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43272



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


[clang-tools-extra] r325220 - [clangd] Fix tracing now that spans lifetimes can overlap on a thread.

2018-02-15 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Feb 15 00:40:54 2018
New Revision: 325220

URL: http://llvm.org/viewvc/llvm-project?rev=325220&view=rev
Log:
[clangd] Fix tracing now that spans lifetimes can overlap on a thread.

Summary:
The chrome trace viewer requires events within a thread to strictly nest.
So we need to record the lifetime of the Span objects, not the contexts.

But we still want to show the relationship between spans where a context crosses
threads, so do this with flow events (i.e. arrows).

Before: https://photos.app.goo.gl/q4Dd9u9xtelaXk1v1
After: https://photos.app.goo.gl/5RNLmAMLZR3unvY83

(This could stand some further improvement, in particular I think we want a
container span whenever we schedule work on a thread. But that's another patch)

Reviewers: ioeric

Subscribers: klimek, ilya-biryukov, jkorous-apple, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/Trace.cpp
clang-tools-extra/trunk/clangd/Trace.h
clang-tools-extra/trunk/test/clangd/trace.test
clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp

Modified: clang-tools-extra/trunk/clangd/Trace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Trace.cpp?rev=325220&r1=325219&r2=325220&view=diff
==
--- clang-tools-extra/trunk/clangd/Trace.cpp (original)
+++ clang-tools-extra/trunk/clangd/Trace.cpp Thu Feb 15 00:40:54 2018
@@ -16,6 +16,7 @@
 #include "llvm/Support/FormatProviders.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Threading.h"
+#include 
 #include 
 
 namespace clang {
@@ -46,40 +47,103 @@ public:
 Out.flush();
   }
 
+  // We stash a Span object in the context. It will record the start/end,
+  // and this also allows us to look up the parent Span's information.
   Context beginSpan(llvm::StringRef Name, json::obj *Args) override {
-jsonEvent("B", json::obj{{"name", Name}});
-return Context::current().derive(make_scope_exit([this, Args] {
-  jsonEvent("E", json::obj{{"args", std::move(*Args)}});
-}));
+return Context::current().derive(SpanKey,
+ make_unique(this, Name, Args));
+  }
+
+  // Trace viewer requires each thread to properly stack events.
+  // So we need to mark only duration that the span was active on the thread.
+  // (Hopefully any off-thread activity will be connected by a flow event).
+  // Record the end time here, but don't write the event: Args aren't ready 
yet.
+  void endSpan() override {
+Context::current().getExisting(SpanKey)->markEnded();
   }
 
   void instant(llvm::StringRef Name, json::obj &&Args) override {
+captureThreadMetadata();
 jsonEvent("i", json::obj{{"name", Name}, {"args", std::move(Args)}});
   }
 
   // Record an event on the current thread. ph, pid, tid, ts are set.
   // Contents must be a list of the other JSON key/values.
-  void jsonEvent(StringRef Phase, json::obj &&Contents) {
-uint64_t TID = get_threadid();
-std::lock_guard Lock(Mu);
-// If we haven't already, emit metadata describing this thread.
-if (ThreadsWithMD.insert(TID).second) {
-  SmallString<32> Name;
-  get_thread_name(Name);
-  if (!Name.empty()) {
-rawEvent("M", json::obj{
-  {"tid", TID},
-  {"name", "thread_name"},
-  {"args", json::obj{{"name", Name}}},
-  });
-  }
-}
-Contents["ts"] = timestamp();
+  void jsonEvent(StringRef Phase, json::obj &&Contents,
+ uint64_t TID = get_threadid(),
+ double Timestamp = 0) {
+Contents["ts"] = Timestamp ? Timestamp : timestamp();
 Contents["tid"] = TID;
+std::lock_guard Lock(Mu);
 rawEvent(Phase, std::move(Contents));
   }
 
 private:
+  class JSONSpan {
+  public:
+JSONSpan(JSONTracer *Tracer, llvm::StringRef Name, json::obj *Args)
+: StartTime(Tracer->timestamp()), EndTime(0), Name(Name),
+  TID(get_threadid()), Tracer(Tracer), Args(Args) {
+  // ~JSONSpan() may run in a different thread, so we need to capture now.
+  Tracer->captureThreadMetadata();
+
+  // We don't record begin events here (and end events in the destructor)
+  // because B/E pairs have to appear in the right order, which is awkward.
+  // Instead we send the complete (X) event in the destructor.
+
+  // If our parent was on a different thread, add an arrow to this span.
+  auto *Parent = Context::current().get(SpanKey);
+  if (Parent && *Parent && (*Parent)->TID != TID) {
+// If the parent span ended already, then show this as "following" it.
+// Otherwise show us as "parallel".
+double OriginTime = (*Parent)->EndTime;
+if (!OriginTime)
+  OriginTime = (*Parent)->StartTime;
+
+auto FlowID = nextID();
+Tracer->jsonEvent("s",
+ 

[PATCH] D43272: [clangd] Fix tracing now that spans lifetimes can overlap on a thread.

2018-02-15 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325220: [clangd] Fix tracing now that spans lifetimes can 
overlap on a thread. (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43272

Files:
  clang-tools-extra/trunk/clangd/Trace.cpp
  clang-tools-extra/trunk/clangd/Trace.h
  clang-tools-extra/trunk/test/clangd/trace.test
  clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp

Index: clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/TraceTests.cpp
@@ -114,12 +114,10 @@
 ASSERT_NE(++Event, Events->end()) << "Expected thread name";
 EXPECT_TRUE(VerifyObject(*Event, {{"ph", "M"}, {"name", "thread_name"}}));
   }
-  ASSERT_NE(++Event, Events->end()) << "Expected span start";
-  EXPECT_TRUE(VerifyObject(*Event, {{"ph", "B"}, {"name", "A"}}));
   ASSERT_NE(++Event, Events->end()) << "Expected log message";
   EXPECT_TRUE(VerifyObject(*Event, {{"ph", "i"}, {"name", "Log"}}));
   ASSERT_NE(++Event, Events->end()) << "Expected span end";
-  EXPECT_TRUE(VerifyObject(*Event, {{"ph", "E"}}));
+  EXPECT_TRUE(VerifyObject(*Event, {{"ph", "X"}, {"name", "A"}}));
   ASSERT_EQ(++Event, Events->end());
   ASSERT_EQ(++Prop, Root->end());
 }
Index: clang-tools-extra/trunk/clangd/Trace.cpp
===
--- clang-tools-extra/trunk/clangd/Trace.cpp
+++ clang-tools-extra/trunk/clangd/Trace.cpp
@@ -16,6 +16,7 @@
 #include "llvm/Support/FormatProviders.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Threading.h"
+#include 
 #include 
 
 namespace clang {
@@ -46,40 +47,103 @@
 Out.flush();
   }
 
+  // We stash a Span object in the context. It will record the start/end,
+  // and this also allows us to look up the parent Span's information.
   Context beginSpan(llvm::StringRef Name, json::obj *Args) override {
-jsonEvent("B", json::obj{{"name", Name}});
-return Context::current().derive(make_scope_exit([this, Args] {
-  jsonEvent("E", json::obj{{"args", std::move(*Args)}});
-}));
+return Context::current().derive(SpanKey,
+ make_unique(this, Name, Args));
+  }
+
+  // Trace viewer requires each thread to properly stack events.
+  // So we need to mark only duration that the span was active on the thread.
+  // (Hopefully any off-thread activity will be connected by a flow event).
+  // Record the end time here, but don't write the event: Args aren't ready yet.
+  void endSpan() override {
+Context::current().getExisting(SpanKey)->markEnded();
   }
 
   void instant(llvm::StringRef Name, json::obj &&Args) override {
+captureThreadMetadata();
 jsonEvent("i", json::obj{{"name", Name}, {"args", std::move(Args)}});
   }
 
   // Record an event on the current thread. ph, pid, tid, ts are set.
   // Contents must be a list of the other JSON key/values.
-  void jsonEvent(StringRef Phase, json::obj &&Contents) {
-uint64_t TID = get_threadid();
-std::lock_guard Lock(Mu);
-// If we haven't already, emit metadata describing this thread.
-if (ThreadsWithMD.insert(TID).second) {
-  SmallString<32> Name;
-  get_thread_name(Name);
-  if (!Name.empty()) {
-rawEvent("M", json::obj{
-  {"tid", TID},
-  {"name", "thread_name"},
-  {"args", json::obj{{"name", Name}}},
-  });
-  }
-}
-Contents["ts"] = timestamp();
+  void jsonEvent(StringRef Phase, json::obj &&Contents,
+ uint64_t TID = get_threadid(),
+ double Timestamp = 0) {
+Contents["ts"] = Timestamp ? Timestamp : timestamp();
 Contents["tid"] = TID;
+std::lock_guard Lock(Mu);
 rawEvent(Phase, std::move(Contents));
   }
 
 private:
+  class JSONSpan {
+  public:
+JSONSpan(JSONTracer *Tracer, llvm::StringRef Name, json::obj *Args)
+: StartTime(Tracer->timestamp()), EndTime(0), Name(Name),
+  TID(get_threadid()), Tracer(Tracer), Args(Args) {
+  // ~JSONSpan() may run in a different thread, so we need to capture now.
+  Tracer->captureThreadMetadata();
+
+  // We don't record begin events here (and end events in the destructor)
+  // because B/E pairs have to appear in the right order, which is awkward.
+  // Instead we send the complete (X) event in the destructor.
+
+  // If our parent was on a different thread, add an arrow to this span.
+  auto *Parent = Context::current().get(SpanKey);
+  if (Parent && *Parent && (*Parent)->TID != TID) {
+// If the parent span ended already, then show this as "following" it.
+// Otherwise show us as "parallel".
+double OriginTime = (*Parent)->EndTim

r325221 - [clang-format] Improve ObjC headers detection

2018-02-15 Thread Jacek Olesiak via cfe-commits
Author: jolesiak
Date: Thu Feb 15 00:47:56 2018
New Revision: 325221

URL: http://llvm.org/viewvc/llvm-project?rev=325221&view=rev
Log:
[clang-format] Improve ObjC headers detection

Summary: Detect ObjC characteristic types when they start a line and add 
additional keywords.

Reviewers: benhamilton

Reviewed By: benhamilton

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTestObjC.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=325221&r1=325220&r2=325221&view=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Thu Feb 15 00:47:56 2018
@@ -1440,7 +1440,9 @@ private:
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
+"NSBundle",
 "NSCache",
+"NSCalendar",
 "NSCharacterSet",
 "NSCountedSet",
 "NSData",
@@ -1466,6 +1468,7 @@ private:
 "NSMutableString",
 "NSNumber",
 "NSNumberFormatter",
+"NSObject",
 "NSOrderedSet",
 "NSPoint",
 "NSPointerArray",
@@ -1475,17 +1478,19 @@ private:
 "NSSet",
 "NSSize",
 "NSString",
+"NSTimeZone",
 "NSUInteger",
 "NSURL",
 "NSURLComponents",
 "NSURLQueryItem",
 "NSUUID",
+"NSValue",
 };
 
 for (auto &Line : AnnotatedLines) {
-  for (FormatToken *FormatTok = Line->First->Next; FormatTok;
+  for (FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
-if ((FormatTok->Previous->is(tok::at) &&
+if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
   FormatTok->isObjCAtKeyword(tok::objc_implementation) ||
   FormatTok->isObjCAtKeyword(tok::objc_protocol) ||

Modified: cfe/trunk/unittests/Format/FormatTestObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestObjC.cpp?rev=325221&r1=325220&r2=325221&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestObjC.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestObjC.cpp Thu Feb 15 00:47:56 2018
@@ -113,10 +113,6 @@ TEST(FormatTestObjCStyle, DetectsObjCInH
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
 
-  Style = getStyle("{}", "a.h", "none", "extern NSString *kFoo;\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
-
   Style =
   getStyle("{}", "a.h", "none", "typedef NS_ENUM(NSInteger, Foo) {};\n");
   ASSERT_TRUE((bool)Style);
@@ -126,10 +122,6 @@ TEST(FormatTestObjCStyle, DetectsObjCInH
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
 
-  Style = getStyle("{}", "a.h", "none", "extern NSInteger Foo();\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
-
   Style =
   getStyle("{}", "a.h", "none", "inline void Foo() { Log(@\"Foo\"); }\n");
   ASSERT_TRUE((bool)Style);
@@ -154,6 +146,23 @@ TEST(FormatTestObjCStyle, DetectsObjCInH
"inline void Foo() { int foo[] = {1, 2, 3}; }\n");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+
+  // ObjC characteristic types.
+  Style = getStyle("{}", "a.h", "none", "extern NSString *kFoo;\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", "extern NSInteger Foo();\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", "NSObject *Foo();\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", "NSSet *Foo();\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 }
 
 TEST_F(FormatTestObjC, FormatObjCTryCatch) {


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


[PATCH] D43124: [clang-format] Improve ObjC headers detection

2018-02-15 Thread Jacek Olesiak via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325221: [clang-format] Improve ObjC headers detection 
(authored by jolesiak, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43124?vs=134180&id=134388#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43124

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1440,7 +1440,9 @@
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
+"NSBundle",
 "NSCache",
+"NSCalendar",
 "NSCharacterSet",
 "NSCountedSet",
 "NSData",
@@ -1466,6 +1468,7 @@
 "NSMutableString",
 "NSNumber",
 "NSNumberFormatter",
+"NSObject",
 "NSOrderedSet",
 "NSPoint",
 "NSPointerArray",
@@ -1475,17 +1478,19 @@
 "NSSet",
 "NSSize",
 "NSString",
+"NSTimeZone",
 "NSUInteger",
 "NSURL",
 "NSURLComponents",
 "NSURLQueryItem",
 "NSUUID",
+"NSValue",
 };
 
 for (auto &Line : AnnotatedLines) {
-  for (FormatToken *FormatTok = Line->First->Next; FormatTok;
+  for (FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
-if ((FormatTok->Previous->is(tok::at) &&
+if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
   FormatTok->isObjCAtKeyword(tok::objc_implementation) ||
   FormatTok->isObjCAtKeyword(tok::objc_protocol) ||
Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -113,10 +113,6 @@
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
 
-  Style = getStyle("{}", "a.h", "none", "extern NSString *kFoo;\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
-
   Style =
   getStyle("{}", "a.h", "none", "typedef NS_ENUM(NSInteger, Foo) {};\n");
   ASSERT_TRUE((bool)Style);
@@ -126,10 +122,6 @@
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
 
-  Style = getStyle("{}", "a.h", "none", "extern NSInteger Foo();\n");
-  ASSERT_TRUE((bool)Style);
-  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
-
   Style =
   getStyle("{}", "a.h", "none", "inline void Foo() { Log(@\"Foo\"); }\n");
   ASSERT_TRUE((bool)Style);
@@ -154,6 +146,23 @@
"inline void Foo() { int foo[] = {1, 2, 3}; }\n");
   ASSERT_TRUE((bool)Style);
   EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
+
+  // ObjC characteristic types.
+  Style = getStyle("{}", "a.h", "none", "extern NSString *kFoo;\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", "extern NSInteger Foo();\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", "NSObject *Foo();\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+  Style = getStyle("{}", "a.h", "none", "NSSet *Foo();\n");
+  ASSERT_TRUE((bool)Style);
+  EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
 }
 
 TEST_F(FormatTestObjC, FormatObjCTryCatch) {


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1440,7 +1440,9 @@
 "NSAffineTransform",
 "NSArray",
 "NSAttributedString",
+"NSBundle",
 "NSCache",
+"NSCalendar",
 "NSCharacterSet",
 "NSCountedSet",
 "NSData",
@@ -1466,6 +1468,7 @@
 "NSMutableString",
 "NSNumber",
 "NSNumberFormatter",
+"NSObject",
 "NSOrderedSet",
 "NSPoint",
 "NSPointerArray",
@@ -1475,17 +1478,19 @@
 "NSSet",
 "NSSize",
 "NSString",
+"NSTimeZone",
 "NSUInteger",
 "NSURL",
 "NSURLComponents",
 "NSURLQueryItem",
 "NSUUID",
+"NSValue",
 };
 
 for (auto &Line : AnnotatedLines) {
-  for (FormatToken *FormatTok = Line->First->Next; FormatTok;
+  for (FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
-if ((FormatTok->Previous->is(tok::at) &&
+if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
  (FormatTok->isObjCAtKeyword(tok::objc_interface) ||
   FormatTok->isObjCAtKeyword(tok::objc_implementation) ||
   FormatTok->isObjCAtKeyword(tok::objc_protocol) ||
Index: unittests/Format/FormatTestObjC.cpp

[clang-tools-extra] r325222 - [clang-tidy] New checker for exceptions that are created but not thrown

2018-02-15 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Thu Feb 15 01:08:51 2018
New Revision: 325222

URL: http://llvm.org/viewvc/llvm-project?rev=325222&view=rev
Log:
[clang-tidy] New checker for exceptions that are created but not thrown

Patch by: Kristof Umann

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

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-throw-keyword-missing.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-throw-keyword-missing.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=325222&r1=325221&r2=325222&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Thu Feb 
15 01:08:51 2018
@@ -25,6 +25,7 @@
 #include "MultipleStatementMacroCheck.h"
 #include "StringConstructorCheck.h"
 #include "SuspiciousMemsetUsageCheck.h"
+#include "ThrowKeywordMissingCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
 #include "UseAfterMoveCheck.h"
 #include "VirtualNearMissCheck.h"
@@ -66,6 +67,8 @@ public:
 "bugprone-string-constructor");
 CheckFactories.registerCheck(
 "bugprone-suspicious-memset-usage");
+CheckFactories.registerCheck(
+"bugprone-throw-keyword-missing");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=325222&r1=325221&r2=325222&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Thu Feb 15 
01:08:51 2018
@@ -17,6 +17,7 @@ add_clang_library(clangTidyBugproneModul
   MultipleStatementMacroCheck.cpp
   StringConstructorCheck.cpp
   SuspiciousMemsetUsageCheck.cpp
+  ThrowKeywordMissingCheck.cpp
   UndefinedMemoryManipulationCheck.cpp
   UseAfterMoveCheck.cpp
   VirtualNearMissCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp?rev=325222&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp 
Thu Feb 15 01:08:51 2018
@@ -0,0 +1,52 @@
+//===--- ThrowKeywordMissingCheck.cpp - 
clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ThrowKeywordMissingCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  auto CtorInitializerList =
+  cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
+
+  Finder->addMatcher(
+  expr(anyOf(cxxFunctionalCastExpr(), cxxBindTemporaryExpr(),
+ cxxTemporaryObjectExpr()),
+   hasType(cxxRecordDecl(
+   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
+   unless(anyOf(hasAncestor(stmt(
+anyOf(cxxThrowExpr(), callExpr(), returnStmt(,
+hasAncestor(varDecl()),
+allOf(hasAncestor(CtorInitializerList),
+  unless(hasAncestor(cxxCatchStmt()))
+  .bind("temporary-exception-not-thrown"),
+  this); 
+}
+
+void ThrowKeywordMissingCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *TemporaryExpr =
+  Result.Nodes.getNodeAs("temporary-exception-not-thrown");
+
+  diag(TemporaryExpr->getLocStart(), "suspicious exception object created but "
+ "not thrown; did you mean 'throw %0'?")
+

[PATCH] D43120: [clang-tidy] New checker for exceptions that are created but not thrown

2018-02-15 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325222: [clang-tidy] New checker for exceptions that are 
created but not thrown (authored by xazax, committed by ).
Herald added subscribers: llvm-commits, klimek.

Changed prior to commit:
  https://reviews.llvm.org/D43120?vs=134174&id=134389#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43120

Files:
  clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-throw-keyword-missing.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/bugprone-throw-keyword-missing.cpp

Index: clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.h
@@ -0,0 +1,36 @@
+//===--- ThrowKeywordMissingCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_THROWKEYWORDMISSINGCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_THROWKEYWORDMISSINGCHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+/// Emits a warning about temporary objects whose type is (or is derived from) a
+/// class that has 'EXCEPTION', 'Exception' or 'exception' in its name.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-throw-keyword-missing.html
+class ThrowKeywordMissingCheck : public ClangTidyCheck {
+public:
+  ThrowKeywordMissingCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace bugprone
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_THROWKEYWORDMISSINGCHECK_H
Index: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -25,6 +25,7 @@
 #include "MultipleStatementMacroCheck.h"
 #include "StringConstructorCheck.h"
 #include "SuspiciousMemsetUsageCheck.h"
+#include "ThrowKeywordMissingCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
 #include "UseAfterMoveCheck.h"
 #include "VirtualNearMissCheck.h"
@@ -66,6 +67,8 @@
 "bugprone-string-constructor");
 CheckFactories.registerCheck(
 "bugprone-suspicious-memset-usage");
+CheckFactories.registerCheck(
+"bugprone-throw-keyword-missing");
 CheckFactories.registerCheck(
 "bugprone-undefined-memory-manipulation");
 CheckFactories.registerCheck(
Index: clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/bugprone/ThrowKeywordMissingCheck.cpp
@@ -0,0 +1,52 @@
+//===--- ThrowKeywordMissingCheck.cpp - clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ThrowKeywordMissingCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+void ThrowKeywordMissingCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  auto CtorInitializerList =
+  cxxConstructorDecl(hasAnyConstructorInitializer(anything()));
+
+  Finder->addMatcher(
+  expr(anyOf(cxxFunctionalCastExpr(), cxxBindTemporaryExpr(),
+ cxxTemporaryObjectExpr()),
+   hasType(cxxRecordDecl(
+   isSameOrDerivedFrom(matchesName("[Ee]xception|EXCEPTION",
+   unless(anyOf(hasAncestor(stmt(
+anyOf

[clang-tools-extra] r325223 - [clang-tidy] Minor documentation fix

2018-02-15 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Thu Feb 15 01:19:23 2018
New Revision: 325223

URL: http://llvm.org/viewvc/llvm-project?rev=325223&view=rev
Log:
[clang-tidy] Minor documentation fix

Modified:

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-throw-keyword-missing.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-throw-keyword-missing.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-throw-keyword-missing.rst?rev=325223&r1=325222&r2=325223&view=diff
==
--- 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-throw-keyword-missing.rst
 (original)
+++ 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-throw-keyword-missing.rst
 Thu Feb 15 01:19:23 2018
@@ -10,6 +10,7 @@ object's type derives from (or is the sa
 Example:
 
 .. code-block:: c++
+
   void f(int i) {
 if (i < 0) {
   // Exception is created but is not thrown.


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


[clang-tools-extra] r325225 - [clang-tidy] Make a test pass on platforms where exceptions disabled by default.

2018-02-15 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Thu Feb 15 01:24:55 2018
New Revision: 325225

URL: http://llvm.org/viewvc/llvm-project?rev=325225&view=rev
Log:
[clang-tidy] Make a test pass on platforms where exceptions disabled by default.

Modified:
clang-tools-extra/trunk/test/clang-tidy/bugprone-throw-keyword-missing.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-throw-keyword-missing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-throw-keyword-missing.cpp?rev=325225&r1=325224&r2=325225&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-throw-keyword-missing.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-throw-keyword-missing.cpp 
Thu Feb 15 01:24:55 2018
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-throw-keyword-missing %t
+// RUN: %check_clang_tidy %s bugprone-throw-keyword-missing %t -- -- 
-fexceptions
 
 namespace std {
 


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


[PATCH] D38639: [clangd] #include statements support for Open definition

2018-02-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Last drop of NITs. After they're fixed, this change is ready to land!




Comment at: unittests/clangd/XRefsTests.cpp:282
+  const char *HeaderContents = R"cpp([[]]int a;)cpp";
+  Annotations HeaderAnnoations(HeaderContents);
+  FS.Files[FooH] = HeaderAnnoations.code();

There's a typo, should be `HeaderAnnotations`



Comment at: unittests/clangd/XRefsTests.cpp:302
+  Locations = ExpectedLocations->Value;
+  EXPECT_TRUE(!Locations.empty());
+  ASSERT_EQ(Locations[0].uri.file, FooH);

NIT: one assertion using `EXPECT_THAT` will read better and produce more 
helpful messages in case of failures:
```
  // Create FooHUri to avoid typing URIForFile everywhere.
  auto FooHUri = URIForFile{FooH.str()};

  EXPECT_THAT(Locations, ElementsAre(Location{FooHUri, 
HeaderAnnoations.range()}));
```




Comment at: unittests/clangd/XRefsTests.cpp:328
+  Locations = ExpectedLocations->Value;
+  EXPECT_TRUE(Locations.empty());
+

NIT: Use `EXPECT_THAT` here too:
`EXPECT_THAT(Locations, IsEmpty());`


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38639



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

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

The clang-tidy code looks good. If no one has further comments, feel free to 
commit it.




Comment at: clang-tidy/readability/SIMDIntrinsicsCheck.cpp:46
+
+  static const llvm::StringMap Mapping{
+// [simd.alg]

MaskRay wrote:
> hokein wrote:
> > consider using `llvm::StringSwitch`?
> The list is currently a scaffold and more operations will be added. It may be 
> more efficient to use a lookup table instead of cascading `.Case("add", ...)`?
I see.  In your case, the normal switch-case statement seems enough? But up to 
you.



Comment at: docs/clang-tidy/checks/readability-simd-intrinsics.rst:8
+
+If the option ``UseStdExperimental`` is set to non-zero, for
+

nit: I think it is stale?



Comment at: test/clang-tidy/readability-simd-intrinsics-ppc.cpp:3
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++11

consider adding test when Suggest is 0?



Comment at: test/clang-tidy/readability-simd-intrinsics-x86.cpp:25
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}

nit: this is not needed. If clang-tidy gives the warning for this case, the lit 
test will fail.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


[PATCH] D43229: [clangd] Enable snippet completion based on client capabilities.

2018-02-15 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: clangd/ClangdLSPServer.cpp:90
 void ClangdLSPServer::onInitialize(InitializeParams &Params) {
+  if (Params.rootUri && !Params.rootUri->file.empty())
+Server.setRootPath(Params.rootUri->file);

This was moved from the end to the top. Is this related to the snippet change 
here?



Comment at: clangd/Protocol.h:184
+  /// Client supports snippets as insert text.
+  llvm::Optional snippetSupport = false;
+  /// Client supports commit characters on a completion item.

Use default `Optional`? I think we would treat empty optional the same as 
`false` anyway?



Comment at: clangd/tool/ClangdMain.cpp:60
 
-static llvm::cl::opt EnableSnippets(
-"enable-snippets",

Would we still have a way to disable snippets (e.g. for debugging) even if 
clients support them? Maybe make this a hidden option instead?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43229



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


[PATCH] D42640: [clangd] collect symbol #include & insert #include in global code completion.

2018-02-15 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 134394.
ioeric added a comment.

- Merged with origin/master


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42640

Files:
  clangd/CMakeLists.txt
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/CodeComplete.cpp
  clangd/Headers.cpp
  clangd/Headers.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
  clangd/index/CanonicalIncludes.cpp
  clangd/index/CanonicalIncludes.h
  clangd/index/Index.cpp
  clangd/index/Index.h
  clangd/index/Merge.cpp
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolCollector.h
  clangd/index/SymbolYAML.cpp
  clangd/tool/ClangdMain.cpp
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  test/clangd/insert-include.test
  unittests/clangd/CMakeLists.txt
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/HeadersTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -47,6 +47,12 @@
 }
 MATCHER_P(QName, Name, "") { return (arg.Scope + arg.Name).str() == Name; }
 MATCHER_P(DeclURI, P, "") { return arg.CanonicalDeclaration.FileURI == P; }
+MATCHER(HasIncludeHeader, "") {
+  return arg.Detail && !arg.Detail->IncludeHeader.empty();
+}
+MATCHER_P(IncludeHeader, P, "") {
+  return arg.Detail && arg.Detail->IncludeHeader == P;
+}
 MATCHER_P(DeclRange, Offsets, "") {
   return arg.CanonicalDeclaration.StartOffset == Offsets.first &&
   arg.CanonicalDeclaration.EndOffset == Offsets.second;
@@ -62,41 +68,62 @@
 namespace {
 class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
 public:
-  SymbolIndexActionFactory(SymbolCollector::Options COpts)
-  : COpts(std::move(COpts)) {}
+  SymbolIndexActionFactory(SymbolCollector::Options COpts,
+   CommentHandler *PragmaHandler)
+  : COpts(std::move(COpts)), PragmaHandler(PragmaHandler) {}
 
   clang::FrontendAction *create() override {
+class WrappedIndexAction : public WrapperFrontendAction {
+public:
+  WrappedIndexAction(std::shared_ptr C,
+ const index::IndexingOptions &Opts,
+ CommentHandler *PragmaHandler)
+  : WrapperFrontendAction(
+index::createIndexingAction(C, Opts, nullptr)),
+PragmaHandler(PragmaHandler) {}
+
+  std::unique_ptr
+  CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
+if (PragmaHandler)
+  CI.getPreprocessor().addCommentHandler(PragmaHandler);
+return WrapperFrontendAction::CreateASTConsumer(CI, InFile);
+  }
+
+private:
+  index::IndexingOptions IndexOpts;
+  CommentHandler *PragmaHandler;
+};
 index::IndexingOptions IndexOpts;
 IndexOpts.SystemSymbolFilter =
 index::IndexingOptions::SystemSymbolFilterKind::All;
 IndexOpts.IndexFunctionLocals = false;
 Collector = std::make_shared(COpts);
-FrontendAction *Action =
-index::createIndexingAction(Collector, IndexOpts, nullptr).release();
-return Action;
+return new WrappedIndexAction(Collector, std::move(IndexOpts),
+  PragmaHandler);
   }
 
   std::shared_ptr Collector;
   SymbolCollector::Options COpts;
+  CommentHandler *PragmaHandler;
 };
 
 class SymbolCollectorTest : public ::testing::Test {
 public:
   SymbolCollectorTest()
-  : TestHeaderName(getVirtualTestFilePath("symbol.h").str()),
+  : InMemoryFileSystem(new vfs::InMemoryFileSystem),
+TestHeaderName(getVirtualTestFilePath("symbol.h").str()),
 TestFileName(getVirtualTestFilePath("symbol.cc").str()) {
 TestHeaderURI = URI::createFile(TestHeaderName).toString();
 TestFileURI = URI::createFile(TestFileName).toString();
   }
 
   bool runSymbolCollector(StringRef HeaderCode, StringRef MainCode,
   const std::vector &ExtraArgs = {}) {
-llvm::IntrusiveRefCntPtr InMemoryFileSystem(
-new vfs::InMemoryFileSystem);
 llvm::IntrusiveRefCntPtr Files(
 new FileManager(FileSystemOptions(), InMemoryFileSystem));
 
-auto Factory = llvm::make_unique(CollectorOpts);
+auto Factory = llvm::make_unique(
+CollectorOpts, PragmaHandler.get());
 
 std::vector Args = {"symbol_collector", "-fsyntax-only",
  "-std=c++11",   "-include",
@@ -117,12 +144,14 @@
   }
 
 protected:
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem;
   std::string TestHeaderName;
   std::string TestHeaderURI;
   std::string TestFileName;
   std::string TestFileURI;
   SymbolSlab Symbols;
   SymbolCollector::Options CollectorOpts;
+  std::unique_ptr PragmaHandler;
 };
 
 TEST_F(SymbolCollectorTest, CollectSymbols) {
@@ -555,6 +584,65 @@
   

[PATCH] D43240: [OpenCL] Fix __enqueue_block for block with captures

2018-02-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks for looking at this. Just one thing, I was wondering whether it 
would be cleaner way if we extend 
test/CodeGenOpenCL/cl20-device-side-enqueue.cl instead of adding a new one 
here? Because this is the test that is meant to exercise all DSE codegen bits. 
Perhaps we can modify one block in that test to have the same format as here 
(i.e. using captures), since  now we test the same block there most of the 
time. However, we don't test any of kernel wrapper `*_block_invoke_kernel` 
there. Not sure why...


https://reviews.llvm.org/D43240



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


[PATCH] D43331: [WIP][Parser][FixIt] Better diagnostics for omitted template keyword (type dependent template names)

2018-02-15 Thread Jan Korous via Phabricator via cfe-commits
jkorous-apple created this revision.

What I would love to have is FixIt for this kind of situation:

  template  void foo() {
  T::bar(); /* missing template keyword */
  }

which currently gets not that helpful diagnostics:

  > clang misleading.cpp
  misleading.cpp:2:15: error: expected '(' for function-style cast or type 
construction
  T::bar();
 ~~~^
  misleading.cpp:2:16: error: expected expression
  T::bar();
 ^
  misleading.cpp:2:18: error: expected expression
  T::bar();
   ^
  3 errors generated.

while

  template  void foo() {
  T::bar();
  }

gets a good one:

  good.cpp:2:8: error: use 'template' keyword to treat 'bar' as a dependent 
template name
  T::bar();
 ^
 template
  1 error generated.

If I understand it correctly than current implementation of

  bool Parser::IsTemplateArgumentList(unsigned Skip)

relies on the fact that if there's a '<' token followed by declaration 
specifier it has to be a template. Which is true but produces false negatives 
for non-type parameters (array<1>) or pointer type parameters (vector) 
(among others).

One particular thing to keep on mind is that there's the [over.over] rule about 
resolving names to function pointers - best explained by test 
test/SemaTemplate/dependent-template-recover.cpp (look for snippet below):

  // Note: no diagnostic here, this is actually valid as a comparison between
  // the decayed pointer to Y::g<> and mb!
  T::g(0);

What I did so far is that in case the simple approach doesn't validate there's 
a template I try to use speculative parsing. The only problem remaining is 
diagnostics - I am able to use TentativeParsingAction which is later reverted 
but I still get all the diagnostics which is incorrect in case my speculation 
about how to parse the code was wrong.


https://reviews.llvm.org/D43331

Files:
  FixIt/fixit-template-for-dependent-name.cpp
  Parse/ParseTemplate.cpp
  SemaTemplate/dependent-template-recover.cpp


Index: SemaTemplate/dependent-template-recover.cpp
===
--- SemaTemplate/dependent-template-recover.cpp
+++ SemaTemplate/dependent-template-recover.cpp
@@ -6,6 +6,7 @@
 t->f0(); // expected-error{{use 'template' keyword to treat 'f0' as a 
dependent template name}}
 
 t->operator+(); // expected-error{{use 'template' keyword to 
treat 'operator +' as a dependent template name}}
+t->operator+<1, U const>(); // expected-error{{use 'template' keyword to 
treat 'operator +' as a dependent template name}}
 t->f1(); // expected-error{{use 'template' keyword to treat 
'f1' as a dependent template name}}
 
 T::getAs(); // expected-error{{use 'template' keyword to treat 'getAs' 
as a dependent template name}}
Index: FixIt/fixit-template-for-dependent-name.cpp
===
--- /dev/null
+++ FixIt/fixit-template-for-dependent-name.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+template  void foo() {
+T::bar(); // expected-error {{use 'template' keyword to treat 'bar' 
as a dependent template name}}
+T::baz(); // expected-error {{use 'template' keyword to treat 'baz' 
as a dependent template name}}
+}
+
+// RUN: not %clang_cc1 -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | 
FileCheck %s
+// CHECK: fix-it:{{.*}}:{4:8-4:8}:"template "
+// CHECK: fix-it:{{.*}}:{5:8-5:8}:"template "
Index: Parse/ParseTemplate.cpp
===
--- Parse/ParseTemplate.cpp
+++ Parse/ParseTemplate.cpp
@@ -1247,30 +1247,45 @@
 /// template argument list (starting with the '<') and never as a '<' 
 /// expression.
 bool Parser::IsTemplateArgumentList(unsigned Skip) {
-  struct AlwaysRevertAction : TentativeParsingAction {
-AlwaysRevertAction(Parser &P) : TentativeParsingAction(P) { }
-~AlwaysRevertAction() { Revert(); }
-  } Tentative(*this);
-  
-  while (Skip) {
-ConsumeAnyToken();
---Skip;
+  {
+RevertingTentativeParsingAction AutoRevertScopeGuard(*this);
+
+for (; Skip > 0; --Skip) {
+  ConsumeToken();
+}
+
+if (!TryConsumeToken(tok::less))
+  return false;
+
+// If the first wannabe template argument consists only of decl specs
+// it's a template argument list indeed.
+
+// See whether we have declaration specifiers, which indicate a type.
+while (isCXXDeclarationSpecifier() == TPResult::True)
+  ConsumeAnyToken();
+
+// If we have a '>' or a ',' then this is a template argument list.
+if (Tok.isOneOf(tok::greater, tok::comma))
+  return true;
   }
-  
-  // '<'
+
+  RevertingTentativeParsingAction AutoRevertScopeGuard(*this);
+
+  for (; Skip > 0; --Skip) {
+ConsumeToken();
+  }
+
   if (!TryConsumeToken(tok::less))
 return false;
 
-  // An empty template argument list.
-  if (Tok.is(tok::greater))
-return true;
-  
-  // See whether we have

[PATCH] D35894: [clangd] Code hover for Clangd

2018-02-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Just a few last remarks and this is good to go.
Should I land it for you after the last comments are fixed?




Comment at: clangd/XRefs.cpp:354
+
+  return Name;
+}

We should call `flush()` before returning `Name` here. The `raw_string_ostream` 
is buffered.



Comment at: clangd/XRefs.cpp:373
+
+  return {};
+}

NIT: use `llvm::None` here instead of `{}`



Comment at: clangd/XRefs.cpp:394
+
+  //  SourceRange SR = D->getSourceRange();
+

Accidental leftover from previous code?



Comment at: unittests/clangd/XRefsTests.cpp:262
+  struct OneTest {
+StringRef input;
+StringRef expectedHover;

NIT: LLVM uses `UpperCamelCase` for field names.



Comment at: unittests/clangd/XRefsTests.cpp:561
+
+EXPECT_EQ(H.contents.value, Test.expectedHover.str()) << Test.input;
+  }

simark wrote:
> Note that I used `.str()` here to make the output of failing tests readable 
> and useful.  By default, gtest tries to print StringRef as if it was a 
> container.  I tried to make add a `PrintTo` function to specify how it should 
> be printed, but couldn't get it to work (to have it called by the compiler), 
> so I settled for this.
Thanks for spotting that.
We have a fix for that in LLVM's gtest extensions (D43330).
`str()` can now be removed.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D35894



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


Re: [clang-tools-extra] r325097 - [clangd] Configure clangd tracing with CLANGD_TRACE env instead of -trace flag

2018-02-15 Thread Ilya Biryukov via cfe-commits
On Thu, Feb 15, 2018 at 8:29 AM Sam McCall  wrote:

> On Wed, Feb 14, 2018 at 10:45 AM Ilya Biryukov 
> wrote:
>
>> Personally, I'm not a big fan of environment variables. There are harder
>> to discover than command-line flags and I still have to change editor
>> config often to switch between different builds of clangd.
>> I know it may sound weird, but maybe we could have both the flag and the
>> environment variables? (flag taking the precedence if both are specified)
>>
> Do you use tracing often? Can you describe your workflow?
>
Reasonably often if I need to use it.
It's also easier to change config flag in vscode and hit "debug" than to
set the global environment variable (I happen to often run clangd from
debug instance of VSCode, not from the command line).

(Less concerned about discoverability - this was always a hidden flag
> anyway)
>
A hidden flag is still more discoverable than environment variable.


>
>
>> On Wed, Feb 14, 2018 at 4:22 AM Sam McCall via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: sammccall
>>> Date: Tue Feb 13 19:20:07 2018
>>> New Revision: 325097
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=325097&view=rev
>>> Log:
>>> [clangd] Configure clangd tracing with CLANGD_TRACE env instead of
>>> -trace flag
>>>
>>> Modified:
>>> clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
>>> clang-tools-extra/trunk/test/clangd/trace.test
>>>
>>> Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=325097&r1=325096&r2=325097&view=diff
>>>
>>> ==
>>> --- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
>>> +++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Tue Feb 13
>>> 19:20:07 2018
>>> @@ -17,6 +17,7 @@
>>>  #include "llvm/Support/Path.h"
>>>  #include "llvm/Support/Program.h"
>>>  #include "llvm/Support/raw_ostream.h"
>>> +#include 
>>>  #include 
>>>  #include 
>>>  #include 
>>> @@ -123,12 +124,6 @@ static llvm::cl::opt InputMirrorFi
>>>  "Mirror all LSP input to the specified file. Useful for
>>> debugging."),
>>>  llvm::cl::init(""), llvm::cl::Hidden);
>>>
>>> -static llvm::cl::opt TraceFile(
>>> -"trace",
>>> -llvm::cl::desc(
>>> -"Trace internal events and timestamps in chrome://tracing JSON
>>> format"),
>>> -llvm::cl::init(""), llvm::cl::Hidden);
>>> -
>>>  static llvm::cl::opt EnableIndexBasedCompletion(
>>>  "enable-index-based-completion",
>>>  llvm::cl::desc(
>>> @@ -176,15 +171,18 @@ int main(int argc, char *argv[]) {
>>>  }
>>>}
>>>
>>> -  // Setup tracing facilities.
>>> +  // Setup tracing facilities if CLANGD_TRACE is set. In practice
>>> enabling a
>>> +  // trace flag in your editor's config is annoying, launching with
>>> +  // `CLANGD_TRACE=trace.json vim` is easier.
>>>llvm::Optional TraceStream;
>>>std::unique_ptr Tracer;
>>> -  if (!TraceFile.empty()) {
>>> +  if (auto *TraceFile = getenv("CLANGD_TRACE")) {
>>>  std::error_code EC;
>>>  TraceStream.emplace(TraceFile, /*ref*/ EC, llvm::sys::fs::F_RW);
>>>  if (EC) {
>>> -  TraceFile.reset();
>>> -  llvm::errs() << "Error while opening trace file: " <<
>>> EC.message();
>>> +  TraceStream.reset();
>>> +  llvm::errs() << "Error while opening trace file " << TraceFile <<
>>> ": "
>>> +   << EC.message();
>>>  } else {
>>>Tracer = trace::createJSONTracer(*TraceStream, PrettyPrint);
>>>  }
>>>
>>> Modified: clang-tools-extra/trunk/test/clangd/trace.test
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/trace.test?rev=325097&r1=325096&r2=325097&view=diff
>>>
>>> ==
>>> --- clang-tools-extra/trunk/test/clangd/trace.test (original)
>>> +++ clang-tools-extra/trunk/test/clangd/trace.test Tue Feb 13 19:20:07
>>> 2018
>>> @@ -1,4 +1,4 @@
>>> -# RUN: clangd -lit-test -trace %t < %s && FileCheck %s < %t
>>> +# RUN: CLANGD_TRACE=%t clangd -lit-test < %s && FileCheck %s < %t
>>>
>>>  
>>> {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
>>>  ---
>>>  
>>> {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"void
>>> main() {}"}}}
>>>
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-commits@lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>>
>>
>>
>> --
>> Regards,
>> Ilya Biryukov
>>
>

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


[PATCH] D43303: [Format] Fix for bug 35641

2018-02-15 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Thanks for the fix.




Comment at: unittests/Format/FormatTest.cpp:9453
+
+  // Bug 35641
+  Alignment.AlignConsecutiveDeclarations = true;

Make this "See llvm.org/PR35641".



Comment at: unittests/Format/FormatTest.cpp:9457
+   "  int b;\n"
+   "  int c;\n"
+   "}",

Might be useful to use different types here to verify that alignment is 
actually happening, e.g. "int" and "unsigned".


Repository:
  rC Clang

https://reviews.llvm.org/D43303



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


[PATCH] D43229: [clangd] Enable snippet completion based on client capabilities.

2018-02-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 134405.
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

- Remove initializers from Optional<> fields


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43229

Files:
  clangd/ClangdLSPServer.cpp
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/tool/ClangdMain.cpp
  test/clangd/completion-snippets-disabled.test
  test/clangd/completion-snippets-enabled.test
  test/clangd/completion-snippets-missing.test

Index: test/clangd/completion-snippets-missing.test
===
--- /dev/null
+++ test/clangd/completion-snippets-missing.test
@@ -0,0 +1,35 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+# RUN: clangd -lit-test -pch-storage=memory < %s | FileCheck -strict-whitespace %s
+{
+  "jsonrpc": "2.0",
+  "id": 0,
+  "method": "initialize",
+  "params": {
+"processId": 123,
+"rootPath": "clangd",
+"capabilities": {},
+"trace": "off"
+  }
+}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"int func_with_args(int a, int b);\nint main() {\nfunc_with\n}"}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":2,"character":7}}}
+#  CHECK:  "id": 1
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": {
+# CHECK-NEXT:"isIncomplete": {{.*}}
+# CHECK-NEXT:"items": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "detail": "int",
+# CHECK-NEXT:  "filterText": "func_with_args",
+# CHECK-NEXT:  "insertText": "func_with_args",
+# CHECK-NEXT:  "insertTextFormat": 1,
+# CHECK-NEXT:  "kind": 3,
+# CHECK-NEXT:  "label": "func_with_args(int a, int b)",
+# CHECK-NEXT:  "sortText": "{{.*}}func_with_args"
+# CHECK-NEXT:}
+# CHECK-NEXT:]
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":4,"method":"shutdown"}
Index: test/clangd/completion-snippets-enabled.test
===
--- /dev/null
+++ test/clangd/completion-snippets-enabled.test
@@ -0,0 +1,43 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+# RUN: clangd -lit-test -pch-storage=memory < %s | FileCheck -strict-whitespace %s
+{
+  "jsonrpc": "2.0",
+  "id": 0,
+  "method": "initialize",
+  "params": {
+"processId": 123,
+"rootPath": "clangd",
+"capabilities": {
+  "textDocument": {
+"completion": {
+  "completionItem": {
+"snippetSupport": true
+  }
+}
+  }
+},
+"trace": "off"
+  }
+}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"int func_with_args(int a, int b);\nint main() {\nfunc_with\n}"}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":2,"character":7}}}
+#  CHECK:  "id": 1
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": {
+# CHECK-NEXT:"isIncomplete": {{.*}}
+# CHECK-NEXT:"items": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "detail": "int",
+# CHECK-NEXT:  "filterText": "func_with_args",
+# CHECK-NEXT:  "insertText": "func_with_args(${1:int a}, ${2:int b})",
+# CHECK-NEXT:  "insertTextFormat": 2,
+# CHECK-NEXT:  "kind": 3,
+# CHECK-NEXT:  "label": "func_with_args(int a, int b)",
+# CHECK-NEXT:  "sortText": "{{.*}}func_with_args"
+# CHECK-NEXT:}
+# CHECK-NEXT:]
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":4,"method":"shutdown"}
Index: test/clangd/completion-snippets-disabled.test
===
--- /dev/null
+++ test/clangd/completion-snippets-disabled.test
@@ -0,0 +1,43 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+# RUN: clangd -lit-test -pch-storage=memory < %s | FileCheck -strict-whitespace %s
+{
+  "jsonrpc": "2.0",
+  "id": 0,
+  "method": "initialize",
+  "params": {
+"processId": 123,
+"rootPath": "clangd",
+"capabilities": {
+  "textDocument": {
+"completion": {
+  "completionItem": {
+"snippetSupport": false
+  }
+}
+  }
+},
+"trace": "off"
+  }
+}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"int func_with_args(int a, int b);\nint main() {\nfunc_with\n}"}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":2,"character":7}}}
+#  CHECK:  "id": 1
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": {
+# CHECK-NEXT:"isIncomplete": {{.*}}
+# CHECK-NEXT:"items": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "detail": "int",
+# CHECK-NEXT:  "filterTex

[PATCH] D43229: [clangd] Enable snippet completion based on client capabilities.

2018-02-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdLSPServer.cpp:90
 void ClangdLSPServer::onInitialize(InitializeParams &Params) {
+  if (Params.rootUri && !Params.rootUri->file.empty())
+Server.setRootPath(Params.rootUri->file);

ioeric wrote:
> This was moved from the end to the top. Is this related to the snippet change 
> here?
Not really, I just thought it's nicer to `reply` after we process the request 
(e.g., if we crash for any reason it will happen before client receives the 
reply).
Can move it back down. WDYT?



Comment at: clangd/Protocol.h:184
+  /// Client supports snippets as insert text.
+  llvm::Optional snippetSupport = false;
+  /// Client supports commit characters on a completion item.

ioeric wrote:
> Use default `Optional`? I think we would treat empty optional the same as 
> `false` anyway?
Thanks for spotting that, I forgot to update this.



Comment at: clangd/tool/ClangdMain.cpp:60
 
-static llvm::cl::opt EnableSnippets(
-"enable-snippets",

ioeric wrote:
> Would we still have a way to disable snippets (e.g. for debugging) even if 
> clients support them? Maybe make this a hidden option instead?
I'm tempted to say in that case we could just recompile clangd so that it 
ignores the options (i.e. change `onInitialized`). The code that will take it 
into account would be a bit trickier (you can't just pass `CodeCompleteOptions` 
to `ClangdLSPServer`, we'll also have to pass `Optional 
OverridenEnableSnippets`).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43229



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


Re: [PATCH] D43120: [clang-tidy] New checker for exceptions that are created but not thrown

2018-02-15 Thread Aaron Ballman via cfe-commits
On Thu, Feb 15, 2018 at 4:11 AM, Phabricator via Phabricator
 wrote:
> This revision was automatically updated to reflect the committed changes.
> Closed by commit rL325222: [clang-tidy] New checker for exceptions that are 
> created but not thrown (authored by xazax, committed by ).

There's nothing wrong with this patch, but it is odd that the
automated text describes the author but not the committer. I wonder if
that's a bug?

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


[PATCH] D43183: clang-format: introduce `CaseBlockIndent` to control indent in switch

2018-02-15 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

Yes, that's what I mean. What do you mean, the style is too error prone?


Repository:
  rC Clang

https://reviews.llvm.org/D43183



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


[PATCH] D43227: [clangd] Make functions of ClangdServer callback-based

2018-02-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 134406.
ilya-biryukov added a comment.

- Rebase onto head


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43227

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  unittests/clangd/ClangdTests.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/SyncAPI.cpp
  unittests/clangd/SyncAPI.h
  unittests/clangd/XRefsTests.cpp

Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -10,6 +10,7 @@
 #include "ClangdUnit.h"
 #include "Compiler.h"
 #include "Matchers.h"
+#include "SyncAPI.h"
 #include "TestFS.h"
 #include "XRefs.h"
 #include "clang/Frontend/CompilerInvocation.h"
@@ -249,7 +250,8 @@
   FS.Files[FooCpp] = "";
 
   Server.addDocument(FooCpp, SourceAnnotations.code());
-  auto Locations = Server.findDefinitions(FooCpp, SourceAnnotations.point());
+  auto Locations =
+  runFindDefinitions(Server, FooCpp, SourceAnnotations.point());
   EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
 
   EXPECT_THAT(Locations->Value,
Index: unittests/clangd/SyncAPI.h
===
--- unittests/clangd/SyncAPI.h
+++ unittests/clangd/SyncAPI.h
@@ -22,6 +22,22 @@
 runCodeComplete(ClangdServer &Server, PathRef File, Position Pos,
 clangd::CodeCompleteOptions Opts,
 llvm::Optional OverridenContents = llvm::None);
+
+llvm::Expected>
+runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos,
+ llvm::Optional OverridenContents = llvm::None);
+
+llvm::Expected>>
+runFindDefinitions(ClangdServer &Server, PathRef File, Position Pos);
+
+llvm::Expected>>
+runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos);
+
+llvm::Expected>
+runRename(ClangdServer &Server, PathRef File, Position Pos, StringRef NewName);
+
+std::string runDumpAST(ClangdServer &Server, PathRef File);
+
 } // namespace clangd
 } // namespace clang
 
Index: unittests/clangd/SyncAPI.cpp
===
--- unittests/clangd/SyncAPI.cpp
+++ unittests/clangd/SyncAPI.cpp
@@ -17,7 +17,9 @@
 ///T Result;
 ///someAsyncFunc(Param1, Param2, /*Callback=*/capture(Result));
 template  struct CaptureProxy {
-  CaptureProxy(T &Target) : Target(&Target) {}
+  CaptureProxy(llvm::Optional &Target) : Target(&Target) {
+assert(!Target.hasValue());
+  }
 
   CaptureProxy(const CaptureProxy &) = delete;
   CaptureProxy &operator=(const CaptureProxy &) = delete;
@@ -39,27 +41,63 @@
 if (!Target)
   return;
 assert(Future.valid() && "conversion to callback was not called");
-*Target = Future.get();
+assert(!Target->hasValue());
+Target->emplace(Future.get());
   }
 
 private:
-  T *Target;
+  llvm::Optional *Target;
   std::promise Promise;
   std::future Future;
 };
 
-template  CaptureProxy capture(T &Target) {
+template  CaptureProxy capture(llvm::Optional &Target) {
   return CaptureProxy(Target);
 }
 } // namespace
 
 Tagged
 runCodeComplete(ClangdServer &Server, PathRef File, Position Pos,
 clangd::CodeCompleteOptions Opts,
 llvm::Optional OverridenContents) {
-  Tagged Result;
+  llvm::Optional> Result;
   Server.codeComplete(File, Pos, Opts, capture(Result), OverridenContents);
-  return Result;
+  return std::move(*Result);
+}
+
+llvm::Expected>
+runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos,
+ llvm::Optional OverridenContents) {
+  llvm::Optional>> Result;
+  Server.signatureHelp(File, Pos, capture(Result), OverridenContents);
+  return std::move(*Result);
+}
+
+llvm::Expected>>
+runFindDefinitions(ClangdServer &Server, PathRef File, Position Pos) {
+  llvm::Optional>>> Result;
+  Server.findDefinitions(File, Pos, capture(Result));
+  return std::move(*Result);
+}
+
+llvm::Expected>>
+runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos) {
+  llvm::Optional>>> Result;
+  Server.findDocumentHighlights(File, Pos, capture(Result));
+  return std::move(*Result);
+}
+
+llvm::Expected>
+runRename(ClangdServer &Server, PathRef File, Position Pos, StringRef NewName) {
+  llvm::Optional>> Result;
+  Server.rename(File, Pos, NewName, capture(Result));
+  return std::move(*Result);
+}
+
+std::string runDumpAST(ClangdServer &Server, PathRef File) {
+  llvm::Optional Result;
+  Server.dumpAST(File, capture(Result));
+  return std::move(*Result);
 }
 
 } // namespace clangd
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -626,7 +626,7 @@
   Annotations Test(Text);
   Server.addDocument(File, Test.code());
   EXPECT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for preamble";
-  

Re: [PATCH] D43120: [clang-tidy] New checker for exceptions that are created but not thrown

2018-02-15 Thread Roman Lebedev via cfe-commits
On Thu, Feb 15, 2018 at 3:48 PM, Aaron Ballman via cfe-commits
 wrote:
> On Thu, Feb 15, 2018 at 4:11 AM, Phabricator via Phabricator
>  wrote:
>> This revision was automatically updated to reflect the committed changes.
>> Closed by commit rL325222: [clang-tidy] New checker for exceptions that are 
>> created but not thrown (authored by xazax, committed by ).
>
> There's nothing wrong with this patch, but it is odd that the
> automated text describes the author but not the committer. I wonder if
> that's a bug?

Committed xazax Thu, Feb 15, 12:08
But there is no https://reviews.llvm.org/p/xazax/, only
https://reviews.llvm.org/p/xazax.hun/

I get that too.
Because committer name (i.e. svn username) does not verbatim match the
Phab username verbatim.

It is a bug i'd say, the match should be email-based.

> ~Aaron
Roman.

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


[PATCH] D43229: [clangd] Enable snippet completion based on client capabilities.

2018-02-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/tool/ClangdMain.cpp:60
 
-static llvm::cl::opt EnableSnippets(
-"enable-snippets",

ilya-biryukov wrote:
> ioeric wrote:
> > Would we still have a way to disable snippets (e.g. for debugging) even if 
> > clients support them? Maybe make this a hidden option instead?
> I'm tempted to say in that case we could just recompile clangd so that it 
> ignores the options (i.e. change `onInitialized`). The code that will take it 
> into account would be a bit trickier (you can't just pass 
> `CodeCompleteOptions` to `ClangdLSPServer`, we'll also have to pass 
> `Optional OverridenEnableSnippets`).
+1 to this - this is really a debugging option, and supporting it has a cost.

If we want debugging options to live forever (may be reasonable!) we need a 
more scalable way to define them than listing them all in ClangdMain.



Comment at: test/clangd/completion-snippets-disabled.test:1
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+# RUN: clangd -lit-test -pch-storage=memory < %s | FileCheck 
-strict-whitespace %s

Please don't add three new lit tests for this. One should be certainly enough 
(off, assuming our normal completion test has this feature on). 

But really I think this can be a unit test in CodeComplete tests instead, right?

If you really want to verify how missing `snippetSupport` parses, that's a 
unittest for protocol.h right? But it doesn't seem important.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43229



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


[PATCH] D43312: [clang-format] fix handling of consecutive unary operators

2018-02-15 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:1497
+!(PrevToken->is(tok::exclaim) &&
+  Style.Language == FormatStyle::LK_JavaScript))
   // There aren't any trailing unary operators except for TypeScript's

I think that TypeScript has both `if (!cond)` and `x!`. I'd expect that `if 
(!+i) {\n}` is also handled in the TypeScript case. Could you add a test for 
this for TypeScript please.


Repository:
  rC Clang

https://reviews.llvm.org/D43312



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


[PATCH] D41880: Adding nocf_check attribute for cf-protection fine tuning

2018-02-15 Thread Oren Ben Simhon via Phabricator via cfe-commits
oren_ben_simhon marked 5 inline comments as done.
oren_ben_simhon added inline comments.



Comment at: lib/Sema/SemaDeclAttr.cpp:1990
 
-bool Sema::CheckNoReturnAttr(const AttributeList &Attrs) {
-  if (!checkAttributeNumArgs(*this, Attrs, 0)) {
-Attrs.setInvalid();
+static void handleNoCfCheckAttr(Sema &S, Decl *D, const AttributeList &attr) {
+  if (S.CheckAttrTarget(attr) || S.CheckAttrNoArgs(attr))

aaron.ballman wrote:
> aaron.ballman wrote:
> > `attr` doesn't follow the proper naming conventions.
> Please don't name the parameter variable after a type -- that can confuse 
> some editors.
I am following the same convention that other functions are using.



Comment at: test/Sema/attr-nocf_check.c:18-20
+  FuncPointerWithNoCfCheck fNoCfCheck = f; // no-warning
+  (*fNoCfCheck)();   // no-warning
+  f = fNoCfCheck;// no-warning

aaron.ballman wrote:
> These are an error in GCC and I think we should match that behavior. 
> https://godbolt.org/g/r3pf4X
I will create a warning however in LLVM we don't create an error upon 
incompatible pointer due to function attribute types.


Repository:
  rL LLVM

https://reviews.llvm.org/D41880



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


[PATCH] D43290: clang-format: tweak formatting of variable initialization blocks

2018-02-15 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

Tweaking the penalty handling would still be needed in any case, since the 
problem happens also when Cpp11BracedListStyle is true (though the effect is 
more subtle)

Generally, I think it is better to just rely on penalties, since it gives a way 
to compare and weight each solution. Then each style can decide what should 
break first: e.g. a style may also have a lower `PenaltyBreakAssignment`, thus 
wrapping after the equal sign would be expected...


Repository:
  rC Clang

https://reviews.llvm.org/D43290



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


[PATCH] D41880: Adding nocf_check attribute for cf-protection fine tuning

2018-02-15 Thread Oren Ben Simhon via Phabricator via cfe-commits
oren_ben_simhon updated this revision to Diff 134407.
oren_ben_simhon added a comment.

Implemented comments posted until 02/15 (Thanks Aaron)


Repository:
  rL LLVM

https://reviews.llvm.org/D41880

Files:
  include/clang/AST/Type.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/CodeGen/CGFunctionInfo.h
  include/clang/Sema/Sema.h
  lib/AST/ASTContext.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/CodeGen/CGCall.cpp
  lib/Sema/SemaDeclAttr.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/CodeGen/attributes.c
  test/CodeGen/cetintrin.c
  test/CodeGen/x86-cf-protection.c
  test/Misc/pragma-attribute-supported-attributes-list.test
  test/Sema/attr-nocf_check.c

Index: test/Sema/attr-nocf_check.c
===
--- /dev/null
+++ test/Sema/attr-nocf_check.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -verify -fsyntax-only %s
+
+// Function pointer definition.
+typedef void (*FuncPointerWithNoCfCheck)(void) __attribute__((nocf_check)); // no-warning
+typedef void (*FuncPointer)(void);
+
+// Dont allow function declaration and definition mismatch.
+void __attribute__((nocf_check)) testNoCfCheck();   // expected-note {{previous declaration is here}}
+void testNoCfCheck(){}; //  expected-error {{conflicting types for 'testNoCfCheck'}}
+
+// No variable or parameter declaration
+__attribute__((nocf_check)) int i;  // expected-warning {{'nocf_check' attribute only applies to function}}
+void testNoCfCheckImpl(double __attribute__((nocf_check)) i) {} // expected-warning {{'nocf_check' attribute only applies to function}}
+
+// Allow attributed function pointers as well as casting between attributed
+// and non-attributed function pointers.
+void testNoCfCheckMismatch(FuncPointer f) {
+  FuncPointerWithNoCfCheck fNoCfCheck = f; // expected-warning {{incompatible function pointer types}}
+  (*fNoCfCheck)(); // no-warning
+  f = fNoCfCheck;  // expected-warning {{incompatible function pointer types}}
+}
+
+// 'nocf_check' Attribute has no parameters.
+int testNoCfCheckParams() __attribute__((nocf_check(1))); // expected-error {{'nocf_check' attribute takes no arguments}}
Index: test/Misc/pragma-attribute-supported-attributes-list.test
===
--- test/Misc/pragma-attribute-supported-attributes-list.test
+++ test/Misc/pragma-attribute-supported-attributes-list.test
@@ -2,7 +2,7 @@
 
 // The number of supported attributes should never go down!
 
-// CHECK: #pragma clang attribute supports 66 attributes:
+// CHECK: #pragma clang attribute supports 67 attributes:
 // CHECK-NEXT: AMDGPUFlatWorkGroupSize (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumSGPR (SubjectMatchRule_function)
 // CHECK-NEXT: AMDGPUNumVGPR (SubjectMatchRule_function)
@@ -12,6 +12,7 @@
 // CHECK-NEXT: AlignValue (SubjectMatchRule_variable, SubjectMatchRule_type_alias)
 // CHECK-NEXT: AllocSize (SubjectMatchRule_function)
 // CHECK-NEXT: Annotate ()
+// CHECK-NEXT: AnyX86NoCfCheck (SubjectMatchRule_hasType_functionType)
 // CHECK-NEXT: AssumeAligned (SubjectMatchRule_objc_method, SubjectMatchRule_function)
 // CHECK-NEXT: Availability ((SubjectMatchRule_record, SubjectMatchRule_enum, SubjectMatchRule_enum_constant, SubjectMatchRule_field, SubjectMatchRule_function, SubjectMatchRule_namespace, SubjectMatchRule_objc_category, SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, SubjectMatchRule_record, SubjectMatchRule_type_alias, SubjectMatchRule_variable))
 // CHECK-NEXT: CXX11NoReturn (SubjectMatchRule_function)
Index: test/CodeGen/x86-cf-protection.c
===
--- test/CodeGen/x86-cf-protection.c
+++ test/CodeGen/x86-cf-protection.c
@@ -1,5 +1,5 @@
-// RUN: not %clang_cc1 -fsyntax-only -S -emit-llvm -o %t -triple i386-unknown-unknown -fcf-protection=return %s 2>&1 | FileCheck %s --check-prefix=RETURN
-// RUN: not %clang_cc1 -fsyntax-only -S -emit-llvm -o %t -triple i386-unknown-unknown -fcf-protection=branch %s 2>&1 | FileCheck %s --check-prefix=BRANCH
+// RUN: not %clang_cc1 -fsyntax-only -S -o %t -triple i386-unknown-unknown -fcf-protection=return %s 2>&1 | FileCheck %s --check-prefix=RETURN
+// RUN: not %clang_cc1 -fsyntax-only -S -o %t -triple i386-unknown-unknown -fcf-protection=branch %s 2>&1 | FileCheck %s --check-prefix=BRANCH
 
 // RETURN: error: option 'cf-protection=return' cannot be specified without '-mshstk'
 // BRANCH: error: option 'cf-protection=branch' cannot be specified without '-mibt'
Index: test/CodeGen/cetintrin.c
===
--- test/CodeGen/cetintrin.c
+++ test/CodeGen/cetintrin.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=i386-apple-darwin -targe

[clang-tools-extra] r325233 - [clangd] Make functions of ClangdServer callback-based

2018-02-15 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Feb 15 05:15:47 2018
New Revision: 325233

URL: http://llvm.org/viewvc/llvm-project?rev=325233&view=rev
Log:
[clangd] Make functions of ClangdServer callback-based

Summary:
As a consequence, all LSP operations are now handled asynchronously,
i.e. they never block the main processing thread. However, if
-run-synchronously flag is specified, clangd still runs everything on
the main thread.

Reviewers: sammccall, ioeric, hokein

Reviewed By: sammccall, ioeric

Subscribers: klimek, jkorous-apple, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.h
clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=325233&r1=325232&r2=325233&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Feb 15 05:15:47 2018
@@ -180,23 +180,25 @@ void ClangdLSPServer::onCommand(ExecuteC
 }
 
 void ClangdLSPServer::onRename(RenameParams &Params) {
-  auto File = Params.textDocument.uri.file;
-  auto Code = Server.getDocument(File);
+  Path File = Params.textDocument.uri.file;
+  llvm::Optional Code = Server.getDocument(File);
   if (!Code)
 return replyError(ErrorCode::InvalidParams,
   "onRename called for non-added file");
 
-  auto Replacements = Server.rename(File, Params.position, Params.newName);
-  if (!Replacements) {
-replyError(ErrorCode::InternalError,
-   llvm::toString(Replacements.takeError()));
-return;
-  }
-
-  std::vector Edits = replacementsToEdits(*Code, *Replacements);
-  WorkspaceEdit WE;
-  WE.changes = {{Params.textDocument.uri.uri(), Edits}};
-  reply(WE);
+  Server.rename(
+  File, Params.position, Params.newName,
+  [File, Code,
+   Params](llvm::Expected> Replacements) 
{
+if (!Replacements)
+  return replyError(ErrorCode::InternalError,
+llvm::toString(Replacements.takeError()));
+
+std::vector Edits = replacementsToEdits(*Code, 
*Replacements);
+WorkspaceEdit WE;
+WE.changes = {{Params.textDocument.uri.uri(), Edits}};
+reply(WE);
+  });
 }
 
 void ClangdLSPServer::onDocumentDidClose(DidCloseTextDocumentParams &Params) {
@@ -280,21 +282,25 @@ void ClangdLSPServer::onCompletion(TextD
 }
 
 void ClangdLSPServer::onSignatureHelp(TextDocumentPositionParams &Params) {
-  auto SignatureHelp =
-  Server.signatureHelp(Params.textDocument.uri.file, Params.position);
-  if (!SignatureHelp)
-return replyError(ErrorCode::InvalidParams,
-  llvm::toString(SignatureHelp.takeError()));
-  reply(SignatureHelp->Value);
+  Server.signatureHelp(Params.textDocument.uri.file, Params.position,
+   [](llvm::Expected> SignatureHelp) 
{
+ if (!SignatureHelp)
+   return replyError(
+   ErrorCode::InvalidParams,
+   llvm::toString(SignatureHelp.takeError()));
+ reply(SignatureHelp->Value);
+   });
 }
 
 void ClangdLSPServer::onGoToDefinition(TextDocumentPositionParams &Params) {
-  auto Items =
-  Server.findDefinitions(Params.textDocument.uri.file, Params.position);
-  if (!Items)
-return replyError(ErrorCode::InvalidParams,
-  llvm::toString(Items.takeError()));
-  reply(json::ary(Items->Value));
+  Server.findDefinitions(
+  Params.textDocument.uri.file, Params.position,
+  [](llvm::Expected>> Items) {
+if (!Items)
+  return replyError(ErrorCode::InvalidParams,
+llvm::toString(Items.takeError()));
+reply(json::ary(Items->Value));
+  });
 }
 
 void ClangdLSPServer::onSwitchSourceHeader(TextDocumentIdentifier &Params) {
@@ -303,16 +309,14 @@ void ClangdLSPServer::onSwitchSourceHead
 }
 
 void ClangdLSPServer::onDocumentHighlight(TextDocumentPositionParams &Params) {
-  auto Highlights = Server.findDocumentHighlights(Params.textDocument.uri.file,
-  Params.position);
-
-  if (!Highlights) {
-replyError(ErrorCode::InternalError,
-   llvm::toString(Highlights.takeError()));
-return;
-  }
-
-  reply(json::ary(Highlights->Value));
+  Server.findDocumentHighlights(
+  Params.textDocument.ur

[PATCH] D43227: [clangd] Make functions of ClangdServer callback-based

2018-02-15 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325233: [clangd] Make functions of ClangdServer 
callback-based (authored by ibiryukov, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43227

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.h
  clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
  clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
  clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
  clang-tools-extra/trunk/unittests/clangd/SyncAPI.h
  clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp

Index: clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/ClangdTests.cpp
@@ -96,7 +96,7 @@
 }
 
 std::string dumpASTWithoutMemoryLocs(ClangdServer &Server, PathRef File) {
-  auto DumpWithMemLocs = Server.dumpAST(File);
+  auto DumpWithMemLocs = runDumpAST(Server, File);
   return replacePtrsInDump(DumpWithMemLocs);
 }
 
@@ -432,17 +432,17 @@
   // Clang can't parse command args in that case, but we shouldn't crash.
   Server.addDocument(FooCpp, "int main() {}");
 
-  EXPECT_EQ(Server.dumpAST(FooCpp), "");
-  EXPECT_ERROR(Server.findDefinitions(FooCpp, Position()));
-  EXPECT_ERROR(Server.findDocumentHighlights(FooCpp, Position()));
-  EXPECT_ERROR(Server.rename(FooCpp, Position(), "new_name"));
+  EXPECT_EQ(runDumpAST(Server, FooCpp), "");
+  EXPECT_ERROR(runFindDefinitions(Server, FooCpp, Position()));
+  EXPECT_ERROR(runFindDocumentHighlights(Server, FooCpp, Position()));
+  EXPECT_ERROR(runRename(Server, FooCpp, Position(), "new_name"));
   // FIXME: codeComplete and signatureHelp should also return errors when they
   // can't parse the file.
   EXPECT_THAT(
   runCodeComplete(Server, FooCpp, Position(), clangd::CodeCompleteOptions())
   .Value.items,
   IsEmpty());
-  auto SigHelp = Server.signatureHelp(FooCpp, Position());
+  auto SigHelp = runSignatureHelp(Server, FooCpp, Position());
   ASSERT_TRUE(bool(SigHelp)) << "signatureHelp returned an error";
   EXPECT_THAT(SigHelp->Value.signatures, IsEmpty());
 }
@@ -646,7 +646,7 @@
   Pos.line = LineDist(RandGen);
   Pos.character = ColumnDist(RandGen);
 
-  ASSERT_TRUE(!!Server.findDefinitions(FilePaths[FileIndex], Pos));
+  ASSERT_TRUE(!!runFindDefinitions(Server, FilePaths[FileIndex], Pos));
 };
 
 std::vector> AsyncRequests = {
@@ -768,8 +768,8 @@
   public:
 std::atomic Count = {0};
 
- NoConcurrentAccessDiagConsumer(std::promise StartSecondReparse)
- : StartSecondReparse(std::move(StartSecondReparse)) {}
+NoConcurrentAccessDiagConsumer(std::promise StartSecondReparse)
+: StartSecondReparse(std::move(StartSecondReparse)) {}
 
 void onDiagnosticsReady(PathRef,
 Tagged>) override {
Index: clang-tools-extra/trunk/unittests/clangd/SyncAPI.h
===
--- clang-tools-extra/trunk/unittests/clangd/SyncAPI.h
+++ clang-tools-extra/trunk/unittests/clangd/SyncAPI.h
@@ -22,6 +22,22 @@
 runCodeComplete(ClangdServer &Server, PathRef File, Position Pos,
 clangd::CodeCompleteOptions Opts,
 llvm::Optional OverridenContents = llvm::None);
+
+llvm::Expected>
+runSignatureHelp(ClangdServer &Server, PathRef File, Position Pos,
+ llvm::Optional OverridenContents = llvm::None);
+
+llvm::Expected>>
+runFindDefinitions(ClangdServer &Server, PathRef File, Position Pos);
+
+llvm::Expected>>
+runFindDocumentHighlights(ClangdServer &Server, PathRef File, Position Pos);
+
+llvm::Expected>
+runRename(ClangdServer &Server, PathRef File, Position Pos, StringRef NewName);
+
+std::string runDumpAST(ClangdServer &Server, PathRef File);
+
 } // namespace clangd
 } // namespace clang
 
Index: clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/XRefsTests.cpp
@@ -10,6 +10,7 @@
 #include "ClangdUnit.h"
 #include "Compiler.h"
 #include "Matchers.h"
+#include "SyncAPI.h"
 #include "TestFS.h"
 #include "XRefs.h"
 #include "clang/Frontend/CompilerInvocation.h"
@@ -249,7 +250,8 @@
   FS.Files[FooCpp] = "";
 
   Server.addDocument(FooCpp, SourceAnnotations.code());
-  auto Locations = Server.findDefinitions(FooCpp, SourceAnnotations.point());
+  auto Locations =
+  runFindDefinitions(Server, FooCpp, SourceAnnotations.point());
   EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
 
   EXPECT_THAT(Locations->Value,
Index: clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp

[PATCH] D43229: [clangd] Enable snippet completion based on client capabilities.

2018-02-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: test/clangd/completion-snippets-disabled.test:1
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+# RUN: clangd -lit-test -pch-storage=memory < %s | FileCheck 
-strict-whitespace %s

sammccall wrote:
> Please don't add three new lit tests for this. One should be certainly enough 
> (off, assuming our normal completion test has this feature on). 
> 
> But really I think this can be a unit test in CodeComplete tests instead, 
> right?
> 
> If you really want to verify how missing `snippetSupport` parses, that's a 
> unittest for protocol.h right? But it doesn't seem important.
> Please don't add three new lit tests for this. One should be certainly enough 
> (off, assuming our normal completion test has this feature on).
Our completion lit test include empty capabilities, we don't test it there at 
all.

> But really I think this can be a unit test in CodeComplete tests instead, 
> right?
We already have a test for that in CodeComplete, but I think we should have a 
small integration test that cover all three cases where snippetSupport is on, 
off and missing.
We could sneak in the "missing" case into the existing `completion.test`, but 
on/off tests are useful to have from my perspective.

> If you really want to verify how missing snippetSupport parses, that's a 
> unittest for protocol.h right? But it doesn't seem important.
I'm not sure checking the parsing code makes sense (it's close to being 
"correct by construction" from my point of view). Checking that LSP outputs the 
right thing seems useful, though.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43229



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


[PATCH] D43298: [clang-format] Support repeated field lists in protos

2018-02-15 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.




Comment at: lib/Format/TokenAnnotator.cpp:2355
+   ((Right.MatchingParen->is(TT_ArrayInitializerLSquare) &&
+ (Style.SpacesInContainerLiterals ||
+  ((Style.Language == FormatStyle::LK_Proto ||

This is almost a duplicate of the one above. Can we pull out a function or 
lambda?


Repository:
  rC Clang

https://reviews.llvm.org/D43298



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


[PATCH] D43272: [clangd] Fix tracing now that spans lifetimes can overlap on a thread.

2018-02-15 Thread Carlos Alberto Enciso via Phabricator via cfe-commits
CarlosAlbertoEnciso added a comment.

Hi,

It seems that your submission have broken the Windows and Linux Builds for 
'clangd'.

This is the error message:

/home/xxx/llvm-root/llvm/tools/clang/tools/extra/clangd/Trace.cpp:54:76: error: 
call of overloaded ‘make_unique(clang::clangd::trace::{anonymous}::JSONTracer*, 
llvm::StringRef&, clang::clangd::json::obj*&)’ is ambiguous

  make_unique(this, Name, Args));
^

Thanks,


Repository:
  rL LLVM

https://reviews.llvm.org/D43272



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


[PATCH] D43290: clang-format: tweak formatting of variable initialization blocks

2018-02-15 Thread Francois Ferrand via Phabricator via cfe-commits
Typz updated this revision to Diff 134411.
Typz marked an inline comment as done.
Typz added a comment.

Address review comments.


Repository:
  rC Clang

https://reviews.llvm.org/D43290

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6650,6 +6650,15 @@
"};");
   verifyFormat("#define A {a, a},");
 
+  // Avoid breaking between equal sign and opening brace
+  FormatStyle AvoidBreakingFirstArgument = getLLVMStyle();
+  AvoidBreakingFirstArgument.PenaltyBreakBeforeFirstCallParameter = 200;
+  verifyFormat("const std::unordered_map MyHashTable = {\n"
+   "{\"a\", 0},\n"
+   "{\"b\", 1},\n"
+   "{\"c\", 2}};",
+   AvoidBreakingFirstArgument);
+
   // Binpacking only if there is no trailing comma
   verifyFormat("const Aa a = {aa, bb,\n"
"  cc, dd};",
@@ -6806,6 +6815,15 @@
   verifyFormat("vector foo = { ::SomeGlobalFunction() };", ExtraSpaces);
   verifyFormat("const struct A a = { .a = 1, .b = 2 };", ExtraSpaces);
   verifyFormat("const struct A a = { [0] = 1, [1] = 2 };", ExtraSpaces);
+
+  // Avoid breaking between equal sign and opening brace
+  ExtraSpaces.PenaltyBreakBeforeFirstCallParameter = 200;
+  verifyFormat("const std::unordered_map MyHashTable = {\n"
+   "  { \"a\", 0 },\n"
+   "  { \"b\", 1 },\n"
+   "  { \"c\", 2 }\n"
+   "};",
+   ExtraSpaces);
 }
 
 TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
@@ -6867,6 +6885,14 @@
" 3, cc};",
getLLVMStyleWithColumns(60));
 
+  // Do not break between equal and opening brace.
+  FormatStyle AvoidBreakingFirstArgument = getLLVMStyleWithColumns(43);
+  AvoidBreakingFirstArgument.PenaltyBreakBeforeFirstCallParameter = 200;
+  AvoidBreakingFirstArgument.ColumnLimit = 43;
+  verifyFormat("vector aa = {\n"
+   "1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};",
+   AvoidBreakingFirstArgument);
+
   // Trailing commas.
   verifyFormat("vector x = {\n"
"1, 1, 1, 1, 1, 1, 1, 1,\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2180,6 +2180,8 @@
   if (Left.opensScope()) {
 if (Style.AlignAfterOpenBracket == FormatStyle::BAS_DontAlign)
   return 0;
+if (Left.Previous && Left.Previous->is(tok::equal))
+  return 19;
 return Left.ParameterCount > 1 ? Style.PenaltyBreakBeforeFirstCallParameter
: 19;
   }


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6650,6 +6650,15 @@
"};");
   verifyFormat("#define A {a, a},");
 
+  // Avoid breaking between equal sign and opening brace
+  FormatStyle AvoidBreakingFirstArgument = getLLVMStyle();
+  AvoidBreakingFirstArgument.PenaltyBreakBeforeFirstCallParameter = 200;
+  verifyFormat("const std::unordered_map MyHashTable = {\n"
+   "{\"a\", 0},\n"
+   "{\"b\", 1},\n"
+   "{\"c\", 2}};",
+   AvoidBreakingFirstArgument);
+
   // Binpacking only if there is no trailing comma
   verifyFormat("const Aa a = {aa, bb,\n"
"  cc, dd};",
@@ -6806,6 +6815,15 @@
   verifyFormat("vector foo = { ::SomeGlobalFunction() };", ExtraSpaces);
   verifyFormat("const struct A a = { .a = 1, .b = 2 };", ExtraSpaces);
   verifyFormat("const struct A a = { [0] = 1, [1] = 2 };", ExtraSpaces);
+
+  // Avoid breaking between equal sign and opening brace
+  ExtraSpaces.PenaltyBreakBeforeFirstCallParameter = 200;
+  verifyFormat("const std::unordered_map MyHashTable = {\n"
+   "  { \"a\", 0 },\n"
+   "  { \"b\", 1 },\n"
+   "  { \"c\", 2 }\n"
+   "};",
+   ExtraSpaces);
 }
 
 TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
@@ -6867,6 +6885,14 @@
" 3, cc};",
getLLVMStyleWithColumns(60));
 
+  // Do not break between equal and opening brace.
+  FormatStyle AvoidBreakingFirstArgument = getLLVMStyleWithColumns(43);
+  AvoidBreakingFirstArgument.PenaltyBreakBeforeFirstCallParameter = 200

r325236 - Add -no-canonical-prefixes to allow different build modes.

2018-02-15 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Thu Feb 15 05:50:07 2018
New Revision: 325236

URL: http://llvm.org/viewvc/llvm-project?rev=325236&view=rev
Log:
Add -no-canonical-prefixes to allow different build modes.

Modified:
cfe/trunk/test/Driver/amdgcn-toolchain-pic.cl

Modified: cfe/trunk/test/Driver/amdgcn-toolchain-pic.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/amdgcn-toolchain-pic.cl?rev=325236&r1=325235&r2=325236&view=diff
==
--- cfe/trunk/test/Driver/amdgcn-toolchain-pic.cl (original)
+++ cfe/trunk/test/Driver/amdgcn-toolchain-pic.cl Thu Feb 15 05:50:07 2018
@@ -1,7 +1,7 @@
-// RUN: %clang -### -target amdgcn-- -mcpu=gfx803 %s 2>&1 | FileCheck %s
-// RUN: %clang -### -target amdgcn-amd- -mcpu=gfx803 %s 2>&1 | FileCheck %s
-// RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx803 %s 2>&1 | FileCheck 
%s
-// RUN: %clang -### -target amdgcn-amd-amdpal -mcpu=gfx803 %s 2>&1 | FileCheck 
%s
-// RUN: %clang -### -target amdgcn-amd-mesa3d -mcpu=gfx803 %s 2>&1 | FileCheck 
%s
+// RUN: %clang -no-canonical-prefixes -### -target amdgcn-- -mcpu=gfx803 %s 
2>&1 | FileCheck %s
+// RUN: %clang -no-canonical-prefixes -### -target amdgcn-amd- -mcpu=gfx803 %s 
2>&1 | FileCheck %s
+// RUN: %clang -no-canonical-prefixes -### -target amdgcn-amd-amdhsa 
-mcpu=gfx803 %s 2>&1 | FileCheck %s
+// RUN: %clang -no-canonical-prefixes -### -target amdgcn-amd-amdpal 
-mcpu=gfx803 %s 2>&1 | FileCheck %s
+// RUN: %clang -no-canonical-prefixes -### -target amdgcn-amd-mesa3d 
-mcpu=gfx803 %s 2>&1 | FileCheck %s
 
 // CHECK: clang{{.*}} "-mrelocation-model" "pic" "-pic-level" "1"


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


[PATCH] D41880: Adding nocf_check attribute for cf-protection fine tuning

2018-02-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Sema/SemaDeclAttr.cpp:1990
 
-bool Sema::CheckNoReturnAttr(const AttributeList &Attrs) {
-  if (!checkAttributeNumArgs(*this, Attrs, 0)) {
-Attrs.setInvalid();
+static void handleNoCfCheckAttr(Sema &S, Decl *D, const AttributeList &attr) {
+  if (S.CheckAttrTarget(attr) || S.CheckAttrNoArgs(attr))

oren_ben_simhon wrote:
> aaron.ballman wrote:
> > aaron.ballman wrote:
> > > `attr` doesn't follow the proper naming conventions.
> > Please don't name the parameter variable after a type -- that can confuse 
> > some editors.
> I am following the same convention that other functions are using.
> I am following the same convention that other functions are using.

They're doing it wrong. I can clean those up in a separate patch.



Comment at: test/Sema/attr-nocf_check.c:18-20
+  FuncPointerWithNoCfCheck fNoCfCheck = f; // no-warning
+  (*fNoCfCheck)();   // no-warning
+  f = fNoCfCheck;// no-warning

oren_ben_simhon wrote:
> aaron.ballman wrote:
> > These are an error in GCC and I think we should match that behavior. 
> > https://godbolt.org/g/r3pf4X
> I will create a warning however in LLVM we don't create an error upon 
> incompatible pointer due to function attribute types.
It should be an error -- Clang does error on this sort of thing when 
appropriate (which I believe it is, here). For instance, calling convention 
attributes do this: https://godbolt.org/g/mkTGLg


Repository:
  rL LLVM

https://reviews.llvm.org/D41880



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


[PATCH] D43303: [Format] Fix for bug 35641

2018-02-15 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 134414.
kadircet added a comment.

Changed description of unit test to include direct link to bug.
Used different variable types to make sure alignment happens.


Repository:
  rC Clang

https://reviews.llvm.org/D43303

Files:
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9450,11 +9450,11 @@
   Alignment);
   Alignment.PointerAlignment = FormatStyle::PAS_Right;
 
-  // Bug 35641
+  // See llvm.org/PR35641
   Alignment.AlignConsecutiveDeclarations = true;
   verifyFormat("int func() { //\n"
-   "  int b;\n"
-   "  int c;\n"
+   "  int  b;\n"
+   "  unsigned c;\n"
"}",
Alignment);
 }


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9450,11 +9450,11 @@
   Alignment);
   Alignment.PointerAlignment = FormatStyle::PAS_Right;
 
-  // Bug 35641
+  // See llvm.org/PR35641
   Alignment.AlignConsecutiveDeclarations = true;
   verifyFormat("int func() { //\n"
-   "  int b;\n"
-   "  int c;\n"
+   "  int  b;\n"
+   "  unsigned c;\n"
"}",
Alignment);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r325238 - Add Xray instrumentation compile-time/link-time support to FreeBSD

2018-02-15 Thread Kamil Rytarowski via cfe-commits
Author: kamil
Date: Thu Feb 15 06:12:21 2018
New Revision: 325238

URL: http://llvm.org/viewvc/llvm-project?rev=325238&view=rev
Log:
Add Xray instrumentation compile-time/link-time support to FreeBSD

Summary: Similarly to the GNU driver version, adding proper compile and linker 
flags.

Patch by: David CARLIER

Reviewers: vitalybuka, krytarowski, dberris

Reviewed By: krytarowski, dberris

Subscribers: emaste, dberris, cfe-commits

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

Modified:
cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp?rev=325238&r1=325237&r2=325238&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp Thu Feb 15 06:12:21 2018
@@ -117,6 +117,30 @@ void freebsd::Assembler::ConstructJob(Co
   C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs));
 }
 
+static bool addXRayRuntime(const ToolChain &TC, const ArgList &Args,
+   ArgStringList &CmdArgs) {
+  if (Args.hasArg(options::OPT_shared))
+return false;
+
+  if (Args.hasFlag(options::OPT_fxray_instrument,
+   options::OPT_fnoxray_instrument, false)) {
+CmdArgs.push_back("-whole-archive");
+CmdArgs.push_back(TC.getCompilerRTArgString(Args, "xray", false));
+CmdArgs.push_back("-no-whole-archive");
+return true;
+  }
+  
+  return false;
+}
+
+static void linkXRayRuntimeDeps(const ToolChain &TC, const ArgList &Args,
+ArgStringList &CmdArgs) {
+  CmdArgs.push_back("--no-as-needed");
+  CmdArgs.push_back("-pthread");
+  CmdArgs.push_back("-lrt");
+  CmdArgs.push_back("-lm");
+} 
+
 void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
@@ -235,6 +259,7 @@ void freebsd::Linker::ConstructJob(Compi
 AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin, D);
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
@@ -249,6 +274,8 @@ void freebsd::Linker::ConstructJob(Compi
 }
 if (NeedsSanitizerDeps)
   linkSanitizerRuntimeDeps(ToolChain, CmdArgs);
+if (NeedsXRayDeps)
+  linkXRayRuntimeDeps(ToolChain, Args, CmdArgs);
 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
 // the default system libraries. Just mimic this for now.
 if (Args.hasArg(options::OPT_pg))


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


[PATCH] D43279: Add Xray instrumentation compile-time/link-time support to FreeBSD

2018-02-15 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325238: Add Xray instrumentation compile-time/link-time 
support to FreeBSD (authored by kamil, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D43279

Files:
  lib/Driver/ToolChains/FreeBSD.cpp


Index: lib/Driver/ToolChains/FreeBSD.cpp
===
--- lib/Driver/ToolChains/FreeBSD.cpp
+++ lib/Driver/ToolChains/FreeBSD.cpp
@@ -117,6 +117,30 @@
   C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs));
 }
 
+static bool addXRayRuntime(const ToolChain &TC, const ArgList &Args,
+   ArgStringList &CmdArgs) {
+  if (Args.hasArg(options::OPT_shared))
+return false;
+
+  if (Args.hasFlag(options::OPT_fxray_instrument,
+   options::OPT_fnoxray_instrument, false)) {
+CmdArgs.push_back("-whole-archive");
+CmdArgs.push_back(TC.getCompilerRTArgString(Args, "xray", false));
+CmdArgs.push_back("-no-whole-archive");
+return true;
+  }
+  
+  return false;
+}
+
+static void linkXRayRuntimeDeps(const ToolChain &TC, const ArgList &Args,
+ArgStringList &CmdArgs) {
+  CmdArgs.push_back("--no-as-needed");
+  CmdArgs.push_back("-pthread");
+  CmdArgs.push_back("-lrt");
+  CmdArgs.push_back("-lm");
+} 
+
 void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
@@ -235,6 +259,7 @@
 AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin, D);
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
@@ -249,6 +274,8 @@
 }
 if (NeedsSanitizerDeps)
   linkSanitizerRuntimeDeps(ToolChain, CmdArgs);
+if (NeedsXRayDeps)
+  linkXRayRuntimeDeps(ToolChain, Args, CmdArgs);
 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
 // the default system libraries. Just mimic this for now.
 if (Args.hasArg(options::OPT_pg))


Index: lib/Driver/ToolChains/FreeBSD.cpp
===
--- lib/Driver/ToolChains/FreeBSD.cpp
+++ lib/Driver/ToolChains/FreeBSD.cpp
@@ -117,6 +117,30 @@
   C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs));
 }
 
+static bool addXRayRuntime(const ToolChain &TC, const ArgList &Args,
+   ArgStringList &CmdArgs) {
+  if (Args.hasArg(options::OPT_shared))
+return false;
+
+  if (Args.hasFlag(options::OPT_fxray_instrument,
+   options::OPT_fnoxray_instrument, false)) {
+CmdArgs.push_back("-whole-archive");
+CmdArgs.push_back(TC.getCompilerRTArgString(Args, "xray", false));
+CmdArgs.push_back("-no-whole-archive");
+return true;
+  }
+  
+  return false;
+}
+
+static void linkXRayRuntimeDeps(const ToolChain &TC, const ArgList &Args,
+ArgStringList &CmdArgs) {
+  CmdArgs.push_back("--no-as-needed");
+  CmdArgs.push_back("-pthread");
+  CmdArgs.push_back("-lrt");
+  CmdArgs.push_back("-lm");
+} 
+
 void freebsd::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
@@ -235,6 +259,7 @@
 AddGoldPlugin(ToolChain, Args, CmdArgs, D.getLTOMode() == LTOK_Thin, D);
 
   bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+  bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
   AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
@@ -249,6 +274,8 @@
 }
 if (NeedsSanitizerDeps)
   linkSanitizerRuntimeDeps(ToolChain, CmdArgs);
+if (NeedsXRayDeps)
+  linkXRayRuntimeDeps(ToolChain, Args, CmdArgs);
 // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
 // the default system libraries. Just mimic this for now.
 if (Args.hasArg(options::OPT_pg))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r325239 - [clangd] Fix make_unique ambiguity, NFC

2018-02-15 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Feb 15 06:16:17 2018
New Revision: 325239

URL: http://llvm.org/viewvc/llvm-project?rev=325239&view=rev
Log:
[clangd] Fix make_unique ambiguity, NFC

Modified:
clang-tools-extra/trunk/clangd/Trace.cpp

Modified: clang-tools-extra/trunk/clangd/Trace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Trace.cpp?rev=325239&r1=325238&r2=325239&view=diff
==
--- clang-tools-extra/trunk/clangd/Trace.cpp (original)
+++ clang-tools-extra/trunk/clangd/Trace.cpp Thu Feb 15 06:16:17 2018
@@ -50,8 +50,8 @@ public:
   // We stash a Span object in the context. It will record the start/end,
   // and this also allows us to look up the parent Span's information.
   Context beginSpan(llvm::StringRef Name, json::obj *Args) override {
-return Context::current().derive(SpanKey,
- make_unique(this, Name, Args));
+return Context::current().derive(
+SpanKey, llvm::make_unique(this, Name, Args));
   }
 
   // Trace viewer requires each thread to properly stack events.


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


[PATCH] D43272: [clangd] Fix tracing now that spans lifetimes can overlap on a thread.

2018-02-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

r325239 should fix, sorry!


Repository:
  rL LLVM

https://reviews.llvm.org/D43272



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


r325241 - Adding msan support for FreeBSD

2018-02-15 Thread Kamil Rytarowski via cfe-commits
Author: kamil
Date: Thu Feb 15 06:19:23 2018
New Revision: 325241

URL: http://llvm.org/viewvc/llvm-project?rev=325241&view=rev
Log:
Adding msan support for FreeBSD

Summary: Enabling memory sanitiser for X86_64 arch only. To match the sanitiser 
counterpart.

Patch by: David CARLIER

Reviewers: krytarowski

Reviewed By: krytarowski

Subscribers: dim, emaste, cfe-commits

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

Modified:
cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp?rev=325241&r1=325240&r2=325241&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/FreeBSD.cpp Thu Feb 15 06:19:23 2018
@@ -424,5 +424,7 @@ SanitizerMask FreeBSD::getSupportedSanit
 Res |= SanitizerKind::Fuzzer;
 Res |= SanitizerKind::FuzzerNoLink;
   }
+  if (IsX86_64)
+Res |= SanitizerKind::Memory;
   return Res;
 }


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


[PATCH] D43148: Adding msan support for FreeBSD

2018-02-15 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325241: Adding msan support for FreeBSD (authored by kamil, 
committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D43148

Files:
  lib/Driver/ToolChains/FreeBSD.cpp


Index: lib/Driver/ToolChains/FreeBSD.cpp
===
--- lib/Driver/ToolChains/FreeBSD.cpp
+++ lib/Driver/ToolChains/FreeBSD.cpp
@@ -424,5 +424,7 @@
 Res |= SanitizerKind::Fuzzer;
 Res |= SanitizerKind::FuzzerNoLink;
   }
+  if (IsX86_64)
+Res |= SanitizerKind::Memory;
   return Res;
 }


Index: lib/Driver/ToolChains/FreeBSD.cpp
===
--- lib/Driver/ToolChains/FreeBSD.cpp
+++ lib/Driver/ToolChains/FreeBSD.cpp
@@ -424,5 +424,7 @@
 Res |= SanitizerKind::Fuzzer;
 Res |= SanitizerKind::FuzzerNoLink;
   }
+  if (IsX86_64)
+Res |= SanitizerKind::Memory;
   return Res;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34367: CodeGen: Fix address space of indirect function argument

2018-02-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 134416.
yaxunl edited the summary of this revision.
yaxunl added a comment.

Revised by John's comments. Removed address space from CallArg and added 
l-value expression instead.


https://reviews.llvm.org/D34367

Files:
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGCall.h
  lib/CodeGen/CGDecl.cpp
  test/CodeGenCXX/amdgcn-func-arg.cpp
  test/CodeGenOpenCL/addr-space-struct-arg.cl
  test/CodeGenOpenCL/byval.cl

Index: test/CodeGenOpenCL/byval.cl
===
--- test/CodeGenOpenCL/byval.cl
+++ test/CodeGenOpenCL/byval.cl
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn %s | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn---opencl %s | FileCheck %s
 
 struct A {
   int x[100];
Index: test/CodeGenOpenCL/addr-space-struct-arg.cl
===
--- test/CodeGenOpenCL/addr-space-struct-arg.cl
+++ test/CodeGenOpenCL/addr-space-struct-arg.cl
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -ffake-address-space-map -triple i686-pc-darwin | FileCheck -enable-var-scope -check-prefixes=COM,X86 %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple amdgcn-amdhsa-amd-amdgizcl | FileCheck -enable-var-scope -check-prefixes=COM,AMD %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple amdgcn-amdhsa-amd | FileCheck -enable-var-scope -check-prefixes=COM,AMD %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 -finclude-default-header -triple amdgcn-amdhsa-amd | FileCheck -enable-var-scope -check-prefixes=COM,AMD,AMD20 %s
 
 typedef struct {
   int cells[9];
@@ -35,6 +36,9 @@
   int2 y[20];
 };
 
+#if __OPENCL_C_VERSION__ >= 200
+struct LargeStructOneMember g_s;
+#endif
 
 // X86-LABEL: define void @foo(%struct.Mat4X4* noalias sret %agg.result, %struct.Mat3X3* byval align 4 %in)
 // AMD-LABEL: define %struct.Mat4X4 @foo([9 x i32] %in.coerce)
@@ -80,10 +84,42 @@
 }
 
 // AMD-LABEL: define void @FuncOneLargeMember(%struct.LargeStructOneMember addrspace(5)* byval align 8 %u)
+// AMD-NOT: addrspacecast
+// AMD:   store <2 x i32> %{{.*}}, <2 x i32> addrspace(5)*
 void FuncOneLargeMember(struct LargeStructOneMember u) {
   u.x[0] = (int2)(0, 0);
 }
 
+// AMD20-LABEL: define void @test_indirect_arg_globl()
+// AMD20:  %[[byval_temp:.*]] = alloca %struct.LargeStructOneMember, align 8, addrspace(5)
+// AMD20:  %[[r0:.*]] = bitcast %struct.LargeStructOneMember addrspace(5)* %[[byval_temp]] to i8 addrspace(5)*
+// AMD20:  call void @llvm.memcpy.p5i8.p1i8.i64(i8 addrspace(5)* align 8 %[[r0]], i8 addrspace(1)* align 8 bitcast (%struct.LargeStructOneMember addrspace(1)* @g_s to i8 addrspace(1)*), i64 800, i1 false)
+// AMD20:  call void @FuncOneLargeMember(%struct.LargeStructOneMember addrspace(5)* byval align 8 %[[byval_temp]])
+#if __OPENCL_C_VERSION__ >= 200
+void test_indirect_arg_globl(void) {
+  FuncOneLargeMember(g_s);
+}
+#endif
+
+// AMD-LABEL: define amdgpu_kernel void @test_indirect_arg_local()
+// AMD: %[[byval_temp:.*]] = alloca %struct.LargeStructOneMember, align 8, addrspace(5)
+// AMD: %[[r0:.*]] = bitcast %struct.LargeStructOneMember addrspace(5)* %[[byval_temp]] to i8 addrspace(5)*
+// AMD: call void @llvm.memcpy.p5i8.p3i8.i64(i8 addrspace(5)* align 8 %[[r0]], i8 addrspace(3)* align 8 bitcast (%struct.LargeStructOneMember addrspace(3)* @test_indirect_arg_local.l_s to i8 addrspace(3)*), i64 800, i1 false)
+// AMD: call void @FuncOneLargeMember(%struct.LargeStructOneMember addrspace(5)* byval align 8 %[[byval_temp]])
+kernel void test_indirect_arg_local(void) {
+  local struct LargeStructOneMember l_s;
+  FuncOneLargeMember(l_s);
+}
+
+// AMD-LABEL: define void @test_indirect_arg_private()
+// AMD: %[[p_s:.*]] = alloca %struct.LargeStructOneMember, align 8, addrspace(5)
+// AMD-NOT: @llvm.memcpy
+// AMD-NEXT: call void @FuncOneLargeMember(%struct.LargeStructOneMember addrspace(5)* byval align 8 %[[p_s]])
+void test_indirect_arg_private(void) {
+  struct LargeStructOneMember p_s;
+  FuncOneLargeMember(p_s);
+}
+
 // AMD-LABEL: define amdgpu_kernel void @KernelOneMember
 // AMD-SAME:  (<2 x i32> %[[u_coerce:.*]])
 // AMD:  %[[u:.*]] = alloca %struct.StructOneMember, align 8, addrspace(5)
@@ -112,7 +148,6 @@
   u.y[0] = (int2)(0, 0);
 }
 
-
 // AMD-LABEL: define amdgpu_kernel void @KernelTwoMember
 // AMD-SAME:  (%struct.StructTwoMember %[[u_coerce:.*]])
 // AMD:  %[[u:.*]] = alloca %struct.StructTwoMember, align 8, addrspace(5)
Index: test/CodeGenCXX/amdgcn-func-arg.cpp
===
--- /dev/null
+++ test/CodeGenCXX/amdgcn-func-arg.cpp
@@ -0,0 +1,94 @@
+// RUN: %clang_cc1 -O0 -triple amdgcn---amdgiz -emit-llvm %s -o - | FileCheck %s
+
+class A {
+public:
+  int x;
+  A():x(0) {}
+  ~A() {}
+};
+
+class B {
+int x[100];
+};
+
+A g_a;
+B g_b;
+
+void func_with_ref_arg(A &a);
+void func_with_ref_arg(B &b);
+
+// CH

[PATCH] D34367: CodeGen: Fix address space of indirect function argument

2018-02-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/CodeGen/CGCall.h:211
+  push_back(CallArg(rvalue, type, needscopy, AS));
 }
 

rjmccall wrote:
> Ah, I think I understand what's going on here now.  "indirect byval" 
> arguments include an implicit copy to the stack, and the code is trying to 
> avoid emitting an extra copy to a temporary in the frontend.  It does this by 
> recognizing loads from aggregate l-values and just adding the l-value to the 
> call-argument list as a "needs copy" argument.  Call-argument preparation 
> then recognizes that the argument is being passed indirect byval and, under 
> certain conditions, just uses the l-value address as the IR argument.
> 
> Instead of creeping more and more information from the LValue into the 
> CallArg, I think there are two reasonable alternatives:
> 
> - Suppress this optimization in EmitCallArg when the LValue isn't in the 
> alloca address space.  EmitCallArg already suppresses it when the argument is 
> under-aligned.
> 
> - Find a way to actually store an LValue in a CallArg.  This has the 
> advantage that we can assert if someone tries to access it as an RValue, 
> which is good because any attempt to use a needs-copy argument as if it were 
> a normal argument is a lurking bug.
Sorry for the delay. I updated the patch with by the second approach. I did not 
add a member of LValue type to CallArg but added a member of Expr* type since 
sometimes LValue is not available. The Expr is the l-value expression from 
which the r-value is derived.


https://reviews.llvm.org/D34367



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


[PATCH] D43229: [clangd] Enable snippet completion based on client capabilities.

2018-02-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 134420.
ilya-biryukov added a comment.

- Use default values for configuration instead of using Optional<> fields.
- Removed redundant tests.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43229

Files:
  clangd/ClangdLSPServer.cpp
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/tool/ClangdMain.cpp
  test/clangd/completion-snippets-missing.test
  test/clangd/completion-snippets.test

Index: test/clangd/completion-snippets.test
===
--- /dev/null
+++ test/clangd/completion-snippets.test
@@ -0,0 +1,43 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+# RUN: clangd -lit-test -pch-storage=memory < %s | FileCheck -strict-whitespace %s
+{
+  "jsonrpc": "2.0",
+  "id": 0,
+  "method": "initialize",
+  "params": {
+"processId": 123,
+"rootPath": "clangd",
+"capabilities": {
+  "textDocument": {
+"completion": {
+  "completionItem": {
+"snippetSupport": true
+  }
+}
+  }
+},
+"trace": "off"
+  }
+}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"int func_with_args(int a, int b);\nint main() {\nfunc_with\n}"}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":2,"character":7}}}
+#  CHECK:  "id": 1
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": {
+# CHECK-NEXT:"isIncomplete": {{.*}}
+# CHECK-NEXT:"items": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "detail": "int",
+# CHECK-NEXT:  "filterText": "func_with_args",
+# CHECK-NEXT:  "insertText": "func_with_args(${1:int a}, ${2:int b})",
+# CHECK-NEXT:  "insertTextFormat": 2,
+# CHECK-NEXT:  "kind": 3,
+# CHECK-NEXT:  "label": "func_with_args(int a, int b)",
+# CHECK-NEXT:  "sortText": "{{.*}}func_with_args"
+# CHECK-NEXT:}
+# CHECK-NEXT:]
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":4,"method":"shutdown"}
Index: test/clangd/completion-snippets-missing.test
===
--- /dev/null
+++ test/clangd/completion-snippets-missing.test
@@ -0,0 +1,35 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+# RUN: clangd -lit-test -pch-storage=memory < %s | FileCheck -strict-whitespace %s
+{
+  "jsonrpc": "2.0",
+  "id": 0,
+  "method": "initialize",
+  "params": {
+"processId": 123,
+"rootPath": "clangd",
+"capabilities": {},
+"trace": "off"
+  }
+}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"int func_with_args(int a, int b);\nint main() {\nfunc_with\n}"}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":2,"character":7}}}
+#  CHECK:  "id": 1
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": {
+# CHECK-NEXT:"isIncomplete": {{.*}}
+# CHECK-NEXT:"items": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "detail": "int",
+# CHECK-NEXT:  "filterText": "func_with_args",
+# CHECK-NEXT:  "insertText": "func_with_args",
+# CHECK-NEXT:  "insertTextFormat": 1,
+# CHECK-NEXT:  "kind": 3,
+# CHECK-NEXT:  "label": "func_with_args(int a, int b)",
+# CHECK-NEXT:  "sortText": "{{.*}}func_with_args"
+# CHECK-NEXT:}
+# CHECK-NEXT:]
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":4,"method":"shutdown"}
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -58,13 +58,6 @@
llvm::cl::desc("Number of async workers used by clangd"),
llvm::cl::init(getDefaultAsyncThreadsCount()));
 
-static llvm::cl::opt EnableSnippets(
-"enable-snippets",
-llvm::cl::desc(
-"Present snippet completions instead of plaintext completions. "
-"This also enables code pattern results." /* FIXME: should it? */),
-llvm::cl::init(clangd::CodeCompleteOptions().EnableSnippets));
-
 // FIXME: Flags are the wrong mechanism for user preferences.
 // We should probably read a dotfile or similar.
 static llvm::cl::opt IncludeIneligibleResults(
@@ -237,7 +230,6 @@
   if (EnableIndexBasedCompletion && !YamlSymbolFile.empty())
 StaticIdx = BuildStaticIndex(YamlSymbolFile);
   clangd::CodeCompleteOptions CCOpts;
-  CCOpts.EnableSnippets = EnableSnippets;
   CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
   CCOpts.Limit = LimitCompletionResult;
   // Initialize and run ClangdLSPServer.
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -179,6 +179,51 @@
 using ShutdownParams = NoParams;
 us

[PATCH] D43229: [clangd] Enable snippet completion based on client capabilities.

2018-02-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 134421.
ilya-biryukov added a comment.

- Removed completion-snippets-missing.test


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43229

Files:
  clangd/ClangdLSPServer.cpp
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/tool/ClangdMain.cpp
  test/clangd/completion-snippets.test

Index: test/clangd/completion-snippets.test
===
--- /dev/null
+++ test/clangd/completion-snippets.test
@@ -0,0 +1,43 @@
+# RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
+# RUN: clangd -lit-test -pch-storage=memory < %s | FileCheck -strict-whitespace %s
+{
+  "jsonrpc": "2.0",
+  "id": 0,
+  "method": "initialize",
+  "params": {
+"processId": 123,
+"rootPath": "clangd",
+"capabilities": {
+  "textDocument": {
+"completion": {
+  "completionItem": {
+"snippetSupport": true
+  }
+}
+  }
+},
+"trace": "off"
+  }
+}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"int func_with_args(int a, int b);\nint main() {\nfunc_with\n}"}}}
+---
+{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":2,"character":7}}}
+#  CHECK:  "id": 1
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": {
+# CHECK-NEXT:"isIncomplete": {{.*}}
+# CHECK-NEXT:"items": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "detail": "int",
+# CHECK-NEXT:  "filterText": "func_with_args",
+# CHECK-NEXT:  "insertText": "func_with_args(${1:int a}, ${2:int b})",
+# CHECK-NEXT:  "insertTextFormat": 2,
+# CHECK-NEXT:  "kind": 3,
+# CHECK-NEXT:  "label": "func_with_args(int a, int b)",
+# CHECK-NEXT:  "sortText": "{{.*}}func_with_args"
+# CHECK-NEXT:}
+# CHECK-NEXT:]
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":4,"method":"shutdown"}
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -58,13 +58,6 @@
llvm::cl::desc("Number of async workers used by clangd"),
llvm::cl::init(getDefaultAsyncThreadsCount()));
 
-static llvm::cl::opt EnableSnippets(
-"enable-snippets",
-llvm::cl::desc(
-"Present snippet completions instead of plaintext completions. "
-"This also enables code pattern results." /* FIXME: should it? */),
-llvm::cl::init(clangd::CodeCompleteOptions().EnableSnippets));
-
 // FIXME: Flags are the wrong mechanism for user preferences.
 // We should probably read a dotfile or similar.
 static llvm::cl::opt IncludeIneligibleResults(
@@ -237,7 +230,6 @@
   if (EnableIndexBasedCompletion && !YamlSymbolFile.empty())
 StaticIdx = BuildStaticIndex(YamlSymbolFile);
   clangd::CodeCompleteOptions CCOpts;
-  CCOpts.EnableSnippets = EnableSnippets;
   CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
   CCOpts.Limit = LimitCompletionResult;
   // Initialize and run ClangdLSPServer.
Index: clangd/Protocol.h
===
--- clangd/Protocol.h
+++ clangd/Protocol.h
@@ -179,6 +179,51 @@
 using ShutdownParams = NoParams;
 using ExitParams = NoParams;
 
+struct CompletionItemClientCapabilities {
+  /// Client supports snippets as insert text.
+  bool snippetSupport = false;
+  /// Client supports commit characters on a completion item.
+  bool commitCharacterSupport = false;
+  // Client supports the follow content formats for the documentation property.
+  // The order describes the preferred format of the client.
+  // NOTE: not used by clangd at the moment.
+  // std::vector documentationFormat;
+};
+bool fromJSON(const json::Expr &, CompletionItemClientCapabilities &);
+
+struct CompletionClientCapabilities {
+  /// Whether completion supports dynamic registration.
+  bool dynamicRegistration = false;
+  /// The client supports the following `CompletionItem` specific capabilities.
+  CompletionItemClientCapabilities completionItem;
+  // NOTE: not used by clangd at the moment.
+  // llvm::Optional completionItemKind;
+
+  /// The client supports to send additional context information for a
+  /// `textDocument/completion` request.
+  bool contextSupport = false;
+};
+bool fromJSON(const json::Expr &, CompletionClientCapabilities &);
+
+// FIXME: most of the capabilities are missing from this struct. Only the ones
+// used by clangd are currently there.
+struct TextDocumentClientCapabilities {
+  /// Capabilities specific to the `textDocument/completion`
+  CompletionClientCapabilities completion;
+};
+bool fromJSON(const json::Expr &, TextDocumentClientCapabilities &);
+
+struct ClientCapabilities {
+  // Workspace specific client capabilities.
+  // NOTE: not used by clangd at the moment.
+  // WorkspaceCl

[PATCH] D43229: [clangd] Enable snippet completion based on client capabilities.

2018-02-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

As discussed offline with @sammccall, we don't really need to hold `Optional<>` 
fields for configuration entries, as we only consume them in clangd and 
therefore can just set the default values explicitly.
Makes the code simpler and requires only one extra test (with snippets enabled).


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D43229



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


[PATCH] D43229: [clangd] Enable snippet completion based on client capabilities.

2018-02-15 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325242: [clangd] Enable snippet completion based on client 
capabilities. (authored by ibiryukov, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43229

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/Protocol.cpp
  clang-tools-extra/trunk/clangd/Protocol.h
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
  clang-tools-extra/trunk/test/clangd/completion-snippets.test

Index: clang-tools-extra/trunk/clangd/Protocol.cpp
===
--- clang-tools-extra/trunk/clangd/Protocol.cpp
+++ clang-tools-extra/trunk/clangd/Protocol.cpp
@@ -150,6 +150,41 @@
   return false;
 }
 
+bool fromJSON(const json::Expr &Params, CompletionItemClientCapabilities &R) {
+  json::ObjectMapper O(Params);
+  if (!O)
+return false;
+  O.map("snippetSupport", R.snippetSupport);
+  O.map("commitCharacterSupport", R.commitCharacterSupport);
+  return true;
+}
+
+bool fromJSON(const json::Expr &Params, CompletionClientCapabilities &R) {
+  json::ObjectMapper O(Params);
+  if (!O)
+return false;
+  O.map("dynamicRegistration", R.dynamicRegistration);
+  O.map("completionItem", R.completionItem);
+  O.map("contextSupport", R.contextSupport);
+  return true;
+}
+
+bool fromJSON(const json::Expr &Params, TextDocumentClientCapabilities &R) {
+  json::ObjectMapper O(Params);
+  if (!O)
+return false;
+  O.map("completion", R.completion);
+  return true;
+}
+
+bool fromJSON(const json::Expr &Params, ClientCapabilities &R) {
+  json::ObjectMapper O(Params);
+  if (!O)
+return false;
+  O.map("textDocument", R.textDocument);
+  return true;
+}
+
 bool fromJSON(const json::Expr &Params, InitializeParams &R) {
   json::ObjectMapper O(Params);
   if (!O)
@@ -159,6 +194,7 @@
   O.map("processId", R.processId);
   O.map("rootUri", R.rootUri);
   O.map("rootPath", R.rootPath);
+  O.map("capabilities", R.capabilities);
   O.map("trace", R.trace);
   // initializationOptions, capabilities unused
   return true;
Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -58,13 +58,6 @@
llvm::cl::desc("Number of async workers used by clangd"),
llvm::cl::init(getDefaultAsyncThreadsCount()));
 
-static llvm::cl::opt EnableSnippets(
-"enable-snippets",
-llvm::cl::desc(
-"Present snippet completions instead of plaintext completions. "
-"This also enables code pattern results." /* FIXME: should it? */),
-llvm::cl::init(clangd::CodeCompleteOptions().EnableSnippets));
-
 // FIXME: Flags are the wrong mechanism for user preferences.
 // We should probably read a dotfile or similar.
 static llvm::cl::opt IncludeIneligibleResults(
@@ -237,7 +230,6 @@
   if (EnableIndexBasedCompletion && !YamlSymbolFile.empty())
 StaticIdx = BuildStaticIndex(YamlSymbolFile);
   clangd::CodeCompleteOptions CCOpts;
-  CCOpts.EnableSnippets = EnableSnippets;
   CCOpts.IncludeIneligibleResults = IncludeIneligibleResults;
   CCOpts.Limit = LimitCompletionResult;
   // Initialize and run ClangdLSPServer.
Index: clang-tools-extra/trunk/clangd/Protocol.h
===
--- clang-tools-extra/trunk/clangd/Protocol.h
+++ clang-tools-extra/trunk/clangd/Protocol.h
@@ -179,6 +179,51 @@
 using ShutdownParams = NoParams;
 using ExitParams = NoParams;
 
+struct CompletionItemClientCapabilities {
+  /// Client supports snippets as insert text.
+  bool snippetSupport = false;
+  /// Client supports commit characters on a completion item.
+  bool commitCharacterSupport = false;
+  // Client supports the follow content formats for the documentation property.
+  // The order describes the preferred format of the client.
+  // NOTE: not used by clangd at the moment.
+  // std::vector documentationFormat;
+};
+bool fromJSON(const json::Expr &, CompletionItemClientCapabilities &);
+
+struct CompletionClientCapabilities {
+  /// Whether completion supports dynamic registration.
+  bool dynamicRegistration = false;
+  /// The client supports the following `CompletionItem` specific capabilities.
+  CompletionItemClientCapabilities completionItem;
+  // NOTE: not used by clangd at the moment.
+  // llvm::Optional completionItemKind;
+
+  /// The client supports to send additional context information for a
+  /// `textDocument/completion` request.
+  bool contextSupport = false;
+};
+bool fromJSON(const json::Expr &, CompletionClientCapabilities &);
+
+// FIXME: most of the capabilities are missing from this struct. Only the ones
+// used by clangd are currently there.
+struct TextDocumentClientCapabilities {
+  /// Capabilities specific to

[clang-tools-extra] r325242 - [clangd] Enable snippet completion based on client capabilities.

2018-02-15 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Feb 15 06:32:57 2018
New Revision: 325242

URL: http://llvm.org/viewvc/llvm-project?rev=325242&view=rev
Log:
[clangd] Enable snippet completion based on client capabilities.

Summary: And remove -enable-snippets flag.

Reviewers: hokein, ioeric, sammccall

Reviewed By: ioeric

Subscribers: klimek, jkorous-apple, cfe-commits

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

Added:
clang-tools-extra/trunk/test/clangd/completion-snippets.test
Modified:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/Protocol.cpp
clang-tools-extra/trunk/clangd/Protocol.h
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=325242&r1=325241&r2=325242&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Thu Feb 15 06:32:57 2018
@@ -87,6 +87,14 @@ std::vector replacementsToEdit
 } // namespace
 
 void ClangdLSPServer::onInitialize(InitializeParams &Params) {
+  if (Params.rootUri && !Params.rootUri->file.empty())
+Server.setRootPath(Params.rootUri->file);
+  else if (Params.rootPath && !Params.rootPath->empty())
+Server.setRootPath(*Params.rootPath);
+
+  CCOpts.EnableSnippets =
+  
Params.capabilities.textDocument.completion.completionItem.snippetSupport;
+
   reply(json::obj{
   {{"capabilities",
 json::obj{
@@ -116,10 +124,6 @@ void ClangdLSPServer::onInitialize(Initi
  {"commands", 
{ExecuteCommandParams::CLANGD_APPLY_FIX_COMMAND}},
  }},
 );
-  if (Params.rootUri && !Params.rootUri->file.empty())
-Server.setRootPath(Params.rootUri->file);
-  else if (Params.rootPath && !Params.rootPath->empty())
-Server.setRootPath(*Params.rootPath);
 }
 
 void ClangdLSPServer::onShutdown(ShutdownParams &Params) {

Modified: clang-tools-extra/trunk/clangd/Protocol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.cpp?rev=325242&r1=325241&r2=325242&view=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.cpp (original)
+++ clang-tools-extra/trunk/clangd/Protocol.cpp Thu Feb 15 06:32:57 2018
@@ -150,6 +150,41 @@ bool fromJSON(const json::Expr &E, Trace
   return false;
 }
 
+bool fromJSON(const json::Expr &Params, CompletionItemClientCapabilities &R) {
+  json::ObjectMapper O(Params);
+  if (!O)
+return false;
+  O.map("snippetSupport", R.snippetSupport);
+  O.map("commitCharacterSupport", R.commitCharacterSupport);
+  return true;
+}
+
+bool fromJSON(const json::Expr &Params, CompletionClientCapabilities &R) {
+  json::ObjectMapper O(Params);
+  if (!O)
+return false;
+  O.map("dynamicRegistration", R.dynamicRegistration);
+  O.map("completionItem", R.completionItem);
+  O.map("contextSupport", R.contextSupport);
+  return true;
+}
+
+bool fromJSON(const json::Expr &Params, TextDocumentClientCapabilities &R) {
+  json::ObjectMapper O(Params);
+  if (!O)
+return false;
+  O.map("completion", R.completion);
+  return true;
+}
+
+bool fromJSON(const json::Expr &Params, ClientCapabilities &R) {
+  json::ObjectMapper O(Params);
+  if (!O)
+return false;
+  O.map("textDocument", R.textDocument);
+  return true;
+}
+
 bool fromJSON(const json::Expr &Params, InitializeParams &R) {
   json::ObjectMapper O(Params);
   if (!O)
@@ -159,6 +194,7 @@ bool fromJSON(const json::Expr &Params,
   O.map("processId", R.processId);
   O.map("rootUri", R.rootUri);
   O.map("rootPath", R.rootPath);
+  O.map("capabilities", R.capabilities);
   O.map("trace", R.trace);
   // initializationOptions, capabilities unused
   return true;

Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=325242&r1=325241&r2=325242&view=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Thu Feb 15 06:32:57 2018
@@ -179,6 +179,51 @@ inline bool fromJSON(const json::Expr &,
 using ShutdownParams = NoParams;
 using ExitParams = NoParams;
 
+struct CompletionItemClientCapabilities {
+  /// Client supports snippets as insert text.
+  bool snippetSupport = false;
+  /// Client supports commit characters on a completion item.
+  bool commitCharacterSupport = false;
+  // Client supports the follow content formats for the documentation property.
+  // The order describes the preferred format of the client.
+  // NOTE: not used by clangd at the moment.
+  // std::vector documentationFormat;
+};
+bool fromJSON(const json::Expr &, CompletionItemClientCapabilities &);
+
+struct CompletionC

[PATCH] D43240: [OpenCL] Fix __enqueue_block for block with captures

2018-02-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D43240#1008560, @Anastasia wrote:

> LGTM! Thanks for looking at this. Just one thing, I was wondering whether it 
> would be cleaner way if we extend 
> test/CodeGenOpenCL/cl20-device-side-enqueue.cl instead of adding a new one 
> here? Because this is the test that is meant to exercise all DSE codegen 
> bits. Perhaps we can modify one block in that test to have the same format as 
> here (i.e. using captures), since  now we test the same block there most of 
> the time. However, we don't test any of kernel wrapper 
> `*_block_invoke_kernel` there. Not sure why...


We do check block wrappers in cl20-device-side-enqueue.cl, which is done at the 
end of the test.

I did not add this test to cl20-device-side-enqueue.cl because 
cl20-device-side-enqueue.cl is already very complicated. I can add this test to 
cl20-device-side-enqueue.cl when committing.


https://reviews.llvm.org/D43240



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


[PATCH] D43183: clang-format: introduce `CaseBlockIndent` to control indent in switch

2018-02-15 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

In https://reviews.llvm.org/D43183#1008632, @djasper wrote:

> Yes, that's what I mean. What do you mean, the style is too error prone?


When `IndentCaseLabels` is false, the code gets formatted in a way that "hides" 
the structure of the code, by indenting the end of the case in the exact same 
way as the end of a switch, which is error prone IMHO.
Indentation should "highlight" the structure of the code, to make it easier to 
understand, and thus avoid this kind of confusion.


Repository:
  rC Clang

https://reviews.llvm.org/D43183



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


[PATCH] D43183: clang-format: introduce `CaseBlockIndent` to control indent in switch

2018-02-15 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

That doesn't explain to me how this is error prone. I can't think how you'd 
create an error by this that would not be caught by the compiler. Much less if 
you consistently use clang-format.

It's fundamentally what you get for IndentCaseLabels: false. Even without 
braces you have this issue to some extend. But LLVM has several thousand 
switches, about a thousand with braces formatted this way and I am not aware of 
a single time this has caused a bug or even confusion.

And to me (but this is obviously objective), your suggestions hide the 
structure of the code even more as they lead to a state where the closing brace 
is not aligned with the start of the line/statement that contains the opening 
braces. That looks like a bug to me more than anything else and I don't think 
there is another situation where clang-format would do that.


Repository:
  rC Clang

https://reviews.llvm.org/D43183



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


[PATCH] D41880: Adding nocf_check attribute for cf-protection fine tuning

2018-02-15 Thread Oren Ben Simhon via Phabricator via cfe-commits
oren_ben_simhon marked an inline comment as done.
oren_ben_simhon added inline comments.



Comment at: lib/Sema/SemaDeclAttr.cpp:1990
 
-bool Sema::CheckNoReturnAttr(const AttributeList &Attrs) {
-  if (!checkAttributeNumArgs(*this, Attrs, 0)) {
-Attrs.setInvalid();
+static void handleNoCfCheckAttr(Sema &S, Decl *D, const AttributeList &attr) {
+  if (S.CheckAttrTarget(attr) || S.CheckAttrNoArgs(attr))

aaron.ballman wrote:
> oren_ben_simhon wrote:
> > aaron.ballman wrote:
> > > aaron.ballman wrote:
> > > > `attr` doesn't follow the proper naming conventions.
> > > Please don't name the parameter variable after a type -- that can confuse 
> > > some editors.
> > I am following the same convention that other functions are using.
> > I am following the same convention that other functions are using.
> 
> They're doing it wrong. I can clean those up in a separate patch.
Its OK i can make the change.



Comment at: test/Sema/attr-nocf_check.c:18-20
+  FuncPointerWithNoCfCheck fNoCfCheck = f; // no-warning
+  (*fNoCfCheck)();   // no-warning
+  f = fNoCfCheck;// no-warning

aaron.ballman wrote:
> oren_ben_simhon wrote:
> > aaron.ballman wrote:
> > > These are an error in GCC and I think we should match that behavior. 
> > > https://godbolt.org/g/r3pf4X
> > I will create a warning however in LLVM we don't create an error upon 
> > incompatible pointer due to function attribute types.
> It should be an error -- Clang does error on this sort of thing when 
> appropriate (which I believe it is, here). For instance, calling convention 
> attributes do this: https://godbolt.org/g/mkTGLg
In Clang there is Sema::IncompatiblePointer in case to pointers are not 
compatible. This flag emits warning message. In the time i check for pointer 
incompatibility (checkPointerTypesForAssignment()), i don;t have a handle to 
the attributes. Any suggestion how to implement the exception for nocf_check 
attribute?


Repository:
  rL LLVM

https://reviews.llvm.org/D41880



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


[PATCH] D43272: [clangd] Fix tracing now that spans lifetimes can overlap on a thread.

2018-02-15 Thread Carlos Alberto Enciso via Phabricator via cfe-commits
CarlosAlbertoEnciso added a comment.

In https://reviews.llvm.org/D43272#1008703, @sammccall wrote:

> r325239 should fix, sorry!


Build now is OK. Thanks @sammccall.


Repository:
  rL LLVM

https://reviews.llvm.org/D43272



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


[PATCH] D43298: [clang-format] Support repeated field lists in protos

2018-02-15 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 134427.
krasimir added a comment.

- Pull out check in lambda
- Address review comments


Repository:
  rC Clang

https://reviews.llvm.org/D43298

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -31,14 +31,18 @@
 return *Result;
   }
 
-  static std::string format(llvm::StringRef Code) {
-FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
-Style.ColumnLimit = 60; // To make writing tests easier.
+  static std::string format(llvm::StringRef Code, const FormatStyle &Style) {
 return format(Code, 0, Code.size(), Style);
   }
 
+  static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) {
+EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+  }
+
   static void verifyFormat(llvm::StringRef Code) {
-EXPECT_EQ(Code.str(), format(test::messUp(Code)));
+FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+Style.ColumnLimit = 60; // To make writing tests easier.
+verifyFormat(Code, Style);
   }
 };
 
@@ -390,5 +394,43 @@
 TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
   verifyFormat("key: %d");
 }
+
+TEST_F(FormatTestTextProto, FormatsRepeatedListInitializers) {
+  verifyFormat("keys: []");
+  verifyFormat("keys: [ 1 ]");
+  verifyFormat("keys: [ 'ala', 'bala' ]");
+  verifyFormat("keys:\n"
+   "[ 'ala', 'bala', 'porto', 'kala', 'too', 'long', 'ng' ]");
+  verifyFormat("key: item\n"
+   "keys: [\n"
+   "  'ala',\n"
+   "  'bala',\n"
+   "  'porto',\n"
+   "  'kala',\n"
+   "  'too',\n"
+   "  'long',\n"
+   "  'long',\n"
+   "  'long'\n"
+   "]\n"
+   "key: item\n"
+   "msg {\n"
+   "  key: item\n"
+   "  keys: [\n"
+   "'ala',\n"
+   "'bala',\n"
+   "'porto',\n"
+   "'kala',\n"
+   "'too',\n"
+   "'long',\n"
+   "'long'\n"
+   "  ]\n"
+   "}\n"
+   "key: value"
+   );
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60; // To make writing tests easier.
+  Style.Cpp11BracedListStyle = true;
+  verifyFormat("keys: [1]", Style);
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -438,5 +438,35 @@
"};");
 }
 
+TEST_F(FormatTestProto, FormatsRepeatedListInitializersInOptions) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: item\n"
+   "  keys: [\n"
+   "'ala',\n"
+   "'bala',\n"
+   "'porto',\n"
+   "'kala',\n"
+   "'too',\n"
+   "'long',\n"
+   "'long',\n"
+   "'long'\n"
+   "  ]\n"
+   "  key: [ item ]\n"
+   "  msg {\n"
+   "key: item\n"
+   "keys: [\n"
+   "  'ala',\n"
+   "  'bala',\n"
+   "  'porto',\n"
+   "  'kala',\n"
+   "  'too',\n"
+   "  'long',\n"
+   "  'long'\n"
+   "]\n"
+   "  }\n"
+   "  key: value\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -383,11 +383,18 @@
 //   }
 // }
 //
-// In the first case we want to spread the contents inside the square
-// braces; in the second we want to keep them inline.
+// or repeated fields (in options):
+//
+// option (Aaa.options) = {
+//   keys: [ 1, 2, 3 ]
+// }
+//
+// In the first and the third case we want to spread the contents inside
+// the square braces; in the second we want to keep them inline.
 Left->Type = TT_ArrayInitializerLSquare;
 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
-tok::equal)) {
+tok::equal) &&
+!Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
   Left->Type = TT_ProtoExtensionLSquare;
   BindingIncrease = 10;

[PATCH] D43227: [clangd] Make functions of ClangdServer callback-based

2018-02-15 Thread Carlos Alberto Enciso via Phabricator via cfe-commits
CarlosAlbertoEnciso added a comment.

Hi,

It seems that your submission broke the Windows/Linux builds for 'clangd'.

The generated error message is:

  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\future(263): 
error C2512: 
'llvm::Expected>>':
 no appropriate default constructor available 
[C:\j\w\opensource\opensource_to_sce_merge\build\tools\clang\tools\extra\unittests\clangd\ClangdTests.vcxproj]
  
  C:\xxx\llvm\tools\clang\tools\extra\clangd\ClangdServer.h(231): note: see 
declaration of 
'llvm::Expected>>'
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\future(255): 
note: while compiling class template member function 
'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)'
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\future(1491): 
note: see reference to function template instantiation 
'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)' 
being compiled
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\future(989): 
note: see reference to class template instantiation 
'std::_Associated_state<_Ty>' being compiled
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\future(987): 
note: while compiling class template member function 'bool 
std::_State_manager<_Ty>::valid(void) throw() const'

Thanks


Repository:
  rL LLVM

https://reviews.llvm.org/D43227



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


r325252 - [clang-format] Support repeated field lists in protos

2018-02-15 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Thu Feb 15 07:30:22 2018
New Revision: 325252

URL: http://llvm.org/viewvc/llvm-project?rev=325252&view=rev
Log:
[clang-format] Support repeated field lists in protos

Summary:
This patch adds support for list initialization of proto repeated fields:
```
keys: [1, 2, 3]
```

Reviewers: djasper

Reviewed By: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=325252&r1=325251&r2=325252&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Feb 15 07:30:22 2018
@@ -383,11 +383,18 @@ private:
 //   }
 // }
 //
-// In the first case we want to spread the contents inside the square
-// braces; in the second we want to keep them inline.
+// or repeated fields (in options):
+//
+// option (Aaa.options) = {
+//   keys: [ 1, 2, 3 ]
+// }
+//
+// In the first and the third case we want to spread the contents 
inside
+// the square braces; in the second we want to keep them inline.
 Left->Type = TT_ArrayInitializerLSquare;
 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
-tok::equal)) {
+tok::equal) &&
+!Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
   Left->Type = TT_ProtoExtensionLSquare;
   BindingIncrease = 10;
 }
@@ -2331,16 +2338,26 @@ bool TokenAnnotator::spaceRequiredBetwee
 !Left.Previous->isOneOf(tok::l_paren, tok::coloncolon));
   if (Right.is(tok::star) && Left.is(tok::l_paren))
 return false;
+  const auto SpaceRequiredForArrayInitializerLSquare =
+  [](const FormatToken &LSquareTok, const FormatStyle &Style) {
+return Style.SpacesInContainerLiterals ||
+   ((Style.Language == FormatStyle::LK_Proto ||
+ Style.Language == FormatStyle::LK_TextProto) &&
+!Style.Cpp11BracedListStyle &&
+LSquareTok.endsSequence(tok::l_square, tok::colon,
+TT_SelectorName));
+  };
   if (Left.is(tok::l_square))
-return (Left.is(TT_ArrayInitializerLSquare) &&
-Style.SpacesInContainerLiterals && Right.isNot(tok::r_square)) ||
+return (Left.is(TT_ArrayInitializerLSquare) && Right.isNot(tok::r_square) 
&&
+SpaceRequiredForArrayInitializerLSquare(Left, Style)) ||
(Left.isOneOf(TT_ArraySubscriptLSquare,
  TT_StructuredBindingLSquare) &&
 Style.SpacesInSquareBrackets && Right.isNot(tok::r_square));
   if (Right.is(tok::r_square))
 return Right.MatchingParen &&
-   ((Style.SpacesInContainerLiterals &&
- Right.MatchingParen->is(TT_ArrayInitializerLSquare)) ||
+   ((Right.MatchingParen->is(TT_ArrayInitializerLSquare) &&
+ SpaceRequiredForArrayInitializerLSquare(*Right.MatchingParen,
+ Style)) ||
 (Style.SpacesInSquareBrackets &&
  Right.MatchingParen->isOneOf(TT_ArraySubscriptLSquare,
   TT_StructuredBindingLSquare)));

Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=325252&r1=325251&r2=325252&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Thu Feb 15 07:30:22 2018
@@ -438,5 +438,35 @@ TEST_F(FormatTestProto, NoSpaceAfterPerc
"};");
 }
 
+TEST_F(FormatTestProto, FormatsRepeatedListInitializersInOptions) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: item\n"
+   "  keys: [\n"
+   "'ala',\n"
+   "'bala',\n"
+   "'porto',\n"
+   "'kala',\n"
+   "'too',\n"
+   "'long',\n"
+   "'long',\n"
+   "'long'\n"
+   "  ]\n"
+   "  key: [ item ]\n"
+   "  msg {\n"
+   "key: item\n"
+   "keys: [\n"
+   "  'ala',\n"
+   "  'bala',\n"
+   "  'porto',\n"
+   "  'kala',\n"
+   "  'too',\n"
+   "  'long',\n"
+   "  'long'\n"
+   

[PATCH] D43298: [clang-format] Support repeated field lists in protos

2018-02-15 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325252: [clang-format] Support repeated field lists in 
protos (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43298

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestProto.cpp
  cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp
@@ -31,14 +31,18 @@
 return *Result;
   }
 
-  static std::string format(llvm::StringRef Code) {
-FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
-Style.ColumnLimit = 60; // To make writing tests easier.
+  static std::string format(llvm::StringRef Code, const FormatStyle &Style) {
 return format(Code, 0, Code.size(), Style);
   }
 
+  static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) {
+EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+  }
+
   static void verifyFormat(llvm::StringRef Code) {
-EXPECT_EQ(Code.str(), format(test::messUp(Code)));
+FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+Style.ColumnLimit = 60; // To make writing tests easier.
+verifyFormat(Code, Style);
   }
 };
 
@@ -390,5 +394,43 @@
 TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
   verifyFormat("key: %d");
 }
+
+TEST_F(FormatTestTextProto, FormatsRepeatedListInitializers) {
+  verifyFormat("keys: []");
+  verifyFormat("keys: [ 1 ]");
+  verifyFormat("keys: [ 'ala', 'bala' ]");
+  verifyFormat("keys:\n"
+   "[ 'ala', 'bala', 'porto', 'kala', 'too', 'long', 'ng' ]");
+  verifyFormat("key: item\n"
+   "keys: [\n"
+   "  'ala',\n"
+   "  'bala',\n"
+   "  'porto',\n"
+   "  'kala',\n"
+   "  'too',\n"
+   "  'long',\n"
+   "  'long',\n"
+   "  'long'\n"
+   "]\n"
+   "key: item\n"
+   "msg {\n"
+   "  key: item\n"
+   "  keys: [\n"
+   "'ala',\n"
+   "'bala',\n"
+   "'porto',\n"
+   "'kala',\n"
+   "'too',\n"
+   "'long',\n"
+   "'long'\n"
+   "  ]\n"
+   "}\n"
+   "key: value"
+   );
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60; // To make writing tests easier.
+  Style.Cpp11BracedListStyle = true;
+  verifyFormat("keys: [1]", Style);
+}
 } // end namespace tooling
 } // end namespace clang
Index: cfe/trunk/unittests/Format/FormatTestProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp
@@ -438,5 +438,35 @@
"};");
 }
 
+TEST_F(FormatTestProto, FormatsRepeatedListInitializersInOptions) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: item\n"
+   "  keys: [\n"
+   "'ala',\n"
+   "'bala',\n"
+   "'porto',\n"
+   "'kala',\n"
+   "'too',\n"
+   "'long',\n"
+   "'long',\n"
+   "'long'\n"
+   "  ]\n"
+   "  key: [ item ]\n"
+   "  msg {\n"
+   "key: item\n"
+   "keys: [\n"
+   "  'ala',\n"
+   "  'bala',\n"
+   "  'porto',\n"
+   "  'kala',\n"
+   "  'too',\n"
+   "  'long',\n"
+   "  'long'\n"
+   "]\n"
+   "  }\n"
+   "  key: value\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -383,11 +383,18 @@
 //   }
 // }
 //
-// In the first case we want to spread the contents inside the square
-// braces; in the second we want to keep them inline.
+// or repeated fields (in options):
+//
+// option (Aaa.options) = {
+//   keys: [ 1, 2, 3 ]
+// }
+//
+// In the first and the third case we want to spread the contents inside
+// the square braces; in the second we want to keep them inline.
 Left->Type = TT_ArrayInitializerLSquare;
 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
-   

[PATCH] D41228: [ObjC] Enable __strong pointers in structs under ARC

2018-02-15 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 134430.
ahatanak marked 14 inline comments as done.
ahatanak added a comment.

Address review comments.


https://reviews.llvm.org/D41228

Files:
  docs/LanguageExtensions.rst
  include/clang/AST/Decl.h
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/ASTContext.cpp
  lib/AST/Decl.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGNonTrivialStruct.cpp
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenFunction.h
  lib/Lex/PPMacroExpansion.cpp
  lib/Sema/JumpDiagnostics.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  test/ARCMT/checking.m
  test/CodeGenObjC/nontrivial-c-struct-exception.m
  test/CodeGenObjC/nontrivial-c-struct-func-name-collision.m
  test/CodeGenObjC/strong-in-c-struct.m
  test/CodeGenObjCXX/arc-blocks.mm
  test/Lexer/has_feature_objc_arc.m
  test/SemaObjC/arc-decls.m
  test/SemaObjC/arc-system-header.m
  test/SemaObjC/strong-in-c-struct.m

Index: test/SemaObjC/strong-in-c-struct.m
===
--- /dev/null
+++ test/SemaObjC/strong-in-c-struct.m
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks  -fobjc-runtime=ios-11.0 -fsyntax-only -verify %s
+
+typedef struct {
+  id a;
+} Strong;
+
+void callee_variadic(const char *, ...);
+
+void test_variadic(void) {
+  Strong t;
+  callee_variadic("s", t); // expected-error {{cannot pass non-trivial C object of type 'Strong' by value to variadic function}}
+}
+
+void test_jump0(int cond) {
+  switch (cond) {
+  case 0:
+;
+Strong x; // expected-note {{jump bypasses initialization of variable of non-trivial C struct type}}
+break;
+  case 1: // expected-error {{cannot jump from switch statement to this case label}}
+x.a = 0;
+break;
+  }
+}
+
+void test_jump1(void) {
+  static void *ips[] = { &&L0 };
+L0:  // expected-note {{possible target of indirect goto}}
+  ;
+  Strong x; // expected-note {{jump exits scope of variable with non-trivial destructor}}
+  goto *ips; // expected-error {{cannot jump}}
+}
+
+typedef void (^BlockTy)(void);
+void func(BlockTy);
+void func2(Strong);
+
+void test_block_scope0(int cond) {
+  Strong x; // expected-note {{jump enters lifetime of block which captures a C struct that is non-trivial to destroy}}
+  switch (cond) {
+  case 0:
+func(^{ func2(x); });
+break;
+  default: // expected-error {{cannot jump from switch statement to this case label}}
+break;
+  }
+}
+
+void test_block_scope1(void) {
+  static void *ips[] = { &&L0 };
+L0:  // expected-note {{possible target of indirect goto}}
+  ;
+  Strong x; // expected-note {{jump exits scope of variable with non-trivial destructor}} expected-note {{jump exits lifetime of block which captures a C struct that is non-trivial to destroy}}
+  func(^{ func2(x); });
+  goto *ips; // expected-error {{cannot jump}}
+}
Index: test/SemaObjC/arc-system-header.m
===
--- test/SemaObjC/arc-system-header.m
+++ test/SemaObjC/arc-system-header.m
@@ -23,8 +23,7 @@
 }
 
 void test5(struct Test5 *p) {
-  p->field = 0; // expected-error {{'field' is unavailable in ARC}}
-// expected-note@arc-system-header.h:25 {{field has non-trivial ownership qualification}}
+  p->field = 0;
 }
 
 id test6() {
@@ -49,8 +48,7 @@
 
 extern void doSomething(Test9 arg);
 void test9() {
-Test9 foo2 = {0, 0}; // expected-error {{'field' is unavailable in ARC}}
- // expected-note@arc-system-header.h:56 {{field has non-trivial ownership qualification}}
+Test9 foo2 = {0, 0};
 doSomething(foo2);
 }
 #endif
Index: test/SemaObjC/arc-decls.m
===
--- test/SemaObjC/arc-decls.m
+++ test/SemaObjC/arc-decls.m
@@ -3,7 +3,7 @@
 // rdar://8843524
 
 struct A {
-id x; // expected-error {{ARC forbids Objective-C objects in struct}}
+id x;
 };
 
 union u {
@@ -13,7 +13,7 @@
 @interface I {
struct A a; 
struct B {
-id y[10][20]; // expected-error {{ARC forbids Objective-C objects in struct}}
+id y[10][20];
 id z;
} b;
 
@@ -23,7 +23,7 @@
 
 // rdar://10260525
 struct r10260525 {
-  id (^block) (); // expected-error {{ARC forbids blocks in struct}}
+  id (^block) ();
 };
 
 struct S { 
Index: test/Lexer/has_feature_objc_arc.m
===
--- test/Lexer/has_feature_objc_arc.m
+++ test/Lexer/has_feature_objc_arc.m
@@ -13,8 +13,16 @@
 void no_objc_arc_weak_feature();
 #endif
 
+#if __has_feature(objc_arc_fields)
+void has_objc_arc_fields();
+#else
+void no_objc_arc_fields();
+#endif
+
 // CHECK-ARC: void has_objc_arc_feature();
 // CHECK-ARC: void has_objc_arc_weak_feature();
+// CHECK-ARC: void has_objc_arc_fields();
 
 // CHECK-ARCLITE: void has_objc_arc_feat

[PATCH] D41228: [ObjC] Enable __strong pointers in structs under ARC

2018-02-15 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: include/clang/AST/Type.h:1137
+return isNonTrivialToPrimitiveDestroy() == PCK_Struct;
+  }
+

rjmccall wrote:
> Are these four queries really important enough to provide API for them on 
> QualType?
I removed these functions.



Comment at: lib/CodeGen/CGDecl.cpp:1299
+return;
+  }
+

rjmccall wrote:
> Again, it would be nice to restructure this code to use the result of 
> isNonTrivialToPrimitiveDefaultInitialize() exhaustively.
It looks like this code needs restructuring, but I didn't understand how I can 
use isNonTrivialToPrimitiveDefaultInitialize() here. The only change I made 
here is that drillIntoBlockVariable is called if the variable is byref. This 
fixes a bug where a non-trivial struct variable declared as __block wasn't 
initialized correctly.

Also, in the process, I found that when a c++ struct declared as a __block is 
captured by its initializer, an assertion fails (see test case in 
test/CodeGenObjCXX/arc-blocks.mm). I fixed the bug in 
CodeGenFunction::EmitExprAsInit, but I'm not sure that's the right way to fix 
it. I'm not sure what the comment "how can we delay here if D is captured by 
its initializer" means.



Comment at: lib/CodeGen/CGNonTrivialStruct.cpp:38
+  template 
+  static void visit(Visitor &V, QualType FT, bool IsVolatile, unsigned Offset,
+Ts... Args) {

rjmccall wrote:
> These visitors would be re-usable components outside of IRGen if they just 
> took a QualType and then forwarded an arbitrary set of other arguments.  I 
> would suggest structuring them like this:
> 
>   template  struct DestructedTypeVisitor {
> Derived &asDerived() { return static_cast(*this); }
> 
> template 
> RetTy visit(QualType Ty, Ts &&...Args) {
>   return asDerived().visit(Ty.isDestructedType(), Ty, 
> std::forward(Args)...);
> }
> 
> template 
> RetTy visit(QualType::DestructionKind DK, QualType Ty, Ts &&...Args) {
>   switch (DK) {
>   case QualType::DK_none: return asDerived().visitTrivial(Ty, 
> std::forward(Args)...);
>   case QualType::DK_cxx_destructor: return 
> asDerived().visitCXXDestructor(Ty, std::forward(Args)...);
>   ...
>   }
> }
>   };
> 
> You can then pretty easily add the special behavior for IsVolatile and arrays 
> (when DK is not DK_none) in an IRGen-specific subclass.  visitArray would 
> take a DK and then recurse by calling back into visit with that same DK.
I created three visitor classes that can be used outside of IRGen,



Comment at: lib/CodeGen/CGNonTrivialStruct.cpp:55
+  break;
+default:
+  break;

rjmccall wrote:
> Better not to have a default case here.  You can add an assert for the C++ 
> case that it should never get here.
I added llvm_unreachable in StructVisitor's methods visitWeak and 
visitCXXDestructor.


https://reviews.llvm.org/D41228



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


[PATCH] D43183: clang-format: introduce `CaseBlockIndent` to control indent in switch

2018-02-15 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

A user can create an error by reasoning like this, after the code has been 
formatted this way (a long time ago) : "oh, I need to make an extra function 
call, but in all cases ah, here is the end of the switch, let's put my 
function call here".

I am not saying it happens often, I am just saying it breaks indentation : i.e. 
that two nested blocks should not close at the same depth. Breaking such things 
makes code harder to read/understand, and when you don't properly get the code 
you can more easily make a mistake. Obviously it should be caught in testing, 
but it is not always.

That said, I am not trying to say in any way that my approach is better. I 
think both `CaseBlockIndent = Block` or your variant (with the extra line break 
before opening brace; but applying it all the time) will indeed be consistent 
with the code and not break indentation; keeping the current behavior when 
`IndentCaseLabels = true` is also not a problem IMHO.

> And to me (but this is obviously objective), your suggestions hide the 
> structure of the code even more as they lead to a state where the closing 
> brace is not aligned with the start of the line/statement that contains the 
> opening braces. That looks like a bug to me more than anything else and I 
> don't think there is another situation where clang-format would do that.

The exact same thing happens for functions blocks, class blocks and control 
statements, depending on BraceWrapping modes. Actually, IMO wrapping the 
opening brace should probably be done according to 
`BraceWrapping.AfterControlStatement` flag.

  // BraceWrapping.AfterControlStatement = false
  switch (x) {
  case 0: {
  foo();
  break;
}
  }
  // BraceWrapping.AfterControlStatement = true
  switch (x)
  {
  case 0:
{
  foo();
  break;
}
  }

But I agree the `CaseBlockIndent = ClosingBrace` mode is definitely not 
consistent with the code. I think it is clearer this way, but that is 
definitely my own subjective opinion: in this case, I accept to lose the extra 
indent for the sake of compactness and to somehow mimic the "regular" case 
blocks (e.g. which do not include an actual block), but that is indeed really 
my personnal way to read code.


Repository:
  rC Clang

https://reviews.llvm.org/D43183



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


[PATCH] D43232: clang-format: use AfterControlStatement to format ObjC control blocks

2018-02-15 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

In https://reviews.llvm.org/D43232#1008004, @benhamilton wrote:

> Thanks! Can you add a test for this, please?


There are actually tests, though they are performed by activating Allman brace 
wrapping mode.
I am trying to change them, but this highlights another issue: when only 
`AfterControlStatement` is set, the block gets inlined, like this:

  @autoreleasepool
  { f(); }

This used to happen before as well, and would require fixing 
UnwrappedLineFormatter.cpp to understand that these blocks are linked to the 
previous ObjC keyword.


Repository:
  rC Clang

https://reviews.llvm.org/D43232



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


[PATCH] D43232: clang-format: use AfterControlStatement to format ObjC control blocks

2018-02-15 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added a comment.

> This used to happen before as well, and would require fixing 
> UnwrappedLineFormatter.cpp to understand that these blocks are linked to the 
> previous ObjC keyword.

Good find! Looks like we should fix that and add some more tests with 
AfterControlStatement set to true and to false.


Repository:
  rC Clang

https://reviews.llvm.org/D43232



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


[clang-tools-extra] r325254 - [clangd] Fixed compilation with MVSC.

2018-02-15 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Feb 15 07:41:49 2018
New Revision: 325254

URL: http://llvm.org/viewvc/llvm-project?rev=325254&view=rev
Log:
[clangd] Fixed compilation with MVSC.

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

Modified: clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp?rev=325254&r1=325253&r2=325254&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp Thu Feb 15 07:41:49 
2018
@@ -32,9 +32,11 @@ template  struct CaptureProx
   operator UniqueFunction() && {
 assert(!Future.valid() && "conversion to callback called multiple times");
 Future = Promise.get_future();
-return BindWithForward([](std::promise Promise,
-  T Value) { Promise.set_value(std::move(Value)); 
},
-   std::move(Promise));
+return BindWithForward(
+[](std::promise> Promise, T Value) {
+  Promise.set_value(std::make_shared(std::move(Value)));
+},
+std::move(Promise));
   }
 
   ~CaptureProxy() {
@@ -42,13 +44,16 @@ template  struct CaptureProx
   return;
 assert(Future.valid() && "conversion to callback was not called");
 assert(!Target->hasValue());
-Target->emplace(Future.get());
+Target->emplace(std::move(*Future.get()));
   }
 
 private:
   llvm::Optional *Target;
-  std::promise Promise;
-  std::future Future;
+  // Using shared_ptr to workaround compilation errors with MSVC.
+  // MSVC only allows default-construcitble and copyable objects as future<>
+  // arguments.
+  std::promise> Promise;
+  std::future> Future;
 };
 
 template  CaptureProxy capture(llvm::Optional &Target) {


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


Re: [PATCH] D43227: [clangd] Make functions of ClangdServer callback-based

2018-02-15 Thread Ilya Biryukov via cfe-commits
Sorry about that, fixed in r325254.
I keep hitting this MSVC compilation error all the time.


On Thu, Feb 15, 2018 at 4:26 PM Carlos Alberto Enciso via Phabricator <
revi...@reviews.llvm.org> wrote:

> CarlosAlbertoEnciso added a comment.
>
> Hi,
>
> It seems that your submission broke the Windows/Linux builds for 'clangd'.
>
> The generated error message is:
>
>   C:\Program Files (x86)\Microsoft Visual Studio
> 14.0\VC\include\future(263): error C2512:
> 'llvm::Expected>>':
> no appropriate default constructor available
> [C:\j\w\opensource\opensource_to_sce_merge\build\tools\clang\tools\extra\unittests\clangd\ClangdTests.vcxproj]
>
>   C:\xxx\llvm\tools\clang\tools\extra\clangd\ClangdServer.h(231): note:
> see declaration of
> 'llvm::Expected>>'
>   C:\Program Files (x86)\Microsoft Visual Studio
> 14.0\VC\include\future(255): note: while compiling class template member
> function
> 'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)'
>   C:\Program Files (x86)\Microsoft Visual Studio
> 14.0\VC\include\future(1491): note: see reference to function template
> instantiation
> 'std::_Associated_state<_Ty>::_Associated_state(std::_Deleter_base<_Ty> *)'
> being compiled
>   C:\Program Files (x86)\Microsoft Visual Studio
> 14.0\VC\include\future(989): note: see reference to class template
> instantiation 'std::_Associated_state<_Ty>' being compiled
>   C:\Program Files (x86)\Microsoft Visual Studio
> 14.0\VC\include\future(987): note: while compiling class template member
> function 'bool std::_State_manager<_Ty>::valid(void) throw() const'
>
> Thanks
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D43227
>
>
>
>

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


[PATCH] D38639: [clangd] #include statements support for Open definition

2018-02-15 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle updated this revision to Diff 134432.
malaperle added a comment.

Use EXPECT_THAT in a few places and clean-ups in tests.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38639

Files:
  clangd/ClangdUnit.cpp
  clangd/ClangdUnit.h
  clangd/Protocol.h
  clangd/SourceCode.cpp
  clangd/SourceCode.h
  clangd/XRefs.cpp
  unittests/clangd/XRefsTests.cpp

Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -36,6 +36,7 @@
 namespace {
 using testing::ElementsAre;
 using testing::Field;
+using testing::IsEmpty;
 using testing::Matcher;
 using testing::UnorderedElementsAreArray;
 
@@ -259,6 +260,73 @@
SourceAnnotations.range()}));
 }
 
+TEST(GoToInclude, All) {
+  MockFSProvider FS;
+  IgnoreDiagnostics DiagConsumer;
+  MockCompilationDatabase CDB;
+
+  ClangdServer Server(CDB, DiagConsumer, FS, getDefaultAsyncThreadsCount(),
+  /*StorePreamblesInMemory=*/true);
+
+  auto FooCpp = getVirtualTestFilePath("foo.cpp");
+  const char *SourceContents = R"cpp(
+  #include ^"$2^foo.h$3^"
+  #include "$4^invalid.h"
+  int b = a;
+  // test
+  int foo;
+  #in$5^clude "$6^foo.h"$7^
+  )cpp";
+  Annotations SourceAnnotations(SourceContents);
+  FS.Files[FooCpp] = SourceAnnotations.code();
+  auto FooH = getVirtualTestFilePath("foo.h");
+  auto FooHUri = URIForFile{FooH.str()};
+
+  const char *HeaderContents = R"cpp([[]]int a;)cpp";
+  Annotations HeaderAnnotations(HeaderContents);
+  FS.Files[FooH] = HeaderAnnotations.code();
+
+  Server.addDocument(FooH, HeaderAnnotations.code());
+  Server.addDocument(FooCpp, SourceAnnotations.code());
+
+  // Test include in preamble.
+  auto Locations =
+  runFindDefinitions(Server, FooCpp, SourceAnnotations.point());
+  EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
+  EXPECT_THAT(Locations->Value,
+  ElementsAre(Location{FooHUri, HeaderAnnotations.range()}));
+
+  // Test include in preamble, last char.
+  Locations = runFindDefinitions(Server, FooCpp, SourceAnnotations.point("2"));
+  EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
+  EXPECT_THAT(Locations->Value,
+  ElementsAre(Location{FooHUri, HeaderAnnotations.range()}));
+
+  Locations = runFindDefinitions(Server, FooCpp, SourceAnnotations.point("3"));
+  EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
+  EXPECT_THAT(Locations->Value,
+  ElementsAre(Location{FooHUri, HeaderAnnotations.range()}));
+
+  // Test include outside of preamble.
+  Locations = runFindDefinitions(Server, FooCpp, SourceAnnotations.point("6"));
+  EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
+  EXPECT_THAT(Locations->Value,
+  ElementsAre(Location{FooHUri, HeaderAnnotations.range()}));
+
+  // Test a few positions that do not result in Locations.
+  Locations = runFindDefinitions(Server, FooCpp, SourceAnnotations.point("4"));
+  EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
+  EXPECT_THAT(Locations->Value, IsEmpty());
+
+  Locations = runFindDefinitions(Server, FooCpp, SourceAnnotations.point("5"));
+  EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
+  EXPECT_THAT(Locations->Value, IsEmpty());
+
+  Locations = runFindDefinitions(Server, FooCpp, SourceAnnotations.point("7"));
+  EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
+  EXPECT_THAT(Locations->Value, IsEmpty());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/XRefs.cpp
===
--- clangd/XRefs.cpp
+++ clangd/XRefs.cpp
@@ -8,6 +8,7 @@
 //===-===//
 #include "XRefs.h"
 #include "Logger.h"
+#include "SourceCode.h"
 #include "URI.h"
 #include "clang/Index/IndexDataConsumer.h"
 #include "clang/Index/IndexingAction.h"
@@ -130,12 +131,8 @@
 return llvm::None;
   SourceLocation LocEnd = Lexer::getLocForEndOfToken(ValSourceRange.getEnd(), 0,
  SourceMgr, LangOpts);
-  Position Begin;
-  Begin.line = SourceMgr.getSpellingLineNumber(LocStart) - 1;
-  Begin.character = SourceMgr.getSpellingColumnNumber(LocStart) - 1;
-  Position End;
-  End.line = SourceMgr.getSpellingLineNumber(LocEnd) - 1;
-  End.character = SourceMgr.getSpellingColumnNumber(LocEnd) - 1;
+  Position Begin = sourceLocToPosition(SourceMgr, LocStart);
+  Position End = sourceLocToPosition(SourceMgr, LocEnd);
   Range R = {Begin, End};
   Location L;
 
@@ -193,6 +190,15 @@
   Result.push_back(*L);
   }
 
+  /// Process targets for paths inside #include directive.
+  for (auto &IncludeLoc : AST.getInclusionLocations()) {
+Range R = IncludeLoc.first;
+Position Pos = sourceLocToPosition(SourceMgr, SourceLocationBeg);
+

[PATCH] D43232: clang-format: use AfterControlStatement to format ObjC control blocks

2018-02-15 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

I'll try to fix this.

Can you please review D43114  in the mean 
time? This patch depends on it, so it must be merged first.


Repository:
  rC Clang

https://reviews.llvm.org/D43232



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


[PATCH] D43183: clang-format: introduce `CaseBlockIndent` to control indent in switch

2018-02-15 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

In https://reviews.llvm.org/D43183#1008784, @Typz wrote:

> A user can create an error by reasoning like this, after the code has been 
> formatted this way (a long time ago) : "oh, I need to make an extra function 
> call, but in all cases ah, here is the end of the switch, let's put my 
> function call here".


And then trying to format it with clang-format they'll be immediately thrown 
off because clang-format gets the indentation wrong :).
But I don't want to argue this to death. I understand what you are saying. I 
just don't think any of your suggested formats make this situation better.

> I am not saying it happens often, I am just saying it breaks indentation : 
> i.e. that two nested blocks should not close at the same depth. Breaking such 
> things makes code harder to read/understand, and when you don't properly get 
> the code you can more easily make a mistake. Obviously it should be caught in 
> testing, but it is not always.
> 
> That said, I am not trying to say in any way that my approach is better. I 
> think both `CaseBlockIndent = Block` or your variant (with the extra line 
> break before opening brace; but applying it all the time) will indeed be 
> consistent with the code and not break indentation; keeping the current 
> behavior when `IndentCaseLabels = true` is also not a problem IMHO.

An extra thing to consider is that my approach is also consistent with having 
something before this block:

  case A:
{
  f();
  g();
}
h();
break;
  case B:
f();
{
  g();
}
h();
break;

>> And to me (but this is obviously objective), your suggestions hide the 
>> structure of the code even more as they lead to a state where the closing 
>> brace is not aligned with the start of the line/statement that contains the 
>> opening braces. That looks like a bug to me more than anything else and I 
>> don't think there is another situation where clang-format would do that.
> 
> The exact same thing happens for functions blocks, class blocks and control 
> statements, depending on BraceWrapping modes. Actually, IMO wrapping the 
> opening brace should probably be done according to 
> `BraceWrapping.AfterControlStatement` flag.
> 
>   // BraceWrapping.AfterControlStatement = false
>   switch (x) {
>   case 0: {
>   foo();
>   break;
> }
>   }
>   // BraceWrapping.AfterControlStatement = true
>   switch (x)
>   {
>   case 0:
> {
>   foo();
>   break;
> }
>   }
> 
> But I agree the `CaseBlockIndent = ClosingBrace` mode is definitely not 
> consistent with the code. I think it is clearer this way, but that is 
> definitely my own subjective opinion: in this case, I accept to lose the 
> extra indent for the sake of compactness and to somehow mimic the "regular" 
> case blocks (e.g. which do not include an actual block), but that is indeed 
> really my personnal way to read code.

I don't agree that that's the same thing. The closing brace is still neatly 
aligned with the line of the opening brace (which happens to be just the 
opening brace).


Repository:
  rC Clang

https://reviews.llvm.org/D43183



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


[PATCH] D43114: clang-format: fix formatting of ObjC @synchronized blocks

2018-02-15 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton accepted this revision.
benhamilton added a comment.
This revision is now accepted and ready to land.

Just a question on the test.




Comment at: unittests/Format/FormatTestObjC.cpp:193-198
+  verifyFormat("@synchronized(self) {\n"
+   "  f();\n"
+   "}\n"
+   "@synchronized(self) {\n"
+   "  f();\n"
+   "}\n");

Why is the block repeated twice?



Comment at: unittests/Format/FormatTestObjC.cpp:200-207
+  verifyFormat("@synchronized(self)\n"
+   "{\n"
+   "  f();\n"
+   "}\n"
+   "@synchronized(self)\n"
+   "{\n"
+   "  f();\n"

Same question.


Repository:
  rC Clang

https://reviews.llvm.org/D43114



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


[clang-tools-extra] r325257 - [clangd] Use explicit env in test to make lit+windows happy. NFC

2018-02-15 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Feb 15 08:20:33 2018
New Revision: 325257

URL: http://llvm.org/viewvc/llvm-project?rev=325257&view=rev
Log:
[clangd] Use explicit env in test to make lit+windows happy. NFC

Modified:
clang-tools-extra/trunk/test/clangd/trace.test

Modified: clang-tools-extra/trunk/test/clangd/trace.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clangd/trace.test?rev=325257&r1=325256&r2=325257&view=diff
==
--- clang-tools-extra/trunk/test/clangd/trace.test (original)
+++ clang-tools-extra/trunk/test/clangd/trace.test Thu Feb 15 08:20:33 2018
@@ -1,4 +1,4 @@
-# RUN: CLANGD_TRACE=%t clangd -lit-test < %s && FileCheck %s < %t
+# RUN: env CLANGD_TRACE=%t clangd -lit-test < %s && FileCheck %s < %t
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---
 
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.c","languageId":"c","version":1,"text":"void
 main() {}"}}}


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


[clang-tools-extra] r325260 - [clangd] Create trace::Span when running ASTCallback

2018-02-15 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Thu Feb 15 08:24:34 2018
New Revision: 325260

URL: http://llvm.org/viewvc/llvm-project?rev=325260&view=rev
Log:
[clangd] Create trace::Span when running ASTCallback

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

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=325260&r1=325259&r2=325260&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Thu Feb 15 08:24:34 2018
@@ -439,8 +439,10 @@ CppFile::rebuild(ParseInputs &&Inputs) {
 Diagnostics.insert(Diagnostics.end(), NewAST->getDiagnostics().begin(),
NewAST->getDiagnostics().end());
   }
-  if (ASTCallback && NewAST)
+  if (ASTCallback && NewAST) {
+trace::Span Tracer("Running ASTCallback");
 ASTCallback(FileName, NewAST.getPointer());
+  }
 
   // Write the results of rebuild into class fields.
   Preamble = std::move(NewPreamble);


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


r325261 - Amend r325256. This change was not properly merged locally before the commit happened.

2018-02-15 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Feb 15 08:28:10 2018
New Revision: 325261

URL: http://llvm.org/viewvc/llvm-project?rev=325261&view=rev
Log:
Amend r325256. This change was not properly merged locally before the commit 
happened.

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

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=325261&r1=325260&r2=325261&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Feb 15 08:28:10 2018
@@ -6029,7 +6029,7 @@ static void ProcessDeclAttribute(Sema &S
 handleAlwaysInlineAttr(S, D, AL);
 break;
   case AttributeList::AT_Artificial:
-handleSimpleAttribute(S, D, Attr);
+handleSimpleAttribute(S, D, AL);
 break;
   case AttributeList::AT_AnalyzerNoReturn:
 handleAnalyzerNoReturnAttr(S, D, AL);


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


[PATCH] D35894: [clangd] Code hover for Clangd

2018-02-15 Thread Simon Marchi via Phabricator via cfe-commits
simark added inline comments.



Comment at: clangd/XRefs.cpp:354
+
+  return Name;
+}

ilya-biryukov wrote:
> We should call `flush()` before returning `Name` here. The 
> `raw_string_ostream` is buffered.
I replaced it with `Stream.str()`.



Comment at: clangd/XRefs.cpp:373
+
+  return {};
+}

ilya-biryukov wrote:
> NIT: use `llvm::None` here instead of `{}`
Done.



Comment at: clangd/XRefs.cpp:394
+
+  //  SourceRange SR = D->getSourceRange();
+

ilya-biryukov wrote:
> Accidental leftover from previous code?
Oops, thanks.



Comment at: unittests/clangd/XRefsTests.cpp:262
+  struct OneTest {
+StringRef input;
+StringRef expectedHover;

ilya-biryukov wrote:
> NIT: LLVM uses `UpperCamelCase` for field names.
Ok, I fixed all the structs this patch adds.



Comment at: unittests/clangd/XRefsTests.cpp:561
+
+EXPECT_EQ(H.contents.value, Test.expectedHover.str()) << Test.input;
+  }

ilya-biryukov wrote:
> simark wrote:
> > Note that I used `.str()` here to make the output of failing tests readable 
> > and useful.  By default, gtest tries to print StringRef as if it was a 
> > container.  I tried to make add a `PrintTo` function to specify how it 
> > should be printed, but couldn't get it to work (to have it called by the 
> > compiler), so I settled for this.
> Thanks for spotting that.
> We have a fix for that in LLVM's gtest extensions (D43330).
> `str()` can now be removed.
Removed.  Even if this patch is merged before D43330 it's not a big deal, since 
it only affects debug output of failing test cases.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D35894



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


[PATCH] D35894: [clangd] Code hover for Clangd

2018-02-15 Thread Simon Marchi via Phabricator via cfe-commits
simark updated this revision to Diff 134437.
simark added a comment.

New version

- Rebase on master, change findHover to have a callback-based interface
- Fix nits from previous review comments


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D35894

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  clangd/XRefs.cpp
  clangd/XRefs.h
  test/clangd/hover.test
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  unittests/clangd/XRefsTests.cpp

Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -259,6 +259,311 @@
SourceAnnotations.range()}));
 }
 
+TEST(Hover, All) {
+  struct OneTest {
+StringRef Input;
+StringRef ExpectedHover;
+  };
+
+  OneTest Tests[] = {
+  {
+  R"cpp(// Local variable
+int main() {
+  int bonjour;
+  ^bonjour = 2;
+  int test1 = bonjour;
+}
+  )cpp",
+  "Declared in function main\n\nint bonjour",
+  },
+  {
+  R"cpp(// Local variable in method
+struct s {
+  void method() {
+int bonjour;
+^bonjour = 2;
+  }
+};
+  )cpp",
+  "Declared in function s::method\n\nint bonjour",
+  },
+  {
+  R"cpp(// Struct
+namespace ns1 {
+  struct MyClass {};
+} // namespace ns1
+int main() {
+  ns1::My^Class* Params;
+}
+  )cpp",
+  "Declared in namespace ns1\n\nstruct MyClass {}",
+  },
+  {
+  R"cpp(// Class
+namespace ns1 {
+  class MyClass {};
+} // namespace ns1
+int main() {
+  ns1::My^Class* Params;
+}
+  )cpp",
+  "Declared in namespace ns1\n\nclass MyClass {}",
+  },
+  {
+  R"cpp(// Union
+namespace ns1 {
+  union MyUnion { int x; int y; };
+} // namespace ns1
+int main() {
+  ns1::My^Union Params;
+}
+  )cpp",
+  "Declared in namespace ns1\n\nunion MyUnion {}",
+  },
+  {
+  R"cpp(// Function definition via pointer
+int foo(int) {}
+int main() {
+  auto *X = &^foo;
+}
+  )cpp",
+  "Declared in global namespace\n\nint foo(int)",
+  },
+  {
+  R"cpp(// Function declaration via call
+int foo(int);
+int main() {
+  return ^foo(42);
+}
+  )cpp",
+  "Declared in global namespace\n\nint foo(int)",
+  },
+  {
+  R"cpp(// Field
+struct Foo { int x; };
+int main() {
+  Foo bar;
+  bar.^x;
+}
+  )cpp",
+  "Declared in struct Foo\n\nint x",
+  },
+  {
+  R"cpp(// Field with initialization
+struct Foo { int x = 5; };
+int main() {
+  Foo bar;
+  bar.^x;
+}
+  )cpp",
+  "Declared in struct Foo\n\nint x = 5",
+  },
+  {
+  R"cpp(// Static field
+struct Foo { static int x; };
+int main() {
+  Foo::^x;
+}
+  )cpp",
+  "Declared in struct Foo\n\nstatic int x",
+  },
+  {
+  R"cpp(// Field, member initializer
+struct Foo {
+  int x;
+  Foo() : ^x(0) {}
+};
+  )cpp",
+  "Declared in struct Foo\n\nint x",
+  },
+  {
+  R"cpp(// Field, GNU old-style field designator
+struct Foo { int x; };
+int main() {
+  Foo bar = { ^x : 1 };
+}
+  )cpp",
+  "Declared in struct Foo\n\nint x",
+  },
+  {
+  R"cpp(// Field, field designator
+struct Foo { int x; };
+int main() {
+  Foo bar = { .^x = 2 };
+}
+  )cpp",
+  "Declared in struct Foo\n\nint x",
+  },
+  {
+  R"cpp(// Method call
+struct Foo { int x(); };
+int main() {
+  Foo bar;
+  bar.^x();
+}
+  )cpp",
+  "Declared in struct Foo\n\nint x()",
+  },
+  {
+  R"cpp(// Static method call
+struct Foo { static int x(); };
+int main() {
+  Foo::^x();
+}
+  )cpp",
+  "Declared in struct Foo\n\nstatic int x()",
+  },
+  {
+  R"cpp(// Typedef
+typede

[PATCH] D35894: [clangd] Code hover for Clangd

2018-02-15 Thread Simon Marchi via Phabricator via cfe-commits
simark added a comment.

In https://reviews.llvm.org/D35894#1008593, @ilya-biryukov wrote:

> Just a few last remarks and this is good to go.
>  Should I land it for you after the last comments are fixed?


I just received my commit access, so if you are ok with it, I would try to push 
it once I get your final OK.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D35894



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


[PATCH] D35894: [clangd] Code hover for Clangd

2018-02-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Only the naming of fields left.

Also, please make sure to run `git-clang-format` on the code before submitting 
to make sure it's formatted properly.




Comment at: clangd/ClangdLSPServer.cpp:331
+ if (!H) {
+   replyError(ErrorCode::InternalError,
+  llvm::toString(H.takeError()));

NIT: use `return replyError` to be consistent with other methods.



Comment at: clangd/XRefs.cpp:354
+
+  return Name;
+}

simark wrote:
> ilya-biryukov wrote:
> > We should call `flush()` before returning `Name` here. The 
> > `raw_string_ostream` is buffered.
> I replaced it with `Stream.str()`.
Also works, albeit less efficient (will probably do a copy where move is 
enough).



Comment at: unittests/clangd/XRefsTests.cpp:262
+  struct OneTest {
+StringRef input;
+StringRef expectedHover;

simark wrote:
> ilya-biryukov wrote:
> > NIT: LLVM uses `UpperCamelCase` for field names.
> Ok, I fixed all the structs this patch adds.
Argh, sorry that I didn't mention it before, but we have an exception for 
structs in `Procotol.h`, they follow the spelling in the LSP spec (i.e. should 
be `lowerCamelCase`).



Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D35894



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


r325264 - [OpenCL] Fix __enqueue_block for block with captures

2018-02-15 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Thu Feb 15 08:39:19 2018
New Revision: 325264

URL: http://llvm.org/viewvc/llvm-project?rev=325264&view=rev
Log:
[OpenCL] Fix __enqueue_block for block with captures

The following test case causes issue with codegen of __enqueue_block

void (^block)(void) = ^{ callee(id, out); };

enqueue_kernel(queue, 0, ndrange, block);
Clang first does codegen for block expression in the first line and deletes its 
block info.
Clang then tries to do codegen for the same block expression again for the 
second line,
and fails because the block info is gone.

The fix is to do normal codegen for both lines. Introduce an API to OpenCL 
runtime to
record llvm block invoke function and llvm block literal emitted for each AST 
block
expression, and use the recorded information for generating the wrapper kernel.

The EmitBlockLiteral APIs are cleaned up to minimize changes to the normal 
codegen
of blocks.

Another minor issue is that some clean up AST expression is generated for block
with captures, which can be stripped by IgnoreImplicit.

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

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.h
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=325264&r1=325263&r2=325264&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Thu Feb 15 08:39:19 2018
@@ -740,27 +740,19 @@ void CodeGenFunction::destroyBlockInfos(
 }
 
 /// Emit a block literal expression in the current function.
-llvm::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr,
-   llvm::Function **InvokeF) {
+llvm::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr) {
   // If the block has no captures, we won't have a pre-computed
   // layout for it.
   if (!blockExpr->getBlockDecl()->hasCaptures()) {
 // The block literal is emitted as a global variable, and the block invoke
 // function has to be extracted from its initializer.
 if (llvm::Constant *Block = CGM.getAddrOfGlobalBlockIfEmitted(blockExpr)) {
-  if (InvokeF) {
-auto *GV = cast(
-cast(Block)->stripPointerCasts());
-auto *BlockInit = cast(GV->getInitializer());
-*InvokeF = cast(
-BlockInit->getAggregateElement(2)->stripPointerCasts());
-  }
   return Block;
 }
 CGBlockInfo blockInfo(blockExpr->getBlockDecl(), CurFn->getName());
 computeBlockInfo(CGM, this, blockInfo);
 blockInfo.BlockExpression = blockExpr;
-return EmitBlockLiteral(blockInfo, InvokeF);
+return EmitBlockLiteral(blockInfo);
   }
 
   // Find the block info for this block and take ownership of it.
@@ -769,11 +761,10 @@ llvm::Value *CodeGenFunction::EmitBlockL
  blockExpr->getBlockDecl()));
 
   blockInfo->BlockExpression = blockExpr;
-  return EmitBlockLiteral(*blockInfo, InvokeF);
+  return EmitBlockLiteral(*blockInfo);
 }
 
-llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo,
-   llvm::Function **InvokeF) {
+llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) {
   bool IsOpenCL = CGM.getContext().getLangOpts().OpenCL;
   auto GenVoidPtrTy =
   IsOpenCL ? CGM.getOpenCLRuntime().getGenericVoidPointerType() : 
VoidPtrTy;
@@ -788,8 +779,6 @@ llvm::Value *CodeGenFunction::EmitBlockL
   BlockCGF.SanOpts = SanOpts;
   auto *InvokeFn = BlockCGF.GenerateBlockFunction(
   CurGD, blockInfo, LocalDeclMap, isLambdaConv, blockInfo.CanBeGlobal);
-  if (InvokeF)
-*InvokeF = InvokeFn;
   auto *blockFn = llvm::ConstantExpr::getPointerCast(InvokeFn, GenVoidPtrTy);
 
   // If there is nothing to capture, we can emit this as a global block.
@@ -1024,6 +1013,11 @@ llvm::Value *CodeGenFunction::EmitBlockL
   llvm::Value *result = Builder.CreatePointerCast(
   blockAddr.getPointer(), 
ConvertType(blockInfo.getBlockExpr()->getType()));
 
+  if (IsOpenCL) {
+CGM.getOpenCLRuntime().recordBlockInfo(blockInfo.BlockExpression, InvokeFn,
+   result);
+  }
+
   return result;
 }
 
@@ -1287,6 +1281,10 @@ static llvm::Constant *buildGlobalBlock(
   llvm::Constant *Result =
   llvm::ConstantExpr::getPointerCast(literal, RequiredType);
   CGM.setAddrOfGlobalBlock(blockInfo.BlockExpression, Result);
+  if (CGM.getContext().getLangOpts().OpenCL)
+CGM.getOpenCLRuntime().recordBlockInfo(
+blockInfo.BlockExpression,
+cast(blockFn->stripPointerCasts()), Result);
   return Result;
 }
 

[PATCH] D43240: [OpenCL] Fix __enqueue_block for block with captures

2018-02-15 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325264: [OpenCL] Fix __enqueue_block for block with captures 
(authored by yaxunl, committed by ).
Herald added subscribers: llvm-commits, nhaehnle.

Changed prior to commit:
  https://reviews.llvm.org/D43240?vs=134041&id=134439#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43240

Files:
  cfe/trunk/lib/CodeGen/CGBlocks.cpp
  cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp
  cfe/trunk/lib/CodeGen/CGOpenCLRuntime.h
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
  cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Index: cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -29,6 +29,10 @@
 // COMMON: define internal spir_func void [[INV_G]](i8 addrspace(4)* %{{.*}}, i8 addrspace(3)* %{{.*}})
 const bl_t block_G = (bl_t) ^ (local void *a) {};
 
+void callee(int id, __global int *out) {
+  out[id] = id;
+}
+
 // COMMON-LABEL: define spir_kernel void @device_side_enqueue(i32 addrspace(1)* %{{.*}}, i32 addrspace(1)* %b, i32 %i)
 kernel void device_side_enqueue(global int *a, global int *b, int i) {
   // COMMON: %default_queue = alloca %opencl.queue_t*
@@ -282,6 +286,21 @@
   // COMMON: call spir_func void [[r2]](i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BLG8]] to i8 addrspace(1)*) to i8 addrspace(4)*))
   block_A();
 
+  void (^block_C)(void) = ^{
+callee(i, a);
+  };
+
+  // Emits block literal on stack and block kernel [[INVLK3]].
+  // COMMON: store i8 addrspace(4)* addrspacecast (i8* bitcast (void (i8 addrspace(4)*)* [[INVL3:@__device_side_enqueue_block_invoke[^ ]*]] to i8*) to i8 addrspace(4)*), i8 addrspace(4)** %block.invoke
+  // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue
+  // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
+  // COMMON: [[BL_I8:%[0-9]+]] = addrspacecast void ()* {{.*}} to i8 addrspace(4)*
+  // COMMON-LABEL: call i32 @__enqueue_kernel_basic(
+  // COMMON-SAME: %opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* byval [[NDR]]{{([0-9]+)?}},
+  // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVLK3:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
+  // COMMON-SAME: i8 addrspace(4)* [[BL_I8]])
+  enqueue_kernel(default_queue, flags, ndrange, block_C);
+
   // Emits global block literal [[BLG9]] and block kernel [[INVGK9]]. [[INVGK9]] calls [[INV9]].
   // COMMON: call i32 @__get_kernel_work_group_size_impl(
   // COMMON-SAME: i8 addrspace(4)* addrspacecast (i8* bitcast ({{.*}} [[INVGK9:[^ ]+_kernel]] to i8*) to i8 addrspace(4)*),
@@ -333,6 +352,7 @@
 // COMMON: define internal spir_func void [[INVG8]](i8 addrspace(4)*{{.*}})
 // COMMON: define internal spir_func void [[INVG9]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)* %{{.*}})
 // COMMON: define internal spir_kernel void [[INVGK8]](i8 addrspace(4)*{{.*}})
+// COMMON: define internal spir_kernel void [[INVLK3]](i8 addrspace(4)*{{.*}})
 // COMMON: define internal spir_kernel void [[INVGK9]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}})
 // COMMON: define internal spir_kernel void [[INV_G_K]](i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}})
 // COMMON: define internal spir_kernel void [[INVGK10]](i8 addrspace(4)*{{.*}})
Index: cfe/trunk/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
===
--- cfe/trunk/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
+++ cfe/trunk/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
@@ -2,6 +2,10 @@
 
 typedef struct {int a;} ndrange_t;
 
+void callee(long id, global long *out) {
+  out[id] = id;
+}
+
 // CHECK-LABEL: define amdgpu_kernel void @test
 kernel void test(global char *a, char b, global long *c, long d) {
   queue_t default_queue;
@@ -24,6 +28,12 @@
  c[0] = d;
  ((local int*)lp)[0] = 1;
  }, 100);
+
+  void (^block)(void) = ^{
+callee(d, c);
+  };
+
+  enqueue_kernel(default_queue, flags, ndrange, block);
 }
 
 // CHECK-LABEL: define internal amdgpu_kernel void @__test_block_invoke_kernel(<{ i32, i32, i8*, i8 addrspace(1)*, i8 }>)
@@ -42,4 +52,7 @@
 // CHECK-LABEL: define internal amdgpu_kernel void @__test_block_invoke_3_kernel(<{ i32, i32, i8*, i8 addrspace(1)*, i64 addrspace(1)*, i64, i8 }>, i8 addrspace(3)*)
 // CHECK-SAME: #[[ATTR]] !kernel_arg_addr_space !{{.*}} !kernel_arg_access_qual !{{.*}} !kernel_arg_type !{{.*}} !kernel_arg_base_type !{{.*}} !kernel_arg_type_qual !{{.*}}
 
+// CHECK-LABEL: define internal amdgpu_kernel void @__test_block_invoke_4_kernel(<{ i32, i32, i8*, i64, i64 addrspace(1)* }>)
+// CHECK-SAME: #[[ATTR]] !kernel_arg_addr_space !{{.*}} !kernel_arg_access_qual !{{.*}} !kernel_

[PATCH] D38639: [clangd] #include statements support for Open definition

2018-02-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM modulo the `ASSERT_TRUE` nit.




Comment at: unittests/clangd/XRefsTests.cpp:295
+  runFindDefinitions(Server, FooCpp, SourceAnnotations.point());
+  EXPECT_TRUE(bool(Locations)) << "findDefinitions returned an error";
+  EXPECT_THAT(Locations->Value,

Maybe replace with `ASSERT_TRUE`?
If `Locations` has an error, an assertion will fire in debug mode inside 
`Expected` that the error was not handled.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D38639



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


[PATCH] D41880: Adding nocf_check attribute for cf-protection fine tuning

2018-02-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Sema/SemaDeclAttr.cpp:1990
 
-bool Sema::CheckNoReturnAttr(const AttributeList &Attrs) {
-  if (!checkAttributeNumArgs(*this, Attrs, 0)) {
-Attrs.setInvalid();
+static void handleNoCfCheckAttr(Sema &S, Decl *D, const AttributeList &attr) {
+  if (S.CheckAttrTarget(attr) || S.CheckAttrNoArgs(attr))

oren_ben_simhon wrote:
> aaron.ballman wrote:
> > oren_ben_simhon wrote:
> > > aaron.ballman wrote:
> > > > aaron.ballman wrote:
> > > > > `attr` doesn't follow the proper naming conventions.
> > > > Please don't name the parameter variable after a type -- that can 
> > > > confuse some editors.
> > > I am following the same convention that other functions are using.
> > > I am following the same convention that other functions are using.
> > 
> > They're doing it wrong. I can clean those up in a separate patch.
> Its OK i can make the change.
I've commit a cleanup in r325256 that fixes the identifiers in the file (along 
with several other coding standard issues).



Comment at: test/Sema/attr-nocf_check.c:18-20
+  FuncPointerWithNoCfCheck fNoCfCheck = f; // no-warning
+  (*fNoCfCheck)();   // no-warning
+  f = fNoCfCheck;// no-warning

oren_ben_simhon wrote:
> aaron.ballman wrote:
> > oren_ben_simhon wrote:
> > > aaron.ballman wrote:
> > > > These are an error in GCC and I think we should match that behavior. 
> > > > https://godbolt.org/g/r3pf4X
> > > I will create a warning however in LLVM we don't create an error upon 
> > > incompatible pointer due to function attribute types.
> > It should be an error -- Clang does error on this sort of thing when 
> > appropriate (which I believe it is, here). For instance, calling convention 
> > attributes do this: https://godbolt.org/g/mkTGLg
> In Clang there is Sema::IncompatiblePointer in case to pointers are not 
> compatible. This flag emits warning message. In the time i check for pointer 
> incompatibility (checkPointerTypesForAssignment()), i don;t have a handle to 
> the attributes. Any suggestion how to implement the exception for nocf_check 
> attribute?
I believe this is handled in `ASTContext::mergeFunctionType()`. See:
```
  // Compatible functions must have compatible calling conventions
  if (lbaseInfo.getCC() != rbaseInfo.getCC())
return QualType();
```
Somewhere around there is likely where you should be.


Repository:
  rL LLVM

https://reviews.llvm.org/D41880



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


[PATCH] D35894: [clangd] Code hover for Clangd

2018-02-15 Thread Simon Marchi via Phabricator via cfe-commits
simark added a comment.

In https://reviews.llvm.org/D35894#1008861, @ilya-biryukov wrote:

> Only the naming of fields left.
>
> Also, please make sure to run `git-clang-format` on the code before 
> submitting to make sure it's formatted properly.


Ahh, I was running clang-format by hand, didn't know about git-clang-format 
(and obviously forgot some files). Thanks.




Comment at: clangd/ClangdLSPServer.cpp:331
+ if (!H) {
+   replyError(ErrorCode::InternalError,
+  llvm::toString(H.takeError()));

ilya-biryukov wrote:
> NIT: use `return replyError` to be consistent with other methods.
Ok.



Comment at: clangd/XRefs.cpp:354
+
+  return Name;
+}

ilya-biryukov wrote:
> simark wrote:
> > ilya-biryukov wrote:
> > > We should call `flush()` before returning `Name` here. The 
> > > `raw_string_ostream` is buffered.
> > I replaced it with `Stream.str()`.
> Also works, albeit less efficient (will probably do a copy where move is 
> enough).
Ah, didn't think about that.  I'll change it to flush + return Name.



Comment at: unittests/clangd/XRefsTests.cpp:262
+  struct OneTest {
+StringRef input;
+StringRef expectedHover;

ilya-biryukov wrote:
> simark wrote:
> > ilya-biryukov wrote:
> > > NIT: LLVM uses `UpperCamelCase` for field names.
> > Ok, I fixed all the structs this patch adds.
> Argh, sorry that I didn't mention it before, but we have an exception for 
> structs in `Procotol.h`, they follow the spelling in the LSP spec (i.e. 
> should be `lowerCamelCase`).
> 
Haha, no problem, changing them back is one keystroke away.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D35894



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


[PATCH] D35894: [clangd] Code hover for Clangd

2018-02-15 Thread Simon Marchi via Phabricator via cfe-commits
simark updated this revision to Diff 134440.
simark added a comment.

Fix some nits

- Revert case change of struct fields in Protocol.h
- Change return formatting in onHover
- Use flush() + return Name in NamedDeclQualifiedName and TypeDeclToString


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D35894

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  clangd/XRefs.cpp
  clangd/XRefs.h
  test/clangd/hover.test
  test/clangd/initialize-params-invalid.test
  test/clangd/initialize-params.test
  unittests/clangd/XRefsTests.cpp

Index: unittests/clangd/XRefsTests.cpp
===
--- unittests/clangd/XRefsTests.cpp
+++ unittests/clangd/XRefsTests.cpp
@@ -259,6 +259,311 @@
SourceAnnotations.range()}));
 }
 
+TEST(Hover, All) {
+  struct OneTest {
+StringRef Input;
+StringRef ExpectedHover;
+  };
+
+  OneTest Tests[] = {
+  {
+  R"cpp(// Local variable
+int main() {
+  int bonjour;
+  ^bonjour = 2;
+  int test1 = bonjour;
+}
+  )cpp",
+  "Declared in function main\n\nint bonjour",
+  },
+  {
+  R"cpp(// Local variable in method
+struct s {
+  void method() {
+int bonjour;
+^bonjour = 2;
+  }
+};
+  )cpp",
+  "Declared in function s::method\n\nint bonjour",
+  },
+  {
+  R"cpp(// Struct
+namespace ns1 {
+  struct MyClass {};
+} // namespace ns1
+int main() {
+  ns1::My^Class* Params;
+}
+  )cpp",
+  "Declared in namespace ns1\n\nstruct MyClass {}",
+  },
+  {
+  R"cpp(// Class
+namespace ns1 {
+  class MyClass {};
+} // namespace ns1
+int main() {
+  ns1::My^Class* Params;
+}
+  )cpp",
+  "Declared in namespace ns1\n\nclass MyClass {}",
+  },
+  {
+  R"cpp(// Union
+namespace ns1 {
+  union MyUnion { int x; int y; };
+} // namespace ns1
+int main() {
+  ns1::My^Union Params;
+}
+  )cpp",
+  "Declared in namespace ns1\n\nunion MyUnion {}",
+  },
+  {
+  R"cpp(// Function definition via pointer
+int foo(int) {}
+int main() {
+  auto *X = &^foo;
+}
+  )cpp",
+  "Declared in global namespace\n\nint foo(int)",
+  },
+  {
+  R"cpp(// Function declaration via call
+int foo(int);
+int main() {
+  return ^foo(42);
+}
+  )cpp",
+  "Declared in global namespace\n\nint foo(int)",
+  },
+  {
+  R"cpp(// Field
+struct Foo { int x; };
+int main() {
+  Foo bar;
+  bar.^x;
+}
+  )cpp",
+  "Declared in struct Foo\n\nint x",
+  },
+  {
+  R"cpp(// Field with initialization
+struct Foo { int x = 5; };
+int main() {
+  Foo bar;
+  bar.^x;
+}
+  )cpp",
+  "Declared in struct Foo\n\nint x = 5",
+  },
+  {
+  R"cpp(// Static field
+struct Foo { static int x; };
+int main() {
+  Foo::^x;
+}
+  )cpp",
+  "Declared in struct Foo\n\nstatic int x",
+  },
+  {
+  R"cpp(// Field, member initializer
+struct Foo {
+  int x;
+  Foo() : ^x(0) {}
+};
+  )cpp",
+  "Declared in struct Foo\n\nint x",
+  },
+  {
+  R"cpp(// Field, GNU old-style field designator
+struct Foo { int x; };
+int main() {
+  Foo bar = { ^x : 1 };
+}
+  )cpp",
+  "Declared in struct Foo\n\nint x",
+  },
+  {
+  R"cpp(// Field, field designator
+struct Foo { int x; };
+int main() {
+  Foo bar = { .^x = 2 };
+}
+  )cpp",
+  "Declared in struct Foo\n\nint x",
+  },
+  {
+  R"cpp(// Method call
+struct Foo { int x(); };
+int main() {
+  Foo bar;
+  bar.^x();
+}
+  )cpp",
+  "Declared in struct Foo\n\nint x()",
+  },
+  {
+  R"cpp(// Static method call
+struct Foo { static int x(); };
+int main() {
+  Foo::^x();
+}
+  )cpp",
+  "Declared in struct Foo\n\nstatic int x()",
+  },
+ 

[PATCH] D43114: clang-format: fix formatting of ObjC @synchronized blocks

2018-02-15 Thread Francois Ferrand via Phabricator via cfe-commits
Typz marked an inline comment as done.
Typz added inline comments.



Comment at: unittests/Format/FormatTestObjC.cpp:193-198
+  verifyFormat("@synchronized(self) {\n"
+   "  f();\n"
+   "}\n"
+   "@synchronized(self) {\n"
+   "  f();\n"
+   "}\n");

benhamilton wrote:
> Why is the block repeated twice?
not sure why, I just copied the @autoreleasepool test code.
this may be to detect some more 'internal' error, which would lead to any 
visible effect on the first statement itself...


Repository:
  rC Clang

https://reviews.llvm.org/D43114



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


[PATCH] D35894: [clangd] Code hover for Clangd

2018-02-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.

Thanks for fixing all the NITs!


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D35894



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


Re: r325175 - [Debug] Annotate compiler generated range-for loop variables.

2018-02-15 Thread Galina Kistanova via cfe-commits
Hello Matt,

This commit broke tests on one of our builders:
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/7920
. . .
Failing Tests (1):
Clang :: CodeGenCXX/debug-info-range-for-var-names.cpp

Please have a look?

Thanks

Galina

On Wed, Feb 14, 2018 at 1:22 PM, Matt Davis via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: mattd
> Date: Wed Feb 14 13:22:11 2018
> New Revision: 325175
>
> URL: http://llvm.org/viewvc/llvm-project?rev=325175&view=rev
> Log:
> [Debug] Annotate compiler generated range-for loop variables.
>
> Summary:
> This change aims to simplify debugging by annotating the range-for loop
> artificial variables (range, begin, end) with the scope depth.
>
>
> Reviewers: rsmith, dblaikie
>
> Reviewed By: dblaikie
>
> Subscribers: dblaikie, cfe-commits
>
> Tags: #debug-info
>
> Differential Revision: https://reviews.llvm.org/D42813
>
> Added:
> cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp
> Modified:
> cfe/trunk/include/clang/Sema/Scope.h
> cfe/trunk/lib/Sema/SemaStmt.cpp
> cfe/trunk/test/CodeGenCXX/debug-info-scope.cpp
> cfe/trunk/test/CodeGenCXX/vla.cpp
>
> Modified: cfe/trunk/include/clang/Sema/Scope.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Sema/Scope.h?rev=325175&r1=325174&r2=325175&view=diff
> 
> ==
> --- cfe/trunk/include/clang/Sema/Scope.h (original)
> +++ cfe/trunk/include/clang/Sema/Scope.h Wed Feb 14 13:22:11 2018
> @@ -259,6 +259,9 @@ public:
>Scope *getTemplateParamParent() { return TemplateParamParent; }
>const Scope *getTemplateParamParent() const { return
> TemplateParamParent; }
>
> +  /// Returns the depth of this scope. The translation-unit has scope
> depth 0.
> +  unsigned getDepth() const { return Depth; }
> +
>/// Returns the number of function prototype scopes in this scope
>/// chain.
>unsigned getFunctionPrototypeDepth() const {
>
> Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaStmt.cpp?rev=325175&r1=325174&r2=325175&view=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Feb 14 13:22:11 2018
> @@ -2025,7 +2025,7 @@ void NoteForRangeBeginEndFunction(Sema &
>
>  /// Build a variable declaration for a for-range statement.
>  VarDecl *BuildForRangeVarDecl(Sema &SemaRef, SourceLocation Loc,
> -  QualType Type, const char *Name) {
> +  QualType Type, StringRef Name) {
>DeclContext *DC = SemaRef.CurContext;
>IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name);
>TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type,
> Loc);
> @@ -2094,10 +2094,12 @@ StmtResult Sema::ActOnCXXForRangeStmt(Sc
>}
>
>// Build  auto && __range = range-init
> +  // Divide by 2, since the variables are in the inner scope (loop body).
> +  const auto DepthStr = std::to_string(S->getDepth() / 2);
>SourceLocation RangeLoc = Range->getLocStart();
>VarDecl *RangeVar = BuildForRangeVarDecl(*this, RangeLoc,
> Context.getAutoRRefDeductType(
> ),
> -   "__range");
> +   std::string("__range") +
> DepthStr);
>if (FinishForRangeVarDecl(*this, RangeVar, Range, RangeLoc,
>  diag::err_for_range_deduction_failure)) {
>  LoopVar->setInvalidDecl();
> @@ -2340,10 +2342,12 @@ Sema::BuildCXXForRangeStmt(SourceLocatio
>return StmtError();
>
>  // Build auto __begin = begin-expr, __end = end-expr.
> +// Divide by 2, since the variables are in the inner scope (loop
> body).
> +const auto DepthStr = std::to_string(S->getDepth() / 2);
>  VarDecl *BeginVar = BuildForRangeVarDecl(*this, ColonLoc, AutoType,
> - "__begin");
> + std::string("__begin") +
> DepthStr);
>  VarDecl *EndVar = BuildForRangeVarDecl(*this, ColonLoc, AutoType,
> -   "__end");
> +   std::string("__end") +
> DepthStr);
>
>  // Build begin-expr and end-expr and attach to __begin and __end
> variables.
>  ExprResult BeginExpr, EndExpr;
>
> Added: cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> CodeGenCXX/debug-info-range-for-var-names.cpp?rev=325175&view=auto
> 
> ==
> --- cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp (added)
> +++ cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp Wed Feb
> 14 13:22:11 2018
> @@ -0,0 +1,36

RE: r325175 - [Debug] Annotate compiler generated range-for loop variables.

2018-02-15 Thread via cfe-commits
From: Galina Kistanova [mailto:gkistan...@gmail.com] 
> Sent: Thursday, February 15, 2018 9:33 AM
> To: Davis, Matthew 
> Cc: cfe-commits 
> Subject: Re: r325175 - [Debug] Annotate compiler generated range-for loop 
> variables.
>
> Hello Matt,
> 
> This commit broke tests on one of our builders:
> http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/7920
> . . .
> Failing Tests (1):
>    Clang :: CodeGenCXX/debug-info-range-for-var-names.cpp
>
> Please have a look?
>
> Thanks
>
> Galina

Thanks Galina, I will look.
-Matt
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43226: __threading_support: Remove (void) in favor of ().

2018-02-15 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.
Herald added a subscriber: christof.

Which clang-tidy module generates this warning, and what is the actual warning?


Repository:
  rCXX libc++

https://reviews.llvm.org/D43226



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


[PATCH] D42606: [Coroutines] Use allocator overload when available

2018-02-15 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov accepted this revision.
GorNishanov added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rC Clang

https://reviews.llvm.org/D42606



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


[PATCH] D43340: Clean up AMDGCN tests

2018-02-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: t-tye, b-sumner.

Remove amdgiz and use AMDGCN as check prefix.


https://reviews.llvm.org/D43340

Files:
  test/CodeGen/address-space.c
  test/CodeGenCXX/cxx0x-initializer-stdinitializerlist.cpp
  test/CodeGenCXX/vla.cpp
  test/CodeGenOpenCL/addr-space-struct-arg.cl
  test/CodeGenOpenCL/address-space-constant-initializers.cl
  test/CodeGenOpenCL/address-spaces.cl
  test/CodeGenOpenCL/blocks.cl
  test/CodeGenOpenCL/lifetime.cl
  test/CodeGenOpenCL/vla.cl
  test/Index/pipe-size.cl

Index: test/Index/pipe-size.cl
===
--- test/Index/pipe-size.cl
+++ test/Index/pipe-size.cl
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple x86_64-unknown-linux-gnu %s -o - | FileCheck %s --check-prefix=X86
 // RUN: %clang_cc1 -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple spir-unknown-unknown %s -o - | FileCheck %s --check-prefix=SPIR
 // RUN: %clang_cc1 -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple spir64-unknown-unknown %s -o - | FileCheck %s --check-prefix=SPIR64
-// RUN: %clang_cc1 -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple amdgcn-amd-amdhsa-amdgizcl %s -o - | FileCheck %s --check-prefix=AMD
+// RUN: %clang_cc1 -x cl -O0 -cl-std=CL2.0 -emit-llvm -triple amdgcn-amd-amdhsa %s -o - | FileCheck %s --check-prefix=AMDGCN
 __kernel void testPipe( pipe int test )
 {
 int s = sizeof(test);
@@ -11,6 +11,6 @@
 // SPIR: store i32 4, i32* %s, align 4
 // SPIR64: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)** %test.addr, align 8
 // SPIR64: store i32 8, i32* %s, align 4
-// AMD: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)* addrspace(5)* %test.addr, align 8
-// AMD: store i32 8, i32 addrspace(5)* %s, align 4
+// AMDGCN: store %opencl.pipe_t addrspace(1)* %test, %opencl.pipe_t addrspace(1)* addrspace(5)* %test.addr, align 8
+// AMDGCN: store i32 8, i32 addrspace(5)* %s, align 4
 }
Index: test/CodeGenOpenCL/vla.cl
===
--- test/CodeGenOpenCL/vla.cl
+++ test/CodeGenOpenCL/vla.cl
@@ -1,14 +1,14 @@
 // RUN: %clang_cc1 -emit-llvm -triple "spir-unknown-unknown" -O0 -cl-std=CL2.0 -o - %s | FileCheck -check-prefixes=CHECK,SPIR %s
-// RUN: %clang_cc1 -emit-llvm -triple amdgcn-amd-amdhsa -O0 -cl-std=CL2.0 -o - %s | FileCheck -check-prefixes=CHECK,AMD %s
+// RUN: %clang_cc1 -emit-llvm -triple amdgcn-amd-amdhsa -O0 -cl-std=CL2.0 -o - %s | FileCheck -check-prefixes=CHECK,AMDGCN %s
 
 constant int sz0 = 5;
 // SPIR: @sz0 = addrspace(2) constant i32 5
-// AMD: @sz0 = addrspace(4) constant i32 5
+// AMDGCN: @sz0 = addrspace(4) constant i32 5
 const global int sz1 = 16;
 // CHECK: @sz1 = addrspace(1) constant i32 16
 const constant int sz2 = 8;
 // SPIR: @sz2 = addrspace(2) constant i32 8
-// AMD: @sz2 = addrspace(4) constant i32 8
+// AMDGCN: @sz2 = addrspace(4) constant i32 8
 // CHECK: @testvla.vla2 = internal addrspace(3) global [8 x i16] undef
 
 kernel void testvla()
@@ -16,10 +16,10 @@
   int vla0[sz0];
 // SPIR: %vla0 = alloca [5 x i32]
 // SPIR-NOT: %vla0 = alloca [5 x i32]{{.*}}addrspace
-// GIZ: %vla0 = alloca [5 x i32]{{.*}}addrspace(5)
+// AMDGCN: %vla0 = alloca [5 x i32]{{.*}}addrspace(5)
   char vla1[sz1];
 // SPIR: %vla1 = alloca [16 x i8]
 // SPIR-NOT: %vla1 = alloca [16 x i8]{{.*}}addrspace
-// GIZ: %vla1 = alloca [16 x i8]{{.*}}addrspace(5)
+// AMDGCN: %vla1 = alloca [16 x i8]{{.*}}addrspace(5)
   local short vla2[sz2];
 }
Index: test/CodeGenOpenCL/lifetime.cl
===
--- test/CodeGenOpenCL/lifetime.cl
+++ test/CodeGenOpenCL/lifetime.cl
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn---amdgizcl %s | FileCheck %s -check-prefix=AMDGIZ
+// RUN: %clang_cc1 -emit-llvm -o - -triple amdgcn %s | FileCheck %s -check-prefix=AMDGCN
 
 void use(char *a);
 
@@ -10,6 +10,6 @@
 
 void lifetime_test() {
 // CHECK: @llvm.lifetime.start.p0i
-// AMDGIZ: @llvm.lifetime.start.p5i
+// AMDGCN: @llvm.lifetime.start.p5i
   helper_no_markers();
 }
Index: test/CodeGenOpenCL/blocks.cl
===
--- test/CodeGenOpenCL/blocks.cl
+++ test/CodeGenOpenCL/blocks.cl
@@ -1,14 +1,14 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck -check-prefixes=COMMON,SPIR %s
-// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple amdgcn-amd-amdhsa-opencl | FileCheck -check-prefixes=COMMON,AMD %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -emit-llvm -o - -O0 -triple amdgcn-amd-amdhsa | FileCheck -check-prefixes=COMMON,AMDGCN %s
 
 // SPIR: %struct.__opencl_block_literal_generic = type { i32, i32, i8 addrspace(4)* }
-// AMD: %struct.__opencl_block_literal_generic = type { i32, i32, i8* }
+// AMDGCN: %struct.__opencl_block_literal_generic = type { i32, i32, i8* }
 // S

[PATCH] D43248: [Attr] Fix printing of parameter indices in attributes

2018-02-15 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: include/clang/Basic/Attr.td:182
+  // it would always be false.
+  string DisallowImplicitThisParamName = disallowImplicitThisParamName;
+}

Is there much benefit to forcing the attribute author to pick a name for this? 
It seems like this is more of a Boolean value: either implicit this is allowed 
or not. It would be really nice if we could hide these mechanics as 
implementation details so that the user only needs to write 
`VariadicParamIndexArgument<"name", DisallowImplicitThis>` (or something 
similar) when defining the attribute, and ideally not have to do any extra work 
in SemaDeclAttr.cpp by taking care of it in ClangAttrEmitter.cpp if possible.



Comment at: lib/Sema/SemaDeclAttr.cpp:355-357
   }
+  else if (DisallowImplicitThisParam)
+*DisallowImplicitThisParam = false;

Formatting is off here -- the `else if` should go up a line.



Comment at: lib/Sema/SemaDeclAttr.cpp:4612
+   TypeTagIdx, false,
+   &DisallowImplicitThisParam))
 return;

This value cannot be different from the previously-read value, correct? Might 
want to assert that.



Comment at: test/Sema/attr-print.cpp:1
+// RUN: %clang_cc1 %s -ast-print | FileCheck %s
+

-ast-print tests generally live in Misc rather than Sema -- can you move this 
test over to that directory?



Comment at: test/Sema/attr-print.cpp:33
+  // CHECK: void ownr(int) __attribute__((ownership_returns(foo, 2)));
+};

Can you add some tests for `__attribute__((format))` and 
`__attribute__((format_arg))` to demonstrate that their pretty-printed argument 
values are also sensible?


https://reviews.llvm.org/D43248



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 134446.
MaskRay marked 4 inline comments as done.
MaskRay added a comment.

Update .rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/readability-simd-intrinsics-x86.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-x86.cpp
@@ -0,0 +1,26 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target x86_64 -std=c++11
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
Index: test/clang-tidy/readability-simd-intrinsics-ppc.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-ppc.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+  vector int i0, i1;
+
+  vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,42 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+If the option ``Suggest`` is set to non-zero, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b); // x86
+  vec_add(a, b);   // Power
+
+the check suggests an alternative:
+
+.. code-block::
+
+  operator+ on std::experimental::simd objects
+
+Otherwise, it just complains the intrinsics are non-portable (and there are `P0214`_ alternatives).
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Suggest
+
+   If this option is set to non-zero (default is `0`), the check will suggest P0214 alternatives, otherwise it only points out the intrinsic function is non-portable.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -217,6 +217,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used 

[PATCH] D43273: [libcxx] [test] Fix MSVC warnings and errors.

2018-02-15 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

The `` bit is fine.
The `veryLarge` is "ok".
The rest of them are just bogus.


https://reviews.llvm.org/D43273



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 134447.
MaskRay marked 2 inline comments as done.
MaskRay added a comment.

Update


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/readability-simd-intrinsics-x86.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-x86.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target x86_64 -std=c++11
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+}
Index: test/clang-tidy/readability-simd-intrinsics-ppc.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-ppc.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+  vector int i0, i1;
+
+  vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,42 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+If the option ``Suggest`` is set to non-zero, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b); // x86
+  vec_add(a, b);   // Power
+
+the check suggests an alternative:
+
+.. code-block::
+
+  operator+ on std::experimental::simd objects
+
+Otherwise, it just complains the intrinsics are non-portable (and there are `P0214`_ alternatives).
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Suggest
+
+   If this option is set to non-zero (default is `0`), the check will suggest P0214 alternatives, otherwise it only points out the intrinsic function is non-portable.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -217,6 +217,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experime

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: test/clang-tidy/readability-simd-intrinsics-ppc.cpp:3
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++11

hokein wrote:
> consider adding test when Suggest is 0?
I'll have to duplicate the CHECK-MESSAGE lines for each intrinsic, which seems 
a lot of boilerplate.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


r325271 - [Test] Remove mangled name from test.

2018-02-15 Thread Matt Davis via cfe-commits
Author: mattd
Date: Thu Feb 15 09:55:52 2018
New Revision: 325271

URL: http://llvm.org/viewvc/llvm-project?rev=325271&view=rev
Log:
[Test] Remove mangled name from test.

This line is not needed in the test, and breaks Windows testing.
Fixes the test added in r325175.


Modified:
cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp

Modified: cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp?rev=325271&r1=325270&r2=325271&view=diff
==
--- cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/debug-info-range-for-var-names.cpp Thu Feb 15 
09:55:52 2018
@@ -15,7 +15,6 @@ void test() {
   }
 }
 
-// CHECK: define void @_Z4testv()
 // CHECK: call void @llvm.dbg.declare(metadata %struct.vec** {{.*}}, metadata 
![[RANGE1:[0-9]+]]
 // CHECK: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata 
![[BEGIN1:[0-9]+]]
 // CHECK: call void @llvm.dbg.declare(metadata i32** {{.*}}, metadata 
![[END1:[0-9]+]]


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


  1   2   >