r363230 - clang-format extension: Widen the supported versions range

2019-06-13 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Thu Jun 13 00:07:24 2019
New Revision: 363230

URL: http://llvm.org/viewvc/llvm-project?rev=363230&view=rev
Log:
clang-format extension: Widen the supported versions range

So that it covers also the latest VS 2019 version.

By Antonio Maiorano!

Modified:
cfe/trunk/tools/clang-format-vs/source.extension.vsixmanifest.in

Modified: cfe/trunk/tools/clang-format-vs/source.extension.vsixmanifest.in
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format-vs/source.extension.vsixmanifest.in?rev=363230&r1=363229&r2=363230&view=diff
==
--- cfe/trunk/tools/clang-format-vs/source.extension.vsixmanifest.in (original)
+++ cfe/trunk/tools/clang-format-vs/source.extension.vsixmanifest.in Thu Jun 13 
00:07:24 2019
@@ -8,7 +8,7 @@
 license.txt
   
   
-
+
   
   
 


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


[PATCH] D63149: Added AST matcher for ignoring elidable constructors

2019-06-13 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 204437.
jvikstrom marked an inline comment as done.
jvikstrom added a comment.

- Added default to switch for language modes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63149

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTest.h

Index: clang/unittests/ASTMatchers/ASTMatchersTest.h
===
--- clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -13,6 +13,7 @@
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Tooling/Tooling.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace ast_matchers {
@@ -57,6 +58,17 @@
   const std::unique_ptr FindResultReviewer;
 };
 
+enum class LanguageMode {
+  Cxx11,
+  Cxx14,
+  Cxx17,
+  Cxx2a,
+  Cxx11OrLater,
+  Cxx14OrLater,
+  Cxx17OrLater,
+  Cxx2aOrLater
+};
+
 template 
 testing::AssertionResult matchesConditionally(
 const std::string &Code, const T &AMatcher, bool ExpectMatch,
@@ -116,14 +128,72 @@
 }
 
 template 
-testing::AssertionResult matches(const std::string &Code, const T &AMatcher) {
-  return matchesConditionally(Code, AMatcher, true, "-std=c++11");
+testing::AssertionResult
+matchesConditionally(const std::string &Code, const T &AMatcher,
+ bool ExpectMatch, const LanguageMode &Mode) {
+  std::vector LangModes;
+  switch (Mode) {
+  case LanguageMode::Cxx11:
+  case LanguageMode::Cxx14:
+  case LanguageMode::Cxx17:
+  case LanguageMode::Cxx2a:
+LangModes = {Mode};
+break;
+  case LanguageMode::Cxx11OrLater:
+LangModes = {LanguageMode::Cxx11, LanguageMode::Cxx14, LanguageMode::Cxx17,
+ LanguageMode::Cxx2a};
+break;
+  case LanguageMode::Cxx14OrLater:
+LangModes = {LanguageMode::Cxx14, LanguageMode::Cxx17, LanguageMode::Cxx2a};
+break;
+  case LanguageMode::Cxx17OrLater:
+LangModes = {LanguageMode::Cxx17, LanguageMode::Cxx2a};
+break;
+  case LanguageMode::Cxx2aOrLater:
+LangModes = {LanguageMode::Cxx2a};
+  }
+
+  for (auto Mode : LangModes) {
+std::string LangModeArg;
+switch (Mode) {
+case LanguageMode::Cxx11:
+  LangModeArg = "-std=c++11";
+  break;
+case LanguageMode::Cxx14:
+  LangModeArg = "-std=c++14";
+  break;
+case LanguageMode::Cxx17:
+  LangModeArg = "-std=c++17";
+  break;
+case LanguageMode::Cxx2a:
+  LangModeArg = "-std=c++2a";
+  break;
+default:
+  llvm_unreachable("Invalid language mode");
+}
+
+auto Result =
+matchesConditionally(Code, AMatcher, ExpectMatch, LangModeArg);
+if (!Result) {
+  return Result;
+}
+  }
+
+  return testing::AssertionSuccess();
 }
 
 template 
-testing::AssertionResult notMatches(const std::string &Code,
-const T &AMatcher) {
-  return matchesConditionally(Code, AMatcher, false, "-std=c++11");
+testing::AssertionResult
+matches(const std::string &Code, const T &AMatcher,
+const LanguageMode &Modes = LanguageMode::Cxx11) {
+  return matchesConditionally(Code, AMatcher, true, Modes);
+}
+
+template 
+testing::AssertionResult
+notMatches(const std::string &Code, const T &AMatcher,
+   const LanguageMode &Modes = LanguageMode::Cxx11) {
+  return matchesConditionally(Code, AMatcher, false, Modes);
 }
 
 template 
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -566,6 +566,74 @@
llvm::make_unique>("x")));
 }
 
+TEST(Matcher, IgnoresElidableConstructors) {
+  EXPECT_TRUE(
+  matches("struct H {};"
+  "template H B(T A);"
+  "void f() {"
+  "  H D1;"
+  "  D1 = B(B(1));"
+  "}",
+  cxxOperatorCallExpr(hasArgument(
+  1, callExpr(hasArgument(
+ 0, ignoringElidableConstructorCall(callExpr()),
+  LanguageMode::Cxx11OrLater));
+  EXPECT_TRUE(
+  matches("struct H {};"
+  "template H B(T A);"
+  "void f() {"
+  "  H D1;"
+  "  D1 = B(1);"
+  "}",
+  cxxOperatorCallExpr(hasArgument(
+  1, callExpr(hasArgument(0, ignoringElidableConstructorCall(
+ integerLiteral()),
+  LanguageMode::Cxx11OrLater));
+  EXPECT_TRUE(matches(
+  "struct H {};"
+  "H G();"
+  "void f() {"
+  "  H D = G();"
+  "}",
+  varDecl(hasInitializ

[PATCH] D63227: [analyzer] Better timers.

2019-06-13 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.
This revision is now accepted and ready to land.

Looks good :) More diagnostics are always welcome.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63227



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


[PATCH] D63227: [analyzer] Better timers.

2019-06-13 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:228
 
-ExprEngine::~ExprEngine() {
-  BR.FlushReports();

Hmm. Maybe add an assert that all the bug reports are flushed at this point? 
Just to make sure we never need this :) I am not insisting on this change just 
wondering.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63227



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


[PATCH] D63149: Added AST matcher for ignoring elidable constructors

2019-06-13 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 204442.
jvikstrom added a comment.

- Updated outdated docs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63149

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTest.h

Index: clang/unittests/ASTMatchers/ASTMatchersTest.h
===
--- clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -13,6 +13,7 @@
 #include "clang/Frontend/ASTUnit.h"
 #include "clang/Tooling/Tooling.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace ast_matchers {
@@ -57,6 +58,17 @@
   const std::unique_ptr FindResultReviewer;
 };
 
+enum class LanguageMode {
+  Cxx11,
+  Cxx14,
+  Cxx17,
+  Cxx2a,
+  Cxx11OrLater,
+  Cxx14OrLater,
+  Cxx17OrLater,
+  Cxx2aOrLater
+};
+
 template 
 testing::AssertionResult matchesConditionally(
 const std::string &Code, const T &AMatcher, bool ExpectMatch,
@@ -116,14 +128,72 @@
 }
 
 template 
-testing::AssertionResult matches(const std::string &Code, const T &AMatcher) {
-  return matchesConditionally(Code, AMatcher, true, "-std=c++11");
+testing::AssertionResult
+matchesConditionally(const std::string &Code, const T &AMatcher,
+ bool ExpectMatch, const LanguageMode &Mode) {
+  std::vector LangModes;
+  switch (Mode) {
+  case LanguageMode::Cxx11:
+  case LanguageMode::Cxx14:
+  case LanguageMode::Cxx17:
+  case LanguageMode::Cxx2a:
+LangModes = {Mode};
+break;
+  case LanguageMode::Cxx11OrLater:
+LangModes = {LanguageMode::Cxx11, LanguageMode::Cxx14, LanguageMode::Cxx17,
+ LanguageMode::Cxx2a};
+break;
+  case LanguageMode::Cxx14OrLater:
+LangModes = {LanguageMode::Cxx14, LanguageMode::Cxx17, LanguageMode::Cxx2a};
+break;
+  case LanguageMode::Cxx17OrLater:
+LangModes = {LanguageMode::Cxx17, LanguageMode::Cxx2a};
+break;
+  case LanguageMode::Cxx2aOrLater:
+LangModes = {LanguageMode::Cxx2a};
+  }
+
+  for (auto Mode : LangModes) {
+std::string LangModeArg;
+switch (Mode) {
+case LanguageMode::Cxx11:
+  LangModeArg = "-std=c++11";
+  break;
+case LanguageMode::Cxx14:
+  LangModeArg = "-std=c++14";
+  break;
+case LanguageMode::Cxx17:
+  LangModeArg = "-std=c++17";
+  break;
+case LanguageMode::Cxx2a:
+  LangModeArg = "-std=c++2a";
+  break;
+default:
+  llvm_unreachable("Invalid language mode");
+}
+
+auto Result =
+matchesConditionally(Code, AMatcher, ExpectMatch, LangModeArg);
+if (!Result) {
+  return Result;
+}
+  }
+
+  return testing::AssertionSuccess();
 }
 
 template 
-testing::AssertionResult notMatches(const std::string &Code,
-const T &AMatcher) {
-  return matchesConditionally(Code, AMatcher, false, "-std=c++11");
+testing::AssertionResult
+matches(const std::string &Code, const T &AMatcher,
+const LanguageMode &Modes = LanguageMode::Cxx11) {
+  return matchesConditionally(Code, AMatcher, true, Modes);
+}
+
+template 
+testing::AssertionResult
+notMatches(const std::string &Code, const T &AMatcher,
+   const LanguageMode &Modes = LanguageMode::Cxx11) {
+  return matchesConditionally(Code, AMatcher, false, Modes);
 }
 
 template 
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -566,6 +566,74 @@
llvm::make_unique>("x")));
 }
 
+TEST(Matcher, IgnoresElidableConstructors) {
+  EXPECT_TRUE(
+  matches("struct H {};"
+  "template H B(T A);"
+  "void f() {"
+  "  H D1;"
+  "  D1 = B(B(1));"
+  "}",
+  cxxOperatorCallExpr(hasArgument(
+  1, callExpr(hasArgument(
+ 0, ignoringElidableConstructorCall(callExpr()),
+  LanguageMode::Cxx11OrLater));
+  EXPECT_TRUE(
+  matches("struct H {};"
+  "template H B(T A);"
+  "void f() {"
+  "  H D1;"
+  "  D1 = B(1);"
+  "}",
+  cxxOperatorCallExpr(hasArgument(
+  1, callExpr(hasArgument(0, ignoringElidableConstructorCall(
+ integerLiteral()),
+  LanguageMode::Cxx11OrLater));
+  EXPECT_TRUE(matches(
+  "struct H {};"
+  "H G();"
+  "void f() {"
+  "  H D = G();"
+  "}",
+  varDecl(hasInitializer(anyOf(
+  ignoringElidableConstructorCall(callExpr()),

[PATCH] D63149: Added AST matcher for ignoring elidable constructors

2019-06-13 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 204443.
jvikstrom marked an inline comment as done.
jvikstrom added a comment.

- Removed dependency on unordered map


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63149

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTest.h

Index: clang/unittests/ASTMatchers/ASTMatchersTest.h
===
--- clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -57,6 +57,17 @@
   const std::unique_ptr FindResultReviewer;
 };
 
+enum class LanguageMode {
+  Cxx11,
+  Cxx14,
+  Cxx17,
+  Cxx2a,
+  Cxx11OrLater,
+  Cxx14OrLater,
+  Cxx17OrLater,
+  Cxx2aOrLater
+};
+
 template 
 testing::AssertionResult matchesConditionally(
 const std::string &Code, const T &AMatcher, bool ExpectMatch,
@@ -116,14 +127,72 @@
 }
 
 template 
-testing::AssertionResult matches(const std::string &Code, const T &AMatcher) {
-  return matchesConditionally(Code, AMatcher, true, "-std=c++11");
+testing::AssertionResult
+matchesConditionally(const std::string &Code, const T &AMatcher,
+ bool ExpectMatch, const LanguageMode &Mode) {
+  std::vector LangModes;
+  switch (Mode) {
+  case LanguageMode::Cxx11:
+  case LanguageMode::Cxx14:
+  case LanguageMode::Cxx17:
+  case LanguageMode::Cxx2a:
+LangModes = {Mode};
+break;
+  case LanguageMode::Cxx11OrLater:
+LangModes = {LanguageMode::Cxx11, LanguageMode::Cxx14, LanguageMode::Cxx17,
+ LanguageMode::Cxx2a};
+break;
+  case LanguageMode::Cxx14OrLater:
+LangModes = {LanguageMode::Cxx14, LanguageMode::Cxx17, LanguageMode::Cxx2a};
+break;
+  case LanguageMode::Cxx17OrLater:
+LangModes = {LanguageMode::Cxx17, LanguageMode::Cxx2a};
+break;
+  case LanguageMode::Cxx2aOrLater:
+LangModes = {LanguageMode::Cxx2a};
+  }
+
+  for (auto Mode : LangModes) {
+std::string LangModeArg;
+switch (Mode) {
+case LanguageMode::Cxx11:
+  LangModeArg = "-std=c++11";
+  break;
+case LanguageMode::Cxx14:
+  LangModeArg = "-std=c++14";
+  break;
+case LanguageMode::Cxx17:
+  LangModeArg = "-std=c++17";
+  break;
+case LanguageMode::Cxx2a:
+  LangModeArg = "-std=c++2a";
+  break;
+default:
+  llvm_unreachable("Invalid language mode");
+}
+
+auto Result =
+matchesConditionally(Code, AMatcher, ExpectMatch, LangModeArg);
+if (!Result) {
+  return Result;
+}
+  }
+
+  return testing::AssertionSuccess();
 }
 
 template 
-testing::AssertionResult notMatches(const std::string &Code,
-const T &AMatcher) {
-  return matchesConditionally(Code, AMatcher, false, "-std=c++11");
+testing::AssertionResult
+matches(const std::string &Code, const T &AMatcher,
+const LanguageMode &Modes = LanguageMode::Cxx11) {
+  return matchesConditionally(Code, AMatcher, true, Modes);
+}
+
+template 
+testing::AssertionResult
+notMatches(const std::string &Code, const T &AMatcher,
+   const LanguageMode &Modes = LanguageMode::Cxx11) {
+  return matchesConditionally(Code, AMatcher, false, Modes);
 }
 
 template 
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -566,6 +566,74 @@
llvm::make_unique>("x")));
 }
 
+TEST(Matcher, IgnoresElidableConstructors) {
+  EXPECT_TRUE(
+  matches("struct H {};"
+  "template H B(T A);"
+  "void f() {"
+  "  H D1;"
+  "  D1 = B(B(1));"
+  "}",
+  cxxOperatorCallExpr(hasArgument(
+  1, callExpr(hasArgument(
+ 0, ignoringElidableConstructorCall(callExpr()),
+  LanguageMode::Cxx11OrLater));
+  EXPECT_TRUE(
+  matches("struct H {};"
+  "template H B(T A);"
+  "void f() {"
+  "  H D1;"
+  "  D1 = B(1);"
+  "}",
+  cxxOperatorCallExpr(hasArgument(
+  1, callExpr(hasArgument(0, ignoringElidableConstructorCall(
+ integerLiteral()),
+  LanguageMode::Cxx11OrLater));
+  EXPECT_TRUE(matches(
+  "struct H {};"
+  "H G();"
+  "void f() {"
+  "  H D = G();"
+  "}",
+  varDecl(hasInitializer(anyOf(
+  ignoringElidableConstructorCall(callExpr()),
+  exprWithCleanups(has(ignoringElidableConstructorCall(callExpr())),
+  LanguageMode::Cxx11OrLater)

[PATCH] D63149: Added AST matcher for ignoring elidable constructors

2019-06-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

looks most good to me, a few nits.




Comment at: clang/include/clang/ASTMatchers/ASTMatchers.h:6488
+  }
+  return InnerMatcher.matches(*CtorExpr, Finder, Builder);
+}

This `return` statement is not needed.



Comment at: clang/unittests/ASTMatchers/ASTMatchersTest.h:16
 #include "gtest/gtest.h"
+#include 
 

looks like the `include` is not used?



Comment at: clang/unittests/ASTMatchers/ASTMatchersTest.h:153
+  case LanguageMode::Cxx2aOrLater:
+LangModes = {LanguageMode::Cxx2a};
+  }

nit: add a llvm_unreachable for `default`.



Comment at: clang/unittests/ASTMatchers/ASTMatchersTest.h:177
+matchesConditionally(Code, AMatcher, ExpectMatch, LangModeArg);
+if (!Result) {
+  return Result;

nit: no `{}` needed for a single-statement body.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63149



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


[PATCH] D63149: Added AST matcher for ignoring elidable constructors

2019-06-13 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 204447.
jvikstrom marked 3 inline comments as done.
jvikstrom added a comment.

- Removed unnecessary return


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63149

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTest.h

Index: clang/unittests/ASTMatchers/ASTMatchersTest.h
===
--- clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -57,6 +57,17 @@
   const std::unique_ptr FindResultReviewer;
 };
 
+enum class LanguageMode {
+  Cxx11,
+  Cxx14,
+  Cxx17,
+  Cxx2a,
+  Cxx11OrLater,
+  Cxx14OrLater,
+  Cxx17OrLater,
+  Cxx2aOrLater
+};
+
 template 
 testing::AssertionResult matchesConditionally(
 const std::string &Code, const T &AMatcher, bool ExpectMatch,
@@ -116,14 +127,71 @@
 }
 
 template 
-testing::AssertionResult matches(const std::string &Code, const T &AMatcher) {
-  return matchesConditionally(Code, AMatcher, true, "-std=c++11");
+testing::AssertionResult
+matchesConditionally(const std::string &Code, const T &AMatcher,
+ bool ExpectMatch, const LanguageMode &Mode) {
+  std::vector LangModes;
+  switch (Mode) {
+  case LanguageMode::Cxx11:
+  case LanguageMode::Cxx14:
+  case LanguageMode::Cxx17:
+  case LanguageMode::Cxx2a:
+LangModes = {Mode};
+break;
+  case LanguageMode::Cxx11OrLater:
+LangModes = {LanguageMode::Cxx11, LanguageMode::Cxx14, LanguageMode::Cxx17,
+ LanguageMode::Cxx2a};
+break;
+  case LanguageMode::Cxx14OrLater:
+LangModes = {LanguageMode::Cxx14, LanguageMode::Cxx17, LanguageMode::Cxx2a};
+break;
+  case LanguageMode::Cxx17OrLater:
+LangModes = {LanguageMode::Cxx17, LanguageMode::Cxx2a};
+break;
+  case LanguageMode::Cxx2aOrLater:
+LangModes = {LanguageMode::Cxx2a};
+  }
+
+  for (auto Mode : LangModes) {
+std::string LangModeArg;
+switch (Mode) {
+case LanguageMode::Cxx11:
+  LangModeArg = "-std=c++11";
+  break;
+case LanguageMode::Cxx14:
+  LangModeArg = "-std=c++14";
+  break;
+case LanguageMode::Cxx17:
+  LangModeArg = "-std=c++17";
+  break;
+case LanguageMode::Cxx2a:
+  LangModeArg = "-std=c++2a";
+  break;
+default:
+  llvm_unreachable("Invalid language mode");
+}
+
+auto Result =
+matchesConditionally(Code, AMatcher, ExpectMatch, LangModeArg);
+if (!Result)
+  return Result;
+  }
+
+  return testing::AssertionSuccess();
+}
+
+template 
+testing::AssertionResult
+matches(const std::string &Code, const T &AMatcher,
+const LanguageMode &Modes = LanguageMode::Cxx11) {
+  return matchesConditionally(Code, AMatcher, true, Modes);
 }
 
 template 
-testing::AssertionResult notMatches(const std::string &Code,
-const T &AMatcher) {
-  return matchesConditionally(Code, AMatcher, false, "-std=c++11");
+testing::AssertionResult
+notMatches(const std::string &Code, const T &AMatcher,
+   const LanguageMode &Modes = LanguageMode::Cxx11) {
+  return matchesConditionally(Code, AMatcher, false, Modes);
 }
 
 template 
Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -566,6 +566,74 @@
llvm::make_unique>("x")));
 }
 
+TEST(Matcher, IgnoresElidableConstructors) {
+  EXPECT_TRUE(
+  matches("struct H {};"
+  "template H B(T A);"
+  "void f() {"
+  "  H D1;"
+  "  D1 = B(B(1));"
+  "}",
+  cxxOperatorCallExpr(hasArgument(
+  1, callExpr(hasArgument(
+ 0, ignoringElidableConstructorCall(callExpr()),
+  LanguageMode::Cxx11OrLater));
+  EXPECT_TRUE(
+  matches("struct H {};"
+  "template H B(T A);"
+  "void f() {"
+  "  H D1;"
+  "  D1 = B(1);"
+  "}",
+  cxxOperatorCallExpr(hasArgument(
+  1, callExpr(hasArgument(0, ignoringElidableConstructorCall(
+ integerLiteral()),
+  LanguageMode::Cxx11OrLater));
+  EXPECT_TRUE(matches(
+  "struct H {};"
+  "H G();"
+  "void f() {"
+  "  H D = G();"
+  "}",
+  varDecl(hasInitializer(anyOf(
+  ignoringElidableConstructorCall(callExpr()),
+  exprWithCleanups(has(ignoringElidableConstructorCall(callExpr())),
+  LanguageMode::Cxx11OrLater));
+}
+
+TEST(Matc

[PATCH] D63245: clang-scan-deps: Fix -DBUILD_SHARED_LIBS=ON build

2019-06-13 Thread Sam Clegg via Phabricator via cfe-commits
sbc100 created this revision.
Herald added subscribers: cfe-commits, tschuett, aheejin, mgorny.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63245

Files:
  clang/tools/clang-scan-deps/CMakeLists.txt


Index: clang/tools/clang-scan-deps/CMakeLists.txt
===
--- clang/tools/clang-scan-deps/CMakeLists.txt
+++ clang/tools/clang-scan-deps/CMakeLists.txt
@@ -16,6 +16,7 @@
   clangFrontendTool
   clangLex
   clangParse
+  clangSerialization
   clangTooling
   )
 


Index: clang/tools/clang-scan-deps/CMakeLists.txt
===
--- clang/tools/clang-scan-deps/CMakeLists.txt
+++ clang/tools/clang-scan-deps/CMakeLists.txt
@@ -16,6 +16,7 @@
   clangFrontendTool
   clangLex
   clangParse
+  clangSerialization
   clangTooling
   )
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63222: [Clangd] Fixed clangd diagnostics priority

2019-06-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Mostly LG, just a few re-orderings to make code more readable and get rid of 
redundant Lexer calls.




Comment at: clang-tools-extra/clangd/Diagnostics.cpp:108
+  // Otherwise use zero width insertion range
   auto R = Lexer::makeFileCharRange(CharSourceRange::getTokenRange(Loc), M, L);
+  if (R.isValid()) {

since we are going to lex again in case of `R.isValid()`, you can get rid of 
this lexer call.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:109
   auto R = Lexer::makeFileCharRange(CharSourceRange::getTokenRange(Loc), M, L);
-  if (!R.isValid()) // Fall back to location only, let the editor deal with it.
+  if (R.isValid()) {
+// check if token at location is a priority i.e. not a comment

let's change this condition to rather check for `Lexer::getRawToken` succeeded 
and underlying token `isNot(tok::comment)`.
Then you can simply construct the range with 
`CharSourceRange::getTokenRange(Tok.getLocation(), Tok.getEndLoc())`.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:111
+// check if token at location is a priority i.e. not a comment
+Token token;
+bool isTokenPriority = false;

LLVM style uses `UpperCammelCase` for variable names. so this should be 
something like, `Token Tok;`, same for the bool below.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:119
+  else if (FallbackRange)
+return *FallbackRange;
+  else // Fall back to location only, let the editor deal with it.

the FallbackRange(if set) and `CharSourceRange::getCharRange(Loc);` are the 
same.

So you can get rid of `FallbackRange` and merge the last two branches of this 
conditional.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D63222



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


[PATCH] D62839: [clangd] Index API and implementations for relations

2019-06-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/Index.h:77
+struct RelationsRequest {
+  SymbolID Subject;
+  index::SymbolRole Predicate;

nridge wrote:
> kadircet wrote:
> > sorry for missing it in previous iteration. but this should also enable 
> > batch queries. let's make this one a `llvm::DenseMap`.
> > And in the callback we should output both the `SymbolID` of the `Subject` 
> > and `Object`.
> > 
> > We have a network based index(internally) and it uses this batch query 
> > optimization to get rid of network latency.
> What is an example use case for a batch query? In a typical LSP editor, the 
> user can only request a type hierarchy for one class at a time.
yes, that's not really applicable to TypeHierarchy, but we are rather 
introducing another endpoint to an existing API(`SymbolIndex`), which will be 
used by a lot more clients later on.

The first example that comes to my mind is, fetching all overrides of a class' 
virtual methods for example.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62839



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


[clang-tools-extra] r363237 - [clangd] Treat lambdas as functions when preparing hover response

2019-06-13 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Jun 13 01:51:44 2019
New Revision: 363237

URL: http://llvm.org/viewvc/llvm-project?rev=363237&view=rev
Log:
[clangd] Treat lambdas as functions when preparing hover response

Reviewers: sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

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

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

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=363237&r1=363236&r2=363237&view=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Thu Jun 13 01:51:44 2019
@@ -19,7 +19,9 @@
 #include "index/SymbolLocation.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
@@ -620,6 +622,23 @@ static llvm::Optional getTokenRan
  CharSourceRange::getCharRange(Loc, End));
 }
 
+static const FunctionDecl *getUnderlyingFunction(const Decl *D) {
+  // Extract lambda from variables.
+  if (const VarDecl *VD = llvm::dyn_cast(D)) {
+auto QT = VD->getType();
+if (!QT.isNull()) {
+  while (!QT->getPointeeType().isNull())
+QT = QT->getPointeeType();
+
+  if (const auto *CD = QT->getAsCXXRecordDecl())
+return CD->getLambdaCallOperator();
+}
+  }
+
+  // Non-lambda functions.
+  return D->getAsFunction();
+}
+
 /// Generate a \p Hover object given the declaration \p D.
 static HoverInfo getHoverContents(const Decl *D) {
   HoverInfo HI;
@@ -654,27 +673,21 @@ static HoverInfo getHoverContents(const
   }
 
   // Fill in types and params.
-  if (const FunctionDecl *FD = D->getAsFunction()) {
+  if (const FunctionDecl *FD = getUnderlyingFunction(D)) {
 HI.ReturnType.emplace();
-llvm::raw_string_ostream OS(*HI.ReturnType);
-FD->getReturnType().print(OS, Policy);
-
-HI.Type.emplace();
-llvm::raw_string_ostream TypeOS(*HI.Type);
-FD->getReturnType().print(TypeOS, Policy);
-TypeOS << '(';
+{
+  llvm::raw_string_ostream OS(*HI.ReturnType);
+  FD->getReturnType().print(OS, Policy);
+}
 
 HI.Parameters.emplace();
 for (const ParmVarDecl *PVD : FD->parameters()) {
-  if (HI.Parameters->size())
-TypeOS << ", ";
   HI.Parameters->emplace_back();
   auto &P = HI.Parameters->back();
   if (!PVD->getType().isNull()) {
 P.Type.emplace();
 llvm::raw_string_ostream OS(*P.Type);
 PVD->getType().print(OS, Policy);
-PVD->getType().print(TypeOS, Policy);
   } else {
 std::string Param;
 llvm::raw_string_ostream OS(Param);
@@ -690,11 +703,17 @@ static HoverInfo getHoverContents(const
 PVD->getDefaultArg()->printPretty(Out, nullptr, Policy);
   }
 }
-TypeOS << ')';
+
+HI.Type.emplace();
+llvm::raw_string_ostream TypeOS(*HI.Type);
+// Lambdas
+if (const VarDecl *VD = llvm::dyn_cast(D))
+  VD->getType().getDesugaredType(D->getASTContext()).print(TypeOS, Policy);
+// Functions
+else
+  FD->getType().print(TypeOS, Policy);
 // FIXME: handle variadics.
   } else if (const auto *VD = dyn_cast(D)) {
-// FIXME: Currently lambdas are also handled as ValueDecls, they should be
-// more similar to functions.
 HI.Type.emplace();
 llvm::raw_string_ostream OS(*HI.Type);
 VD->getType().print(OS, Policy);

Modified: clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp?rev=363237&r1=363236&r2=363237&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp Thu Jun 13 01:51:44 
2019
@@ -22,6 +22,7 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -588,7 +589,7 @@ TEST(Hover, Structured) {
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
  HI.ReturnType = "void";
- HI.Type = "void()";
+ HI.Type = "void ()";
  HI.Parameters.emplace();
}},
   // Inside namespace
@@ -605,7 +606,7 @@ TEST(Hover, Structured) {
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
  HI.ReturnType = "void";
- HI.Type = "void()";
+ HI.Type = "void ()";
  HI.Parameters.emplace();
}},
   // Field
@@ -733,7 +734,7 @@ clas

[PATCH] D62814: [clangd] Treat lambdas as functions when preparing hover response

2019-06-13 Thread Kadir Cetinkaya 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 rL363237: [clangd] Treat lambdas as functions when preparing 
hover response (authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62814?vs=203533&id=204449#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D62814

Files:
  clang-tools-extra/trunk/clangd/XRefs.cpp
  clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/trunk/clangd/XRefs.cpp
===
--- clang-tools-extra/trunk/clangd/XRefs.cpp
+++ clang-tools-extra/trunk/clangd/XRefs.cpp
@@ -19,7 +19,9 @@
 #include "index/SymbolLocation.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
@@ -620,6 +622,23 @@
  CharSourceRange::getCharRange(Loc, End));
 }
 
+static const FunctionDecl *getUnderlyingFunction(const Decl *D) {
+  // Extract lambda from variables.
+  if (const VarDecl *VD = llvm::dyn_cast(D)) {
+auto QT = VD->getType();
+if (!QT.isNull()) {
+  while (!QT->getPointeeType().isNull())
+QT = QT->getPointeeType();
+
+  if (const auto *CD = QT->getAsCXXRecordDecl())
+return CD->getLambdaCallOperator();
+}
+  }
+
+  // Non-lambda functions.
+  return D->getAsFunction();
+}
+
 /// Generate a \p Hover object given the declaration \p D.
 static HoverInfo getHoverContents(const Decl *D) {
   HoverInfo HI;
@@ -654,27 +673,21 @@
   }
 
   // Fill in types and params.
-  if (const FunctionDecl *FD = D->getAsFunction()) {
+  if (const FunctionDecl *FD = getUnderlyingFunction(D)) {
 HI.ReturnType.emplace();
-llvm::raw_string_ostream OS(*HI.ReturnType);
-FD->getReturnType().print(OS, Policy);
-
-HI.Type.emplace();
-llvm::raw_string_ostream TypeOS(*HI.Type);
-FD->getReturnType().print(TypeOS, Policy);
-TypeOS << '(';
+{
+  llvm::raw_string_ostream OS(*HI.ReturnType);
+  FD->getReturnType().print(OS, Policy);
+}
 
 HI.Parameters.emplace();
 for (const ParmVarDecl *PVD : FD->parameters()) {
-  if (HI.Parameters->size())
-TypeOS << ", ";
   HI.Parameters->emplace_back();
   auto &P = HI.Parameters->back();
   if (!PVD->getType().isNull()) {
 P.Type.emplace();
 llvm::raw_string_ostream OS(*P.Type);
 PVD->getType().print(OS, Policy);
-PVD->getType().print(TypeOS, Policy);
   } else {
 std::string Param;
 llvm::raw_string_ostream OS(Param);
@@ -690,11 +703,17 @@
 PVD->getDefaultArg()->printPretty(Out, nullptr, Policy);
   }
 }
-TypeOS << ')';
+
+HI.Type.emplace();
+llvm::raw_string_ostream TypeOS(*HI.Type);
+// Lambdas
+if (const VarDecl *VD = llvm::dyn_cast(D))
+  VD->getType().getDesugaredType(D->getASTContext()).print(TypeOS, Policy);
+// Functions
+else
+  FD->getType().print(TypeOS, Policy);
 // FIXME: handle variadics.
   } else if (const auto *VD = dyn_cast(D)) {
-// FIXME: Currently lambdas are also handled as ValueDecls, they should be
-// more similar to functions.
 HI.Type.emplace();
 llvm::raw_string_ostream OS(*HI.Type);
 VD->getType().print(OS, Policy);
Index: clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/XRefsTests.cpp
@@ -22,6 +22,7 @@
 #include "llvm/Support/ScopedPrinter.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
 
 namespace clang {
 namespace clangd {
@@ -588,7 +589,7 @@
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
  HI.ReturnType = "void";
- HI.Type = "void()";
+ HI.Type = "void ()";
  HI.Parameters.emplace();
}},
   // Inside namespace
@@ -605,7 +606,7 @@
  HI.Documentation = "Best foo ever.";
  HI.Definition = "void foo()";
  HI.ReturnType = "void";
- HI.Type = "void()";
+ HI.Type = "void ()";
  HI.Parameters.emplace();
}},
   // Field
@@ -733,7 +734,7 @@
   bool Q = false, class... Ts>
 void foo())cpp";
  HI.ReturnType = "void";
- HI.Type = "void()";
+ HI.Type = "void ()";
  HI.Parameters.emplace();
  HI.TemplateParameters = {
  {std::string("template  class"),
@@ -759,12 +760,76 @@
  HI.Kind = SymbolKind::Function;
   

r363238 - [clang-scan-deps] Fix -DBUILD_SHARED_LIBS=ON build

2019-06-13 Thread Sam Clegg via cfe-commits
Author: sbc
Date: Thu Jun 13 01:58:46 2019
New Revision: 363238

URL: http://llvm.org/viewvc/llvm-project?rev=363238&view=rev
Log:
[clang-scan-deps] Fix -DBUILD_SHARED_LIBS=ON build

The -DBUILD_SHARED_LIBS=ON build was broken in rL363204

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

Modified:
cfe/trunk/tools/clang-scan-deps/CMakeLists.txt

Modified: cfe/trunk/tools/clang-scan-deps/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-scan-deps/CMakeLists.txt?rev=363238&r1=363237&r2=363238&view=diff
==
--- cfe/trunk/tools/clang-scan-deps/CMakeLists.txt (original)
+++ cfe/trunk/tools/clang-scan-deps/CMakeLists.txt Thu Jun 13 01:58:46 2019
@@ -16,6 +16,7 @@ set(CLANG_SCAN_DEPS_LIB_DEPS
   clangFrontendTool
   clangLex
   clangParse
+  clangSerialization
   clangTooling
   )
 


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


[PATCH] D63245: clang-scan-deps: Fix -DBUILD_SHARED_LIBS=ON build

2019-06-13 Thread Phabricator 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 rL363238: [clang-scan-deps] Fix -DBUILD_SHARED_LIBS=ON build 
(authored by sbc, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63245?vs=204448&id=204452#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63245

Files:
  cfe/trunk/tools/clang-scan-deps/CMakeLists.txt


Index: cfe/trunk/tools/clang-scan-deps/CMakeLists.txt
===
--- cfe/trunk/tools/clang-scan-deps/CMakeLists.txt
+++ cfe/trunk/tools/clang-scan-deps/CMakeLists.txt
@@ -16,6 +16,7 @@
   clangFrontendTool
   clangLex
   clangParse
+  clangSerialization
   clangTooling
   )
 


Index: cfe/trunk/tools/clang-scan-deps/CMakeLists.txt
===
--- cfe/trunk/tools/clang-scan-deps/CMakeLists.txt
+++ cfe/trunk/tools/clang-scan-deps/CMakeLists.txt
@@ -16,6 +16,7 @@
   clangFrontendTool
   clangLex
   clangParse
+  clangSerialization
   clangTooling
   )
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62944: [Driver] Fix wchar_t and wint_t definitions on Solaris

2019-06-13 Thread Rainer Orth via Phabricator via cfe-commits
ro added a comment.

Ping?  This has been a week, too.  According to gcc/config headers, there are 
quite a number of targets with long int for wchar_t/wint_t,
so there should be some generic way to handle the Clang :: 
Sema/format-strings.c failure.  Suggestions?


Repository:
  rC Clang

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

https://reviews.llvm.org/D62944



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


[PATCH] D63149: Added AST matcher for ignoring elidable constructors

2019-06-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks, looks good to me. I'll commit for you. @gribozavr do you want to take 
another look on the patch?




Comment at: clang/unittests/ASTMatchers/ASTMatchersTest.h:153
+  case LanguageMode::Cxx2aOrLater:
+LangModes = {LanguageMode::Cxx2a};
+  }

hokein wrote:
> nit: add a llvm_unreachable for `default`.
this is not done?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63149



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


[PATCH] D63149: Added AST matcher for ignoring elidable constructors

2019-06-13 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom marked an inline comment as done.
jvikstrom added inline comments.



Comment at: clang/unittests/ASTMatchers/ASTMatchersTest.h:153
+  case LanguageMode::Cxx2aOrLater:
+LangModes = {LanguageMode::Cxx2a};
+  }

hokein wrote:
> nit: add a llvm_unreachable for `default`.
But the switch covers all enum values so that would give warnings


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63149



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


[PATCH] D63030: [WebAssembly] Modernize include path handling

2019-06-13 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363241: [WebAssembly] Modernize include path handling 
(authored by sbc, committed by ).
Herald added subscribers: llvm-commits, ormris.
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D63030?vs=203634&id=204456#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63030

Files:
  cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
  cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
  cfe/trunk/test/Driver/wasm-toolchain.cpp

Index: cfe/trunk/test/Driver/wasm-toolchain.cpp
===
--- cfe/trunk/test/Driver/wasm-toolchain.cpp
+++ cfe/trunk/test/Driver/wasm-toolchain.cpp
@@ -45,8 +45,10 @@
 // RUN: %clangxx -### -no-canonical-prefixes -target wasm32-wasi --sysroot=/foo --stdlib=c++ %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=COMPILE %s
 // COMPILE: clang{{.*}}" "-cc1"
+// COMPILE: "-resource-dir" "[[RESOURCE_DIR:[^"]*]]"
 // COMPILE: "-isysroot" "/foo"
 // COMPILE: "-internal-isystem" "/foo/include/wasm32-wasi/c++/v1"
 // COMPILE: "-internal-isystem" "/foo/include/c++/v1"
+// COMPILE: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
 // COMPILE: "-internal-isystem" "/foo/include/wasm32-wasi"
 // COMPILE: "-internal-isystem" "/foo/include"
Index: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
===
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
@@ -414,9 +414,11 @@
   default:
 break; // Everything else continues to use this routine's logic.
 
+  case llvm::Triple::Emscripten:
   case llvm::Triple::Linux:
   case llvm::Triple::Hurd:
   case llvm::Triple::Solaris:
+  case llvm::Triple::WASI:
 return;
 
   case llvm::Triple::Win32:
@@ -424,6 +426,12 @@
 triple.isOSBinFormatMachO())
   return;
 break;
+
+  case llvm::Triple::UnknownOS:
+if (triple.getArch() == llvm::Triple::wasm32 ||
+triple.getArch() == llvm::Triple::wasm64)
+  return;
+break;
   }
 
   // All header search logic is handled in the Driver for Darwin.
Index: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
@@ -8,6 +8,7 @@
 
 #include "WebAssembly.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
@@ -170,14 +171,39 @@
 
 void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
 ArgStringList &CC1Args) const {
-  if (!DriverArgs.hasArg(options::OPT_nostdinc)) {
-if (getTriple().getOS() != llvm::Triple::UnknownOS) {
-  const std::string MultiarchTriple =
-  getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
-  addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include/" + MultiarchTriple);
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  const Driver &D = getDriver();
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> P(D.ResourceDir);
+llvm::sys::path::append(P, "include");
+addSystemInclude(DriverArgs, CC1Args, P);
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Check for configure-time C include directories.
+  StringRef CIncludeDirs(C_INCLUDE_DIRS);
+  if (CIncludeDirs != "") {
+SmallVector dirs;
+CIncludeDirs.split(dirs, ":");
+for (StringRef dir : dirs) {
+  StringRef Prefix =
+  llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
+  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
 }
-addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include");
+return;
+  }
+
+  if (getTriple().getOS() != llvm::Triple::UnknownOS) {
+const std::string MultiarchTriple =
+getMultiarchTriple(D, getTriple(), D.SysRoot);
+addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include/" + MultiarchTriple);
   }
+  addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
 }
 
 void WebAssembly::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
@@ -188,7 +214,8 @@
   const std::string MultiarchTriple =
   getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
   addSystemInclude(DriverArgs, CC1Args,
-   getDriver().SysRoot + "/include/" + MultiarchTriple + "/c++/v1");
+   getDriver().SysRoot + "/include/" + MultiarchTriple +
+   "/c++/v1");
 }
 addSystemInclude(DriverArgs, CC1Args,
  getDriver().SysRoot + "/include/c++/v1");
__

r363241 - [WebAssembly] Modernize include path handling

2019-06-13 Thread Sam Clegg via cfe-commits
Author: sbc
Date: Thu Jun 13 02:42:43 2019
New Revision: 363241

URL: http://llvm.org/viewvc/llvm-project?rev=363241&view=rev
Log:
[WebAssembly] Modernize include path handling

Move include path construction from
InitHeaderSearch::AddDefaultIncludePaths in the Driver which appears
to be the more modern/correct way of doing things.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
cfe/trunk/test/Driver/wasm-toolchain.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp?rev=363241&r1=363240&r2=363241&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/WebAssembly.cpp Thu Jun 13 02:42:43 2019
@@ -8,6 +8,7 @@
 
 #include "WebAssembly.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
@@ -170,14 +171,39 @@ WebAssembly::GetCXXStdlibType(const ArgL
 
 void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
 ArgStringList &CC1Args) const {
-  if (!DriverArgs.hasArg(options::OPT_nostdinc)) {
-if (getTriple().getOS() != llvm::Triple::UnknownOS) {
-  const std::string MultiarchTriple =
-  getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
-  addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include/" 
+ MultiarchTriple);
+  if (DriverArgs.hasArg(clang::driver::options::OPT_nostdinc))
+return;
+
+  const Driver &D = getDriver();
+
+  if (!DriverArgs.hasArg(options::OPT_nobuiltininc)) {
+SmallString<128> P(D.ResourceDir);
+llvm::sys::path::append(P, "include");
+addSystemInclude(DriverArgs, CC1Args, P);
+  }
+
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
+return;
+
+  // Check for configure-time C include directories.
+  StringRef CIncludeDirs(C_INCLUDE_DIRS);
+  if (CIncludeDirs != "") {
+SmallVector dirs;
+CIncludeDirs.split(dirs, ":");
+for (StringRef dir : dirs) {
+  StringRef Prefix =
+  llvm::sys::path::is_absolute(dir) ? StringRef(D.SysRoot) : "";
+  addExternCSystemInclude(DriverArgs, CC1Args, Prefix + dir);
 }
-addSystemInclude(DriverArgs, CC1Args, getDriver().SysRoot + "/include");
+return;
+  }
+
+  if (getTriple().getOS() != llvm::Triple::UnknownOS) {
+const std::string MultiarchTriple =
+getMultiarchTriple(D, getTriple(), D.SysRoot);
+addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include/" + 
MultiarchTriple);
   }
+  addSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
 }
 
 void WebAssembly::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
@@ -188,7 +214,8 @@ void WebAssembly::AddClangCXXStdlibInclu
   const std::string MultiarchTriple =
   getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
   addSystemInclude(DriverArgs, CC1Args,
-   getDriver().SysRoot + "/include/" + MultiarchTriple + 
"/c++/v1");
+   getDriver().SysRoot + "/include/" + MultiarchTriple +
+   "/c++/v1");
 }
 addSystemInclude(DriverArgs, CC1Args,
  getDriver().SysRoot + "/include/c++/v1");

Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=363241&r1=363240&r2=363241&view=diff
==
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Thu Jun 13 02:42:43 2019
@@ -414,9 +414,11 @@ void InitHeaderSearch::AddDefaultInclude
   default:
 break; // Everything else continues to use this routine's logic.
 
+  case llvm::Triple::Emscripten:
   case llvm::Triple::Linux:
   case llvm::Triple::Hurd:
   case llvm::Triple::Solaris:
+  case llvm::Triple::WASI:
 return;
 
   case llvm::Triple::Win32:
@@ -424,6 +426,12 @@ void InitHeaderSearch::AddDefaultInclude
 triple.isOSBinFormatMachO())
   return;
 break;
+
+  case llvm::Triple::UnknownOS:
+if (triple.getArch() == llvm::Triple::wasm32 ||
+triple.getArch() == llvm::Triple::wasm64)
+  return;
+break;
   }
 
   // All header search logic is handled in the Driver for Darwin.

Modified: cfe/trunk/test/Driver/wasm-toolchain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/wasm-toolchain.cpp?rev=363241&r1=363240&r2=363241&view=diff
==
--- cfe/trunk/test/Driver/wasm-toolchain.cpp (original)
+++ cfe/trunk/test/Driver/wasm-toolchain.cpp Thu Jun 13 0

r363242 - [OpenCL] Move OpenCLBuiltins.td and remove unused include

2019-06-13 Thread Sven van Haastregt via cfe-commits
Author: svenvh
Date: Thu Jun 13 02:54:22 2019
New Revision: 363242

URL: http://llvm.org/viewvc/llvm-project?rev=363242&view=rev
Log:
[OpenCL] Move OpenCLBuiltins.td and remove unused include

Patch by Pierre Gondois.

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

Added:
cfe/trunk/lib/Sema/OpenCLBuiltins.td
  - copied, changed from r363241, 
cfe/trunk/include/clang/Basic/OpenCLBuiltins.td
Removed:
cfe/trunk/include/clang/Basic/OpenCLBuiltins.td
Modified:
cfe/trunk/include/clang/Basic/CMakeLists.txt
cfe/trunk/lib/Sema/CMakeLists.txt
cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/include/clang/Basic/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CMakeLists.txt?rev=363242&r1=363241&r2=363242&view=diff
==
--- cfe/trunk/include/clang/Basic/CMakeLists.txt (original)
+++ cfe/trunk/include/clang/Basic/CMakeLists.txt Thu Jun 13 02:54:22 2019
@@ -41,12 +41,6 @@ clang_tablegen(AttrHasAttributeImpl.inc
   TARGET ClangAttrHasAttributeImpl
   )
 
-clang_tablegen(OpenCLBuiltins.inc
-  -I ${CMAKE_CURRENT_SOURCE_DIR}/../../ -gen-clang-opencl-builtins
-  SOURCE OpenCLBuiltins.td
-  TARGET ClangOpenCLBuiltinsImpl
-  )
-
 # ARM NEON
 clang_tablegen(arm_neon.inc -gen-arm-neon-sema
   SOURCE arm_neon.td

Removed: cfe/trunk/include/clang/Basic/OpenCLBuiltins.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OpenCLBuiltins.td?rev=363241&view=auto
==
--- cfe/trunk/include/clang/Basic/OpenCLBuiltins.td (original)
+++ cfe/trunk/include/clang/Basic/OpenCLBuiltins.td (removed)
@@ -1,296 +0,0 @@
-//==--- OpenCLBuiltins.td - OpenCL builtin declarations 
---===//
-//
-// The LLVM Compiler Infrastructure
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// This file contains TableGen definitions for OpenCL builtin function
-// declarations.  In case of an unresolved function name in OpenCL, Clang will
-// check for a function described in this file when -fdeclare-opencl-builtins
-// is specified.
-//
-//===--===//
-
-//===--===//
-//  Definitions of miscellaneous basic entities.
-//===--===//
-// Versions of OpenCL
-class Version {
-  int Version = _Version;
-}
-def CL10: Version<100>;
-def CL11: Version<110>;
-def CL12: Version<120>;
-def CL20: Version<200>;
-
-// Address spaces
-// Pointer types need to be assigned an address space.
-class AddressSpace {
-  string AddrSpace = _AS;
-}
-def default_as: AddressSpace<"clang::LangAS::Default">;
-def private_as: AddressSpace<"clang::LangAS::opencl_private">;
-def global_as : AddressSpace<"clang::LangAS::opencl_global">;
-def constant_as   : AddressSpace<"clang::LangAS::opencl_constant">;
-def local_as  : AddressSpace<"clang::LangAS::opencl_local">;
-def generic_as: AddressSpace<"clang::LangAS::opencl_generic">;
-
-
-// Qualified Type. Allow to retrieve one ASTContext QualType.
-class QualType {
-  // Name of the field or function in a clang::ASTContext
-  // E.g. Name="IntTy" for the int type, and "getIntPtrType()" for an intptr_t
-  string Name = _Name;
-}
-
-// Helper class to store type access qualifiers (volatile, const, ...).
-class Qualifier {
-  string QualName = _QualName;
-}
-
-//===--===//
-//  OpenCL C classes for types
-//===--===//
-// OpenCL types (int, float, ...)
-class Type {
-  // Name of the Type
-  string Name = _Name;
-  // QualType associated with this type
-  QualType QTName = _QTName;
-  // Size of the vector (if applicable)
-  int VecWidth = 0;
-  // Is pointer
-  bit IsPointer = 0;
-  // List of qualifiers associated with the type (volatile, ...)
-  list QualList = [];
-  // Address space
-  string AddrSpace = "clang::LangAS::Default";
-  // Access qualifier. Must be one of ("RO", "WO", "RW").
-  string AccessQualifier = "";
-}
-
-// OpenCL vector types (e.g. int2, int3, int16, float8, ...)
-class VectorType : Type<_Ty.Name, _Ty.QTName> {
-  int VecWidth = _VecWidth;
-}
-
-// OpenCL pointer types (e.g. int*, float*, ...)
-class PointerType :
-  Type<_Ty.Name, _Ty.QTName> {
-  bit IsPointer = 1;
-  string AddrSpace = _AS.AddrSpace;
-}
-
-// OpenCL image types (e.g. image2d_t, ...)
-class ImageType :
- 

[PATCH] D63222: [Clangd] Fixed clangd diagnostics priority

2019-06-13 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah updated this revision to Diff 204467.
SureYeaah added a comment.

Refactored code as pointed out by @kadircet


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D63222

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -101,6 +101,7 @@
   Annotations Test(R"cpp(
 namespace test{};
 void $decl[[foo]]();
+class T{$explicit[[]]$constructor[[T]](int a);};
 int main() {
   $typo[[go\
 o]]();
@@ -112,8 +113,10 @@
   test::$nomembernamespace[[test]];
 }
   )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  TU.ClangTidyChecks = "-*,google-explicit-constructor";
   EXPECT_THAT(
-  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  TU.build().getDiagnostics(),
   ElementsAre(
   // This range spans lines.
   AllOf(Diag(Test.range("typo"),
@@ -135,7 +138,13 @@
"of type 'const char [4]'"),
   Diag(Test.range("nomember"), "no member named 'y' in 'Foo'"),
   Diag(Test.range("nomembernamespace"),
-   "no member named 'test' in namespace 'test'")));
+   "no member named 'test' in namespace 'test'"),
+  // We make sure here that the entire token is highlighted
+  AllOf(Diag(Test.range("constructor"),
+ "single-argument constructors must be marked explicit to "
+ "avoid unintentional implicit conversions"),
+WithFix(Fix(Test.range("explicit"), "explicit ",
+"insert 'explicit '");
 }
 
 TEST(DiagnosticsTest, FlagsMatter) {
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
@@ -102,12 +103,18 @@
 if (R.getBegin() == R.getEnd() && Loc == R.getBegin())
   FallbackRange = halfOpenToRange(M, R);
   }
-  if (FallbackRange)
-return *FallbackRange;
-  // If no suitable range is found, just use the token at the location.
-  auto R = Lexer::makeFileCharRange(CharSourceRange::getTokenRange(Loc), M, L);
-  if (!R.isValid()) // Fall back to location only, let the editor deal with it.
-R = CharSourceRange::getCharRange(Loc);
+  // If we can't get the token at the location, fall back to using the location
+  // and let the editor deal with it.
+  auto R = CharSourceRange::getCharRange(Loc);
+  Token Tok;
+  if(!Lexer::getRawToken(Loc, Tok, M, L, true)) {
+bool IsTokenComment = Tok.isNot(tok::comment);
+// If the token at the location is a comment, just use the location.
+// Otherwise use the token.
+if (!IsTokenComment && FallbackRange)
+  return *FallbackRange;
+else R = CharSourceRange::getTokenRange(Tok.getLocation(), 
Tok.getEndLoc());
+  }
   return halfOpenToRange(M, R);
 }
 


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -101,6 +101,7 @@
   Annotations Test(R"cpp(
 namespace test{};
 void $decl[[foo]]();
+class T{$explicit[[]]$constructor[[T]](int a);};
 int main() {
   $typo[[go\
 o]]();
@@ -112,8 +113,10 @@
   test::$nomembernamespace[[test]];
 }
   )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  TU.ClangTidyChecks = "-*,google-explicit-constructor";
   EXPECT_THAT(
-  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  TU.build().getDiagnostics(),
   ElementsAre(
   // This range spans lines.
   AllOf(Diag(Test.range("typo"),
@@ -135,7 +138,13 @@
"of type 'const char [4]'"),
   Diag(Test.range("nomember"), "no member named 'y' in 'Foo'"),
   Diag(Test.range("nomembernamespace"),
-   "no member named 'test' in namespace 'test'")));
+   "no member named 'test' in namespace 'test'"),
+  // We make sure here that the entire token is highlighted
+  AllOf(Diag(Test.range("constructor"),
+ "single-argument constructors must be marked explicit to "
+ "avoid unintentional implicit conversions"),
+WithFix(Fix(Test.range("explicit"), "explicit ",
+"insert 'e

[PATCH] D63222: [Clangd] Fixed clangd diagnostics priority

2019-06-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!

Also please make sure you've clang-formatted the code before you land this.




Comment at: clang-tools-extra/clangd/Diagnostics.cpp:94
   }
   llvm::Optional FallbackRange;
   // The range may be given as a fixit hint instead.

`FallbackRange` is not returned anymore, you can safely delete it.



Comment at: clang-tools-extra/clangd/Diagnostics.cpp:110
+  Token Tok;
+  if(!Lexer::getRawToken(Loc, Tok, M, L, true)) {
+bool IsTokenComment = Tok.isNot(tok::comment);

I think you can simply it further by:

```
// Fallback to zero-width range at diagnostic location.
auto R = CharSourceRange::getCharRange(Loc);
Token Tok;
// For non-comment tokens, use token at the location.
if (!Lexer::getRawToken(Loc, Tok, M, L, true) && Tok.isNot(tok::comment))
  R = CharSourceRange::getTokenRange(Tok.getLocation(), Tok.getEndLoc());
return halfOpenToRange(M, R);
```


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D63222



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


[PATCH] D63194: [clangd] Link in target infos and pass target and mode while invoking driver

2019-06-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp:36
   Cmd.CommandLine = ArgsAdjuster(Cmd.CommandLine, Cmd.Filename);
+  tooling::addTargetAndModeForProgramName(Cmd.CommandLine, Cmd.CommandLine[0]);
   // Inject the resource dir.

ilya-biryukov wrote:
> kadircet wrote:
> > ilya-biryukov wrote:
> > > Do we actually need this if we provide a proper `Argv[0]` to the driver?
> > > My understanding is that the driver should figure out the targets from 
> > > custom binary names on its own.
> > unfortunately yes. 
> > 
> > because if the "-target" is missing, driver tries to deduce it from the 
> > "running binary" which is "clangd" in our case.
> I wonder if it would sense to change this? Where does this code live?
> 
> That's exactly what `argv[0]` is for in `compile_commands.json`. Fixing that 
> at the driver level would "fix" all libclang- and libtooling-based binaries, 
> like `clang-tidy`, etc.
ah sorry, I've mixed that one actually. the behavior is: if the "-target" is 
missing, we always use the default target(depends on the host). even though 
`ClangExecutable` is available in the Driver and set correctly to `argv[0]`.
tools that care about target deduction needs to pass "-target" to driver 
explicitly. currently the driver only deduces "driver-mode" from the executable 
name.

adding this to rather driver side, looks like nothing is broken.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63194



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


[PATCH] D63194: [clangd] Link in target infos and pass target and mode while invoking driver

2019-06-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 204484.
kadircet marked an inline comment as done.
kadircet added a comment.

- Move target name deduction into Driver


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63194

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/test/target_info.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang/lib/Driver/Driver.cpp

Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1046,8 +1046,14 @@
 T.setObjectFormat(llvm::Triple::COFF);
 TargetTriple = T.str();
   }
+
   if (const Arg *A = Args.getLastArg(options::OPT_target))
 TargetTriple = A->getValue();
+  // Deduce target triplet from clang executable name, if not specified
+  // explicitly.
+  else if (ClangNameParts.TargetIsValid)
+TargetTriple = ClangNameParts.TargetPrefix;
+
   if (const Arg *A = Args.getLastArg(options::OPT_ccc_install_dir))
 Dir = InstalledDir = A->getValue();
   for (const Arg *A : Args.filtered(options::OPT_B)) {
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -24,6 +24,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -324,6 +325,7 @@
   using namespace clang;
   using namespace clang::clangd;
 
+  llvm::InitializeAllTargetInfos();
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
 OS << clang::getClangToolFullVersion("clangd") << "\n";
Index: clang-tools-extra/clangd/test/target_info.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/target_info.test
@@ -0,0 +1,34 @@
+# Mock 'compile_commands.json' to contain a driver name targeting fuchsia OS.
+# Afterwards check that correct target is passed into clang.
+
+# RUN: rm -rf %t.dir && mkdir -p %t.dir
+
+# RUN: echo '[{"directory": "%/t.dir", "command": "%/t.dir/x86_64-fuchsia-clang -x c++ the-file.cpp -v", "file": "the-file.cpp"}]' > %t.dir/compile_commands.json
+
+# RUN: sed -e "s|INPUT_DIR|%/t.dir|g" %s > %t.test.1
+# On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..."
+# (with the extra slash in the front), so we add it here.
+# RUN: sed -e "s|file://\([A-Z]\):/|file:///\1:/|g" %t.test.1 > %t.test
+
+# RUN: clangd -lit-test < %t.test 2>&1 | FileCheck -strict-whitespace %t.test
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{}}
+---
+{
+  "jsonrpc":"2.0",
+  "method":"textDocument/didOpen",
+  "params": {
+"textDocument": {
+  "uri": "file://INPUT_DIR/the-file.cpp",
+  "languageId":"cpp",
+  "version":1,
+  "text":""
+}
+  }
+}
+# Make sure we have target passed into cc1 driver, which is printed due to -v in
+# the compile_commands.json
+# CHECK: Target: x86_64-unknown-fuchsia
+---
+{"jsonrpc":"2.0","id":1,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -11,6 +11,7 @@
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
Index: clang-tools-extra/clangd/CMakeLists.txt
===
--- clang-tools-extra/clangd/CMakeLists.txt
+++ clang-tools-extra/clangd/CMakeLists.txt
@@ -21,6 +21,7 @@
 
 set(LLVM_LINK_COMPONENTS
   Support
+  AllTargetsInfos
   )
 
 if(CLANG_BUILT_STANDALONE)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D61637: [Syntax] Introduce syntax trees

2019-06-13 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 204488.
ilya-biryukov marked 7 inline comments as done.
ilya-biryukov added a comment.

- A leaf node stores a single token
- Restructure code to avoid special-casing leaf nodes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61637

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/CMakeLists.txt
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/lib/Tooling/Syntax/Tree.cpp
  clang/unittests/Tooling/Syntax/CMakeLists.txt
  clang/unittests/Tooling/Syntax/TreeTest.cpp
  llvm/utils/gn/secondary/clang/lib/Tooling/Syntax/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Tooling/Syntax/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Tooling/Syntax/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Tooling/Syntax/BUILD.gn
@@ -8,6 +8,10 @@
 "//llvm/lib/Support",
   ]
   sources = [
+"Arena.cpp",
+"BuildFromAST.cpp",
+"Cascade.cpp",
+"Nodes.cpp",
 "Tokens.cpp",
   ]
 }
Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- /dev/null
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -0,0 +1,160 @@
+//===- TreeTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/Syntax/Tree.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/Decl.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendAction.h"
+#include "clang/Lex/PreprocessorOptions.h"
+#include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Nodes.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace clang;
+
+namespace {
+class SyntaxTreeTest : public ::testing::Test {
+protected:
+  // Build a syntax tree for the code.
+  syntax::TranslationUnit *buildTree(llvm::StringRef Code) {
+// FIXME: this code is almost the identical to the one in TokensTest. Share
+//it.
+class BuildSyntaxTree : public ASTConsumer {
+public:
+  BuildSyntaxTree(syntax::TranslationUnit *&Root,
+  std::unique_ptr &Arena,
+  std::unique_ptr Tokens)
+  : Root(Root), Arena(Arena), Tokens(std::move(Tokens)) {
+assert(this->Tokens);
+  }
+
+  void HandleTranslationUnit(ASTContext &Ctx) override {
+Arena = llvm::make_unique(Ctx.getSourceManager(),
+ Ctx.getLangOpts(),
+ std::move(*Tokens).consume());
+Tokens = nullptr; // make sure we fail if this gets called twice.
+Root = syntax::buildSyntaxTree(*Arena, *Ctx.getTranslationUnitDecl());
+  }
+
+private:
+  syntax::TranslationUnit *&Root;
+  std::unique_ptr &Arena;
+  std::unique_ptr Tokens;
+};
+
+class BuildSyntaxTreeAction : public ASTFrontendAction {
+public:
+  BuildSyntaxTreeAction(syntax::TranslationUnit *&Root,
+std::unique_ptr &Arena)
+  : Root(Root), Arena(Arena) {}
+
+  std::unique_ptr
+  CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override {
+// We start recording the tokens, ast consumer will take on the result.
+auto Tokens =
+llvm::make_unique(CI.getPreprocessor());
+return llvm::make_unique(Root, Arena,
+  std::move(Tokens));
+  }
+
+private:
+  syntax::TranslationUnit *&Root;
+  std::unique_ptr &Arena;
+};
+
+constexpr const char *FileName = "./input.cpp";
+FS->addFile(FileName, time_t(), llvm::MemoryBuffer::getMemBufferCopy(""));
+// Prepare to run a compiler.
+std::vector Args = {"tok-test", "-std=c++03", "-fsyntax-only",
+  FileName};
+auto CI = createInvocationFromCommandLine(Args, Diags, FS);
+assert(CI);
+CI->getFrontendOpts().DisableFree = false;
+CI->getPreprocessorOpts().addRemappedFile(
+FileName, llvm::MemoryBuffer::getMemBufferCopy(Code).release());
+CompilerInstance Compiler;
+Compiler.setInvocation(std::move(CI));
+if (!Diags->getClient())
+  Diags->setClient(new IgnoringDiagConsumer);
+Compiler.setDiagnostics(Diags.get());
+Compiler.setFileManager(FileMgr.get());
+  

[PATCH] D63222: [Clangd] Fixed clangd diagnostics priority

2019-06-13 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah updated this revision to Diff 204489.
SureYeaah marked 4 inline comments as done.
SureYeaah added a comment.

Simplified logic for diagnostics range.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D63222

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -101,6 +101,7 @@
   Annotations Test(R"cpp(
 namespace test{};
 void $decl[[foo]]();
+class T{$explicit[[]]$constructor[[T]](int a);};
 int main() {
   $typo[[go\
 o]]();
@@ -112,8 +113,10 @@
   test::$nomembernamespace[[test]];
 }
   )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  TU.ClangTidyChecks = "-*,google-explicit-constructor";
   EXPECT_THAT(
-  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  TU.build().getDiagnostics(),
   ElementsAre(
   // This range spans lines.
   AllOf(Diag(Test.range("typo"),
@@ -135,7 +138,13 @@
"of type 'const char [4]'"),
   Diag(Test.range("nomember"), "no member named 'y' in 'Foo'"),
   Diag(Test.range("nomembernamespace"),
-   "no member named 'test' in namespace 'test'")));
+   "no member named 'test' in namespace 'test'"),
+  // We make sure here that the entire token is highlighted
+  AllOf(Diag(Test.range("constructor"),
+ "single-argument constructors must be marked explicit to "
+ "avoid unintentional implicit conversions"),
+WithFix(Fix(Test.range("explicit"), "explicit ",
+"insert 'explicit '");
 }
 
 TEST(DiagnosticsTest, FlagsMatter) {
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
@@ -90,24 +91,22 @@
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
   }
-  llvm::Optional FallbackRange;
   // The range may be given as a fixit hint instead.
   for (const auto &F : D.getFixItHints()) {
 auto R = Lexer::makeFileCharRange(F.RemoveRange, M, L);
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
-// If there's a fixit that performs insertion, it has zero-width. Therefore
-// it can't contain the location of the diag, but it might be possible that
-// this should be reported as range. For example missing semicolon.
-if (R.getBegin() == R.getEnd() && Loc == R.getBegin())
-  FallbackRange = halfOpenToRange(M, R);
   }
-  if (FallbackRange)
-return *FallbackRange;
-  // If no suitable range is found, just use the token at the location.
-  auto R = Lexer::makeFileCharRange(CharSourceRange::getTokenRange(Loc), M, L);
-  if (!R.isValid()) // Fall back to location only, let the editor deal with it.
-R = CharSourceRange::getCharRange(Loc);
+  // If there's a fixit that performs insertion, it has zero-width. Therefore
+  // it can't contain the location of the diag, but it might be possible that
+  // this should be reported as range. For example missing semicolon.
+  // If the token at the location is not a comment, use the token.
+  // If we can't get the token at the location, fall back to using the location
+  auto R = CharSourceRange::getCharRange(Loc);
+  Token Tok;
+  if(!Lexer::getRawToken(Loc, Tok, M, L, true) && Tok.isNot(tok::comment)) {
+R = CharSourceRange::getTokenRange(Tok.getLocation(), Tok.getEndLoc());
+  }
   return halfOpenToRange(M, R);
 }
 


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -101,6 +101,7 @@
   Annotations Test(R"cpp(
 namespace test{};
 void $decl[[foo]]();
+class T{$explicit[[]]$constructor[[T]](int a);};
 int main() {
   $typo[[go\
 o]]();
@@ -112,8 +113,10 @@
   test::$nomembernamespace[[test]];
 }
   )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  TU.ClangTidyChecks = "-*,google-explicit-constructor";
   EXPECT_THAT(
-  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  TU.build().getDiagnostics(),
   ElementsAre(
   // This range spans lines.
   AllOf(Diag(Test.range("typo"),
@@ -135,7 +138,13 @@

[PATCH] D61637: [Syntax] Introduce syntax trees

2019-06-13 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

This is not 100% ready yet, but wanted to send it out anyway, as I'll be on 
vacation until Tuesday.

I've addressed most major comments. In particular, `TreeBuilder` now looks 
simpler (and more structured)  to my taste.
One thing that's missing is adding children in arbitrary order. It won't be too 
complicated (would require some thought on how to properly create recovery 
nodes, though). I'd be tempted to land the current implementation as is and 
allow adding children in arbitrary order in a separate change (alongside more 
types of nodes), but let me know what you think.




Comment at: clang/include/clang/Tooling/Syntax/Tree.h:104
+
+  llvm::ArrayRef tokens() const { return Tokens; }
+

sammccall wrote:
> as discussed offline, having a leaf node store a range of tokens (rather than 
> just one) looks attractive now, but as the syntax tree gets more detailed 
> there are relatively few cases where multiple consecutive tokens should 
> really be undifferentiated siblings.
> 
> Might be better to bite the bullet now and make leaf hold a single token, so 
> our consecutive token ranges become a linked list. This will also flush out 
> accidental assumptions that only tokens in the same Leaf are adjacent.
> 
> Given this, I'm not sure there's a better name than `syntax::Leaf`. You might 
> consider making it a pointer-like object dereferenceable to Token&.
Leaf now stores a single token, that actually simplifies things quite a bit, 
thanks!
I'd avoid making it a pointer-like object, given that nodes are often passed as 
pointers on their own. Making them a pointer-like object would mean we can get 
code that does double deferences (Tok = **Leaf).



Comment at: clang/include/clang/Tooling/Syntax/Tree.h:129
+  /// by TreeBuilder.
+  void prependChildLowLevel(Node *Child);
+  friend class TreeBuilder;

sammccall wrote:
> (curious: why prepend rather than append?)
Appending to a linked list is `O(n)`. If we reverse it, traversing 
left-to-right order is `O(n)`.




Comment at: clang/include/clang/Tooling/Syntax/Tree.h:129
+  /// by TreeBuilder.
+  void prependChildLowLevel(Node *Child);
+  friend class TreeBuilder;

ilya-biryukov wrote:
> sammccall wrote:
> > (curious: why prepend rather than append?)
> Appending to a linked list is `O(n)`. If we reverse it, traversing 
> left-to-right order is `O(n)`.
> 
Append is `O(n)` in the current representation as it requires walking to the 
tail of the list.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:41
+  /// Add a leaf node for a token starting at \p Loc.
+  void learnTokenNode(SourceLocation Loc, tok::TokenKind Kind);
+

sammccall wrote:
> Particularly in view of having tokens be 1:1 with Leaf, *constructing* the 
> token nodes as part of higher level constructs / as part of recovery seems a 
> little odd.
> 
> What if we constructed all the leaf nodes up front, forming a linked list:
> `int -> a -> = -> 2 -> + -> 2 -> ; -> eof`
> 
> When you form a node that covers a range, you splice out the nodes in that 
> range, replacing with the new node:
> 
> `int -> a -> = -> (2 + 2) -> ; -> eof`
> `(int a = (2 + 2)) -> ; -> eof`
> etc
> 
> Then the invariant is you have a forest, the roots form a linked list, and 
> the trees' respective leaves are a left-to-right partition of the input 
> tokens.
> 
> I think this would mean:
>  - no separate vector data structure (AFAICS we can reuse Node)
>  - don't have the requirement that the formed node must claim a suffix of the 
> pending nodes, which simplifies the recursive AST visitior
> 
> We lose the binary search, but I think tracking the last accessed root 
> (current position) and linear searching left/right will be at least as good 
> in practice, because tree traversal is fundamentally pretty local.
I went with a slightly different approach, similar to how parser does it. 
Please let me know what you think.
The new `Forest` helper struct ensures the tree structure invariants (all 
tokens must be covered, nodes must nest properly based on a syntax structure), 
the rest of the code in tree builder takes care of folding the nodes in a 
proper order and properly advancing the token stream (it's somewhat similar in 
the details of how parsers are implemented, except that instead of parsing we 
actually walk a pre-parsed AST).

It still needs some comments, but I think its intentions should be clear.
Let me know what you think, happy to discuss this offline too.



Comment at: clang/lib/Tooling/Syntax/BuildTree.cpp:48
+  /// Consume the root node.
+  syntax::TranslationUnit *root() && {
+assert(Root);

sammccall wrote:
> any particular reason learnRoot() and root() are different functions?
> 
> If learnRoot() returned TranslationUnit*, then we avoid the need for the 
> caller to know about the dependency, it would track 

[PATCH] D63222: [Clangd] Fixed clangd diagnostics priority

2019-06-13 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah updated this revision to Diff 204494.
SureYeaah marked 2 inline comments as done.
SureYeaah added a comment.

Formatted code


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D63222

Files:
  clang-tools-extra/clangd/Diagnostics.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -101,6 +101,7 @@
   Annotations Test(R"cpp(
 namespace test{};
 void $decl[[foo]]();
+class T{$explicit[[]]$constructor[[T]](int a);};
 int main() {
   $typo[[go\
 o]]();
@@ -112,8 +113,10 @@
   test::$nomembernamespace[[test]];
 }
   )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  TU.ClangTidyChecks = "-*,google-explicit-constructor";
   EXPECT_THAT(
-  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  TU.build().getDiagnostics(),
   ElementsAre(
   // This range spans lines.
   AllOf(Diag(Test.range("typo"),
@@ -135,7 +138,13 @@
"of type 'const char [4]'"),
   Diag(Test.range("nomember"), "no member named 'y' in 'Foo'"),
   Diag(Test.range("nomembernamespace"),
-   "no member named 'test' in namespace 'test'")));
+   "no member named 'test' in namespace 'test'"),
+  // We make sure here that the entire token is highlighted
+  AllOf(Diag(Test.range("constructor"),
+ "single-argument constructors must be marked explicit to "
+ "avoid unintentional implicit conversions"),
+WithFix(Fix(Test.range("explicit"), "explicit ",
+"insert 'explicit '");
 }
 
 TEST(DiagnosticsTest, FlagsMatter) {
Index: clang-tools-extra/clangd/Diagnostics.cpp
===
--- clang-tools-extra/clangd/Diagnostics.cpp
+++ clang-tools-extra/clangd/Diagnostics.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
@@ -90,24 +91,22 @@
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
   }
-  llvm::Optional FallbackRange;
   // The range may be given as a fixit hint instead.
   for (const auto &F : D.getFixItHints()) {
 auto R = Lexer::makeFileCharRange(F.RemoveRange, M, L);
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
-// If there's a fixit that performs insertion, it has zero-width. Therefore
-// it can't contain the location of the diag, but it might be possible that
-// this should be reported as range. For example missing semicolon.
-if (R.getBegin() == R.getEnd() && Loc == R.getBegin())
-  FallbackRange = halfOpenToRange(M, R);
   }
-  if (FallbackRange)
-return *FallbackRange;
-  // If no suitable range is found, just use the token at the location.
-  auto R = Lexer::makeFileCharRange(CharSourceRange::getTokenRange(Loc), M, L);
-  if (!R.isValid()) // Fall back to location only, let the editor deal with it.
-R = CharSourceRange::getCharRange(Loc);
+  // If there's a fixit that performs insertion, it has zero-width. Therefore
+  // it can't contain the location of the diag, but it might be possible that
+  // this should be reported as range. For example missing semicolon.
+  // If the token at the location is not a comment, we use the token.
+  // If we can't get the token at the location, fall back to using the location
+  auto R = CharSourceRange::getCharRange(Loc);
+  Token Tok;
+  if (!Lexer::getRawToken(Loc, Tok, M, L, true) && Tok.isNot(tok::comment)) {
+R = CharSourceRange::getTokenRange(Tok.getLocation(), Tok.getEndLoc());
+  }
   return halfOpenToRange(M, R);
 }
 


Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -101,6 +101,7 @@
   Annotations Test(R"cpp(
 namespace test{};
 void $decl[[foo]]();
+class T{$explicit[[]]$constructor[[T]](int a);};
 int main() {
   $typo[[go\
 o]]();
@@ -112,8 +113,10 @@
   test::$nomembernamespace[[test]];
 }
   )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  TU.ClangTidyChecks = "-*,google-explicit-constructor";
   EXPECT_THAT(
-  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  TU.build().getDiagnostics(),
   ElementsAre(
   // This range spans lines.
   AllOf(Diag(Test.range("typo"),
@@ -135,7 +138,13 @@
"of t

[PATCH] D63253: [clang-tidy] Made abseil-faster-strsplit-delimiter tests pass on C++17

2019-06-13 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom created this revision.
jvikstrom added a reviewer: hokein.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63253

Files:
  clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
  clang-tools-extra/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp


Index: clang-tools-extra/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
===
--- clang-tools-extra/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
+++ clang-tools-extra/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-faster-strsplit-delimiter 
%t
+// RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-faster-strsplit-delimiter %t
 // FIXME: Fix the checker to work in C++17 mode.
 
 namespace absl {
Index: clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
@@ -20,21 +20,6 @@
 
 AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
 
-::internal::Matcher
-constructExprWithArg(llvm::StringRef ClassName,
- const ::internal::Matcher &Arg) {
-  auto ConstrExpr = cxxConstructExpr(hasType(recordDecl(hasName(ClassName))),
- hasArgument(0, ignoringParenCasts(Arg)));
-
-  return anyOf(ConstrExpr, cxxBindTemporaryExpr(has(ConstrExpr)));
-}
-
-::internal::Matcher
-copyConstructExprWithArg(llvm::StringRef ClassName,
- const ::internal::Matcher &Arg) {
-  return constructExprWithArg(ClassName, constructExprWithArg(ClassName, Arg));
-}
-
 llvm::Optional makeCharacterLiteral(const StringLiteral *Literal) 
{
   std::string Result;
   {
@@ -74,11 +59,17 @@
 
   // Binds to a string_view (either absl or std) that was passed by value and
   // contructed from string literal.
-  auto StringViewArg =
-  copyConstructExprWithArg("::absl::string_view", SingleChar);
+  auto StringViewArg = ignoringElidableConstructorCall(ignoringImpCasts(
+  cxxConstructExpr(hasType(recordDecl(hasName("::absl::string_view"))),
+   hasArgument(0, ignoringParenImpCasts(SingleChar);
 
+  // Need to ignore the elidable constructor as otherwise there is no match for
+  // c++14 and earlier.
   auto ByAnyCharArg =
-  expr(copyConstructExprWithArg("::absl::ByAnyChar", StringViewArg))
+  expr(has(ignoringElidableConstructorCall(
+   ignoringParenCasts(cxxBindTemporaryExpr(has(cxxConstructExpr(
+   hasType(recordDecl(hasName("::absl::ByAnyChar"))),
+   hasArgument(0, StringViewArg
   .bind("ByAnyChar");
 
   // Find uses of absl::StrSplit(..., "x") and absl::StrSplit(...,


Index: clang-tools-extra/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
===
--- clang-tools-extra/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
+++ clang-tools-extra/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-faster-strsplit-delimiter %t
+// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-faster-strsplit-delimiter %t
 // FIXME: Fix the checker to work in C++17 mode.
 
 namespace absl {
Index: clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
@@ -20,21 +20,6 @@
 
 AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
 
-::internal::Matcher
-constructExprWithArg(llvm::StringRef ClassName,
- const ::internal::Matcher &Arg) {
-  auto ConstrExpr = cxxConstructExpr(hasType(recordDecl(hasName(ClassName))),
- hasArgument(0, ignoringParenCasts(Arg)));
-
-  return anyOf(ConstrExpr, cxxBindTemporaryExpr(has(ConstrExpr)));
-}
-
-::internal::Matcher
-copyConstructExprWithArg(llvm::StringRef ClassName,
- const ::internal::Matcher &Arg) {
-  return constructExprWithArg(ClassName, constructExprWithArg(ClassName, Arg));
-}
-
 llvm::Optional makeCharacterLiteral(const StringLiteral *Literal) {
   std::string Result;
   {
@@ -74,11 +59,17 @@
 
   // Binds to a string_view (either absl or std) that was passed by value and
   // contructed from string literal.
-  auto StringViewArg =
-  copyConstructExprWithArg("::absl::string_view", SingleChar);
+  auto StringViewArg = ignoringElidableConstructorCall(ignoringImpCasts(
+  cxxConstructExpr(hasType(recordDecl(hasName("::absl::string_view"

[PATCH] D63253: [clang-tidy] Made abseil-faster-strsplit-delimiter tests pass on C++17

2019-06-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

looks good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63253



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


[PATCH] D63194: [clangd] Link in target infos and pass target and mode while invoking driver

2019-06-13 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

Nice, thanks! The clangd parts obviously LGTM, but let's be more conservative 
with the driver bits (see the relevant comment)




Comment at: clang-tools-extra/clangd/test/target_info.test:28
+}
+# Make sure we have target passed into cc1 driver, which is printed due to -v 
in
+# the compile_commands.json

This is a marvellous hack!



Comment at: clang/lib/Driver/Driver.cpp:1055
+  else if (ClangNameParts.TargetIsValid)
+TargetTriple = ClangNameParts.TargetPrefix;
+

I strongly think the driver is the right place to do this, but we have to watch 
out for breakages coming from this. The drivers code has way more uses than 
clangd code, so we should expect that people rely on all kinds of things there.

Could you separate the driver pieces into a separate change and add driver 
tests for them? To make it more focused and easier to revert in case of 
breakages.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63194



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


[clang-tools-extra] r363253 - [Clangd] Fixed clangd diagnostics priority

2019-06-13 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Jun 13 05:31:36 2019
New Revision: 363253

URL: http://llvm.org/viewvc/llvm-project?rev=363253&view=rev
Log:
[Clangd] Fixed clangd diagnostics priority

Summary:
- Fixed diagnostics where zero width inserted ranges were being used instead of 
the whole token
- Added unit tests

Patch by @SureYeaah !

Reviewers: sammccall, kadircet

Reviewed By: kadircet

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

Tags: #clang-tools-extra, #clang

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

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

Modified: clang-tools-extra/trunk/clangd/Diagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Diagnostics.cpp?rev=363253&r1=363252&r2=363253&view=diff
==
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp (original)
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp Thu Jun 13 05:31:36 2019
@@ -18,6 +18,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
@@ -90,24 +91,19 @@ Range diagnosticRange(const clang::Diagn
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
   }
-  llvm::Optional FallbackRange;
   // The range may be given as a fixit hint instead.
   for (const auto &F : D.getFixItHints()) {
 auto R = Lexer::makeFileCharRange(F.RemoveRange, M, L);
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
-// If there's a fixit that performs insertion, it has zero-width. Therefore
-// it can't contain the location of the diag, but it might be possible that
-// this should be reported as range. For example missing semicolon.
-if (R.getBegin() == R.getEnd() && Loc == R.getBegin())
-  FallbackRange = halfOpenToRange(M, R);
   }
-  if (FallbackRange)
-return *FallbackRange;
-  // If no suitable range is found, just use the token at the location.
-  auto R = Lexer::makeFileCharRange(CharSourceRange::getTokenRange(Loc), M, L);
-  if (!R.isValid()) // Fall back to location only, let the editor deal with it.
-R = CharSourceRange::getCharRange(Loc);
+  // If the token at the location is not a comment, we use the token.
+  // If we can't get the token at the location, fall back to using the location
+  auto R = CharSourceRange::getCharRange(Loc);
+  Token Tok;
+  if (!Lexer::getRawToken(Loc, Tok, M, L, true) && Tok.isNot(tok::comment)) {
+R = CharSourceRange::getTokenRange(Tok.getLocation(), Tok.getEndLoc());
+  }
   return halfOpenToRange(M, R);
 }
 

Modified: clang-tools-extra/trunk/clangd/unittests/DiagnosticsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/DiagnosticsTests.cpp?rev=363253&r1=363252&r2=363253&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/DiagnosticsTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/DiagnosticsTests.cpp Thu Jun 13 
05:31:36 2019
@@ -101,6 +101,7 @@ TEST(DiagnosticsTest, DiagnosticRanges)
   Annotations Test(R"cpp(
 namespace test{};
 void $decl[[foo]]();
+class T{$explicit[[]]$constructor[[T]](int a);};
 int main() {
   $typo[[go\
 o]]();
@@ -112,8 +113,10 @@ o]]();
   test::$nomembernamespace[[test]];
 }
   )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  TU.ClangTidyChecks = "-*,google-explicit-constructor";
   EXPECT_THAT(
-  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  TU.build().getDiagnostics(),
   ElementsAre(
   // This range spans lines.
   AllOf(Diag(Test.range("typo"),
@@ -135,7 +138,13 @@ o]]();
"of type 'const char [4]'"),
   Diag(Test.range("nomember"), "no member named 'y' in 'Foo'"),
   Diag(Test.range("nomembernamespace"),
-   "no member named 'test' in namespace 'test'")));
+   "no member named 'test' in namespace 'test'"),
+  // We make sure here that the entire token is highlighted
+  AllOf(Diag(Test.range("constructor"),
+ "single-argument constructors must be marked explicit to "
+ "avoid unintentional implicit conversions"),
+WithFix(Fix(Test.range("explicit"), "explicit ",
+"insert 'explicit '");
 }
 
 TEST(DiagnosticsTest, FlagsMatter) {


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


[PATCH] D63222: [Clangd] Fixed clangd diagnostics priority

2019-06-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363253: [Clangd] Fixed clangd diagnostics priority (authored 
by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63222?vs=204494&id=204499#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63222

Files:
  clang-tools-extra/trunk/clangd/Diagnostics.cpp
  clang-tools-extra/trunk/clangd/unittests/DiagnosticsTests.cpp


Index: clang-tools-extra/trunk/clangd/Diagnostics.cpp
===
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
@@ -90,24 +91,19 @@
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
   }
-  llvm::Optional FallbackRange;
   // The range may be given as a fixit hint instead.
   for (const auto &F : D.getFixItHints()) {
 auto R = Lexer::makeFileCharRange(F.RemoveRange, M, L);
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
-// If there's a fixit that performs insertion, it has zero-width. Therefore
-// it can't contain the location of the diag, but it might be possible that
-// this should be reported as range. For example missing semicolon.
-if (R.getBegin() == R.getEnd() && Loc == R.getBegin())
-  FallbackRange = halfOpenToRange(M, R);
-  }
-  if (FallbackRange)
-return *FallbackRange;
-  // If no suitable range is found, just use the token at the location.
-  auto R = Lexer::makeFileCharRange(CharSourceRange::getTokenRange(Loc), M, L);
-  if (!R.isValid()) // Fall back to location only, let the editor deal with it.
-R = CharSourceRange::getCharRange(Loc);
+  }
+  // If the token at the location is not a comment, we use the token.
+  // If we can't get the token at the location, fall back to using the location
+  auto R = CharSourceRange::getCharRange(Loc);
+  Token Tok;
+  if (!Lexer::getRawToken(Loc, Tok, M, L, true) && Tok.isNot(tok::comment)) {
+R = CharSourceRange::getTokenRange(Tok.getLocation(), Tok.getEndLoc());
+  }
   return halfOpenToRange(M, R);
 }
 
Index: clang-tools-extra/trunk/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/DiagnosticsTests.cpp
@@ -101,6 +101,7 @@
   Annotations Test(R"cpp(
 namespace test{};
 void $decl[[foo]]();
+class T{$explicit[[]]$constructor[[T]](int a);};
 int main() {
   $typo[[go\
 o]]();
@@ -112,8 +113,10 @@
   test::$nomembernamespace[[test]];
 }
   )cpp");
+  auto TU = TestTU::withCode(Test.code());
+  TU.ClangTidyChecks = "-*,google-explicit-constructor";
   EXPECT_THAT(
-  TestTU::withCode(Test.code()).build().getDiagnostics(),
+  TU.build().getDiagnostics(),
   ElementsAre(
   // This range spans lines.
   AllOf(Diag(Test.range("typo"),
@@ -135,7 +138,13 @@
"of type 'const char [4]'"),
   Diag(Test.range("nomember"), "no member named 'y' in 'Foo'"),
   Diag(Test.range("nomembernamespace"),
-   "no member named 'test' in namespace 'test'")));
+   "no member named 'test' in namespace 'test'"),
+  // We make sure here that the entire token is highlighted
+  AllOf(Diag(Test.range("constructor"),
+ "single-argument constructors must be marked explicit to "
+ "avoid unintentional implicit conversions"),
+WithFix(Fix(Test.range("explicit"), "explicit ",
+"insert 'explicit '");
 }
 
 TEST(DiagnosticsTest, FlagsMatter) {


Index: clang-tools-extra/trunk/clangd/Diagnostics.cpp
===
--- clang-tools-extra/trunk/clangd/Diagnostics.cpp
+++ clang-tools-extra/trunk/clangd/Diagnostics.cpp
@@ -18,6 +18,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
+#include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
@@ -90,24 +91,19 @@
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
   }
-  llvm::Optional FallbackRange;
   // The range may be given as a fixit hint instead.
   for (const auto &F : D.getFixItHints()) {
 auto R = Lexer::makeFileCharRange(F.RemoveRange, M, L);
 if (locationInRange(Loc, R, M))
   return halfOpenToRange(M, R);
-// If there's a fixit that 

[PATCH] D63256: [OpenCL] Split type and macro definitions into opencl-c-base.h

2019-06-13 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.
svenvh added a reviewer: asavonic.
Herald added subscribers: cfe-commits, jfb, yaxunl, mgorny.
Herald added a project: clang.

Using the -fdeclare-opencl-builtins option will require a way to
predefine types and macros such as `int4`, `CLK_GLOBAL_MEM_FENCE`,
etc.  Move these out of opencl-c.h into opencl-c-base.h that is shared
by -fdeclare-opencl-builtins and -finclude-default-header.


Repository:
  rC Clang

https://reviews.llvm.org/D63256

Files:
  lib/Frontend/CompilerInvocation.cpp
  lib/Headers/CMakeLists.txt
  lib/Headers/opencl-c-base.h
  lib/Headers/opencl-c.h
  test/SemaOpenCL/fdeclare-opencl-builtins.cl

Index: test/SemaOpenCL/fdeclare-opencl-builtins.cl
===
--- test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -2,12 +2,6 @@
 
 // Test the -fdeclare-opencl-builtins option.
 
-typedef float float4 __attribute__((ext_vector_type(4)));
-typedef int int4 __attribute__((ext_vector_type(4)));
-typedef int int2 __attribute__((ext_vector_type(2)));
-typedef unsigned int uint;
-typedef __SIZE_TYPE__ size_t;
-
 kernel void basic_conversion(global float4 *buf, global int4 *res) {
   res[0] = convert_int4(buf[0]);
 }
Index: lib/Headers/opencl-c.h
===
--- lib/Headers/opencl-c.h
+++ lib/Headers/opencl-c.h
@@ -9,6 +9,8 @@
 #ifndef _OPENCL_H_
 #define _OPENCL_H_
 
+#include "opencl-c-base.h"
+
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
 #ifndef cl_khr_depth_images
 #define cl_khr_depth_images
@@ -33,255 +35,6 @@
 #define __purefn __attribute__((pure))
 #define __cnfn __attribute__((const))
 
-// built-in scalar data types:
-
-/**
- * An unsigned 8-bit integer.
- */
-typedef unsigned char uchar;
-
-/**
- * An unsigned 16-bit integer.
- */
-typedef unsigned short ushort;
-
-/**
- * An unsigned 32-bit integer.
- */
-typedef unsigned int uint;
-
-/**
- * An unsigned 64-bit integer.
- */
-typedef unsigned long ulong;
-
-/**
- * The unsigned integer type of the result of the sizeof operator. This
- * is a 32-bit unsigned integer if CL_DEVICE_ADDRESS_BITS
- * defined in table 4.3 is 32-bits and is a 64-bit unsigned integer if
- * CL_DEVICE_ADDRESS_BITS is 64-bits.
- */
-typedef __SIZE_TYPE__ size_t;
-
-/**
- * A signed integer type that is the result of subtracting two pointers.
- * This is a 32-bit signed integer if CL_DEVICE_ADDRESS_BITS
- * defined in table 4.3 is 32-bits and is a 64-bit signed integer if
- * CL_DEVICE_ADDRESS_BITS is 64-bits.
- */
-typedef __PTRDIFF_TYPE__ ptrdiff_t;
-
-/**
-* A signed integer type with the property that any valid pointer to
-* void can be converted to this type, then converted back to pointer
-* to void, and the result will compare equal to the original pointer.
-*/
-typedef __INTPTR_TYPE__ intptr_t;
-
-/**
-* An unsigned integer type with the property that any valid pointer to
-* void can be converted to this type, then converted back to pointer
-* to void, and the result will compare equal to the original pointer.
-*/
-typedef __UINTPTR_TYPE__ uintptr_t;
-
-// built-in vector data types:
-typedef char char2 __attribute__((ext_vector_type(2)));
-typedef char char3 __attribute__((ext_vector_type(3)));
-typedef char char4 __attribute__((ext_vector_type(4)));
-typedef char char8 __attribute__((ext_vector_type(8)));
-typedef char char16 __attribute__((ext_vector_type(16)));
-typedef uchar uchar2 __attribute__((ext_vector_type(2)));
-typedef uchar uchar3 __attribute__((ext_vector_type(3)));
-typedef uchar uchar4 __attribute__((ext_vector_type(4)));
-typedef uchar uchar8 __attribute__((ext_vector_type(8)));
-typedef uchar uchar16 __attribute__((ext_vector_type(16)));
-typedef short short2 __attribute__((ext_vector_type(2)));
-typedef short short3 __attribute__((ext_vector_type(3)));
-typedef short short4 __attribute__((ext_vector_type(4)));
-typedef short short8 __attribute__((ext_vector_type(8)));
-typedef short short16 __attribute__((ext_vector_type(16)));
-typedef ushort ushort2 __attribute__((ext_vector_type(2)));
-typedef ushort ushort3 __attribute__((ext_vector_type(3)));
-typedef ushort ushort4 __attribute__((ext_vector_type(4)));
-typedef ushort ushort8 __attribute__((ext_vector_type(8)));
-typedef ushort ushort16 __attribute__((ext_vector_type(16)));
-typedef int int2 __attribute__((ext_vector_type(2)));
-typedef int int3 __attribute__((ext_vector_type(3)));
-typedef int int4 __attribute__((ext_vector_type(4)));
-typedef int int8 __attribute__((ext_vector_type(8)));
-typedef int int16 __attribute__((ext_vector_type(16)));
-typedef uint uint2 __attribute__((ext_vector_type(2)));
-typedef uint uint3 __attribute__((ext_vector_type(3)));
-typedef uint uint4 __attribute__((ext_vector_type(4)));
-typedef uint uint8 __attribute__((ext_vector_type(8)));
-typedef uint uint16 __attribute__((ext_vector_type(16)));
-typedef long long2 __attribute__((ext_vector_type(2)));
-typedef long l

[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

2019-06-13 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 created this revision.
xbolva00 added reviewers: aaron.ballman, rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D63260

Files:
  include/clang/Basic/Attr.td
  lib/Parse/ParseStmt.cpp
  lib/Sema/AnalysisBasedWarnings.cpp
  test/Sema/address_spaces.c
  test/Sema/block-literal.c
  test/Sema/fallthrough-attr.c
  test/SemaCXX/switch-implicit-fallthrough.cpp
  test/SemaCXX/warn-unused-label-error.cpp

Index: test/SemaCXX/warn-unused-label-error.cpp
===
--- test/SemaCXX/warn-unused-label-error.cpp
+++ test/SemaCXX/warn-unused-label-error.cpp
@@ -18,9 +18,9 @@
   }
 
   void h() {
-D: // expected-warning {{unused label 'D'}}
+D:
   #pragma weak unused_local_static
-  __attribute__((unused))  // expected-warning {{declaration does not declare anything}}
+  __attribute__((unused))  // expected-error {{'unused' attribute cannot be applied to a statement}}
   ;
   }
 }
Index: test/SemaCXX/switch-implicit-fallthrough.cpp
===
--- test/SemaCXX/switch-implicit-fallthrough.cpp
+++ test/SemaCXX/switch-implicit-fallthrough.cpp
@@ -329,3 +329,15 @@
   }
   return n;
 }
+
+int fallthrough_attribute_spelling(int n) {
+  switch (n) {
+  case 0:
+n++;
+__attribute__ ((fallthrough));
+  case 1:
+n++;
+break;
+  }
+  return n;
+}
Index: test/Sema/fallthrough-attr.c
===
--- test/Sema/fallthrough-attr.c
+++ test/Sema/fallthrough-attr.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -verify -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -std=c11 -verify -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2x -DC2X -verify -Wimplicit-fallthrough %s
+
+int fallthrough_attribute_spelling(int n) {
+  switch (n) {
+  case 0:
+n++;
+  case 1: 
+#if defined(C2X)
+// expected-warning@-2{{unannotated fall-through between switch labels}} expected-note@-2{{insert '[[fallthrough]];' to silence this warning}} expected-note@-2{{insert 'break;' to avoid fall-through}}
+#else
+// expected-warning@-4{{unannotated fall-through between switch labels}} expected-note@-4{{insert '__attribute__ ((fallthrough));' to silence this warning}} expected-note@-4{{insert 'break;' to avoid fall-through}}
+#endif
+n++;
+__attribute__ ((fallthrough));
+  case 2:
+n++;
+break;
+  }
+  return n;
+}
\ No newline at end of file
Index: test/Sema/block-literal.c
===
--- test/Sema/block-literal.c
+++ test/Sema/block-literal.c
@@ -41,8 +41,8 @@
 
   foo:
   takeblock(^{ x = 4; });  // expected-error {{variable is not assignable (missing __block type specifier)}}
-  __block y = 7;// expected-warning {{type specifier missing, defaults to 'int'}}
-  takeblock(^{ y = 8; });
+  __block y = 7;// expected-error {{use of undeclared identifier 'y'}}
+  takeblock(^{ y = 8; }); // expected-error {{use of undeclared identifier 'y'}}
 }
 
 
Index: test/Sema/address_spaces.c
===
--- test/Sema/address_spaces.c
+++ test/Sema/address_spaces.c
@@ -9,7 +9,7 @@
 void foo(_AS3 float *a,
  _AS1 float b) // expected-error {{parameter may not be qualified with an address space}}
 {
-  _AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}}
+  _AS2 *x;// expected-error {{use of undeclared identifier 'x'}}
   _AS1 float * _AS2 *B;
 
   int _AS1 _AS2 *Y;   // expected-error {{multiple address spaces specified for type}}
Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -1215,7 +1215,7 @@
 tok::r_square, tok::r_square
   };
 
-  bool PreferClangAttr = !PP.getLangOpts().CPlusPlus17;
+  bool PreferClangAttr = !PP.getLangOpts().CPlusPlus17 && !PP.getLangOpts().C2x;
 
   StringRef MacroName;
   if (PreferClangAttr)
@@ -1224,24 +1224,19 @@
 MacroName = PP.getLastMacroWithSpelling(Loc, FallthroughTokens);
   if (MacroName.empty() && !PreferClangAttr)
 MacroName = PP.getLastMacroWithSpelling(Loc, ClangFallthroughTokens);
-  if (MacroName.empty())
-MacroName = PreferClangAttr ? "[[clang::fallthrough]]" : "[[fallthrough]]";
+  if (MacroName.empty()) {
+if (!PreferClangAttr)
+  MacroName = "[[fallthrough]]";
+else if (PP.getLangOpts().CPlusPlus)
+  MacroName = "[[clang::fallthrough]]";
+else
+  MacroName = "__attribute__ ((fallthrough))";
+  }
   return MacroName;
 }
 
 static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC,
 bool PerFunction) {
-  // Only perform this analysis when using [[]] attributes. There is no go

[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

2019-06-13 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 marked an inline comment as done.
xbolva00 added inline comments.



Comment at: test/Sema/block-literal.c:44
   takeblock(^{ x = 4; });  // expected-error {{variable is not assignable 
(missing __block type specifier)}}
-  __block y = 7;// expected-warning {{type specifier missing, defaults to 
'int'}}
-  takeblock(^{ y = 8; });
+  __block y = 7;// expected-error {{use of undeclared identifier 'y'}}
+  takeblock(^{ y = 8; }); // expected-error {{use of undeclared identifier 
'y'}}

I tried look at this, but I have no idea how my change to parse GNU affects 
__block.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63260



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


[PATCH] D63261: [clang-tidy] Fixed abseil-time-subtraction to work on C++17

2019-06-13 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom created this revision.
jvikstrom added reviewers: hokein, gribozavr.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Fixed abseil-time-subtraction to work on C++17


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63261

Files:
  clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
  clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp


Index: clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp
===
--- clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp
+++ clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-time-subtraction %t -- -- 
-I %S/Inputs
+// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-time-subtraction %t -- 
-- -I %S/Inputs
 // FIXME: Fix the checker to work in C++17 mode.
 
 #include "absl/time/time.h"
Index: clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
@@ -29,16 +29,26 @@
 
 static bool isConstructorAssignment(const MatchFinder::MatchResult &Result,
 const Expr *Node) {
+  // For C++14 and earlier there are elidable constructors that must be matched
+  // in hasParent. The elidable constructors do not exist in C++17 and later 
and
+  // therefore an additional check that does not match against the elidable
+  // constructors are needed for this case.
   return selectFirst(
- "e", match(expr(hasParent(materializeTemporaryExpr(hasParent(
- cxxConstructExpr(hasParent(exprWithCleanups(
- hasParent(varDecl()
-.bind("e"),
-*Node, *Result.Context)) != nullptr;
+ "e",
+ match(callExpr(hasParent(materializeTemporaryExpr(
+hasParent(cxxConstructExpr(hasParent(
+
exprWithCleanups(hasParent(varDecl()
+   .bind("e"),
+   *Node, *Result.Context)) != nullptr ||
+ selectFirst("e",
+ 
match(callExpr(hasParent(varDecl())).bind("e"),
+   *Node, *Result.Context)) != nullptr;
 }
 
 static bool isArgument(const MatchFinder::MatchResult &Result,
const Expr *Node) {
+  // For the same reason as in isConstructorAssignment two separate 
selectFirsts
+  // need to be checked here
   return selectFirst(
  "e",
  match(expr(hasParent(
@@ -46,16 +56,26 @@
 hasParent(callExpr()),
 unless(hasParent(cxxOperatorCallExpr(
.bind("e"),
-   *Node, *Result.Context)) != nullptr;
+   *Node, *Result.Context)) != nullptr ||
+ selectFirst(
+ "e", match(expr(hasParent(callExpr()),
+ unless(hasParent(cxxOperatorCallExpr(
+.bind("e"),
+*Node, *Result.Context)) != nullptr;
 }
 
 static bool isReturn(const MatchFinder::MatchResult &Result, const Expr *Node) 
{
+  // For the same reason as in isConstructorAssignment two separate 
selectFirsts
+  // need to be checked here
   return selectFirst(
  "e", match(expr(hasParent(materializeTemporaryExpr(hasParent(
  cxxConstructExpr(hasParent(exprWithCleanups(
  hasParent(returnStmt()
 .bind("e"),
-*Node, *Result.Context)) != nullptr;
+*Node, *Result.Context)) != nullptr ||
+ selectFirst("e",
+ match(expr(hasParent(returnStmt())).bind("e"),
+   *Node, *Result.Context)) != nullptr;
 }
 
 static bool parensRequired(const MatchFinder::MatchResult &Result,


Index: clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp
===
--- clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp
+++ clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-time-subtraction %t -- -- -I %S/Inputs
+// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-time-subtraction %t -- -- -I %S/Inputs
 // FIXME: Fix the checker to work in C++17 mode.
 
 #include "absl/time/time.h"
Index: clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
===
--- clang-tools-extra

[PATCH] D63262: [clang-tidy] Made abseil-upgrade-duration-conversions tests pass on c++17

2019-06-13 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom created this revision.
jvikstrom added reviewers: hokein, gribozavr.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Made abseil-upgrade-duration-conversions tests pass on c++17


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63262

Files:
  clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
  clang-tools-extra/test/clang-tidy/abseil-upgrade-duration-conversions.cpp


Index: clang-tools-extra/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
===
--- clang-tools-extra/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
+++ clang-tools-extra/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s 
abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs
+// RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs
 // FIXME: Fix the checker to work in C++17 mode.
 
 using int64_t = long long;
Index: clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
@@ -40,7 +40,8 @@
   callee(functionDecl(
   hasParent(functionTemplateDecl()),
   unless(hasTemplateArgument(0, refersToType(builtinType(,
-  hasAnyName("operator*=", "operator/=",
+  hasAnyName("operator*=", "operator/="
+  .bind("OuterExpr"),
   this);
 
   // Match expressions like `a.operator*=(b)` and `a.operator/=(b)` where `a`
@@ -52,7 +53,8 @@
   hasParent(functionTemplateDecl()),
   unless(hasTemplateArgument(0, refersToType(builtinType(,
   hasAnyName("operator*=", "operator/="))),
-  argumentCountIs(1), hasArgument(0, expr().bind("arg"))),
+  argumentCountIs(1), hasArgument(0, expr().bind("arg")))
+  .bind("OuterExpr"),
   this);
 
   // Match expressions like `a * b`, `a / b`, `operator*(a, b)`, and
@@ -66,7 +68,8 @@
argumentCountIs(2),
hasArgument(0, expr(hasType(
   
cxxRecordDecl(hasName("::absl::Duration"),
-   hasArgument(1, expr().bind("arg"))),
+   hasArgument(1, expr().bind("arg")))
+  .bind("OuterExpr"),
   this);
 
   // Match expressions like `a * b` and `operator*(a, b)` where `a` is not of a
@@ -77,8 +80,9 @@
unless(hasTemplateArgument(0, refersToType(builtinType(,
hasName("::absl::operator*"))),
argumentCountIs(2), hasArgument(0, expr().bind("arg")),
-   hasArgument(1, expr(hasType(cxxRecordDecl(
-  hasName("::absl::Duration")),
+   hasArgument(1, expr(hasType(
+  
cxxRecordDecl(hasName("::absl::Duration"))
+  .bind("OuterExpr"),
   this);
 
   // For the factory functions, we match only the non-templated overloads that
@@ -103,8 +107,9 @@
 has(implicitCastExpr(hasCastKind(CK_UserDefinedConversion,
   hasParent(callExpr(
   callee(functionDecl(DurationFactoryFunction(),
-  unless(hasParent(functionTemplateDecl(),
-  hasArgument(0, expr().bind("arg"),
+  unless(hasParent(functionTemplateDecl(),
+  hasArgument(0, expr().bind("arg")
+  .bind("OuterExpr"),
   this);
 }
 
@@ -117,7 +122,10 @@
   const auto *ArgExpr = Result.Nodes.getNodeAs("arg");
   SourceLocation Loc = ArgExpr->getBeginLoc();
 
-  if (!match(isInTemplateInstantiation(), *ArgExpr, *Result.Context).empty()) {
+  const auto *OuterExpr = Result.Nodes.getNodeAs("OuterExpr");
+
+  if (!match(isInTemplateInstantiation(), *OuterExpr, *Result.Context)
+   .empty()) {
 if (MatchedTemplateLocations.count(Loc.getRawEncoding()) == 0) {
   // For each location matched in a template instantiation, we check if the
   // location can also be found in `MatchedTemplateLocations`. If it is not


Index: clang-tools-extra/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
===
--- clang-tools-extra/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
+++ clang-tools-extra/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs
+// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs
 // FIXME: Fix the checker to work in C++17 mode.
 
 using int64_t = long long;
Index: clang-tools-extra/clang

[PATCH] D63263: [clang-tidy] Fixed abseil-duration-unnecessary-conversion tests for c++17

2019-06-13 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom created this revision.
jvikstrom added reviewers: hokein, gribozavr.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Fixed abseil-duration-unnecessary-conversion tests for c++17


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63263

Files:
  clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
  clang-tools-extra/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp


Index: 
clang-tools-extra/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
===
--- clang-tools-extra/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
+++ clang-tools-extra/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s 
abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
 
 #include "absl/time/time.h"
 
Index: 
clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
@@ -30,10 +30,9 @@
 
 // Matcher which matches the current scale's factory with a `1` argument,
 // e.g. `absl::Seconds(1)`.
-auto factory_matcher = cxxConstructExpr(hasArgument(
-0,
+auto factory_matcher = ignoringElidableConstructorCall(
 callExpr(callee(functionDecl(hasName(DurationFactory))),
- hasArgument(0, 
ignoringImpCasts(integerLiteral(equals(1)));
+ hasArgument(0, ignoringImpCasts(integerLiteral(equals(1));
 
 // Matcher which matches either inverse function and binds its argument,
 // e.g. `absl::ToDoubleSeconds(dur)`.


Index: clang-tools-extra/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
===
--- clang-tools-extra/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
+++ clang-tools-extra/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
 
 #include "absl/time/time.h"
 
Index: clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
@@ -30,10 +30,9 @@
 
 // Matcher which matches the current scale's factory with a `1` argument,
 // e.g. `absl::Seconds(1)`.
-auto factory_matcher = cxxConstructExpr(hasArgument(
-0,
+auto factory_matcher = ignoringElidableConstructorCall(
 callExpr(callee(functionDecl(hasName(DurationFactory))),
- hasArgument(0, ignoringImpCasts(integerLiteral(equals(1)));
+ hasArgument(0, ignoringImpCasts(integerLiteral(equals(1));
 
 // Matcher which matches either inverse function and binds its argument,
 // e.g. `absl::ToDoubleSeconds(dur)`.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63127: [clang-tidy] Fixed checker for abseil to work in C++17 mode

2019-06-13 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom abandoned this revision.
jvikstrom added a comment.

Resubmitted as 4 different CLs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63127



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


[PATCH] D63261: [clang-tidy] Fixed abseil-time-subtraction to work on C++17

2019-06-13 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added inline comments.



Comment at: clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp:45
+ 
match(callExpr(hasParent(varDecl())).bind("e"),
+   *Node, *Result.Context)) != nullptr;
 }

Use anyOf() instead two selectFirsts?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63261



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


r363262 - Added AST matcher for ignoring elidable constructors

2019-06-13 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Jun 13 06:48:24 2019
New Revision: 363262

URL: http://llvm.org/viewvc/llvm-project?rev=363262&view=rev
Log:
Added AST matcher for ignoring elidable constructors

Summary: Added AST matcher for ignoring elidable move constructors

Reviewers: hokein, gribozavr

Reviewed By: hokein, gribozavr

Subscribers: cfe-commits

Tags: #clang

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

Patch by Johan Vikström.

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=363262&r1=363261&r2=363262&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Jun 13 06:48:24 2019
@@ -5728,6 +5728,32 @@ Example matches x (matcher = expr(hasTyp
 
 
 
+MatcherExpr>ignoringElidableConstructorCallast_matchers::MatcherExpr> 
InnerMatcher
+Matches expressions that match 
InnerMatcher that are possibly wrapped in an
+elidable constructor.
+
+In C++17 copy elidable constructors are no longer being
+generated in the AST as it is not permitted by the standard. They are
+however part of the AST in C++14 and earlier. Therefore, to write a matcher
+that works in all language modes, the matcher has to skip elidable
+constructor AST nodes if they appear in the AST. This matcher can be used to
+skip those elidable constructors.
+
+Given
+
+struct H {};
+H G();
+void f() {
+  H D = G();
+}
+
+``varDecl(hasInitializer(any(
+  ignoringElidableConstructorCall(callExpr()),
+  exprWithCleanups(ignoringElidableConstructorCall(callExpr()``
+matches ``H D = G()``
+
+
+
 MatcherExpr>ignoringImpCastsMatcherExpr> 
InnerMatcher
 Matches 
expressions that match InnerMatcher after any implicit casts
 are stripped off.

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=363262&r1=363261&r2=363262&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Jun 13 06:48:24 2019
@@ -6452,6 +6452,44 @@ AST_MATCHER(FunctionDecl, hasTrailingRet
   return false;
 }
 
+/// Matches expressions that match InnerMatcher that are possibly wrapped in an
+/// elidable constructor.
+///
+/// In C++17 copy elidable constructors are no longer being
+/// generated in the AST as it is not permitted by the standard. They are
+/// however part of the AST in C++14 and earlier. Therefore, to write a matcher
+/// that works in all language modes, the matcher has to skip elidable
+/// constructor AST nodes if they appear in the AST. This matcher can be used 
to
+/// skip those elidable constructors.
+///
+/// Given
+///
+/// \code
+/// struct H {};
+/// H G();
+/// void f() {
+///   H D = G();
+/// }
+/// \endcode
+///
+/// ``varDecl(hasInitializer(any(
+///   ignoringElidableConstructorCall(callExpr()),
+///   exprWithCleanups(ignoringElidableConstructorCall(callExpr()``
+/// matches ``H D = G()``
+AST_MATCHER_P(Expr, ignoringElidableConstructorCall,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  if (const auto *CtorExpr = dyn_cast(&Node)) {
+if (CtorExpr->isElidable()) {
+  if (const auto *MaterializeTemp =
+  dyn_cast(CtorExpr->getArg(0))) {
+return InnerMatcher.matches(*MaterializeTemp->GetTemporaryExpr(),
+Finder, Builder);
+  }
+}
+  }
+  return InnerMatcher.matches(Node, Finder, Builder);
+}
+
 
////
 // OpenMP handling.
 
////

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=363262&r1=363261&r2=363262&view=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Thu Jun 13 06:48:24 2019
@@ -320,6 +320,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(hasUnqualifiedDesugaredType);
   REGISTER_MATCHER(hasValueType);
   REGISTER_MATCHER(ifStmt);
+  REGI

[PATCH] D63149: Added AST matcher for ignoring elidable constructors

2019-06-13 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363262: Added AST matcher for ignoring elidable constructors 
(authored by gribozavr, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63149?vs=204447&id=204522#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63149

Files:
  cfe/trunk/docs/LibASTMatchersReference.html
  cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
  cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
  cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.h

Index: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -320,6 +320,7 @@
   REGISTER_MATCHER(hasUnqualifiedDesugaredType);
   REGISTER_MATCHER(hasValueType);
   REGISTER_MATCHER(ifStmt);
+  REGISTER_MATCHER(ignoringElidableConstructorCall);
   REGISTER_MATCHER(ignoringImpCasts);
   REGISTER_MATCHER(ignoringImplicit);
   REGISTER_MATCHER(ignoringParenCasts);
Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -566,6 +566,74 @@
llvm::make_unique>("x")));
 }
 
+TEST(Matcher, IgnoresElidableConstructors) {
+  EXPECT_TRUE(
+  matches("struct H {};"
+  "template H B(T A);"
+  "void f() {"
+  "  H D1;"
+  "  D1 = B(B(1));"
+  "}",
+  cxxOperatorCallExpr(hasArgument(
+  1, callExpr(hasArgument(
+ 0, ignoringElidableConstructorCall(callExpr()),
+  LanguageMode::Cxx11OrLater));
+  EXPECT_TRUE(
+  matches("struct H {};"
+  "template H B(T A);"
+  "void f() {"
+  "  H D1;"
+  "  D1 = B(1);"
+  "}",
+  cxxOperatorCallExpr(hasArgument(
+  1, callExpr(hasArgument(0, ignoringElidableConstructorCall(
+ integerLiteral()),
+  LanguageMode::Cxx11OrLater));
+  EXPECT_TRUE(matches(
+  "struct H {};"
+  "H G();"
+  "void f() {"
+  "  H D = G();"
+  "}",
+  varDecl(hasInitializer(anyOf(
+  ignoringElidableConstructorCall(callExpr()),
+  exprWithCleanups(has(ignoringElidableConstructorCall(callExpr())),
+  LanguageMode::Cxx11OrLater));
+}
+
+TEST(Matcher, IgnoresElidableInReturn) {
+  auto matcher = expr(ignoringElidableConstructorCall(declRefExpr()));
+  EXPECT_TRUE(matches("struct H {};"
+  "H f() {"
+  "  H g;"
+  "  return g;"
+  "}",
+  matcher, LanguageMode::Cxx11OrLater));
+  EXPECT_TRUE(notMatches("struct H {};"
+ "H f() {"
+ "  return H();"
+ "}",
+ matcher, LanguageMode::Cxx11OrLater));
+}
+
+TEST(Matcher, IgnoreElidableConstructorDoesNotMatchConstructors) {
+  EXPECT_TRUE(matches("struct H {};"
+  "void f() {"
+  "  H D;"
+  "}",
+  varDecl(hasInitializer(
+  ignoringElidableConstructorCall(cxxConstructExpr(,
+  LanguageMode::Cxx11OrLater));
+}
+
+TEST(Matcher, IgnoresElidableDoesNotPreventMatches) {
+  EXPECT_TRUE(matches("void f() {"
+  "  int D = 10;"
+  "}",
+  expr(ignoringElidableConstructorCall(integerLiteral())),
+  LanguageMode::Cxx11OrLater));
+}
+
 TEST(Matcher, BindTheSameNameInAlternatives) {
   StatementMatcher matcher = anyOf(
 binaryOperator(hasOperatorName("+"),
@@ -914,10 +982,10 @@
   varDecl(hasName("foo"), isConstexpr(;
   EXPECT_TRUE(matches("constexpr int bar();",
   functionDecl(hasName("bar"), isConstexpr(;
-  EXPECT_TRUE(matchesConditionally("void baz() { if constexpr(1 > 0) {} }",
-   ifStmt(isConstexpr()), true, "-std=c++17"));
-  EXPECT_TRUE(matchesConditionally("void baz() { if (1 > 0) {} }",
-   ifStmt(isConstexpr()), false, "-std=c++17"));
+  EXPECT_TRUE(matches("void baz() { if constexpr(1 > 0) {} }",
+  ifStmt(isConstexpr()), LanguageMode::Cxx17OrLater));
+  EXPECT_TRUE(notMatches("void baz() { if (1 > 0) {} }", ifStmt(isConstexpr()),
+ LanguageMode::Cxx17

[clang-tools-extra] r363263 - [clang-tidy] Fixed abseil-duration-unnecessary-conversion tests for c++17

2019-06-13 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Jun 13 06:52:45 2019
New Revision: 363263

URL: http://llvm.org/viewvc/llvm-project?rev=363263&view=rev
Log:
[clang-tidy] Fixed abseil-duration-unnecessary-conversion tests for c++17

Summary: Fixed abseil-duration-unnecessary-conversion tests for c++17

Reviewers: hokein, gribozavr

Reviewed By: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Patch by Johan Vikström.

Modified:

clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp?rev=363263&r1=363262&r2=363263&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
 Thu Jun 13 06:52:45 2019
@@ -30,10 +30,9 @@ void DurationUnnecessaryConversionCheck:
 
 // Matcher which matches the current scale's factory with a `1` argument,
 // e.g. `absl::Seconds(1)`.
-auto factory_matcher = cxxConstructExpr(hasArgument(
-0,
+auto factory_matcher = ignoringElidableConstructorCall(
 callExpr(callee(functionDecl(hasName(DurationFactory))),
- hasArgument(0, 
ignoringImpCasts(integerLiteral(equals(1)));
+ hasArgument(0, ignoringImpCasts(integerLiteral(equals(1));
 
 // Matcher which matches either inverse function and binds its argument,
 // e.g. `absl::ToDoubleSeconds(dur)`.

Modified: 
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp?rev=363263&r1=363262&r2=363263&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
 Thu Jun 13 06:52:45 2019
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s 
abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
 
 #include "absl/time/time.h"
 


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


[PATCH] D63263: [clang-tidy] Fixed abseil-duration-unnecessary-conversion tests for c++17

2019-06-13 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363263: [clang-tidy] Fixed 
abseil-duration-unnecessary-conversion tests for c++17 (authored by gribozavr, 
committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63263?vs=204519&id=204523#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63263

Files:
  
clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
  
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp


Index: 
clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
===
--- 
clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
+++ 
clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
@@ -30,10 +30,9 @@
 
 // Matcher which matches the current scale's factory with a `1` argument,
 // e.g. `absl::Seconds(1)`.
-auto factory_matcher = cxxConstructExpr(hasArgument(
-0,
+auto factory_matcher = ignoringElidableConstructorCall(
 callExpr(callee(functionDecl(hasName(DurationFactory))),
- hasArgument(0, 
ignoringImpCasts(integerLiteral(equals(1)));
+ hasArgument(0, ignoringImpCasts(integerLiteral(equals(1));
 
 // Matcher which matches either inverse function and binds its argument,
 // e.g. `absl::ToDoubleSeconds(dur)`.
Index: 
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
===
--- 
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
+++ 
clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s 
abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
 
 #include "absl/time/time.h"
 


Index: clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/abseil/DurationUnnecessaryConversionCheck.cpp
@@ -30,10 +30,9 @@
 
 // Matcher which matches the current scale's factory with a `1` argument,
 // e.g. `absl::Seconds(1)`.
-auto factory_matcher = cxxConstructExpr(hasArgument(
-0,
+auto factory_matcher = ignoringElidableConstructorCall(
 callExpr(callee(functionDecl(hasName(DurationFactory))),
- hasArgument(0, ignoringImpCasts(integerLiteral(equals(1)));
+ hasArgument(0, ignoringImpCasts(integerLiteral(equals(1));
 
 // Matcher which matches either inverse function and binds its argument,
 // e.g. `absl::ToDoubleSeconds(dur)`.
Index: clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-duration-unnecessary-conversion.cpp
@@ -1,5 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
-// FIXME: Fix the checker to work in C++17 mode.
+// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
 
 #include "absl/time/time.h"
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63264: [clang][Driver] Deduce target triplet from clang executable name

2019-06-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: ilya-biryukov.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
kadircet added a child revision: D63194: [clangd] Link in target infos and pass 
target and mode while invoking driver.
Herald added a subscriber: ormris.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63264

Files:
  clang/examples/clang-interpreter/main.cpp
  clang/include/clang/Driver/Driver.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
  clang/lib/Tooling/CompilationDatabase.cpp
  clang/lib/Tooling/Tooling.cpp
  clang/tools/driver/cc1gen_reproducer_main.cpp
  clang/tools/driver/driver.cpp
  clang/unittests/Driver/ToolChainTest.cpp

Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -16,6 +16,8 @@
 #include "clang/Basic/LLVM.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/VirtualFileSystem.h"
@@ -34,8 +36,8 @@
   DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
   IntrusiveRefCntPtr InMemoryFileSystem(
   new llvm::vfs::InMemoryFileSystem);
-  Driver TheDriver("/bin/clang", "arm-linux-gnueabihf", Diags,
-   InMemoryFileSystem);
+  Driver TheDriver("/bin/clang", Diags, InMemoryFileSystem,
+   "arm-linux-gnueabihf");
 
   const char *EmptyFiles[] = {
   "foo.cpp",
@@ -88,8 +90,8 @@
   DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
   IntrusiveRefCntPtr InMemoryFileSystem(
   new llvm::vfs::InMemoryFileSystem);
-  Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
-   InMemoryFileSystem);
+  Driver TheDriver("/home/test/bin/clang", Diags, InMemoryFileSystem,
+   "arm-linux-gnueabi");
 
   const char *EmptyFiles[] = {
   "foo.cpp", "/home/test/lib/gcc/arm-linux-gnueabi/4.6.1/crtbegin.o",
@@ -129,14 +131,14 @@
   IntrusiveRefCntPtr InMemoryFileSystem(
   new llvm::vfs::InMemoryFileSystem);
 
-  Driver CCDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
-  InMemoryFileSystem);
+  Driver CCDriver("/home/test/bin/clang", Diags, InMemoryFileSystem,
+  "arm-linux-gnueabi");
   CCDriver.setCheckInputsExist(false);
-  Driver CXXDriver("/home/test/bin/clang++", "arm-linux-gnueabi", Diags,
-   InMemoryFileSystem);
+  Driver CXXDriver("/home/test/bin/clang++", Diags, InMemoryFileSystem,
+   "arm-linux-gnueabi");
   CXXDriver.setCheckInputsExist(false);
-  Driver CLDriver("/home/test/bin/clang-cl", "arm-linux-gnueabi", Diags,
-  InMemoryFileSystem);
+  Driver CLDriver("/home/test/bin/clang-cl", Diags, InMemoryFileSystem,
+  "arm-linux-gnueabi");
   CLDriver.setCheckInputsExist(false);
 
   std::unique_ptr CC(CCDriver.BuildCompilation(
@@ -158,7 +160,7 @@
   struct TestDiagnosticConsumer : public DiagnosticConsumer {};
   IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
   DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
-  Driver TheDriver("/bin/clang", "arm-linux-gnueabihf", Diags);
+  Driver TheDriver("/bin/clang", Diags, nullptr, "arm-linux-gnueabihf");
   std::unique_ptr C(TheDriver.BuildCompilation(
   {"-fsyntax-only", "-fan-unknown-option", "foo.cpp"}));
   EXPECT_TRUE(C);
@@ -259,4 +261,46 @@
   EXPECT_STREQ(Res.DriverMode, "--driver-mode=cl");
   EXPECT_FALSE(Res.TargetIsValid);
 }
+
+TEST(ToolChainTest, TargetTripletDeduction) {
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+  DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+
+  // TargetTriple set
+  {
+Driver TheDriver("/bin/x86_64-fuchsia-clang", Diags, nullptr,
+ "arm-linux-gnueabihf");
+std::unique_ptr C(
+TheDriver.BuildCompilation({"-fsyntax-only", "foo.cpp"}));
+EXPECT_TRUE(C);
+EXPECT_EQ(C->getDefaultToolChain().ComputeEffectiveClangTriple(
+  llvm::opt::InputArgList{}),
+  "armv6kz-unknown-linux-gnueabihf");
+  }
+
+  // TargetTriple deduced from executable
+  {
+Driver TheDriver("/bin/x86_64-fuchsia-clang", Diags);
+std::unique_ptr C(
+TheDriver.BuildCompilation({"-fsyntax-only", "foo.cpp"}));
+EXPECT_TRUE(C);
+EXPECT_EQ(C->getDefaultToolChain().ComputeEffectiveClangTriple(
+  llvm::opt::InputArgList{}),
+  "x86_64-unknown-linux-gnu");
+  }
+
+  // TargetTriple from default triplet
+  {
+Driver TheDriver("clang", Diags);
+std::un

[PATCH] D63194: [clangd] Link in target infos and pass target and mode while invoking driver

2019-06-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 3 inline comments as done.
kadircet added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:1055
+  else if (ClangNameParts.TargetIsValid)
+TargetTriple = ClangNameParts.TargetPrefix;
+

ilya-biryukov wrote:
> I strongly think the driver is the right place to do this, but we have to 
> watch out for breakages coming from this. The drivers code has way more uses 
> than clangd code, so we should expect that people rely on all kinds of things 
> there.
> 
> Could you separate the driver pieces into a separate change and add driver 
> tests for them? To make it more focused and easier to revert in case of 
> breakages.
sent out D63264


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63194



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


[clang-tools-extra] r363270 - [clang-tidy] Made abseil-upgrade-duration-conversions tests pass on c++17

2019-06-13 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Jun 13 07:27:54 2019
New Revision: 363270

URL: http://llvm.org/viewvc/llvm-project?rev=363270&view=rev
Log:
[clang-tidy] Made abseil-upgrade-duration-conversions tests pass on c++17

Summary: Made abseil-upgrade-duration-conversions tests pass on c++17

Reviewers: hokein, gribozavr

Reviewed By: gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Patch by Johan Vikström.

Modified:

clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp

clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp?rev=363270&r1=363269&r2=363270&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp 
(original)
+++ 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp 
Thu Jun 13 07:27:54 2019
@@ -40,7 +40,8 @@ void UpgradeDurationConversionsCheck::re
   callee(functionDecl(
   hasParent(functionTemplateDecl()),
   unless(hasTemplateArgument(0, refersToType(builtinType(,
-  hasAnyName("operator*=", "operator/=",
+  hasAnyName("operator*=", "operator/="
+  .bind("OuterExpr"),
   this);
 
   // Match expressions like `a.operator*=(b)` and `a.operator/=(b)` where `a`
@@ -52,7 +53,8 @@ void UpgradeDurationConversionsCheck::re
   hasParent(functionTemplateDecl()),
   unless(hasTemplateArgument(0, refersToType(builtinType(,
   hasAnyName("operator*=", "operator/="))),
-  argumentCountIs(1), hasArgument(0, expr().bind("arg"))),
+  argumentCountIs(1), hasArgument(0, expr().bind("arg")))
+  .bind("OuterExpr"),
   this);
 
   // Match expressions like `a * b`, `a / b`, `operator*(a, b)`, and
@@ -66,7 +68,8 @@ void UpgradeDurationConversionsCheck::re
argumentCountIs(2),
hasArgument(0, expr(hasType(
   
cxxRecordDecl(hasName("::absl::Duration"),
-   hasArgument(1, expr().bind("arg"))),
+   hasArgument(1, expr().bind("arg")))
+  .bind("OuterExpr"),
   this);
 
   // Match expressions like `a * b` and `operator*(a, b)` where `a` is not of a
@@ -77,8 +80,9 @@ void UpgradeDurationConversionsCheck::re
unless(hasTemplateArgument(0, refersToType(builtinType(,
hasName("::absl::operator*"))),
argumentCountIs(2), hasArgument(0, expr().bind("arg")),
-   hasArgument(1, expr(hasType(cxxRecordDecl(
-  hasName("::absl::Duration")),
+   hasArgument(1, expr(hasType(
+  
cxxRecordDecl(hasName("::absl::Duration"))
+  .bind("OuterExpr"),
   this);
 
   // For the factory functions, we match only the non-templated overloads that
@@ -103,8 +107,9 @@ void UpgradeDurationConversionsCheck::re
 has(implicitCastExpr(hasCastKind(CK_UserDefinedConversion,
   hasParent(callExpr(
   callee(functionDecl(DurationFactoryFunction(),
-  unless(hasParent(functionTemplateDecl(),
-  hasArgument(0, expr().bind("arg"),
+  unless(hasParent(functionTemplateDecl(),
+  hasArgument(0, expr().bind("arg")
+  .bind("OuterExpr"),
   this);
 }
 
@@ -117,7 +122,10 @@ void UpgradeDurationConversionsCheck::ch
   const auto *ArgExpr = Result.Nodes.getNodeAs("arg");
   SourceLocation Loc = ArgExpr->getBeginLoc();
 
-  if (!match(isInTemplateInstantiation(), *ArgExpr, *Result.Context).empty()) {
+  const auto *OuterExpr = Result.Nodes.getNodeAs("OuterExpr");
+
+  if (!match(isInTemplateInstantiation(), *OuterExpr, *Result.Context)
+   .empty()) {
 if (MatchedTemplateLocations.count(Loc.getRawEncoding()) == 0) {
   // For each location matched in a template instantiation, we check if the
   // location can also be found in `MatchedTemplateLocations`. If it is not

Modified: 
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp?rev=363270&r1=363269&r2=363270&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp 
Thu Jun 13 07:27:54 2019
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy

[PATCH] D63262: [clang-tidy] Made abseil-upgrade-duration-conversions tests pass on c++17

2019-06-13 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363270: [clang-tidy] Made 
abseil-upgrade-duration-conversions tests pass on c++17 (authored by gribozavr, 
committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63262?vs=204517&id=204532#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63262

Files:
  clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
  
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp


Index: 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
===
--- 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
+++ 
clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
@@ -40,7 +40,8 @@
   callee(functionDecl(
   hasParent(functionTemplateDecl()),
   unless(hasTemplateArgument(0, refersToType(builtinType(,
-  hasAnyName("operator*=", "operator/=",
+  hasAnyName("operator*=", "operator/="
+  .bind("OuterExpr"),
   this);
 
   // Match expressions like `a.operator*=(b)` and `a.operator/=(b)` where `a`
@@ -52,7 +53,8 @@
   hasParent(functionTemplateDecl()),
   unless(hasTemplateArgument(0, refersToType(builtinType(,
   hasAnyName("operator*=", "operator/="))),
-  argumentCountIs(1), hasArgument(0, expr().bind("arg"))),
+  argumentCountIs(1), hasArgument(0, expr().bind("arg")))
+  .bind("OuterExpr"),
   this);
 
   // Match expressions like `a * b`, `a / b`, `operator*(a, b)`, and
@@ -66,7 +68,8 @@
argumentCountIs(2),
hasArgument(0, expr(hasType(
   
cxxRecordDecl(hasName("::absl::Duration"),
-   hasArgument(1, expr().bind("arg"))),
+   hasArgument(1, expr().bind("arg")))
+  .bind("OuterExpr"),
   this);
 
   // Match expressions like `a * b` and `operator*(a, b)` where `a` is not of a
@@ -77,8 +80,9 @@
unless(hasTemplateArgument(0, refersToType(builtinType(,
hasName("::absl::operator*"))),
argumentCountIs(2), hasArgument(0, expr().bind("arg")),
-   hasArgument(1, expr(hasType(cxxRecordDecl(
-  hasName("::absl::Duration")),
+   hasArgument(1, expr(hasType(
+  
cxxRecordDecl(hasName("::absl::Duration"))
+  .bind("OuterExpr"),
   this);
 
   // For the factory functions, we match only the non-templated overloads that
@@ -103,8 +107,9 @@
 has(implicitCastExpr(hasCastKind(CK_UserDefinedConversion,
   hasParent(callExpr(
   callee(functionDecl(DurationFactoryFunction(),
-  unless(hasParent(functionTemplateDecl(),
-  hasArgument(0, expr().bind("arg"),
+  unless(hasParent(functionTemplateDecl(),
+  hasArgument(0, expr().bind("arg")
+  .bind("OuterExpr"),
   this);
 }
 
@@ -117,7 +122,10 @@
   const auto *ArgExpr = Result.Nodes.getNodeAs("arg");
   SourceLocation Loc = ArgExpr->getBeginLoc();
 
-  if (!match(isInTemplateInstantiation(), *ArgExpr, *Result.Context).empty()) {
+  const auto *OuterExpr = Result.Nodes.getNodeAs("OuterExpr");
+
+  if (!match(isInTemplateInstantiation(), *OuterExpr, *Result.Context)
+   .empty()) {
 if (MatchedTemplateLocations.count(Loc.getRawEncoding()) == 0) {
   // For each location matched in a template instantiation, we check if the
   // location can also be found in `MatchedTemplateLocations`. If it is not
Index: 
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
===
--- 
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
+++ 
clang-tools-extra/trunk/test/clang-tidy/abseil-upgrade-duration-conversions.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s 
abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs
+// RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs
 // FIXME: Fix the checker to work in C++17 mode.
 
 using int64_t = long long;


Index: clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
@@ -40,7 +40,8 @@
   callee(functionDecl(
   hasPar

[PATCH] D63261: [clang-tidy] Fixed abseil-time-subtraction to work on C++17

2019-06-13 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 204538.
jvikstrom marked an inline comment as done.
jvikstrom added a comment.

Using anyOf instead of multiple selectFirsts


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63261

Files:
  clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
  clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp


Index: clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp
===
--- clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp
+++ clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-time-subtraction %t -- -- 
-I %S/Inputs
+// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-time-subtraction %t -- 
-- -I %S/Inputs
 // FIXME: Fix the checker to work in C++17 mode.
 
 #include "absl/time/time.h"
Index: clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
===
--- clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
+++ clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
@@ -29,33 +29,52 @@
 
 static bool isConstructorAssignment(const MatchFinder::MatchResult &Result,
 const Expr *Node) {
+  // For C++14 and earlier there are elidable constructors that must be matched
+  // in hasParent. The elidable constructors do not exist in C++17 and later 
and
+  // therefore an additional check that does not match against the elidable
+  // constructors are needed for this case.
   return selectFirst(
- "e", match(expr(hasParent(materializeTemporaryExpr(hasParent(
- cxxConstructExpr(hasParent(exprWithCleanups(
- hasParent(varDecl()
-.bind("e"),
-*Node, *Result.Context)) != nullptr;
+ "e",
+ match(expr(anyOf(
+   callExpr(hasParent(materializeTemporaryExpr(hasParent(
+
cxxConstructExpr(hasParent(exprWithCleanups(
+hasParent(varDecl()
+   .bind("e"),
+   callExpr(hasParent(varDecl())).bind("e"))),
+   *Node, *Result.Context)) != nullptr;
 }
 
 static bool isArgument(const MatchFinder::MatchResult &Result,
const Expr *Node) {
+  // For the same reason as in isConstructorAssignment two separate 
selectFirsts
+  // need to be checked here
   return selectFirst(
  "e",
- match(expr(hasParent(
-
materializeTemporaryExpr(hasParent(cxxConstructExpr(
-hasParent(callExpr()),
-unless(hasParent(cxxOperatorCallExpr(
-   .bind("e"),
-   *Node, *Result.Context)) != nullptr;
+ match(
+ expr(anyOf(
+ expr(hasParent(materializeTemporaryExpr(
+  hasParent(cxxConstructExpr(
+  hasParent(callExpr()),
+  unless(hasParent(cxxOperatorCallExpr(
+ .bind("e"),
+ expr(hasParent(callExpr()),
+  unless(hasParent(cxxOperatorCallExpr(
+ .bind("e"))),
+ *Node, *Result.Context)) != nullptr;
 }
 
 static bool isReturn(const MatchFinder::MatchResult &Result, const Expr *Node) 
{
+  // For the same reason as in isConstructorAssignment two separate 
selectFirsts
+  // need to be checked here
   return selectFirst(
- "e", match(expr(hasParent(materializeTemporaryExpr(hasParent(
- cxxConstructExpr(hasParent(exprWithCleanups(
- hasParent(returnStmt()
-.bind("e"),
-*Node, *Result.Context)) != nullptr;
+ "e",
+ match(expr(anyOf(
+   expr(hasParent(materializeTemporaryExpr(hasParent(
+cxxConstructExpr(hasParent(exprWithCleanups(
+hasParent(returnStmt()
+   .bind("e"),
+   expr(hasParent(returnStmt())).bind("e"))),
+   *Node, *Result.Context)) != nullptr;
 }
 
 static bool parensRequired(const MatchFinder::MatchResult &Result,


Index: clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp
===
--- clang-tools-extra/test/clang-tidy/abseil-time-subtraction.cpp
+++ clang-tools-extra/test/clang-tidy/abseil-time-subtr

[PATCH] D63270: [clangd] Add include-mapping for C symbols.

2019-06-13 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added subscribers: jfb, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

This resolves the issue of introducing c++-style includes for C files.

- refactor the gen_std.py, make it reusable for parsing C symbols.
- add a language mode to the mapping method to use different mapping for C and 
C++ files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63270

Files:
  clang-tools-extra/clangd/CSymbolMap.inc
  clang-tools-extra/clangd/ClangdUnit.cpp
  clang-tools-extra/clangd/StdSymbolMap.inc
  clang-tools-extra/clangd/include-mapping/cppreference_parser.py
  clang-tools-extra/clangd/include-mapping/gen_std.py
  clang-tools-extra/clangd/include-mapping/test.py
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.h
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp

Index: clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
===
--- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -945,7 +945,9 @@
 TEST_F(SymbolCollectorTest, CanonicalSTLHeader) {
   CollectorOpts.CollectIncludePath = true;
   CanonicalIncludes Includes;
-  addSystemHeadersMapping(&Includes);
+  auto Language = LangOptions();
+  Language.CPlusPlus = true;
+  addSystemHeadersMapping(&Includes, Language);
   CollectorOpts.Includes = &Includes;
   runSymbolCollector("namespace std { class string {}; }", /*Main=*/"");
   EXPECT_THAT(Symbols,
Index: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
===
--- clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
+++ clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp
@@ -15,7 +15,9 @@
 
 TEST(CanonicalIncludesTest, CXXStandardLibrary) {
   CanonicalIncludes CI;
-  addSystemHeadersMapping(&CI);
+  auto Language = LangOptions();
+  Language.CPlusPlus = true;
+  addSystemHeadersMapping(&CI, Language);
 
   // Usual standard library symbols are mapped correctly.
   EXPECT_EQ("", CI.mapHeader("path/vector.h", "std::vector"));
Index: clang-tools-extra/clangd/index/IndexAction.cpp
===
--- clang-tools-extra/clangd/index/IndexAction.cpp
+++ clang-tools-extra/clangd/index/IndexAction.cpp
@@ -126,6 +126,7 @@
   std::unique_ptr
   CreateASTConsumer(CompilerInstance &CI, llvm::StringRef InFile) override {
 CI.getPreprocessor().addCommentHandler(PragmaHandler.get());
+addSystemHeadersMapping(Includes.get(), CI.getLangOpts());
 if (IncludeGraphCallback != nullptr)
   CI.getPreprocessor().addPPCallbacks(
   llvm::make_unique(CI.getSourceManager(), IG));
@@ -194,7 +195,6 @@
 Opts.RefsInHeaders = true;
   }
   auto Includes = llvm::make_unique();
-  addSystemHeadersMapping(Includes.get());
   Opts.Includes = Includes.get();
   return llvm::make_unique(
   std::make_shared(std::move(Opts)), std::move(Includes),
Index: clang-tools-extra/clangd/index/CanonicalIncludes.h
===
--- clang-tools-extra/clangd/index/CanonicalIncludes.h
+++ clang-tools-extra/clangd/index/CanonicalIncludes.h
@@ -84,7 +84,8 @@
 ///   - Compiler extensions, e.g. include/avx512bwintrin.h$ -> 
 /// The mapping is hardcoded and hand-maintained, so it might not cover all
 /// headers.
-void addSystemHeadersMapping(CanonicalIncludes *Includes);
+void addSystemHeadersMapping(CanonicalIncludes *Includes,
+ const LangOptions &Language);
 
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/index/CanonicalIncludes.cpp
===
--- clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -86,16 +86,25 @@
   return llvm::make_unique(Includes);
 }
 
-void addSystemHeadersMapping(CanonicalIncludes *Includes) {
+void addSystemHeadersMapping(CanonicalIncludes *Includes,
+ const LangOptions &Language) {
   static const std::vector> SymbolMap = {
 #define SYMBOL(Name, NameSpace, Header) { #NameSpace#Name, #Header },
   #include "StdSymbolMap.inc"
 #undef SYMBOL
   };
-
-  for (const auto &Pair : SymbolMap)
-Includes->addSymbolMapping(Pair.first, Pair.second);
-
+  static const std::vector> CSymbolMap = {
+#define SYMBOL(Name, NameSpace, Header) {#NameSpace #Name, #Header},
+  #include "CSymbolMap.inc"
+#undef SYMBOL
+  };
+  if (Language.CPlusPlus) {
+for (const auto &Pair : SymbolMap)
+  Includes->addSymbolMapping(Pair.first, Pair.second);
+  } else if (Language.C11) {
+  

[clang-tools-extra] r363272 - [clang-tidy] Fixed abseil-time-subtraction to work on C++17

2019-06-13 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Jun 13 08:11:02 2019
New Revision: 363272

URL: http://llvm.org/viewvc/llvm-project?rev=363272&view=rev
Log:
[clang-tidy] Fixed abseil-time-subtraction to work on C++17

Summary: Fixed abseil-time-subtraction to work on C++17

Reviewers: hokein, gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Patch by Johan Vikström.

Modified:
clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/abseil-time-subtraction.cpp

Modified: clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp?rev=363272&r1=363271&r2=363272&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp Thu Jun 
13 08:11:02 2019
@@ -29,33 +29,52 @@ static bool InsideMacroDefinition(const
 
 static bool isConstructorAssignment(const MatchFinder::MatchResult &Result,
 const Expr *Node) {
+  // For C++14 and earlier there are elidable constructors that must be matched
+  // in hasParent. The elidable constructors do not exist in C++17 and later 
and
+  // therefore an additional check that does not match against the elidable
+  // constructors are needed for this case.
   return selectFirst(
- "e", match(expr(hasParent(materializeTemporaryExpr(hasParent(
- cxxConstructExpr(hasParent(exprWithCleanups(
- hasParent(varDecl()
-.bind("e"),
-*Node, *Result.Context)) != nullptr;
+ "e",
+ match(expr(anyOf(
+   callExpr(hasParent(materializeTemporaryExpr(hasParent(
+
cxxConstructExpr(hasParent(exprWithCleanups(
+hasParent(varDecl()
+   .bind("e"),
+   callExpr(hasParent(varDecl())).bind("e"))),
+   *Node, *Result.Context)) != nullptr;
 }
 
 static bool isArgument(const MatchFinder::MatchResult &Result,
const Expr *Node) {
+  // For the same reason as in isConstructorAssignment two AST shapes need to 
be
+  // matched here.
   return selectFirst(
  "e",
- match(expr(hasParent(
-
materializeTemporaryExpr(hasParent(cxxConstructExpr(
-hasParent(callExpr()),
-unless(hasParent(cxxOperatorCallExpr(
-   .bind("e"),
-   *Node, *Result.Context)) != nullptr;
+ match(
+ expr(anyOf(
+ expr(hasParent(materializeTemporaryExpr(
+  hasParent(cxxConstructExpr(
+  hasParent(callExpr()),
+  unless(hasParent(cxxOperatorCallExpr(
+ .bind("e"),
+ expr(hasParent(callExpr()),
+  unless(hasParent(cxxOperatorCallExpr(
+ .bind("e"))),
+ *Node, *Result.Context)) != nullptr;
 }
 
 static bool isReturn(const MatchFinder::MatchResult &Result, const Expr *Node) 
{
+  // For the same reason as in isConstructorAssignment two AST shapes need to 
be
+  // matched here.
   return selectFirst(
- "e", match(expr(hasParent(materializeTemporaryExpr(hasParent(
- cxxConstructExpr(hasParent(exprWithCleanups(
- hasParent(returnStmt()
-.bind("e"),
-*Node, *Result.Context)) != nullptr;
+ "e",
+ match(expr(anyOf(
+   expr(hasParent(materializeTemporaryExpr(hasParent(
+cxxConstructExpr(hasParent(exprWithCleanups(
+hasParent(returnStmt()
+   .bind("e"),
+   expr(hasParent(returnStmt())).bind("e"))),
+   *Node, *Result.Context)) != nullptr;
 }
 
 static bool parensRequired(const MatchFinder::MatchResult &Result,

Modified: clang-tools-extra/trunk/test/clang-tidy/abseil-time-subtraction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-time-subtraction.cpp?rev=363272&r1=363271&r2=363272&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/abseil-time-subtraction.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-ti

[PATCH] D63261: [clang-tidy] Fixed abseil-time-subtraction to work on C++17

2019-06-13 Thread Dmitri Gribenko 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 rL363272: [clang-tidy] Fixed abseil-time-subtraction to work 
on C++17 (authored by gribozavr, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63261?vs=204538&id=204544#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63261

Files:
  clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/abseil-time-subtraction.cpp


Index: clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/abseil/TimeSubtractionCheck.cpp
@@ -29,33 +29,52 @@
 
 static bool isConstructorAssignment(const MatchFinder::MatchResult &Result,
 const Expr *Node) {
+  // For C++14 and earlier there are elidable constructors that must be matched
+  // in hasParent. The elidable constructors do not exist in C++17 and later 
and
+  // therefore an additional check that does not match against the elidable
+  // constructors are needed for this case.
   return selectFirst(
- "e", match(expr(hasParent(materializeTemporaryExpr(hasParent(
- cxxConstructExpr(hasParent(exprWithCleanups(
- hasParent(varDecl()
-.bind("e"),
-*Node, *Result.Context)) != nullptr;
+ "e",
+ match(expr(anyOf(
+   callExpr(hasParent(materializeTemporaryExpr(hasParent(
+
cxxConstructExpr(hasParent(exprWithCleanups(
+hasParent(varDecl()
+   .bind("e"),
+   callExpr(hasParent(varDecl())).bind("e"))),
+   *Node, *Result.Context)) != nullptr;
 }
 
 static bool isArgument(const MatchFinder::MatchResult &Result,
const Expr *Node) {
+  // For the same reason as in isConstructorAssignment two AST shapes need to 
be
+  // matched here.
   return selectFirst(
  "e",
- match(expr(hasParent(
-
materializeTemporaryExpr(hasParent(cxxConstructExpr(
-hasParent(callExpr()),
-unless(hasParent(cxxOperatorCallExpr(
-   .bind("e"),
-   *Node, *Result.Context)) != nullptr;
+ match(
+ expr(anyOf(
+ expr(hasParent(materializeTemporaryExpr(
+  hasParent(cxxConstructExpr(
+  hasParent(callExpr()),
+  unless(hasParent(cxxOperatorCallExpr(
+ .bind("e"),
+ expr(hasParent(callExpr()),
+  unless(hasParent(cxxOperatorCallExpr(
+ .bind("e"))),
+ *Node, *Result.Context)) != nullptr;
 }
 
 static bool isReturn(const MatchFinder::MatchResult &Result, const Expr *Node) 
{
+  // For the same reason as in isConstructorAssignment two AST shapes need to 
be
+  // matched here.
   return selectFirst(
- "e", match(expr(hasParent(materializeTemporaryExpr(hasParent(
- cxxConstructExpr(hasParent(exprWithCleanups(
- hasParent(returnStmt()
-.bind("e"),
-*Node, *Result.Context)) != nullptr;
+ "e",
+ match(expr(anyOf(
+   expr(hasParent(materializeTemporaryExpr(hasParent(
+cxxConstructExpr(hasParent(exprWithCleanups(
+hasParent(returnStmt()
+   .bind("e"),
+   expr(hasParent(returnStmt())).bind("e"))),
+   *Node, *Result.Context)) != nullptr;
 }
 
 static bool parensRequired(const MatchFinder::MatchResult &Result,
Index: clang-tools-extra/trunk/test/clang-tidy/abseil-time-subtraction.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/abseil-time-subtraction.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-time-subtraction.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-time-subtraction %t -- -- 
-I %S/Inputs
+// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-time-subtraction %t -- 
-- -I %S/Inputs
 // FIXME: Fix the checker to work in C++17 mode.
 
 #i

[clang-tools-extra] r363273 - [clang-tidy] Made abseil-faster-strsplit-delimiter tests pass on C++17

2019-06-13 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Jun 13 08:16:44 2019
New Revision: 363273

URL: http://llvm.org/viewvc/llvm-project?rev=363273&view=rev
Log:
[clang-tidy] Made abseil-faster-strsplit-delimiter tests pass on C++17

Reviewers: hokein, gribozavr

Reviewed By: hokein, gribozavr

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

Patch by Johan Vikström.

Modified:
clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp?rev=363273&r1=363272&r2=363273&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp 
Thu Jun 13 08:16:44 2019
@@ -20,21 +20,6 @@ namespace {
 
 AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
 
-::internal::Matcher
-constructExprWithArg(llvm::StringRef ClassName,
- const ::internal::Matcher &Arg) {
-  auto ConstrExpr = cxxConstructExpr(hasType(recordDecl(hasName(ClassName))),
- hasArgument(0, ignoringParenCasts(Arg)));
-
-  return anyOf(ConstrExpr, cxxBindTemporaryExpr(has(ConstrExpr)));
-}
-
-::internal::Matcher
-copyConstructExprWithArg(llvm::StringRef ClassName,
- const ::internal::Matcher &Arg) {
-  return constructExprWithArg(ClassName, constructExprWithArg(ClassName, Arg));
-}
-
 llvm::Optional makeCharacterLiteral(const StringLiteral *Literal) 
{
   std::string Result;
   {
@@ -74,11 +59,17 @@ void FasterStrsplitDelimiterCheck::regis
 
   // Binds to a string_view (either absl or std) that was passed by value and
   // contructed from string literal.
-  auto StringViewArg =
-  copyConstructExprWithArg("::absl::string_view", SingleChar);
+  auto StringViewArg = ignoringElidableConstructorCall(ignoringImpCasts(
+  cxxConstructExpr(hasType(recordDecl(hasName("::absl::string_view"))),
+   hasArgument(0, ignoringParenImpCasts(SingleChar);
 
+  // Need to ignore the elidable constructor as otherwise there is no match for
+  // c++14 and earlier.
   auto ByAnyCharArg =
-  expr(copyConstructExprWithArg("::absl::ByAnyChar", StringViewArg))
+  expr(has(ignoringElidableConstructorCall(
+   ignoringParenCasts(cxxBindTemporaryExpr(has(cxxConstructExpr(
+   hasType(recordDecl(hasName("::absl::ByAnyChar"))),
+   hasArgument(0, StringViewArg
   .bind("ByAnyChar");
 
   // Find uses of absl::StrSplit(..., "x") and absl::StrSplit(...,

Modified: 
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp?rev=363273&r1=363272&r2=363273&view=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp 
Thu Jun 13 08:16:44 2019
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-faster-strsplit-delimiter 
%t
+// RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-faster-strsplit-delimiter %t
 // FIXME: Fix the checker to work in C++17 mode.
 
 namespace absl {


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


[PATCH] D63253: [clang-tidy] Made abseil-faster-strsplit-delimiter tests pass on C++17

2019-06-13 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363273: [clang-tidy] Made abseil-faster-strsplit-delimiter 
tests pass on C++17 (authored by gribozavr, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63253?vs=204495&id=204549#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63253

Files:
  clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp


Index: 
clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
@@ -20,21 +20,6 @@
 
 AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
 
-::internal::Matcher
-constructExprWithArg(llvm::StringRef ClassName,
- const ::internal::Matcher &Arg) {
-  auto ConstrExpr = cxxConstructExpr(hasType(recordDecl(hasName(ClassName))),
- hasArgument(0, ignoringParenCasts(Arg)));
-
-  return anyOf(ConstrExpr, cxxBindTemporaryExpr(has(ConstrExpr)));
-}
-
-::internal::Matcher
-copyConstructExprWithArg(llvm::StringRef ClassName,
- const ::internal::Matcher &Arg) {
-  return constructExprWithArg(ClassName, constructExprWithArg(ClassName, Arg));
-}
-
 llvm::Optional makeCharacterLiteral(const StringLiteral *Literal) 
{
   std::string Result;
   {
@@ -74,11 +59,17 @@
 
   // Binds to a string_view (either absl or std) that was passed by value and
   // contructed from string literal.
-  auto StringViewArg =
-  copyConstructExprWithArg("::absl::string_view", SingleChar);
+  auto StringViewArg = ignoringElidableConstructorCall(ignoringImpCasts(
+  cxxConstructExpr(hasType(recordDecl(hasName("::absl::string_view"))),
+   hasArgument(0, ignoringParenImpCasts(SingleChar);
 
+  // Need to ignore the elidable constructor as otherwise there is no match for
+  // c++14 and earlier.
   auto ByAnyCharArg =
-  expr(copyConstructExprWithArg("::absl::ByAnyChar", StringViewArg))
+  expr(has(ignoringElidableConstructorCall(
+   ignoringParenCasts(cxxBindTemporaryExpr(has(cxxConstructExpr(
+   hasType(recordDecl(hasName("::absl::ByAnyChar"))),
+   hasArgument(0, StringViewArg
   .bind("ByAnyChar");
 
   // Find uses of absl::StrSplit(..., "x") and absl::StrSplit(...,
Index: 
clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy -std=c++11,c++14 %s abseil-faster-strsplit-delimiter 
%t
+// RUN: %check_clang_tidy -std=c++11-or-later %s 
abseil-faster-strsplit-delimiter %t
 // FIXME: Fix the checker to work in C++17 mode.
 
 namespace absl {


Index: clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
@@ -20,21 +20,6 @@
 
 AST_MATCHER(StringLiteral, lengthIsOne) { return Node.getLength() == 1; }
 
-::internal::Matcher
-constructExprWithArg(llvm::StringRef ClassName,
- const ::internal::Matcher &Arg) {
-  auto ConstrExpr = cxxConstructExpr(hasType(recordDecl(hasName(ClassName))),
- hasArgument(0, ignoringParenCasts(Arg)));
-
-  return anyOf(ConstrExpr, cxxBindTemporaryExpr(has(ConstrExpr)));
-}
-
-::internal::Matcher
-copyConstructExprWithArg(llvm::StringRef ClassName,
- const ::internal::Matcher &Arg) {
-  return constructExprWithArg(ClassName, constructExprWithArg(ClassName, Arg));
-}
-
 llvm::Optional makeCharacterLiteral(const StringLiteral *Literal) {
   std::string Result;
   {
@@ -74,11 +59,17 @@
 
   // Binds to a string_view (either absl or std) that was passed by value and
   // contructed from string literal.
-  auto StringViewArg =
-  copyConstructExprWithArg("::absl::string_view", SingleChar);
+  auto StringViewArg = ignoringElidableConstructorCall(ignoringImpCasts(
+  cxxConstructExpr(hasType(recordDecl(hasName("::absl::string_view"))),
+   hasArgument(0, ignoringParenImpCasts(SingleChar);
 
+  // Need to ignore the elidable constructor as otherwise there is no match for
+  // c++14 and earlier.
   auto ByAn

[PATCH] D63276: [AST] Add FunctionDecl::getParametersSourceRange()

2019-06-13 Thread Nicolas Manichon via Phabricator via cfe-commits
nicolas created this revision.
nicolas added reviewers: rsmith, steveire.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This source range covers the list of parameters of the function declaration.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63276

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp
  clang/unittests/AST/SourceLocationTest.cpp


Index: clang/unittests/AST/SourceLocationTest.cpp
===
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -648,6 +648,32 @@
   Language::Lang_CXX11));
 }
 
+class FunctionDeclParametersRangeVerifier : public RangeVerifier 
{
+protected:
+  SourceRange getRange(const FunctionDecl &Function) override {
+return Function.getParametersSourceRange();
+  }
+};
+
+TEST(FunctionDeclParameters, FunctionDeclSingleParameter) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 12);
+  EXPECT_TRUE(Verifier.match("void f(int a);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclMultipleParameters) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 28);
+  EXPECT_TRUE(
+  Verifier.match("void f(int a, int b, char *c);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclWithDefaultValue) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 16);
+  EXPECT_TRUE(Verifier.match("void f(int a = 5);\n", functionDecl()));
+}
+
 TEST(CXXMethodDecl, CXXMethodDeclWithThrowSpecification) {
   RangeVerifier Verifier;
   Verifier.expectRange(2, 1, 2, 16);
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -3301,6 +3301,17 @@
   return RTRange;
 }
 
+SourceRange FunctionDecl::getParametersSourceRange() const {
+  auto NP = getNumParams();
+  if (NP == 0)
+return SourceRange();
+
+  auto Begin = ParamInfo[0]->getSourceRange().getBegin();
+  auto End = ParamInfo[NP - 1]->getSourceRange().getEnd();
+
+  return SourceRange(Begin, End);
+}
+
 SourceRange FunctionDecl::getExceptionSpecSourceRange() const {
   const TypeSourceInfo *TSI = getTypeSourceInfo();
   if (!TSI)
Index: clang/include/clang/AST/Decl.h
===
--- clang/include/clang/AST/Decl.h
+++ clang/include/clang/AST/Decl.h
@@ -2327,6 +2327,10 @@
   /// limited representation in the AST.
   SourceRange getReturnTypeSourceRange() const;
 
+  /// Attempt to compute an informative source range covering the
+  /// function parameters. This omits the ellipsis of a variadic function.
+  SourceRange getParametersSourceRange() const;
+
   /// Get the declared return type, which may differ from the actual return
   /// type if the return type is deduced.
   QualType getDeclaredReturnType() const {


Index: clang/unittests/AST/SourceLocationTest.cpp
===
--- clang/unittests/AST/SourceLocationTest.cpp
+++ clang/unittests/AST/SourceLocationTest.cpp
@@ -648,6 +648,32 @@
   Language::Lang_CXX11));
 }
 
+class FunctionDeclParametersRangeVerifier : public RangeVerifier {
+protected:
+  SourceRange getRange(const FunctionDecl &Function) override {
+return Function.getParametersSourceRange();
+  }
+};
+
+TEST(FunctionDeclParameters, FunctionDeclSingleParameter) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 12);
+  EXPECT_TRUE(Verifier.match("void f(int a);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclMultipleParameters) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 28);
+  EXPECT_TRUE(
+  Verifier.match("void f(int a, int b, char *c);\n", functionDecl()));
+}
+
+TEST(FunctionDeclParameters, FunctionDeclWithDefaultValue) {
+  FunctionDeclParametersRangeVerifier Verifier;
+  Verifier.expectRange(1, 8, 1, 16);
+  EXPECT_TRUE(Verifier.match("void f(int a = 5);\n", functionDecl()));
+}
+
 TEST(CXXMethodDecl, CXXMethodDeclWithThrowSpecification) {
   RangeVerifier Verifier;
   Verifier.expectRange(2, 1, 2, 16);
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -3301,6 +3301,17 @@
   return RTRange;
 }
 
+SourceRange FunctionDecl::getParametersSourceRange() const {
+  auto NP = getNumParams();
+  if (NP == 0)
+return SourceRange();
+
+  auto Begin = ParamInfo[0]->getSourceRange().getBegin();
+  auto End = ParamInfo[NP - 1]->getSourceRange().getEnd();
+
+  return SourceRange(Begin, End);
+}
+
 SourceRange FunctionDecl::getExceptionSpecSourceRange() const {
   const TypeSourceInfo *TSI = getTypeSourceInfo();
   if (!TSI)
Index: clang/include/clang/AST/Decl.h
===

[PATCH] D63277: Don't set "comdat" attribute for CUDA device stub functions.

2019-06-13 Thread Konstantin Pyzhov via Phabricator via cfe-commits
kpyzhov created this revision.
kpyzhov added a reviewer: rjmccall.
kpyzhov added projects: clang, AMDGPU.
Herald added a subscriber: cfe-commits.

When compiling the HOST part of CUDA programs, clang replaces device kernels 
with so-called "stub" functions that contains a few calls to the Runtime API 
functions (which set the kernel argument values and launch the kernel itself). 
The stub functions are very small, so they may have identical generated code 
for different kernels with same arguments.
The Microsoft Linker has an optimization called "COMDAT Folding". It's able to 
detect functions with identical binary code and "merge" them, i.e. replace 
calls and pointers to those different functions with call/pointer to one of 
them and eliminate other copies.

Here is the description of this optimization: 
https://docs.microsoft.com/en-us/cpp/build/reference/opt-optimizations?view=vs-2019
This page contains a warning about "COMDAT Folding":
//"Because /OPT:ICF can cause the same address to be assigned to different 
functions or read-only data members (that is, const variables when compiled by 
using /Gy), it can break a program that depends on unique addresses for 
functions or read-only data members."//
That's exactly what happens to the CUDA stub functions.

This change disables setting "COMDAT" attribute for CUDA stub functions in the 
HOST code.


Repository:
  rC Clang

https://reviews.llvm.org/D63277

Files:
  clang/lib/CodeGen/CodeGenModule.cpp


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4291,14 +4291,15 @@

   MaybeHandleStaticInExternC(D, Fn);

-
-  maybeSetTrivialComdat(*D, *Fn);
+  if (!D->hasAttr()) {
+  maybeSetTrivialComdat(*D, *Fn);
+  }

   CodeGenFunction(*this).GenerateCode(D, Fn, FI);

   setNonAliasAttributes(GD, Fn);
   SetLLVMFunctionAttributesForDefinition(D, Fn);

   if (const ConstructorAttr *CA = D->getAttr())
 AddGlobalCtor(Fn, CA->getPriority());
   if (const DestructorAttr *DA = D->getAttr())


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4291,14 +4291,15 @@

   MaybeHandleStaticInExternC(D, Fn);

-
-  maybeSetTrivialComdat(*D, *Fn);
+  if (!D->hasAttr()) {
+  maybeSetTrivialComdat(*D, *Fn);
+  }

   CodeGenFunction(*this).GenerateCode(D, Fn, FI);

   setNonAliasAttributes(GD, Fn);
   SetLLVMFunctionAttributesForDefinition(D, Fn);

   if (const ConstructorAttr *CA = D->getAttr())
 AddGlobalCtor(Fn, CA->getPriority());
   if (const DestructorAttr *DA = D->getAttr())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D62883: [analyzer] Track conditions of terminator statements on which the reported node depends on

2019-06-13 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus updated this revision to Diff 204554.
Szelethus added a comment.

- Resolved some reviewer comments
- Added a `BugReport` level set to avoid tracking the same condition (which 
would result in an almost infinite loop)

Aaaand I have some results to show: http://cc.elte.hu:15001/Default/#

Sort by "Storage date", and look for "LLVM/Clang/Clang-tools-extra BEFORE 
tracking conditions" and "LLVM/Clang/Clang-tools-extra AFTER tracking 
conditions". I didn't have much time to draw conclusions yet, but it's clear 
that the amount of extra notes are intolerable.


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

https://reviews.llvm.org/D62883

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/Inputs/expected-plists/cxx-for-range.cpp.plist
  clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist
  clang/test/Analysis/Inputs/expected-plists/retain-release.m.objc.plist
  clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
  clang/test/Analysis/Inputs/expected-plists/unix-fns.c.plist
  
clang/test/Analysis/diagnostics/Inputs/expected-plists/undef-value-param.m.plist
  clang/test/Analysis/diagnostics/no-store-func-path-notes.m
  clang/test/Analysis/diagnostics/undef-value-param.m
  clang/test/Analysis/track-control-dependency-conditions.cpp

Index: clang/test/Analysis/track-control-dependency-conditions.cpp
===
--- /dev/null
+++ clang/test/Analysis/track-control-dependency-conditions.cpp
@@ -0,0 +1,87 @@
+// RUN: %clang_analyze_cc1 %s -verify \
+// RUN:   -analyzer-output=text \
+// RUN:   -analyzer-checker=core
+
+namespace example_1 {
+int flag;
+bool coin();
+
+void foo() {
+  flag = coin(); // expected-note {{Value assigned to 'flag'}}
+}
+
+void test() {
+  int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
+  flag = 1;
+
+  foo(); // TODO: Add nodes here about flag's value being invalidated.
+  if (flag) // expected-note   {{Taking false branch}}
+// expected-note@-1{{Assuming 'flag' is 0}}
+x = new int;
+
+  foo(); // expected-note   {{Calling 'foo'}}
+ // expected-note@-1{{Returning from 'foo'}}
+
+  if (flag) // expected-note   {{Taking true branch}}
+// expected-note@-1{{Assuming 'flag' is not equal to 0}}
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace example_1
+
+namespace example_2 {
+int flag;
+bool coin();
+
+void foo() {
+  flag = coin(); // expected-note {{Value assigned to 'flag'}}
+}
+
+void test() {
+  int *x = 0;
+  flag = 1;
+
+  foo(); // TODO: Add nodes here about flag's value being invalidated.
+  if (flag) // expected-note   {{Taking false branch}}
+// expected-note@-1{{Assuming 'flag' is 0}}
+x = new int;
+
+  x = 0; // expected-note{{Null pointer value stored to 'x'}}
+
+  foo(); // expected-note   {{Calling 'foo'}}
+ // expected-note@-1{{Returning from 'foo'}}
+
+  if (flag) // expected-note   {{Taking true branch}}
+// expected-note@-1{{Assuming 'flag' is not equal to 0}}
+*x = 5; // expected-warning{{Dereference of null pointer}}
+// expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace example_2
+
+namespace example_3 {
+int flag;
+bool coin();
+
+void foo() {
+  // TODO: It makes no sense at all for bar to have been assigned here.
+  flag = coin(); // expected-note {{Value assigned to 'flag'}}
+ // expected-note@-1 {{Value assigned to 'bar'}}
+}
+
+int bar;
+
+void test() {
+  int *x = 0; // expected-note{{'x' initialized to a null pointer value}}
+  flag = 1;
+
+  foo(); // expected-note   {{Calling 'foo'}}
+ // expected-note@-1{{Returning from 'foo'}}
+
+  if (bar) // expected-note   {{Taking true branch}}
+   // expected-note@-1{{Assuming 'bar' is not equal to 0}}
+if (flag) // expected-note   {{Taking true branch}}
+  // expected-note@-1{{Assuming 'flag' is not equal to 0}}
+  *x = 5; // expected-warning{{Dereference of null pointer}}
+  // expected-note@-1{{Dereference of null pointer}}
+}
+} // end of namespace example_3
Index: clang/test/Analysis/diagnostics/undef-value-param.m
===
--- clang/test/Analysis/diagnostics/undef-value-param.m
+++ clang/test/Analysis/diagnostics/undef-value-param.m
@@ -52,7 +52,7 @@
 
 static void CreateRef(SCDynamicStoreRef *storeRef, unsigned x) {
 unsigned err = 0;
-SCDynamicStoreRef ref = anotherCreateRef(&err, x);
+SCDynamicStoreRef ref = anotherCreateRef(&err, x); // expected-note{{Value assigned to 'err'}}
 if (err) { 
//expected-note@-1{{Assuming 'err' is not equ

[PATCH] D62883: [analyzer] Track conditions of terminator statements on which the reported node depends on

2019-06-13 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked 6 inline comments as done.
Szelethus added inline comments.



Comment at: clang/test/Analysis/track-control-dependency-conditions.cpp:34
+
+  foo(); // TODO: Add nodes here about flag's value being invalidated.
+  if (flag) // expected-note   {{Taking false branch}}

NoQ wrote:
> Why?
I'll remove it in the next diff *pinky swear*.


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

https://reviews.llvm.org/D62883



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


[PATCH] D63279: [Analyzer] Unroll for-loops where the upper boundary is a variable with know value

2019-06-13 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added reviewers: NoQ, szepet, Szelethus.
baloghadamsoftware added a project: clang.
Herald added subscribers: Charusso, gamesh411, donat.nagy, mikhail.ramalho, 
dmgreen, a.sidorin, zzheng, rnkovacs, xazax.hun, whisperity.

For-loops with a variable upper boundary do not differ very much from for-loops 
with integer literals if the value of the variable is known. Unroll these loops 
as well, similarly to them. This was a TODO anyway.


Repository:
  rC Clang

https://reviews.llvm.org/D63279

Files:
  lib/StaticAnalyzer/Core/LoopUnrolling.cpp
  test/Analysis/loop-unrolling.cpp


Index: test/Analysis/loop-unrolling.cpp
===
--- test/Analysis/loop-unrolling.cpp
+++ test/Analysis/loop-unrolling.cpp
@@ -499,3 +499,15 @@
 clang_analyzer_numTimesReached(); // expected-warning {{6}}
   }
 }
+
+int unroll_known_value_of_variable() {
+  int a[9];
+  int k = 42;
+  int n = 9;
+  for (int i = 0; i < n; i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{9}}
+a[i] = 42;
+  }
+  int b = 22 / (k - 42); // expected-warning {{Division by zero}}
+  return 0;
+}
Index: lib/StaticAnalyzer/Core/LoopUnrolling.cpp
===
--- lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -84,9 +84,8 @@
   hasOperatorName("<="), hasOperatorName(">="),
   hasOperatorName("!=")),
 hasEitherOperand(ignoringParenImpCasts(declRefExpr(
-
to(varDecl(hasType(isInteger())).bind(BindName),
-hasEitherOperand(ignoringParenImpCasts(
-integerLiteral().bind("boundNum"
+to(varDecl(hasType(isInteger())).bind(BindName)))
+.bind("boundVarOperand"
   .bind("conditionOperator");
 }
 
@@ -200,18 +199,40 @@
   if (!isLoopStmt(LoopStmt))
 return false;
 
-  // TODO: Match the cases where the bound is not a concrete literal but an
-  // integer with known value
   auto Matches = match(forLoopMatcher(), *LoopStmt, ASTCtx);
   if (Matches.empty())
 return false;
 
+  const auto State = Pred->getState();
+  auto &SVB = State->getStateManager().getSValBuilder();
+
   auto CounterVar = Matches[0].getNodeAs("initVarName");
-  llvm::APInt BoundNum =
-  Matches[0].getNodeAs("boundNum")->getValue();
   llvm::APInt InitNum =
   Matches[0].getNodeAs("initNum")->getValue();
   auto CondOp = Matches[0].getNodeAs("conditionOperator");
+
+  const Expr *BoundExpr = CondOp->getLHS()->IgnoreParenImpCasts();
+  if (BoundExpr == Matches[0].getNodeAs("boundVarOperand"))
+BoundExpr = CondOp->getRHS()->IgnoreParenImpCasts();
+  SVal BoundNumVal = Pred->getSVal(BoundExpr);
+
+  // If the value of the expression is unknown and it is a declaration
+  // reference then try to get the value of the declaration instead
+  if (BoundNumVal.isUnknown()) {
+if (const auto *BoundDeclRefExpr = dyn_cast(BoundExpr)) {
+  // FIXME: Add other declarations such as Objective-C fields
+  if (const auto *BoundVarDecl =
+  dyn_cast(BoundDeclRefExpr->getDecl())) {
+BoundNumVal = State->getSVal(
+State->getLValue(BoundVarDecl, Pred->getLocationContext()));
+  }
+}
+  }
+  const llvm::APSInt *BoundNumPtr = SVB.getKnownValue(State, BoundNumVal);
+  if (!BoundNumPtr)
+return false;
+  llvm::APInt BoundNum = *BoundNumPtr;
+
   if (InitNum.getBitWidth() != BoundNum.getBitWidth()) {
 InitNum = InitNum.zextOrSelf(BoundNum.getBitWidth());
 BoundNum = BoundNum.zextOrSelf(InitNum.getBitWidth());


Index: test/Analysis/loop-unrolling.cpp
===
--- test/Analysis/loop-unrolling.cpp
+++ test/Analysis/loop-unrolling.cpp
@@ -499,3 +499,15 @@
 clang_analyzer_numTimesReached(); // expected-warning {{6}}
   }
 }
+
+int unroll_known_value_of_variable() {
+  int a[9];
+  int k = 42;
+  int n = 9;
+  for (int i = 0; i < n; i++) {
+clang_analyzer_numTimesReached(); // expected-warning {{9}}
+a[i] = 42;
+  }
+  int b = 22 / (k - 42); // expected-warning {{Division by zero}}
+  return 0;
+}
Index: lib/StaticAnalyzer/Core/LoopUnrolling.cpp
===
--- lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -84,9 +84,8 @@
   hasOperatorName("<="), hasOperatorName(">="),
   hasOperatorName("!=")),
 hasEitherOperand(ignoringParenImpCasts(declRefExpr(
-to(varDecl(hasType(isInteger())).bind(BindName),
-hasEitherOperand(ignoringParenImpCasts(
-integerLiteral().

[PATCH] D63153: [clang][NewPM] Fix broken -O0 test from the AlwaysInliner

2019-06-13 Thread Leonard Chan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363277: [clang][NewPM] Fix broken -O0 test from the 
AlwaysInliner (authored by leonardchan, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63153?vs=204107&id=204564#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63153

Files:
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  cfe/trunk/test/CodeGen/lifetime.c


Index: cfe/trunk/test/CodeGen/lifetime.c
===
--- cfe/trunk/test/CodeGen/lifetime.c
+++ cfe/trunk/test/CodeGen/lifetime.c
@@ -1,7 +1,8 @@
-// RUN: %clang -S -emit-llvm -o - -O0 %s | FileCheck %s -check-prefix=O0
+// RUN: %clang -S -emit-llvm -o - -O0 -fno-experimental-new-pass-manager %s | 
FileCheck %s -check-prefix=O0
 // RUN: %clang -S -emit-llvm -o - -O1 -fno-experimental-new-pass-manager %s | 
FileCheck %s -check-prefix=O1
 // RUN: %clang -S -emit-llvm -o - -O2 -fno-experimental-new-pass-manager %s | 
FileCheck %s -check-prefix=O2
 // RUN: %clang -S -emit-llvm -o - -O3 -fno-experimental-new-pass-manager %s | 
FileCheck %s -check-prefix=O3
+// RUN: %clang -S -emit-llvm -o - -O0 -fexperimental-new-pass-manager %s | 
FileCheck %s -check-prefix=O0
 
 extern void use(char *a);
 
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -,8 +,10 @@
 MPM.addPass(InstrProfiling(*Options, false));
 
   // Build a minimal pipeline based on the semantics required by Clang,
-  // which is just that always inlining occurs.
-  MPM.addPass(AlwaysInlinerPass());
+  // which is just that always inlining occurs. Further, disable generating
+  // lifetime intrinsics to avoid enabling further optimizations during
+  // code generation.
+  MPM.addPass(AlwaysInlinerPass(/*InsertLifetimeIntrinsics=*/false));
 
   // At -O0 we directly run necessary sanitizer passes.
   if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))


Index: cfe/trunk/test/CodeGen/lifetime.c
===
--- cfe/trunk/test/CodeGen/lifetime.c
+++ cfe/trunk/test/CodeGen/lifetime.c
@@ -1,7 +1,8 @@
-// RUN: %clang -S -emit-llvm -o - -O0 %s | FileCheck %s -check-prefix=O0
+// RUN: %clang -S -emit-llvm -o - -O0 -fno-experimental-new-pass-manager %s | FileCheck %s -check-prefix=O0
 // RUN: %clang -S -emit-llvm -o - -O1 -fno-experimental-new-pass-manager %s | FileCheck %s -check-prefix=O1
 // RUN: %clang -S -emit-llvm -o - -O2 -fno-experimental-new-pass-manager %s | FileCheck %s -check-prefix=O2
 // RUN: %clang -S -emit-llvm -o - -O3 -fno-experimental-new-pass-manager %s | FileCheck %s -check-prefix=O3
+// RUN: %clang -S -emit-llvm -o - -O0 -fexperimental-new-pass-manager %s | FileCheck %s -check-prefix=O0
 
 extern void use(char *a);
 
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -,8 +,10 @@
 MPM.addPass(InstrProfiling(*Options, false));
 
   // Build a minimal pipeline based on the semantics required by Clang,
-  // which is just that always inlining occurs.
-  MPM.addPass(AlwaysInlinerPass());
+  // which is just that always inlining occurs. Further, disable generating
+  // lifetime intrinsics to avoid enabling further optimizations during
+  // code generation.
+  MPM.addPass(AlwaysInlinerPass(/*InsertLifetimeIntrinsics=*/false));
 
   // At -O0 we directly run necessary sanitizer passes.
   if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r363277 - [clang][NewPM] Fix broken -O0 test from the AlwaysInliner

2019-06-13 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Thu Jun 13 09:45:29 2019
New Revision: 363277

URL: http://llvm.org/viewvc/llvm-project?rev=363277&view=rev
Log:
[clang][NewPM] Fix broken -O0 test from the AlwaysInliner

This contains the part of D62225 which prevents insertion of lifetime
intrinsics when creating the AlwaysInliner. This fixes the following tests
when the new PM is enabled by default:

Clang :: CodeGen/aarch64-neon-across.c
Clang :: CodeGen/aarch64-neon-fcvt-intrinsics.c
Clang :: CodeGen/aarch64-neon-fma.c
Clang :: CodeGen/aarch64-neon-perm.c
Clang :: CodeGen/aarch64-neon-tbl.c
Clang :: CodeGen/aarch64-poly128.c
Clang :: CodeGen/aarch64-v8.2a-neon-intrinsics.c
Clang :: CodeGen/arm-neon-fma.c
Clang :: CodeGen/arm-neon-numeric-maxmin.c
Clang :: CodeGen/arm-neon-vcvtX.c
Clang :: CodeGen/avx-builtins.c
Clang :: CodeGen/builtins-ppc-p9vector.c
Clang :: CodeGen/builtins-ppc-vsx.c
Clang :: CodeGen/lifetime.c
Clang :: CodeGen/sse-builtins.c
Clang :: CodeGen/sse2-builtins.c

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

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/test/CodeGen/lifetime.c

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=363277&r1=363276&r2=363277&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Thu Jun 13 09:45:29 2019
@@ -,8 +,10 @@ void EmitAssemblyHelper::EmitAssemblyWit
 MPM.addPass(InstrProfiling(*Options, false));
 
   // Build a minimal pipeline based on the semantics required by Clang,
-  // which is just that always inlining occurs.
-  MPM.addPass(AlwaysInlinerPass());
+  // which is just that always inlining occurs. Further, disable generating
+  // lifetime intrinsics to avoid enabling further optimizations during
+  // code generation.
+  MPM.addPass(AlwaysInlinerPass(/*InsertLifetimeIntrinsics=*/false));
 
   // At -O0 we directly run necessary sanitizer passes.
   if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))

Modified: cfe/trunk/test/CodeGen/lifetime.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/lifetime.c?rev=363277&r1=363276&r2=363277&view=diff
==
--- cfe/trunk/test/CodeGen/lifetime.c (original)
+++ cfe/trunk/test/CodeGen/lifetime.c Thu Jun 13 09:45:29 2019
@@ -1,7 +1,8 @@
-// RUN: %clang -S -emit-llvm -o - -O0 %s | FileCheck %s -check-prefix=O0
+// RUN: %clang -S -emit-llvm -o - -O0 -fno-experimental-new-pass-manager %s | 
FileCheck %s -check-prefix=O0
 // RUN: %clang -S -emit-llvm -o - -O1 -fno-experimental-new-pass-manager %s | 
FileCheck %s -check-prefix=O1
 // RUN: %clang -S -emit-llvm -o - -O2 -fno-experimental-new-pass-manager %s | 
FileCheck %s -check-prefix=O2
 // RUN: %clang -S -emit-llvm -o - -O3 -fno-experimental-new-pass-manager %s | 
FileCheck %s -check-prefix=O3
+// RUN: %clang -S -emit-llvm -o - -O0 -fexperimental-new-pass-manager %s | 
FileCheck %s -check-prefix=O0
 
 extern void use(char *a);
 


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


[PATCH] D63153: [clang][NewPM] Fix broken -O0 test from the AlwaysInliner

2019-06-13 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In D63153#1540920 , @chandlerc wrote:

> Code change LGTM. Can you update at least one of the tests to explicitly run 
> both PMs so that we'll notice if this breaks in some weird way? Feel free to 
> submit with that change.


Done


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63153



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


[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

2019-06-13 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

Thanks for the patch, I look forward to this feature!

I think the changes in `test/SemaCXX/warn-unused-label-error.cpp`, 
`test/Sema/block-literal.c`, and `test/Sema/address_spaces.c` should not be 
committed (2 look like unrelated cleanups?).




Comment at: lib/Parse/ParseStmt.cpp:110-111
 
   assert((Attrs.empty() || Res.isInvalid() || Res.isUsable()) &&
  "attributes on empty statement");
 

Wouldn't this statement have to change? `__attribute__((fallthrough))` //is// 
an "attribute on [an] empty statement."  Maybe this is not the correct place to 
try to parse a GNU attr?



Comment at: lib/Sema/AnalysisBasedWarnings.cpp:1279
 continue;
-  if (S.getLangOpts().CPlusPlus11) {
+  if (S.getLangOpts().CPlusPlus11 || S.getLangOpts().C99) {
 const Stmt *Term = B->getTerminatorStmt();

Probably should additionally/instead check `S.getLangOpts().GNUMode` (since 
these are GNU C style attributes)?  I guess we want these attributes to be 
supported in C regardless of `-std=`?



Comment at: test/Sema/block-literal.c:44
   takeblock(^{ x = 4; });  // expected-error {{variable is not assignable 
(missing __block type specifier)}}
-  __block y = 7;// expected-warning {{type specifier missing, defaults to 
'int'}}
-  takeblock(^{ y = 8; });
+  __block y = 7;// expected-error {{use of undeclared identifier 'y'}}
+  takeblock(^{ y = 8; }); // expected-error {{use of undeclared identifier 
'y'}}

xbolva00 wrote:
> I tried look at this, but I have no idea how my change to parse GNU affects 
> __block.
If you remove your change to `lib/Parse/ParseStmt.cpp`, does this test still 
fail in this way?  Did you test this on an assertion enabled build 
(`-DLLVM_ENABLE_ASSERTIONS=ON`)? (I would have expected the assertion I 
commented on above to fail.)



Comment at: test/Sema/fallthrough-attr.c:1
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -verify -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -std=c11 -verify -Wimplicit-fallthrough %s

would you mind adding a run for `-std=gnu89`? In particular, I'm worried about 
you're above change checking c99.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63260



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


[PATCH] D62883: [analyzer] Track conditions of terminator statements on which the reported node depends on

2019-06-13 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

I marked reports, confusingly, "Confirmed" if the extra notes were meaningful, 
"Intentional" if they were meaningless, and "False positive" if it's in between.


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

https://reviews.llvm.org/D62883



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


[PATCH] D63283: PR42182: Allow thread-local to use __cxa_thread_atexit when -fno-use-cxx-atexit is used

2019-06-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: jyu2, rnk, ahatanak, rjmccall, jyknight.
Herald added a subscriber: dexonsmith.
Herald added a project: clang.

This matches the GCC behavior, __cxa_thread_atexit should be permissible 
even though cxa_atexit is disabled.


Repository:
  rC Clang

https://reviews.llvm.org/D63283

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp


Index: clang/test/CodeGenCXX/cxx11-thread-local.cpp
===
--- clang/test/CodeGenCXX/cxx11-thread-local.cpp
+++ clang/test/CodeGenCXX/cxx11-thread-local.cpp
@@ -4,6 +4,12 @@
 // RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK 
--check-prefix=LINUX %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-apple-darwin12 
| FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
 
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple 
x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 
-disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck 
--check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -femulated-tls -emit-llvm %s 
-o - \
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK 
--check-prefix=LINUX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple 
x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
+
 int f();
 int g();
 
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2270,6 +2270,8 @@
 static void emitGlobalDtorWithCXAAtExit(CodeGenFunction &CGF,
 llvm::FunctionCallee dtor,
 llvm::Constant *addr, bool TLS) {
+  assert((TLS || CGF.getTypes().getCodeGenOpts().CXAAtExit) &&
+ "__cxa_atexit is disabled");
   const char *Name = "__cxa_atexit";
   if (TLS) {
 const llvm::Triple &T = CGF.getTarget().getTriple();
@@ -2364,12 +2366,9 @@
 return;
 
   // Use __cxa_atexit if available.
-  if (CGM.getCodeGenOpts().CXAAtExit)
+  if (CGM.getCodeGenOpts().CXAAtExit || D.getTLSKind())
 return emitGlobalDtorWithCXAAtExit(CGF, dtor, addr, D.getTLSKind());
 
-  if (D.getTLSKind())
-CGM.ErrorUnsupported(&D, "non-trivial TLS destruction");
-
   // In Apple kexts, we want to add a global destructor entry.
   // FIXME: shouldn't this be guarded by some variable?
   if (CGM.getLangOpts().AppleKext) {


Index: clang/test/CodeGenCXX/cxx11-thread-local.cpp
===
--- clang/test/CodeGenCXX/cxx11-thread-local.cpp
+++ clang/test/CodeGenCXX/cxx11-thread-local.cpp
@@ -4,6 +4,12 @@
 // RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
 
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -femulated-tls -emit-llvm %s -o - \
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
+
 int f();
 int g();
 
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2270,6 +2270,8 @@
 static void emitGlobalDtorWithCXAAtExit(CodeGenFunction &CGF,
 llvm::FunctionCallee dtor,
 llvm::Constant *addr, bool TLS) {
+  assert((TLS || CGF.getTypes().getCodeGenOpts().CXAAtExit) &&
+ "__cxa_atexit is disabled");
   const char *Name = "__cxa_atexit";
   if (TLS) {
 const llvm::Triple &T = CGF.getTarget().getTriple();
@@ -2364,12 +2366,9 @@
 return;
 
   // Use __cxa_atexit if available.
-  if (CGM.getCodeGenOpts().CXAAtExit)
+  if (CGM.getCodeGenOpts().CXAAtExit || D.getTLSKind())
 return emitGlobalDtorWithCXAAtExit(CGF, dtor, addr, D.getTLSKind());
 
-  if (D.getTLSKind())
-CGM.ErrorUnsupported(&D, "non-trivial TLS destruction");
-
   // In Apple kexts, we want to add a global destructor entry.
 

r363278 - [clang][NewPM] Fix broken profile test

2019-06-13 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Thu Jun 13 10:25:36 2019
New Revision: 363278

URL: http://llvm.org/viewvc/llvm-project?rev=363278&view=rev
Log:
[clang][NewPM] Fix broken profile test

This contains the part of D62225 which fixes Profile/gcc-flag-compatibility.c
by adding the pass that allows default profile generation to work under the new
PM. It seems that ./default.profraw was not being generated with new PM enabled.

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

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/test/Profile/gcc-flag-compatibility.c

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=363278&r1=363277&r2=363278&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Thu Jun 13 10:25:36 2019
@@ -60,6 +60,7 @@
 #include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
 #include "llvm/Transforms/Instrumentation/InstrProfiling.h"
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
+#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
 #include "llvm/Transforms/ObjCARC.h"
 #include "llvm/Transforms/Scalar.h"
@@ -1216,6 +1217,11 @@ void EmitAssemblyHelper::EmitAssemblyWit
 
 if (CodeGenOpts.OptimizationLevel == 0)
   addSanitizersAtO0(MPM, TargetTriple, LangOpts, CodeGenOpts);
+
+if (CodeGenOpts.hasProfileIRInstr()) {
+  // This file is stored as the ProfileFile.
+  MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->ProfileFile));
+}
   }
 
   // FIXME: We still use the legacy pass manager to do code generation. We

Modified: cfe/trunk/test/Profile/gcc-flag-compatibility.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/gcc-flag-compatibility.c?rev=363278&r1=363277&r2=363278&view=diff
==
--- cfe/trunk/test/Profile/gcc-flag-compatibility.c (original)
+++ cfe/trunk/test/Profile/gcc-flag-compatibility.c Thu Jun 13 10:25:36 2019
@@ -7,25 +7,29 @@
 // -fprofile-use=Uses the profile file /default.profdata
 // -fprofile-use=/file   Uses the profile file /file
 
-// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate | FileCheck 
-check-prefix=PROFILE-GEN %s
+// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate 
-fno-experimental-new-pass-manager | FileCheck -check-prefix=PROFILE-GEN %s
+// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate 
-fexperimental-new-pass-manager | FileCheck -check-prefix=PROFILE-GEN %s
 // PROFILE-GEN: __llvm_profile_filename
 
 // Check that -fprofile-generate=/path/to generates /path/to/default.profraw
-// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate=/path/to | 
FileCheck -check-prefix=PROFILE-GEN-EQ %s
+// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate=/path/to 
-fno-experimental-new-pass-manager | FileCheck -check-prefix=PROFILE-GEN-EQ %s
+// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate=/path/to 
-fexperimental-new-pass-manager | FileCheck -check-prefix=PROFILE-GEN-EQ %s
 // PROFILE-GEN-EQ: constant [{{.*}} x i8] c"/path/to{{/|\\5C}}{{.*}}\00"
 
 // Check that -fprofile-use=some/path reads some/path/default.profdata
 // RUN: rm -rf %t.dir
 // RUN: mkdir -p %t.dir/some/path
 // RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility.proftext -o 
%t.dir/some/path/default.profdata
-// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path | FileCheck -check-prefix=PROFILE-USE-2 %s
+// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path -fno-experimental-new-pass-manager | FileCheck 
-check-prefix=PROFILE-USE-2 %s
+// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path -fexperimental-new-pass-manager | FileCheck 
-check-prefix=PROFILE-USE-2 %s
 // PROFILE-USE-2: = !{!"branch_weights", i32 101, i32 2}
 
 // Check that -fprofile-use=some/path/file.prof reads some/path/file.prof
 // RUN: rm -rf %t.dir
 // RUN: mkdir -p %t.dir/some/path
 // RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility.proftext -o 
%t.dir/some/path/file.prof
-// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path/file.prof | FileCheck 
-check-prefix=PROFILE-USE-3 %s
+// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path/file.prof -fno-experimental-new-pass-manager | 
FileCheck -check-prefix=PROFILE-USE-3 %s
+// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path/file.prof -fexperimental-new-pass-manager | 
FileCheck -check-prefix=PROFILE-USE-3 %s
 // PROFILE-USE-3: = !{!"branch_weights", i32 101, i32 2}
 
 int X = 0;


___

[PATCH] D63155: [clang][NewPM] Fix broken profile test

2019-06-13 Thread Leonard Chan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363278: [clang][NewPM] Fix broken profile test (authored by 
leonardchan, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63155?vs=204124&id=204574#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63155

Files:
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  cfe/trunk/test/Profile/gcc-flag-compatibility.c


Index: cfe/trunk/test/Profile/gcc-flag-compatibility.c
===
--- cfe/trunk/test/Profile/gcc-flag-compatibility.c
+++ cfe/trunk/test/Profile/gcc-flag-compatibility.c
@@ -7,25 +7,29 @@
 // -fprofile-use=Uses the profile file /default.profdata
 // -fprofile-use=/file   Uses the profile file /file
 
-// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate | FileCheck 
-check-prefix=PROFILE-GEN %s
+// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate 
-fno-experimental-new-pass-manager | FileCheck -check-prefix=PROFILE-GEN %s
+// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate 
-fexperimental-new-pass-manager | FileCheck -check-prefix=PROFILE-GEN %s
 // PROFILE-GEN: __llvm_profile_filename
 
 // Check that -fprofile-generate=/path/to generates /path/to/default.profraw
-// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate=/path/to | 
FileCheck -check-prefix=PROFILE-GEN-EQ %s
+// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate=/path/to 
-fno-experimental-new-pass-manager | FileCheck -check-prefix=PROFILE-GEN-EQ %s
+// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate=/path/to 
-fexperimental-new-pass-manager | FileCheck -check-prefix=PROFILE-GEN-EQ %s
 // PROFILE-GEN-EQ: constant [{{.*}} x i8] c"/path/to{{/|\\5C}}{{.*}}\00"
 
 // Check that -fprofile-use=some/path reads some/path/default.profdata
 // RUN: rm -rf %t.dir
 // RUN: mkdir -p %t.dir/some/path
 // RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility.proftext -o 
%t.dir/some/path/default.profdata
-// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path | FileCheck -check-prefix=PROFILE-USE-2 %s
+// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path -fno-experimental-new-pass-manager | FileCheck 
-check-prefix=PROFILE-USE-2 %s
+// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path -fexperimental-new-pass-manager | FileCheck 
-check-prefix=PROFILE-USE-2 %s
 // PROFILE-USE-2: = !{!"branch_weights", i32 101, i32 2}
 
 // Check that -fprofile-use=some/path/file.prof reads some/path/file.prof
 // RUN: rm -rf %t.dir
 // RUN: mkdir -p %t.dir/some/path
 // RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility.proftext -o 
%t.dir/some/path/file.prof
-// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path/file.prof | FileCheck 
-check-prefix=PROFILE-USE-3 %s
+// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path/file.prof -fno-experimental-new-pass-manager | 
FileCheck -check-prefix=PROFILE-USE-3 %s
+// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path/file.prof -fexperimental-new-pass-manager | 
FileCheck -check-prefix=PROFILE-USE-3 %s
 // PROFILE-USE-3: = !{!"branch_weights", i32 101, i32 2}
 
 int X = 0;
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -60,6 +60,7 @@
 #include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
 #include "llvm/Transforms/Instrumentation/InstrProfiling.h"
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
+#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
 #include "llvm/Transforms/ObjCARC.h"
 #include "llvm/Transforms/Scalar.h"
@@ -1216,6 +1217,11 @@
 
 if (CodeGenOpts.OptimizationLevel == 0)
   addSanitizersAtO0(MPM, TargetTriple, LangOpts, CodeGenOpts);
+
+if (CodeGenOpts.hasProfileIRInstr()) {
+  // This file is stored as the ProfileFile.
+  MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->ProfileFile));
+}
   }
 
   // FIXME: We still use the legacy pass manager to do code generation. We


Index: cfe/trunk/test/Profile/gcc-flag-compatibility.c
===
--- cfe/trunk/test/Profile/gcc-flag-compatibility.c
+++ cfe/trunk/test/Profile/gcc-flag-compatibility.c
@@ -7,25 +7,29 @@
 // -fprofile-use=Uses the profile file /default.profdata
 // -fprofile-use=/file   Uses the profile file /file
 
-// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate | FileCheck -check-prefix=PROFILE-G

[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

2019-06-13 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 marked 5 inline comments as done.
xbolva00 added inline comments.



Comment at: lib/Parse/ParseStmt.cpp:110-111
 
   assert((Attrs.empty() || Res.isInvalid() || Res.isUsable()) &&
  "attributes on empty statement");
 

nickdesaulniers wrote:
> Wouldn't this statement have to change? `__attribute__((fallthrough))` //is// 
> an "attribute on [an] empty statement."  Maybe this is not the correct place 
> to try to parse a GNU attr?
Since we parse [[ ]] parse here too, I expect it could be correct place.

@aaron.ballman ?



Comment at: lib/Sema/AnalysisBasedWarnings.cpp:1279
 continue;
-  if (S.getLangOpts().CPlusPlus11) {
+  if (S.getLangOpts().CPlusPlus11 || S.getLangOpts().C99) {
 const Stmt *Term = B->getTerminatorStmt();

nickdesaulniers wrote:
> Probably should additionally/instead check `S.getLangOpts().GNUMode` (since 
> these are GNU C style attributes)?  I guess we want these attributes to be 
> supported in C regardless of `-std=`?
Good point.



Comment at: test/Sema/block-literal.c:44
   takeblock(^{ x = 4; });  // expected-error {{variable is not assignable 
(missing __block type specifier)}}
-  __block y = 7;// expected-warning {{type specifier missing, defaults to 
'int'}}
-  takeblock(^{ y = 8; });
+  __block y = 7;// expected-error {{use of undeclared identifier 'y'}}
+  takeblock(^{ y = 8; }); // expected-error {{use of undeclared identifier 
'y'}}

nickdesaulniers wrote:
> xbolva00 wrote:
> > I tried look at this, but I have no idea how my change to parse GNU affects 
> > __block.
> If you remove your change to `lib/Parse/ParseStmt.cpp`, does this test still 
> fail in this way?  Did you test this on an assertion enabled build 
> (`-DLLVM_ENABLE_ASSERTIONS=ON`)? (I would have expected the assertion I 
> commented on above to fail.)
Yes, added line "MaybeParseGNUAttributes(Attrs);" cause this changes in 
block-literal.c and address_spaces.c.



Comment at: test/Sema/block-literal.c:44
   takeblock(^{ x = 4; });  // expected-error {{variable is not assignable 
(missing __block type specifier)}}
-  __block y = 7;// expected-warning {{type specifier missing, defaults to 
'int'}}
-  takeblock(^{ y = 8; });
+  __block y = 7;// expected-error {{use of undeclared identifier 'y'}}
+  takeblock(^{ y = 8; }); // expected-error {{use of undeclared identifier 
'y'}}

xbolva00 wrote:
> nickdesaulniers wrote:
> > xbolva00 wrote:
> > > I tried look at this, but I have no idea how my change to parse GNU 
> > > affects __block.
> > If you remove your change to `lib/Parse/ParseStmt.cpp`, does this test 
> > still fail in this way?  Did you test this on an assertion enabled build 
> > (`-DLLVM_ENABLE_ASSERTIONS=ON`)? (I would have expected the assertion I 
> > commented on above to fail.)
> Yes, added line "MaybeParseGNUAttributes(Attrs);" cause this changes in 
> block-literal.c and address_spaces.c.
Yes, LLVM_ENABLE_ASSERTIONS is ticked in cmake-gui.. I have no assert failure 
in that place..


Repository:
  rC Clang

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

https://reviews.llvm.org/D63260



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


[PATCH] D63287: [clang-tidy] Make ClangTidyCheck::OptionsView public.

2019-06-13 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: gribozavr.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.

The `OptionsView` class is currently protected. This constraint prevents tidies 
from passing the OptionsView to, for example, a helper function. Similarly, 
TransformerClangTidyCheck cannot pass the `OptionsView` object to functions 
that generate `tooling::RewriteRule`s.  The latter is needed to allow the 
definition of such rules to depend on the clang-tidy options, as demonstrated 
in the child revision.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63287

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h


Index: clang-tools-extra/clang-tidy/ClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -100,13 +100,6 @@
   /// whether it has the default value or it has been overridden.
   virtual void storeOptions(ClangTidyOptions::OptionMap &Options) {}
 
-private:
-  void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  StringRef getID() const override { return CheckName; }
-  std::string CheckName;
-  ClangTidyContext *Context;
-
-protected:
   /// \brief Provides access to the ``ClangTidyCheck`` options via check-local
   /// names.
   ///
@@ -181,6 +174,13 @@
 const ClangTidyOptions::OptionMap &CheckOptions;
   };
 
+private:
+  void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  StringRef getID() const override { return CheckName; }
+  std::string CheckName;
+  ClangTidyContext *Context;
+
+protected:
   OptionsView Options;
   /// \brief Returns the main file name of the current translation unit.
   StringRef getCurrentMainFile() const { return Context->getCurrentFile(); }


Index: clang-tools-extra/clang-tidy/ClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -100,13 +100,6 @@
   /// whether it has the default value or it has been overridden.
   virtual void storeOptions(ClangTidyOptions::OptionMap &Options) {}
 
-private:
-  void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
-  StringRef getID() const override { return CheckName; }
-  std::string CheckName;
-  ClangTidyContext *Context;
-
-protected:
   /// \brief Provides access to the ``ClangTidyCheck`` options via check-local
   /// names.
   ///
@@ -181,6 +174,13 @@
 const ClangTidyOptions::OptionMap &CheckOptions;
   };
 
+private:
+  void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  StringRef getID() const override { return CheckName; }
+  std::string CheckName;
+  ClangTidyContext *Context;
+
+protected:
   OptionsView Options;
   /// \brief Returns the main file name of the current translation unit.
   StringRef getCurrentMainFile() const { return Context->getCurrentFile(); }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r363281 - [clang][NewPM] Fix split debug test

2019-06-13 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Thu Jun 13 10:40:03 2019
New Revision: 363281

URL: http://llvm.org/viewvc/llvm-project?rev=363281&view=rev
Log:
[clang][NewPM] Fix split debug test

This contains the part of D62225 which fixes CodeGen/split-debug-single-file.c
by not placing .dwo sections when using -enable-split-dwarf=split.

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

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/test/CodeGen/split-debug-single-file.c

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=363281&r1=363280&r2=363281&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Thu Jun 13 10:40:03 2019
@@ -1275,7 +1275,8 @@ void EmitAssemblyHelper::EmitAssemblyWit
 NeedCodeGen = true;
 CodeGenPasses.add(
 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
-if (!CodeGenOpts.SplitDwarfFile.empty()) {
+if (!CodeGenOpts.SplitDwarfFile.empty() &&
+CodeGenOpts.getSplitDwarfMode() == CodeGenOptions::SplitFileFission) {
   DwoOS = openOutputFile(CodeGenOpts.SplitDwarfFile);
   if (!DwoOS)
 return;

Modified: cfe/trunk/test/CodeGen/split-debug-single-file.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/split-debug-single-file.c?rev=363281&r1=363280&r2=363281&view=diff
==
--- cfe/trunk/test/CodeGen/split-debug-single-file.c (original)
+++ cfe/trunk/test/CodeGen/split-debug-single-file.c Thu Jun 13 10:40:03 2019
@@ -2,13 +2,19 @@
 
 // Testing to ensure -enable-split-dwarf=single allows to place .dwo sections 
into regular output object.
 //  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
-//  RUN:   -enable-split-dwarf=single -split-dwarf-file %t.o -emit-obj -o %t.o 
%s
+//  RUN:   -enable-split-dwarf=single -split-dwarf-file %t.o -emit-obj -o %t.o 
%s -fno-experimental-new-pass-manager
+//  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SINGLE %s
+//  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
+//  RUN:   -enable-split-dwarf=single -split-dwarf-file %t.o -emit-obj -o %t.o 
%s -fexperimental-new-pass-manager
 //  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SINGLE %s
 //  MODE-SINGLE: .dwo
 
 // Testing to ensure -enable-split-dwarf=split does not place .dwo sections 
into regular output object.
 //  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
-//  RUN:   -enable-split-dwarf=split -split-dwarf-file %t.o -emit-obj -o %t.o 
%s
+//  RUN:   -enable-split-dwarf=split -split-dwarf-file %t.o -emit-obj -o %t.o 
%s -fno-experimental-new-pass-manager
+//  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SPLIT %s
+//  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
+//  RUN:   -enable-split-dwarf=split -split-dwarf-file %t.o -emit-obj -o %t.o 
%s -fexperimental-new-pass-manager
 //  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SPLIT %s
 //  MODE-SPLIT-NOT: .dwo
 


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


[PATCH] D63168: [clang][NewPM] Fix split debug test

2019-06-13 Thread Leonard Chan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363281: [clang][NewPM] Fix split debug test (authored by 
leonardchan, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63168?vs=204165&id=204580#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63168

Files:
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  cfe/trunk/test/CodeGen/split-debug-single-file.c


Index: cfe/trunk/test/CodeGen/split-debug-single-file.c
===
--- cfe/trunk/test/CodeGen/split-debug-single-file.c
+++ cfe/trunk/test/CodeGen/split-debug-single-file.c
@@ -2,13 +2,19 @@
 
 // Testing to ensure -enable-split-dwarf=single allows to place .dwo sections 
into regular output object.
 //  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
-//  RUN:   -enable-split-dwarf=single -split-dwarf-file %t.o -emit-obj -o %t.o 
%s
+//  RUN:   -enable-split-dwarf=single -split-dwarf-file %t.o -emit-obj -o %t.o 
%s -fno-experimental-new-pass-manager
+//  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SINGLE %s
+//  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
+//  RUN:   -enable-split-dwarf=single -split-dwarf-file %t.o -emit-obj -o %t.o 
%s -fexperimental-new-pass-manager
 //  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SINGLE %s
 //  MODE-SINGLE: .dwo
 
 // Testing to ensure -enable-split-dwarf=split does not place .dwo sections 
into regular output object.
 //  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
-//  RUN:   -enable-split-dwarf=split -split-dwarf-file %t.o -emit-obj -o %t.o 
%s
+//  RUN:   -enable-split-dwarf=split -split-dwarf-file %t.o -emit-obj -o %t.o 
%s -fno-experimental-new-pass-manager
+//  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SPLIT %s
+//  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
+//  RUN:   -enable-split-dwarf=split -split-dwarf-file %t.o -emit-obj -o %t.o 
%s -fexperimental-new-pass-manager
 //  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SPLIT %s
 //  MODE-SPLIT-NOT: .dwo
 
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -1275,7 +1275,8 @@
 NeedCodeGen = true;
 CodeGenPasses.add(
 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
-if (!CodeGenOpts.SplitDwarfFile.empty()) {
+if (!CodeGenOpts.SplitDwarfFile.empty() &&
+CodeGenOpts.getSplitDwarfMode() == CodeGenOptions::SplitFileFission) {
   DwoOS = openOutputFile(CodeGenOpts.SplitDwarfFile);
   if (!DwoOS)
 return;


Index: cfe/trunk/test/CodeGen/split-debug-single-file.c
===
--- cfe/trunk/test/CodeGen/split-debug-single-file.c
+++ cfe/trunk/test/CodeGen/split-debug-single-file.c
@@ -2,13 +2,19 @@
 
 // Testing to ensure -enable-split-dwarf=single allows to place .dwo sections into regular output object.
 //  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
-//  RUN:   -enable-split-dwarf=single -split-dwarf-file %t.o -emit-obj -o %t.o %s
+//  RUN:   -enable-split-dwarf=single -split-dwarf-file %t.o -emit-obj -o %t.o %s -fno-experimental-new-pass-manager
+//  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SINGLE %s
+//  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
+//  RUN:   -enable-split-dwarf=single -split-dwarf-file %t.o -emit-obj -o %t.o %s -fexperimental-new-pass-manager
 //  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SINGLE %s
 //  MODE-SINGLE: .dwo
 
 // Testing to ensure -enable-split-dwarf=split does not place .dwo sections into regular output object.
 //  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
-//  RUN:   -enable-split-dwarf=split -split-dwarf-file %t.o -emit-obj -o %t.o %s
+//  RUN:   -enable-split-dwarf=split -split-dwarf-file %t.o -emit-obj -o %t.o %s -fno-experimental-new-pass-manager
+//  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SPLIT %s
+//  RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux \
+//  RUN:   -enable-split-dwarf=split -split-dwarf-file %t.o -emit-obj -o %t.o %s -fexperimental-new-pass-manager
 //  RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=MODE-SPLIT %s
 //  MODE-SPLIT-NOT: .dwo
 
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -1275,7 +1275,8 @@
 NeedCodeGen = true;
 CodeGenPasses.add(
 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()))

[PATCH] D63288: [clang-tidy] Generalize TransformerClangTidyCheck to take a rule generator.

2019-06-13 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: gribozavr.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.
ymandel added a parent revision: D63287: [clang-tidy] Make 
ClangTidyCheck::OptionsView public..

Tidy check behavior often depends on language and/or clang-tidy options. This 
revision allows a user of TranformerClangTidyCheck to pass rule _generator_ in 
place of a rule, where the generator takes both the language and clang-tidy 
options. Additionally, the generator returns an `Optional` to allow for the 
case where the check is deemed irrelevant/disable based on those options.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63288

Files:
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h


Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
@@ -31,19 +31,32 @@
 // };
 class TransformerClangTidyCheck : public ClangTidyCheck {
 public:
-  // All cases in \p R must have a non-null \c Explanation, even though \c
-  // Explanation is optional for RewriteRule in general. Because the primary
-  // purpose of clang-tidy checks is to provide users with diagnostics, we
-  // assume that a missing explanation is a bug.  If no explanation is desired,
-  // indicate that explicitly (for example, by passing `text("no explanation")`
-  //  to `makeRule` as the `Explanation` argument).
+  // \p MakeRule generates the rewrite rule to be used by the check, based on
+  // the given language and clang-tidy options. It can return \c None to handle
+  // cases where the options disable the check.
+  //
+  // All cases in the rule generated by \p MakeRule must have a non-null \c
+  // Explanation, even though \c Explanation is optional for RewriteRule in
+  // general. Because the primary purpose of clang-tidy checks is to provide
+  // users with diagnostics, we assume that a missing explanation is a bug.  If
+  // no explanation is desired, indicate that explicitly (for example, by
+  // passing `text("no explanation")` to `makeRule` as the `Explanation`
+  // argument).
+  TransformerClangTidyCheck(std::function(
+const LangOptions &, const OptionsView &)>
+MakeRule,
+StringRef Name, ClangTidyContext *Context);
+
+  // Convenience overload of the constructor when the rule doesn't depend on 
any
+  // of the language or clang-tidy options.
   TransformerClangTidyCheck(tooling::RewriteRule R, StringRef Name,
 ClangTidyContext *Context);
+
   void registerMatchers(ast_matchers::MatchFinder *Finder) final;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
 
 private:
-  tooling::RewriteRule Rule;
+  Optional Rule;
 };
 
 } // namespace utils
Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -25,9 +25,23 @@
  " explicitly provide an empty explanation if none is desired");
 }
 
+TransformerClangTidyCheck::TransformerClangTidyCheck(
+std::function(const LangOptions &,
+const OptionsView &)>
+MakeRule,
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), Rule(MakeRule(getLangOpts(), Options)) {
+  assert(llvm::all_of(Rule.Cases, [](const RewriteRule::Case &C) {
+   return C.Explanation != nullptr;
+ }) &&
+ "clang-tidy checks must have an explanation by default;"
+ " explicitly provide an empty explanation if none is desired");
+}
+
 void TransformerClangTidyCheck::registerMatchers(
 ast_matchers::MatchFinder *Finder) {
-  Finder->addDynamicMatcher(tooling::detail::buildMatcher(Rule), this);
+  if (Rule)
+Finder->addDynamicMatcher(tooling::detail::buildMatcher(*Rule), this);
 }
 
 void TransformerClangTidyCheck::check(
@@ -43,7 +57,8 @@
   Root->second.getSourceRange().getBegin());
   assert(RootLoc.isValid() && "Invalid location for Root node of match.");
 
-  RewriteRule::Case Case = tooling::detail::findSelectedCase(Result, Rule);
+  assert(Rule && "check() should not fire if Rule is None");
+  RewriteRule::Case Case = tooling::detail::findSelectedCase(Result, *Rule);
   Expected> Transformations =
   tooling::detail::translateEdits(Result, Case.Edits);
   if (!Transformations) {


Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.h
===
--- clang-tools-extra/clang-tidy

[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

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

__block y = 7;

if (Tok.is(tok::kw___attribute))

  printf("__attr\n");

Output:
__attr


Repository:
  rC Clang

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

https://reviews.llvm.org/D63260



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


[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

2019-06-13 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 marked an inline comment as done.
xbolva00 added inline comments.



Comment at: test/Sema/block-literal.c:44
   takeblock(^{ x = 4; });  // expected-error {{variable is not assignable 
(missing __block type specifier)}}
-  __block y = 7;// expected-warning {{type specifier missing, defaults to 
'int'}}
-  takeblock(^{ y = 8; });
+  __block y = 7;// expected-error {{use of undeclared identifier 'y'}}
+  takeblock(^{ y = 8; }); // expected-error {{use of undeclared identifier 
'y'}}

xbolva00 wrote:
> xbolva00 wrote:
> > nickdesaulniers wrote:
> > > xbolva00 wrote:
> > > > I tried look at this, but I have no idea how my change to parse GNU 
> > > > affects __block.
> > > If you remove your change to `lib/Parse/ParseStmt.cpp`, does this test 
> > > still fail in this way?  Did you test this on an assertion enabled build 
> > > (`-DLLVM_ENABLE_ASSERTIONS=ON`)? (I would have expected the assertion I 
> > > commented on above to fail.)
> > Yes, added line "MaybeParseGNUAttributes(Attrs);" cause this changes in 
> > block-literal.c and address_spaces.c.
> Yes, LLVM_ENABLE_ASSERTIONS is ticked in cmake-gui.. I have no assert failure 
> in that place..
See my comment.. if __block is internally as "kw _ _ attribute", now I know why 
this was changed.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63260



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


[PATCH] D63288: [clang-tidy] Generalize TransformerClangTidyCheck to take a rule generator.

2019-06-13 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr accepted this revision.
gribozavr added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp:33
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), Rule(MakeRule(getLangOpts(), Options)) {
+  assert(llvm::all_of(Rule.Cases, [](const RewriteRule::Case &C) {

Can we dispatch to the other constructor?



Comment at: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp:40
+}
+
 void TransformerClangTidyCheck::registerMatchers(

Keep the definition order of constructors consistent with declaration order?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63288



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


[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

2019-06-13 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 204583.
xbolva00 added a comment.

Addressed some review notes. Thanks.


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

https://reviews.llvm.org/D63260

Files:
  include/clang/Basic/Attr.td
  lib/Parse/ParseStmt.cpp
  lib/Sema/AnalysisBasedWarnings.cpp
  test/Sema/address_spaces.c
  test/Sema/block-literal.c
  test/Sema/fallthrough-attr.c
  test/SemaCXX/switch-implicit-fallthrough.cpp
  test/SemaCXX/warn-unused-label-error.cpp

Index: test/SemaCXX/warn-unused-label-error.cpp
===
--- test/SemaCXX/warn-unused-label-error.cpp
+++ test/SemaCXX/warn-unused-label-error.cpp
@@ -18,9 +18,9 @@
   }
 
   void h() {
-D: // expected-warning {{unused label 'D'}}
+D:
   #pragma weak unused_local_static
-  __attribute__((unused))  // expected-warning {{declaration does not declare anything}}
+  __attribute__((unused))  // expected-error {{'unused' attribute cannot be applied to a statement}}
   ;
   }
 }
Index: test/SemaCXX/switch-implicit-fallthrough.cpp
===
--- test/SemaCXX/switch-implicit-fallthrough.cpp
+++ test/SemaCXX/switch-implicit-fallthrough.cpp
@@ -329,3 +329,15 @@
   }
   return n;
 }
+
+int fallthrough_attribute_spelling(int n) {
+  switch (n) {
+  case 0:
+n++;
+__attribute__ ((fallthrough));
+  case 1:
+n++;
+break;
+  }
+  return n;
+}
Index: test/Sema/fallthrough-attr.c
===
--- test/Sema/fallthrough-attr.c
+++ test/Sema/fallthrough-attr.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -std=gnu89 -verify -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -std=gnu99 -verify -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -verify -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -std=c11 -verify -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2x -DC2X -verify -Wimplicit-fallthrough %s
+
+int fallthrough_attribute_spelling(int n) {
+  switch (n) {
+  case 0:
+n++;
+  case 1: 
+#if defined(C2X)
+// expected-warning@-2{{unannotated fall-through between switch labels}} expected-note@-2{{insert '[[fallthrough]];' to silence this warning}} expected-note@-2{{insert 'break;' to avoid fall-through}}
+#else
+// expected-warning@-4{{unannotated fall-through between switch labels}} expected-note@-4{{insert '__attribute__ ((fallthrough));' to silence this warning}} expected-note@-4{{insert 'break;' to avoid fall-through}}
+#endif
+n++;
+__attribute__ ((fallthrough));
+  case 2:
+n++;
+break;
+  }
+  return n;
+}
Index: test/Sema/block-literal.c
===
--- test/Sema/block-literal.c
+++ test/Sema/block-literal.c
@@ -41,8 +41,8 @@
 
   foo:
   takeblock(^{ x = 4; });  // expected-error {{variable is not assignable (missing __block type specifier)}}
-  __block y = 7;// expected-warning {{type specifier missing, defaults to 'int'}}
-  takeblock(^{ y = 8; });
+  __block y = 7;// expected-error {{use of undeclared identifier 'y'}}
+  takeblock(^{ x = 8; }); // expected-error {{use of undeclared identifier 'y'}}
 }
 
 
Index: test/Sema/address_spaces.c
===
--- test/Sema/address_spaces.c
+++ test/Sema/address_spaces.c
@@ -9,7 +9,7 @@
 void foo(_AS3 float *a,
  _AS1 float b) // expected-error {{parameter may not be qualified with an address space}}
 {
-  _AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}}
+  _AS2 *x;// expected-error {{use of undeclared identifier 'x'}}
   _AS1 float * _AS2 *B;
 
   int _AS1 _AS2 *Y;   // expected-error {{multiple address spaces specified for type}}
Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -1215,7 +1215,7 @@
 tok::r_square, tok::r_square
   };
 
-  bool PreferClangAttr = !PP.getLangOpts().CPlusPlus17;
+  bool PreferClangAttr = !PP.getLangOpts().CPlusPlus17 && !PP.getLangOpts().C2x;
 
   StringRef MacroName;
   if (PreferClangAttr)
@@ -1224,24 +1224,19 @@
 MacroName = PP.getLastMacroWithSpelling(Loc, FallthroughTokens);
   if (MacroName.empty() && !PreferClangAttr)
 MacroName = PP.getLastMacroWithSpelling(Loc, ClangFallthroughTokens);
-  if (MacroName.empty())
-MacroName = PreferClangAttr ? "[[clang::fallthrough]]" : "[[fallthrough]]";
+  if (MacroName.empty()) {
+if (!PreferClangAttr)
+  MacroName = "[[fallthrough]]";
+else if (PP.getLangOpts().CPlusPlus)
+  MacroName = "[[clang::fallthrough]]";
+else
+  MacroName = "__attribute__ ((fallthrough))";
+  }
   return MacroName;
 }
 
 static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC,

[PATCH] D63270: [clangd] Add include-mapping for C symbols.

2019-06-13 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/include-mapping/cppreference_parser.py:1
-#!/usr/bin/env python
-#===- gen_std.py -  --*- python 
-*--===#

could we add a similar License and header comment section to this file as well ?



Comment at: clang-tools-extra/clangd/include-mapping/gen_std.py:90
+symbol_index_root = page_root
+parse_pages = [(page_root, "index.html", "")]
+

maybe we should rather pass some something like "INVALID" as namespace for C 
symbols?



Comment at: clang-tools-extra/clangd/include-mapping/gen_std.py:95
 
-  parse_pages =  [
-(cpp_root, "symbol_index.html", "std::"),
-# std sub-namespace symbols have separated pages.
-# We don't index std literal operators (e.g.
-# std::literals::chrono_literals::operator""d), these symbols can't be
-# accessed by std::.
-# FIXME: index std::placeholders symbols, placeholders.html page is
-# different (which contains one entry for _1, _2, ..., _N), we need special
-# handling.
-(symbol_index_root, "chrono.html", "std::chrono::"),
-(symbol_index_root, "filesystem.html", "std::filesystem::"),
-(symbol_index_root, "pmr.html", "std::pmr::"),
-(symbol_index_root, "regex_constants.html", "std::regex_constants::"),
-(symbol_index_root, "this_thread.html", "std::this_thread::"),
-  ]
-
-  symbols = []
-  # Run many workers to process individual symbol pages under the symbol index.
-  # Don't allow workers to capture Ctrl-C.
-  pool = multiprocessing.Pool(
-  initializer=lambda: signal.signal(signal.SIGINT, signal.SIG_IGN))
-  try:
-for root_dir, page_name, namespace in parse_pages:
-  symbols.extend(GetSymbols(pool, root_dir, page_name, namespace))
-  finally:
-pool.terminate()
-pool.join()
+  symbols = cppreference_parser.GetSymbols(parse_pages)
 

I believe it is more sensible for this function to take `(args.cppreference, 
args.language)` and perform the above mentioned logic to generate `parse_pages` 
from these two internally.



Comment at: clang-tools-extra/clangd/include-mapping/test.py:1
 #!/usr/bin/env python
 #===- test.py -  -*- python 
-*--===#

no new tests for c symbol parsing ?



Comment at: clang-tools-extra/clangd/index/CanonicalIncludes.cpp:97
+  static const std::vector> CSymbolMap = 
{
+#define SYMBOL(Name, NameSpace, Header) {#NameSpace #Name, #Header},
+  #include "CSymbolMap.inc"

Let's drop the `#NameSpace` part from the expansion



Comment at: clang-tools-extra/clangd/unittests/CanonicalIncludesTests.cpp:19
+  auto Language = LangOptions();
+  Language.CPlusPlus = true;
+  addSystemHeadersMapping(&CI, Language);

could you also add some tests for C?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63270



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


[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

2019-06-13 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 204584.

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

https://reviews.llvm.org/D63260

Files:
  include/clang/Basic/Attr.td
  lib/Parse/ParseStmt.cpp
  lib/Sema/AnalysisBasedWarnings.cpp
  test/Sema/address_spaces.c
  test/Sema/block-literal.c
  test/Sema/fallthrough-attr.c
  test/SemaCXX/switch-implicit-fallthrough.cpp
  test/SemaCXX/warn-unused-label-error.cpp

Index: test/SemaCXX/warn-unused-label-error.cpp
===
--- test/SemaCXX/warn-unused-label-error.cpp
+++ test/SemaCXX/warn-unused-label-error.cpp
@@ -18,9 +18,9 @@
   }
 
   void h() {
-D: // expected-warning {{unused label 'D'}}
+D:
   #pragma weak unused_local_static
-  __attribute__((unused))  // expected-warning {{declaration does not declare anything}}
+  __attribute__((unused))  // expected-error {{'unused' attribute cannot be applied to a statement}}
   ;
   }
 }
Index: test/SemaCXX/switch-implicit-fallthrough.cpp
===
--- test/SemaCXX/switch-implicit-fallthrough.cpp
+++ test/SemaCXX/switch-implicit-fallthrough.cpp
@@ -329,3 +329,15 @@
   }
   return n;
 }
+
+int fallthrough_attribute_spelling(int n) {
+  switch (n) {
+  case 0:
+n++;
+__attribute__ ((fallthrough));
+  case 1:
+n++;
+break;
+  }
+  return n;
+}
Index: test/Sema/fallthrough-attr.c
===
--- test/Sema/fallthrough-attr.c
+++ test/Sema/fallthrough-attr.c
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fsyntax-only -std=gnu89 -verify -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -std=gnu99 -verify -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -std=c99 -verify -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -std=c11 -verify -Wimplicit-fallthrough %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2x -DC2X -verify -Wimplicit-fallthrough %s
+
+int fallthrough_attribute_spelling(int n) {
+  switch (n) {
+  case 0:
+n++;
+  case 1: 
+#if defined(C2X)
+// expected-warning@-2{{unannotated fall-through between switch labels}} expected-note@-2{{insert '[[fallthrough]];' to silence this warning}} expected-note@-2{{insert 'break;' to avoid fall-through}}
+#else
+// expected-warning@-4{{unannotated fall-through between switch labels}} expected-note@-4{{insert '__attribute__ ((fallthrough));' to silence this warning}} expected-note@-4{{insert 'break;' to avoid fall-through}}
+#endif
+n++;
+__attribute__ ((fallthrough));
+  case 2:
+n++;
+break;
+  }
+  return n;
+}
Index: test/Sema/block-literal.c
===
--- test/Sema/block-literal.c
+++ test/Sema/block-literal.c
@@ -41,8 +41,8 @@
 
   foo:
   takeblock(^{ x = 4; });  // expected-error {{variable is not assignable (missing __block type specifier)}}
-  __block y = 7;// expected-warning {{type specifier missing, defaults to 'int'}}
-  takeblock(^{ y = 8; });
+  __block y = 7;// expected-error {{use of undeclared identifier 'y'}}
+  takeblock(^{ y = 8; }); // expected-error {{use of undeclared identifier 'y'}}
 }
 
 
Index: test/Sema/address_spaces.c
===
--- test/Sema/address_spaces.c
+++ test/Sema/address_spaces.c
@@ -9,7 +9,7 @@
 void foo(_AS3 float *a,
  _AS1 float b) // expected-error {{parameter may not be qualified with an address space}}
 {
-  _AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}}
+  _AS2 *x;// expected-error {{use of undeclared identifier 'x'}}
   _AS1 float * _AS2 *B;
 
   int _AS1 _AS2 *Y;   // expected-error {{multiple address spaces specified for type}}
Index: lib/Sema/AnalysisBasedWarnings.cpp
===
--- lib/Sema/AnalysisBasedWarnings.cpp
+++ lib/Sema/AnalysisBasedWarnings.cpp
@@ -1215,7 +1215,7 @@
 tok::r_square, tok::r_square
   };
 
-  bool PreferClangAttr = !PP.getLangOpts().CPlusPlus17;
+  bool PreferClangAttr = !PP.getLangOpts().CPlusPlus17 && !PP.getLangOpts().C2x;
 
   StringRef MacroName;
   if (PreferClangAttr)
@@ -1224,24 +1224,19 @@
 MacroName = PP.getLastMacroWithSpelling(Loc, FallthroughTokens);
   if (MacroName.empty() && !PreferClangAttr)
 MacroName = PP.getLastMacroWithSpelling(Loc, ClangFallthroughTokens);
-  if (MacroName.empty())
-MacroName = PreferClangAttr ? "[[clang::fallthrough]]" : "[[fallthrough]]";
+  if (MacroName.empty()) {
+if (!PreferClangAttr)
+  MacroName = "[[fallthrough]]";
+else if (PP.getLangOpts().CPlusPlus)
+  MacroName = "[[clang::fallthrough]]";
+else
+  MacroName = "__attribute__ ((fallthrough))";
+  }
   return MacroName;
 }
 
 static void DiagnoseSwitchLabelsFallthrough(Sema &S, AnalysisDeclContext &AC,
 bool PerFunction) {
-  // On

[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

2019-06-13 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 marked 2 inline comments as done.
xbolva00 added inline comments.



Comment at: test/Sema/address_spaces.c:12
 {
-  _AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}}
+  _AS2 *x;// expected-error {{use of undeclared identifier 'x'}}
   _AS1 float * _AS2 *B;

I think this is an acceptable change..



Comment at: test/SemaCXX/warn-unused-label-error.cpp:23
   #pragma weak unused_local_static
-  __attribute__((unused))  // expected-warning {{declaration does not 
declare anything}}
+  __attribute__((unused))  // expected-error {{'unused' attribute cannot 
be applied to a statement}}
   ;

I think this is an improvement.


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

https://reviews.llvm.org/D63260



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


[PATCH] D62944: [Driver] Fix wchar_t and wint_t definitions on Solaris

2019-06-13 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

For format-strings.c, I'm not really happy suggesting `#if defined(__sun) && 
!defined(__LP64__)`, but I don't think the alternative is better.  We could 
restrict the test so it doesn't run using a Solaris target triple, but we 
actually want coverage here: the difference in wint_t affects the semantics of 
"%lc", so we want some coverage of that path.

The other changes look okay.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62944



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


[PATCH] D63283: PR42182: Allow thread-local to use __cxa_thread_atexit when -fno-use-cxx-atexit is used

2019-06-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:2370
+  if (CGM.getCodeGenOpts().CXAAtExit || D.getTLSKind())
 return emitGlobalDtorWithCXAAtExit(CGF, dtor, addr, D.getTLSKind());
 

It's fine to match the GCC behavior, and it's even somewhat explicable.  Could 
you update the comment to explain, first of all, that this path handles both 
`__cxa_atexit` and `__cxa_thread_atexit`, and secondly that the option is only 
meant to control the former?


Repository:
  rC Clang

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

https://reviews.llvm.org/D63283



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


[PATCH] D63288: [clang-tidy] Generalize TransformerClangTidyCheck to take a rule generator.

2019-06-13 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel marked an inline comment as done.
ymandel added a comment.

Thanks for the review!




Comment at: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp:33
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), Rule(MakeRule(getLangOpts(), Options)) {
+  assert(llvm::all_of(Rule.Cases, [](const RewriteRule::Case &C) {

gribozavr wrote:
> Can we dispatch to the other constructor?
I think not, but please correct me if I'm wrong (and clearly I should add a 
comment explaining this): in order to get meaningful results from `getLangOpts` 
and `Options`, we need the `ClangTidyCheck()` constructor to have been called. 
If we were to dispatch, it would look like:
```
 : TransformerClangTidyCheck(MakeRule(getLangOpts(), Options), Name, Context) {}
```

which, if I understand correctly, means that `MakeRule` will access that data 
_before_ the check object is properly initialized.

That said, I can factor out the assertion into a method to avoid the 
redundancy.  WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63288



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


[PATCH] D62914: [Sema] Fix diagnostic for addr spaces in reference binding

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

I like this wording of the diagnostic better in general.  Could you make the 
diagnostic change in a separate patch and then fix the address-space problem?  
Both patches are approved.


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

https://reviews.llvm.org/D62914



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


[PATCH] D63283: PR42182: Allow thread-local to use __cxa_thread_atexit when -fno-use-cxx-atexit is used

2019-06-13 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 204587.
erichkeane marked an inline comment as done.
erichkeane added a comment.

Update the comment as requested by @rjmccall


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

https://reviews.llvm.org/D63283

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp


Index: clang/test/CodeGenCXX/cxx11-thread-local.cpp
===
--- clang/test/CodeGenCXX/cxx11-thread-local.cpp
+++ clang/test/CodeGenCXX/cxx11-thread-local.cpp
@@ -4,6 +4,12 @@
 // RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK 
--check-prefix=LINUX %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-apple-darwin12 
| FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
 
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple 
x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 
-disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck 
--check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -femulated-tls -emit-llvm %s 
-o - \
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK 
--check-prefix=LINUX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple 
x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
+
 int f();
 int g();
 
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2270,6 +2270,8 @@
 static void emitGlobalDtorWithCXAAtExit(CodeGenFunction &CGF,
 llvm::FunctionCallee dtor,
 llvm::Constant *addr, bool TLS) {
+  assert((TLS || CGF.getTypes().getCodeGenOpts().CXAAtExit) &&
+ "__cxa_atexit is disabled");
   const char *Name = "__cxa_atexit";
   if (TLS) {
 const llvm::Triple &T = CGF.getTarget().getTriple();
@@ -2363,13 +2365,13 @@
   if (D.isNoDestroy(CGM.getContext()))
 return;
 
-  // Use __cxa_atexit if available.
-  if (CGM.getCodeGenOpts().CXAAtExit)
+  // emitGlobalDtorWithCXAAtExit will emit a call to either __cxa_thread_atexit
+  // or __cxa_atexit depending on whether this VarDecl is a thread-local 
storage
+  // or not. CXAAtExit controls only __cxa_atexit, so use it if it is enabled.
+  // We can always use __cxa_thread_atexit.
+  if (CGM.getCodeGenOpts().CXAAtExit || D.getTLSKind())
 return emitGlobalDtorWithCXAAtExit(CGF, dtor, addr, D.getTLSKind());
 
-  if (D.getTLSKind())
-CGM.ErrorUnsupported(&D, "non-trivial TLS destruction");
-
   // In Apple kexts, we want to add a global destructor entry.
   // FIXME: shouldn't this be guarded by some variable?
   if (CGM.getLangOpts().AppleKext) {


Index: clang/test/CodeGenCXX/cxx11-thread-local.cpp
===
--- clang/test/CodeGenCXX/cxx11-thread-local.cpp
+++ clang/test/CodeGenCXX/cxx11-thread-local.cpp
@@ -4,6 +4,12 @@
 // RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
 
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 -disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -femulated-tls -emit-llvm %s -o - \
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
+
 int f();
 int g();
 
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2270,6 +2270,8 @@
 static void emitGlobalDtorWithCXAAtExit(CodeGenFunction &CGF,
 llvm::FunctionCallee dtor,
 llvm::Constant *addr, bool TLS) {
+  assert((TLS || CGF.getTypes().getCodeGenOpts().CXAAtExit) &&
+ "__cxa_atexit is disabled");
   const char *Name = "__cxa_atexit";
   if (TLS) {
 const llvm::Triple &T = CGF.getTarget().getTriple();
@@ -2363,13 +2365,13 @@
   if (D.isNoDestroy(CGM.getContext()))
 return;
 
-  // Use __cxa_atexit if available.
-  if (CGM.getCodeGenOpts()

[PATCH] D62825: [C++2a] Add __builtin_bit_cast, used to implement std::bit_cast

2019-06-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In what sense is the bit-pattern of a null pointer indeterminate?  It's 
implementation-specified, but the compiler is certainly required to be able to 
produce that value during the constant initialization phase.  If the language 
committee wants to make this non-constant out of some sort of portability 
concern, that's its business, but it's certainly implementable even if the 
target has non-zero null pointers or even different null pointer patterns for 
different types (though of course `nullptr_t` uses `void*`'s pattern).


Repository:
  rC Clang

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

https://reviews.llvm.org/D62825



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


r363287 - [clang][NewPM] Fix broken -O0 test from missing assumptions

2019-06-13 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Thu Jun 13 11:18:40 2019
New Revision: 363287

URL: http://llvm.org/viewvc/llvm-project?rev=363287&view=rev
Log:
[clang][NewPM] Fix broken -O0 test from missing assumptions

Add an AssumptionCache callback to the InlineFuntionInfo used for the
AlwaysInlinerPass to match codegen of the AlwaysInlinerLegacyPass to generate
llvm.assume. This fixes CodeGen/builtin-movdir.c when new PM is enabled by
default.

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

Modified:
cfe/trunk/test/CodeGen/builtin-movdir.c
cfe/trunk/test/CodeGen/lto-newpm-pipeline.c

Modified: cfe/trunk/test/CodeGen/builtin-movdir.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-movdir.c?rev=363287&r1=363286&r2=363287&view=diff
==
--- cfe/trunk/test/CodeGen/builtin-movdir.c (original)
+++ cfe/trunk/test/CodeGen/builtin-movdir.c Thu Jun 13 11:18:40 2019
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 -ffreestanding -Wall -pedantic -triple 
x86_64-unknown-unknown -target-feature +movdiri -target-feature +movdir64b %s 
-emit-llvm -o - | FileCheck %s --check-prefix=X86_64 --check-prefix=CHECK
-// RUN: %clang_cc1 -ffreestanding -Wall -pedantic -triple i386-unknown-unknown 
-target-feature +movdiri -target-feature +movdir64b %s -emit-llvm -o - | 
FileCheck %s --check-prefix=X86 --check-prefix=CHECK
+// RUN: %clang_cc1 -ffreestanding -Wall -pedantic 
-fno-experimental-new-pass-manager -triple x86_64-unknown-unknown 
-target-feature +movdiri -target-feature +movdir64b %s -emit-llvm -o - | 
FileCheck %s --check-prefix=X86_64 --check-prefix=CHECK
+// RUN: %clang_cc1 -ffreestanding -Wall -pedantic 
-fno-experimental-new-pass-manager -triple i386-unknown-unknown -target-feature 
+movdiri -target-feature +movdir64b %s -emit-llvm -o - | FileCheck %s 
--check-prefix=X86 --check-prefix=CHECK
+// RUN: %clang_cc1 -ffreestanding -Wall -pedantic 
-fexperimental-new-pass-manager -triple x86_64-unknown-unknown -target-feature 
+movdiri -target-feature +movdir64b %s -emit-llvm -o - | FileCheck %s 
--check-prefix=X86_64 --check-prefix=CHECK
+// RUN: %clang_cc1 -ffreestanding -Wall -pedantic 
-fexperimental-new-pass-manager -triple i386-unknown-unknown -target-feature 
+movdiri -target-feature +movdir64b %s -emit-llvm -o - | FileCheck %s 
--check-prefix=X86 --check-prefix=CHECK
 
 #include 
 #include 

Modified: cfe/trunk/test/CodeGen/lto-newpm-pipeline.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/lto-newpm-pipeline.c?rev=363287&r1=363286&r2=363287&view=diff
==
--- cfe/trunk/test/CodeGen/lto-newpm-pipeline.c (original)
+++ cfe/trunk/test/CodeGen/lto-newpm-pipeline.c Thu Jun 13 11:18:40 2019
@@ -27,6 +27,7 @@
 
 // CHECK-FULL-O0: Starting llvm::Module pass manager run.
 // CHECK-FULL-O0: Running pass: AlwaysInlinerPass
+// CHECK-FULL-O0-NEXT: Running analysis: InnerAnalysisManagerProxy
 // CHECK-FULL-O0-NEXT: Running pass: CanonicalizeAliasesPass
 // CHECK-FULL-O0-NEXT: Running pass: NameAnonGlobalPass
 // CHECK-FULL-O0-NEXT: Running pass: BitcodeWriterPass
@@ -34,6 +35,7 @@
 
 // CHECK-THIN-O0: Starting llvm::Module pass manager run.
 // CHECK-THIN-O0: Running pass: AlwaysInlinerPass
+// CHECK-THIN-O0-NEXT: Running analysis: InnerAnalysisManagerProxy
 // CHECK-THIN-O0-NEXT: Running pass: CanonicalizeAliasesPass
 // CHECK-THIN-O0-NEXT: Running pass: NameAnonGlobalPass
 // CHECK-THIN-O0-NEXT: Running pass: ThinLTOBitcodeWriterPass


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


[PATCH] D63283: PR42182: Allow thread-local to use __cxa_thread_atexit when -fno-use-cxx-atexit is used

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

Thanks!


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

https://reviews.llvm.org/D63283



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


r363288 - PR42182: Allow thread-local to use __cxa_thread_atexit when

2019-06-13 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Thu Jun 13 11:20:19 2019
New Revision: 363288

URL: http://llvm.org/viewvc/llvm-project?rev=363288&view=rev
Log:
PR42182: Allow thread-local to use __cxa_thread_atexit when
-fno-use-cxx-atexit is used

This matches the GCC behavior, __cxa_thread_atexit should be permissible
even though cxa_atexit is disabled.

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

Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=363288&r1=363287&r2=363288&view=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Thu Jun 13 11:20:19 2019
@@ -2270,6 +2270,8 @@ void ItaniumCXXABI::EmitGuardedInit(Code
 static void emitGlobalDtorWithCXAAtExit(CodeGenFunction &CGF,
 llvm::FunctionCallee dtor,
 llvm::Constant *addr, bool TLS) {
+  assert((TLS || CGF.getTypes().getCodeGenOpts().CXAAtExit) &&
+ "__cxa_atexit is disabled");
   const char *Name = "__cxa_atexit";
   if (TLS) {
 const llvm::Triple &T = CGF.getTarget().getTriple();
@@ -2363,13 +2365,13 @@ void ItaniumCXXABI::registerGlobalDtor(C
   if (D.isNoDestroy(CGM.getContext()))
 return;
 
-  // Use __cxa_atexit if available.
-  if (CGM.getCodeGenOpts().CXAAtExit)
+  // emitGlobalDtorWithCXAAtExit will emit a call to either __cxa_thread_atexit
+  // or __cxa_atexit depending on whether this VarDecl is a thread-local 
storage
+  // or not. CXAAtExit controls only __cxa_atexit, so use it if it is enabled.
+  // We can always use __cxa_thread_atexit.
+  if (CGM.getCodeGenOpts().CXAAtExit || D.getTLSKind())
 return emitGlobalDtorWithCXAAtExit(CGF, dtor, addr, D.getTLSKind());
 
-  if (D.getTLSKind())
-CGM.ErrorUnsupported(&D, "non-trivial TLS destruction");
-
   // In Apple kexts, we want to add a global destructor entry.
   // FIXME: shouldn't this be guarded by some variable?
   if (CGM.getLangOpts().AppleKext) {

Modified: cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp?rev=363288&r1=363287&r2=363288&view=diff
==
--- cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp Thu Jun 13 11:20:19 2019
@@ -4,6 +4,12 @@
 // RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK 
--check-prefix=LINUX %s
 // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple x86_64-apple-darwin12 
| FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
 
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple 
x86_64-linux-gnu | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -O2 
-disable-llvm-passes -o - -triple x86_64-linux-gnu | FileCheck 
--check-prefix=CHECK --check-prefix=LINUX --check-prefix=CHECK-OPT %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -femulated-tls -emit-llvm %s 
-o - \
+// RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK 
--check-prefix=LINUX %s
+// RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple 
x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
+
 int f();
 int g();
 


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


[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

2019-06-13 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: lib/Sema/AnalysisBasedWarnings.cpp:1279
 continue;
-  if (S.getLangOpts().CPlusPlus11) {
+  if (S.getLangOpts().CPlusPlus11 || S.getLangOpts().C99) {
 const Stmt *Term = B->getTerminatorStmt();

xbolva00 wrote:
> nickdesaulniers wrote:
> > Probably should additionally/instead check `S.getLangOpts().GNUMode` (since 
> > these are GNU C style attributes)?  I guess we want these attributes to be 
> > supported in C regardless of `-std=`?
> Good point.
IIUC, we allow GNU C attributes for C regardless of ISO vs GNU C.  What we want 
to express is "if c++11 and newer, or c".

I think this might be better expressed as:

```
if (S.getLangOpts().CPlusPlus11 || (!S.getLangOpts().CPlusPlus && 
!S.getLangOpts().ObjC) {
```

But maybe there's a more canonical way to express "if the language is C." (If 
not, maybe we can consider such a change to `LangOpt` to make this easier, but 
as part of this commit).


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

https://reviews.llvm.org/D63260



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


[PATCH] D63157: C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue conversion applied to a member access or similar not-quite-trivial lvalue expression.

2019-06-13 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith updated this revision to Diff 204589.
rsmith marked 2 inline comments as done.
rsmith added a comment.

Updated comment, fixed typo, added use of `[[clang::lifetimebound]]`.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63157

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Sema/SemaExpr.cpp
  test/CXX/basic/basic.def.odr/p2.cpp
  test/CXX/drs/dr20xx.cpp
  test/CXX/drs/dr21xx.cpp
  test/CXX/drs/dr23xx.cpp
  test/CXX/drs/dr6xx.cpp
  test/CXX/drs/dr7xx.cpp
  test/CodeGenCXX/no-odr-use.cpp
  www/cxx_dr_status.html

Index: www/cxx_dr_status.html
===
--- www/cxx_dr_status.html
+++ www/cxx_dr_status.html
@@ -4219,7 +4219,7 @@
 http://wg21.link/cwg696";>696
 C++11
 Use of block-scope constants in local classes
-Unknown
+Yes
   
   
 http://wg21.link/cwg697";>697
@@ -4315,7 +4315,7 @@
 http://wg21.link/cwg712";>712
 CD3
 Are integer constant operands of a conditional-expression “used?”
-Unknown
+Partial
   
   
 http://wg21.link/cwg713";>713
@@ -12313,7 +12313,7 @@
 http://wg21.link/cwg2083";>2083
 DR
 Incorrect cases of odr-use
-Unknown
+Partial
   
   
 http://wg21.link/cwg2084";>2084
@@ -12433,7 +12433,7 @@
 http://wg21.link/cwg2103";>2103
 DR
 Lvalue-to-rvalue conversion is irrelevant in odr-use of a reference
-Unknown
+Yes
   
   
 http://wg21.link/cwg2104";>2104
@@ -12835,7 +12835,7 @@
 http://wg21.link/cwg2170";>2170
 DR
 Unclear definition of odr-use for arrays
-Unknown
+SVN
   
   
 http://wg21.link/cwg2171";>2171
@@ -13933,7 +13933,7 @@
 http://wg21.link/cwg2353";>2353
 DR
 Potential results of a member access expression for a static data member
-Unknown
+SVN
   
   
 http://wg21.link/cwg2354";>2354
Index: test/CodeGenCXX/no-odr-use.cpp
===
--- /dev/null
+++ test/CodeGenCXX/no-odr-use.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-linux-gnu %s | FileCheck %s
+
+// CHECK: @__const._Z1fi.a = private unnamed_addr constant {{.*}} { i32 1, [2 x i32] [i32 2, i32 3], [3 x i32] [i32 4, i32 5, i32 6] }
+
+struct A { int x, y[2]; int arr[3]; };
+// CHECK-LABEL: define i32 @_Z1fi(
+int f(int i) {
+  // CHECK: call void {{.*}}memcpy{{.*}}({{.*}}, {{.*}} @__const._Z1fi.a
+  constexpr A a = {1, 2, 3, 4, 5, 6};
+
+  // CHECK-LABEL: define {{.*}}@"_ZZ1fiENK3$_0clEiM1Ai"(
+  return [] (int n, int A::*p) {
+// CHECK: br i1
+return (n >= 0
+  // CHECK: getelementptr inbounds [3 x i32], [3 x i32]* getelementptr inbounds ({{.*}} @__const._Z1fi.a, i32 0, i32 2), i64 0, i64 %
+  ? a.arr[n]
+  // CHECK: br i1
+  : (n == -1
+// CHECK: getelementptr inbounds i8, i8* bitcast ({{.*}} @__const._Z1fi.a to i8*), i64 %
+// CHECK: bitcast i8* %{{.*}} to i32*
+// CHECK: load i32
+? a.*p
+// CHECK: getelementptr inbounds [2 x i32], [2 x i32]* getelementptr inbounds ({{.*}} @__const._Z1fi.a, i32 0, i32 1), i64 0, i64 %
+// CHECK: load i32
+: a.y[2 - n]));
+  }(i, &A::x);
+}
Index: test/CXX/drs/dr7xx.cpp
===
--- test/CXX/drs/dr7xx.cpp
+++ test/CXX/drs/dr7xx.cpp
@@ -17,6 +17,42 @@
   }
 }
 
+namespace dr712 { // dr712: partial
+  void use(int);
+  void f() {
+const int a = 0; // expected-note 5{{here}}
+struct X {
+  void g(bool cond) {
+use(a);
+use((a));
+use(cond ? a : a);
+use((cond, a)); // expected-warning 2{{unused}} FIXME: should only warn once
+
+(void)a; // FIXME: expected-error {{declared in enclosing}}
+(void)(a); // FIXME: expected-error {{declared in enclosing}}
+(void)(cond ? a : a); // FIXME: expected-error 2{{declared in enclosing}}
+(void)(cond, a); // FIXME: expected-error {{declared in enclosing}} expected-warning {{unused}}
+  }
+};
+  }
+
+#if __cplusplus >= 201103L
+  void g() {
+struct A { int n; };
+constexpr A a = {0}; // expected-note 2{{here}}
+struct X {
+  void g(bool cond) {
+use(a.n);
+use(a.*&A::n);
+
+(void)a.n; // FIXME: expected-error {{declared in enclosing}}
+(void)(a.*&A::n); // FIXME: expected-error {{declared in enclosing}}
+  }
+};
+  }
+#endif
+}
+
 namespace dr727 { // dr727: partial
   struct A {
 template struct C; // expected-note 6{{here}}
Index: test/CXX/drs/dr6xx.cpp
===
--- test/CXX/drs/dr6xx.cpp
+++ test/CXX/drs/dr6xx.cpp
@@ -1132,3 +1132,20 @@
 template void f(int*); // expected-error {{ambiguous}}
   }
 }
+
+namespace dr696 { // dr696: yes
+  void f(const int*);
+  void g() {
+const int N = 10; // expected-note 1+{{here}}

[PATCH] D63170: [clang][NewPM] Fix broken -O0 test from missing assumptions

2019-06-13 Thread Leonard Chan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363287: [clang][NewPM] Fix broken -O0 test from missing 
assumptions (authored by leonardchan, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D63170?vs=204174&id=204590#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63170

Files:
  cfe/trunk/test/CodeGen/builtin-movdir.c
  cfe/trunk/test/CodeGen/lto-newpm-pipeline.c
  llvm/trunk/lib/Transforms/IPO/AlwaysInliner.cpp


Index: llvm/trunk/lib/Transforms/IPO/AlwaysInliner.cpp
===
--- llvm/trunk/lib/Transforms/IPO/AlwaysInliner.cpp
+++ llvm/trunk/lib/Transforms/IPO/AlwaysInliner.cpp
@@ -31,8 +31,17 @@
 
 #define DEBUG_TYPE "inline"
 
-PreservedAnalyses AlwaysInlinerPass::run(Module &M, ModuleAnalysisManager &) {
-  InlineFunctionInfo IFI;
+PreservedAnalyses AlwaysInlinerPass::run(Module &M,
+ ModuleAnalysisManager &MAM) {
+  // Add inline assumptions during code generation.
+  FunctionAnalysisManager &FAM =
+  MAM.getResult(M).getManager();
+  std::function GetAssumptionCache =
+  [&](Function &F) -> AssumptionCache & {
+return FAM.getResult(F);
+  };
+  InlineFunctionInfo IFI(/*cg=*/nullptr, &GetAssumptionCache);
+
   SmallSetVector Calls;
   bool Changed = false;
   SmallVector InlinedFunctions;
Index: cfe/trunk/test/CodeGen/builtin-movdir.c
===
--- cfe/trunk/test/CodeGen/builtin-movdir.c
+++ cfe/trunk/test/CodeGen/builtin-movdir.c
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 -ffreestanding -Wall -pedantic -triple 
x86_64-unknown-unknown -target-feature +movdiri -target-feature +movdir64b %s 
-emit-llvm -o - | FileCheck %s --check-prefix=X86_64 --check-prefix=CHECK
-// RUN: %clang_cc1 -ffreestanding -Wall -pedantic -triple i386-unknown-unknown 
-target-feature +movdiri -target-feature +movdir64b %s -emit-llvm -o - | 
FileCheck %s --check-prefix=X86 --check-prefix=CHECK
+// RUN: %clang_cc1 -ffreestanding -Wall -pedantic 
-fno-experimental-new-pass-manager -triple x86_64-unknown-unknown 
-target-feature +movdiri -target-feature +movdir64b %s -emit-llvm -o - | 
FileCheck %s --check-prefix=X86_64 --check-prefix=CHECK
+// RUN: %clang_cc1 -ffreestanding -Wall -pedantic 
-fno-experimental-new-pass-manager -triple i386-unknown-unknown -target-feature 
+movdiri -target-feature +movdir64b %s -emit-llvm -o - | FileCheck %s 
--check-prefix=X86 --check-prefix=CHECK
+// RUN: %clang_cc1 -ffreestanding -Wall -pedantic 
-fexperimental-new-pass-manager -triple x86_64-unknown-unknown -target-feature 
+movdiri -target-feature +movdir64b %s -emit-llvm -o - | FileCheck %s 
--check-prefix=X86_64 --check-prefix=CHECK
+// RUN: %clang_cc1 -ffreestanding -Wall -pedantic 
-fexperimental-new-pass-manager -triple i386-unknown-unknown -target-feature 
+movdiri -target-feature +movdir64b %s -emit-llvm -o - | FileCheck %s 
--check-prefix=X86 --check-prefix=CHECK
 
 #include 
 #include 
Index: cfe/trunk/test/CodeGen/lto-newpm-pipeline.c
===
--- cfe/trunk/test/CodeGen/lto-newpm-pipeline.c
+++ cfe/trunk/test/CodeGen/lto-newpm-pipeline.c
@@ -27,6 +27,7 @@
 
 // CHECK-FULL-O0: Starting llvm::Module pass manager run.
 // CHECK-FULL-O0: Running pass: AlwaysInlinerPass
+// CHECK-FULL-O0-NEXT: Running analysis: InnerAnalysisManagerProxy
 // CHECK-FULL-O0-NEXT: Running pass: CanonicalizeAliasesPass
 // CHECK-FULL-O0-NEXT: Running pass: NameAnonGlobalPass
 // CHECK-FULL-O0-NEXT: Running pass: BitcodeWriterPass
@@ -34,6 +35,7 @@
 
 // CHECK-THIN-O0: Starting llvm::Module pass manager run.
 // CHECK-THIN-O0: Running pass: AlwaysInlinerPass
+// CHECK-THIN-O0-NEXT: Running analysis: InnerAnalysisManagerProxy
 // CHECK-THIN-O0-NEXT: Running pass: CanonicalizeAliasesPass
 // CHECK-THIN-O0-NEXT: Running pass: NameAnonGlobalPass
 // CHECK-THIN-O0-NEXT: Running pass: ThinLTOBitcodeWriterPass


Index: llvm/trunk/lib/Transforms/IPO/AlwaysInliner.cpp
===
--- llvm/trunk/lib/Transforms/IPO/AlwaysInliner.cpp
+++ llvm/trunk/lib/Transforms/IPO/AlwaysInliner.cpp
@@ -31,8 +31,17 @@
 
 #define DEBUG_TYPE "inline"
 
-PreservedAnalyses AlwaysInlinerPass::run(Module &M, ModuleAnalysisManager &) {
-  InlineFunctionInfo IFI;
+PreservedAnalyses AlwaysInlinerPass::run(Module &M,
+ ModuleAnalysisManager &MAM) {
+  // Add inline assumptions during code generation.
+  FunctionAnalysisManager &FAM =
+  MAM.getResult(M).getManager();
+  std::function GetAssumptionCache =
+  [&](Function &F) -> AssumptionCache & {
+return FAM.getResult(F);
+  };
+  InlineFunctionInfo IFI(/*cg=*/nullptr, &GetAssumptionCache);
+
   SmallSetVector Calls;
   bool Changed = false;
   SmallVector InlinedFunctions;
Index: cfe/trun

[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

2019-06-13 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

> but as part of this commit

but *not* as part of this commit


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

https://reviews.llvm.org/D63260



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


[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

2019-06-13 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: test/Sema/address_spaces.c:12
 {
-  _AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}}
+  _AS2 *x;// expected-error {{use of undeclared identifier 'x'}}
   _AS1 float * _AS2 *B;

xbolva00 wrote:
> I think this is an acceptable change..
This is scary.  gcc and clang both parse `void f() { __attribute((aligned)) *x; 
}` etc. as a declaration; I don't think we want to change that, even if that 
usage is a bit dubious in modern C.  And it's not clear to me if there are 
other implications here; does this affect the handling of statement/declaration 
ambiguity in C++?


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

https://reviews.llvm.org/D63260



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


[PATCH] D63157: C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue conversion applied to a member access or similar not-quite-trivial lvalue expression.

2019-06-13 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: lib/CodeGen/CGExpr.cpp:1429
+/// for instance if a block or lambda or a member of a local class uses a
+/// const int variable or constexpr variable from an enclosing function.
 CodeGenFunction::ConstantEmission

rjmccall wrote:
> Isn't the old comment correct here?  This is mandatory because of the 
> enclosing-local-scope issues; that might be an "optimization" in the 
> language, but it's not an optimization at the IRGen level because Sema 
> literally is forcing us to do it. 
In the absence of this code, we'd emit the variable as a global constant from 
`EmitDeclRefLValue` in the enclosing-local-scope case (as we now do in the 
more-complex cases), so this should never be necessary for correct code 
generation any more.



Comment at: lib/Sema/SemaExpr.cpp:15808
+namespace {
+// Helper to copy the template arguments from a DeclRefExpr or MemberExpr.
+class CopiedTemplateArgs {

rjmccall wrote:
> This is really cute; I might steal this idea.  That said, it's probably worth 
> explaining the lifetime mechanics here so that non-experts can understand how 
> this works.
Done. I also added a `[[clang::lifetimebound]]` attribute so we'll get a 
warning if this is misused.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63157



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


[PATCH] D63260: [Attr] Support _attribute__ ((fallthrough))

2019-06-13 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: test/Sema/address_spaces.c:12
 {
-  _AS2 *x;// expected-warning {{type specifier missing, defaults to 'int'}}
+  _AS2 *x;// expected-error {{use of undeclared identifier 'x'}}
   _AS1 float * _AS2 *B;

efriedma wrote:
> xbolva00 wrote:
> > I think this is an acceptable change..
> This is scary.  gcc and clang both parse `void f() { __attribute((aligned)) 
> *x; }` etc. as a declaration; I don't think we want to change that, even if 
> that usage is a bit dubious in modern C.  And it's not clear to me if there 
> are other implications here; does this affect the handling of 
> statement/declaration ambiguity in C++?
It's a pointer to implicit int.  Either way, I think the change and the 
comments are polluting this code review, hence the suggestion to submit as a 
separate individual patch.


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

https://reviews.llvm.org/D63260



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


[PATCH] D63290: Unify DependencyFileGenerator class and DependencyCollector interface

2019-06-13 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: Bigcheese, vsapsai, bruno, aganea.
Herald added subscribers: dexonsmith, jkorous.
Herald added a project: clang.

This NFCI patch makes DependencyFileGenerator a DependencyCollector as it was 
intended when DependencyCollector was introduced. The missing PP overrides are 
added to the DependencyCollector as well.

This change will allow `clang-scan-deps` to access the produced dependencies 
without writing them out to `.d` files to disk, so that it will be able collate 
them and report them to the user.


Repository:
  rC Clang

https://reviews.llvm.org/D63290

Files:
  clang/include/clang/Frontend/CompilerInstance.h
  clang/include/clang/Frontend/Utils.h
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/DependencyFile.cpp

Index: clang/lib/Frontend/DependencyFile.cpp
===
--- clang/lib/Frontend/DependencyFile.cpp
+++ clang/lib/Frontend/DependencyFile.cpp
@@ -32,8 +32,10 @@
 struct DepCollectorPPCallbacks : public PPCallbacks {
   DependencyCollector &DepCollector;
   SourceManager &SM;
-  DepCollectorPPCallbacks(DependencyCollector &L, SourceManager &SM)
-  : DepCollector(L), SM(SM) { }
+  DiagnosticsEngine &Diags;
+  DepCollectorPPCallbacks(DependencyCollector &L, SourceManager &SM,
+  DiagnosticsEngine &Diags)
+  : DepCollector(L), SM(SM), Diags(Diags) {}
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
@@ -57,6 +59,16 @@
 /*IsModuleFile*/false, /*IsMissing*/false);
   }
 
+  void FileSkipped(const FileEntry &SkippedFile, const Token &FilenameTok,
+   SrcMgr::CharacteristicKind FileType) override {
+StringRef Filename =
+llvm::sys::path::remove_leading_dotslash(SkippedFile.getName());
+DepCollector.maybeAddDependency(Filename, /*FromModule=*/false,
+/*IsSystem=*/isSystem(FileType),
+/*IsModuleFile=*/false,
+/*IsMissing=*/false);
+  }
+
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange, const FileEntry *File,
@@ -70,9 +82,20 @@
 // Files that actually exist are handled by FileChanged.
   }
 
-  void EndOfMainFile() override {
-DepCollector.finishedMainFile();
+  void HasInclude(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled,
+  const FileEntry *File,
+  SrcMgr::CharacteristicKind FileType) override {
+if (!File)
+  return;
+StringRef Filename =
+llvm::sys::path::remove_leading_dotslash(File->getName());
+DepCollector.maybeAddDependency(Filename, /*FromModule=*/false,
+/*IsSystem=*/isSystem(FileType),
+/*IsModuleFile=*/false,
+/*IsMissing=*/false);
   }
+
+  void EndOfMainFile() override { DepCollector.finishedMainFile(Diags); }
 };
 
 struct DepCollectorMMCallbacks : public ModuleMapCallbacks {
@@ -117,9 +140,16 @@
 void DependencyCollector::maybeAddDependency(StringRef Filename, bool FromModule,
 bool IsSystem, bool IsModuleFile,
 bool IsMissing) {
-  if (Seen.insert(Filename).second &&
-  sawDependency(Filename, FromModule, IsSystem, IsModuleFile, IsMissing))
+  if (sawDependency(Filename, FromModule, IsSystem, IsModuleFile, IsMissing))
+addDependency(Filename);
+}
+
+bool DependencyCollector::addDependency(StringRef Filename) {
+  if (Seen.insert(Filename).second) {
 Dependencies.push_back(Filename);
+return true;
+  }
+  return false;
 }
 
 static bool isSpecialFilename(StringRef Filename) {
@@ -138,8 +168,8 @@
 
 DependencyCollector::~DependencyCollector() { }
 void DependencyCollector::attachToPreprocessor(Preprocessor &PP) {
-  PP.addPPCallbacks(
-  llvm::make_unique(*this, PP.getSourceManager()));
+  PP.addPPCallbacks(llvm::make_unique(
+  *this, PP.getSourceManager(), PP.getDiagnostics()));
   PP.getHeaderSearchInfo().getModuleMap().addModuleMapCallbacks(
   llvm::make_unique(*this));
 }
@@ -147,206 +177,57 @@
   R.addListener(llvm::make_unique(*this));
 }
 
-namespace {
-/// Private implementation for DependencyFileGenerator
-class DFGImpl : public PPCallbacks {
-  std::vector Files;
-  llvm::StringSet<> FilesSet;
-  const Preprocessor *PP;
-  std::string OutputFile;
-  std::vector Targets;
-  bool IncludeSystemHeaders;
-  bool PhonyTarget;
-  bool AddMissingHeaderDeps;
-  bool SeenMissingHeader;
-  bool IncludeModuleFiles;
-  DependencyOutputFormat OutputFormat;
-  unsigned InputFileIndex;
-
-private:
-  bool FileMatchesDepCriteria(const char *Fi

[PATCH] D62825: [C++2a] Add __builtin_bit_cast, used to implement std::bit_cast

2019-06-13 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D62825#1542247 , @rjmccall wrote:

> In what sense is the bit-pattern of a null pointer indeterminate?


The problem is not null pointers, it's `nullptr_t`, which is required to have 
the same size and alignment as `void*` but which comprises only padding bits. 
(Loads of `nullptr_t` are not even permitted to touch memory...).


Repository:
  rC Clang

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

https://reviews.llvm.org/D62825



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


[PATCH] D63157: C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue conversion applied to a member access or similar not-quite-trivial lvalue expression.

2019-06-13 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Minor comment request, then LGTM.




Comment at: lib/CodeGen/CGDecl.cpp:1102
+  // Form a simple per-variable LRU cache of these values in case we find we
+  // want to reuse them.
+  llvm::GlobalVariable *&CacheEntry = InitializerConstants[&D];

I don't think this cache is LRU in any meaningful sense; it just grows 
unbounded.  There's this thing about requiring the initializer to match, but 
that's not LRU.



Comment at: lib/CodeGen/CGExpr.cpp:1429
+/// for instance if a block or lambda or a member of a local class uses a
+/// const int variable or constexpr variable from an enclosing function.
 CodeGenFunction::ConstantEmission

rsmith wrote:
> rjmccall wrote:
> > Isn't the old comment correct here?  This is mandatory because of the 
> > enclosing-local-scope issues; that might be an "optimization" in the 
> > language, but it's not an optimization at the IRGen level because Sema 
> > literally is forcing us to do it. 
> In the absence of this code, we'd emit the variable as a global constant from 
> `EmitDeclRefLValue` in the enclosing-local-scope case (as we now do in the 
> more-complex cases), so this should never be necessary for correct code 
> generation any more.
Hmm, alright.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63157



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


  1   2   >