[clang-tools-extra] r334162 - [clangd] Make workspace/symbols actually rank its results.

2018-06-07 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Wed Jun  6 23:55:59 2018
New Revision: 334162

URL: http://llvm.org/viewvc/llvm-project?rev=334162&view=rev
Log:
[clangd] Make workspace/symbols actually rank its results.

Summary: The index doesn't actually return results in ranked order.

Reviewers: hokein

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits

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

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

Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.cpp?rev=334162&r1=334161&r2=334162&view=diff
==
--- clang-tools-extra/trunk/clangd/FindSymbols.cpp (original)
+++ clang-tools-extra/trunk/clangd/FindSymbols.cpp Wed Jun  6 23:55:59 2018
@@ -9,12 +9,16 @@
 #include "FindSymbols.h"
 
 #include "Logger.h"
+#include "FuzzyMatch.h"
 #include "SourceCode.h"
+#include "Quality.h"
 #include "index/Index.h"
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 
+#define DEBUG_TYPE "FindSymbols"
+
 namespace clang {
 namespace clangd {
 
@@ -79,6 +83,15 @@ SymbolKind indexSymbolKindToSymbolKind(i
   llvm_unreachable("invalid symbol kind");
 }
 
+using ScoredSymbolInfo = std::pair;
+struct ScoredSymbolGreater {
+  bool operator()(const ScoredSymbolInfo &L, const ScoredSymbolInfo &R) {
+if (L.first != R.first)
+  return L.first > R.first;
+return L.second.name < R.second.name; // Earlier name is better.
+  }
+};
+
 } // namespace
 
 llvm::Expected>
@@ -101,7 +114,9 @@ getWorkspaceSymbols(StringRef Query, int
 Req.Scopes = {Names.first};
   if (Limit)
 Req.MaxCandidateCount = Limit;
-  Index->fuzzyFind(Req, [&Result](const Symbol &Sym) {
+  TopN Top(Req.MaxCandidateCount);
+  FuzzyMatcher Filter(Req.Query);
+  Index->fuzzyFind(Req, [&Top, &Filter](const Symbol &Sym) {
 // Prefer the definition over e.g. a function declaration in a header
 auto &CD = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
 auto Uri = URI::parse(CD.FileURI);
@@ -132,8 +147,30 @@ getWorkspaceSymbols(StringRef Query, int
 std::string Scope = Sym.Scope;
 StringRef ScopeRef = Scope;
 ScopeRef.consume_back("::");
-Result.push_back({Sym.Name, SK, L, ScopeRef});
+SymbolInformation Info = {Sym.Name, SK, L, ScopeRef};
+
+SymbolQualitySignals Quality;
+Quality.merge(Sym);
+SymbolRelevanceSignals Relevance;
+Relevance.Query = SymbolRelevanceSignals::Generic;
+if (auto NameMatch = Filter.match(Sym.Name))
+  Relevance.NameMatch = *NameMatch;
+else {
+  log(llvm::formatv("Workspace symbol: {0} didn't match query {1}",
+Sym.Name, Filter.pattern()));
+  return;
+}
+Relevance.merge(Sym);
+auto Score =
+evaluateSymbolAndRelevance(Quality.evaluate(), Relevance.evaluate());
+LLVM_DEBUG(llvm::dbgs() << "FindSymbols: " << Sym.Scope << Sym.Name << " = 
"
+<< Score << "\n"
+<< Quality << Relevance << "\n");
+
+Top.push({Score, std::move(Info)});
   });
+  for (auto &R : std::move(Top).items())
+Result.push_back(std::move(R.second));
   return Result;
 }
 

Modified: clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp?rev=334162&r1=334161&r2=334162&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp Wed Jun  6 
23:55:59 2018
@@ -264,6 +264,17 @@ TEST_F(WorkspaceSymbolsTest, Enums) {
   EXPECT_THAT(getSymbols("ns::Color4::White"), ElementsAre(Named("White")));
 }
 
+TEST_F(WorkspaceSymbolsTest, Ranking) {
+  addFile("foo.h", R"cpp(
+  namespace ns{}
+  function func();
+  )cpp");
+  addFile("foo.cpp", R"cpp(
+  #include "foo.h"
+  )cpp");
+  EXPECT_THAT(getSymbols("::"), ElementsAre(Named("func"), Named("ns")));
+}
+
 TEST_F(WorkspaceSymbolsTest, WithLimit) {
   addFile("foo.h", R"cpp(
   int foo;
@@ -272,6 +283,7 @@ TEST_F(WorkspaceSymbolsTest, WithLimit)
   addFile("foo.cpp", R"cpp(
   #include "foo.h"
   )cpp");
+  // Foo is higher ranked because of exact name match.
   EXPECT_THAT(getSymbols("foo"),
   UnorderedElementsAre(AllOf(Named("foo"), InContainer(""),
  WithKind(SymbolKind::Variable)),
@@ -279,9 +291,7 @@ TEST_F(WorkspaceSymbolsTest, WithLimit)
  WithKind(SymbolKind::Variable;
 
   Limit = 1;
-  EXPECT_THAT(getSymbols("foo"),
-  ElementsAre(AnyOf((Named("foo"), InContainer("")),

[PATCH] D47821: [clangd] Make workspace/symbols actually rank its results.

2018-06-07 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334162: [clangd] Make workspace/symbols actually rank its 
results. (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D47821?vs=150113&id=150260#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D47821

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

Index: clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/FindSymbolsTests.cpp
@@ -264,24 +264,34 @@
   EXPECT_THAT(getSymbols("ns::Color4::White"), ElementsAre(Named("White")));
 }
 
+TEST_F(WorkspaceSymbolsTest, Ranking) {
+  addFile("foo.h", R"cpp(
+  namespace ns{}
+  function func();
+  )cpp");
+  addFile("foo.cpp", R"cpp(
+  #include "foo.h"
+  )cpp");
+  EXPECT_THAT(getSymbols("::"), ElementsAre(Named("func"), Named("ns")));
+}
+
 TEST_F(WorkspaceSymbolsTest, WithLimit) {
   addFile("foo.h", R"cpp(
   int foo;
   int foo2;
   )cpp");
   addFile("foo.cpp", R"cpp(
   #include "foo.h"
   )cpp");
+  // Foo is higher ranked because of exact name match.
   EXPECT_THAT(getSymbols("foo"),
   UnorderedElementsAre(AllOf(Named("foo"), InContainer(""),
  WithKind(SymbolKind::Variable)),
AllOf(Named("foo2"), InContainer(""),
  WithKind(SymbolKind::Variable;
 
   Limit = 1;
-  EXPECT_THAT(getSymbols("foo"),
-  ElementsAre(AnyOf((Named("foo"), InContainer("")),
-AllOf(Named("foo2"), InContainer("");
+  EXPECT_THAT(getSymbols("foo"), ElementsAre(Named("foo")));
 }
 
 } // namespace clangd
Index: clang-tools-extra/trunk/clangd/FindSymbols.cpp
===
--- clang-tools-extra/trunk/clangd/FindSymbols.cpp
+++ clang-tools-extra/trunk/clangd/FindSymbols.cpp
@@ -9,12 +9,16 @@
 #include "FindSymbols.h"
 
 #include "Logger.h"
+#include "FuzzyMatch.h"
 #include "SourceCode.h"
+#include "Quality.h"
 #include "index/Index.h"
 #include "clang/Index/IndexSymbol.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 
+#define DEBUG_TYPE "FindSymbols"
+
 namespace clang {
 namespace clangd {
 
@@ -79,6 +83,15 @@
   llvm_unreachable("invalid symbol kind");
 }
 
+using ScoredSymbolInfo = std::pair;
+struct ScoredSymbolGreater {
+  bool operator()(const ScoredSymbolInfo &L, const ScoredSymbolInfo &R) {
+if (L.first != R.first)
+  return L.first > R.first;
+return L.second.name < R.second.name; // Earlier name is better.
+  }
+};
+
 } // namespace
 
 llvm::Expected>
@@ -101,7 +114,9 @@
 Req.Scopes = {Names.first};
   if (Limit)
 Req.MaxCandidateCount = Limit;
-  Index->fuzzyFind(Req, [&Result](const Symbol &Sym) {
+  TopN Top(Req.MaxCandidateCount);
+  FuzzyMatcher Filter(Req.Query);
+  Index->fuzzyFind(Req, [&Top, &Filter](const Symbol &Sym) {
 // Prefer the definition over e.g. a function declaration in a header
 auto &CD = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
 auto Uri = URI::parse(CD.FileURI);
@@ -132,8 +147,30 @@
 std::string Scope = Sym.Scope;
 StringRef ScopeRef = Scope;
 ScopeRef.consume_back("::");
-Result.push_back({Sym.Name, SK, L, ScopeRef});
+SymbolInformation Info = {Sym.Name, SK, L, ScopeRef};
+
+SymbolQualitySignals Quality;
+Quality.merge(Sym);
+SymbolRelevanceSignals Relevance;
+Relevance.Query = SymbolRelevanceSignals::Generic;
+if (auto NameMatch = Filter.match(Sym.Name))
+  Relevance.NameMatch = *NameMatch;
+else {
+  log(llvm::formatv("Workspace symbol: {0} didn't match query {1}",
+Sym.Name, Filter.pattern()));
+  return;
+}
+Relevance.merge(Sym);
+auto Score =
+evaluateSymbolAndRelevance(Quality.evaluate(), Relevance.evaluate());
+LLVM_DEBUG(llvm::dbgs() << "FindSymbols: " << Sym.Scope << Sym.Name << " = "
+<< Score << "\n"
+<< Quality << Relevance << "\n");
+
+Top.push({Score, std::move(Info)});
   });
+  for (auto &R : std::move(Top).items())
+Result.push_back(std::move(R.second));
   return Result;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46911: [Fixed Point Arithmetic] Addition of the remaining fixed point types and their saturated equivalents

2018-06-07 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added a comment.

Yes, it looks good to me.


Repository:
  rC Clang

https://reviews.llvm.org/D46911



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


[PATCH] D47869: [clangd] Fix using the incorrect Index for go-to-definition.

2018-06-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: jkorous, MaskRay, ioeric, ilya-biryukov.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47869

Files:
  clangd/ClangdServer.cpp


Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -302,7 +302,7 @@
 llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
-CB(clangd::findDefinitions(InpAST->AST, Pos, this->FileIdx.get()));
+CB(clangd::findDefinitions(InpAST->AST, Pos, this->Index));
   };
 
   WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB)));


Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -302,7 +302,7 @@
 llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
-CB(clangd::findDefinitions(InpAST->AST, Pos, this->FileIdx.get()));
+CB(clangd::findDefinitions(InpAST->AST, Pos, this->Index));
   };
 
   WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB)));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46757: [clang-format] Break inside submessages containing a submessage and something else

2018-06-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 150273.
krasimir added a comment.

- Polish


Repository:
  rC Clang

https://reviews.llvm.org/D46757

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestRawStrings.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -171,17 +171,48 @@
   verifyFormat("msg_field < field_a < field_b <> > >");
   verifyFormat("msg_field: < field_a < field_b: <> > >");
   verifyFormat("msg_field < field_a: OK, field_b: \"OK\" >");
-  verifyFormat("msg_field < field_a: OK field_b: <>, field_c: OK >");
-  verifyFormat("msg_field < field_a { field_b: 1 }, field_c: < f_d: 2 > >");
   verifyFormat("msg_field: < field_a: OK, field_b: \"OK\" >");
-  verifyFormat("msg_field: < field_a: OK field_b: <>, field_c: OK >");
-  verifyFormat("msg_field: < field_a { field_b: 1 }, field_c: < fd_d: 2 > >");
-  verifyFormat("field_a: \"OK\", msg_field: < field_b: 123 >, field_c: {}");
-  verifyFormat("field_a < field_b: 1 >, msg_fid: < fiel_b: 123 >, field_c <>");
-  verifyFormat("field_a < field_b: 1 > msg_fied: < field_b: 123 > field_c <>");
-  verifyFormat("field < field < field: <> >, field <> > field: < field: 1 >");
-
   // Multiple lines tests
+  verifyFormat("msg_field <\n"
+   "  field_a: OK\n"
+   "  field_b: <>,\n"
+   "  field_c: OK\n"
+   ">");
+
+  verifyFormat("msg_field <\n"
+   "  field_a { field_b: 1 },\n"
+   "  field_c: < f_d: 2 >\n"
+   ">");
+
+  verifyFormat("msg_field: <\n"
+   "  field_a: OK\n"
+   "  field_b: <>,\n"
+   "  field_c: OK\n"
+   ">");
+
+  verifyFormat("msg_field: <\n"
+   "  field_a { field_b: 1 },\n"
+   "  field_c: < fd_d: 2 >\n"
+   ">");
+
+  verifyFormat("field_a: \"OK\",\n"
+   "msg_field: < field_b: 123 >,\n"
+   "field_c: {}");
+
+  verifyFormat("field_a < field_b: 1 >,\n"
+   "msg_fid: < fiel_b: 123 >,\n" 
+   "field_c <>");
+
+  verifyFormat("field_a < field_b: 1 >\n"
+   "msg_fied: < field_b: 123 >\n"
+   "field_c <>");
+
+  verifyFormat("field <\n"
+   "  field < field: <> >,\n"
+   "  field <>\n"
+   ">\n"
+   "field: < field: 1 >");
+
   verifyFormat("msg_field <\n"
"  field_a: OK\n"
"  field_b: \"OK\"\n"
@@ -242,7 +273,10 @@
"  field_d: ok\n"
"}");
 
-  verifyFormat("field_a: < f1: 1, f2: <> >\n"
+  verifyFormat("field_a: <\n"
+   "  f1: 1,\n"
+   "  f2: <>\n"
+   ">\n"
"field_b <\n"
"  field_b1: <>\n"
"  field_b2: ok,\n"
@@ -507,5 +541,107 @@
">");
 }
 
+TEST_F(FormatTestTextProto, BreaksEntriesOfSubmessagesContainingSubmessages) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60;
+  // The column limit allows for the keys submessage to be put on 1 line, but we
+  // break it since it contains a submessage an another entry.
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: ''\n"
+   "  sub <>\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: ''\n"
+   "  sub {}\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  sub {}\n"
+   "  sub: <>\n"
+   "  sub: []\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub { msg: 1 }\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub: { msg: 1 }\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub < msg: 1 >\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub: [ msg: 1 ]\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: <\n"
+   "  item: 'aaa'\n"
+   "  sub: [ 1, 2 ]\n"
+   ">");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  sub {}\n"
+   "  item: ''\n"
+   "}");
+  verifyFormat("key: valu\

[PATCH] D47869: [clangd] Fix using the incorrect Index for go-to-definition.

2018-06-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clangd/ClangdServer.cpp:305
   return CB(InpAST.takeError());
-CB(clangd::findDefinitions(InpAST->AST, Pos, this->FileIdx.get()));
+CB(clangd::findDefinitions(InpAST->AST, Pos, this->Index));
   };

nit: just `Index`?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47869



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


[clang-tools-extra] r334170 - [clangd] fix unintended fallthrough in scope-based scoring

2018-06-07 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Jun  7 01:16:36 2018
New Revision: 334170

URL: http://llvm.org/viewvc/llvm-project?rev=334170&view=rev
Log:
[clangd] fix unintended fallthrough in scope-based scoring

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

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=334170&r1=334169&r2=334170&view=diff
==
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Thu Jun  7 01:16:36 2018
@@ -216,10 +216,13 @@ float SymbolRelevanceSignals::evaluate()
   break;
 case FileScope:
   Score *= 1.5;
+  break;
 case ClassScope:
   Score *= 2;
+  break;
 case FunctionScope:
   Score *= 4;
+  break;
 }
   }
 


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


[PATCH] D47849: [OpenMP][Clang][NVPTX] Enable math functions called in an OpenMP NVPTX target device region to be resolved as device-native function calls

2018-06-07 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

IMO this goes into the right direction, we should use the fast implementation 
in libdevice. If LLVM doesn't lower these calls in the NVPTX backend, I think 
it's ok to use header wrappers as CUDA already does.

Two questions:

1. Can you explain where this is important for "correctness"? Yesterday I 
compiled a code using `sqrt` and it seems to spit out the correct results. 
Maybe that's relevant for other functions?
2. Incidentally I ran into a closely related problem: I can't `#include 
` in translation units compiled for offloading, Clang complains about 
inline assembly for x86 (see below). Does that work for you?

  In file included from /usr/include/math.h:413:
  /usr/include/bits/mathinline.h:131:43: error: invalid input constraint 'x' in 
asm
__asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
^
  /usr/include/bits/mathinline.h:143:43: error: invalid input constraint 'x' in 
asm
__asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x));
^
  2 errors generated.




Comment at: lib/Headers/__clang_cuda_device_functions.h:65
 }
+#if defined(__cplusplus)
 __DEVICE__ void __brkpt() { asm volatile("brkpt;"); }

Why is that only valid for C++?


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D47870: [clang-format] Consider tok::hashhash in python-style comments

2018-06-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a subscriber: cfe-commits.

We were missing the case when python-style comments in text protos start with 
`##`.


Repository:
  rC Clang

https://reviews.llvm.org/D47870

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/FormatTokenLexer.cpp
  unittests/Format/FormatTestTextProto.cpp


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -347,6 +347,28 @@
": 3849");
 }
 
+TEST_F(FormatTestTextProto, UnderstandsHashHashComments) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60; // To make writing tests easier.
+  EXPECT_EQ("aaa: 100\n"
+"##this is a double-hash comment.\n"
+"bb: 100\n"
+"## another double-hash comment.\n"
+"### a triple-hash comment\n"
+"cc: 200\n"
+" a quadriple-hash comment\n"
+"dd: 100\n",
+format("aaa: 100\n"
+   "##this is a double-hash comment.\n"
+   "bb: 100\n"
+   "## another double-hash comment.\n"
+   "### a triple-hash comment\n"
+   "cc: 200\n"
+   " a quadriple-hash comment\n"
+   "dd: 100\n",
+   Style));
+}
+
 TEST_F(FormatTestTextProto, FormatsExtensions) {
   verifyFormat("[type] { key: value }");
   verifyFormat("[type] {\n"
Index: lib/Format/FormatTokenLexer.cpp
===
--- lib/Format/FormatTokenLexer.cpp
+++ lib/Format/FormatTokenLexer.cpp
@@ -334,7 +334,7 @@
 
 void FormatTokenLexer::tryParsePythonComment() {
   FormatToken *HashToken = Tokens.back();
-  if (HashToken->isNot(tok::hash))
+  if (!HashToken->isOneOf(tok::hash, tok::hashhash))
 return;
   // Turn the remainder of this line into a comment.
   const char *CommentBegin =
Index: lib/Format/BreakableToken.cpp
===
--- lib/Format/BreakableToken.cpp
+++ lib/Format/BreakableToken.cpp
@@ -44,7 +44,8 @@
 const FormatStyle &Style) {
   static const char *const KnownCStylePrefixes[] = {"///<", "//!<", "///", 
"//",
 "//!"};
-  static const char *const KnownTextProtoPrefixes[] = {"//", "#"};
+  static const char *const KnownTextProtoPrefixes[] = {"//", "#", "##", "###",
+   ""};
   ArrayRef KnownPrefixes(KnownCStylePrefixes);
   if (Style.Language == FormatStyle::LK_TextProto)
 KnownPrefixes = KnownTextProtoPrefixes;


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -347,6 +347,28 @@
": 3849");
 }
 
+TEST_F(FormatTestTextProto, UnderstandsHashHashComments) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60; // To make writing tests easier.
+  EXPECT_EQ("aaa: 100\n"
+"##this is a double-hash comment.\n"
+"bb: 100\n"
+"## another double-hash comment.\n"
+"### a triple-hash comment\n"
+"cc: 200\n"
+" a quadriple-hash comment\n"
+"dd: 100\n",
+format("aaa: 100\n"
+   "##this is a double-hash comment.\n"
+   "bb: 100\n"
+   "## another double-hash comment.\n"
+   "### a triple-hash comment\n"
+   "cc: 200\n"
+   " a quadriple-hash comment\n"
+   "dd: 100\n",
+   Style));
+}
+
 TEST_F(FormatTestTextProto, FormatsExtensions) {
   verifyFormat("[type] { key: value }");
   verifyFormat("[type] {\n"
Index: lib/Format/FormatTokenLexer.cpp
===
--- lib/Format/FormatTokenLexer.cpp
+++ lib/Format/FormatTokenLexer.cpp
@@ -334,7 +334,7 @@
 
 void FormatTokenLexer::tryParsePythonComment() {
   FormatToken *HashToken = Tokens.back();
-  if (HashToken->isNot(tok::hash))
+  if (!HashToken->isOneOf(tok::hash, tok::hashhash))
 return;
   // Turn the remainder of this line into a comment.
   const char *CommentBegin =
Index: lib/Format/BreakableToken.cpp
===
--- lib/Format/BreakableToken.cpp
+++ lib/Format/BreakableToken.cpp
@@ -44,7 +44,8 @@
 const FormatStyle &Style) {
   static const char *const KnownCStylePrefixes[] = {"///<", "//!<", "///", "//",
 "//!"};
-  

[PATCH] D46915: [Fixed Point Arithmetic] Fixed Point Precision Bits and Fixed Point Literals

2018-06-07 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: include/clang/AST/Type.h:6552
+// as a scaled integer.
+std::string FixedPointValueToString(unsigned Radix, unsigned Scale,
+uint64_t Val);

This should probably take an APInt or APSInt.

Also, is there a reason to only have it produce unsigned numbers?



Comment at: include/clang/Basic/LangOptions.def:306
 LANGOPT(FixedPoint, 1, 0, "fixed point types")
+LANGOPT(SameFBits, 1, 0,
+"unsigned and signed fixed point type having the same number of 
fractional bits")

Is it safe to have this as a flag? What about making it a target property?



Comment at: include/clang/Basic/TargetInfo.h:89
+  // corresponding unsaturated types.
+  unsigned char ShortAccumFBits, ShortAccumIBits;
+  unsigned char AccumFBits, AccumIBits;

I suspect it's still possible to calculate the ibits based on the fbits, even 
for _Accum.

Are the unsigned values needed? The fbits for unsigned _Fract are the same as 
for signed _Fract if SameFBits is set, and +1 otherwise. The same should go for 
unsigned _Accum, but I don't think it's entirely clear how this affects the 
integral part.



Comment at: include/clang/Lex/LiteralSupport.h:116
+  /// occurred when calculating the integral part of the scaled integer.
+  bool GetFixedPointValue(uint64_t &Val, unsigned Scale);
+

This should return an APInt. That way you won't run the risk of losing any bits 
due to overflow or extraneous precision.



Comment at: lib/AST/ExprConstant.cpp:9427
+  const APSInt &Value = Result.getInt();
+  if (Value.isSigned() && Value.isMinSignedValue() && E->canOverflow()) {
+std::string Val =

This doesn't saturate properly. Is that coming in a later patch?



Comment at: lib/AST/ExprConstant.cpp:9429
+std::string Val =
+"-" + FixedPointValueToString(
+  /*Radix=*/10, Info.Ctx.getTypeInfo(E->getType()).Width,

This would probably be simpler if the FixedPointValueToString function could 
produce signed values.



Comment at: lib/AST/StmtPrinter.cpp:1540
+  llvm_unreachable("Unexpected type for fixed point literal!");
+case BuiltinType::ShortFract:
+  OS << "hr";

Format this more like the one above to make fewer lines.



Comment at: lib/AST/Type.cpp:3992
+
+std::string clang::FixedPointValueToString(unsigned Radix, unsigned Scale,
+   uint64_t Val) {

I think this would be better if it took a SmallString (or SmallVectorImpl) as 
reference and used that instead of returning a std::string.

Also should probably take an APInt/APSInt.



Comment at: lib/Lex/LiteralSupport.cpp:1045
 
+bool NumericLiteralParser::GetFixedPointValue(uint64_t &Val, unsigned Scale) {
+  assert(radix == 16 || radix == 10);

This should take an APInt (and use APInts for processing) to store the result 
in.

It should be possible to calculate exactly how many bits are needed to fit the 
literal before you start reading the digits. Overflow should not be a problem, 
but you might get precision loss in the fractional part. The calculation in our 
version is `ceil(log2(10^(noof-digits))) + Scale` but ours only handles normal 
decimal notation (123.456) so it might need to be extended to handle exponents 
and hex.



Comment at: lib/Sema/SemaExpr.cpp:1248
+  bool RHSFixed = RHSType->isFixedPointType();
+
+  if (LHSFixed && RHSFixed) {

I don't see how these semantics work properly. The specification requires that 
operations be done in the full precision of both types. You cannot convert the 
types before performing the operation like this, since the operation will not 
be done in full precision in that case.

The operator semantics of Embedded-C require the operand types of binary 
operators to be different. It's only when you've performed the operation that 
you are allowed to convert the result to the resulting type.



Comment at: lib/Sema/SemaExpr.cpp:1336
+  // Handle fixed point types
+  if (LHSType->isFixedPointType() || RHSType->isFixedPointType())
+return handleFixedPointConversion(*this, LHS, RHS, LHSType, RHSType,

I guess you haven't gotten there yet, but this should probably be before 
handleFloatConversion if you want to handle 'float + _fract' later.



Comment at: lib/Sema/SemaExpr.cpp:3415
+if (Literal.isFract) {
+  uint64_t MaxVal = 1ULL << scale;
+  if (Val > MaxVal) {

With APInts it should be possible to generalize this code to work with both 
accum and fract.


Repository:
  rC Clang

https://reviews.llvm.org/D46915



___
cfe-commits mailing 

r334174 - [CodeGen] Improve diagnostics related to target attributes

2018-06-07 Thread Gabor Buella via cfe-commits
Author: gbuella
Date: Thu Jun  7 01:48:36 2018
New Revision: 334174

URL: http://llvm.org/viewvc/llvm-project?rev=334174&view=rev
Log:
[CodeGen] Improve diagnostics related to target attributes

Summary:
When requirement imposed by __target__ attributes on functions
are not satisfied, prefer printing those requirements, which
are explicitly mentioned in the attributes.

This makes such messages more useful, e.g. printing avx512f instead of avx2
in the following scenario:

```
$ cat foo.c
static inline void __attribute__((__always_inline__, __target__("avx512f")))
x(void)
{
}

int main(void)
{
x();
}
$ clang foo.c
foo.c:7:2: error: always_inline function 'x' requires target feature 'avx2', 
but would be inlined into function 'main' that is compiled without support for 
'avx2'
x();
^
1 error generated.
```

bugzilla: https://bugs.llvm.org/show_bug.cgi?id=37338

Reviewers: craig.topper, echristo, dblaikie

Reviewed By: craig.topper, echristo

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


Modified:
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/test/CodeGen/target-features-error-2.c
cfe/trunk/test/CodeGen/target-features-error.c

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=334174&r1=334173&r2=334174&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Thu Jun  7 01:48:36 2018
@@ -2330,9 +2330,19 @@ void CodeGenFunction::checkTargetFeature
 
   } else if (TargetDecl->hasAttr()) {
 // Get the required features for the callee.
+
+const TargetAttr *TD = TargetDecl->getAttr();
+TargetAttr::ParsedTargetAttr ParsedAttr = 
CGM.filterFunctionTargetAttrs(TD);
+
 SmallVector ReqFeatures;
 llvm::StringMap CalleeFeatureMap;
 CGM.getFunctionFeatureMap(CalleeFeatureMap, TargetDecl);
+
+for (const auto &F : ParsedAttr.Features) {
+  if (F[0] == '+' && CalleeFeatureMap.lookup(F.substr(1)))
+ReqFeatures.push_back(StringRef(F).substr(1));
+}
+
 for (const auto &F : CalleeFeatureMap) {
   // Only positive features are "required".
   if (F.getValue())

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=334174&r1=334173&r2=334174&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Jun  7 01:48:36 2018
@@ -5033,22 +5033,28 @@ void CodeGenModule::AddVTableTypeMetadat
   }
 }
 
+TargetAttr::ParsedTargetAttr CodeGenModule::filterFunctionTargetAttrs(const 
TargetAttr *TD) {
+  assert(TD != nullptr);
+  TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
+
+  ParsedAttr.Features.erase(
+  llvm::remove_if(ParsedAttr.Features,
+  [&](const std::string &Feat) {
+return !Target.isValidFeatureName(
+StringRef{Feat}.substr(1));
+  }),
+  ParsedAttr.Features.end());
+  return ParsedAttr;
+}
+
+
 // Fills in the supplied string map with the set of target features for the
 // passed in function.
 void CodeGenModule::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   const FunctionDecl *FD) {
   StringRef TargetCPU = Target.getTargetOpts().CPU;
   if (const auto *TD = FD->getAttr()) {
-// If we have a TargetAttr build up the feature map based on that.
-TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
-
-ParsedAttr.Features.erase(
-llvm::remove_if(ParsedAttr.Features,
-[&](const std::string &Feat) {
-  return !Target.isValidFeatureName(
-  StringRef{Feat}.substr(1));
-}),
-ParsedAttr.Features.end());
+TargetAttr::ParsedTargetAttr ParsedAttr = filterFunctionTargetAttrs(TD);
 
 // Make a copy of the features as passed on the command line into the
 // beginning of the additional features from the function to override.

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=334174&r1=334173&r2=334174&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Thu Jun  7 01:48:36 2018
@@ -1089,6 +1089,10 @@ public:
   /// It's up to you to ensure that this is safe.
   void AddDefaultFnAttrs(llvm::Function &F);
 
+  /// Parses the target attributes passed in, and returns only the ones that 
are
+  /// valid feature names.
+  Targ

[PATCH] D47869: [clangd] Fix using the incorrect Index for go-to-definition.

2018-06-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 150276.
hokein added a comment.

this->Index => Index.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47869

Files:
  clangd/ClangdServer.cpp


Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -302,7 +302,7 @@
 llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
-CB(clangd::findDefinitions(InpAST->AST, Pos, this->FileIdx.get()));
+CB(clangd::findDefinitions(InpAST->AST, Pos, Index));
   };
 
   WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB)));


Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -302,7 +302,7 @@
 llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
-CB(clangd::findDefinitions(InpAST->AST, Pos, this->FileIdx.get()));
+CB(clangd::findDefinitions(InpAST->AST, Pos, Index));
   };
 
   WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB)));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46541: [CodeGen] Improve diagnostics related to target attributes

2018-06-07 Thread Gabor Buella via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334174: [CodeGen] Improve diagnostics related to target 
attributes (authored by GBuella, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46541?vs=150018&id=150277#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46541

Files:
  cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.h
  cfe/trunk/test/CodeGen/target-features-error-2.c
  cfe/trunk/test/CodeGen/target-features-error.c

Index: cfe/trunk/test/CodeGen/target-features-error-2.c
===
--- cfe/trunk/test/CodeGen/target-features-error-2.c
+++ cfe/trunk/test/CodeGen/target-features-error-2.c
@@ -1,38 +1,46 @@
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_SSE42
 // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_1
 // RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_2
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_3
-// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX_4
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -S -verify -o - -D NEED_AVX512f
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +movdir64b -S -verify -o - -D NEED_MOVDIRI
+// RUN: %clang_cc1 %s -triple=x86_64-linux-gnu -target-feature +avx512vnni -target-feature +movdiri -S -verify -o - -D NEED_CLWB
 
 #define __MM_MALLOC_H
 #include 
 
-#if NEED_SSE42
+#if NEED_AVX_1
 int baz(__m256i a) {
   return _mm256_extract_epi32(a, 3); // expected-error {{'__builtin_ia32_vec_ext_v8si' needs target feature avx}}
 }
 #endif
 
-#if NEED_AVX_1
+#if NEED_AVX_2
 __m128 need_avx(__m128 a, __m128 b) {
   return _mm_cmp_ps(a, b, 0); // expected-error {{'__builtin_ia32_cmpps' needs target feature avx}}
 }
 #endif
 
-#if NEED_AVX_2
-__m128 need_avx(__m128 a, __m128 b) {
-  return _mm_cmp_ss(a, b, 0); // expected-error {{'__builtin_ia32_cmpss' needs target feature avx}}
+#if NEED_AVX512f
+unsigned short need_avx512f(unsigned short a, unsigned short b) {
+  return __builtin_ia32_korhi(a, b); // expected-error {{'__builtin_ia32_korhi' needs target feature avx512f}}
 }
 #endif
 
-#if NEED_AVX_3
-__m128d need_avx(__m128d a, __m128d b) {
-  return _mm_cmp_pd(a, b, 0); // expected-error {{'__builtin_ia32_cmppd' needs target feature avx}}
+#if NEED_MOVDIRI
+void need_movdiri(unsigned int *a, unsigned int b) {
+  __builtin_ia32_directstore_u32(a, b); // expected-error {{'__builtin_ia32_directstore_u32' needs target feature movdiri}}
 }
 #endif
 
-#if NEED_AVX_4
-__m128d need_avx(__m128d a, __m128d b) {
-  return _mm_cmp_sd(a, b, 0); // expected-error {{'__builtin_ia32_cmpsd' needs target feature avx}}
+#if NEED_CLWB
+static __inline__ void
+ __attribute__((__always_inline__, __nodebug__,  __target__("avx512vnni,clwb,movdiri,movdir64b")))
+ func(unsigned int *a, unsigned int b)
+{
+  __builtin_ia32_directstore_u32(a, b);
+}
+
+void need_clwb(unsigned int *a, unsigned int b) {
+  func(a, b); // expected-error {{always_inline function 'func' requires target feature 'clwb', but would be inlined into function 'need_clwb' that is compiled without support for 'clwb'}}
+
 }
 #endif
Index: cfe/trunk/test/CodeGen/target-features-error.c
===
--- cfe/trunk/test/CodeGen/target-features-error.c
+++ cfe/trunk/test/CodeGen/target-features-error.c
@@ -3,6 +3,5 @@
   return a + 4;
 }
 int bar() {
-  return foo(4); // expected-error {{always_inline function 'foo' requires target feature 'sse4.2', but would be inlined into function 'bar' that is compiled without support for 'sse4.2'}}
+  return foo(4); // expected-error {{always_inline function 'foo' requires target feature 'avx', but would be inlined into function 'bar' that is compiled without support for 'avx'}}
 }
-
Index: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp
@@ -5033,22 +5033,28 @@
   }
 }
 
+TargetAttr::ParsedTargetAttr CodeGenModule::filterFunctionTargetAttrs(const TargetAttr *TD) {
+  assert(TD != nullptr);
+  TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
+
+  ParsedAttr.Features.erase(
+  llvm::remove_if(ParsedAttr.Features,
+  [&](const std::string &Feat) {
+return !Target.isValidFeatureName(
+StringRef{Feat}.substr(1));
+  }),
+  ParsedAttr.Features.end());
+  return ParsedAttr;
+}
+
+
 // Fills in the supplied string map with the set of target features for the
 // passed in function.
 void CodeGenModule::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   const FunctionDecl *FD) {

[clang-tools-extra] r334176 - [clangd] Fix using the incorrect Index for go-to-definition.

2018-06-07 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Jun  7 01:49:55 2018
New Revision: 334176

URL: http://llvm.org/viewvc/llvm-project?rev=334176&view=rev
Log:
[clangd] Fix using the incorrect Index for go-to-definition.

Reviewers: sammccall

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, cfe-commits

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

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

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=334176&r1=334175&r2=334176&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Thu Jun  7 01:49:55 2018
@@ -302,7 +302,7 @@ void ClangdServer::findDefinitions(PathR
 llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
-CB(clangd::findDefinitions(InpAST->AST, Pos, this->FileIdx.get()));
+CB(clangd::findDefinitions(InpAST->AST, Pos, Index));
   };
 
   WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB)));


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


[PATCH] D47869: [clangd] Fix using the incorrect Index for go-to-definition.

2018-06-07 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
hokein marked an inline comment as done.
Closed by commit rCTE334176: [clangd] Fix using the incorrect Index for 
go-to-definition. (authored by hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D47869?vs=150276&id=150279#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47869

Files:
  clangd/ClangdServer.cpp


Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -302,7 +302,7 @@
 llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
-CB(clangd::findDefinitions(InpAST->AST, Pos, this->FileIdx.get()));
+CB(clangd::findDefinitions(InpAST->AST, Pos, Index));
   };
 
   WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB)));


Index: clangd/ClangdServer.cpp
===
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -302,7 +302,7 @@
 llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
-CB(clangd::findDefinitions(InpAST->AST, Pos, this->FileIdx.get()));
+CB(clangd::findDefinitions(InpAST->AST, Pos, Index));
   };
 
   WorkScheduler.runWithAST("Definitions", File, Bind(Action, std::move(CB)));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47853: [Frontend] Disallow non-MSVC exception models for windows-msvc targets

2018-06-07 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added inline comments.



Comment at: test/CodeGen/personality.c:10
-// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -D __SEH_EXCEPTIONS__ 
-fms-extensions -fexceptions -fblocks -fseh-exceptions -S -emit-llvm %s -o - | 
FileCheck %s -check-prefix CHECK-WIN-SEH -check-prefix CHECK-WIN-SEH-X64
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fblocks 
-fsjlj-exceptions -S -emit-llvm %s -o - | FileCheck %s -check-prefix 
CHECK-WIN-SJLJ
 

I'd prefer if you didn't remove these tests, but instead retarget them to use a 
`-gnu` triplet, to keep testing where you can explicitly choose between 
sjlj/dwarf/seh for mingw setups.



Comment at: test/CodeGenCXX/personality.cpp:9
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions 
-fseh-exceptions -fcxx-exceptions -S -emit-llvm %s -o - | FileCheck %s 
-check-prefix CHECK-WIN-SEH
-// %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fsjlj-exceptions 
-fcxx-exceptions -S -emit-llvm %s -o - | FileCheck %s -check-prefix 
CHECK-WIN-SJLJ
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -D __SEH_EXCEPTIONS__ 
-fms-extensions -fexceptions -fseh-exceptions -fcxx-exceptions -S -emit-llvm %s 
-o - | FileCheck %s -check-prefix CHECK-WIN-SEH-X86

Same here, please keep the existing tests but retarget them to gnu/mingw.



Comment at: test/Frontend/windows-exceptions.cpp:19
+// RUN: %clang_cc1 -triple x86_64--windows-gnu -fsyntax-only -fseh-exceptions 
%s
+// RUN: %clang_cc1 -triple x86_64--windows-gnu -fsyntax-only -fsjlj-exceptions 
%s
+

Ok, I see you're readding some sort of tests for the EH mode switching for 
mingw cases here, but you don't actually check that they produce the right 
thing here, only that it doesn't error out. So keeping the existing tests in 
the personality test files would probably be best.


Repository:
  rC Clang

https://reviews.llvm.org/D47853



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


[PATCH] D47630: [Sema] Allow creating types with multiple of the same addrspace.

2018-06-07 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: test/Sema/address_spaces.c:17
   int *_AS1 _AS2 *Z;  // expected-error {{multiple address spaces specified 
for type}}
+  int *_AS1 _AS1 *M;
 

Anastasia wrote:
> ebevhan wrote:
> > bader wrote:
> > > I think it might be valuable to give a warning or remark to user. 
> > > Using the same address space qualifier multiple times is not something 
> > > OpenCL C developers are supposed to do.
> > > 
> > The test is obviously a bit contrived, but it could happen by mistake, or 
> > as a result of some typedef or macro combination. It also cannot go wrong, 
> > so there's no harm in it happening.
> > 
> > I see your point, though. A warning feels like a bit much, so I'm not sure 
> > what else to use. A note?
> Just checked for const qualifier we get a warning:
>   warning: duplicate 'const' declaration specifier 
> [-Wduplicate-decl-specifier]
> 
> We could do the same... not sure if we could try to share the diagnostic as 
> well.
I have a patch ready that adds a warning in the same warning group and uses 
that. I'm not sure about reusing the other one since address spaces don't have 
to be declaration specifiers.

The warning is 'multiple identical address spaces specified for type', similar 
to the error. Is that acceptable?


Repository:
  rC Clang

https://reviews.llvm.org/D47630



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


[PATCH] D46911: [Fixed Point Arithmetic] Addition of the remaining fixed point types and their saturated equivalents

2018-06-07 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added a comment.

Actually, wait! One last thing I missed.




Comment at: include/clang/Sema/DeclSpec.h:670
const PrintingPolicy &Policy);
+  bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec,
+  unsigned &DiagID);

This should take a PrintingPolicy like the others.


Repository:
  rC Clang

https://reviews.llvm.org/D46911



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


[PATCH] D46190: For a referenced declaration, mark any associated usings as referenced.

2018-06-07 Thread Carlos Alberto Enciso via Phabricator via cfe-commits
CarlosAlbertoEnciso added a comment.

Ping.

The review

https://reviews.llvm.org/D44826

is already approved and it is dependent on this patch being reviewed.

Is there anything I can add to this patch?

Thanks very much.


https://reviews.llvm.org/D46190



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


r334179 - [clang-format] Consider tok::hashhash in python-style comments

2018-06-07 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Thu Jun  7 02:46:24 2018
New Revision: 334179

URL: http://llvm.org/viewvc/llvm-project?rev=334179&view=rev
Log:
[clang-format] Consider tok::hashhash in python-style comments

Summary: We were missing the case when python-style comments in text protos 
start with `##`.

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/FormatTokenLexer.cpp
cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=334179&r1=334178&r2=334179&view=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Thu Jun  7 02:46:24 2018
@@ -44,7 +44,8 @@ static StringRef getLineCommentIndentPre
 const FormatStyle &Style) {
   static const char *const KnownCStylePrefixes[] = {"///<", "//!<", "///", 
"//",
 "//!"};
-  static const char *const KnownTextProtoPrefixes[] = {"//", "#"};
+  static const char *const KnownTextProtoPrefixes[] = {"//", "#", "##", "###",
+   ""};
   ArrayRef KnownPrefixes(KnownCStylePrefixes);
   if (Style.Language == FormatStyle::LK_TextProto)
 KnownPrefixes = KnownTextProtoPrefixes;

Modified: cfe/trunk/lib/Format/FormatTokenLexer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatTokenLexer.cpp?rev=334179&r1=334178&r2=334179&view=diff
==
--- cfe/trunk/lib/Format/FormatTokenLexer.cpp (original)
+++ cfe/trunk/lib/Format/FormatTokenLexer.cpp Thu Jun  7 02:46:24 2018
@@ -334,7 +334,7 @@ void FormatTokenLexer::handleTemplateStr
 
 void FormatTokenLexer::tryParsePythonComment() {
   FormatToken *HashToken = Tokens.back();
-  if (HashToken->isNot(tok::hash))
+  if (!HashToken->isOneOf(tok::hash, tok::hashhash))
 return;
   // Turn the remainder of this line into a comment.
   const char *CommentBegin =

Modified: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestTextProto.cpp?rev=334179&r1=334178&r2=334179&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp Thu Jun  7 02:46:24 2018
@@ -347,6 +347,28 @@ TEST_F(FormatTestTextProto, KeepsComment
": 3849");
 }
 
+TEST_F(FormatTestTextProto, UnderstandsHashHashComments) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60; // To make writing tests easier.
+  EXPECT_EQ("aaa: 100\n"
+"##this is a double-hash comment.\n"
+"bb: 100\n"
+"## another double-hash comment.\n"
+"### a triple-hash comment\n"
+"cc: 200\n"
+" a quadriple-hash comment\n"
+"dd: 100\n",
+format("aaa: 100\n"
+   "##this is a double-hash comment.\n"
+   "bb: 100\n"
+   "## another double-hash comment.\n"
+   "### a triple-hash comment\n"
+   "cc: 200\n"
+   " a quadriple-hash comment\n"
+   "dd: 100\n",
+   Style));
+}
+
 TEST_F(FormatTestTextProto, FormatsExtensions) {
   verifyFormat("[type] { key: value }");
   verifyFormat("[type] {\n"


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


[PATCH] D47870: [clang-format] Consider tok::hashhash in python-style comments

2018-06-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC334179: [clang-format] Consider tok::hashhash in 
python-style comments (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D47870?vs=150275&id=150284#toc

Repository:
  rC Clang

https://reviews.llvm.org/D47870

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/FormatTokenLexer.cpp
  unittests/Format/FormatTestTextProto.cpp


Index: lib/Format/FormatTokenLexer.cpp
===
--- lib/Format/FormatTokenLexer.cpp
+++ lib/Format/FormatTokenLexer.cpp
@@ -334,7 +334,7 @@
 
 void FormatTokenLexer::tryParsePythonComment() {
   FormatToken *HashToken = Tokens.back();
-  if (HashToken->isNot(tok::hash))
+  if (!HashToken->isOneOf(tok::hash, tok::hashhash))
 return;
   // Turn the remainder of this line into a comment.
   const char *CommentBegin =
Index: lib/Format/BreakableToken.cpp
===
--- lib/Format/BreakableToken.cpp
+++ lib/Format/BreakableToken.cpp
@@ -44,7 +44,8 @@
 const FormatStyle &Style) {
   static const char *const KnownCStylePrefixes[] = {"///<", "//!<", "///", 
"//",
 "//!"};
-  static const char *const KnownTextProtoPrefixes[] = {"//", "#"};
+  static const char *const KnownTextProtoPrefixes[] = {"//", "#", "##", "###",
+   ""};
   ArrayRef KnownPrefixes(KnownCStylePrefixes);
   if (Style.Language == FormatStyle::LK_TextProto)
 KnownPrefixes = KnownTextProtoPrefixes;
Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -347,6 +347,28 @@
": 3849");
 }
 
+TEST_F(FormatTestTextProto, UnderstandsHashHashComments) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60; // To make writing tests easier.
+  EXPECT_EQ("aaa: 100\n"
+"##this is a double-hash comment.\n"
+"bb: 100\n"
+"## another double-hash comment.\n"
+"### a triple-hash comment\n"
+"cc: 200\n"
+" a quadriple-hash comment\n"
+"dd: 100\n",
+format("aaa: 100\n"
+   "##this is a double-hash comment.\n"
+   "bb: 100\n"
+   "## another double-hash comment.\n"
+   "### a triple-hash comment\n"
+   "cc: 200\n"
+   " a quadriple-hash comment\n"
+   "dd: 100\n",
+   Style));
+}
+
 TEST_F(FormatTestTextProto, FormatsExtensions) {
   verifyFormat("[type] { key: value }");
   verifyFormat("[type] {\n"


Index: lib/Format/FormatTokenLexer.cpp
===
--- lib/Format/FormatTokenLexer.cpp
+++ lib/Format/FormatTokenLexer.cpp
@@ -334,7 +334,7 @@
 
 void FormatTokenLexer::tryParsePythonComment() {
   FormatToken *HashToken = Tokens.back();
-  if (HashToken->isNot(tok::hash))
+  if (!HashToken->isOneOf(tok::hash, tok::hashhash))
 return;
   // Turn the remainder of this line into a comment.
   const char *CommentBegin =
Index: lib/Format/BreakableToken.cpp
===
--- lib/Format/BreakableToken.cpp
+++ lib/Format/BreakableToken.cpp
@@ -44,7 +44,8 @@
 const FormatStyle &Style) {
   static const char *const KnownCStylePrefixes[] = {"///<", "//!<", "///", "//",
 "//!"};
-  static const char *const KnownTextProtoPrefixes[] = {"//", "#"};
+  static const char *const KnownTextProtoPrefixes[] = {"//", "#", "##", "###",
+   ""};
   ArrayRef KnownPrefixes(KnownCStylePrefixes);
   if (Style.Language == FormatStyle::LK_TextProto)
 KnownPrefixes = KnownTextProtoPrefixes;
Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -347,6 +347,28 @@
": 3849");
 }
 
+TEST_F(FormatTestTextProto, UnderstandsHashHashComments) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60; // To make writing tests easier.
+  EXPECT_EQ("aaa: 100\n"
+"##this is a double-hash comment.\n"
+"bb: 100\n"
+"## another double-hash comment.\n"
+"### a triple-hash comment\n"
+"cc: 200\n"
+   

[PATCH] D47871: [clangd] Code completion: drop explicit injected names/operators, ignore Sema priority

2018-06-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: ioeric.
Herald added subscribers: cfe-commits, jkorous, MaskRay, ilya-biryukov.

Now we have most of Sema's code completion signals incorporated in Quality,
which will allow us to give consistent ranking to sema/index results.

Therefore we can/should stop using Sema priority as an explicit signal.
This fixes some issues like namespaces always having a terrible score.

The most important missing signals are:

- Really dumb/rarely useful completions like: SomeStruct().^SomeStruct 
SomeStruct().^operator= SomeStruct().~SomeStruct() We already filter out 
destructors, this patch adds injected names and operators to that list.
- type matching the expression context. Ilya has a plan to add this in a way 
that's compatible with indexes (design doc should be shared real soon now!)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47871

Files:
  clangd/CodeComplete.cpp
  clangd/Quality.cpp
  clangd/Quality.h
  test/clangd/completion.test
  test/clangd/protocol.test
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/QualityTests.cpp

Index: unittests/clangd/QualityTests.cpp
===
--- unittests/clangd/QualityTests.cpp
+++ unittests/clangd/QualityTests.cpp
@@ -39,23 +39,20 @@
   SymbolQualitySignals Quality;
   Quality.merge(findSymbol(Symbols, "x"));
   EXPECT_FALSE(Quality.Deprecated);
-  EXPECT_EQ(Quality.SemaCCPriority, SymbolQualitySignals().SemaCCPriority);
   EXPECT_EQ(Quality.References, SymbolQualitySignals().References);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Variable);
 
   Symbol F = findSymbol(Symbols, "f");
   F.References = 24; // TestTU doesn't count references, so fake it.
   Quality = {};
   Quality.merge(F);
   EXPECT_FALSE(Quality.Deprecated); // FIXME: Include deprecated bit in index.
-  EXPECT_EQ(Quality.SemaCCPriority, SymbolQualitySignals().SemaCCPriority);
   EXPECT_EQ(Quality.References, 24u);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Function);
 
   Quality = {};
   Quality.merge(CodeCompletionResult(&findDecl(AST, "f"), /*Priority=*/42));
   EXPECT_TRUE(Quality.Deprecated);
-  EXPECT_EQ(Quality.SemaCCPriority, 42u);
   EXPECT_EQ(Quality.References, SymbolQualitySignals().References);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Function);
 }
@@ -121,12 +118,6 @@
   EXPECT_GT(WithReferences.evaluate(), Default.evaluate());
   EXPECT_GT(ManyReferences.evaluate(), WithReferences.evaluate());
 
-  SymbolQualitySignals LowPriority, HighPriority;
-  LowPriority.SemaCCPriority = 60;
-  HighPriority.SemaCCPriority = 20;
-  EXPECT_GT(HighPriority.evaluate(), Default.evaluate());
-  EXPECT_LT(LowPriority.evaluate(), Default.evaluate());
-
   SymbolQualitySignals Variable, Macro;
   Variable.Category = SymbolQualitySignals::Variable;
   Macro.Category = SymbolQualitySignals::Macro;
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -207,9 +207,6 @@
   EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
   AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux";
 
-  EXPECT_THAT(completions(Body + "int main() { S().opr^ }").items,
-  Has("operator="));
-
   EXPECT_THAT(completions(Body + "int main() { aaa^ }").items,
   AllOf(Has("Abracadabra"), Has("Alakazam")));
 
Index: test/clangd/protocol.test
===
--- test/clangd/protocol.test
+++ test/clangd/protocol.test
@@ -34,11 +34,11 @@
 # CHECK-NEXT:  "result": {
 # CHECK-NEXT:"isIncomplete": false,
 # CHECK-NEXT:"items": [
-#  CHECK:"filterText": "fake",
-# CHECK-NEXT:"insertText": "fake",
+#  CHECK:"filterText": "a",
+# CHECK-NEXT:"insertText": "a",
 # CHECK-NEXT:"insertTextFormat": 1,
-# CHECK-NEXT:"kind": 7,
-# CHECK-NEXT:"label": "fake",
+# CHECK-NEXT:"kind": 5,
+# CHECK-NEXT:"label": "a",
 # CHECK-NEXT:"sortText": "{{.*}}"
 #  CHECK:]
 # CHECK-NEXT:  }
@@ -63,11 +63,11 @@
 # CHECK-NEXT:  "result": {
 # CHECK-NEXT:"isIncomplete": false,
 # CHECK-NEXT:"items": [
-#  CHECK:"filterText": "fake",
-# CHECK-NEXT:"insertText": "fake",
+#  CHECK:"filterText": "a",
+# CHECK-NEXT:"insertText": "a",
 # CHECK-NEXT:"insertTextFormat": 1,
-# CHECK-NEXT:"kind": 7,
-# CHECK-NEXT:"label": "fake",
+# CHECK-NEXT:"kind": 5,
+# CHECK-NEXT:"label": "a",
 # CHECK-NEXT:"sortText": "{{.*}}"
 #  CHECK:]
 # CHECK-NEXT:  }
@@ -92,11 +92,11 @@
 # CHECK-NEXT:  "result": {
 # CHECK-NEXT:"isIncomplete": false,
 # CHECK-NEXT:"items": [
-#  CHECK:"filterText": "fake",
-# CHECK-NEXT:"insertText": "fake",
+#  C

[PATCH] D46862: [libclang] Optionally add code completion results for arrow instead of dot

2018-06-07 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 150291.
yvvan marked 8 inline comments as done.
yvvan added a comment.

Address review comments


https://reviews.llvm.org/D46862

Files:
  include/clang-c/Index.h
  include/clang/Sema/CodeCompleteConsumer.h
  test/Index/complete-arrow-dot.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp
  tools/libclang/CIndexCodeCompletion.cpp
  tools/libclang/libclang.exports

Index: tools/libclang/libclang.exports
===
--- tools/libclang/libclang.exports
+++ tools/libclang/libclang.exports
@@ -171,6 +171,8 @@
 clang_getCompletionChunkCompletionString
 clang_getCompletionChunkKind
 clang_getCompletionChunkText
+clang_getCompletionNumFixIts
+clang_getCompletionFixIt
 clang_getCompletionNumAnnotations
 clang_getCompletionParent
 clang_getCompletionPriority
@@ -260,6 +262,7 @@
 clang_getSpellingLocation
 clang_getTUResourceUsageName
 clang_getTemplateCursorKind
+clang_getToken
 clang_getTokenExtent
 clang_getTokenKind
 clang_getTokenLocation
Index: tools/libclang/CIndexCodeCompletion.cpp
===
--- tools/libclang/CIndexCodeCompletion.cpp
+++ tools/libclang/CIndexCodeCompletion.cpp
@@ -16,6 +16,7 @@
 #include "CIndexDiagnostic.h"
 #include "CLog.h"
 #include "CXCursor.h"
+#include "CXSourceLocation.h"
 #include "CXString.h"
 #include "CXTranslationUnit.h"
 #include "clang/AST/Decl.h"
@@ -302,10 +303,53 @@
   /// A string containing the Objective-C selector entered thus far for a
   /// message send.
   std::string Selector;
+
+  /// Vector of fix-its for each completion result that *must* be applied
+  /// before that result for the corresponding completion item.
+  std::vector> FixItsVector;
 };
 
 } // end anonymous namespace
 
+unsigned clang_getCompletionNumFixIts(CXCodeCompleteResults *results,
+  unsigned completion_index) {
+  AllocatedCXCodeCompleteResults *allocated_results = (AllocatedCXCodeCompleteResults *)results;
+
+  if (!allocated_results || allocated_results->FixItsVector.size() <= completion_index)
+return 0;
+
+  return static_cast(allocated_results->FixItsVector[completion_index].size());
+}
+
+CXString clang_getCompletionFixIt(CXCodeCompleteResults *results,
+  unsigned completion_index,
+  unsigned fixit_index,
+  CXSourceRange *replacement_range) {
+  AllocatedCXCodeCompleteResults *allocated_results = (AllocatedCXCodeCompleteResults *)results;
+
+  if (!allocated_results || allocated_results->FixItsVector.size() <= completion_index) {
+if (replacement_range)
+  *replacement_range = clang_getNullRange();
+return cxstring::createNull();
+  }
+
+  ArrayRef FixIts = allocated_results->FixItsVector[completion_index];
+  if (FixIts.size() <= fixit_index) {
+if (replacement_range)
+  *replacement_range = clang_getNullRange();
+return cxstring::createNull();
+  }
+
+  const FixItHint &FixIt = FixIts[fixit_index];
+  if (replacement_range) {
+*replacement_range = cxloc::translateSourceRange(
+*allocated_results->SourceMgr, allocated_results->LangOpts,
+FixIt.RemoveRange);
+  }
+
+  return cxstring::createRef(FixIt.CodeToInsert.c_str());
+}
+
 /// Tracks the number of code-completion result objects that are 
 /// currently active.
 ///
@@ -531,18 +575,22 @@
 CodeCompletionResult *Results,
 unsigned NumResults) override {
   StoredResults.reserve(StoredResults.size() + NumResults);
+  if (includeFixIts())
+AllocatedResults.FixItsVector.reserve(NumResults);
   for (unsigned I = 0; I != NumResults; ++I) {
-CodeCompletionString *StoredCompletion
+CodeCompletionString *StoredCompletion
   = Results[I].CreateCodeCompletionString(S, Context, getAllocator(),
   getCodeCompletionTUInfo(),
   includeBriefComments());
 
 CXCompletionResult R;
 R.CursorKind = Results[I].CursorKind;
 R.CompletionString = StoredCompletion;
 StoredResults.push_back(R);
+if (includeFixIts())
+  AllocatedResults.FixItsVector.emplace_back(std::move(Results[I].FixIts));
   }
-  
+
   enum CodeCompletionContext::Kind contextKind = Context.getKind();
   
   AllocatedResults.ContextKind = contextKind;
@@ -644,13 +692,13 @@
   unsigned options) {
   bool IncludeBriefComments = options & CXCodeComplete_IncludeBriefComments;
   bool SkipPreamble = options & CXCodeComplete_SkipPreamble;
+  bool IncludeFixIts = options & CXCodeComplete_IncludeCompletionsWithFixIts;
 
 #ifdef UDP_CODE_COMPLETION_LOGGER
 #ifdef UDP_CODE_COMPLETION_LOGGER_PORT
   const llvm::TimeRecord &StartTime =  llvm::T

[PATCH] D47875: [MS ABI] Mangle unnamed empty enums (PR37723)

2018-06-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans created this revision.
hans added a reviewer: majnemer.

Clang would previously assert here.


https://reviews.llvm.org/D47875

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenCXX/mangle-ms-cxx11.cpp


Index: test/CodeGenCXX/mangle-ms-cxx11.cpp
===
--- test/CodeGenCXX/mangle-ms-cxx11.cpp
+++ test/CodeGenCXX/mangle-ms-cxx11.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - 
-triple=i386-pc-win32 -fms-compatibility-version=19.00 | FileCheck %s 
--check-prefix=CHECK --check-prefix=MSVC2015
 // RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - 
-triple=i386-pc-win32 -fms-compatibility-version=18.00 | FileCheck %s 
--check-prefix=CHECK --check-prefix=MSVC2013
+// RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - 
-triple=i386-pc-win32 -gcodeview -debug-info-kind=limited | FileCheck %s 
--check-prefix=DBG
 
 namespace FTypeWithQuals {
 template 
@@ -350,3 +351,9 @@
 void f(decltype(enumerator)) {}
 // CHECK-DAG: define internal void @"?f@@YAXW4@@@Z"(
 void use_f() { f(enumerator); }
+
+namespace pr37723 {
+struct s { enum {}; };
+// DBG-DAG: DW_TAG_enumeration_type{{.*}}identifier: 
".?AW4@s@pr37723@@"
+s x;
+}
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -886,9 +886,12 @@
 Name += TND->getName();
   } else if (auto *ED = dyn_cast(TD)) {
 auto EnumeratorI = ED->enumerator_begin();
-assert(EnumeratorI != ED->enumerator_end());
-Name += "getName();
+if (EnumeratorI == ED->enumerator_end()) {
+  Name += "getName();
+}
   } else {
 // Otherwise, number the types using a $S prefix.
 Name += "Index: test/CodeGenCXX/mangle-ms-cxx11.cpp
===
--- test/CodeGenCXX/mangle-ms-cxx11.cpp
+++ test/CodeGenCXX/mangle-ms-cxx11.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 -fms-compatibility-version=19.00 | FileCheck %s --check-prefix=CHECK --check-prefix=MSVC2015
 // RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 -fms-compatibility-version=18.00 | FileCheck %s --check-prefix=CHECK --check-prefix=MSVC2013
+// RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - -triple=i386-pc-win32 -gcodeview -debug-info-kind=limited | FileCheck %s --check-prefix=DBG
 
 namespace FTypeWithQuals {
 template 
@@ -350,3 +351,9 @@
 void f(decltype(enumerator)) {}
 // CHECK-DAG: define internal void @"?f@@YAXW4@@@Z"(
 void use_f() { f(enumerator); }
+
+namespace pr37723 {
+struct s { enum {}; };
+// DBG-DAG: DW_TAG_enumeration_type{{.*}}identifier: ".?AW4@s@pr37723@@"
+s x;
+}
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -886,9 +886,12 @@
 Name += TND->getName();
   } else if (auto *ED = dyn_cast(TD)) {
 auto EnumeratorI = ED->enumerator_begin();
-assert(EnumeratorI != ED->enumerator_end());
-Name += "getName();
+if (EnumeratorI == ED->enumerator_end()) {
+  Name += "getName();
+}
   } else {
 // Otherwise, number the types using a $S prefix.
 Name += "___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46911: [Fixed Point Arithmetic] Addition of the remaining fixed point types and their saturated equivalents

2018-06-07 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: lib/Sema/SemaType.cpp:1612
+  // Only fixed point types can be saturated
+  if (DS.isTypeSpecSat() && !IsFixedPointType)
+S.Diag(DS.getTypeSpecSatLoc(), diag::err_invalid_saturation_spec)

Also, this does not seem to invalidate the declarator.


Repository:
  rC Clang

https://reviews.llvm.org/D46911



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


[PATCH] D47875: [MS ABI] Mangle unnamed empty enums (PR37723)

2018-06-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Please take a look.

I couldn't figure out a way to get a mangled name for this without using debug 
info. Do you have any ideas?


https://reviews.llvm.org/D47875



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


[PATCH] D47578: Do not enforce absolute path argv0 in windows

2018-06-07 Thread Takuto Ikuta via Phabricator via cfe-commits
takuto.ikuta updated this revision to Diff 150300.

https://reviews.llvm.org/D47578

Files:
  llvm/lib/Support/Windows/Process.inc
  llvm/unittests/Support/CommandLineTest.cpp

Index: llvm/unittests/Support/CommandLineTest.cpp
===
--- llvm/unittests/Support/CommandLineTest.cpp
+++ llvm/unittests/Support/CommandLineTest.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/Triple.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/InitLLVM.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/StringSaver.h"
@@ -821,4 +822,22 @@
   EXPECT_TRUE(Errs.empty());
 }
 
+#ifdef _WIN32
+TEST(CommandLineTest, GetCommandLineArguments) {
+  int argc = __argc;
+  char **argv = __argv;
+
+  // GetCommandLineArguments is called in InitLLVM.
+  llvm::InitLLVM X(argc, argv);
+
+  EXPECT_EQ(llvm::sys::path::is_absolute(argv[0]),
+llvm::sys::path::is_absolute(__argv[0]));
+
+  EXPECT_TRUE(llvm::sys::path::filename(argv[0])
+  .equals_lower("supporttests.exe"))
+  << "Filename of test executable is "
+  << llvm::sys::path::filename(argv[0]);
+}
+#endif
+
 }  // anonymous namespace
Index: llvm/lib/Support/Windows/Process.inc
===
--- llvm/lib/Support/Windows/Process.inc
+++ llvm/lib/Support/Windows/Process.inc
@@ -209,54 +209,63 @@
   return ec;
 }
 
-static std::error_code ExpandShortFileName(const wchar_t *Arg,
-   SmallVectorImpl &Args,
-   BumpPtrAllocator &Alloc) {
-  SmallVector LongPath;
-  DWORD Length = GetLongPathNameW(Arg, LongPath.data(), LongPath.capacity());
+static std::error_code GetExecutableName(SmallVectorImpl &Filename) {
+  // The first argument may contain just the name of the executable (e.g.,
+  // "clang") rather than the full path, so swap it with the full path.
+  wchar_t ModuleName[MAX_PATH];
+  int Length = ::GetModuleFileNameW(NULL, ModuleName, MAX_PATH);
+  if (Length == 0 || Length == MAX_PATH) {
+return mapWindowsError(GetLastError());
+  }
+
+  // If the first argument is a shortened (8.3) name (which is possible even
+  // if we got the module name), the driver will have trouble distinguishing it
+  // (e.g., clang.exe v. clang++.exe), so expand it now.
+  Length = GetLongPathNameW(ModuleName, ModuleName, MAX_PATH);
   if (Length == 0)
 return mapWindowsError(GetLastError());
-  if (Length > LongPath.capacity()) {
+  if (static_cast(Length) > MAX_PATH) {
 // We're not going to try to deal with paths longer than MAX_PATH, so we'll
 // treat this as an error.  GetLastError() returns ERROR_SUCCESS, which
 // isn't useful, so we'll hardcode an appropriate error value.
 return mapWindowsError(ERROR_INSUFFICIENT_BUFFER);
   }
-  LongPath.set_size(Length);
-  return ConvertAndPushArg(LongPath.data(), Args, Alloc);
+
+  std::error_code ec = windows::UTF16ToUTF8(ModuleName, Length, Filename);
+  if (ec)
+return ec;
+
+  StringRef Base = sys::path::filename(Filename.data());
+  Filename.assign(Base.begin(), Base.end());
+  return ec;
 }
 
 std::error_code
 windows::GetCommandLineArguments(SmallVectorImpl &Args,
  BumpPtrAllocator &Alloc) {
   int ArgCount;
-  wchar_t **UnicodeCommandLine =
-  CommandLineToArgvW(GetCommandLineW(), &ArgCount);
+  std::unique_ptr UnicodeCommandLine{
+CommandLineToArgvW(GetCommandLineW(), &ArgCount), &LocalFree};
   if (!UnicodeCommandLine)
 return mapWindowsError(::GetLastError());
 
-  Args.reserve(ArgCount);
   std::error_code ec;
 
-  // The first argument may contain just the name of the executable (e.g.,
-  // "clang") rather than the full path, so swap it with the full path.
-  wchar_t ModuleName[MAX_PATH];
-  int Length = ::GetModuleFileNameW(NULL, ModuleName, MAX_PATH);
-  if (0 < Length && Length < MAX_PATH)
-UnicodeCommandLine[0] = ModuleName;
-
-  // If the first argument is a shortened (8.3) name (which is possible even
-  // if we got the module name), the driver will have trouble distinguishing it
-  // (e.g., clang.exe v. clang++.exe), so expand it now.
-  ec = ExpandShortFileName(UnicodeCommandLine[0], Args, Alloc);
+  Args.reserve(ArgCount);
 
-  for (int i = 1; i < ArgCount && !ec; ++i) {
+  for (int i = 0; i < ArgCount; ++i) {
 ec = WildcardExpand(UnicodeCommandLine[i], Args, Alloc);
 if (ec)
-  break;
+  return ec;
   }
 
-  LocalFree(UnicodeCommandLine);
+  SmallVector Arg0(Args[0], Args[0] + strlen(Args[0])), Filename;
+  sys::path::remove_filename(Arg0);
+  ec = GetExecutableName(Filename);
+  if (ec)
+return ec;
+  sys::path::append(Arg0, Filename);
+  Args[0] = AllocateString(Arg0, Alloc);
   return ec;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/lis

[PATCH] D47578: Do not enforce absolute path argv0 in windows

2018-06-07 Thread Takuto Ikuta via Phabricator via cfe-commits
takuto.ikuta added a comment.

I see.  Changed not to convert many times.

I confirmed that this passed check-lld, check-llvm and check-clang. If this 
looks good for you, can I ask you to merge this?

Thanks.


https://reviews.llvm.org/D47578



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


[PATCH] D47871: [clangd] Code completion: drop explicit injected names/operators, ignore Sema priority

2018-06-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Maybe we could add the test cases that the blacklisted members still show up in 
completion that don't involve member qualifiers? For example,

  struct X : std::vector { 
int test( ){
   // <-- 'vector' might be a useful completion here.
}
  };


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47871



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


[PATCH] D47849: [OpenMP][Clang][NVPTX] Enable math functions called in an OpenMP NVPTX target device region to be resolved as device-native function calls

2018-06-07 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel added a comment.

In https://reviews.llvm.org/D47849#1124638, @Hahnfeld wrote:

> IMO this goes into the right direction, we should use the fast implementation 
> in libdevice. If LLVM doesn't lower these calls in the NVPTX backend, I think 
> it's ok to use header wrappers as CUDA already does.
>
> Two questions:
>
> 1. Can you explain where this is important for "correctness"? Yesterday I 
> compiled a code using `sqrt` and it seems to spit out the correct results. 
> Maybe that's relevant for other functions?
> 2. Incidentally I ran into a closely related problem: I can't `#include 
> ` in translation units compiled for offloading, Clang complains about 
> inline assembly for x86 (see below). Does that work for you?
>
>   ``` In file included from /usr/include/math.h:413: 
> /usr/include/bits/mathinline.h:131:43: error: invalid input constraint 'x' in 
> asm __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x)); ^ 
> /usr/include/bits/mathinline.h:143:43: error: invalid input constraint 'x' in 
> asm __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x)); ^ 2 errors generated. 
> ```


Hrmm. I thought that we had fixed that already.

In case it's helpful, in an out-of-tree experimental target I have I ran into a 
similar problem, and to fix that I wrote the following code in the target's 
getTargetDefines function (in lib/Basic/Targets):

  // If used as an OpenMP target on x86, x86 target feature macros are defined. 
math.h
  // and other system headers will include inline asm if these are defined.
  Builder.undefineMacro("__SSE2_MATH__");
  Builder.undefineMacro("__SSE_MATH__");


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D47871: [clangd] Code completion: drop explicit injected names/operators, ignore Sema priority

2018-06-07 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added inline comments.
This revision is now accepted and ready to land.



Comment at: clangd/CodeComplete.cpp:542
 continue;
-  // Destructor completion is rarely useful, and works inconsistently.
-  // (s.^ completes ~string, but s.~st^ is an error).
-  if (dyn_cast_or_null(Result.Declaration))
+  if (Result.Declaration && !Context.getBaseType().isNull() &&
+  isBlacklistedMember(*Result.Declaration))

`!Context.getBaseType().isNull()`  probably deserves a comment. 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47871



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


[PATCH] D47290: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %zu/%zi on Darwin

2018-06-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

What's special about size_t though? If I understand your patch correctly, it 
would suppress warning about printing NSInteger with %zd, but still warn about 
%ld even though ssize_t=long on the target? As a user I'd find this confusing.

If we really want to special-case NSInteger, and given that you're targeting a 
specific wide-spread pattern maybe that's the right thing to do, I think we 
should make -Wformat accept (move the warning behind -Wformat-pedantic I 
suppose) printing NSInteger with *any* integral type of the right size, not 
just size_t.

Also, I haven't looked at what happens on the scanf side. Does that need an 
equivalent change?


Repository:
  rC Clang

https://reviews.llvm.org/D47290



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


[PATCH] D47871: [clangd] Code completion: drop explicit injected names/operators, ignore Sema priority

2018-06-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 150307.
sammccall added a comment.

Added tests and comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47871

Files:
  clangd/CodeComplete.cpp
  clangd/Quality.cpp
  clangd/Quality.h
  test/clangd/completion.test
  test/clangd/protocol.test
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/QualityTests.cpp

Index: unittests/clangd/QualityTests.cpp
===
--- unittests/clangd/QualityTests.cpp
+++ unittests/clangd/QualityTests.cpp
@@ -39,23 +39,20 @@
   SymbolQualitySignals Quality;
   Quality.merge(findSymbol(Symbols, "x"));
   EXPECT_FALSE(Quality.Deprecated);
-  EXPECT_EQ(Quality.SemaCCPriority, SymbolQualitySignals().SemaCCPriority);
   EXPECT_EQ(Quality.References, SymbolQualitySignals().References);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Variable);
 
   Symbol F = findSymbol(Symbols, "f");
   F.References = 24; // TestTU doesn't count references, so fake it.
   Quality = {};
   Quality.merge(F);
   EXPECT_FALSE(Quality.Deprecated); // FIXME: Include deprecated bit in index.
-  EXPECT_EQ(Quality.SemaCCPriority, SymbolQualitySignals().SemaCCPriority);
   EXPECT_EQ(Quality.References, 24u);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Function);
 
   Quality = {};
   Quality.merge(CodeCompletionResult(&findDecl(AST, "f"), /*Priority=*/42));
   EXPECT_TRUE(Quality.Deprecated);
-  EXPECT_EQ(Quality.SemaCCPriority, 42u);
   EXPECT_EQ(Quality.References, SymbolQualitySignals().References);
   EXPECT_EQ(Quality.Category, SymbolQualitySignals::Function);
 }
@@ -121,12 +118,6 @@
   EXPECT_GT(WithReferences.evaluate(), Default.evaluate());
   EXPECT_GT(ManyReferences.evaluate(), WithReferences.evaluate());
 
-  SymbolQualitySignals LowPriority, HighPriority;
-  LowPriority.SemaCCPriority = 60;
-  HighPriority.SemaCCPriority = 20;
-  EXPECT_GT(HighPriority.evaluate(), Default.evaluate());
-  EXPECT_LT(LowPriority.evaluate(), Default.evaluate());
-
   SymbolQualitySignals Variable, Macro;
   Variable.Category = SymbolQualitySignals::Variable;
   Macro.Category = SymbolQualitySignals::Macro;
Index: unittests/clangd/CodeCompleteTests.cpp
===
--- unittests/clangd/CodeCompleteTests.cpp
+++ unittests/clangd/CodeCompleteTests.cpp
@@ -207,9 +207,6 @@
   EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
   AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux";
 
-  EXPECT_THAT(completions(Body + "int main() { S().opr^ }").items,
-  Has("operator="));
-
   EXPECT_THAT(completions(Body + "int main() { aaa^ }").items,
   AllOf(Has("Abracadabra"), Has("Alakazam")));
 
@@ -250,9 +247,10 @@
 
   // Class members. The only items that must be present in after-dot
   // completion.
-  EXPECT_THAT(
-  Results.items,
-  AllOf(Has(Opts.EnableSnippets ? "method()" : "method"), Has("field")));
+  EXPECT_THAT(Results.items,
+  AllOf(Has(Opts.EnableSnippets ? "method()" : "method"),
+Has("field"), Not(Has("ClassWithMembers")),
+Not(Has("operator=")), Not(Has("~ClassWithMembers";
   EXPECT_IFF(Opts.IncludeIneligibleResults, Results.items,
  Has("private_field"));
   // Global items.
@@ -379,6 +377,25 @@
   EXPECT_THAT(Results.items, Not(Contains(Labeled("foo() const"; // private
 }
 
+TEST(CompletionTest, InjectedTypename) {
+  // These are suppressed when accessed as a member...
+  EXPECT_THAT(completions("struct X{}; void foo(){ X().^ }").items,
+  Not(Has("X")));
+  EXPECT_THAT(completions("struct X{ void foo(){ this->^ } };").items,
+  Not(Has("X")));
+  // ...but accessible in other, more useful cases.
+  EXPECT_THAT(completions("struct X{ void foo(){ ^ } };").items, Has("X"));
+  EXPECT_THAT(completions("struct Y{}; struct X:Y{ void foo(){ ^ } };").items,
+  Has("Y"));
+  EXPECT_THAT(
+  completions(
+  "template struct Y{}; struct X:Y{ void foo(){ ^ } };")
+  .items,
+  Has("Y"));
+  // This case is marginal (`using X::X` is useful), we allow it for now.
+  EXPECT_THAT(completions("struct X{}; void foo(){ X::^ }").items, Has("X"));
+}
+
 TEST(CompletionTest, Snippets) {
   clangd::CodeCompleteOptions Opts;
   Opts.EnableSnippets = true;
Index: test/clangd/protocol.test
===
--- test/clangd/protocol.test
+++ test/clangd/protocol.test
@@ -34,11 +34,11 @@
 # CHECK-NEXT:  "result": {
 # CHECK-NEXT:"isIncomplete": false,
 # CHECK-NEXT:"items": [
-#  CHECK:"filterText": "fake",
-# CHECK-NEXT:"insertText": "fake",
+#  CHECK:"filterText": "a",
+# CHECK-NEXT:"insertText": "a",
 # CHECK-NEXT:"insertTextFormat": 1,
-# CHECK-NEXT:"kind": 7,
-# CHECK-NEXT:"label": "fake",
+# CHECK-NEXT:"kind": 5,

[PATCH] D47871: [clangd] Code completion: drop explicit injected names/operators, ignore Sema priority

2018-06-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added a comment.

Added explicit tests for this feature.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47871



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


[PATCH] D47871: [clangd] Code completion: drop explicit injected names/operators, ignore Sema priority

2018-06-07 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334192: [clangd] Code completion: drop explicit injected 
names/operators, ignore Sema… (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D47871

Files:
  clang-tools-extra/trunk/clangd/CodeComplete.cpp
  clang-tools-extra/trunk/clangd/Quality.cpp
  clang-tools-extra/trunk/clangd/Quality.h
  clang-tools-extra/trunk/test/clangd/completion.test
  clang-tools-extra/trunk/test/clangd/protocol.test
  clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
  clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp

Index: clang-tools-extra/trunk/test/clangd/completion.test
===
--- clang-tools-extra/trunk/test/clangd/completion.test
+++ clang-tools-extra/trunk/test/clangd/completion.test
@@ -18,8 +18,8 @@
 # CHECK-NEXT:  "kind": 5,
 # CHECK-NEXT:  "label": "a",
 # CHECK-NEXT:  "sortText": "{{.*}}a"
-# CHECK-NEXT:},
-#  CHECK:  ]
+# CHECK-NEXT:}
+# CHECK-NEXT:  ]
 ---
 # Update the source file and check for completions again.
 {"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"test:///main.cpp","version":2},"contentChanges":[{"text":"struct S { int b; };\nint main() {\nS().\n}"}]}}
@@ -38,7 +38,7 @@
 # CHECK-NEXT:  "kind": 5,
 # CHECK-NEXT:  "label": "b",
 # CHECK-NEXT:  "sortText": "{{.*}}b"
-# CHECK-NEXT:},
-#  CHECK:  ]
+# CHECK-NEXT:}
+# CHECK-NEXT:  ]
 ---
 {"jsonrpc":"2.0","id":4,"method":"shutdown"}
Index: clang-tools-extra/trunk/test/clangd/protocol.test
===
--- clang-tools-extra/trunk/test/clangd/protocol.test
+++ clang-tools-extra/trunk/test/clangd/protocol.test
@@ -34,11 +34,11 @@
 # CHECK-NEXT:  "result": {
 # CHECK-NEXT:"isIncomplete": false,
 # CHECK-NEXT:"items": [
-#  CHECK:"filterText": "fake",
-# CHECK-NEXT:"insertText": "fake",
+#  CHECK:"filterText": "a",
+# CHECK-NEXT:"insertText": "a",
 # CHECK-NEXT:"insertTextFormat": 1,
-# CHECK-NEXT:"kind": 7,
-# CHECK-NEXT:"label": "fake",
+# CHECK-NEXT:"kind": 5,
+# CHECK-NEXT:"label": "a",
 # CHECK-NEXT:"sortText": "{{.*}}"
 #  CHECK:]
 # CHECK-NEXT:  }
@@ -63,11 +63,11 @@
 # CHECK-NEXT:  "result": {
 # CHECK-NEXT:"isIncomplete": false,
 # CHECK-NEXT:"items": [
-#  CHECK:"filterText": "fake",
-# CHECK-NEXT:"insertText": "fake",
+#  CHECK:"filterText": "a",
+# CHECK-NEXT:"insertText": "a",
 # CHECK-NEXT:"insertTextFormat": 1,
-# CHECK-NEXT:"kind": 7,
-# CHECK-NEXT:"label": "fake",
+# CHECK-NEXT:"kind": 5,
+# CHECK-NEXT:"label": "a",
 # CHECK-NEXT:"sortText": "{{.*}}"
 #  CHECK:]
 # CHECK-NEXT:  }
@@ -92,11 +92,11 @@
 # CHECK-NEXT:  "result": {
 # CHECK-NEXT:"isIncomplete": false,
 # CHECK-NEXT:"items": [
-#  CHECK:"filterText": "fake",
-# CHECK-NEXT:"insertText": "fake",
+#  CHECK:"filterText": "a",
+# CHECK-NEXT:"insertText": "a",
 # CHECK-NEXT:"insertTextFormat": 1,
-# CHECK-NEXT:"kind": 7,
-# CHECK-NEXT:"label": "fake",
+# CHECK-NEXT:"kind": 5,
+# CHECK-NEXT:"label": "a",
 # CHECK-NEXT:"sortText": "{{.*}}"
 #  CHECK:]
 # CHECK-NEXT:  }
Index: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
@@ -207,9 +207,6 @@
   EXPECT_THAT(completions(Body + "int main() { S().FR^ }").items,
   AllOf(Has("FooBar"), Not(Has("FooBaz")), Not(Has("Qux";
 
-  EXPECT_THAT(completions(Body + "int main() { S().opr^ }").items,
-  Has("operator="));
-
   EXPECT_THAT(completions(Body + "int main() { aaa^ }").items,
   AllOf(Has("Abracadabra"), Has("Alakazam")));
 
@@ -250,9 +247,10 @@
 
   // Class members. The only items that must be present in after-dot
   // completion.
-  EXPECT_THAT(
-  Results.items,
-  AllOf(Has(Opts.EnableSnippets ? "method()" : "method"), Has("field")));
+  EXPECT_THAT(Results.items,
+  AllOf(Has(Opts.EnableSnippets ? "method()" : "method"),
+Has("field"), Not(Has("ClassWithMembers")),
+Not(Has("operator=")), Not(Has("~ClassWithMembers";
   EXPECT_IFF(Opts.IncludeIneligibleResults, Results.items,
  Has("private_field"));
   // Global items.
@@ -379,6 +377,25 @@
   EXPECT_THAT(Results.items, Not(Contains(Labeled("foo() const"; // private
 }
 
+TEST(CompletionTest, InjectedTypename) {
+  // These are suppressed when accessed as a member

[clang-tools-extra] r334192 - [clangd] Code completion: drop explicit injected names/operators, ignore Sema priority

2018-06-07 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Jun  7 05:49:17 2018
New Revision: 334192

URL: http://llvm.org/viewvc/llvm-project?rev=334192&view=rev
Log:
[clangd] Code completion: drop explicit injected names/operators, ignore Sema 
priority

Summary:
Now we have most of Sema's code completion signals incorporated in Quality,
which will allow us to give consistent ranking to sema/index results.

Therefore we can/should stop using Sema priority as an explicit signal.
This fixes some issues like namespaces always having a terrible score.

The most important missing signals are:
 - Really dumb/rarely useful completions like:
SomeStruct().^SomeStruct
SomeStruct().^operator=
SomeStruct().~SomeStruct()
   We already filter out destructors, this patch adds injected names and
   operators to that list.
 - type matching the expression context.
   Ilya has a plan to add this in a way that's compatible with indexes
   (design doc should be shared real soon now!)

Reviewers: ioeric

Subscribers: ilya-biryukov, MaskRay, jkorous, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/clangd/Quality.cpp
clang-tools-extra/trunk/clangd/Quality.h
clang-tools-extra/trunk/test/clangd/completion.test
clang-tools-extra/trunk/test/clangd/protocol.test
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
clang-tools-extra/trunk/unittests/clangd/QualityTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=334192&r1=334191&r2=334192&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Thu Jun  7 05:49:17 2018
@@ -467,6 +467,25 @@ bool contextAllowsIndex(enum CodeComplet
   llvm_unreachable("unknown code completion context");
 }
 
+// Some member calls are blacklisted because they're so rarely useful.
+static bool isBlacklistedMember(const NamedDecl &D) {
+  // Destructor completion is rarely useful, and works inconsistently.
+  // (s.^ completes ~string, but s.~st^ is an error).
+  if (D.getKind() == Decl::CXXDestructor)
+return true;
+  // Injected name may be useful for A::foo(), but who writes A::A::foo()?
+  if (auto *R = dyn_cast_or_null(&D))
+if (R->isInjectedClassName())
+  return true;
+  // Explicit calls to operators are also rare.
+  auto NameKind = D.getDeclName().getNameKind();
+  if (NameKind == DeclarationName::CXXOperatorName ||
+  NameKind == DeclarationName::CXXLiteralOperatorName ||
+  NameKind == DeclarationName::CXXConversionFunctionName)
+return true;
+  return false;
+}
+
 // The CompletionRecorder captures Sema code-complete output, including 
context.
 // It filters out ignored results (but doesn't apply fuzzy-filtering yet).
 // It doesn't do scoring or conversion to CompletionItem yet, as we want to
@@ -520,9 +539,9 @@ struct CompletionRecorder : public CodeC
   (Result.Availability == CXAvailability_NotAvailable ||
Result.Availability == CXAvailability_NotAccessible))
 continue;
-  // Destructor completion is rarely useful, and works inconsistently.
-  // (s.^ completes ~string, but s.~st^ is an error).
-  if (dyn_cast_or_null(Result.Declaration))
+  if (Result.Declaration &&
+  !Context.getBaseType().isNull() // is this a member-access context?
+  && isBlacklistedMember(*Result.Declaration))
 continue;
   // We choose to never append '::' to completion results in clangd.
   Result.StartsNestedNameSpecifier = false;

Modified: clang-tools-extra/trunk/clangd/Quality.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Quality.cpp?rev=334192&r1=334191&r2=334192&view=diff
==
--- clang-tools-extra/trunk/clangd/Quality.cpp (original)
+++ clang-tools-extra/trunk/clangd/Quality.cpp Thu Jun  7 05:49:17 2018
@@ -94,7 +94,6 @@ categorize(const index::SymbolInfo &D) {
 }
 
 void SymbolQualitySignals::merge(const CodeCompletionResult &SemaCCResult) {
-  SemaCCPriority = SemaCCResult.Priority;
   if (SemaCCResult.Availability == CXAvailability_Deprecated)
 Deprecated = true;
 
@@ -117,11 +116,6 @@ float SymbolQualitySignals::evaluate() c
   if (References >= 3)
 Score *= std::log(References);
 
-  if (SemaCCPriority)
-// Map onto a 0-2 interval, so we don't reward/penalize non-Sema results.
-// Priority 80 is a really bad score.
-Score *= 2 - std::min(80, SemaCCPriority) / 40;
-
   if (Deprecated)
 Score *= 0.1f;
 
@@ -146,8 +140,6 @@ float SymbolQualitySignals::evaluate() c
 
 raw_ostream &operator<<(raw_ostream &OS, const SymbolQualitySignals &S) {
   OS << formatv("=== Symbol quality: {0}\n", S.evaluate());
-  if

[PATCH] D46757: [clang-format] Break inside submessages containing a submessage and something else

2018-06-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 150317.
krasimir added a comment.

- Update comments


Repository:
  rC Clang

https://reviews.llvm.org/D46757

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

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -171,17 +171,48 @@
   verifyFormat("msg_field < field_a < field_b <> > >");
   verifyFormat("msg_field: < field_a < field_b: <> > >");
   verifyFormat("msg_field < field_a: OK, field_b: \"OK\" >");
-  verifyFormat("msg_field < field_a: OK field_b: <>, field_c: OK >");
-  verifyFormat("msg_field < field_a { field_b: 1 }, field_c: < f_d: 2 > >");
   verifyFormat("msg_field: < field_a: OK, field_b: \"OK\" >");
-  verifyFormat("msg_field: < field_a: OK field_b: <>, field_c: OK >");
-  verifyFormat("msg_field: < field_a { field_b: 1 }, field_c: < fd_d: 2 > >");
-  verifyFormat("field_a: \"OK\", msg_field: < field_b: 123 >, field_c: {}");
-  verifyFormat("field_a < field_b: 1 >, msg_fid: < fiel_b: 123 >, field_c <>");
-  verifyFormat("field_a < field_b: 1 > msg_fied: < field_b: 123 > field_c <>");
-  verifyFormat("field < field < field: <> >, field <> > field: < field: 1 >");
-
   // Multiple lines tests
+  verifyFormat("msg_field <\n"
+   "  field_a: OK\n"
+   "  field_b: <>,\n"
+   "  field_c: OK\n"
+   ">");
+
+  verifyFormat("msg_field <\n"
+   "  field_a { field_b: 1 },\n"
+   "  field_c: < f_d: 2 >\n"
+   ">");
+
+  verifyFormat("msg_field: <\n"
+   "  field_a: OK\n"
+   "  field_b: <>,\n"
+   "  field_c: OK\n"
+   ">");
+
+  verifyFormat("msg_field: <\n"
+   "  field_a { field_b: 1 },\n"
+   "  field_c: < fd_d: 2 >\n"
+   ">");
+
+  verifyFormat("field_a: \"OK\",\n"
+   "msg_field: < field_b: 123 >,\n"
+   "field_c: {}");
+
+  verifyFormat("field_a < field_b: 1 >,\n"
+   "msg_fid: < fiel_b: 123 >,\n" 
+   "field_c <>");
+
+  verifyFormat("field_a < field_b: 1 >\n"
+   "msg_fied: < field_b: 123 >\n"
+   "field_c <>");
+
+  verifyFormat("field <\n"
+   "  field < field: <> >,\n"
+   "  field <>\n"
+   ">\n"
+   "field: < field: 1 >");
+
   verifyFormat("msg_field <\n"
"  field_a: OK\n"
"  field_b: \"OK\"\n"
@@ -242,7 +273,10 @@
"  field_d: ok\n"
"}");
 
-  verifyFormat("field_a: < f1: 1, f2: <> >\n"
+  verifyFormat("field_a: <\n"
+   "  f1: 1,\n"
+   "  f2: <>\n"
+   ">\n"
"field_b <\n"
"  field_b1: <>\n"
"  field_b2: ok,\n"
@@ -507,5 +541,107 @@
">");
 }
 
+TEST_F(FormatTestTextProto, BreaksEntriesOfSubmessagesContainingSubmessages) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60;
+  // The column limit allows for the keys submessage to be put on 1 line, but we
+  // break it since it contains a submessage an another entry.
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: ''\n"
+   "  sub <>\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: ''\n"
+   "  sub {}\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  sub {}\n"
+   "  sub: <>\n"
+   "  sub: []\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub { msg: 1 }\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub: { msg: 1 }\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub < msg: 1 >\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub: [ msg: 1 ]\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: <\n"
+   "  item: 'aaa'\n"
+   "  sub: [ 1, 2 ]\n"
+   ">");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  sub {}\n"
+   "  item: ''\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  sub: []\n"
+   

[PATCH] D46757: [clang-format] Break inside submessages containing a submessage and something else

2018-06-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 150320.
krasimir added a comment.

- Add comments tests


Repository:
  rC Clang

https://reviews.llvm.org/D46757

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

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -171,17 +171,48 @@
   verifyFormat("msg_field < field_a < field_b <> > >");
   verifyFormat("msg_field: < field_a < field_b: <> > >");
   verifyFormat("msg_field < field_a: OK, field_b: \"OK\" >");
-  verifyFormat("msg_field < field_a: OK field_b: <>, field_c: OK >");
-  verifyFormat("msg_field < field_a { field_b: 1 }, field_c: < f_d: 2 > >");
   verifyFormat("msg_field: < field_a: OK, field_b: \"OK\" >");
-  verifyFormat("msg_field: < field_a: OK field_b: <>, field_c: OK >");
-  verifyFormat("msg_field: < field_a { field_b: 1 }, field_c: < fd_d: 2 > >");
-  verifyFormat("field_a: \"OK\", msg_field: < field_b: 123 >, field_c: {}");
-  verifyFormat("field_a < field_b: 1 >, msg_fid: < fiel_b: 123 >, field_c <>");
-  verifyFormat("field_a < field_b: 1 > msg_fied: < field_b: 123 > field_c <>");
-  verifyFormat("field < field < field: <> >, field <> > field: < field: 1 >");
-
   // Multiple lines tests
+  verifyFormat("msg_field <\n"
+   "  field_a: OK\n"
+   "  field_b: <>,\n"
+   "  field_c: OK\n"
+   ">");
+
+  verifyFormat("msg_field <\n"
+   "  field_a { field_b: 1 },\n"
+   "  field_c: < f_d: 2 >\n"
+   ">");
+
+  verifyFormat("msg_field: <\n"
+   "  field_a: OK\n"
+   "  field_b: <>,\n"
+   "  field_c: OK\n"
+   ">");
+
+  verifyFormat("msg_field: <\n"
+   "  field_a { field_b: 1 },\n"
+   "  field_c: < fd_d: 2 >\n"
+   ">");
+
+  verifyFormat("field_a: \"OK\",\n"
+   "msg_field: < field_b: 123 >,\n"
+   "field_c: {}");
+
+  verifyFormat("field_a < field_b: 1 >,\n"
+   "msg_fid: < fiel_b: 123 >,\n" 
+   "field_c <>");
+
+  verifyFormat("field_a < field_b: 1 >\n"
+   "msg_fied: < field_b: 123 >\n"
+   "field_c <>");
+
+  verifyFormat("field <\n"
+   "  field < field: <> >,\n"
+   "  field <>\n"
+   ">\n"
+   "field: < field: 1 >");
+
   verifyFormat("msg_field <\n"
"  field_a: OK\n"
"  field_b: \"OK\"\n"
@@ -242,7 +273,10 @@
"  field_d: ok\n"
"}");
 
-  verifyFormat("field_a: < f1: 1, f2: <> >\n"
+  verifyFormat("field_a: <\n"
+   "  f1: 1,\n"
+   "  f2: <>\n"
+   ">\n"
"field_b <\n"
"  field_b1: <>\n"
"  field_b2: ok,\n"
@@ -507,5 +541,112 @@
">");
 }
 
+TEST_F(FormatTestTextProto, BreaksEntriesOfSubmessagesContainingSubmessages) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60;
+  // The column limit allows for the keys submessage to be put on 1 line, but we
+  // break it since it contains a submessage an another entry.
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: ''\n"
+   "  sub <>\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: ''\n"
+   "  sub {}\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  sub {}\n"
+   "  sub: <>\n"
+   "  sub: []\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub { msg: 1 }\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub: { msg: 1 }\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub < msg: 1 >\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub: [ msg: 1 ]\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: <\n"
+   "  item: 'aaa'\n"
+   "  sub: [ 1, 2 ]\n"
+   ">");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  sub {}\n"
+   "  item: ''\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  sub: []\n"
+

[PATCH] D47290: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %zu/%zi on Darwin

2018-06-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D47290#1124866, @hans wrote:

> If we really want to special-case NSInteger, and given that you're targeting 
> a specific wide-spread pattern maybe that's the right thing to do, I think we 
> should make -Wformat accept (move the warning behind -Wformat-pedantic I 
> suppose) printing NSInteger with *any* integral type of the right size, not 
> just size_t.


Would you be similarly okay with %ld and %d on Windows platforms when mixing up 
int and long?


Repository:
  rC Clang

https://reviews.llvm.org/D47290



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


[PATCH] D47864: [python] Fix most Python binding unittests on Windows

2018-06-07 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

I don't know much about the python bindings, but this is probably fine.


Repository:
  rC Clang

https://reviews.llvm.org/D47864



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


[PATCH] D47290: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %zu/%zi on Darwin

2018-06-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In https://reviews.llvm.org/D47290#1124933, @aaron.ballman wrote:

> In https://reviews.llvm.org/D47290#1124866, @hans wrote:
>
> > If we really want to special-case NSInteger, and given that you're 
> > targeting a specific wide-spread pattern maybe that's the right thing to 
> > do, I think we should make -Wformat accept (move the warning behind 
> > -Wformat-pedantic I suppose) printing NSInteger with *any* integral type of 
> > the right size, not just size_t.
>
>
> Would you be similarly okay with %ld and %d on Windows platforms when mixing 
> up int and long?


No, I'm against a general relaxation of -Wformat, but to solve JF's problem I 
think special-casing NSInteger might be reasonable.


Repository:
  rC Clang

https://reviews.llvm.org/D47290



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


[PATCH] D47290: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %zu/%zi on Darwin

2018-06-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D47290#1124956, @hans wrote:

> In https://reviews.llvm.org/D47290#1124933, @aaron.ballman wrote:
>
> > In https://reviews.llvm.org/D47290#1124866, @hans wrote:
> >
> > > If we really want to special-case NSInteger, and given that you're 
> > > targeting a specific wide-spread pattern maybe that's the right thing to 
> > > do, I think we should make -Wformat accept (move the warning behind 
> > > -Wformat-pedantic I suppose) printing NSInteger with *any* integral type 
> > > of the right size, not just size_t.
> >
> >
> > Would you be similarly okay with %ld and %d on Windows platforms when 
> > mixing up int and long?
>
>
> No, I'm against a general relaxation of -Wformat, but to solve JF's problem I 
> think special-casing NSInteger might be reasonable.


How is JF's problem different?


Repository:
  rC Clang

https://reviews.llvm.org/D47290



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


Re: [PATCH] D47875: [MS ABI] Mangle unnamed empty enums (PR37723)

2018-06-07 Thread Richard Smith via cfe-commits
On Thu, 7 Jun 2018, 13:54 Hans Wennborg via Phabricator via cfe-commits, <
cfe-commits@lists.llvm.org> wrote:

> hans added a comment.
>
> Please take a look.
>
> I couldn't figure out a way to get a mangled name for this without using
> debug info. Do you have any ideas?
>

struct S { enum {} e; };

... then do something with decltype(S::e). What happens if there are two
such types in the class?

https://reviews.llvm.org/D47875
>
>
>
> ___
> 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] D47290: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %zu/%zi on Darwin

2018-06-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In https://reviews.llvm.org/D47290#1124964, @aaron.ballman wrote:

> In https://reviews.llvm.org/D47290#1124956, @hans wrote:
>
> > In https://reviews.llvm.org/D47290#1124933, @aaron.ballman wrote:
> >
> > > In https://reviews.llvm.org/D47290#1124866, @hans wrote:
> > >
> > > > If we really want to special-case NSInteger, and given that you're 
> > > > targeting a specific wide-spread pattern maybe that's the right thing 
> > > > to do, I think we should make -Wformat accept (move the warning behind 
> > > > -Wformat-pedantic I suppose) printing NSInteger with *any* integral 
> > > > type of the right size, not just size_t.
> > >
> > >
> > > Would you be similarly okay with %ld and %d on Windows platforms when 
> > > mixing up int and long?
> >
> >
> > No, I'm against a general relaxation of -Wformat, but to solve JF's problem 
> > I think special-casing NSInteger might be reasonable.
>
>
> How is JF's problem different?


It concerns a vendor-specific type. Of course I personally think it would be 
better if the code could be fixed, but it doesn't sound like that's an option 
so then I think special-casing for NSInteger is an acceptable solution.


Repository:
  rC Clang

https://reviews.llvm.org/D47290



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


[PATCH] D47849: [OpenMP][Clang][NVPTX] Enable math functions called in an OpenMP NVPTX target device region to be resolved as device-native function calls

2018-06-07 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added inline comments.



Comment at: lib/Headers/__clang_cuda_device_functions.h:65
 }
+#if defined(__cplusplus)
 __DEVICE__ void __brkpt() { asm volatile("brkpt;"); }

Hahnfeld wrote:
> Why is that only valid for C++?
C does not support overloading of functions.


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D47704: [clang-tidy] Improve string type matcher for abseil-string-find-starts-with check.

2018-06-07 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47704



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


[PATCH] D47849: [OpenMP][Clang][NVPTX] Enable math functions called in an OpenMP NVPTX target device region to be resolved as device-native function calls

2018-06-07 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added a comment.

In https://reviews.llvm.org/D47849#1124638, @Hahnfeld wrote:

> IMO this goes into the right direction, we should use the fast implementation 
> in libdevice. If LLVM doesn't lower these calls in the NVPTX backend, I think 
> it's ok to use header wrappers as CUDA already does.
>
> Two questions:
>
> 1. Can you explain where this is important for "correctness"? Yesterday I 
> compiled a code using `sqrt` and it seems to spit out the correct results. 
> Maybe that's relevant for other functions?
> 2. Incidentally I ran into a closely related problem: I can't `#include 
> ` in translation units compiled for offloading, Clang complains about 
> inline assembly for x86 (see below). Does that work for you?
>
>   ``` In file included from /usr/include/math.h:413: 
> /usr/include/bits/mathinline.h:131:43: error: invalid input constraint 'x' in 
> asm __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x)); ^ 
> /usr/include/bits/mathinline.h:143:43: error: invalid input constraint 'x' in 
> asm __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x)); ^ 2 errors generated. 
> ```


It's precisely the issue which you report here. Since you don't use device 
specific math functions, you can run into the problem where you may end up 
calling assembly instructions for a different architecture. I may have 
mis-classified this as a correctness issue.


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D47577: [clang-format] Separate block comments with CRLF correctly

2018-06-07 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a reviewer: djasper.
alexfh added inline comments.



Comment at: lib/Format/BreakableToken.cpp:327
+  TokenText.substr(2, TokenText.size() - 4)
+  .split(Lines, TokenText.count('\r') > 0 ? "\r\n" : "\n");
 

FYI, there's a global UseCRLF flag in WhitespaceManager. It may make sense to 
use it everywhere instead of deciding for each comment. But I'll let actual 
clang-format maintainers decide on pros and cons of this.


Repository:
  rC Clang

https://reviews.llvm.org/D47577



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


[PATCH] D47290: [Sema] -Wformat-pedantic only for NSInteger/NSUInteger %zu/%zi on Darwin

2018-06-07 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D47290#1124991, @hans wrote:

> In https://reviews.llvm.org/D47290#1124964, @aaron.ballman wrote:
>
> > In https://reviews.llvm.org/D47290#1124956, @hans wrote:
> >
> > > In https://reviews.llvm.org/D47290#1124933, @aaron.ballman wrote:
> > >
> > > > In https://reviews.llvm.org/D47290#1124866, @hans wrote:
> > > >
> > > > > If we really want to special-case NSInteger, and given that you're 
> > > > > targeting a specific wide-spread pattern maybe that's the right thing 
> > > > > to do, I think we should make -Wformat accept (move the warning 
> > > > > behind -Wformat-pedantic I suppose) printing NSInteger with *any* 
> > > > > integral type of the right size, not just size_t.
> > > >
> > > >
> > > > Would you be similarly okay with %ld and %d on Windows platforms when 
> > > > mixing up int and long?
> > >
> > >
> > > No, I'm against a general relaxation of -Wformat, but to solve JF's 
> > > problem I think special-casing NSInteger might be reasonable.
> >
> >
> > How is JF's problem different?
>
>
> It concerns a vendor-specific type. Of course I personally think it would be 
> better if the code could be fixed, but it doesn't sound like that's an option 
> so then I think special-casing for NSInteger is an acceptable solution.


Okay, that's fair, but the vendor-specific type for my Windows example is 
spelled `DWORD`. I'm really worried that this special case will become a 
precedent and we'll wind up with -Wformat being relaxed for everything based on 
the same rationale. If that's how the community wants -Wformat to work, cool, 
but I'd like to know if we're intending to change (what I see as) the design of 
this warning.


Repository:
  rC Clang

https://reviews.llvm.org/D47290



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


[PATCH] D47849: [OpenMP][Clang][NVPTX] Enable math functions called in an OpenMP NVPTX target device region to be resolved as device-native function calls

2018-06-07 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In https://reviews.llvm.org/D47849#1125019, @gtbercea wrote:

> It's precisely the issue which you report here. Since you don't use device 
> specific math functions, you can run into the problem where you may end up 
> calling assembly instructions for a different architecture. I may have 
> mis-classified this as a correctness issue.


I think the issue is slightly different, the assembly is not necessarily in the 
called functions, as I said `sqrt` seems to work fine. Clang just errors 
because they are included via the header.

This is because `clang::InitializePreprocessor` has this:

  // FIXME: This will create multiple definitions for most of the predefined
  // macros. This is not the right way to handle this.
  if ((LangOpts.CUDA || LangOpts.OpenMPIsDevice) && PP.getAuxTargetInfo())
InitializePredefinedMacros(*PP.getAuxTargetInfo(), LangOpts, FEOpts,
   Builder);

So we will end up with all host defines (including `__SSE2_MATH__` as @hfinkel 
wrote) during target compilation :-(


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


[PATCH] D47875: [MS ABI] Mangle unnamed empty enums (PR37723)

2018-06-07 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: lib/AST/MicrosoftMangle.cpp:888-891
 auto EnumeratorI = ED->enumerator_begin();
-assert(EnumeratorI != ED->enumerator_end());
-Name += "getName();
+if (EnumeratorI == ED->enumerator_end()) {
+  Name += " and .


https://reviews.llvm.org/D47875



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


Re: [PATCH] D47875: [MS ABI] Mangle unnamed empty enums (PR37723)

2018-06-07 Thread Hans Wennborg via cfe-commits
On Thu, Jun 7, 2018 at 4:05 PM, Richard Smith via cfe-commits
 wrote:
>
> struct S { enum {} e; };
>
> ... then do something with decltype(S::e). What happens if there are two
> such types in the class?

The bug doesn't reproduce if the enumeration has a name, which is why
it's hard to reference :-)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46911: [Fixed Point Arithmetic] Addition of the remaining fixed point types and their saturated equivalents

2018-06-07 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added inline comments.



Comment at: include/clang/Sema/DeclSpec.h:670
const PrintingPolicy &Policy);
+  bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec,
+  unsigned &DiagID);

ebevhan wrote:
> This should take a PrintingPolicy like the others.
I think the PrintingPolicy may not be necessary because it's only used for 
getting the name of the current TypeSpecType. More specifically, for just 
differentiating vetween "bool" and "_Bool" for `TST_bool`. It also seems that 
other setters that don't touch TypeSpecType use PrintingPolicy, like 
`SetTypeSpecComplex` or `SetTypeSpecSign`



Comment at: lib/Sema/SemaType.cpp:1612
+  // Only fixed point types can be saturated
+  if (DS.isTypeSpecSat() && !IsFixedPointType)
+S.Diag(DS.getTypeSpecSatLoc(), diag::err_invalid_saturation_spec)

ebevhan wrote:
> Also, this does not seem to invalidate the declarator.
How so? I have tests under `test/Frontend/fixed_point_errors.c` that check for 
an error thrown if `_Sat` is used with non-fixed point types.


Repository:
  rC Clang

https://reviews.llvm.org/D46911



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


[PATCH] D47875: [MS ABI] Mangle unnamed empty enums (PR37723)

2018-06-07 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Thanks!




Comment at: lib/AST/MicrosoftMangle.cpp:888-891
 auto EnumeratorI = ED->enumerator_begin();
-assert(EnumeratorI != ED->enumerator_end());
-Name += "getName();
+if (EnumeratorI == ED->enumerator_end()) {
+  Name += " Thinking about it some more, it'd be better if we handled this like the else 
> case:
>   Name += "   Name += llvm::utostr(Context.getAnonymousStructId(TD) + 1);
> 
> Reason being that something like:
>   struct S {
> enum {};
> enum {};
>   };
> 
> Would otherwise end up with two identical mangles.
> 
> This would also make us more consistent with other mangles, for example:
>   enum {} x;
>   struct {} y;
> 
> These are mangled as:  and .
Okay, yeah that makes sense.

I just checked

struct S {
  enum {};
  enum {};
};

with MSVC, and they seem to give them identical mangling.

I have to head out, but will update the patch tomorrow morning unless you're 
keen to do it :-)


https://reviews.llvm.org/D47875



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


[PATCH] D46190: For a referenced declaration, mark any associated usings as referenced.

2018-06-07 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

@rsmith anything else needed here?


https://reviews.llvm.org/D46190



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


[PATCH] D47135: [analyzer] A checker for dangling internal buffer pointers in C++

2018-06-07 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Ping


https://reviews.llvm.org/D47135



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


[PATCH] D46911: [Fixed Point Arithmetic] Addition of the remaining fixed point types and their saturated equivalents

2018-06-07 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: include/clang/Sema/DeclSpec.h:670
const PrintingPolicy &Policy);
+  bool SetTypeSpecSat(SourceLocation Loc, const char *&PrevSpec,
+  unsigned &DiagID);

leonardchan wrote:
> ebevhan wrote:
> > This should take a PrintingPolicy like the others.
> I think the PrintingPolicy may not be necessary because it's only used for 
> getting the name of the current TypeSpecType. More specifically, for just 
> differentiating vetween "bool" and "_Bool" for `TST_bool`. It also seems that 
> other setters that don't touch TypeSpecType use PrintingPolicy, like 
> `SetTypeSpecComplex` or `SetTypeSpecSign`
You are correct, the ones that don't need it don't take it. I'm just being 
selfish since I need it downstream to disambiguate `__sat` and `_Sat`.

It's fine the way it is.



Comment at: lib/Sema/SemaType.cpp:1612
+  // Only fixed point types can be saturated
+  if (DS.isTypeSpecSat() && !IsFixedPointType)
+S.Diag(DS.getTypeSpecSatLoc(), diag::err_invalid_saturation_spec)

leonardchan wrote:
> ebevhan wrote:
> > Also, this does not seem to invalidate the declarator.
> How so? I have tests under `test/Frontend/fixed_point_errors.c` that check 
> for an error thrown if `_Sat` is used with non-fixed point types.
Hm, that is true. We don't have it downstream either. I'm not sure what the 
purpose of doing it is, but other invalid specifiers do 
`declarator.setInvalidType(true);`

I guess it isn't needed, just curious as to why it's done for some other ones.


Repository:
  rC Clang

https://reviews.llvm.org/D46911



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


[PATCH] D47886: Move VersionTuple from clang/Basic to llvm/Support, clang part

2018-06-07 Thread Pavel Labath via Phabricator via cfe-commits
labath created this revision.
labath added reviewers: erik.pilkington, zturner.
Herald added a subscriber: mgorny.

This kind of functionality is useful to other project apart from clang.
LLDB works with version numbers a lot, but it does not have a convenient
abstraction for this. Moving this class to a lower level library allows
it to be freely used within LLDB.

Since this class is used in a lot of places, and it used to be in the
clang namespace, it seemed appropriate to add it to the list of adopted
classes in LLVM.h to avoid prefixing all uses with "llvm::".


Repository:
  rC Clang

https://reviews.llvm.org/D47886

Files:
  include/clang/AST/Attr.h
  include/clang/AST/Availability.h
  include/clang/AST/DeclBase.h
  include/clang/AST/ExprObjC.h
  include/clang/Basic/AlignedAllocation.h
  include/clang/Basic/LLVM.h
  include/clang/Basic/ObjCRuntime.h
  include/clang/Basic/TargetInfo.h
  include/clang/Basic/VersionTuple.h
  include/clang/Driver/ToolChain.h
  include/clang/Parse/Parser.h
  include/clang/Sema/AttributeList.h
  include/clang/Serialization/ASTReader.h
  include/clang/Serialization/ASTWriter.h
  lib/AST/DeclBase.cpp
  lib/Basic/CMakeLists.txt
  lib/Basic/ObjCRuntime.cpp
  lib/Basic/VersionTuple.cpp
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/Cuda.h
  lib/Frontend/CompilerInvocation.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp

Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -53,7 +53,6 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Basic/Version.h"
-#include "clang/Basic/VersionTuple.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Lex/MacroInfo.h"
@@ -97,6 +96,7 @@
 #include "llvm/Support/OnDiskHashTable.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SHA1.h"
+#include "llvm/Support/VersionTuple.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -61,7 +61,6 @@
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Basic/Version.h"
-#include "clang/Basic/VersionTuple.h"
 #include "clang/Frontend/PCHContainerOperations.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
@@ -104,8 +103,8 @@
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/Bitcode/BitstreamReader.h"
 #include "llvm/Support/Casting.h"
-#include "llvm/Support/Compression.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/Compression.h"
 #include "llvm/Support/DJB.h"
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Error.h"
@@ -115,6 +114,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/Timer.h"
+#include "llvm/Support/VersionTuple.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -23,7 +23,6 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/TargetOptions.h"
 #include "clang/Basic/Version.h"
-#include "clang/Basic/VersionTuple.h"
 #include "clang/Basic/VirtualFileSystem.h"
 #include "clang/Basic/Visibility.h"
 #include "clang/Basic/XRayInstr.h"
@@ -76,6 +75,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Regex.h"
+#include "llvm/Support/VersionTuple.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetOptions.h"
 #include 
Index: lib/Driver/ToolChains/Cuda.h
===
--- lib/Driver/ToolChains/Cuda.h
+++ lib/Driver/ToolChains/Cuda.h
@@ -11,14 +11,14 @@
 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CUDA_H
 
 #include "clang/Basic/Cuda.h"
-#include "clang/Basic/VersionTuple.h"
 #include "clang/Driver/Action.h"
 #include "clang/Driver/Multilib.h"
-#include "clang/Driver/ToolChain.h"
 #include "clang/Driver/Tool.h"
+#include "clang/Driver/ToolChain.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/VersionTuple.h"
 #include 
 #include 
 
Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -13,7 +13,6 @@
 #include "ToolChains/Clang.h"
 #include "clang/Basic/ObjCRuntime.h"
 #include "clang/Basic/Sanitizers.h"
-#include "clang/Basic/VersionTuple.h"
 #include "clang/Basic/VirtualFileSystem.h"
 #include "clang/Config/config.h"
 #include "clang/Driver/Action.h"
@@ -29,16 +28,17 @@
 #include "llvm/ADT/Trip

[PATCH] D47887: Move VersionTuple from clang/Basic to llvm/Support, llvm part

2018-06-07 Thread Pavel Labath via Phabricator via cfe-commits
labath created this revision.
labath added reviewers: zturner, erik.pilkington.
Herald added a subscriber: mgorny.

This kind of functionality is useful to other project apart from clang.
LLDB works with version numbers a lot, but it does not have a convenient
abstraction for this. Moving this class to a lower level library allows
it to be freely used within LLDB.

The code is an identical copy of the version from clang (apart from
namespace change and re-clang-formatting).

I didn't find any tests specific for this class, so I wrote a couple of
quick ones for the more interesting bits of functionality.


Repository:
  rL LLVM

https://reviews.llvm.org/D47887

Files:
  include/llvm/Support/VersionTuple.h
  lib/Support/CMakeLists.txt
  lib/Support/VersionTuple.cpp
  unittests/Support/CMakeLists.txt
  unittests/Support/VersionTupleTest.cpp

Index: unittests/Support/VersionTupleTest.cpp
===
--- /dev/null
+++ unittests/Support/VersionTupleTest.cpp
@@ -0,0 +1,50 @@
+//===- VersionTupleTests.cpp - Version Number Handling Tests --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "llvm/Support/VersionTuple.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+TEST(VersionTuple, getAsString) {
+  EXPECT_EQ("0", VersionTuple().getAsString());
+  EXPECT_EQ("1", VersionTuple(1).getAsString());
+  EXPECT_EQ("1.2", VersionTuple(1, 2).getAsString());
+  EXPECT_EQ("1.2.3", VersionTuple(1, 2, 3).getAsString());
+  EXPECT_EQ("1.2.3.4", VersionTuple(1, 2, 3, 4).getAsString());
+}
+
+TEST(VersionTuple, tryParse) {
+  VersionTuple VT;
+
+  EXPECT_FALSE(VT.tryParse("1"));
+  EXPECT_EQ("1", VT.getAsString());
+
+  EXPECT_FALSE(VT.tryParse("1.2"));
+  EXPECT_EQ("1.2", VT.getAsString());
+
+  EXPECT_FALSE(VT.tryParse("1.2.3"));
+  EXPECT_EQ("1.2.3", VT.getAsString());
+
+  EXPECT_FALSE(VT.tryParse("1.2.3.4"));
+  EXPECT_EQ("1.2.3.4", VT.getAsString());
+
+  EXPECT_TRUE(VT.tryParse(""));
+  EXPECT_TRUE(VT.tryParse("1."));
+  EXPECT_TRUE(VT.tryParse("1.2."));
+  EXPECT_TRUE(VT.tryParse("1.2.3."));
+  EXPECT_TRUE(VT.tryParse("1.2.3.4."));
+  EXPECT_TRUE(VT.tryParse("1.2.3.4.5"));
+  EXPECT_TRUE(VT.tryParse("1-2"));
+  EXPECT_TRUE(VT.tryParse("1+2"));
+  EXPECT_TRUE(VT.tryParse(".1"));
+  EXPECT_TRUE(VT.tryParse(" 1"));
+  EXPECT_TRUE(VT.tryParse("1 "));
+  EXPECT_TRUE(VT.tryParse("."));
+}
Index: unittests/Support/CMakeLists.txt
===
--- unittests/Support/CMakeLists.txt
+++ unittests/Support/CMakeLists.txt
@@ -61,6 +61,7 @@
   TrailingObjectsTest.cpp
   TrigramIndexTest.cpp
   UnicodeTest.cpp
+  VersionTupleTest.cpp
   YAMLIOTest.cpp
   YAMLParserTest.cpp
   formatted_raw_ostream_test.cpp
Index: lib/Support/VersionTuple.cpp
===
--- /dev/null
+++ lib/Support/VersionTuple.cpp
@@ -0,0 +1,110 @@
+//===- VersionTuple.cpp - Version Number Handling ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file implements the VersionTuple class, which represents a version in
+// the form major[.minor[.subminor]].
+//
+//===--===//
+#include "llvm/Support/VersionTuple.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm;
+
+std::string VersionTuple::getAsString() const {
+  std::string Result;
+  {
+llvm::raw_string_ostream Out(Result);
+Out << *this;
+  }
+  return Result;
+}
+
+raw_ostream &llvm::operator<<(raw_ostream &Out, const VersionTuple &V) {
+  Out << V.getMajor();
+  if (Optional Minor = V.getMinor())
+Out << '.' << *Minor;
+  if (Optional Subminor = V.getSubminor())
+Out << '.' << *Subminor;
+  if (Optional Build = V.getBuild())
+Out << '.' << *Build;
+  return Out;
+}
+
+static bool parseInt(StringRef &input, unsigned &value) {
+  assert(value == 0);
+  if (input.empty())
+return true;
+
+  char next = input[0];
+  input = input.substr(1);
+  if (next < '0' || next > '9')
+return true;
+  value = (unsigned)(next - '0');
+
+  while (!input.empty()) {
+next = input[0];
+if (next < '0' || next > '9')
+  return false;
+input = input.substr(1);
+value = value * 10 + (unsigned)(next - '0');
+  }
+
+  return false;
+}
+
+bool VersionTuple::tryParse(StringRef input) {
+  unsigned major = 0, minor = 0, micro = 0, build = 0;
+
+  // Parse the major version, [0-9]+
+  if (parseInt(input, major))
+return true;
+
+  if (input.empty

[PATCH] D47887: Move VersionTuple from clang/Basic to llvm/Support, llvm part

2018-06-07 Thread Zachary Turner via Phabricator via cfe-commits
zturner added a comment.

It would be better if you're using a monorepo, that way both parts can just be 
one single patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D47887



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


[PATCH] D47887: Move VersionTuple from clang/Basic to llvm/Support, llvm part

2018-06-07 Thread Pavel Labath via Phabricator via cfe-commits
labath added a comment.

Yea, one day I'll have to try that out. I'm just putting it off cause it would 
nuke all my branches and build folders :/

FWIW, the llvm part can actually be committed without breaking clang or anyone.


Repository:
  rL LLVM

https://reviews.llvm.org/D47887



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


[PATCH] D47630: [Sema] Allow creating types with multiple of the same addrspace.

2018-06-07 Thread Alexey Bader via Phabricator via cfe-commits
bader added inline comments.



Comment at: test/Sema/address_spaces.c:17
   int *_AS1 _AS2 *Z;  // expected-error {{multiple address spaces specified 
for type}}
+  int *_AS1 _AS1 *M;
 

ebevhan wrote:
> Anastasia wrote:
> > ebevhan wrote:
> > > bader wrote:
> > > > I think it might be valuable to give a warning or remark to user. 
> > > > Using the same address space qualifier multiple times is not something 
> > > > OpenCL C developers are supposed to do.
> > > > 
> > > The test is obviously a bit contrived, but it could happen by mistake, or 
> > > as a result of some typedef or macro combination. It also cannot go 
> > > wrong, so there's no harm in it happening.
> > > 
> > > I see your point, though. A warning feels like a bit much, so I'm not 
> > > sure what else to use. A note?
> > Just checked for const qualifier we get a warning:
> >   warning: duplicate 'const' declaration specifier 
> > [-Wduplicate-decl-specifier]
> > 
> > We could do the same... not sure if we could try to share the diagnostic as 
> > well.
> I have a patch ready that adds a warning in the same warning group and uses 
> that. I'm not sure about reusing the other one since address spaces don't 
> have to be declaration specifiers.
> 
> The warning is 'multiple identical address spaces specified for type', 
> similar to the error. Is that acceptable?
Sounds good to me. Could you share your patch, please?


Repository:
  rC Clang

https://reviews.llvm.org/D47630



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


[PATCH] D47097: [DebugInfo] Preserve scope in auto generated StoreInst

2018-06-07 Thread Anastasis via Phabricator via cfe-commits
gramanas updated this revision to Diff 150357.
gramanas added a comment.

Make more elaborate comment.


Repository:
  rC Clang

https://reviews.llvm.org/D47097

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGen/debug-info-preserve-scope.c


Index: test/CodeGen/debug-info-preserve-scope.c
===
--- /dev/null
+++ test/CodeGen/debug-info-preserve-scope.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -O1 -debug-info-kind=limited -emit-llvm -mllvm \
+// RUN: -opt-bisect-limit=2 -o - %s 2> /dev/null | FileCheck %s \
+// RUN: --check-prefix PHI
+
+extern int map[];
+// PHI-LABEL: define void @test1
+void test1(int a, int n) {
+  for (int i = 0; i < n; ++i)
+a = map[a];
+}
+
+// PHI: for.cond:
+// PHI-NEXT: {{.*}} = phi i32 {{.*}} !dbg ![[test1DbgLoc:[0-9]+]]
+
+// PHI: ![[test1DbgLoc]] = !DILocation(line: 0
+
+
+static int i;
+// CHECK-LABEL: define void @test2
+void test2(int b) {
+  i = b;
+}
+
+// CHECK: store i32 {{.*}} !dbg ![[test2DbgLoc:[0-9]+]]
+
+// CHECK: ![[test2DbgLoc]] = !DILocation(line: 0
+
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1946,6 +1946,10 @@
 }
   }
 
+  // Set artificial debug location to preserve the scope. This is later
+  // used by mem2reg to assign DL at the phi's it generates.
+  auto DL = ApplyDebugLocation::CreateArtificial(*this);
+
   Address DeclPtr = Address::invalid();
   bool DoStore = false;
   bool IsScalar = hasScalarEvaluationKind(Ty);


Index: test/CodeGen/debug-info-preserve-scope.c
===
--- /dev/null
+++ test/CodeGen/debug-info-preserve-scope.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -O1 -debug-info-kind=limited -emit-llvm -mllvm \
+// RUN: -opt-bisect-limit=2 -o - %s 2> /dev/null | FileCheck %s \
+// RUN: --check-prefix PHI
+
+extern int map[];
+// PHI-LABEL: define void @test1
+void test1(int a, int n) {
+  for (int i = 0; i < n; ++i)
+a = map[a];
+}
+
+// PHI: for.cond:
+// PHI-NEXT: {{.*}} = phi i32 {{.*}} !dbg ![[test1DbgLoc:[0-9]+]]
+
+// PHI: ![[test1DbgLoc]] = !DILocation(line: 0
+
+
+static int i;
+// CHECK-LABEL: define void @test2
+void test2(int b) {
+  i = b;
+}
+
+// CHECK: store i32 {{.*}} !dbg ![[test2DbgLoc:[0-9]+]]
+
+// CHECK: ![[test2DbgLoc]] = !DILocation(line: 0
+
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1946,6 +1946,10 @@
 }
   }
 
+  // Set artificial debug location to preserve the scope. This is later
+  // used by mem2reg to assign DL at the phi's it generates.
+  auto DL = ApplyDebugLocation::CreateArtificial(*this);
+
   Address DeclPtr = Address::invalid();
   bool DoStore = false;
   bool IsScalar = hasScalarEvaluationKind(Ty);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47849: [OpenMP][Clang][NVPTX] Enable math functions called in an OpenMP NVPTX target device region to be resolved as device-native function calls

2018-06-07 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In https://reviews.llvm.org/D47849#1124638, @Hahnfeld wrote:

> IMO this goes into the right direction, we should use the fast implementation 
> in libdevice. If LLVM doesn't lower these calls in the NVPTX backend, I think 
> it's ok to use header wrappers as CUDA already does.


Using wrapper headers may be OK solution for now. Ideally we should grow our 
own equivalent of device-side libm so we don't have to rely on libdevice 
bitcode.

> Two questions:
> 
> 1. Can you explain where this is important for "correctness"? Yesterday I 
> compiled a code using `sqrt` and it seems to spit out the correct results. 
> Maybe that's relevant for other functions?
> 2. Incidentally I ran into a closely related problem: I can't `#include 
> ` in translation units compiled for offloading, Clang complains about 
> inline assembly for x86 (see below). Does that work for you?
> 
>   ``` In file included from /usr/include/math.h:413: 
> /usr/include/bits/mathinline.h:131:43: error: invalid input constraint 'x' in 
> asm __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x)); ^ 
> /usr/include/bits/mathinline.h:143:43: error: invalid input constraint 'x' in 
> asm __asm ("pmovmskb %1, %0" : "=r" (__m) : "x" (__x)); ^ 2 errors generated. 
> ```

Avoiding conflicts between host and device implementations of the same 
functions in C++ requires use of attribute-based overloading 
(https://goo.gl/EXnymm). For CUDA compilation, we provide device-side overloads 
with __device__ attributes but otherwise identical signatures. We may need to 
extend it to work in C mode, too. Clang already has 
__attribute__((overloadable)), so basic overloading mechanisms should be there 
already.




Comment at: lib/Headers/__clang_cuda_device_functions.h:1153-1155
+__DEVICE__ long long llabs(long long __a) { return __nv_llabs(__a); }
 #if defined(__LP64__)
 __DEVICE__ long labs(long __a) { return llabs(__a); };

I think it should've been `return __nv_llabs(__a)` here and the definition of 
`long long llabs()` should remain back  where it was.


Repository:
  rC Clang

https://reviews.llvm.org/D47849



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


r334208 - [X86] Add back builtins for _mm_slli_si128/_mm_srli_si128 and similar intrinsics.

2018-06-07 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Thu Jun  7 10:28:03 2018
New Revision: 334208

URL: http://llvm.org/viewvc/llvm-project?rev=334208&view=rev
Log:
[X86] Add back builtins for  _mm_slli_si128/_mm_srli_si128 and similar 
intrinsics.

We still lower them to native shuffle IR, but we do it in CGBuiltin.cpp now. 
This allows us to check the target feature and ensure the immediate fits in 8 
bits.

This also improves our -O0 codegen slightly because we're able to see the 
zeroinitializer in the shuffle. It looks like it got lost behind a store+load 
previously.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/avx2intrin.h
cfe/trunk/lib/Headers/avx512bwintrin.h
cfe/trunk/lib/Headers/emmintrin.h
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGen/avx2-builtins.c
cfe/trunk/test/CodeGen/avx512bw-builtins.c
cfe/trunk/test/CodeGen/sse2-builtins.c

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=334208&r1=334207&r2=334208&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Thu Jun  7 10:28:03 2018
@@ -358,6 +358,8 @@ TARGET_BUILTIN(__builtin_ia32_psrlqi128,
 TARGET_BUILTIN(__builtin_ia32_psrawi128, "V8sV8si", "nc", "sse2")
 TARGET_BUILTIN(__builtin_ia32_psradi128, "V4iV4ii", "nc", "sse2")
 TARGET_BUILTIN(__builtin_ia32_pmaddwd128, "V4iV8sV8s", "nc", "sse2")
+TARGET_BUILTIN(__builtin_ia32_pslldqi128, "V2LLiV2LLiIi", "nc", "sse2")
+TARGET_BUILTIN(__builtin_ia32_psrldqi128, "V2LLiV2LLiIi", "nc", "sse2")
 
 TARGET_BUILTIN(__builtin_ia32_monitor, "vv*UiUi", "n", "sse3")
 TARGET_BUILTIN(__builtin_ia32_mwait, "vUiUi", "n", "sse3")
@@ -585,6 +587,7 @@ TARGET_BUILTIN(__builtin_ia32_psignw256,
 TARGET_BUILTIN(__builtin_ia32_psignd256, "V8iV8iV8i", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_psllwi256, "V16sV16si", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_psllw256, "V16sV16sV8s", "nc", "avx2")
+TARGET_BUILTIN(__builtin_ia32_pslldqi256, "V4LLiV4LLiIi", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_pslldi256, "V8iV8ii", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_pslld256, "V8iV8iV4i", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_psllqi256, "V4LLiV4LLii", "nc", "avx2")
@@ -593,6 +596,7 @@ TARGET_BUILTIN(__builtin_ia32_psrawi256,
 TARGET_BUILTIN(__builtin_ia32_psraw256, "V16sV16sV8s", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_psradi256, "V8iV8ii", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_psrad256, "V8iV8iV4i", "nc", "avx2")
+TARGET_BUILTIN(__builtin_ia32_psrldqi256, "V4LLiV4LLiIi", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_psrlwi256, "V16sV16si", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_psrlw256, "V16sV16sV8s", "nc", "avx2")
 TARGET_BUILTIN(__builtin_ia32_psrldi256, "V8iV8ii", "nc", "avx2")
@@ -1352,6 +1356,8 @@ TARGET_BUILTIN(__builtin_ia32_psraw512,
 TARGET_BUILTIN(__builtin_ia32_psrawi512, "V32sV32si", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_psrlw512, "V32sV32sV8s", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_psrlwi512, "V32sV32si", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_pslldqi512, "V8LLiV8LLiIi", "nc", "avx512bw")
+TARGET_BUILTIN(__builtin_ia32_psrldqi512, "V8LLiV8LLiIi", "nc", "avx512bw")
 TARGET_BUILTIN(__builtin_ia32_movdqa32load128_mask, "V4iV4i*V4iUc", "n", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_movdqa32load256_mask, "V8iV8i*V8iUc", "n", 
"avx512vl")
 TARGET_BUILTIN(__builtin_ia32_movdqa32load512_mask, "V16iV16iC*V16iUs", "n", 
"avx512f")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=334208&r1=334207&r2=334208&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Jun  7 10:28:03 2018
@@ -9262,6 +9262,68 @@ Value *CodeGenFunction::EmitX86BuiltinEx
"vperm");
   }
 
+  case X86::BI__builtin_ia32_pslldqi128:
+  case X86::BI__builtin_ia32_pslldqi256:
+  case X86::BI__builtin_ia32_pslldqi512: {
+// Shift value is in bits so divide by 8.
+unsigned ShiftVal = cast(Ops[1])->getZExtValue() >> 3;
+llvm::Type *ResultType = Ops[0]->getType();
+// Builtin type is vXi64 so multiply by 8 to get bytes.
+unsigned NumElts = ResultType->getVectorNumElements() * 8;
+
+// If pslldq is shifting the vector more than 15 bytes, emit zero.
+if (ShiftVal >= 16)
+  return llvm::Constant::getNullValue(ResultType);
+
+uint32_t Indices[64];
+// 256/512-bit pslldq operates on 128-bit lanes so we need to handle that
+for (unsigned l = 0; l != NumElts; l += 16) {
+  for (unsigned i = 0; i != 16; ++i) {
+unsigned Idx = NumElts + i - ShiftVal;
+if (Idx < NumElts)

[PATCH] D47707: [clangd] Downrank symbols with reserved names (score *= 0.1)

2018-06-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

@ilya-biryukov Ping, anything left for me to do here?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D47707



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


[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

2018-06-07 Thread Emmett Neyman via Phabricator via cfe-commits
emmettneyman updated this revision to Diff 150365.
emmettneyman added a comment.

- refactored cmake and deleted header file


Repository:
  rC Clang

https://reviews.llvm.org/D47843

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h

Index: tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
===
--- tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
+++ tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
@@ -17,6 +17,10 @@
 
 namespace clang_fuzzer {
 class Function;
+class LoopFunction;
+
 std::string FunctionToString(const Function &input);
 std::string ProtoToCxx(const uint8_t *data, size_t size);
+std::string LoopFunctionToString(const LoopFunction &input);
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
 }
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,33 @@
+//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements a simple driver to print a C++ program from a protobuf with loops.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+#include 
+
+#include "proto_to_cxx.h"
+
+int main(int argc, char **argv) {
+  for (int i = 1; i < argc; i++) {
+std::fstream in(argv[i]);
+std::string str((std::istreambuf_iterator(in)),
+std::istreambuf_iterator());
+std::cout << "// " << argv[i] << std::endl;
+std::cout << clang_fuzzer::LoopProtoToCxx(
+reinterpret_cast(str.data()), str.size());
+  }
+}
+
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
@@ -0,0 +1,115 @@
+//==-- loop_proto_to_cxx.cpp - Protobuf-C++ conversion -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and C++. Extends
+// proto_to_cxx.cpp by wrapping all the generated C++ code in a single for
+// loop. Also coutputs a different function signature that includes a 
+// size_t parameter for the loop to use.
+//
+//===--===//
+
+#include "proto_to_cxx.h"
+#include "cxx_loop_proto.pb.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls.
+std::ostream &operator<<(std::ostream &os, const BinaryOp &x);
+std::ostream &operator<<(std::ostream &os, const StatementSeq &x);
+
+// Proto to C++.
+std::ostream &operator<<(std::ostream &os, const Const &x) {
+  return os << "(" << x.val() << ")";
+}
+std::ostream &operator<<(std::ostream &os, const VarRef &x) {
+  if (x.is_loop_var()) {
+return os << "a[loop_ctr]";
+  } else {
+return os << "a[" << static_cast(x.varnum()) << " % s]";
+  }
+}
+std::ostream &operator<<(std::ostream &os, const Lvalue &x) {
+  return os << x.varref();
+}
+std::ostream &operator<<(std::ostream &os, const Rvalue &x) {
+if (x.has_varref()) return os << x.varref();
+if (x.has_cons())   return os << x.cons();
+if (x.has_binop())  return os << x.binop();
+return os << "1";
+}
+std::ostream &operator<<(std::ostream &os, const BinaryOp &x) {
+  os << "(" << x.left();
+  switch (x.op()) {
+case BinaryOp::PLUS: os << "+"; break;
+case BinaryOp::MINUS: os << "-"; break;
+case BinaryOp::MUL: os << "*"; break;
+case BinaryOp::DIV: os << "/"; break;
+case BinaryOp::MOD: os << "%"; break;
+case BinaryOp::XOR: os << "^"; break;
+case BinaryOp::AND: os << "&"; break;
+case BinaryOp::OR: os << "|"; break;
+case BinaryOp::EQ: os << "=="; break;
+case BinaryOp::NE: os << "!="; break;
+case BinaryOp::LE: os << "<="; break;
+case BinaryOp::GE: os << ">="; break;
+case BinaryOp::LT: os << "<"; break;
+case BinaryOp::GT: os << ">"; break;
+  }
+

[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-06-07 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta created this revision.
manojgupta added reviewers: t.p.northover, efriedma, jyknight, chandlerc, rnk, 
srhines, void.

Support for this option is needed for building Linux kernel.
This is a very frequently requested feature by kernel developers.

More details : https://lkml.org/lkml/2018/4/4/601

GCC option description for -fdelete-null-pointer-checks:
This Assume that programs cannot safely dereference null pointers,
and that no code or data element resides at address zero.

-fno-delete-null-pointer-checks is the inverse of this implying that
null pointer dereferencing is not undefined.

This feature is implemented in as the function attribute
"null-pointer-is-valid"="true".
This CL only adds the attribute on the function. Another corresponding LLVM
change updates the optimizations to not treat null pointer dereferencing
as undefined if the attribute is present.


Repository:
  rC Clang

https://reviews.llvm.org/D47894

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGCall.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/delete-null-pointer-checks.c
  test/Driver/clang_f_opts.c

Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -348,7 +348,6 @@
 // RUN: -fwhole-program   \
 // RUN: -fcaller-saves\
 // RUN: -freorder-blocks  \
-// RUN: -fdelete-null-pointer-checks  \
 // RUN: -ffat-lto-objects \
 // RUN: -fmerge-constants \
 // RUN: -finline-small-functions  \
@@ -414,7 +413,6 @@
 // CHECK-WARNING-DAG: optimization flag '-fwhole-program' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fcaller-saves' is not supported
 // CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
-// CHECK-WARNING-DAG: optimization flag '-fdelete-null-pointer-checks' is not supported
 // CHECK-WARNING-DAG: optimization flag '-ffat-lto-objects' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fmerge-constants' is not supported
 // CHECK-WARNING-DAG: optimization flag '-finline-small-functions' is not supported
@@ -526,3 +524,10 @@
 // RUN: %clang -### -S -fno-merge-all-constants -fmerge-all-constants %s 2>&1 | FileCheck -check-prefix=CHECK-MERGE-ALL-CONSTANTS %s
 // CHECK-NO-MERGE-ALL-CONSTANTS-NOT: "-fmerge-all-constants"
 // CHECK-MERGE-ALL-CONSTANTS: "-fmerge-all-constants"
+
+// RUN: %clang -### -S -fdelete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NULL-POINTER-CHECKS %s
+// RUN: %clang -### -S -fno-delete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NO-NULL-POINTER-CHECKS %s
+// RUN: %clang -### -S -fdelete-null-pointer-checks -fno-delete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NO-NULL-POINTER-CHECKS %s
+// RUN: %clang -### -S -fno-delete-null-pointer-checks -fdelete-null-pointer-checks %s 2>&1 | FileCheck -check-prefix=CHECK-NULL-POINTER-CHECKS %s
+// CHECK-NO-NULL-POINTER-CHECKS: "-fno-delete-null-pointer-checks"
+// CHECK-NULL-POINTER-CHECKS-NOT: "-fno-delete-null-pointer-checks"
Index: test/CodeGen/delete-null-pointer-checks.c
===
--- /dev/null
+++ test/CodeGen/delete-null-pointer-checks.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck -check-prefix=NULL-POINTER-INVALID  %s
+// RUN: %clang_cc1 -emit-llvm -o - %s -fno-delete-null-pointer-checks | FileCheck -check-prefix=NULL-POINTER-VALID  %s
+
+int test1(int a) {
+  return a;
+}
+
+// NULL-POINTER-INVALID-NOT: attributes #0 = {{.*}} "null-pointer-is-valid"="true"
+// NULL-POINTER-VALID: attributes #0 = {{.*}} "null-pointer-is-valid"="true"
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -742,6 +742,7 @@
  OPT_fno_unique_section_names, true);
 
   Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions);
+  Opts.NullPointerIsValid = Args.hasArg(OPT_fno_delete_null_pointer_checks);
 
   Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);
 
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3382,6 +3382,10 @@
options::OPT_fno_merge_all_constants, false))
 CmdArgs.push_back("-fmerge-all-constants");
 
+  if (Args.hasFlag(options::OPT_fno_delete_null_pointer_checks,
+   options::OPT_fdel

[PATCH] D47896: [CodeComplete] suppress define X X macros

2018-06-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added a subscriber: cfe-commits.

In particular, stderr etc where the equivalent symbols exist in the global
namespace. Having the symbol instead of the macro helps with ranking, and avoids
the current duplicate stderr suggestions.

@ilya-biryukov: think this is the right way to fix the duplicate completions?
Hiding the shadowed decl might be more correct, but it'd be hard *and* give
unfortunate ranking.


Repository:
  rC Clang

https://reviews.llvm.org/D47896

Files:
  lib/Sema/SemaCodeComplete.cpp
  test/Index/complete-macros.c


Index: test/Index/complete-macros.c
===
--- test/Index/complete-macros.c
+++ test/Index/complete-macros.c
@@ -25,6 +25,12 @@
   
 }
 
+int shadow;
+#define shadow shadow
+void test_shadow() {
+
+}
+
 // RUN: c-index-test -code-completion-at=%s:7:1 %s -I%S | FileCheck 
-check-prefix=CHECK-CC0 %s
 // CHECK-CC0-NOT: FOO
 // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test 
-code-completion-at=%s:7:1 %s -I%S | FileCheck -check-prefix=CHECK-CC1 %s
@@ -45,3 +51,7 @@
 
 // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test 
-code-completion-at=%s:15:5 %s -I%S | FileCheck -check-prefix=CHECK-CC4 %s
 // CHECK-CC4-NOT: COMPLETE_MACROS_H_GUARD
+
+// RUN: c-index-test -code-completion-at=%s:31:1 %s -I%S | FileCheck 
-check-prefix=CHECK-SHADOW %s
+// CHECK-SHADOW: FunctionDecl:{ResultType void}{TypedText g}
+// CHECK-SHADOW-NOT: macro definition:{TypedText shadow}
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -3308,9 +3308,18 @@
M != MEnd; ++M) {
 auto MD = PP.getMacroDefinition(M->first);
 if (IncludeUndefined || MD) {
-  if (MacroInfo *MI = MD.getMacroInfo())
+  if (MacroInfo *MI = MD.getMacroInfo()) {
 if (MI->isUsedForHeaderGuard())
   continue;
+// Some standard libraries e.g. #define stderr stderr, the underlying
+// decl is more useful.
+if (MI->getNumTokens() == 1 && MI->isObjectLike()) {
+  const Token &Tok = MI->getReplacementToken(0);
+  if (Tok.is(tok::identifier) &&
+  Tok.getIdentifierInfo()->getName() == M->first->getName())
+continue;
+}
+  }
 
   Results.AddResult(Result(M->first,
  getMacroUsagePriority(M->first->getName(),


Index: test/Index/complete-macros.c
===
--- test/Index/complete-macros.c
+++ test/Index/complete-macros.c
@@ -25,6 +25,12 @@
   
 }
 
+int shadow;
+#define shadow shadow
+void test_shadow() {
+
+}
+
 // RUN: c-index-test -code-completion-at=%s:7:1 %s -I%S | FileCheck -check-prefix=CHECK-CC0 %s
 // CHECK-CC0-NOT: FOO
 // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:7:1 %s -I%S | FileCheck -check-prefix=CHECK-CC1 %s
@@ -45,3 +51,7 @@
 
 // RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:15:5 %s -I%S | FileCheck -check-prefix=CHECK-CC4 %s
 // CHECK-CC4-NOT: COMPLETE_MACROS_H_GUARD
+
+// RUN: c-index-test -code-completion-at=%s:31:1 %s -I%S | FileCheck -check-prefix=CHECK-SHADOW %s
+// CHECK-SHADOW: FunctionDecl:{ResultType void}{TypedText g}
+// CHECK-SHADOW-NOT: macro definition:{TypedText shadow}
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -3308,9 +3308,18 @@
M != MEnd; ++M) {
 auto MD = PP.getMacroDefinition(M->first);
 if (IncludeUndefined || MD) {
-  if (MacroInfo *MI = MD.getMacroInfo())
+  if (MacroInfo *MI = MD.getMacroInfo()) {
 if (MI->isUsedForHeaderGuard())
   continue;
+// Some standard libraries e.g. #define stderr stderr, the underlying
+// decl is more useful.
+if (MI->getNumTokens() == 1 && MI->isObjectLike()) {
+  const Token &Tok = MI->getReplacementToken(0);
+  if (Tok.is(tok::identifier) &&
+  Tok.getIdentifierInfo()->getName() == M->first->getName())
+continue;
+}
+  }
 
   Results.AddResult(Result(M->first,
  getMacroUsagePriority(M->first->getName(),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-06-07 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Does IR generation need any special handling for this?  We add nonnull 
attributes in various places.


Repository:
  rC Clang

https://reviews.llvm.org/D47894



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


[PATCH] D47044: [analyzer] Ensure that we only visit a destructor for a reference if type information is available.

2018-06-07 Thread Matthew Voss via Phabricator via cfe-commits
ormris updated this revision to Diff 150377.
ormris added a comment.

Use AST matchers to select references for preservation


Repository:
  rC Clang

https://reviews.llvm.org/D47044

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/LoopWidening.cpp
  test/Analysis/loop-widening-invalid-type.cpp

Index: test/Analysis/loop-widening-invalid-type.cpp
===
--- /dev/null
+++ test/Analysis/loop-widening-invalid-type.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-max-loop 4 -analyzer-config widen-loops=true -verify %s
+
+struct A {
+  ~A() {}
+};
+struct B : public A {};
+
+void invalid_type_region_access() { // expected-no-diagnostics
+  const A &x = B();
+  for(int i = 0; i < 10; ++i) {}
+}
Index: lib/StaticAnalyzer/Core/LoopWidening.cpp
===
--- lib/StaticAnalyzer/Core/LoopWidening.cpp
+++ lib/StaticAnalyzer/Core/LoopWidening.cpp
@@ -15,9 +15,15 @@
 //===--===//
 
 #include "clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h"
+#include "clang/AST/AST.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
+#include "llvm/ADT/SmallSet.h"
 
 using namespace clang;
 using namespace ento;
+using namespace clang::ast_matchers;
 
 /// Return the loops condition Stmt or NULL if LoopStmt is not a loop
 static const Expr *getLoopCondition(const Stmt *LoopStmt) {
@@ -33,10 +39,27 @@
   }
 }
 
+struct Callback : public MatchFinder::MatchCallback {
+  const LocationContext *LCtx;
+  MemRegionManager &MRMgr;
+  RegionAndSymbolInvalidationTraits &ITraits;
+  explicit Callback(const LocationContext *LCtx_,
+MemRegionManager &MRMgr_,
+RegionAndSymbolInvalidationTraits &ITraits_) : LCtx(LCtx_),
+   MRMgr(MRMgr_),
+   ITraits(ITraits_) {}
+  virtual void run(const MatchFinder::MatchResult &Result) override {
+const VarDecl *VD = Result.Nodes.getNodeAs("match");
+const VarRegion *VarMem = MRMgr.getVarRegion(VD, LCtx);
+ITraits.setTrait(VarMem,
+ RegionAndSymbolInvalidationTraits::TK_PreserveContents);
+  }
+};
+
 namespace clang {
 namespace ento {
 
-ProgramStateRef getWidenedLoopState(ProgramStateRef PrevState,
+ProgramStateRef getWidenedLoopState(ProgramStateRef PrevState, ASTContext &ASTCtx,
 const LocationContext *LCtx,
 unsigned BlockCount, const Stmt *LoopStmt) {
 
@@ -60,6 +83,12 @@
  RegionAndSymbolInvalidationTraits::TK_EntireMemSpace);
   }
 
+  //References should not be invalidated.
+  MatchFinder Finder;
+  Finder.addMatcher(varDecl(hasType(referenceType())).bind("match"), new Callback(LCtx, MRMgr, ITraits));
+  Finder.matchAST(ASTCtx);
+
+
   // 'this' pointer is not an lvalue, we should not invalidate it. If the loop
   // is located in a method, constructor or destructor, the value of 'this'
   // pointer shoule remain unchanged.
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1855,7 +1855,7 @@
 // Widen.
 const LocationContext *LCtx = Pred->getLocationContext();
 ProgramStateRef WidenedState =
-getWidenedLoopState(Pred->getState(), LCtx, BlockCount, Term);
+getWidenedLoopState(Pred->getState(), AMgr.getASTContext(), LCtx, BlockCount, Term);
 nodeBuilder.generateNode(WidenedState, Pred);
 return;
   }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/LoopWidening.h
@@ -26,7 +26,7 @@
 ///
 /// Widen the loop by invalidating anything that might be modified
 /// by the loop body in any iteration.
-ProgramStateRef getWidenedLoopState(ProgramStateRef PrevState,
+ProgramStateRef getWidenedLoopState(ProgramStateRef PrevState, ASTContext &ASTCtx,
 const LocationContext *LCtx,
 unsigned BlockCount, const Stmt *LoopStmt);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

2018-06-07 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka updated this revision to Diff 150380.
vitalybuka added a comment.

git clang-format -f --style=file HEAD^


Repository:
  rC Clang

https://reviews.llvm.org/D47843

Files:
  tools/clang-fuzzer/CMakeLists.txt
  tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
  tools/clang-fuzzer/cxx_loop_proto.proto
  tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h

Index: tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
===
--- tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
+++ tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
@@ -17,6 +17,10 @@
 
 namespace clang_fuzzer {
 class Function;
+class LoopFunction;
+
 std::string FunctionToString(const Function &input);
 std::string ProtoToCxx(const uint8_t *data, size_t size);
+std::string LoopFunctionToString(const LoopFunction &input);
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
 }
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,32 @@
+//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements a simple driver to print a C++ program from a protobuf with loops.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+#include 
+
+#include "proto_to_cxx.h"
+
+int main(int argc, char **argv) {
+  for (int i = 1; i < argc; i++) {
+std::fstream in(argv[i]);
+std::string str((std::istreambuf_iterator(in)),
+std::istreambuf_iterator());
+std::cout << "// " << argv[i] << std::endl;
+std::cout << clang_fuzzer::LoopProtoToCxx(
+reinterpret_cast(str.data()), str.size());
+  }
+}
Index: tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
===
--- /dev/null
+++ tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
@@ -0,0 +1,148 @@
+//==-- loop_proto_to_cxx.cpp - Protobuf-C++ conversion -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements functions for converting between protobufs and C++. Extends
+// proto_to_cxx.cpp by wrapping all the generated C++ code in a single for
+// loop. Also coutputs a different function signature that includes a
+// size_t parameter for the loop to use.
+//
+//===--===//
+
+#include "cxx_loop_proto.pb.h"
+#include "proto_to_cxx.h"
+
+// The following is needed to convert protos in human-readable form
+#include 
+
+#include 
+#include 
+
+namespace clang_fuzzer {
+
+// Forward decls.
+std::ostream &operator<<(std::ostream &os, const BinaryOp &x);
+std::ostream &operator<<(std::ostream &os, const StatementSeq &x);
+
+// Proto to C++.
+std::ostream &operator<<(std::ostream &os, const Const &x) {
+  return os << "(" << x.val() << ")";
+}
+std::ostream &operator<<(std::ostream &os, const VarRef &x) {
+  if (x.is_loop_var()) {
+return os << "a[loop_ctr]";
+  } else {
+return os << "a[" << static_cast(x.varnum()) << " % s]";
+  }
+}
+std::ostream &operator<<(std::ostream &os, const Lvalue &x) {
+  return os << x.varref();
+}
+std::ostream &operator<<(std::ostream &os, const Rvalue &x) {
+  if (x.has_varref())
+return os << x.varref();
+  if (x.has_cons())
+return os << x.cons();
+  if (x.has_binop())
+return os << x.binop();
+  return os << "1";
+}
+std::ostream &operator<<(std::ostream &os, const BinaryOp &x) {
+  os << "(" << x.left();
+  switch (x.op()) {
+  case BinaryOp::PLUS:
+os << "+";
+break;
+  case BinaryOp::MINUS:
+os << "-";
+break;
+  case BinaryOp::MUL:
+os << "*";
+break;
+  case BinaryOp::DIV:
+os << "/";
+break;
+  case BinaryOp::MOD:
+os << "%";
+break;
+  case BinaryOp::XOR:
+os << "^";
+break;
+  case BinaryOp::AND:
+os << "&";
+break;
+  case BinaryOp::OR:
+os << "|";
+break;
+  case BinaryOp::EQ:
+os << "==";
+break;
+  case BinaryOp::NE:
+os << "!=";
+break;
+  case BinaryOp::LE:
+os << "<=";
+break;
+  case BinaryOp::GE:
+os << ">=";
+break;
+  

[PATCH] D47864: [python] Fix most Python binding unittests on Windows

2018-06-07 Thread Ethan via Phabricator via cfe-commits
ethanhs added a comment.

In https://reviews.llvm.org/D47864#1124948, @bkramer wrote:

> I don't know much about the python bindings, but this is probably fine.


Yeah I wasn't really sure who to add so I looked at the commit history. Thank 
you for adding the right people.


Repository:
  rC Clang

https://reviews.llvm.org/D47864



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


r334216 - Introducing single for loop into clang_proto_fuzzer

2018-06-07 Thread Vitaly Buka via cfe-commits
Author: vitalybuka
Date: Thu Jun  7 12:17:46 2018
New Revision: 334216

URL: http://llvm.org/viewvc/llvm-project?rev=334216&view=rev
Log:
Introducing single for loop into clang_proto_fuzzer

Summary:
Created a new protobuf and protobuf-to-C++ "converter" that wraps the entire 
C++ code in a single for loop.
  - Slightly changed cxx_proto.proto -> cxx_loop_proto.proto
  - Made some changes to proto_to_cxx files to handle the new kind of protobuf
  - Created ExampleClangLoopProtoFuzzer to test new protobuf and "converter"

Patch by Emmett Neyman

Reviewers: kcc, vitalybuka, morehouse

Reviewed By: vitalybuka, morehouse

Subscribers: mgorny, llvm-commits, cfe-commits

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

Added:
cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
cfe/trunk/tools/clang-fuzzer/cxx_loop_proto.proto
cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
Modified:
cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h

Modified: cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/CMakeLists.txt?rev=334216&r1=334215&r2=334216&view=diff
==
--- cfe/trunk/tools/clang-fuzzer/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-fuzzer/CMakeLists.txt Thu Jun  7 12:17:46 2018
@@ -14,6 +14,7 @@ set(LLVM_OPTIONAL_SOURCES
   ClangFuzzer.cpp
   DummyClangFuzzer.cpp
   ExampleClangProtoFuzzer.cpp
+  ExampleClangLoopProtoFuzzer.cpp
   )
 
 if(CLANG_ENABLE_PROTO_FUZZER)
@@ -24,6 +25,7 @@ if(CLANG_ENABLE_PROTO_FUZZER)
   include_directories(${PROTOBUF_INCLUDE_DIRS})
   include_directories(${CMAKE_CURRENT_BINARY_DIR})
   protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS cxx_proto.proto)
+  protobuf_generate_cpp(LOOP_PROTO_SRCS LOOP_PROTO_HDRS cxx_loop_proto.proto)
   set(LLVM_OPTIONAL_SOURCES ${LLVM_OPTIONAL_SOURCES} ${PROTO_SRCS})
   add_clang_library(clangCXXProto
 ${PROTO_SRCS}
@@ -33,13 +35,21 @@ if(CLANG_ENABLE_PROTO_FUZZER)
 ${PROTOBUF_LIBRARIES}
 )
 
+  add_clang_library(clangCXXLoopProto
+${LOOP_PROTO_SRCS}
+${LOOP_PROTO_HDRS}
+
+LINK_LIBS
+${PROTOBUF_LIBRARIES}
+)
+
   # Build and include libprotobuf-mutator
   include(ProtobufMutator)
   include_directories(${ProtobufMutator_INCLUDE_DIRS})
 
   # Build the protobuf->C++ translation library and driver.
   add_clang_subdirectory(proto-to-cxx)
-
+  
   # Build the fuzzer initialization library.
   add_clang_subdirectory(fuzzer-initialize)
 
@@ -49,16 +59,32 @@ if(CLANG_ENABLE_PROTO_FUZZER)
 ExampleClangProtoFuzzer.cpp
 )
 
-  target_link_libraries(clang-proto-fuzzer
-PRIVATE
+  # Build the loop protobuf fuzzer
+  add_clang_executable(clang-loop-proto-fuzzer
+${DUMMY_MAIN}
+ExampleClangLoopProtoFuzzer.cpp
+)
+
+  set(COMMON_PROTO_FUZZ_LIBRARIES
 ${ProtobufMutator_LIBRARIES}
 ${PROTOBUF_LIBRARIES}
 ${LLVM_LIB_FUZZING_ENGINE}
-clangCXXProto
 clangFuzzerInitialize
 clangHandleCXX
+)
+
+  target_link_libraries(clang-proto-fuzzer
+PRIVATE
+${COMMON_PROTO_FUZZ_LIBRARIES}
+clangCXXProto
 clangProtoToCXX
 )
+  target_link_libraries(clang-loop-proto-fuzzer
+PRIVATE
+${COMMON_PROTO_FUZZ_LIBRARIES}
+clangCXXLoopProto
+clangLoopProtoToCXX
+)
 endif()
 
 add_clang_subdirectory(handle-cxx)

Added: cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp?rev=334216&view=auto
==
--- cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp (added)
+++ cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp Thu Jun  7 
12:17:46 2018
@@ -0,0 +1,30 @@
+//===-- ExampleClangLoopProtoFuzzer.cpp - Fuzz Clang 
--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+///  This file implements a function that runs Clang on a single
+///  input and uses libprotobuf-mutator to find new inputs. This function is
+///  then linked into the Fuzzer library. This file differs from
+///  ExampleClangProtoFuzzer in that it uses the new protobuf that includes
+///  C++ code with a single for loop.
+///
+//===--===//
+
+#include "cxx_loop_proto.pb.h"
+#include "fuzzer-initialize/fuzzer_initialize.h"
+#include "handle-cxx/handle_cxx.h"
+#include "proto-to-cxx/proto_to_cxx.h"
+#include "src/libfuzzer/libfuzzer_

[PATCH] D47843: Introducing single for loop into clang_proto_fuzzer

2018-06-07 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334216: Introducing single for loop into clang_proto_fuzzer 
(authored by vitalybuka, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D47843

Files:
  cfe/trunk/tools/clang-fuzzer/CMakeLists.txt
  cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
  cfe/trunk/tools/clang-fuzzer/cxx_loop_proto.proto
  cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
  cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx.cpp
  cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
  cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h

Index: cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
===
--- cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
+++ cfe/trunk/tools/clang-fuzzer/ExampleClangLoopProtoFuzzer.cpp
@@ -0,0 +1,30 @@
+//===-- ExampleClangLoopProtoFuzzer.cpp - Fuzz Clang --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+///  This file implements a function that runs Clang on a single
+///  input and uses libprotobuf-mutator to find new inputs. This function is
+///  then linked into the Fuzzer library. This file differs from
+///  ExampleClangProtoFuzzer in that it uses the new protobuf that includes
+///  C++ code with a single for loop.
+///
+//===--===//
+
+#include "cxx_loop_proto.pb.h"
+#include "fuzzer-initialize/fuzzer_initialize.h"
+#include "handle-cxx/handle_cxx.h"
+#include "proto-to-cxx/proto_to_cxx.h"
+#include "src/libfuzzer/libfuzzer_macro.h"
+
+using namespace clang_fuzzer;
+
+DEFINE_BINARY_PROTO_FUZZER(const LoopFunction &input) {
+  auto S = LoopFunctionToString(input);
+  HandleCXX(S, GetCLArgs());
+}
Index: cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
===
--- cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
+++ cfe/trunk/tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h
@@ -17,6 +17,10 @@
 
 namespace clang_fuzzer {
 class Function;
+class LoopFunction;
+
 std::string FunctionToString(const Function &input);
 std::string ProtoToCxx(const uint8_t *data, size_t size);
+std::string LoopFunctionToString(const LoopFunction &input);
+std::string LoopProtoToCxx(const uint8_t *data, size_t size);
 }
Index: cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
===
--- cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
+++ cfe/trunk/tools/clang-fuzzer/proto-to-cxx/CMakeLists.txt
@@ -2,12 +2,21 @@
 set(CMAKE_CXX_FLAGS ${CXX_FLAGS_NOFUZZ})
 
 # Needed by LLVM's CMake checks because this file defines multiple targets.
-set(LLVM_OPTIONAL_SOURCES proto_to_cxx.cpp proto_to_cxx_main.cpp)
+set(LLVM_OPTIONAL_SOURCES proto_to_cxx.cpp proto_to_cxx_main.cpp
+  loop_proto_to_cxx.cpp loop_proto_to_cxx_main.cpp)
 
 add_clang_library(clangProtoToCXX proto_to_cxx.cpp
   DEPENDS clangCXXProto
   LINK_LIBS clangCXXProto ${PROTOBUF_LIBRARIES}
   )
 
+add_clang_library(clangLoopProtoToCXX loop_proto_to_cxx.cpp
+  DEPENDS clangCXXLoopProto
+  LINK_LIBS clangCXXLoopProto ${PROTOBUF_LIBRARIES}
+  )
+
 add_clang_executable(clang-proto-to-cxx proto_to_cxx_main.cpp)
+add_clang_executable(clang-loop-proto-to-cxx loop_proto_to_cxx_main.cpp)
+
 target_link_libraries(clang-proto-to-cxx PRIVATE clangProtoToCXX)
+target_link_libraries(clang-loop-proto-to-cxx PRIVATE clangLoopProtoToCXX)
Index: cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
===
--- cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
+++ cfe/trunk/tools/clang-fuzzer/proto-to-cxx/loop_proto_to_cxx_main.cpp
@@ -0,0 +1,32 @@
+//==-- loop_proto_to_cxx_main.cpp - Driver for protobuf-C++ conversion -==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// Implements a simple driver to print a C++ program from a protobuf with loops.
+//
+//===--===//
+
+// This is a copy and will be updated later to introduce changes
+
+#include 
+#include 
+#include 
+#include 
+
+#include "proto_to_cxx.h"
+
+int main(int argc, char **argv) {
+  for (int i = 1; i < argc; i++) {

[PATCH] D34156: [LTO] Enable module summary emission by default for regular LTO

2018-06-07 Thread Vlad Tsyrklevich via Phabricator via cfe-commits
vlad.tsyrklevich added a comment.
Herald added a subscriber: steven_wu.

Hi Tobias, I tracked down the failure self-hosting LLVM with LTO with this 
revision to https://bugs.llvm.org/show_bug.cgi?id=37684#c2 and have a fix under 
review in https://reviews.llvm.org/D47898. This revision needs to be updated to 
include the following trivial EmitSummaryIndex->PrepareForThinLTO renames to 
build:

  --- a/lib/CodeGen/BackendUtil.cpp
  +++ b/lib/CodeGen/BackendUtil.cpp
  @@ -944,7 +944,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
 ModulePassManager MPM(CodeGenOpts.DebugPassManager);
   
 if (!CodeGenOpts.DisableLLVMPasses) {
  -bool IsThinLTO = CodeGenOpts.EmitSummaryIndex;
  +bool IsThinLTO = CodeGenOpts.PrepareForThinLTO;
   bool IsLTO = CodeGenOpts.PrepareForLTO;
   
   if (CodeGenOpts.OptimizationLevel == 0) {
  diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp
  index db6a82b415..91f80e5739 100644
  --- a/lib/CodeGen/CGDebugInfo.cpp
  +++ b/lib/CodeGen/CGDebugInfo.cpp
  @@ -578,7 +578,7 @@ void CGDebugInfo::CreateCompileUnit() {
 CSInfo,
 getSource(SM, SM.getMainFileID())),
 CGOpts.EmitVersionIdentMetadata ? Producer : "",
  -  LO.Optimize || CGOpts.PrepareForLTO || CGOpts.EmitSummaryIndex,
  +  LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO,
 CGOpts.DwarfDebugFlags, RuntimeVers,
 CGOpts.EnableSplitDwarf ? "" : CGOpts.SplitDwarfFile, EmissionKind,
 0 /* DWOid */, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,

Are you still interested in landing this?


https://reviews.llvm.org/D34156



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


[PATCH] D47902: [CUDA] Fix emission of constant strings in sections

2018-06-07 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld created this revision.
Hahnfeld added a reviewer: tra.
Herald added a subscriber: cfe-commits.

CGM.GetAddrOfConstantCString() sets the adress of the created GlobalValue
to unnamed. When emitting the object file LLVM will mark the surrounding
section as SHF_MERGE iff the string is nul-terminated and contains no
other nuls (see IsNullTerminatedString). This results in problems when
saving temporaries because LLVM doesn't set an EntrySize, so reading in
the serialized assembly file fails.
This never happened for the GPU binaries because they usually contain
a nul-character somewhere. Instead this only affected the module ID
when compiling relocatable device code.

However, this points to a potentially larger problem: If we put a
constant string into a named section, we really want the data to end
up in that section in the object file. To avoid LLVM merging sections
this patch unmarks the GlobalVariable's address as unnamed which also
fixes the problem of invalid serialized assembly files when saving
temporaries.


Repository:
  rC Clang

https://reviews.llvm.org/D47902

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


Index: test/CodeGenCUDA/device-stub.cu
===
--- test/CodeGenCUDA/device-stub.cu
+++ test/CodeGenCUDA/device-stub.cu
@@ -65,7 +65,7 @@
 // ALL: private unnamed_addr constant{{.*}}kernelfunc{{.*}}\00"
 // * constant unnamed string with GPU binary
 // HIP: @[[FATBIN:__hip_fatbin]] = external constant i8, section ".hip_fatbin"
-// CUDA: @[[FATBIN:.*]] = private unnamed_addr constant{{.*GPU binary would be 
here.*}}\00",
+// CUDA: @[[FATBIN:.*]] = private constant{{.*GPU binary would be here.*}}\00",
 // CUDANORDC-SAME: section ".nv_fatbin", align 8
 // CUDARDC-SAME: section "__nv_relfatbin", align 8
 // * constant struct that wraps GPU binary
@@ -81,7 +81,7 @@
 // * variable to save GPU binary handle after initialization
 // NORDC: @__[[PREFIX]]_gpubin_handle = internal global i8** null
 // * constant unnamed string with NVModuleID
-// RDC: [[MODULE_ID_GLOBAL:@.*]] = private unnamed_addr constant
+// RDC: [[MODULE_ID_GLOBAL:@.*]] = private constant
 // CUDARDC-SAME: c"[[MODULE_ID:.+]]\00", section "__nv_module_id", align 32
 // HIPRDC-SAME: c"[[MODULE_ID:.+]]\00", section "__hip_module_id", align 32
 // * Make sure our constructor was added to global ctor list.
@@ -141,7 +141,7 @@
 // There should be no __[[PREFIX]]_register_globals if we have no
 // device-side globals, but we still need to register GPU binary.
 // Skip GPU binary string first.
-// CUDANOGLOBALS: @{{.*}} = private unnamed_addr constant{{.*}}
+// CUDANOGLOBALS: @{{.*}} = private constant{{.*}}
 // HIPNOGLOBALS: @{{.*}} = external constant{{.*}}
 // NOGLOBALS-NOT: define internal void @__{{.*}}_register_globals
 // NOGLOBALS: define internal void @__[[PREFIX:cuda|hip]]_module_ctor
Index: lib/CodeGen/CGCUDANV.cpp
===
--- lib/CodeGen/CGCUDANV.cpp
+++ lib/CodeGen/CGCUDANV.cpp
@@ -75,8 +75,12 @@
 auto ConstStr = CGM.GetAddrOfConstantCString(Str, Name.c_str());
 llvm::GlobalVariable *GV =
 cast(ConstStr.getPointer());
-if (!SectionName.empty())
+if (!SectionName.empty()) {
   GV->setSection(SectionName);
+  // Mark the address as used which make sure that this section isn't
+  // merged and we will really have it in the object file.
+  GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::None);
+}
 if (Alignment)
   GV->setAlignment(Alignment);
 


Index: test/CodeGenCUDA/device-stub.cu
===
--- test/CodeGenCUDA/device-stub.cu
+++ test/CodeGenCUDA/device-stub.cu
@@ -65,7 +65,7 @@
 // ALL: private unnamed_addr constant{{.*}}kernelfunc{{.*}}\00"
 // * constant unnamed string with GPU binary
 // HIP: @[[FATBIN:__hip_fatbin]] = external constant i8, section ".hip_fatbin"
-// CUDA: @[[FATBIN:.*]] = private unnamed_addr constant{{.*GPU binary would be here.*}}\00",
+// CUDA: @[[FATBIN:.*]] = private constant{{.*GPU binary would be here.*}}\00",
 // CUDANORDC-SAME: section ".nv_fatbin", align 8
 // CUDARDC-SAME: section "__nv_relfatbin", align 8
 // * constant struct that wraps GPU binary
@@ -81,7 +81,7 @@
 // * variable to save GPU binary handle after initialization
 // NORDC: @__[[PREFIX]]_gpubin_handle = internal global i8** null
 // * constant unnamed string with NVModuleID
-// RDC: [[MODULE_ID_GLOBAL:@.*]] = private unnamed_addr constant
+// RDC: [[MODULE_ID_GLOBAL:@.*]] = private constant
 // CUDARDC-SAME: c"[[MODULE_ID:.+]]\00", section "__nv_module_id", align 32
 // HIPRDC-SAME: c"[[MODULE_ID:.+]]\00", section "__hip_module_id", align 32
 // * Make sure our constructor was added to global ctor list.
@@ -141,7 +141,7 @@
 // There should be no __[[PREFIX]]_register_globals if we have no
 // device-side globals, but we still need to register GPU binary.
 // Skip GPU binary s

[PATCH] D47578: Do not enforce absolute path argv0 in windows

2018-06-07 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added inline comments.



Comment at: llvm/lib/Support/Windows/Process.inc:240
+  Filename.assign(Base.begin(), Base.end());
+  return ec;
 }

The intention of the code is to return a success, so it is less confusing if 
you directly return a success (i.e. std::error_code())



Comment at: llvm/lib/Support/Windows/Process.inc:262
 
-  LocalFree(UnicodeCommandLine);
+  SmallVector Arg0(Args[0], Args[0] + strlen(Args[0])), 
Filename;
+  sys::path::remove_filename(Arg0);

Looks like defining a variable on at a time is more common than defining two 
variables in one line.


https://reviews.llvm.org/D47578



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


[PATCH] D47853: [Frontend] Disallow non-MSVC exception models for windows-msvc targets

2018-06-07 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai marked 2 inline comments as done.
smeenai added inline comments.



Comment at: test/CodeGen/personality.c:10
-// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -D __SEH_EXCEPTIONS__ 
-fms-extensions -fexceptions -fblocks -fseh-exceptions -S -emit-llvm %s -o - | 
FileCheck %s -check-prefix CHECK-WIN-SEH -check-prefix CHECK-WIN-SEH-X64
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fblocks 
-fsjlj-exceptions -S -emit-llvm %s -o - | FileCheck %s -check-prefix 
CHECK-WIN-SJLJ
 

mstorsjo wrote:
> I'd prefer if you didn't remove these tests, but instead retarget them to use 
> a `-gnu` triplet, to keep testing where you can explicitly choose between 
> sjlj/dwarf/seh for mingw setups.
I'll re-add those back; I didnt' realize they weren't already covered. I'm 
gonna drop the __SEH_EXCEPTIONS__ thing for MinGW, since AFAIK SEH 
`__try`/`__finally` doesn't work there.



Comment at: test/CodeGenCXX/personality.cpp:9
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions 
-fseh-exceptions -fcxx-exceptions -S -emit-llvm %s -o - | FileCheck %s 
-check-prefix CHECK-WIN-SEH
-// %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fsjlj-exceptions 
-fcxx-exceptions -S -emit-llvm %s -o - | FileCheck %s -check-prefix 
CHECK-WIN-SJLJ
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -D __SEH_EXCEPTIONS__ 
-fms-extensions -fexceptions -fseh-exceptions -fcxx-exceptions -S -emit-llvm %s 
-o - | FileCheck %s -check-prefix CHECK-WIN-SEH-X86

mstorsjo wrote:
> Same here, please keep the existing tests but retarget them to gnu/mingw.
This should all be covered by the group of RUN lines right below this one.


Repository:
  rC Clang

https://reviews.llvm.org/D47853



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


[PATCH] D47853: [Frontend] Disallow non-MSVC exception models for windows-msvc targets

2018-06-07 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai updated this revision to Diff 150394.
smeenai marked 2 inline comments as done.
smeenai added a comment.

Add back missing MinGW coverage


Repository:
  rC Clang

https://reviews.llvm.org/D47853

Files:
  include/clang/Basic/DiagnosticFrontendKinds.td
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/personality.c
  test/CodeGenCXX/ms-eh-personality.cpp
  test/CodeGenCXX/personality.cpp
  test/CodeGenObjC/personality.m
  test/CodeGenObjCXX/personality.mm
  test/Frontend/windows-exceptions.cpp

Index: test/Frontend/windows-exceptions.cpp
===
--- /dev/null
+++ test/Frontend/windows-exceptions.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -triple i686--windows-msvc -fsyntax-only %s
+// RUN: not %clang_cc1 -triple i686--windows-msvc -fsyntax-only -fdwarf-exceptions %s 2>&1 | FileCheck -check-prefix=MSVC-X86-DWARF %s
+// RUN: not %clang_cc1 -triple i686--windows-msvc -fsyntax-only -fseh-exceptions %s 2>&1 | FileCheck -check-prefix=MSVC-X86-SEH %s
+// RUN: not %clang_cc1 -triple i686--windows-msvc -fsyntax-only -fsjlj-exceptions %s 2>&1 | FileCheck -check-prefix=MSVC-X86-SJLJ %s
+
+// RUN: %clang_cc1 -triple x86_64--windows-msvc -fsyntax-only %s
+// RUN: not %clang_cc1 -triple x86_64--windows-msvc -fsyntax-only -fdwarf-exceptions %s 2>&1 | FileCheck -check-prefix=MSVC-X64-DWARF %s
+// RUN: not %clang_cc1 -triple x86_64--windows-msvc -fsyntax-only -fseh-exceptions %s 2>&1 | FileCheck -check-prefix=MSVC-X64-SEH %s
+// RUN: not %clang_cc1 -triple x86_64--windows-msvc -fsyntax-only -fsjlj-exceptions %s 2>&1 | FileCheck -check-prefix=MSVC-X64-SJLJ %s
+
+// RUN: %clang_cc1 -triple i686--windows-gnu -fsyntax-only %s
+// RUN: %clang_cc1 -triple i686--windows-gnu -fsyntax-only -fdwarf-exceptions %s
+// RUN: %clang_cc1 -triple i686--windows-gnu -fsyntax-only -fseh-exceptions %s
+// RUN: %clang_cc1 -triple i686--windows-gnu -fsyntax-only -fsjlj-exceptions %s
+
+// RUN: %clang_cc1 -triple x86_64--windows-gnu -fsyntax-only %s
+// RUN: %clang_cc1 -triple x86_64--windows-gnu -fsyntax-only -fdwarf-exceptions %s
+// RUN: %clang_cc1 -triple x86_64--windows-gnu -fsyntax-only -fseh-exceptions %s
+// RUN: %clang_cc1 -triple x86_64--windows-gnu -fsyntax-only -fsjlj-exceptions %s
+
+// MSVC-X86-DWARF: error: invalid exception model 'fdwarf-exceptions' for target 'i686--windows-msvc'
+// MSVC-X86-SEH: error: invalid exception model 'fseh-exceptions' for target 'i686--windows-msvc'
+// MSVC-X86-SJLJ: error: invalid exception model 'fsjlj-exceptions' for target 'i686--windows-msvc'
+
+// MSVC-X64-DWARF: error: invalid exception model 'fdwarf-exceptions' for target 'x86_64--windows-msvc'
+// MSVC-X64-SEH: error: invalid exception model 'fseh-exceptions' for target 'x86_64--windows-msvc'
+// MSVC-X64-SJLJ: error: invalid exception model 'fsjlj-exceptions' for target 'x86_64--windows-msvc'
Index: test/CodeGenObjCXX/personality.mm
===
--- test/CodeGenObjCXX/personality.mm
+++ test/CodeGenObjCXX/personality.mm
@@ -26,31 +26,13 @@
 // RUN: %clang_cc1 -triple i686-unknown-linux-gnu -fexceptions -fsjlj-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=objfw -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-OBJFW-SJLJ
 
 // RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx-fragile -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN-MACOSX-FRAGILE
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fdwarf-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx-fragile -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN-MACOSX-FRAGILE-DWARF
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fseh-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx-fragile -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN-MACOSX-FRAGILE-SEH
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fsjlj-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx-fragile -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN-MACOSX-FRAGILE-SJLJ
 // RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN-NS
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fdwarf-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN-NS-DWARF
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fseh-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN-NS
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fsjlj-exceptions -fobjc-exceptions -fcxx-exceptions -fobjc-runtime=macosx -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-WIN

r334221 - [FileSystem] Split up the OpenFlags enumeration.

2018-06-07 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Thu Jun  7 12:58:58 2018
New Revision: 334221

URL: http://llvm.org/viewvc/llvm-project?rev=334221&view=rev
Log:
[FileSystem] Split up the OpenFlags enumeration.

This breaks the OpenFlags enumeration into two separate
enumerations: OpenFlags and CreationDisposition.  The first
controls the behavior of the API depending on whether or not
the target file already exists, and is not a flags-based
enum.  The second controls more flags-like values.

This yields a more easy to understand API, while also allowing
flags to be passed to the openForRead api, where most of the
values didn't make sense before.  This also makes the apis more
testable as it becomes easy to enumerate all the configurations
which make sense, so I've added many new tests to exercise all
the different values.

Modified:
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=334221&r1=334220&r2=334221&view=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Thu Jun  7 12:58:58 2018
@@ -258,7 +258,8 @@ ErrorOr>
 RealFileSystem::openFileForRead(const Twine &Name) {
   int FD;
   SmallString<256> RealName;
-  if (std::error_code EC = sys::fs::openFileForRead(Name, FD, &RealName))
+  if (std::error_code EC =
+  sys::fs::openFileForRead(Name, FD, sys::fs::OF_None, &RealName))
 return EC;
   return std::unique_ptr(new RealFile(FD, Name.str(), RealName.str()));
 }

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=334221&r1=334220&r2=334221&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Thu Jun  7 12:58:58 2018
@@ -1293,7 +1293,7 @@ void Driver::generateCompilationDiagnost
 
   std::string Script = CrashInfo.Filename.rsplit('.').first.str() + ".sh";
   std::error_code EC;
-  llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::F_Excl);
+  llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::CD_CreateNew);
   if (EC) {
 Diag(clang::diag::note_drv_command_failed_diag_msg)
 << "Error generating run script: " + Script + " " + EC.message();

Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=334221&r1=334220&r2=334221&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Thu Jun  7 12:58:58 
2018
@@ -238,10 +238,8 @@ void HTMLDiagnostics::ReportDiag(const P
<< "-" << i << ".html";
   llvm::sys::path::append(Model, Directory,
   filename.str());
-  EC = llvm::sys::fs::openFileForWrite(Model,
-   FD,
-   llvm::sys::fs::F_RW |
-   llvm::sys::fs::F_Excl);
+  EC = llvm::sys::fs::openFileForReadWrite(
+  Model, FD, llvm::sys::fs::CD_CreateNew, llvm::sys::fs::OF_None);
   if (EC && EC != llvm::errc::file_exists) {
   llvm::errs() << "warning: could not create file '" << Model
<< "': " << EC.message() << '\n';


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


[clang-tools-extra] r334221 - [FileSystem] Split up the OpenFlags enumeration.

2018-06-07 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Thu Jun  7 12:58:58 2018
New Revision: 334221

URL: http://llvm.org/viewvc/llvm-project?rev=334221&view=rev
Log:
[FileSystem] Split up the OpenFlags enumeration.

This breaks the OpenFlags enumeration into two separate
enumerations: OpenFlags and CreationDisposition.  The first
controls the behavior of the API depending on whether or not
the target file already exists, and is not a flags-based
enum.  The second controls more flags-like values.

This yields a more easy to understand API, while also allowing
flags to be passed to the openForRead api, where most of the
values didn't make sense before.  This also makes the apis more
testable as it becomes easy to enumerate all the configurations
which make sense, so I've added many new tests to exercise all
the different values.

Modified:
clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp?rev=334221&r1=334220&r2=334221&view=diff
==
--- clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp (original)
+++ clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp Thu Jun  7 
12:58:58 2018
@@ -30,8 +30,8 @@ namespace {
 
 std::error_code CreateNewFile(const llvm::Twine &path) {
   int fd = 0;
-  if (std::error_code ec =
-  llvm::sys::fs::openFileForWrite(path, fd, llvm::sys::fs::F_Text))
+  if (std::error_code ec = llvm::sys::fs::openFileForWrite(
+  path, fd, llvm::sys::fs::CD_CreateAlways, llvm::sys::fs::F_Text))
 return ec;
 
   return llvm::sys::Process::SafelyCloseFileDescriptor(fd);

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=334221&r1=334220&r2=334221&view=diff
==
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Thu Jun  7 12:58:58 2018
@@ -159,7 +159,8 @@ int main(int argc, char *argv[]) {
   llvm::Optional InputMirrorStream;
   if (!InputMirrorFile.empty()) {
 std::error_code EC;
-InputMirrorStream.emplace(InputMirrorFile, /*ref*/ EC, 
llvm::sys::fs::F_RW);
+InputMirrorStream.emplace(InputMirrorFile, /*ref*/ EC,
+  llvm::sys::fs::FA_Read | 
llvm::sys::fs::FA_Write);
 if (EC) {
   InputMirrorStream.reset();
   llvm::errs() << "Error while opening an input mirror file: "
@@ -174,7 +175,8 @@ int main(int argc, char *argv[]) {
   std::unique_ptr Tracer;
   if (auto *TraceFile = getenv("CLANGD_TRACE")) {
 std::error_code EC;
-TraceStream.emplace(TraceFile, /*ref*/ EC, llvm::sys::fs::F_RW);
+TraceStream.emplace(TraceFile, /*ref*/ EC,
+llvm::sys::fs::FA_Read | llvm::sys::fs::FA_Write);
 if (EC) {
   TraceStream.reset();
   llvm::errs() << "Error while opening trace file " << TraceFile << ": "


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


[PATCH] D47853: [Frontend] Disallow non-MSVC exception models for windows-msvc targets

2018-06-07 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo accepted this revision.
mstorsjo added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!




Comment at: test/CodeGenCXX/personality.cpp:9
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions 
-fseh-exceptions -fcxx-exceptions -S -emit-llvm %s -o - | FileCheck %s 
-check-prefix CHECK-WIN-SEH
-// %clang_cc1 -triple i686-unknown-windows-msvc -fexceptions -fsjlj-exceptions 
-fcxx-exceptions -S -emit-llvm %s -o - | FileCheck %s -check-prefix 
CHECK-WIN-SJLJ
-// RUN: %clang_cc1 -triple i686-unknown-windows-msvc -D __SEH_EXCEPTIONS__ 
-fms-extensions -fexceptions -fseh-exceptions -fcxx-exceptions -S -emit-llvm %s 
-o - | FileCheck %s -check-prefix CHECK-WIN-SEH-X86

smeenai wrote:
> mstorsjo wrote:
> > Same here, please keep the existing tests but retarget them to gnu/mingw.
> This should all be covered by the group of RUN lines right below this one.
Oh, right.


Repository:
  rC Clang

https://reviews.llvm.org/D47853



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


r334224 - [Parse] Use CapturedStmt for @finally on MSVC

2018-06-07 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Thu Jun  7 13:07:52 2018
New Revision: 334224

URL: http://llvm.org/viewvc/llvm-project?rev=334224&view=rev
Log:
[Parse] Use CapturedStmt for @finally on MSVC

The body of a `@finally` needs to be executed on both exceptional and
non-exceptional paths. On landingpad platforms, this is straightforward:
the `@finally` body is emitted as a normal (non-exceptional) cleanup,
and then a catch-all is emitted which branches to that cleanup (the
cleanup has code to conditionally re-throw based on a flag which is set
by the catch-all).

Unfortunately, we can't use the same approach for MSVC exceptions, where
the catch-all will be emitted as a catchpad. We can't just branch to the
cleanup from within the catchpad, since we can only exit it via a
catchret, at which point the exception is destroyed and we can't
rethrow. We could potentially emit the finally body inside the catchpad
and have the normal cleanup path somehow branch into it, but that would
require some new IR construct that could branch into a catchpad.

Instead, after discussing it with Reid Kleckner, we decided that
frontend outlining was the best approach, similar to how SEH `__finally`
works today. We decided to use CapturedStmt (which was also suggested by
Reid) rather than CaptureFinder (which is what `__finally` uses) since
the latter doesn't handle a lot of cases we care about, e.g. self
accesses, property accesses, block captures, etc. Extending
CaptureFinder to handle those additional cases proved unwieldy, whereas
CapturedStmt already took care of all of those.  In theory `__finally`
could also be moved over to CapturedStmt, which would remove some
existing limitations (e.g. the inability to capture this), although
CaptureFinder would still be needed for SEH filters.

The one case supported by `@finally` but not CapturedStmt (or
CaptureFinder for that matter) is arbitrary control flow out of the
`@finally`, e.g. having a return statement inside a `@finally`. We can
add that support as a follow-up, but in practice we've found it to be
used very rarely anyway.

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

Added:
cfe/trunk/test/SemaObjC/finally-msvc.m
Modified:
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/Basic/CapturedStmt.h
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/lib/Parse/ParseObjc.cpp

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=334224&r1=334223&r2=334224&view=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Thu Jun  7 13:07:52 2018
@@ -2133,7 +2133,7 @@ private:
 
   /// The pointer part is the implicit the outlined function and the 
   /// int part is the captured region kind, 'CR_Default' etc.
-  llvm::PointerIntPair CapDeclAndKind;
+  llvm::PointerIntPair CapDeclAndKind;
 
   /// The record for captured variables, a RecordDecl or CXXRecordDecl.
   RecordDecl *TheRecordDecl = nullptr;

Modified: cfe/trunk/include/clang/Basic/CapturedStmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CapturedStmt.h?rev=334224&r1=334223&r2=334224&view=diff
==
--- cfe/trunk/include/clang/Basic/CapturedStmt.h (original)
+++ cfe/trunk/include/clang/Basic/CapturedStmt.h Thu Jun  7 13:07:52 2018
@@ -16,6 +16,7 @@ namespace clang {
 /// The different kinds of captured statement.
 enum CapturedRegionKind {
   CR_Default,
+  CR_ObjCAtFinally,
   CR_OpenMP
 };
 

Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=334224&r1=334223&r2=334224&view=diff
==
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Thu Jun  7 13:07:52 2018
@@ -748,6 +748,8 @@ public:
 switch (CapRegionKind) {
 case CR_Default:
   return "default captured statement";
+case CR_ObjCAtFinally:
+  return "Objective-C @finally statement";
 case CR_OpenMP:
   return "OpenMP region";
 }

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=334224&r1=334223&r2=334224&view=diff
==
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Thu Jun  7 13:07:52 2018
@@ -2585,13 +2585,26 @@ StmtResult Parser::ParseObjCTryStmt(Sour
   ParseScope FinallyScope(this,
   Scope::DeclScope | Scope::CompoundStmtScope);
 
+  bool ShouldCapture =
+  getTargetInfo().getTriple().isWindowsMSVCEnvironment();
+  if (ShouldCapture)
+Actions.ActOnCapturedRegionStart(Tok.getLocation

[PATCH] D47564: [Parse] Use CapturedStmt for @finally on MSVC

2018-06-07 Thread Shoaib Meenai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334224: [Parse] Use CapturedStmt for @finally on MSVC 
(authored by smeenai, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D47564

Files:
  cfe/trunk/include/clang/AST/Stmt.h
  cfe/trunk/include/clang/Basic/CapturedStmt.h
  cfe/trunk/include/clang/Sema/ScopeInfo.h
  cfe/trunk/lib/Parse/ParseObjc.cpp
  cfe/trunk/test/SemaObjC/finally-msvc.m


Index: cfe/trunk/test/SemaObjC/finally-msvc.m
===
--- cfe/trunk/test/SemaObjC/finally-msvc.m
+++ cfe/trunk/test/SemaObjC/finally-msvc.m
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple i686--windows-msvc -fexceptions -fobjc-exceptions 
-ast-dump %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64--windows-msvc -fexceptions -fobjc-exceptions 
-ast-dump %s 2>&1 | FileCheck %s
+
+void f() {
+  @try {
+  } @finally {
+  }
+}
+
+// CHECK:  ObjCAtFinallyStmt
+// CHECK-NEXT:   CapturedStmt
+// CHECK-NEXT: CapturedDecl
+// CHECK-NEXT:   CompoundStmt
+// CHECK-NEXT:   ImplicitParamDecl
Index: cfe/trunk/lib/Parse/ParseObjc.cpp
===
--- cfe/trunk/lib/Parse/ParseObjc.cpp
+++ cfe/trunk/lib/Parse/ParseObjc.cpp
@@ -2585,13 +2585,26 @@
   ParseScope FinallyScope(this,
   Scope::DeclScope | Scope::CompoundStmtScope);
 
+  bool ShouldCapture =
+  getTargetInfo().getTriple().isWindowsMSVCEnvironment();
+  if (ShouldCapture)
+Actions.ActOnCapturedRegionStart(Tok.getLocation(), getCurScope(),
+ CR_ObjCAtFinally, 1);
+
   StmtResult FinallyBody(true);
   if (Tok.is(tok::l_brace))
 FinallyBody = ParseCompoundStatementBody();
   else
 Diag(Tok, diag::err_expected) << tok::l_brace;
-  if (FinallyBody.isInvalid())
+
+  if (FinallyBody.isInvalid()) {
 FinallyBody = Actions.ActOnNullStmt(Tok.getLocation());
+if (ShouldCapture)
+  Actions.ActOnCapturedRegionError();
+  } else if (ShouldCapture) {
+FinallyBody = Actions.ActOnCapturedRegionEnd(FinallyBody.get());
+  }
+
   FinallyStmt = Actions.ActOnObjCAtFinallyStmt(AtCatchFinallyLoc,
FinallyBody.get());
   catch_or_finally_seen = true;
Index: cfe/trunk/include/clang/AST/Stmt.h
===
--- cfe/trunk/include/clang/AST/Stmt.h
+++ cfe/trunk/include/clang/AST/Stmt.h
@@ -2133,7 +2133,7 @@
 
   /// The pointer part is the implicit the outlined function and the 
   /// int part is the captured region kind, 'CR_Default' etc.
-  llvm::PointerIntPair CapDeclAndKind;
+  llvm::PointerIntPair CapDeclAndKind;
 
   /// The record for captured variables, a RecordDecl or CXXRecordDecl.
   RecordDecl *TheRecordDecl = nullptr;
Index: cfe/trunk/include/clang/Sema/ScopeInfo.h
===
--- cfe/trunk/include/clang/Sema/ScopeInfo.h
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h
@@ -748,6 +748,8 @@
 switch (CapRegionKind) {
 case CR_Default:
   return "default captured statement";
+case CR_ObjCAtFinally:
+  return "Objective-C @finally statement";
 case CR_OpenMP:
   return "OpenMP region";
 }
Index: cfe/trunk/include/clang/Basic/CapturedStmt.h
===
--- cfe/trunk/include/clang/Basic/CapturedStmt.h
+++ cfe/trunk/include/clang/Basic/CapturedStmt.h
@@ -16,6 +16,7 @@
 /// The different kinds of captured statement.
 enum CapturedRegionKind {
   CR_Default,
+  CR_ObjCAtFinally,
   CR_OpenMP
 };
 


Index: cfe/trunk/test/SemaObjC/finally-msvc.m
===
--- cfe/trunk/test/SemaObjC/finally-msvc.m
+++ cfe/trunk/test/SemaObjC/finally-msvc.m
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple i686--windows-msvc -fexceptions -fobjc-exceptions -ast-dump %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64--windows-msvc -fexceptions -fobjc-exceptions -ast-dump %s 2>&1 | FileCheck %s
+
+void f() {
+  @try {
+  } @finally {
+  }
+}
+
+// CHECK:  ObjCAtFinallyStmt
+// CHECK-NEXT:   CapturedStmt
+// CHECK-NEXT: CapturedDecl
+// CHECK-NEXT:   CompoundStmt
+// CHECK-NEXT:   ImplicitParamDecl
Index: cfe/trunk/lib/Parse/ParseObjc.cpp
===
--- cfe/trunk/lib/Parse/ParseObjc.cpp
+++ cfe/trunk/lib/Parse/ParseObjc.cpp
@@ -2585,13 +2585,26 @@
   ParseScope FinallyScope(this,
   Scope::DeclScope | Scope::CompoundStmtScope);
 
+  bool ShouldCapture =
+  getTargetInfo().getTriple().isWindowsMSVCEnvironment();
+  if (ShouldCapture)
+Actions.ActOnCapturedRegionStart(Tok.getLocation(), getC

[PATCH] D47233: [CodeGen] Emit MSVC RTTI for Obj-C EH types

2018-06-07 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai updated this revision to Diff 150399.
smeenai added a comment.

Address objc_exception attribute case


Repository:
  rC Clang

https://reviews.llvm.org/D47233

Files:
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGObjCMac.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenObjC/dllstorage.m
  test/CodeGenObjC/exceptions-msvc.m

Index: test/CodeGenObjC/exceptions-msvc.m
===
--- /dev/null
+++ test/CodeGenObjC/exceptions-msvc.m
@@ -0,0 +1,81 @@
+// RUN: %clang_cc1 -triple i686--windows-msvc -fobjc-runtime=ios-6.0 -fdeclspec -fexceptions -fobjc-exceptions -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,X86 %s
+// RUN: %clang_cc1 -triple i686--windows-msvc -fobjc-runtime=ios-6.0 -fobjc-arc -fdeclspec -fexceptions -fobjc-exceptions -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,X86 %s
+// RUN: %clang_cc1 -triple x86_64--windows-msvc -fobjc-runtime=ios-6.0 -fdeclspec -fexceptions -fobjc-exceptions -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,X64 %s
+// RUN: %clang_cc1 -triple x86_64--windows-msvc -fobjc-runtime=ios-6.0 -fobjc-arc -fdeclspec -fexceptions -fobjc-exceptions -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,X64 %s
+
+#if __has_feature(objc_arc)
+#define WEAK __weak
+#else
+#define WEAK
+#endif
+
+// CHECK-DAG: $OBJC_EHTYPE_id = comdat any
+// X86-DAG: @OBJC_EHTYPE_id = linkonce_odr global {{%[^ ]+}} { i8** @"??_7type_info@@6B@", i8* null, [18 x i8] c".PAUobjc_object@@\00" }, comdat
+// X64-DAG: @OBJC_EHTYPE_id = linkonce_odr global {{%[^ ]+}} { i8** @"??_7type_info@@6B@", i8* null, [19 x i8] c".PEAUobjc_object@@\00" }, comdat
+
+@class I;
+
+// CHECK-DAG: $"OBJC_EHTYPE_$_I" = comdat any
+// X86-DAG: @"OBJC_EHTYPE_$_I" = linkonce_odr global {{%[^ ]+}} { i8** @"??_7type_info@@6B@", i8* null, [8 x i8] c".PAUI@@\00" }, comdat
+// X64-DAG: @"OBJC_EHTYPE_$_I" = linkonce_odr global {{%[^ ]+}} { i8** @"??_7type_info@@6B@", i8* null, [9 x i8] c".PEAUI@@\00" }, comdat
+
+@class J;
+
+// CHECK-DAG: $"OBJC_EHTYPE_$_J" = comdat any
+// X86-DAG: @"OBJC_EHTYPE_$_J" = linkonce_odr global {{%[^ ]+}} { i8** @"??_7type_info@@6B@", i8* null, [8 x i8] c".PAUJ@@\00" }, comdat
+// X64-DAG: @"OBJC_EHTYPE_$_J" = linkonce_odr global {{%[^ ]+}} { i8** @"??_7type_info@@6B@", i8* null, [9 x i8] c".PEAUJ@@\00" }, comdat
+
+// The EHType shouldn't be exported
+__declspec(dllexport)
+__attribute__((objc_root_class))
+@interface K
+@end
+
+@implementation K
+@end
+
+// CHECK-DAG: $"OBJC_EHTYPE_$_K" = comdat any
+// X86-DAG: @"OBJC_EHTYPE_$_K" = linkonce_odr global {{%[^ ]+}} { i8** @"??_7type_info@@6B@", i8* null, [8 x i8] c".PAUK@@\00" }, comdat
+// X64-DAG: @"OBJC_EHTYPE_$_K" = linkonce_odr global {{%[^ ]+}} { i8** @"??_7type_info@@6B@", i8* null, [9 x i8] c".PEAUK@@\00" }, comdat
+
+__attribute__((objc_root_class))
+__attribute__((objc_runtime_name("NotL")))
+@interface L
+@end
+
+// CHECK-DAG: $"OBJC_EHTYPE_$_NotL" = comdat any
+// X86-DAG: @"OBJC_EHTYPE_$_NotL" = linkonce_odr global {{%[^ ]+}} { i8** @"??_7type_info@@6B@", i8* null, [8 x i8] c".PAUL@@\00" }, comdat
+// X64-DAG: @"OBJC_EHTYPE_$_NotL" = linkonce_odr global {{%[^ ]+}} { i8** @"??_7type_info@@6B@", i8* null, [9 x i8] c".PEAUL@@\00" }, comdat
+
+@class M;
+
+// CHECK-DAG: $"OBJC_EHTYPE_$_M" = comdat any
+// X86-DAG: @"OBJC_EHTYPE_$_M" = linkonce_odr global {{%[^ ]+}} { i8** @"??_7type_info@@6B@", i8* null, [8 x i8] c".PAUM@@\00" }, comdat
+// X64-DAG: @"OBJC_EHTYPE_$_M" = linkonce_odr global {{%[^ ]+}} { i8** @"??_7type_info@@6B@", i8* null, [9 x i8] c".PEAUM@@\00" }, comdat
+
+// The EHType shouldn't be generated for this definition, since it's not referenced.
+__attribute__((objc_root_class))
+__attribute__((objc_exception))
+@interface N
+@end
+
+@implementation N
+@end
+
+// CHECK-NOT: @"OBJC_EHTYPE_$_N"
+
+@protocol P;
+
+void f(void);
+
+void g() {
+  @try {
+f();
+  } @catch (I *) {
+  } @catch (J *) {
+  } @catch (K *) {
+  } @catch (L *) {
+  } @catch (M *WEAK) {
+  } @catch (id) {
+  }
+}
Index: test/CodeGenObjC/dllstorage.m
===
--- test/CodeGenObjC/dllstorage.m
+++ test/CodeGenObjC/dllstorage.m
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -fdeclspec -fobjc-runtime=ios -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -check-prefix CHECK-IR %s
-// RUN: %clang_cc1 -triple i686-windows-itanium -fms-extensions -fobjc-runtime=macosx -fdeclspec -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -check-prefix CHECK-IR %s
+// RUN: %clang_cc1 -triple i686-windows-itanium -fms-extensions -fobjc-runtime=macosx -fdeclspec -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -check-prefix CHECK-IR -check-prefix CHECK-ITANIUM %s
 // RUN: %clang_cc1 -triple i686-windows-itanium -fms-extensions -fobjc-runtime=objfw -fdeclspec -fobjc-exceptions -S -emit-llvm -o - %s | FileCheck -check-prefix CHECK-FW %s
 
 // CHECK-IR-DAG: @_objc_empty_cache = external dllimport global %struct._objc_cache

[PATCH] D47233: [CodeGen] Emit MSVC RTTI for Obj-C EH types

2018-06-07 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Ping @rjmccall


Repository:
  rC Clang

https://reviews.llvm.org/D47233



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


[libclc] r334226 - math/fma: Add fp32 software implementation

2018-06-07 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jun  7 13:27:43 2018
New Revision: 334226

URL: http://llvm.org/viewvc/llvm-project?rev=334226&view=rev
Log:
math/fma: Add fp32 software implementation

Passes CTS on carrizo (when forced to use sw fma) and turks.
Reviewer: Tom Stellard 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/ternary_decl.inc
libclc/trunk/generic/include/math/clc_fma.h
libclc/trunk/generic/lib/math/clc_fma.cl
libclc/trunk/generic/lib/math/fma.cl
libclc/trunk/generic/lib/math/fma.inc
Modified:
libclc/trunk/generic/include/clc/math/fma.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/math/fma.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/fma.h?rev=334226&r1=334225&r2=334226&view=diff
==
--- libclc/trunk/generic/include/clc/math/fma.h (original)
+++ libclc/trunk/generic/include/clc/math/fma.h Thu Jun  7 13:27:43 2018
@@ -1,6 +1,7 @@
-#undef fma
-#define fma __clc_fma
+#define __CLC_BODY 
+#define __CLC_FUNCTION fma
 
-#define __CLC_FUNCTION __clc_fma
-#define __CLC_INTRINSIC "llvm.fma"
-#include 
+#include 
+
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Added: libclc/trunk/generic/include/clc/math/ternary_decl.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/ternary_decl.inc?rev=334226&view=auto
==
--- libclc/trunk/generic/include/clc/math/ternary_decl.inc (added)
+++ libclc/trunk/generic/include/clc/math/ternary_decl.inc Thu Jun  7 13:27:43 
2018
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __CLC_FUNCTION(__CLC_GENTYPE a, 
__CLC_GENTYPE b, __CLC_GENTYPE c);

Added: libclc/trunk/generic/include/math/clc_fma.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/math/clc_fma.h?rev=334226&view=auto
==
--- libclc/trunk/generic/include/math/clc_fma.h (added)
+++ libclc/trunk/generic/include/math/clc_fma.h Thu Jun  7 13:27:43 2018
@@ -0,0 +1,11 @@
+#define __CLC_FUNCTION __clc_fma
+#define __CLC_INTRINSIC "llvm.fma"
+#include 
+
+#define __FLOAT_ONLY
+#define __CLC_FUNCTION __clc_sw_fma
+#define __CLC_BODY 
+#include 
+#undef __CLC_BODY
+#undef __CLC_FUNCTION
+#undef __FLOAT_ONLY

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=334226&r1=334225&r2=334226&view=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Thu Jun  7 13:27:43 2018
@@ -101,6 +101,8 @@ math/exp2.cl
 math/clc_exp10.cl
 math/exp10.cl
 math/fdim.cl
+math/clc_fma.cl
+math/fma.cl
 math/fmax.cl
 math/fmin.cl
 math/clc_fmod.cl

Added: libclc/trunk/generic/lib/math/clc_fma.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/clc_fma.cl?rev=334226&view=auto
==
--- libclc/trunk/generic/lib/math/clc_fma.cl (added)
+++ libclc/trunk/generic/lib/math/clc_fma.cl Thu Jun  7 13:27:43 2018
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include 
+
+#include "config.h"
+#include "math.h"
+#include "../clcmacro.h"
+
+struct fp {
+   ulong mantissa;
+   int exponent;
+   uint sign;
+};
+
+_CLC_DEF _CLC_OVERLOAD float __clc_sw_fma(float a, float b, float c)
+{
+   /* special cases */
+   if (isnan(a) || isnan(b) || isnan(c) || isinf(a) || isinf(b))
+   return mad(a, b, c);
+
+   /* If only c is inf, and both a,b are regular numbers, the result is c*/
+   if (isinf(c))
+   return c;
+
+   a = __clc_flush_denormal_if_not_su

[libclc] r334227 - r600/fmax: Flush denormals before calling builtin.

2018-06-07 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jun  7 13:27:56 2018
New Revision: 334227

URL: http://llvm.org/viewvc/llvm-project?rev=334227&view=rev
Log:
r600/fmax: Flush denormals before calling builtin.

Same reason as amdgcn.
Fixes fmax, maxmag CTS on turks.
Reviewer: Tom Stellard 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/r600/lib/math/fmax.cl
Modified:
libclc/trunk/r600/lib/SOURCES

Modified: libclc/trunk/r600/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/SOURCES?rev=334227&r1=334226&r2=334227&view=diff
==
--- libclc/trunk/r600/lib/SOURCES (original)
+++ libclc/trunk/r600/lib/SOURCES Thu Jun  7 13:27:56 2018
@@ -1,3 +1,4 @@
+math/fmax.cl
 synchronization/barrier_impl.ll
 workitem/get_global_offset.cl
 workitem/get_group_id.cl

Added: libclc/trunk/r600/lib/math/fmax.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/math/fmax.cl?rev=334227&view=auto
==
--- libclc/trunk/r600/lib/math/fmax.cl (added)
+++ libclc/trunk/r600/lib/math/fmax.cl Thu Jun  7 13:27:56 2018
@@ -0,0 +1,29 @@
+#include 
+
+#include "../../../generic/lib/clcmacro.h"
+#include "../../../generic/lib/math/math.h"
+
+_CLC_DEF _CLC_OVERLOAD float fmax(float x, float y)
+{
+   /* Flush denormals if not enabled. Otherwise fmax instruction flushes
+* the values for comparison, but outputs original denormal */
+   x = __clc_flush_denormal_if_not_supported(x);
+   y = __clc_flush_denormal_if_not_supported(y);
+   return __builtin_fmaxf(x, y);
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, fmax, float, float)
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_DEF _CLC_OVERLOAD double fmax(double x, double y)
+{
+   return __builtin_fmax(x, y);
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, fmax, double, double)
+
+#endif
+
+#define __CLC_BODY <../../../generic/lib/math/fmax.inc>
+#include 


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


[libclc] r334228 - r600/fmin: Flush denormals before calling builtin.

2018-06-07 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Thu Jun  7 13:27:58 2018
New Revision: 334228

URL: http://llvm.org/viewvc/llvm-project?rev=334228&view=rev
Log:
r600/fmin: Flush denormals before calling builtin.

Same reason as amdgcn.
Fixes fmin, minmag CTS on turks.
Reviewer: Tom Stellard 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/r600/lib/math/fmin.cl
Modified:
libclc/trunk/r600/lib/SOURCES

Modified: libclc/trunk/r600/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/SOURCES?rev=334228&r1=334227&r2=334228&view=diff
==
--- libclc/trunk/r600/lib/SOURCES (original)
+++ libclc/trunk/r600/lib/SOURCES Thu Jun  7 13:27:58 2018
@@ -1,4 +1,5 @@
 math/fmax.cl
+math/fmin.cl
 synchronization/barrier_impl.ll
 workitem/get_global_offset.cl
 workitem/get_group_id.cl

Added: libclc/trunk/r600/lib/math/fmin.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/r600/lib/math/fmin.cl?rev=334228&view=auto
==
--- libclc/trunk/r600/lib/math/fmin.cl (added)
+++ libclc/trunk/r600/lib/math/fmin.cl Thu Jun  7 13:27:58 2018
@@ -0,0 +1,30 @@
+#include 
+
+#include "../../../generic/lib/clcmacro.h"
+#include "../../../generic/lib/math/math.h"
+
+_CLC_DEF _CLC_OVERLOAD float fmin(float x, float y)
+{
+   /* fcanonicalize removes sNaNs and flushes denormals if not enabled.
+* Otherwise fmin instruction flushes the values for comparison,
+* but outputs original denormal */
+   x = __clc_flush_denormal_if_not_supported(x);
+   y = __clc_flush_denormal_if_not_supported(y);
+   return __builtin_fminf(x, y);
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, float, fmin, float, float)
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_DEF _CLC_OVERLOAD double fmin(double x, double y)
+{
+   return __builtin_fmin(x, y);
+}
+_CLC_BINARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, fmin, double, double)
+
+#endif
+
+#define __CLC_BODY <../../../generic/lib/math/fmin.inc>
+#include 


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


[PATCH] D47906: [ThinLTO] Add testing of summary index parsing to a couple CFI tests

2018-06-07 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson created this revision.
tejohnson added reviewers: pcc, dexonsmith, mehdi_amini.
Herald added subscribers: steven_wu, eraman, inglorion.

Changes to some clang side tests to go with the summary parsing patch.

Depends on https://reviews.llvm.org/D47905.


Repository:
  rC Clang

https://reviews.llvm.org/D47906

Files:
  test/CodeGen/thinlto-distributed-cfi-devirt.ll
  test/CodeGen/thinlto-distributed-cfi.ll


Index: test/CodeGen/thinlto-distributed-cfi.ll
===
--- test/CodeGen/thinlto-distributed-cfi.ll
+++ test/CodeGen/thinlto-distributed-cfi.ll
@@ -21,6 +21,8 @@
 ; CHECK-LABEL: Index: test/CodeGen/thinlto-distributed-cfi.ll
===
--- test/CodeGen/thinlto-distributed-cfi.ll
+++ test/CodeGen/thinlto-distributed-cfi.ll
@@ -21,6 +21,8 @@
 ; CHECK-LABEL: ___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46922: [checks/property-decls] Fix comment in clang-tidy/objc/PropertyDeclarationCheck.cpp ✍️

2018-06-07 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added a comment.

Is it possible to get someone to land this for me? I don't believe I have 
access to land it myself.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46922



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


[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-06-07 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta added a comment.

In https://reviews.llvm.org/D47894#1125406, @efriedma wrote:

> Does IR generation need any special handling for this?  We add nonnull 
> attributes in various places.


My interpretation is adding nonnull attributes is fine as long is it is not 
derived from a pointer dereference. 
E.g. addresses from alloca can be treated non-null.


Repository:
  rC Clang

https://reviews.llvm.org/D47894



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


[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-06-07 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

The problem would come from propagating nonnull-ness from something which isn't 
inherently nonnull.  For example, strlen has a nonnull argument, so 
`strlen(NULL)` is UB, therefore given `int z = strlen(x); if (x) {...}`, we can 
remove the null check.  (Not sure we actually do this transform at the moment, 
but it's something we could do in the future.)


Repository:
  rC Clang

https://reviews.llvm.org/D47894



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


r334237 - [X86] Add builtins for VALIGNQ/VALIGND to enable proper target feature checking.

2018-06-07 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Thu Jun  7 14:27:41 2018
New Revision: 334237

URL: http://llvm.org/viewvc/llvm-project?rev=334237&view=rev
Log:
[X86] Add builtins for VALIGNQ/VALIGND to enable proper target feature checking.

We still emit shufflevector instructions we just do it from CGBuiltin.cpp now. 
This ensures the intrinsics that use this are only available on CPUs that 
support the feature.

I also added range checking to the immediate, but only checked it is 8 bits or 
smaller. We should maybe be stricter since we never use all 8 bits, but gcc 
doesn't seem to do that.

Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/avx512fintrin.h
cfe/trunk/lib/Headers/avx512vlintrin.h
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=334237&r1=334236&r2=334237&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Thu Jun  7 14:27:41 2018
@@ -909,6 +909,12 @@ TARGET_BUILTIN(__builtin_ia32_storeupd51
 TARGET_BUILTIN(__builtin_ia32_storeapd512_mask, "vV8d*V8dUc", "n", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_storeups512_mask, "vf*V16fUs", "n", "avx512f")
 TARGET_BUILTIN(__builtin_ia32_storeaps512_mask, "vV16f*V16fUs", "n", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_alignq512, "V8LLiV8LLiV8LLiIi", "nc", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_alignd512, "V16iV16iV16iIi", "nc", "avx512f")
+TARGET_BUILTIN(__builtin_ia32_alignd128, "V4iV4iV4iIi", "nc", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_alignd256, "V8iV8iV8iIi", "nc", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_alignq128, "V2LLiV2LLiV2LLiIi", "nc", "avx512vl")
+TARGET_BUILTIN(__builtin_ia32_alignq256, "V4LLiV4LLiV4LLiIi", "nc", "avx512vl")
 
 TARGET_BUILTIN(__builtin_ia32_vpdpbusd128, "V4iV4iV4iV4i", "nc", 
"avx512vl,avx512vnni")
 TARGET_BUILTIN(__builtin_ia32_vpdpbusd256, "V8iV8iV8iV8i", "nc", 
"avx512vl,avx512vnni")

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=334237&r1=334236&r2=334237&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Jun  7 14:27:41 2018
@@ -9222,6 +9222,26 @@ Value *CodeGenFunction::EmitX86BuiltinEx
makeArrayRef(Indices, NumElts),
"palignr");
   }
+  case X86::BI__builtin_ia32_alignd128:
+  case X86::BI__builtin_ia32_alignd256:
+  case X86::BI__builtin_ia32_alignd512:
+  case X86::BI__builtin_ia32_alignq128:
+  case X86::BI__builtin_ia32_alignq256:
+  case X86::BI__builtin_ia32_alignq512: {
+unsigned NumElts = Ops[0]->getType()->getVectorNumElements();
+unsigned ShiftVal = cast(Ops[2])->getZExtValue();
+
+// Mask the shift amount to width of two vectors.
+ShiftVal &= (2 * NumElts) - 1;
+
+uint32_t Indices[16];
+for (unsigned i = 0; i != NumElts; ++i)
+  Indices[i] = i + ShiftVal;
+
+return Builder.CreateShuffleVector(Ops[1], Ops[0],
+   makeArrayRef(Indices, NumElts),
+   "valign");
+  }
 
   case X86::BI__builtin_ia32_vperm2f128_pd256:
   case X86::BI__builtin_ia32_vperm2f128_ps256:

Modified: cfe/trunk/lib/Headers/avx512fintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=334237&r1=334236&r2=334237&view=diff
==
--- cfe/trunk/lib/Headers/avx512fintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512fintrin.h Thu Jun  7 14:27:41 2018
@@ -3465,16 +3465,8 @@ _mm512_maskz_permutex2var_epi64(__mmask8
 }
 
 #define _mm512_alignr_epi64(A, B, I) \
-  (__m512i)__builtin_shufflevector((__v8di)(__m512i)(B), \
-   (__v8di)(__m512i)(A), \
-   ((int)(I) & 0x7) + 0, \
-   ((int)(I) & 0x7) + 1, \
-   ((int)(I) & 0x7) + 2, \
-   ((int)(I) & 0x7) + 3, \
-   ((int)(I) & 0x7) + 4, \
-   ((int)(I) & 0x7) + 5, \
-   ((int)(I) & 0x7) + 6, \
-   ((int)(I) & 0x7) + 7)
+  (__m512i)__builtin_ia32_alignq512((__v8di)(__m512i)(A), \
+(__v8di)(__m512i)(B), (int)(I))
 
 #define _mm512_mask_alignr_epi64(W, U, A, B, imm) \
   (__m512i)__builtin_ia32_selectq_512((__mmask8)(U), \
@@ -3487,24 +3479,8 @@ _mm512_maskz_permutex2var_epi64(__mmask8
  (__v8di)_mm512_setzer

[PATCH] D46922: [checks/property-decls] Fix comment in clang-tidy/objc/PropertyDeclarationCheck.cpp ✍️

2018-06-07 Thread Ben Hamilton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334238: [checks/property-decls] Fix comment in 
clang-tidy/objc/PropertyDeclarationCheck. (authored by benhamilton, committed 
by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46922?vs=146981&id=150409#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46922

Files:
  clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp


Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -34,7 +34,7 @@
   CategoryProperty = 2,
 };
 
-/// The acronyms are from
+/// The acronyms are aggregated from multiple sources including
 /// 
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE
 ///
 /// Keep this list sorted.


Index: clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/objc/PropertyDeclarationCheck.cpp
@@ -34,7 +34,7 @@
   CategoryProperty = 2,
 };
 
-/// The acronyms are from
+/// The acronyms are aggregated from multiple sources including
 /// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/APIAbbreviations.html#//apple_ref/doc/uid/20001285-BCIHCGAE
 ///
 /// Keep this list sorted.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46922: [checks/property-decls] Fix comment in clang-tidy/objc/PropertyDeclarationCheck.cpp ✍️

2018-06-07 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added a comment.

> Is it possible to get someone to land this for me? I don't believe I have 
> access to land it myself.

Done.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D46922



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


r334239 - [MS] Re-add support for the ARM interlocked bittest intrinscs

2018-06-07 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Thu Jun  7 14:39:04 2018
New Revision: 334239

URL: http://llvm.org/viewvc/llvm-project?rev=334239&view=rev
Log:
[MS] Re-add support for the ARM interlocked bittest intrinscs

Adds support for these intrinsics, which are ARM and ARM64 only:
  _interlockedbittestandreset_acq
  _interlockedbittestandreset_rel
  _interlockedbittestandreset_nf
  _interlockedbittestandset_acq
  _interlockedbittestandset_rel
  _interlockedbittestandset_nf

Refactor the bittest intrinsic handling to decompose each intrinsic into
its action, its width, and its atomicity.

Added:
cfe/trunk/test/Sema/bittest-intrinsics.c
Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/intrin.h
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGen/bittest-intrin.c

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=334239&r1=334238&r2=334239&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Thu Jun  7 14:39:04 2018
@@ -791,10 +791,16 @@ LANGBUILTIN(_InterlockedOr,   "NiNiD*Ni"
 LANGBUILTIN(_InterlockedXor8,  "ccD*c",   "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedXor16, "ssD*s",   "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(_InterlockedXor,   "NiNiD*Ni","n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_interlockedbittestandreset,   "UcNiD*Ni", "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_interlockedbittestandreset64, "UcWiD*Wi", "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_interlockedbittestandset,   "UcNiD*Ni", "n", ALL_MS_LANGUAGES)
-LANGBUILTIN(_interlockedbittestandset64, "UcWiD*Wi", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_interlockedbittestandreset, "UcNiD*Ni", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_interlockedbittestandreset64,   "UcWiD*Wi", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_interlockedbittestandreset_acq, "UcNiD*Ni", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_interlockedbittestandreset_nf,  "UcNiD*Ni", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_interlockedbittestandreset_rel, "UcNiD*Ni", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_interlockedbittestandset,   "UcNiD*Ni", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_interlockedbittestandset64, "UcWiD*Wi", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_interlockedbittestandset_acq,   "UcNiD*Ni", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_interlockedbittestandset_nf,"UcNiD*Ni", "n", ALL_MS_LANGUAGES)
+LANGBUILTIN(_interlockedbittestandset_rel,   "UcNiD*Ni", "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__noop,   "i.",  "n", ALL_MS_LANGUAGES)
 LANGBUILTIN(__popcnt16, "UsUs", "nc", ALL_MS_LANGUAGES)
 LANGBUILTIN(__popcnt,   "UiUi", "nc", ALL_MS_LANGUAGES)

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=334239&r1=334238&r2=334239&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jun  7 14:39:04 
2018
@@ -8154,6 +8154,8 @@ def err_x86_builtin_invalid_rounding : E
   "invalid rounding argument">;
 def err_x86_builtin_invalid_scale : Error<
   "scale argument must be 1, 2, 4, or 8">;
+def err_builtin_target_unsupported : Error<
+  "builtin is not supported on this target">;
 
 def err_builtin_longjmp_unsupported : Error<
   "__builtin_longjmp is not supported for the current target">;

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=334239&r1=334238&r2=334239&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Jun  7 14:39:04 2018
@@ -484,58 +484,99 @@ CodeGenFunction::emitBuiltinObjectSize(c
   return Builder.CreateCall(F, {Ptr, Min, NullIsUnknown});
 }
 
-// Get properties of an X86 BT* assembly instruction. The first returned value
-// is the action character code, which can be for complement, reset, or set. 
The
-// second is the size suffix which our assembler needs. The last is whether to
-// add the lock prefix.
-static std::tuple
-getBitTestActionSizeAndLocking(unsigned BuiltinID) {
+namespace {
+/// A struct to generically desribe a bit test intrinsic.
+struct BitTest {
+  enum ActionKind : uint8_t { TestOnly, Complement, Reset, Set };
+  enum InterlockingKind : uint8_t {
+Unlocked,
+Sequential,
+Acquire,
+Release,
+NoFence
+  };
+
+  ActionKind Action;
+  InterlockingKind Interlocking;
+  bool Is64Bit;
+
+  static BitTest decodeBitTestBuiltin(unsigned BuiltinID);
+};
+} // namespace
+
+BitTest BitTest::decodeBitTestBuiltin(unsigned Builti

[PATCH] D47894: [clang]: Add support for "-fno-delete-null-pointer-checks"

2018-06-07 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

For the kernel, specifically, strlen() isn't an issue because it builds with 
-fno-builtin, but the kernel uses explicit nonnull attributes in a few places.  
But I guess we can assume they know what they're doing if nonnull is explicitly 
specified. 
 We probably want to call this out in the users manual, though.

We add nonnull attributes to the LLVM IR in a few other places which don't 
involve the C nonnull attribute: we assume C++ references are always non-null, 
and we use the "static" array modifier to assume arrays are non-null.  We 
probably shouldn't add those attributes if fno-delete-null-pointer-checks is 
specified.


Repository:
  rC Clang

https://reviews.llvm.org/D47894



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


Re: r333978 - Reimplement the bittest intrinsic family as builtins with inline asm

2018-06-07 Thread Reid Kleckner via cfe-commits
This should be fixed now with r334239. In for a penny, in for a pound.

On Wed, Jun 6, 2018 at 6:09 PM Grang, Mandeep Singh 
wrote:

> @rnk I tried building spec2000/eon for Windows ARM64 and ran into these
> errors:
>
> use of undeclared identifier '_interlockedbittestandset_acq'
> use of undeclared identifier '_interlockedbittestandset_rel'
> use of undeclared identifier '_interlockedbittestandset_nf'
>
> I see that you have removed them in your patch. Apparently they are needed
> (at least for ARM64 Win).
>
> --Mandeep
>
> On 6/5/2018 11:01 AM, Reid Kleckner via cfe-commits wrote:
>
> On Tue, Jun 5, 2018 at 2:33 AM Martin Storsjö  wrote:
>
>> > // Many of MSVC builtins are on both x64 and ARM; to avoid repeating
>> code, we
>> > // handle them here.
>>
>> This doesn't seem thought through wrt non-x86 architectures. I'm not sure
>> if there's any similar suitable instruction to use on ARM/AArch64, but we
>> should at the very least fall back to doing whatever we did before this
>> change for anything not x86.
>>
>
>  I'll go back and take a look, but I'm not convinced that what we did
> before was correct for ARM either. I'm installing the Visual C++ aarch64
> compiler now so I can make sure we get it right.
>
>
> ___
> cfe-commits mailing 
> listcfe-comm...@lists.llvm.orghttp://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


  1   2   >