r368128 - [RISCV] Remove duplicated logic when determining the target ABI

2019-08-07 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Wed Aug  7 00:08:00 2019
New Revision: 368128

URL: http://llvm.org/viewvc/llvm-project?rev=368128&view=rev
Log:
[RISCV] Remove duplicated logic when determining the target ABI

We were calculating twice ilp32/lp64. Do this in one place instead.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp?rev=368128&r1=368127&r2=368128&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp Wed Aug  7 00:08:00 2019
@@ -372,8 +372,14 @@ void riscv::getRISCVTargetFeatures(const
 }
 
 StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {
-  if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
+  assert((Triple.getArch() == llvm::Triple::riscv32 ||
+  Triple.getArch() == llvm::Triple::riscv64) &&
+ "Unexpected triple");
+
+  if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
 return A->getValue();
 
+  // FIXME: currently defaults to the soft-float ABIs. Will need to be
+  // expanded to select ilp32f, ilp32d, lp64f, lp64d when appropriate.
   return Triple.getArch() == llvm::Triple::riscv32 ? "ilp32" : "lp64";
 }

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=368128&r1=368127&r2=368128&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Wed Aug  7 00:08:00 2019
@@ -1848,21 +1848,11 @@ void Clang::AddPPCTargetArgs(const ArgLi
 
 void Clang::AddRISCVTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
-  // FIXME: currently defaults to the soft-float ABIs. Will need to be
-  // expanded to select ilp32f, ilp32d, lp64f, lp64d when appropriate.
-  const char *ABIName = nullptr;
   const llvm::Triple &Triple = getToolChain().getTriple();
-  if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
-ABIName = A->getValue();
-  else if (Triple.getArch() == llvm::Triple::riscv32)
-ABIName = "ilp32";
-  else if (Triple.getArch() == llvm::Triple::riscv64)
-ABIName = "lp64";
-  else
-llvm_unreachable("Unexpected triple!");
+  StringRef ABIName = riscv::getRISCVABI(Args, Triple);
 
   CmdArgs.push_back("-target-abi");
-  CmdArgs.push_back(ABIName);
+  CmdArgs.push_back(ABIName.data());
 }
 
 void Clang::AddSparcTargetArgs(const ArgList &Args,


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


[PATCH] D48357: [RISCV] Remove duplicated logic when determining the target ABI

2019-08-07 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 added a comment.

Thanks @lenary ! I will commit this shortly.


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

https://reviews.llvm.org/D48357



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


[PATCH] D48357: [RISCV] Remove duplicated logic when determining the target ABI

2019-08-07 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368128: [RISCV] Remove duplicated logic when determining the 
target ABI (authored by rogfer01, committed by ).
Herald added subscribers: llvm-commits, jrtc27.
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D48357?vs=212970&id=213804#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D48357

Files:
  cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp


Index: cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -372,8 +372,14 @@
 }
 
 StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {
-  if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
+  assert((Triple.getArch() == llvm::Triple::riscv32 ||
+  Triple.getArch() == llvm::Triple::riscv64) &&
+ "Unexpected triple");
+
+  if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
 return A->getValue();
 
+  // FIXME: currently defaults to the soft-float ABIs. Will need to be
+  // expanded to select ilp32f, ilp32d, lp64f, lp64d when appropriate.
   return Triple.getArch() == llvm::Triple::riscv32 ? "ilp32" : "lp64";
 }
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -1848,21 +1848,11 @@
 
 void Clang::AddRISCVTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
-  // FIXME: currently defaults to the soft-float ABIs. Will need to be
-  // expanded to select ilp32f, ilp32d, lp64f, lp64d when appropriate.
-  const char *ABIName = nullptr;
   const llvm::Triple &Triple = getToolChain().getTriple();
-  if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
-ABIName = A->getValue();
-  else if (Triple.getArch() == llvm::Triple::riscv32)
-ABIName = "ilp32";
-  else if (Triple.getArch() == llvm::Triple::riscv64)
-ABIName = "lp64";
-  else
-llvm_unreachable("Unexpected triple!");
+  StringRef ABIName = riscv::getRISCVABI(Args, Triple);
 
   CmdArgs.push_back("-target-abi");
-  CmdArgs.push_back(ABIName);
+  CmdArgs.push_back(ABIName.data());
 }
 
 void Clang::AddSparcTargetArgs(const ArgList &Args,


Index: cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -372,8 +372,14 @@
 }
 
 StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {
-  if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
+  assert((Triple.getArch() == llvm::Triple::riscv32 ||
+  Triple.getArch() == llvm::Triple::riscv64) &&
+ "Unexpected triple");
+
+  if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
 return A->getValue();
 
+  // FIXME: currently defaults to the soft-float ABIs. Will need to be
+  // expanded to select ilp32f, ilp32d, lp64f, lp64d when appropriate.
   return Triple.getArch() == llvm::Triple::riscv32 ? "ilp32" : "lp64";
 }
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -1848,21 +1848,11 @@
 
 void Clang::AddRISCVTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
-  // FIXME: currently defaults to the soft-float ABIs. Will need to be
-  // expanded to select ilp32f, ilp32d, lp64f, lp64d when appropriate.
-  const char *ABIName = nullptr;
   const llvm::Triple &Triple = getToolChain().getTriple();
-  if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
-ABIName = A->getValue();
-  else if (Triple.getArch() == llvm::Triple::riscv32)
-ABIName = "ilp32";
-  else if (Triple.getArch() == llvm::Triple::riscv64)
-ABIName = "lp64";
-  else
-llvm_unreachable("Unexpected triple!");
+  StringRef ABIName = riscv::getRISCVABI(Args, Triple);
 
   CmdArgs.push_back("-target-abi");
-  CmdArgs.push_back(ABIName);
+  CmdArgs.push_back(ABIName.data());
 }
 
 void Clang::AddSparcTargetArgs(const ArgList &Args,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65776: [Clang] Pragma vectorize_predicate implies vectorize

2019-08-07 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

> I do not know whether/how "setting a transformation option implicitly enables 
> the transformation" should be implemented, maybe we should discuss this.

Yep, agreed. I've sent a mail to the dev list:
http://lists.llvm.org/pipermail/cfe-dev/2019-August/063054.html


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

https://reviews.llvm.org/D65776



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


[PATCH] D65833: [Tooling] Expose ExecutorConcurrency option.

2019-08-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Only hesitation is that AllTUsExecution is one executor of (potentially) many, 
so this is a weird place for a common flag.

However it's already "global" in the sense that --help will show it, so we may 
as well reuse it.
Maybe it should be moved to another file at some point.


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

https://reviews.llvm.org/D65833



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


r368131 - Re-submit r367649: Improve raw_ostream so that you can "write" colors using operator<

2019-08-07 Thread Rui Ueyama via cfe-commits
Author: ruiu
Date: Wed Aug  7 01:08:17 2019
New Revision: 368131

URL: http://llvm.org/viewvc/llvm-project?rev=368131&view=rev
Log:
Re-submit r367649: Improve raw_ostream so that you can "write" colors using 
operator<<

The original patch broke buildbots, perhaps because it changed the
default setting whether colors are enabled or not.

Modified:
cfe/trunk/tools/diagtool/TreeView.cpp

Modified: cfe/trunk/tools/diagtool/TreeView.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/diagtool/TreeView.cpp?rev=368131&r1=368130&r2=368131&view=diff
==
--- cfe/trunk/tools/diagtool/TreeView.cpp (original)
+++ cfe/trunk/tools/diagtool/TreeView.cpp Wed Aug  7 01:08:17 2019
@@ -37,7 +37,8 @@ public:
 
   void setColor(llvm::raw_ostream::Colors Color) {
 if (ShowColors)
-  out << llvm::sys::Process::OutputColor(Color, false, false);
+  out << llvm::sys::Process::OutputColor(static_cast(Color), false,
+ false);
   }
 
   void resetColor() {


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


[PATCH] D65510: [clangd] Fix implicit template instatiations appearing as topLevelDecls.

2019-08-07 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom added inline comments.



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:144
+  EXPECT_THAT(AST.getLocalTopLevelDecls(),
+  ElementsAre(DeclNamed("f"), DeclNamed("f"), DeclNamed("f"),
+  DeclNamed("V"), DeclNamed("V"), DeclNamed("foo"),

ilya-biryukov wrote:
> Is there a way to check we are seeing the explicit instantiations? (e.g. by 
> looking at template arguments?)
> 
> It's not clear whether multiple `DeclNamed("foo")` refer to the decls we 
> expect.
Well in this case all the expressions in the top level should be in 
topLevelDecls so unless say `void f(T) {}` somehow starts duplicating while 
`void f(bool)` disappears from topLevelDecls they should all be visible.
I could add a gtest matcher that also checks the types but I think that would 
become a pretty large matcher (would have to handle FunctionDecls with template 
arguments, VarDecls, TemplateClassSpecializationDecls etc.) and I'm not sure it 
would really add anything to the tests.

A thing we  we could do is shuffle the order of the decls in the test so we 
never have two decls of the same name after each other (because the matcher 
cares about the order of the elements). Which should give us pretty high 
confidence we are getting the correct decls... Or maybe I'm misunderstanding 
you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65510



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


[PATCH] D65510: [clangd] Fix implicit template instatiations appearing as topLevelDecls.

2019-08-07 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 213808.
jvikstrom marked 4 inline comments as done.
jvikstrom added a comment.

Added more ways to specialize/instantiate templates to test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65510

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/ClangdUnit.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -249,6 +249,12 @@
 
   template
   void $Function[[foo]]($TemplateParameter[[T]] ...);
+)cpp",
+R"cpp(
+  template 
+  struct $Class[[Tmpl]] {$TemplateParameter[[T]] $Field[[x]] = 0;};
+  extern template struct $Class[[Tmpl]];
+  template struct $Class[[Tmpl]];
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
@@ -21,6 +21,8 @@
 namespace {
 
 using ::testing::ElementsAre;
+using ::testing::ElementsAreArray;
+
 
 TEST(ClangdUnitTest, GetBeginningOfIdentifier) {
   std::string Preamble = R"cpp(
@@ -103,6 +105,57 @@
   EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main")));
 }
 
+TEST(ClangdUnitTest, DoesNotGetImplicitTemplateTopDecls) {
+  TestTU TU;
+  TU.Code = R"cpp(
+template
+void f(T) {}
+void s() {
+  f(10UL);
+}
+  )cpp";
+
+  auto AST = TU.build();
+  EXPECT_THAT(AST.getLocalTopLevelDecls(),
+  ElementsAre(DeclNamed("f"), DeclNamed("s")));
+}
+
+TEST(ClangdUnitTest,
+ GetsExplicitInstantiationAndSpecializationTemplateTopDecls) {
+  TestTU TU;
+  TU.Code = R"cpp(
+template 
+void f(T) {}
+template<>
+void f(bool);
+template void f(double);
+
+template 
+struct V {};
+template
+struct V {};
+template <>
+struct V {};
+
+template
+T foo = T(10);
+int i = foo;
+double d = foo;
+template 
+int foo = 0;
+template <>
+int foo = 0;
+  )cpp";
+
+  auto AST = TU.build();
+  EXPECT_THAT(
+  AST.getLocalTopLevelDecls(),
+  ElementsAreArray({DeclNamed("f"), DeclNamed("f"), DeclNamed("f"),
+DeclNamed("V"), DeclNamed("V"), DeclNamed("V"),
+DeclNamed("foo"), DeclNamed("i"), DeclNamed("d"),
+DeclNamed("foo"), DeclNamed("foo")}));
+}
+
 TEST(ClangdUnitTest, TokensAfterPreamble) {
   TestTU TU;
   TU.AdditionalFiles["foo.h"] = R"(
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -1674,13 +1674,6 @@
   }
 };
 
-template  bool isExplicitTemplateSpecialization(const NamedDecl &ND) {
-  if (const auto *TD = dyn_cast(&ND))
-if (TD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
-  return true;
-  return false;
-}
-
 } // namespace
 
 clang::CodeCompleteOptions CodeCompleteOptions::getClangCompleteOpts() const {
@@ -1783,9 +1776,7 @@
   };
   // We only complete symbol's name, which is the same as the name of the
   // *primary* template in case of template specializations.
-  if (isExplicitTemplateSpecialization(ND) ||
-  isExplicitTemplateSpecialization(ND) ||
-  isExplicitTemplateSpecialization(ND))
+  if (isExplicitTemplateSpecialization(&ND))
 return false;
 
   if (InTopLevelScope(ND))
Index: clang-tools-extra/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/clangd/ClangdUnit.cpp
+++ clang-tools-extra/clangd/ClangdUnit.cpp
@@ -9,6 +9,7 @@
 #include "ClangdUnit.h"
 #include "../clang-tidy/ClangTidyDiagnosticConsumer.h"
 #include "../clang-tidy/ClangTidyModuleRegistry.h"
+#include "AST.h"
 #include "Compiler.h"
 #include "Diagnostics.h"
 #include "Headers.h"
@@ -19,8 +20,11 @@
 #include "index/CanonicalIncludes.h"
 #include "index/Index.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
@@ -70,6 +74,9 @@
   auto &SM = D->getASTContext().getSourceManager();
   if (!isInsideM

r368132 - Remove inclusion of a private gmock header from a test

2019-08-07 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Wed Aug  7 01:16:29 2019
New Revision: 368132

URL: http://llvm.org/viewvc/llvm-project?rev=368132&view=rev
Log:
Remove inclusion of a private gmock header from a test

Modified:
cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp

Modified: cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp?rev=368132&r1=368131&r2=368132&view=diff
==
--- cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp (original)
+++ cfe/trunk/unittests/AST/RecursiveASTVisitorTest.cpp Wed Aug  7 01:16:29 2019
@@ -14,7 +14,6 @@
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/STLExtras.h"
-#include "gmock/gmock-generated-matchers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 


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


[PATCH] D65738: [clangd] Added a TextMate theme parser that updates when the current theme changes.

2019-08-07 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.

mostly good, please update the patch description.




Comment at: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts:6
+
+interface TokenColorRule {
+  // Scope is the TextMate scope for this rule.

the interface also needs a documentation.



Comment at: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts:7
+interface TokenColorRule {
+  // Scope is the TextMate scope for this rule.
+  scope: string;

maybe: `// A TextMate scope that specifies the context of the token, e.g. 
"entity.name.function.cpp"`






Comment at: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts:9
+  scope: string;
+  // textColor is the color tokens of this scope should have.
+  textColor: string;

I know the current name was my suggestion, but rethinking the name here, I 
think it'd be better to align with the name used by vscode (to avoid 
confusion), just use `foreground`.



Comment at: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts:13
+
+// Gets a TextMate theme and all its included themes by its name.
+function loadTheme(themeName: string): Promise {

just `// Get all token color rules provided by the theme`



Comment at: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts:34
+/**
+ * Recursively parse the TM theme at fullPath. If there are multiple TM scopes
+ * of the same name in the include chain only the earliest entry of the scope 
is

nit: I think there is no need to explicitly mention the `Recursively`.

we are using `TextMate` and `TM` to refer the same thing in the source file, 
could we use a consistent way (just use `TextMate`)?



Comment at: 
clang-tools-extra/clangd/clients/clangd-vscode/test/assets/firstIncludedTheme.jsonc:3
+// Some comment
+"include": "secondIncludedTheme.jsonc",
+"tokenColors": [

jvikstrom wrote:
> hokein wrote:
> > nit: any reason use `jsonc` not `json`?
> > 
> By default vscode will bind .json files to normal json files which don't 
> allow comments. So if you'd try to run the tests without having set .json to 
> bind to json with comments than it will be a "compile error" because of 
> vscode not allowing comments in .json.
>  
thanks for the explanations, fair enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65738



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


[PATCH] D65849: [unittests] Mark private gmock headers with IWYU pragmas. NFC

2019-08-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: gribozavr.
Herald added subscribers: llvm-commits, kadircet.
Herald added a project: LLVM.

To prevent clangd from adding #include of those headers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65849

Files:
  llvm/utils/unittest/googlemock/include/gmock/gmock-actions.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-cardinalities.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-generated-actions.h
  
llvm/utils/unittest/googlemock/include/gmock/gmock-generated-function-mockers.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-generated-matchers.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-generated-nice-strict.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-matchers.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-more-actions.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-more-matchers.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-spec-builders.h
  
llvm/utils/unittest/googlemock/include/gmock/internal/gmock-generated-internal-utils.h
  llvm/utils/unittest/googlemock/include/gmock/internal/gmock-internal-utils.h
  llvm/utils/unittest/googlemock/include/gmock/internal/gmock-port.h

Index: llvm/utils/unittest/googlemock/include/gmock/internal/gmock-port.h
===
--- llvm/utils/unittest/googlemock/include/gmock/internal/gmock-port.h
+++ llvm/utils/unittest/googlemock/include/gmock/internal/gmock-port.h
@@ -36,6 +36,8 @@
 // end with _ are part of Google Mock's public API and can be used by
 // code outside Google Mock.
 
+// IWYU pragma: private, include "gmock/gmock.h"
+
 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_
 
Index: llvm/utils/unittest/googlemock/include/gmock/internal/gmock-internal-utils.h
===
--- llvm/utils/unittest/googlemock/include/gmock/internal/gmock-internal-utils.h
+++ llvm/utils/unittest/googlemock/include/gmock/internal/gmock-internal-utils.h
@@ -35,6 +35,8 @@
 // Mock.  They are subject to change without notice, so please DO NOT
 // USE THEM IN USER CODE.
 
+// IWYU pragma: private, include "gmock/gmock.h"
+
 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_
 
Index: llvm/utils/unittest/googlemock/include/gmock/internal/gmock-generated-internal-utils.h
===
--- llvm/utils/unittest/googlemock/include/gmock/internal/gmock-generated-internal-utils.h
+++ llvm/utils/unittest/googlemock/include/gmock/internal/gmock-generated-internal-utils.h
@@ -38,6 +38,8 @@
 // This file contains template meta-programming utility classes needed
 // for implementing Google Mock.
 
+// IWYU pragma: private, include "gmock/gmock.h"
+
 #ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
 #define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_GENERATED_INTERNAL_UTILS_H_
 
Index: llvm/utils/unittest/googlemock/include/gmock/gmock-spec-builders.h
===
--- llvm/utils/unittest/googlemock/include/gmock/gmock-spec-builders.h
+++ llvm/utils/unittest/googlemock/include/gmock/gmock-spec-builders.h
@@ -57,6 +57,8 @@
 // where all clauses are optional, and .InSequence()/.After()/
 // .WillOnce() can appear any number of times.
 
+// IWYU pragma: private, include "gmock/gmock.h"
+
 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
 #define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
 
Index: llvm/utils/unittest/googlemock/include/gmock/gmock-more-matchers.h
===
--- llvm/utils/unittest/googlemock/include/gmock/gmock-more-matchers.h
+++ llvm/utils/unittest/googlemock/include/gmock/gmock-more-matchers.h
@@ -36,6 +36,8 @@
 // Note that tests are implemented in gmock-matchers_test.cc rather than
 // gmock-more-matchers-test.cc.
 
+// IWYU pragma: private, include "gmock/gmock.h"
+
 #ifndef GMOCK_GMOCK_MORE_MATCHERS_H_
 #define GMOCK_GMOCK_MORE_MATCHERS_H_
 
Index: llvm/utils/unittest/googlemock/include/gmock/gmock-more-actions.h
===
--- llvm/utils/unittest/googlemock/include/gmock/gmock-more-actions.h
+++ llvm/utils/unittest/googlemock/include/gmock/gmock-more-actions.h
@@ -33,6 +33,8 @@
 //
 // This file implements some actions that depend on gmock-generated-actions.h.
 
+// IWYU pragma: private, include "gmock/gmock.h"
+
 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
 #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
 
Index: llvm/utils/unittest/googlemock/include/gmock/gmock-matchers.h
===
--- llvm/utils/unittest/googlemock/include/gmock/gmock-matchers.h
+++ llvm/utils/unittest/googlemock/include/gmock/gmo

Re: [clang-tools-extra] r368019 - [clangd] Compute scopes eagerly in IncludeFixer

2019-08-07 Thread Hans Wennborg via cfe-commits
Yes, merged in r368133.

On Tue, Aug 6, 2019 at 4:33 PM Ilya Biryukov  wrote:
>
> +Hans Wennborg, could we merge this into the release?
>
> On Tue, Aug 6, 2019 at 1:36 PM Ilya Biryukov via cfe-commits 
>  wrote:
>>
>> Author: ibiryukov
>> Date: Tue Aug  6 04:37:50 2019
>> New Revision: 368019
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=368019&view=rev
>> Log:
>> [clangd] Compute scopes eagerly in IncludeFixer
>>
>> Summary:
>> Computing lazily leads to crashes. In particular, computing scopes may
>> produce diagnostics (from inside template instantiations) and we
>> currently do it when processing another diagnostic, which leads to
>> crashes.
>>
>> Moreover, we remember and access 'Scope*' when computing scopes. This
>> might lead to invalid memory access if the Scope is deleted by the time
>> we run the delayed computation. We did not actually construct an example
>> when this happens, though.
>>
>> From the VCS and review history, it seems the optimization was
>> introduced in the initial version without a mention of any performance
>> benchmarks justifying the performance gains. This led me to a
>> conclusion that the optimization was premature, so removing it to avoid
>> crashes seems like the right trade-off at that point.
>>
>> Reviewers: sammccall
>>
>> Reviewed By: sammccall
>>
>> Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
>>
>> Tags: #clang
>>
>> Differential Revision: https://reviews.llvm.org/D65796
>>
>> Modified:
>> clang-tools-extra/trunk/clangd/IncludeFixer.cpp
>> clang-tools-extra/trunk/clangd/IncludeFixer.h
>> clang-tools-extra/trunk/clangd/unittests/DiagnosticsTests.cpp
>>
>> Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=368019&r1=368018&r2=368019&view=diff
>> ==
>> --- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original)
>> +++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Tue Aug  6 04:37:50 2019
>> @@ -16,6 +16,7 @@
>>  #include "index/Symbol.h"
>>  #include "clang/AST/Decl.h"
>>  #include "clang/AST/DeclBase.h"
>> +#include "clang/AST/DeclarationName.h"
>>  #include "clang/AST/NestedNameSpecifier.h"
>>  #include "clang/AST/Type.h"
>>  #include "clang/Basic/Diagnostic.h"
>> @@ -34,6 +35,7 @@
>>  #include "llvm/ADT/DenseMap.h"
>>  #include "llvm/ADT/None.h"
>>  #include "llvm/ADT/Optional.h"
>> +#include "llvm/ADT/StringExtras.h"
>>  #include "llvm/ADT/StringRef.h"
>>  #include "llvm/ADT/StringSet.h"
>>  #include "llvm/Support/Error.h"
>> @@ -301,6 +303,24 @@ llvm::Optional extr
>>return Result;
>>  }
>>
>> +/// Returns all namespace scopes that the unqualified lookup would visit.
>> +std::vector
>> +collectAccessibleScopes(Sema &Sem, const DeclarationNameInfo &Typo, Scope 
>> *S,
>> +Sema::LookupNameKind LookupKind) {
>> +  std::vector Scopes;
>> +  VisitedContextCollector Collector;
>> +  Sem.LookupVisibleDecls(S, LookupKind, Collector,
>> + /*IncludeGlobalScope=*/false,
>> + /*LoadExternal=*/false);
>> +
>> +  Scopes.push_back("");
>> +  for (const auto *Ctx : Collector.takeVisitedContexts()) {
>> +if (isa(Ctx))
>> +  Scopes.push_back(printNamespaceScope(*Ctx));
>> +  }
>> +  return Scopes;
>> +}
>> +
>>  class IncludeFixer::UnresolvedNameRecorder : public ExternalSemaSource {
>>  public:
>>UnresolvedNameRecorder(llvm::Optional &LastUnresolvedName)
>> @@ -321,48 +341,30 @@ public:
>>  if (!isInsideMainFile(Typo.getLoc(), SemaPtr->SourceMgr))
>>return clang::TypoCorrection();
>>
>> -// This is not done lazily because `SS` can get out of scope and it's
>> -// relatively cheap.
>>  auto Extracted = extractUnresolvedNameCheaply(
>>  SemaPtr->SourceMgr, Typo, SS, SemaPtr->LangOpts,
>>  static_cast(LookupKind) ==
>>  Sema::LookupNameKind::LookupNestedNameSpecifierName);
>>  if (!Extracted)
>>return TypoCorrection();
>> -auto CheapUnresolved = std::move(*Extracted);
>> +
>>  UnresolvedName Unresolved;
>> -Unresolved.Name = CheapUnresolved.Name;
>> +Unresolved.Name = Extracted->Name;
>>  Unresolved.Loc = Typo.getBeginLoc();
>> -
>> -if (!CheapUnresolved.ResolvedScope && !S) // Give up if no scope 
>> available.
>> +if (!Extracted->ResolvedScope && !S) // Give up if no scope available.
>>return TypoCorrection();
>>
>> -auto *Sem = SemaPtr; // Avoid capturing `this`.
>> -Unresolved.GetScopes = [Sem, CheapUnresolved, S, LookupKind]() {
>> -  std::vector Scopes;
>> -  if (CheapUnresolved.ResolvedScope) {
>> -Scopes.push_back(*CheapUnresolved.ResolvedScope);
>> -  } else {
>> -assert(S);
>> -// No scope specifier is specified. Collect all accessible scopes 
>> in the
>> -// context.
>> -VisitedContextCollector Collector;
>

[PATCH] D65510: [clangd] Fix implicit template instatiations appearing as topLevelDecls.

2019-08-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:144
+  EXPECT_THAT(AST.getLocalTopLevelDecls(),
+  ElementsAre(DeclNamed("f"), DeclNamed("f"), DeclNamed("f"),
+  DeclNamed("V"), DeclNamed("V"), DeclNamed("foo"),

jvikstrom wrote:
> ilya-biryukov wrote:
> > Is there a way to check we are seeing the explicit instantiations? (e.g. by 
> > looking at template arguments?)
> > 
> > It's not clear whether multiple `DeclNamed("foo")` refer to the decls we 
> > expect.
> Well in this case all the expressions in the top level should be in 
> topLevelDecls so unless say `void f(T) {}` somehow starts duplicating while 
> `void f(bool)` disappears from topLevelDecls they should all be visible.
> I could add a gtest matcher that also checks the types but I think that would 
> become a pretty large matcher (would have to handle FunctionDecls with 
> template arguments, VarDecls, TemplateClassSpecializationDecls etc.) and I'm 
> not sure it would really add anything to the tests.
> 
> A thing we  we could do is shuffle the order of the decls in the test so we 
> never have two decls of the same name after each other (because the matcher 
> cares about the order of the elements). Which should give us pretty high 
> confidence we are getting the correct decls... Or maybe I'm misunderstanding 
> you?
The tests should be easy to read and understand, we should definitely find a 
way to distinguish decls with different arguments.
Adding a matcher for template args should be easy enough:
```
AllOf(DeclNamed("f"), WithTemplateArgs(""))
```

Implementing the matcher is easy with `printTemplateSpecializationArgs` from 
`AST.h`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65510



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


Re: [clang-tools-extra] r368019 - [clangd] Compute scopes eagerly in IncludeFixer

2019-08-07 Thread Ilya Biryukov via cfe-commits
Many thanks!

On Wed, Aug 7, 2019 at 10:31 AM Hans Wennborg  wrote:

> Yes, merged in r368133.
>
> On Tue, Aug 6, 2019 at 4:33 PM Ilya Biryukov  wrote:
> >
> > +Hans Wennborg, could we merge this into the release?
> >
> > On Tue, Aug 6, 2019 at 1:36 PM Ilya Biryukov via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >>
> >> Author: ibiryukov
> >> Date: Tue Aug  6 04:37:50 2019
> >> New Revision: 368019
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=368019&view=rev
> >> Log:
> >> [clangd] Compute scopes eagerly in IncludeFixer
> >>
> >> Summary:
> >> Computing lazily leads to crashes. In particular, computing scopes may
> >> produce diagnostics (from inside template instantiations) and we
> >> currently do it when processing another diagnostic, which leads to
> >> crashes.
> >>
> >> Moreover, we remember and access 'Scope*' when computing scopes. This
> >> might lead to invalid memory access if the Scope is deleted by the time
> >> we run the delayed computation. We did not actually construct an example
> >> when this happens, though.
> >>
> >> From the VCS and review history, it seems the optimization was
> >> introduced in the initial version without a mention of any performance
> >> benchmarks justifying the performance gains. This led me to a
> >> conclusion that the optimization was premature, so removing it to avoid
> >> crashes seems like the right trade-off at that point.
> >>
> >> Reviewers: sammccall
> >>
> >> Reviewed By: sammccall
> >>
> >> Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
> >>
> >> Tags: #clang
> >>
> >> Differential Revision: https://reviews.llvm.org/D65796
> >>
> >> Modified:
> >> clang-tools-extra/trunk/clangd/IncludeFixer.cpp
> >> clang-tools-extra/trunk/clangd/IncludeFixer.h
> >> clang-tools-extra/trunk/clangd/unittests/DiagnosticsTests.cpp
> >>
> >> Modified: clang-tools-extra/trunk/clangd/IncludeFixer.cpp
> >> URL:
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/IncludeFixer.cpp?rev=368019&r1=368018&r2=368019&view=diff
> >>
> ==
> >> --- clang-tools-extra/trunk/clangd/IncludeFixer.cpp (original)
> >> +++ clang-tools-extra/trunk/clangd/IncludeFixer.cpp Tue Aug  6 04:37:50
> 2019
> >> @@ -16,6 +16,7 @@
> >>  #include "index/Symbol.h"
> >>  #include "clang/AST/Decl.h"
> >>  #include "clang/AST/DeclBase.h"
> >> +#include "clang/AST/DeclarationName.h"
> >>  #include "clang/AST/NestedNameSpecifier.h"
> >>  #include "clang/AST/Type.h"
> >>  #include "clang/Basic/Diagnostic.h"
> >> @@ -34,6 +35,7 @@
> >>  #include "llvm/ADT/DenseMap.h"
> >>  #include "llvm/ADT/None.h"
> >>  #include "llvm/ADT/Optional.h"
> >> +#include "llvm/ADT/StringExtras.h"
> >>  #include "llvm/ADT/StringRef.h"
> >>  #include "llvm/ADT/StringSet.h"
> >>  #include "llvm/Support/Error.h"
> >> @@ -301,6 +303,24 @@ llvm::Optional extr
> >>return Result;
> >>  }
> >>
> >> +/// Returns all namespace scopes that the unqualified lookup would
> visit.
> >> +std::vector
> >> +collectAccessibleScopes(Sema &Sem, const DeclarationNameInfo &Typo,
> Scope *S,
> >> +Sema::LookupNameKind LookupKind) {
> >> +  std::vector Scopes;
> >> +  VisitedContextCollector Collector;
> >> +  Sem.LookupVisibleDecls(S, LookupKind, Collector,
> >> + /*IncludeGlobalScope=*/false,
> >> + /*LoadExternal=*/false);
> >> +
> >> +  Scopes.push_back("");
> >> +  for (const auto *Ctx : Collector.takeVisitedContexts()) {
> >> +if (isa(Ctx))
> >> +  Scopes.push_back(printNamespaceScope(*Ctx));
> >> +  }
> >> +  return Scopes;
> >> +}
> >> +
> >>  class IncludeFixer::UnresolvedNameRecorder : public ExternalSemaSource
> {
> >>  public:
> >>UnresolvedNameRecorder(llvm::Optional
> &LastUnresolvedName)
> >> @@ -321,48 +341,30 @@ public:
> >>  if (!isInsideMainFile(Typo.getLoc(), SemaPtr->SourceMgr))
> >>return clang::TypoCorrection();
> >>
> >> -// This is not done lazily because `SS` can get out of scope and
> it's
> >> -// relatively cheap.
> >>  auto Extracted = extractUnresolvedNameCheaply(
> >>  SemaPtr->SourceMgr, Typo, SS, SemaPtr->LangOpts,
> >>  static_cast(LookupKind) ==
> >>  Sema::LookupNameKind::LookupNestedNameSpecifierName);
> >>  if (!Extracted)
> >>return TypoCorrection();
> >> -auto CheapUnresolved = std::move(*Extracted);
> >> +
> >>  UnresolvedName Unresolved;
> >> -Unresolved.Name = CheapUnresolved.Name;
> >> +Unresolved.Name = Extracted->Name;
> >>  Unresolved.Loc = Typo.getBeginLoc();
> >> -
> >> -if (!CheapUnresolved.ResolvedScope && !S) // Give up if no scope
> available.
> >> +if (!Extracted->ResolvedScope && !S) // Give up if no scope
> available.
> >>return TypoCorrection();
> >>
> >> -auto *Sem = SemaPtr; // Avoid capturing `this`.
> >> -Unresolved.GetScopes = [Sem, CheapUnresolved, S, LookupKind]() {

[PATCH] D65849: [unittests] Mark private gmock headers with IWYU pragmas. NFC

2019-08-07 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368135: [unittests] Mark private gmock headers with IWYU 
pragmas. NFC (authored by ibiryukov, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D65849?vs=213810&id=213816#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65849

Files:
  llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-actions.h
  llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-cardinalities.h
  llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-actions.h
  
llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-function-mockers.h
  llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-matchers.h
  
llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-nice-strict.h
  llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-matchers.h
  llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-more-actions.h
  llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-more-matchers.h
  llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-spec-builders.h
  
llvm/trunk/utils/unittest/googlemock/include/gmock/internal/gmock-generated-internal-utils.h
  
llvm/trunk/utils/unittest/googlemock/include/gmock/internal/gmock-internal-utils.h
  llvm/trunk/utils/unittest/googlemock/include/gmock/internal/gmock-port.h

Index: llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-matchers.h
===
--- llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-matchers.h
+++ llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-matchers.h
@@ -35,6 +35,8 @@
 //
 // This file implements some commonly used variadic matchers.
 
+// IWYU pragma: private, include "gmock/gmock.h"
+
 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
 
Index: llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-function-mockers.h
===
--- llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-function-mockers.h
+++ llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-function-mockers.h
@@ -37,6 +37,8 @@
 //
 // This file implements function mockers of various arities.
 
+// IWYU pragma: private, include "gmock/gmock.h"
+
 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
 
Index: llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-spec-builders.h
===
--- llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-spec-builders.h
+++ llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-spec-builders.h
@@ -57,6 +57,8 @@
 // where all clauses are optional, and .InSequence()/.After()/
 // .WillOnce() can appear any number of times.
 
+// IWYU pragma: private, include "gmock/gmock.h"
+
 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
 #define GMOCK_INCLUDE_GMOCK_GMOCK_SPEC_BUILDERS_H_
 
Index: llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-more-actions.h
===
--- llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-more-actions.h
+++ llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-more-actions.h
@@ -33,6 +33,8 @@
 //
 // This file implements some actions that depend on gmock-generated-actions.h.
 
+// IWYU pragma: private, include "gmock/gmock.h"
+
 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
 #define GMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
 
Index: llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-nice-strict.h
===
--- llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-nice-strict.h
+++ llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-nice-strict.h
@@ -68,6 +68,8 @@
 // cannot have arguments passed by non-const reference, which are
 // banned by the Google C++ style guide anyway.
 
+// IWYU pragma: private, include "gmock/gmock.h"
+
 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
 
Index: llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-actions.h
===
--- llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-actions.h
+++ llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-actions.h
@@ -33,6 +33,8 @@
 //
 // This file implements some commonly used actions.
 
+// IWYU pragma: private, include "gmock/gmock.h"
+
 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
 #define GMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_
 
Index: llvm/trunk/utils/unittest/googlemock/include/gmock/gmock-generated-ac

[clang-tools-extra] r368136 - [clangd] Added a TextMate theme parser to the vscode extension.

2019-08-07 Thread Johan Vikstrom via cfe-commits
Author: jvikstrom
Date: Wed Aug  7 01:48:52 2019
New Revision: 368136

URL: http://llvm.org/viewvc/llvm-project?rev=368136&view=rev
Log:
[clangd] Added a TextMate theme parser to the vscode extension.

Summary:
Adds a TextMate parser module to the vscode extension. It parses a theme into 
an array of a pair of TextMate scopes and text colors.

Reviewers: hokein, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Added:

clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/assets/

clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/assets/includeTheme.jsonc

clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/assets/simpleTheme.jsonc

clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json?rev=368136&r1=368135&r2=368136&view=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json Wed Aug  
7 01:48:52 2019
@@ -36,14 +36,15 @@
 "test": "node ./node_modules/vscode/bin/test"
 },
 "dependencies": {
+"jsonc-parser": "^2.1.0",
 "vscode-languageclient": "^5.3.0-next.6",
 "vscode-languageserver": "^5.3.0-next.6"
 },
 "devDependencies": {
 "@types/mocha": "^2.2.32",
 "@types/node": "^6.0.40",
-"mocha": "^5.2.0",
 "clang-format": "1.2.4",
+"mocha": "^5.2.0",
 "typescript": "^2.0.3",
 "vscode": "^1.1.0"
 },

Added: 
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts?rev=368136&view=auto
==
--- 
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
 (added)
+++ 
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
 Wed Aug  7 01:48:52 2019
@@ -0,0 +1,102 @@
+import * as fs from 'fs';
+import * as jsonc from "jsonc-parser";
+import * as path from 'path';
+import * as vscode from 'vscode';
+
+// A rule for how to color TextMate scopes.
+interface TokenColorRule {
+  // A TextMate scope that specifies the context of the token, e.g.
+  // "entity.name.function.cpp".
+  scope: string;
+  // foreground is the color tokens of this scope should have.
+  foreground: string;
+}
+
+// Get all token color rules provided by the theme.
+function loadTheme(themeName: string): Promise {
+  const extension =
+  vscode.extensions.all.find((extension: vscode.Extension) => {
+const contribs = extension.packageJSON.contributes;
+if (!contribs || !contribs.themes)
+  return false;
+return contribs.themes.some((theme: any) => theme.id === themeName ||
+theme.label === themeName);
+  });
+
+  if (!extension) {
+return Promise.reject('Could not find a theme with name: ' + themeName);
+  }
+
+  const themeInfo = extension.packageJSON.contributes.themes.find(
+  (theme: any) => theme.id === themeName || theme.label === themeName);
+  return parseThemeFile(path.join(extension.extensionPath, themeInfo.path));
+}
+
+/**
+ * Parse the TextMate theme at fullPath. If there are multiple TextMate scopes
+ * of the same name in the include chain only the earliest entry of the scope 
is
+ * saved.
+ * @param fullPath The absolute path to the theme.
+ * @param seenScopes A set containing the name of the scopes that have already
+ * been set.
+ */
+export async function parseThemeFile(
+fullPath: string, seenScopes?: Set): Promise {
+  if (!seenScopes)
+seenScopes = new Set();
+  // FIXME: Add support for themes written as .tmTheme.
+  if (path.extname(fullPath) === '.tmTheme')
+return [];
+  try {
+const contents = await readFileText(fullPath);
+const parsed = jsonc.parse(contents);
+const rules: TokenColorRule[] = [];
+// To make sure it does not crash if tokenColors is undefined.
+if (!parsed.tokenColors)
+  parsed.tokenColors = [];
+parsed.tokenColors.forEach((rule: any) => {
+  if (!rule.scope || !rule.settings || !rule.settings.foreground)
+return;
+  const textColor = rule.settings.foreground;
+  // Scopes that were found further up the TextMate chain should not be
+  // overwritten.
+  const addColor = (scope: st

[PATCH] D65738: [clangd] Added a TextMate theme parser to the vscode extension.

2019-08-07 Thread Johan Vikström via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
jvikstrom marked 5 inline comments as done.
Closed by commit rL368136: [clangd] Added a TextMate theme parser to the vscode 
extension. (authored by jvikstrom, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65738?vs=213801&id=213818#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65738

Files:
  clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
  
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
  
clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/assets/includeTheme.jsonc
  
clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/assets/simpleTheme.jsonc
  
clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts

Index: clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
===
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/package.json
@@ -36,14 +36,15 @@
 "test": "node ./node_modules/vscode/bin/test"
 },
 "dependencies": {
+"jsonc-parser": "^2.1.0",
 "vscode-languageclient": "^5.3.0-next.6",
 "vscode-languageserver": "^5.3.0-next.6"
 },
 "devDependencies": {
 "@types/mocha": "^2.2.32",
 "@types/node": "^6.0.40",
-"mocha": "^5.2.0",
 "clang-format": "1.2.4",
+"mocha": "^5.2.0",
 "typescript": "^2.0.3",
 "vscode": "^1.1.0"
 },
Index: clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/assets/simpleTheme.jsonc
===
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/assets/simpleTheme.jsonc
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/assets/simpleTheme.jsonc
@@ -0,0 +1,17 @@
+{
+// Some comment
+"tokenColors": [
+{
+"scope": "a",
+"settings": {
+"foreground": "#ff"
+}
+},
+{
+"scope": "c",
+"settings": {
+"foreground": "#bcd"
+}
+}
+]
+}
Index: clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/assets/includeTheme.jsonc
===
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/assets/includeTheme.jsonc
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/assets/includeTheme.jsonc
@@ -0,0 +1,28 @@
+{
+// Some comment
+"include": "simpleTheme.jsonc",
+"name": "TestTheme",
+"type": "dark",
+"colors": {
+"dropdown.background": "#fff"
+},
+"tokenColors": [
+{
+"settings": {
+"foreground": "#fff"
+}
+},
+{
+"scope": "a",
+"settings": {
+"foreground": "#fff"
+}
+},
+{
+"scope": ["a", "b"],
+"settings": {
+"foreground": "#000"
+}
+}
+]
+}
Index: clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
===
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
@@ -0,0 +1,18 @@
+import * as assert from 'assert';
+import * as path from 'path';
+
+import * as TM from '../src/semantic-highlighting';
+
+suite('TextMate Tests', () => {
+  test('Parses arrays of textmate themes.', async () => {
+const themePath =
+path.join(__dirname, '../../test/assets/includeTheme.jsonc');
+const scopeColorRules = await TM.parseThemeFile(themePath);
+const getScopeRule = (scope: string) =>
+scopeColorRules.find((v) => v.scope === scope);
+assert.equal(scopeColorRules.length, 3);
+assert.deepEqual(getScopeRule('a'), {scope : 'a', textColor : '#fff'});
+assert.deepEqual(getScopeRule('b'), {scope : 'b', textColor : '#000'});
+assert.deepEqual(getScopeRule('c'), {scope : 'c', textColor : '#bcd'});
+  });
+});
Index: clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -0,0 +1,102 @@
+import * as fs from 'fs';
+import * as jsonc from "jsonc-parser";
+import * as path from 'path';
+import * as vscode from 'vscode';
+
+// A rule for how to color TextMate scopes.
+interface 

[PATCH] D65853: Use ASSERT_THAT_ERROR instead of logAllUnhandledErrors/exit

2019-08-07 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
gribozavr added reviewers: plotfi, jkorous, compnerd.
Herald added subscribers: cfe-commits, dexonsmith, mgorny.
Herald added a project: clang.

ASSERT_THAT_ERROR looks like the intended helper for use in tests.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65853

Files:
  clang/unittests/DirectoryWatcher/CMakeLists.txt
  clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Index: clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
===
--- clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -11,6 +11,7 @@
 #include "llvm/Support/Mutex.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 #include 
 #include 
@@ -285,12 +286,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-  if (!DW) {
-logAllUnhandledErrors(
-DW.takeError(), llvm::errs(),
-"DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-exit(EXIT_FAILURE);
-  }
+  ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -323,12 +319,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/false);
-  if (!DW) {
-logAllUnhandledErrors(
-DW.takeError(), llvm::errs(),
-"DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-exit(EXIT_FAILURE);
-  }
+  ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -350,12 +341,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-  if (!DW) {
-logAllUnhandledErrors(
-DW.takeError(), llvm::errs(),
-"DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-exit(EXIT_FAILURE);
-  }
+  ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
 
   fixture.addFile("a");
   fixture.addFile("b");
@@ -382,12 +368,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-  if (!DW) {
-logAllUnhandledErrors(
-DW.takeError(), llvm::errs(),
-"DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-exit(EXIT_FAILURE);
-  }
+  ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
 
   // modify the file
   {
@@ -419,12 +400,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-  if (!DW) {
-logAllUnhandledErrors(
-DW.takeError(), llvm::errs(),
-"DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-exit(EXIT_FAILURE);
-  }
+  ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
 
   fixture.deleteFile("a");
 
@@ -447,12 +423,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-  if (!DW) {
-logAllUnhandledErrors(
-DW.takeError(), llvm::errs(),
-"DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-exit(EXIT_FAILURE);
-  }
+  ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
 
   remove_directories(fixture.TestWatchedDir);
 
@@ -474,12 +445,7 @@
   TestConsumer.consume(Events, IsInitial);
 },
 /*waitForInitialSync=*/true);
-if (!DW) {
-  logAllUnhandledErrors(
-  DW.takeError(), llvm::errs(),
-  "DirectoryWatcherTest Failure on DirectoryWatcher::create(): ");
-  exit(EXIT_FAILURE);
-}
+ASSERT_THAT_ERROR(DW.takeError(), Succeeded());
   } // DW is destructed here.
 
   checkEventualResultWithTimeout(TestConsumer);
Index: clang/unittests/DirectoryWatcher/CMakeLists.txt
===
--- clang/unittests/DirectoryWatcher/CMakeLists.txt
+++ clang/unittests/DirectoryWatcher/CMakeLists.txt
@@ -10,8 +10,9 @@
 
   target_link_libraries(DirectoryWatcherTests
 PRIVATE
+LLVMTestingSupport
 clangDirectoryWatcher
 clangBasic
 )
 
-endif()
\ No newline at end of file
+endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65854: [diagtool] Use `operator<<(Colors)` to print out colored output.

2019-08-07 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu created this revision.
ruiu added a reviewer: JDevlieghere.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

r368131 introduced this new API to print out messages in colors.
If the colored output is disabled, `operator<<(Colors)` becomes nop.
No functionality change intended.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65854

Files:
  clang/tools/diagtool/TreeView.cpp


Index: clang/tools/diagtool/TreeView.cpp
===
--- clang/tools/diagtool/TreeView.cpp
+++ clang/tools/diagtool/TreeView.cpp
@@ -27,24 +27,13 @@
 }
 
 class TreePrinter {
+  using Colors = llvm::raw_ostream::Colors;
+
 public:
   llvm::raw_ostream &out;
-  const bool ShowColors;
   bool Internal;
 
-  TreePrinter(llvm::raw_ostream &out)
-  : out(out), ShowColors(hasColors(out)), Internal(false) {}
-
-  void setColor(llvm::raw_ostream::Colors Color) {
-if (ShowColors)
-  out << llvm::sys::Process::OutputColor(static_cast(Color), false,
- false);
-  }
-
-  void resetColor() {
-if (ShowColors)
-  out << llvm::sys::Process::ResetColor();
-  }
+  TreePrinter(llvm::raw_ostream &out) : out(out), Internal(false) {}
 
   static bool isIgnored(unsigned DiagID) {
 // FIXME: This feels like a hack.
@@ -71,12 +60,11 @@
 out.indent(Indent * 2);
 
 if (enabledByDefault(Group))
-  setColor(llvm::raw_ostream::GREEN);
+  out << Colors::GREEN;
 else
-  setColor(llvm::raw_ostream::YELLOW);
+  out << Colors::YELLOW;
 
-out << "-W" << Group.getName() << "\n";
-resetColor();
+out << "-W" << Group.getName() << "\n" << Colors::RESET;
 
 ++Indent;
 for (const GroupRecord &GR : Group.subgroups()) {
@@ -85,12 +73,10 @@
 
 if (Internal) {
   for (const DiagnosticRecord &DR : Group.diagnostics()) {
-if (ShowColors && !isIgnored(DR.DiagID))
-  setColor(llvm::raw_ostream::GREEN);
+if (!isIgnored(DR.DiagID))
+  out << Colors::GREEN;
 out.indent(Indent * 2);
-out << DR.getName();
-resetColor();
-out << "\n";
+out << DR.getName() << Colors::RESET << "\n";
   }
 }
   }
@@ -136,13 +122,8 @@
   }
 
   void showKey() {
-if (ShowColors) {
-  out << '\n';
-  setColor(llvm::raw_ostream::GREEN);
-  out << "GREEN";
-  resetColor();
-  out << " = enabled by default\n\n";
-}
+out << '\n' << Colors::GREEN << "GREEN" << Colors::RESET
+<< " = enabled by default\n\n";
   }
 };
 
@@ -182,6 +163,9 @@
 return -1;
   }
 
+  if (!hasColors(out))
+out.enable_colors(false);
+
   TreePrinter TP(out);
   TP.Internal = Internal;
   TP.showKey();


Index: clang/tools/diagtool/TreeView.cpp
===
--- clang/tools/diagtool/TreeView.cpp
+++ clang/tools/diagtool/TreeView.cpp
@@ -27,24 +27,13 @@
 }
 
 class TreePrinter {
+  using Colors = llvm::raw_ostream::Colors;
+
 public:
   llvm::raw_ostream &out;
-  const bool ShowColors;
   bool Internal;
 
-  TreePrinter(llvm::raw_ostream &out)
-  : out(out), ShowColors(hasColors(out)), Internal(false) {}
-
-  void setColor(llvm::raw_ostream::Colors Color) {
-if (ShowColors)
-  out << llvm::sys::Process::OutputColor(static_cast(Color), false,
- false);
-  }
-
-  void resetColor() {
-if (ShowColors)
-  out << llvm::sys::Process::ResetColor();
-  }
+  TreePrinter(llvm::raw_ostream &out) : out(out), Internal(false) {}
 
   static bool isIgnored(unsigned DiagID) {
 // FIXME: This feels like a hack.
@@ -71,12 +60,11 @@
 out.indent(Indent * 2);
 
 if (enabledByDefault(Group))
-  setColor(llvm::raw_ostream::GREEN);
+  out << Colors::GREEN;
 else
-  setColor(llvm::raw_ostream::YELLOW);
+  out << Colors::YELLOW;
 
-out << "-W" << Group.getName() << "\n";
-resetColor();
+out << "-W" << Group.getName() << "\n" << Colors::RESET;
 
 ++Indent;
 for (const GroupRecord &GR : Group.subgroups()) {
@@ -85,12 +73,10 @@
 
 if (Internal) {
   for (const DiagnosticRecord &DR : Group.diagnostics()) {
-if (ShowColors && !isIgnored(DR.DiagID))
-  setColor(llvm::raw_ostream::GREEN);
+if (!isIgnored(DR.DiagID))
+  out << Colors::GREEN;
 out.indent(Indent * 2);
-out << DR.getName();
-resetColor();
-out << "\n";
+out << DR.getName() << Colors::RESET << "\n";
   }
 }
   }
@@ -136,13 +122,8 @@
   }
 
   void showKey() {
-if (ShowColors) {
-  out << '\n';
-  setColor(llvm::raw_ostream::GREEN);
-  out << "GREEN";
-  resetColor();
-  out << " = enabled by default\n\n";
-}
+out << '\n' << Colors::GREEN << "GREEN" << Colors::RESET
+<< " = enabled by default\n\n";
   }
 };
 
@@ -182,6 +163,9 @@
 return -1;
   }
 
+  if (!hasColors(out))
+o

[PATCH] D65854: [diagtool] Use `operator<<(Colors)` to print out colored output.

2019-08-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/tools/diagtool/TreeView.cpp:167
+  if (!hasColors(out))
+out.enable_colors(false);
+

`out.enable_colors(out.has_colors());`

It looks the function `hasColors` is overengineered. `out` in these files can 
only be `llvm::outs()`. It doesn't have to check if `llvm::errs()` is connected 
to a terminal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65854



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


[PATCH] D65856: [clangd] Added class for mapping TokenColorRules to their associated clangd TextMate scope

2019-08-07 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom created this revision.
jvikstrom added reviewers: hokein, ilya-biryukov.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

Maps an array of TM scopes to the most specific scope that is added. Needed to 
have fast access to a rule when doing the actual coloring.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65856

Files:
  clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
  
clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts


Index: 
clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
===
--- 
clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
+++ 
clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
@@ -11,8 +11,23 @@
 const getScopeRule = (scope: string) =>
 scopeColorRules.find((v) => v.scope === scope);
 assert.equal(scopeColorRules.length, 3);
-assert.deepEqual(getScopeRule('a'), {scope : 'a', textColor : '#fff'});
-assert.deepEqual(getScopeRule('b'), {scope : 'b', textColor : '#000'});
-assert.deepEqual(getScopeRule('c'), {scope : 'c', textColor : '#bcd'});
+assert.deepEqual(getScopeRule('a'), {scope : 'a', foreground : '#fff'});
+assert.deepEqual(getScopeRule('b'), {scope : 'b', foreground : '#000'});
+assert.deepEqual(getScopeRule('c'), {scope : 'c', foreground : '#bcd'});
+  });
+  test('ScopeRules overrides for more specific themes', () => {
+const scopes = [ 'a.b.c.d', 'a.b.f', 'a' ];
+const rules = [
+  {scope : 'a.b.c', foreground : '1'},
+  {scope : 'a.b', foreground : '2'},
+  {scope : 'a.b.c.d', foreground : '3'},
+  {scope : 'a', foreground : '4'},
+];
+
+const tm = new TM.ScopeRules(scopes);
+rules.forEach((r) => tm.addRule(r));
+assert.deepEqual(tm.getRule(0), rules[2]);
+assert.deepEqual(tm.getRule(1), rules[1]);
+assert.deepEqual(tm.getRule(2), rules[3]);
   });
 });
Index: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -12,6 +12,39 @@
   foreground: string;
 }
 
+export class ScopeRules {
+  // The TextMate scopes that should be mapped to a color.
+  private scopes: string[];
+  // Contains the current best matching scope for the scope at the 
corresponding
+  // index.
+  private scopeRules: TokenColorRule[];
+
+  constructor(scopes: string[]) {
+this.scopes = scopes;
+this.scopeRules =
+this.scopes.map(() => ({scope : '', foreground : '#000'}));
+  }
+
+  addRule(rule: TokenColorRule) {
+// Find the associated clangd scope(s) index for this scope. A scope being 
a
+// possible candidate means that the clangd scope must have the rule's 
scope
+// as a prefix.
+const allCandidates =
+this.scopes.map((s, i) => ({s : s, i : i}))
+.filter(({s}) => s.substr(0, rule.scope.length) === rule.scope);
+// If this scope is more specific than any of current scopes for the clangd
+// scopes it should be replaced. As both options are prefixes of the clangd
+// scope it's enough to compare lengths.
+allCandidates.forEach(({i}) => {
+  if (rule.scope.length > this.scopeRules[i].scope.length) {
+this.scopeRules[i] = rule;
+  }
+});
+  }
+
+  getRule(idx: number) { return this.scopeRules[idx]; }
+}
+
 // Get all token color rules provided by the theme.
 function loadTheme(themeName: string): Promise {
   const extension =


Index: clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/test/semantic-highlighting.test.ts
@@ -11,8 +11,23 @@
 const getScopeRule = (scope: string) =>
 scopeColorRules.find((v) => v.scope === scope);
 assert.equal(scopeColorRules.length, 3);
-assert.deepEqual(getScopeRule('a'), {scope : 'a', textColor : '#fff'});
-assert.deepEqual(getScopeRule('b'), {scope : 'b', textColor : '#000'});
-assert.deepEqual(getScopeRule('c'), {scope : 'c', textColor : '#bcd'});
+assert.deepEqual(getScopeRule('a'), {scope : 'a', foreground : '#fff'});
+assert.deepEqual(getScopeRule('b'), {scope : 'b', foreground : '#000'});
+assert.deepEqual(getScopeRule('c'), {scope : 'c', foreground : '#bcd'});
+  });
+  test('ScopeRules overrides for more specific themes', () => {
+const scopes = [ 'a.b.c.d', 'a.b.f', 'a' ];
+const rules = [
+  {scope : 'a.b.c', foreground : '1'},
+  {scope : 'a.b', foregro

r368147 - gsl::Owner/gsl::Pointer: Add implicit annotations for some std types

2019-08-07 Thread Matthias Gehre via cfe-commits
Author: mgehre
Date: Wed Aug  7 03:45:36 2019
New Revision: 368147

URL: http://llvm.org/viewvc/llvm-project?rev=368147&view=rev
Log:
gsl::Owner/gsl::Pointer: Add implicit annotations for some std types

Summary:
Hard code gsl::Owner/gsl::Pointer for std types. The paper mentions
some types explicitly. Generally, all containers and their iterators are
covered. For iterators, we cover both the case that they are defined
as an nested class or as an typedef/using. I have started to test this
implementation against some real standard library implementations, namely
libc++ 7.1.0, libc++ 8.0.1rc2, libstdc++ 4.6.4, libstdc++ 4.8.5,
libstdc++ 4.9.4, libstdc++ 5.4.0, libstdc++ 6.5.0, libstdc++ 7.3.0,
libstdc++ 8.3.0 and libstdc++ 9.1.0.

The tests are currently here
  https://github.com/mgehre/llvm-project/blob/lifetime-ci/lifetime-attr-test.sh
  https://github.com/mgehre/llvm-project/blob/lifetime-ci/lifetime-attr-test.cpp
I think due to their dependency on a standard library, they are not a good fit
for clang/test/. Where else could I put them?

Reviewers: gribozavr, xazax.hun

Subscribers: rnkovacs, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
Modified:
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaAttr.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=368147&r1=368146&r2=368147&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Wed Aug  7 03:45:36 2019
@@ -4249,7 +4249,7 @@ object of type ``T``:
 int *getInt() { return &value; }
   };
 
-The argument ``T`` is optional and currently ignored.
+The argument ``T`` is optional and is ignored.
 This attribute may be used by analysis tools and has no effect on code
 generation.
 
@@ -4275,7 +4275,7 @@ like pointers to an object of type ``T``
 int *getInt() { return &valuePointer; }
   };
 
-The argument ``T`` is optional and currently ignored.
+The argument ``T`` is optional and is ignored.
 This attribute may be used by analysis tools and has no effect on code
 generation.
 

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=368147&r1=368146&r2=368147&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Aug  7 03:45:36 2019
@@ -6116,6 +6116,17 @@ public:
   ClassTemplateSpecializationDecl *BaseTemplateSpec,
   SourceLocation BaseLoc);
 
+  /// Add gsl::Pointer attribute to std::container::iterator
+  /// \param ND The declaration that introduces the name
+  /// std::container::iterator. \param UnderlyingRecord The record named by ND.
+  void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl 
*UnderlyingRecord);
+
+  /// Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types.
+  void inferGslOwnerPointerAttribute(CXXRecordDecl *Record);
+
+  /// Add [[gsl::Pointer]] attributes for std:: types.
+  void inferGslPointerAttribute(TypedefNameDecl *TD);
+
   void CheckCompletedCXXClass(CXXRecordDecl *Record);
 
   /// Check that the C++ class annoated with "trivial_abi" satisfies all the

Modified: cfe/trunk/lib/Sema/SemaAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAttr.cpp?rev=368147&r1=368146&r2=368147&view=diff
==
--- cfe/trunk/lib/Sema/SemaAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAttr.cpp Wed Aug  7 03:45:36 2019
@@ -85,6 +85,126 @@ void Sema::AddMsStructLayoutForRecord(Re
 MSVtorDispAttr::CreateImplicit(Context, VtorDispStack.CurrentValue));
 }
 
+template 
+static void addGslOwnerPointerAttributeIfNotExisting(ASTContext &Context,
+ CXXRecordDecl *Record) {
+  CXXRecordDecl *Canonical = Record->getCanonicalDecl();
+  if (Canonical->hasAttr() || Canonical->hasAttr())
+return;
+
+  Canonical->addAttr(::new (Context) Attribute(SourceRange{}, Context,
+   /*DerefType*/ nullptr,
+   /*Spelling=*/0));
+}
+
+void Sema::inferGslPointerAttribute(NamedDecl *ND,
+CXXRecordDecl *UnderlyingRecord) {
+  if (!UnderlyingRecord)
+return;
+
+  const auto *Parent = dyn_cast(ND->getDeclContext());
+  if (!Parent)
+return;
+
+  static llvm::StringSet<> Containers{
+  "array",
+  "basic_string",
+  "deque",
+  "forward_list",
+  "vector",
+  "list",
+  

[PATCH] D64448: gsl::Owner/gsl::Pointer: Add implicit annotations for some std types

2019-08-07 Thread Matthias Gehre via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368147: gsl::Owner/gsl::Pointer: Add implicit annotations 
for some std types (authored by mgehre, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64448?vs=212446&id=213836#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64448

Files:
  cfe/trunk/include/clang/Basic/AttrDocs.td
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Sema/SemaAttr.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaTemplate.cpp
  cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer-std.cpp

Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -6116,6 +6116,17 @@
   ClassTemplateSpecializationDecl *BaseTemplateSpec,
   SourceLocation BaseLoc);
 
+  /// Add gsl::Pointer attribute to std::container::iterator
+  /// \param ND The declaration that introduces the name
+  /// std::container::iterator. \param UnderlyingRecord The record named by ND.
+  void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord);
+
+  /// Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types.
+  void inferGslOwnerPointerAttribute(CXXRecordDecl *Record);
+
+  /// Add [[gsl::Pointer]] attributes for std:: types.
+  void inferGslPointerAttribute(TypedefNameDecl *TD);
+
   void CheckCompletedCXXClass(CXXRecordDecl *Record);
 
   /// Check that the C++ class annoated with "trivial_abi" satisfies all the
Index: cfe/trunk/include/clang/Basic/AttrDocs.td
===
--- cfe/trunk/include/clang/Basic/AttrDocs.td
+++ cfe/trunk/include/clang/Basic/AttrDocs.td
@@ -4249,7 +4249,7 @@
 int *getInt() { return &value; }
   };
 
-The argument ``T`` is optional and currently ignored.
+The argument ``T`` is optional and is ignored.
 This attribute may be used by analysis tools and has no effect on code
 generation.
 
@@ -4275,7 +4275,7 @@
 int *getInt() { return &valuePointer; }
   };
 
-The argument ``T`` is optional and currently ignored.
+The argument ``T`` is optional and is ignored.
 This attribute may be used by analysis tools and has no effect on code
 generation.
 
Index: cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
===
--- cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
+++ cfe/trunk/test/SemaCXX/attr-gsl-owner-pointer-std.cpp
@@ -0,0 +1,129 @@
+// RUN: %clang_cc1 -ast-dump %s | \
+// RUN: FileCheck --implicit-check-not OwnerAttr --implicit-check-not PointerAttr %s
+
+// Test attribute inference for types in the standard library.
+namespace std {
+// Attributes are inferred for a (complete) class.
+class any {
+  // CHECK: CXXRecordDecl {{.*}} any
+  // CHECK: OwnerAttr {{.*}}
+};
+
+// Attributes are inferred for instantiations of a complete template.
+template 
+class vector {
+public:
+  class iterator {};
+  // CHECK: ClassTemplateDecl {{.*}} vector
+  // CHECK: OwnerAttr {{.*}}
+  // CHECK: CXXRecordDecl {{.*}} iterator
+  // CHECK: PointerAttr {{.*}}
+  // CHECK: ClassTemplateSpecializationDecl {{.*}} vector
+  // CHECK: TemplateArgument type 'int'
+  // CHECK: OwnerAttr
+  // CHECK: CXXRecordDecl {{.*}} iterator
+  // CHECK: PointerAttr {{.*}}
+};
+static_assert(sizeof(vector), "");   // Force instantiation.
+static_assert(sizeof(vector::iterator), ""); // Force instantiation.
+
+// If std::container::iterator is a using declaration, attributes are inferred
+// for the underlying class.
+template 
+class __set_iterator {};
+// CHECK: ClassTemplateDecl {{.*}} __set_iterator
+// CHECK: PointerAttr
+// CHECK: ClassTemplateSpecializationDecl {{.*}} __set_iterator
+// CHECK: TemplateArgument type 'int'
+// CHECK: PointerAttr
+
+template 
+class set {
+  // CHECK: ClassTemplateDecl {{.*}} set
+  // CHECK: OwnerAttr {{.*}}
+  // CHECK: ClassTemplateSpecializationDecl {{.*}} set
+  // CHECK: OwnerAttr {{.*}}
+public:
+  using iterator = __set_iterator;
+};
+static_assert(sizeof(set::iterator), ""); // Force instantiation.
+
+// If std::container::iterator is a typedef, attributes are inferred for the
+// underlying class.
+template 
+class __map_iterator {};
+// CHECK: ClassTemplateDecl {{.*}} __map_iterator
+// CHECK: PointerAttr
+// CHECK: ClassTemplateSpecializationDecl {{.*}} __map_iterator
+// CHECK: TemplateArgument type 'int'
+// CHECK: PointerAttr
+
+template 
+class map {
+  // CHECK: ClassTemplateDecl {{.*}} map
+  // CHECK: OwnerAttr {{.*}}
+  // CHECK: ClassTemplateSpecializationDecl {{.*}} map
+  // CHECK: OwnerAttr {{.*}}
+public:
+  typedef __map_iterator iterator;
+};
+static_assert(sizeof(map::iterator), ""); // Force instantiation.
+
+// Inline namespaces are igno

r368149 - Replace llvm::MutexGuard/UniqueLock with their standard equivalents

2019-08-07 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Aug  7 03:57:25 2019
New Revision: 368149

URL: http://llvm.org/viewvc/llvm-project?rev=368149&view=rev
Log:
Replace llvm::MutexGuard/UniqueLock with their standard equivalents

All supported platforms have  now, so we don't need our own
copies any longer. No functionality change intended.

Modified:
cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
cfe/trunk/tools/libclang/CIndexer.cpp
cfe/trunk/tools/libclang/Indexing.cpp

Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=368149&r1=368148&r2=368149&view=diff
==
--- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original)
+++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Wed Aug  7 03:57:25 2019
@@ -28,10 +28,10 @@
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Mutex.h"
-#include "llvm/Support/MutexGuard.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include 
+#include 
 #include 
 
 using namespace clang;
@@ -106,20 +106,20 @@ TemporaryFiles &TemporaryFiles::getInsta
 }
 
 TemporaryFiles::~TemporaryFiles() {
-  llvm::MutexGuard Guard(Mutex);
+  std::lock_guard Guard(Mutex);
   for (const auto &File : Files)
 llvm::sys::fs::remove(File.getKey());
 }
 
 void TemporaryFiles::addFile(StringRef File) {
-  llvm::MutexGuard Guard(Mutex);
+  std::lock_guard Guard(Mutex);
   auto IsInserted = Files.insert(File).second;
   (void)IsInserted;
   assert(IsInserted && "File has already been added");
 }
 
 void TemporaryFiles::removeFile(StringRef File) {
-  llvm::MutexGuard Guard(Mutex);
+  std::lock_guard Guard(Mutex);
   auto WasPresent = Files.erase(File);
   (void)WasPresent;
   assert(WasPresent && "File was not tracked");

Modified: cfe/trunk/tools/libclang/CIndexer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexer.cpp?rev=368149&r1=368148&r2=368149&view=diff
==
--- cfe/trunk/tools/libclang/CIndexer.cpp (original)
+++ cfe/trunk/tools/libclang/CIndexer.cpp Wed Aug  7 03:57:25 2019
@@ -18,11 +18,11 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/MD5.h"
-#include "llvm/Support/MutexGuard.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/YAMLParser.h"
 #include 
+#include 
 
 #ifdef __CYGWIN__
 #include 

Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=368149&r1=368148&r2=368149&view=diff
==
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Wed Aug  7 03:57:25 2019
@@ -29,8 +29,8 @@
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Mutex.h"
-#include "llvm/Support/MutexGuard.h"
 #include 
+#include 
 #include 
 
 using namespace clang;
@@ -132,12 +132,12 @@ public:
   }
 
   void copyTo(PPRegionSetTy &Set) {
-llvm::MutexGuard MG(Mux);
+std::lock_guard MG(Mux);
 Set = ParsedRegions;
   }
 
   void update(ArrayRef Regions) {
-llvm::MutexGuard MG(Mux);
+std::lock_guard MG(Mux);
 ParsedRegions.insert(Regions.begin(), Regions.end());
   }
 };


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


[PATCH] D65589: [clang] Fix mismatched args constructing AddressSpaceAttr.

2019-08-07 Thread Anton Bikineev 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 rL368152: [clang] Fix mismatched args constructing 
AddressSpaceAttr. (authored by AntonBikineev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65589?vs=212882&id=213840#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65589

Files:
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/unittests/AST/ASTTraverserTest.cpp


Index: cfe/trunk/lib/Sema/SemaType.cpp
===
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -5978,9 +5978,9 @@
 }
 
 ASTContext &Ctx = S.Context;
-auto *ASAttr = ::new (Ctx) AddressSpaceAttr(
-Attr.getRange(), Ctx, Attr.getAttributeSpellingListIndex(),
-static_cast(ASIdx));
+auto *ASAttr = ::new (Ctx)
+AddressSpaceAttr(Attr.getRange(), Ctx, static_cast(ASIdx),
+ Attr.getAttributeSpellingListIndex());
 
 // If the expression is not value dependent (not templated), then we can
 // apply the address space qualifiers just to the equivalent type.
Index: cfe/trunk/unittests/AST/ASTTraverserTest.cpp
===
--- cfe/trunk/unittests/AST/ASTTraverserTest.cpp
+++ cfe/trunk/unittests/AST/ASTTraverserTest.cpp
@@ -139,6 +139,8 @@
 { 
 };
 
+void parmvardecl_attr(struct A __attribute__((address_space(19)))*);
+
 )cpp");
 
   const FunctionDecl *Func = getFunctionNode(AST.get(), "func");
@@ -220,5 +222,16 @@
 R"cpp(
 TemplateArgument
 )cpp");
+
+  Func = getFunctionNode(AST.get(), "parmvardecl_attr");
+
+  const auto *Parm = Func->getParamDecl(0);
+  const auto TL = Parm->getTypeSourceInfo()->getTypeLoc();
+  ASSERT_TRUE(TL.getType()->isPointerType());
+
+  const auto ATL = TL.getNextTypeLoc().getAs();
+  const auto *AS = cast(ATL.getAttr());
+  EXPECT_EQ(toTargetAddressSpace(static_cast(AS->getAddressSpace())),
+19u);
 }
 } // namespace clang


Index: cfe/trunk/lib/Sema/SemaType.cpp
===
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -5978,9 +5978,9 @@
 }
 
 ASTContext &Ctx = S.Context;
-auto *ASAttr = ::new (Ctx) AddressSpaceAttr(
-Attr.getRange(), Ctx, Attr.getAttributeSpellingListIndex(),
-static_cast(ASIdx));
+auto *ASAttr = ::new (Ctx)
+AddressSpaceAttr(Attr.getRange(), Ctx, static_cast(ASIdx),
+ Attr.getAttributeSpellingListIndex());
 
 // If the expression is not value dependent (not templated), then we can
 // apply the address space qualifiers just to the equivalent type.
Index: cfe/trunk/unittests/AST/ASTTraverserTest.cpp
===
--- cfe/trunk/unittests/AST/ASTTraverserTest.cpp
+++ cfe/trunk/unittests/AST/ASTTraverserTest.cpp
@@ -139,6 +139,8 @@
 { 
 };
 
+void parmvardecl_attr(struct A __attribute__((address_space(19)))*);
+
 )cpp");
 
   const FunctionDecl *Func = getFunctionNode(AST.get(), "func");
@@ -220,5 +222,16 @@
 R"cpp(
 TemplateArgument
 )cpp");
+
+  Func = getFunctionNode(AST.get(), "parmvardecl_attr");
+
+  const auto *Parm = Func->getParamDecl(0);
+  const auto TL = Parm->getTypeSourceInfo()->getTypeLoc();
+  ASSERT_TRUE(TL.getType()->isPointerType());
+
+  const auto ATL = TL.getNextTypeLoc().getAs();
+  const auto *AS = cast(ATL.getAttr());
+  EXPECT_EQ(toTargetAddressSpace(static_cast(AS->getAddressSpace())),
+19u);
 }
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64374: [analyzer] CastValueChecker: Model casts

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

Do you have plans to extend this checker with the modeling of `isa<>`? I might 
take that off your shoulder if not :)


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

https://reviews.llvm.org/D64374



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


[PATCH] D60943: Delay diagnosing asm constraints that require immediates until after inlining

2019-08-07 Thread Bill Wendling 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 rL368104: Delay diagnosing asm constraints that require 
immediates until after inlining (authored by void, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D60943?vs=212085&id=213738#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D60943

Files:
  cfe/trunk/lib/CodeGen/CGStmt.cpp
  cfe/trunk/lib/Sema/SemaStmtAsm.cpp
  cfe/trunk/test/CodeGen/pr41027.c
  cfe/trunk/test/Sema/inline-asm-validate-riscv.c
  cfe/trunk/test/Sema/inline-asm-validate-x86.c
  cfe/trunk/test/Sema/pr41027.c

Index: cfe/trunk/lib/CodeGen/CGStmt.cpp
===
--- cfe/trunk/lib/CodeGen/CGStmt.cpp
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp
@@ -1846,11 +1846,9 @@
   InputExpr->EvaluateAsRValue(EVResult, getContext(), true);
 
   llvm::APSInt IntResult;
-  if (!EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
-   getContext()))
-llvm_unreachable("Invalid immediate constant!");
-
-  return llvm::ConstantInt::get(getLLVMContext(), IntResult);
+  if (EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
+  getContext()))
+return llvm::ConstantInt::get(getLLVMContext(), IntResult);
 }
 
 Expr::EvalResult Result;
Index: cfe/trunk/lib/Sema/SemaStmtAsm.cpp
===
--- cfe/trunk/lib/Sema/SemaStmtAsm.cpp
+++ cfe/trunk/lib/Sema/SemaStmtAsm.cpp
@@ -383,25 +383,19 @@
 } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
   if (!InputExpr->isValueDependent()) {
 Expr::EvalResult EVResult;
-if (!InputExpr->EvaluateAsRValue(EVResult, Context, true))
-  return StmtError(
-  Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
-  << Info.getConstraintStr() << InputExpr->getSourceRange());
-
-// For compatibility with GCC, we also allow pointers that would be
-// integral constant expressions if they were cast to int.
-llvm::APSInt IntResult;
-if (!EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
- Context))
-  return StmtError(
-  Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
-  << Info.getConstraintStr() << InputExpr->getSourceRange());
-
-if (!Info.isValidAsmImmediate(IntResult))
-  return StmtError(Diag(InputExpr->getBeginLoc(),
-diag::err_invalid_asm_value_for_constraint)
-   << IntResult.toString(10) << Info.getConstraintStr()
-   << InputExpr->getSourceRange());
+if (InputExpr->EvaluateAsRValue(EVResult, Context, true)) {
+  // For compatibility with GCC, we also allow pointers that would be
+  // integral constant expressions if they were cast to int.
+  llvm::APSInt IntResult;
+  if (EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
+   Context))
+if (!Info.isValidAsmImmediate(IntResult))
+  return StmtError(Diag(InputExpr->getBeginLoc(),
+diag::err_invalid_asm_value_for_constraint)
+   << IntResult.toString(10)
+   << Info.getConstraintStr()
+   << InputExpr->getSourceRange());
+}
   }
 
 } else {
Index: cfe/trunk/test/Sema/inline-asm-validate-riscv.c
===
--- cfe/trunk/test/Sema/inline-asm-validate-riscv.c
+++ cfe/trunk/test/Sema/inline-asm-validate-riscv.c
@@ -4,7 +4,6 @@
 void I(int i) {
   static const int BelowMin = -2049;
   static const int AboveMax = 2048;
-  asm volatile ("" :: "I"(i)); // expected-error{{constraint 'I' expects an integer constant expression}}
   asm volatile ("" :: "I"(BelowMin)); // expected-error{{value '-2049' out of range for constraint 'I'}}
   asm volatile ("" :: "I"(AboveMax)); // expected-error{{value '2048' out of range for constraint 'I'}}
 }
@@ -12,7 +11,6 @@
 void J(int j) {
   static const int BelowMin = -1;
   static const int AboveMax = 1;
-  asm volatile ("" :: "J"(j)); // expected-error{{constraint 'J' expects an integer constant expression}}
   asm volatile ("" :: "J"(BelowMin)); // expected-error{{value '-1' out of range for constraint 'J'}}
   asm volatile ("" :: "J"(AboveMax)); // expected-error{{value '1' out of range for constraint 'J'}}
 }
@@ -20,7 +18,6 @@
 void K(int k) {

[PATCH] D65634: [RISCV] Default to ilp32d/lp64d in RISC-V Linux

2019-08-07 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 added a comment.

Thanks @asb @lenary for the review!

I understand that, after this change, we will also want to make 
`-march=rv{32,64}gc` the default in Linux as well. Otherwise there will be an 
ABI mismatch with the default `-march=rv{32.64}i` in a default invocation.

Does this make sense?


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

https://reviews.llvm.org/D65634



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


r368152 - [clang] Fix mismatched args constructing AddressSpaceAttr.

2019-08-07 Thread Anton Bikineev via cfe-commits
Author: antonbikineev
Date: Wed Aug  7 04:12:43 2019
New Revision: 368152

URL: http://llvm.org/viewvc/llvm-project?rev=368152&view=rev
Log:
[clang] Fix mismatched args constructing AddressSpaceAttr.

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

Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/unittests/AST/ASTTraverserTest.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=368152&r1=368151&r2=368152&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Aug  7 04:12:43 2019
@@ -5978,9 +5978,9 @@ static void HandleAddressSpaceTypeAttrib
 }
 
 ASTContext &Ctx = S.Context;
-auto *ASAttr = ::new (Ctx) AddressSpaceAttr(
-Attr.getRange(), Ctx, Attr.getAttributeSpellingListIndex(),
-static_cast(ASIdx));
+auto *ASAttr = ::new (Ctx)
+AddressSpaceAttr(Attr.getRange(), Ctx, static_cast(ASIdx),
+ Attr.getAttributeSpellingListIndex());
 
 // If the expression is not value dependent (not templated), then we can
 // apply the address space qualifiers just to the equivalent type.

Modified: cfe/trunk/unittests/AST/ASTTraverserTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTTraverserTest.cpp?rev=368152&r1=368151&r2=368152&view=diff
==
--- cfe/trunk/unittests/AST/ASTTraverserTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTTraverserTest.cpp Wed Aug  7 04:12:43 2019
@@ -139,6 +139,8 @@ struct templ
 { 
 };
 
+void parmvardecl_attr(struct A __attribute__((address_space(19)))*);
+
 )cpp");
 
   const FunctionDecl *Func = getFunctionNode(AST.get(), "func");
@@ -220,5 +222,16 @@ FullComment
 R"cpp(
 TemplateArgument
 )cpp");
+
+  Func = getFunctionNode(AST.get(), "parmvardecl_attr");
+
+  const auto *Parm = Func->getParamDecl(0);
+  const auto TL = Parm->getTypeSourceInfo()->getTypeLoc();
+  ASSERT_TRUE(TL.getType()->isPointerType());
+
+  const auto ATL = TL.getNextTypeLoc().getAs();
+  const auto *AS = cast(ATL.getAttr());
+  EXPECT_EQ(toTargetAddressSpace(static_cast(AS->getAddressSpace())),
+19u);
 }
 } // namespace clang


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


[PATCH] D65634: [RISCV] Default to ilp32d/lp64d in RISC-V Linux

2019-08-07 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 updated this revision to Diff 213812.
rogfer01 retitled this revision from "[RISCV] Default to lp64d in 64-bit RISC-V 
Linux" to "[RISCV] Default to ilp32d/lp64d in RISC-V Linux".
rogfer01 edited the summary of this revision.
rogfer01 added a comment.

ChangeLog:

- Make `ilp32d` also the default in 32-bit RISC-V Linux
- Do not use nested conditional expressions


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

https://reviews.llvm.org/D65634

Files:
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv32-toolchain.c
  clang/test/Driver/riscv64-toolchain.c
  clang/test/Preprocessor/riscv-target-features.c


Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -48,9 +48,9 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s
 // CHECK-C-EXT: __riscv_compressed 1
 
-// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -x c -E -dM %s 
\
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -mabi=ilp32 -x 
c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-SOFT %s
-// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ifd -x c -E -dM %s 
\
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ifd -mabi=lp64 -x 
c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-SOFT %s
 // CHECK-SOFT: __riscv_float_abi_soft 1
 // CHECK-SOFT-NOT: __riscv_float_abi_single
@@ -64,9 +64,9 @@
 // CHECK-SINGLE-NOT: __riscv_float_abi_soft
 // CHECK-SINGLE-NOT: __riscv_float_abi_double
 
-// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -mabi=ilp32d 
-x c -E -dM %s \
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -x c -E -dM %s 
\
 // RUN: -o - | FileCheck --check-prefix=CHECK-DOUBLE %s
-// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ifd -mabi=lp64d -x 
c -E -dM %s \
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ifd -x c -E -dM %s 
\
 // RUN: -o - | FileCheck --check-prefix=CHECK-DOUBLE %s
 // CHECK-DOUBLE: __riscv_float_abi_double 1
 // CHECK-DOUBLE-NOT: __riscv_float_abi_soft
Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -68,7 +68,7 @@
 // CXX-RV64-BAREMETAL-NOSYSROOT-LP64: 
"{{.*}}/Inputs/basic_riscv64_tree/lib/gcc/riscv64-unknown-elf/8.0.1{{/|}}crtend.o"
 
 // RUN: %clang %s -### -no-canonical-prefixes -fuse-ld=ld \
-// RUN:   -target riscv64-unknown-linux-gnu \
+// RUN:   -target riscv64-unknown-linux-gnu -mabi=lp64 \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
 // RUN:   --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV64-LINUX-MULTI-LP64 %s
@@ -84,7 +84,7 @@
 // C-RV64-LINUX-MULTI-LP64: 
"-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/usr/lib64/lp64"
 
 // RUN: %clang %s -### -no-canonical-prefixes -fuse-ld=ld \
-// RUN:   -target riscv64-unknown-linux-gnu -march=rv64imafd -mabi=lp64d \
+// RUN:   -target riscv64-unknown-linux-gnu -march=rv64imafd \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
 // RUN:   --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV64-LINUX-MULTI-LP64D %s
Index: clang/test/Driver/riscv32-toolchain.c
===
--- clang/test/Driver/riscv32-toolchain.c
+++ clang/test/Driver/riscv32-toolchain.c
@@ -68,7 +68,7 @@
 // CXX-RV32-BAREMETAL-NOSYSROOT-ILP32: 
"{{.*}}/Inputs/basic_riscv32_tree/lib/gcc/riscv32-unknown-elf/8.0.1{{/|}}crtend.o"
 
 // RUN: %clang %s -### -no-canonical-prefixes -fuse-ld=ld \
-// RUN:   -target riscv32-unknown-linux-gnu \
+// RUN:   -target riscv32-unknown-linux-gnu -mabi=ilp32 \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
 // RUN:   --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV32-LINUX-MULTI-ILP32 %s
@@ -84,7 +84,7 @@
 // C-RV32-LINUX-MULTI-ILP32: 
"-L{{.*}}/Inputs/multilib_riscv_linux_sdk/sysroot/usr/lib32/ilp32"
 
 // RUN: %clang %s -### -no-canonical-prefixes -fuse-ld=ld \
-// RUN:   -target riscv32-unknown-linux-gnu -march=rv32imafd -mabi=ilp32d \
+// RUN:   -target riscv32-unknown-linux-gnu -march=rv32imafd \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
 // RUN:   --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot 2>&1 \
 // RUN:   | FileCheck -check-prefix=C-RV32-LINUX-MULTI-ILP32D %s
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -379,7 +379,9 @@
   if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
 return A->getValue

r368157 - Replace non-recursive sys::Mutex users with std::mutex

2019-08-07 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Aug  7 04:59:44 2019
New Revision: 368157

URL: http://llvm.org/viewvc/llvm-project?rev=368157&view=rev
Log:
Replace non-recursive sys::Mutex users with std::mutex

Also remove a use of sys::MutexImpl, that's just evil. No functionality
change intended.

Modified:
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/tools/libclang/Indexing.cpp

Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=368157&r1=368156&r2=368157&view=diff
==
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Wed Aug  7 04:59:44 2019
@@ -390,7 +390,7 @@ private:
   /// just about any usage.
   /// Becomes a noop in release mode; only useful for debug mode checking.
   class ConcurrencyState {
-void *Mutex; // a llvm::sys::MutexImpl in debug;
+void *Mutex; // a std::recursive_mutex in debug;
 
   public:
 ConcurrencyState();

Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=368157&r1=368156&r2=368157&view=diff
==
--- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
+++ cfe/trunk/lib/Frontend/ASTUnit.cpp Wed Aug  7 04:59:44 2019
@@ -85,7 +85,6 @@
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Mutex.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
@@ -96,6 +95,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2692,20 +2692,20 @@ InputKind ASTUnit::getInputKind() const
 
 #ifndef NDEBUG
 ASTUnit::ConcurrencyState::ConcurrencyState() {
-  Mutex = new llvm::sys::MutexImpl(/*recursive=*/true);
+  Mutex = new std::recursive_mutex;
 }
 
 ASTUnit::ConcurrencyState::~ConcurrencyState() {
-  delete static_cast(Mutex);
+  delete static_cast(Mutex);
 }
 
 void ASTUnit::ConcurrencyState::start() {
-  bool acquired = static_cast(Mutex)->tryacquire();
+  bool acquired = static_cast(Mutex)->try_lock();
   assert(acquired && "Concurrent access to ASTUnit!");
 }
 
 void ASTUnit::ConcurrencyState::finish() {
-  static_cast(Mutex)->release();
+  static_cast(Mutex)->unlock();
 }
 
 #else // NDEBUG

Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=368157&r1=368156&r2=368157&view=diff
==
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Wed Aug  7 04:59:44 2019
@@ -28,7 +28,6 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Mutex.h"
 #include 
 #include 
 #include 
@@ -122,22 +121,21 @@ namespace llvm {
 namespace {
 
 class SessionSkipBodyData {
-  llvm::sys::Mutex Mux;
+  std::mutex Mux;
   PPRegionSetTy ParsedRegions;
 
 public:
-  SessionSkipBodyData() : Mux(/*recursive=*/false) {}
   ~SessionSkipBodyData() {
 //llvm::errs() << "RegionData: " << Skipped.size() << " - " << 
Skipped.getMemorySize() << "\n";
   }
 
   void copyTo(PPRegionSetTy &Set) {
-std::lock_guard MG(Mux);
+std::lock_guard MG(Mux);
 Set = ParsedRegions;
   }
 
   void update(ArrayRef Regions) {
-std::lock_guard MG(Mux);
+std::lock_guard MG(Mux);
 ParsedRegions.insert(Regions.begin(), Regions.end());
   }
 };


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


[PATCH] D65863: [ARM] Add support for the s,j,x,N,O inline asm constraints

2019-08-07 Thread David Candler via Phabricator via cfe-commits
dcandler created this revision.
dcandler added reviewers: rsmith, t.p.northover, compnerd, void, joerg, 
efriedma, ostannard.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, kristof.beyls, 
javed.absar.
Herald added projects: clang, LLVM.

A number of inline assembly constraints are currently supported by LLVM, but 
rejected as invalid by Clang:

Target independent constraints:

s: An integer constant, but allowing only relocatable values

ARM specific constraints:

j: An immediate integer between 0 and 65535 (valid for MOVW)
x: A 32, 64, or 128-bit floating-point/SIMD register: s0-s15, d0-d7, or q0-q3
N: An immediate integer between 0 and 31 (Thumb1 only)
O: An immediate integer which is a multiple of 4 between -508 and 508. (Thumb1 
only)

This patch adds support to Clang for the missing constraints along with some 
checks to ensure that the constraints are used with the correct target and 
Thumb mode, and that immediates are within valid ranges (at least where 
possible). The constraints are already implemented in LLVM, but just a couple 
of minor corrections to checks (V8M Baseline includes MOVW so should work with 
'j', 'N' and 'O' shouldn't be valid in Thumb2) so that Clang and LLVM are in 
line with each other and the documentation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65863

Files:
  clang/lib/Basic/Targets/ARM.cpp
  clang/test/Sema/arm_inline_asm_constraints.c
  llvm/lib/Target/ARM/ARMISelLowering.cpp

Index: llvm/lib/Target/ARM/ARMISelLowering.cpp
===
--- llvm/lib/Target/ARM/ARMISelLowering.cpp
+++ llvm/lib/Target/ARM/ARMISelLowering.cpp
@@ -15143,7 +15143,7 @@
   case 'j':
 // Constant suitable for movw, must be between 0 and
 // 65535.
-if (Subtarget->hasV6T2Ops())
+if (Subtarget->hasV6T2Ops() || (Subtarget->hasV8MBaselineOps()))
   if (CVal >= 0 && CVal <= 65535)
 break;
 return;
@@ -15251,7 +15251,7 @@
 return;
 
   case 'N':
-if (Subtarget->isThumb()) {  // FIXME thumb2
+if (Subtarget->isThumb1Only()) {
   // This must be a constant between 0 and 31, for shift amounts.
   if (CVal >= 0 && CVal <= 31)
 break;
@@ -15259,7 +15259,7 @@
 return;
 
   case 'O':
-if (Subtarget->isThumb()) {  // FIXME thumb2
+if (Subtarget->isThumb1Only()) {
   // This must be a multiple of 4 between -508 and 508, for
   // ADD/SUB sp = sp + immediate.
   if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0))
Index: clang/test/Sema/arm_inline_asm_constraints.c
===
--- /dev/null
+++ clang/test/Sema/arm_inline_asm_constraints.c
@@ -0,0 +1,305 @@
+// REQUIRES: arm-registered-target
+
+// RUN: %clang_cc1 -triple armv6 -verify=arm6 %s
+// RUN: %clang_cc1 -triple armv7 -verify=arm7 %s
+// RUN: %clang_cc1 -triple thumbv6 -verify=thumb1 %s
+// RUN: %clang_cc1 -triple thumbv7 -verify=thumb2 %s
+
+// j: An immediate integer between 0 and 65535 (valid for MOVW) (ARM/Thumb2)
+int test_j(int i) {
+  int res;
+  __asm("movw %0, %1;"
+: [ result ] "=r"(res)
+: [ constant ] "j"(-1), [ input ] "r"(i)
+:);
+  // arm6-error@13 {{invalid input constraint 'j' in asm}}
+  // arm7-error@13 {{value '-1' out of range for constraint 'j'}}
+  // thumb1-error@13 {{invalid input constraint 'j' in asm}}
+  // thumb2-error@13 {{value '-1' out of range for constraint 'j'}}
+  __asm("movw %0, %1;"
+: [ result ] "=r"(res)
+: [ constant ] "j"(0), [ input ] "r"(i)
+:);
+  // arm6-error@21 {{invalid input constraint 'j' in asm}}
+  // arm7-no-error
+  // thumb1-error@21 {{invalid input constraint 'j' in asm}}
+  // thumb2-no-error
+  __asm("movw %0, %1;"
+: [ result ] "=r"(res)
+: [ constant ] "j"(65535), [ input ] "r"(i)
+:);
+  // arm6-error@29 {{invalid input constraint 'j' in asm}}
+  // arm7-no-error
+  // thumb1-error@29 {{invalid input constraint 'j' in asm}}
+  // thumb2-no-error
+  __asm("movw %0, %1;"
+: [ result ] "=r"(res)
+: [ constant ] "j"(65536), [ input ] "r"(i)
+:);
+  // arm6-error@37 {{invalid input constraint 'j' in asm}}
+  // arm7-error@37 {{value '65536' out of range for constraint 'j'}}
+  // thumb1-error@37 {{invalid input constraint 'j' in asm}}
+  // thumb2-error@37 {{value '65536' out of range for constraint 'j'}}
+  return res;
+}
+
+// I: An immediate integer valid for a data-processing instruction. (ARM/Thumb2)
+//An immediate integer between -255 and -1. (Thumb1)
+int test_I(int i) {
+  int res;
+  __asm(
+  "add %0, %1;"
+  : [ result ] "=r"(res)
+  : [ constant ] "I"(-1), [ input ] "r"(i)
+  :); // thumb1-error@53 {{value '-1' out of range for constraint 'I'}}
+  __asm(
+  "add %0, %1;"
+  : [ result ] "=r"(res)
+  : [ constant ] "I"(0), [ input ] "r"(

r368163 - [ASTImporter] Do not import FunctionTemplateDecl in record twice.

2019-08-07 Thread Balazs Keri via cfe-commits
Author: balazske
Date: Wed Aug  7 05:40:17 2019
New Revision: 368163

URL: http://llvm.org/viewvc/llvm-project?rev=368163&view=rev
Log:
[ASTImporter] Do not import FunctionTemplateDecl in record twice.

Summary:
For functions there is a check to not duplicate the declaration if it is in a
record (class). For function templates there was no similar check, if a
template (in the same class) was imported multiple times the
FunctionTemplateDecl was created multiple times with the same templated
FunctionDecl. This can result in problems with the declaration chain.

Reviewers: martong, a.sidorin, shafik, a_sidorin

Reviewed By: a_sidorin

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/unittests/AST/ASTImporterTest.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=368163&r1=368162&r2=368163&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Wed Aug  7 05:40:17 2019
@@ -3118,9 +3118,19 @@ ExpectedDecl ASTNodeImporter::VisitFunct
   if (FoundByLookup) {
 if (isa(FoundByLookup)) {
   if (D->getLexicalDeclContext() == D->getDeclContext()) {
-if (!D->doesThisDeclarationHaveABody())
+if (!D->doesThisDeclarationHaveABody()) {
+  if (FunctionTemplateDecl *DescribedD =
+  D->getDescribedFunctionTemplate()) {
+// Handle a "templated" function together with its described
+// template. This avoids need for a similar check at import of the
+// described template.
+assert(FoundByLookup->getDescribedFunctionTemplate() &&
+   "Templated function mapped to non-templated?");
+Importer.MapImported(DescribedD,
+ 
FoundByLookup->getDescribedFunctionTemplate());
+  }
   return Importer.MapImported(D, FoundByLookup);
-else {
+} else {
   // Let's continue and build up the redecl chain in this case.
   // FIXME Merge the functions into one decl.
 }

Modified: cfe/trunk/unittests/AST/ASTImporterTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/AST/ASTImporterTest.cpp?rev=368163&r1=368162&r2=368163&view=diff
==
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp (original)
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp Wed Aug  7 05:40:17 2019
@@ -2389,6 +2389,49 @@ TEST_P(ImportFunctions,
 functionDecl(hasName("f"), hasDescendant(declRefExpr()));
 }
 
+struct ImportFunctionTemplates : ASTImporterOptionSpecificTestBase {};
+
+TEST_P(ImportFunctionTemplates, ImportFunctionTemplateInRecordDeclTwice) {
+  auto Code =
+  R"(
+  class X {
+template 
+void f(T t);
+  };
+  )";
+  Decl *FromTU1 = getTuDecl(Code, Lang_CXX, "input1.cc");
+  auto *FromD1 = FirstDeclMatcher().match(
+  FromTU1, functionTemplateDecl(hasName("f")));
+  auto *ToD1 = Import(FromD1, Lang_CXX);
+  Decl *FromTU2 = getTuDecl(Code, Lang_CXX, "input2.cc");
+  auto *FromD2 = FirstDeclMatcher().match(
+  FromTU2, functionTemplateDecl(hasName("f")));
+  auto *ToD2 = Import(FromD2, Lang_CXX);
+  EXPECT_EQ(ToD1, ToD2);
+}
+
+TEST_P(ImportFunctionTemplates,
+   ImportFunctionTemplateWithDefInRecordDeclTwice) {
+  auto Code =
+  R"(
+  class X {
+template 
+void f(T t);
+  };
+  template 
+  void X::f(T t) {};
+  )";
+  Decl *FromTU1 = getTuDecl(Code, Lang_CXX, "input1.cc");
+  auto *FromD1 = FirstDeclMatcher().match(
+  FromTU1, functionTemplateDecl(hasName("f")));
+  auto *ToD1 = Import(FromD1, Lang_CXX);
+  Decl *FromTU2 = getTuDecl(Code, Lang_CXX, "input2.cc");
+  auto *FromD2 = FirstDeclMatcher().match(
+  FromTU2, functionTemplateDecl(hasName("f")));
+  auto *ToD2 = Import(FromD2, Lang_CXX);
+  EXPECT_EQ(ToD1, ToD2);
+}
+
 struct ImportFriendFunctions : ImportFunctions {};
 
 TEST_P(ImportFriendFunctions, ImportFriendFunctionRedeclChainProto) {
@@ -5223,6 +5266,9 @@ INSTANTIATE_TEST_CASE_P(ParameterizedTes
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportClasses,
 DefaultTestValuesForRunOptions, );
 
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFunctionTemplates,
+DefaultTestValuesForRunOptions, );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFriendFunctions,
 DefaultTestValuesForRunOptions, );
 


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


[PATCH] D65203: [ASTImporter] Do not import FunctionTemplateDecl in record twice.

2019-08-07 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368163: [ASTImporter] Do not import FunctionTemplateDecl in 
record twice. (authored by balazske, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65203?vs=211743&id=213858#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65203

Files:
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/unittests/AST/ASTImporterTest.cpp


Index: cfe/trunk/lib/AST/ASTImporter.cpp
===
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -3118,9 +3118,19 @@
   if (FoundByLookup) {
 if (isa(FoundByLookup)) {
   if (D->getLexicalDeclContext() == D->getDeclContext()) {
-if (!D->doesThisDeclarationHaveABody())
+if (!D->doesThisDeclarationHaveABody()) {
+  if (FunctionTemplateDecl *DescribedD =
+  D->getDescribedFunctionTemplate()) {
+// Handle a "templated" function together with its described
+// template. This avoids need for a similar check at import of the
+// described template.
+assert(FoundByLookup->getDescribedFunctionTemplate() &&
+   "Templated function mapped to non-templated?");
+Importer.MapImported(DescribedD,
+ 
FoundByLookup->getDescribedFunctionTemplate());
+  }
   return Importer.MapImported(D, FoundByLookup);
-else {
+} else {
   // Let's continue and build up the redecl chain in this case.
   // FIXME Merge the functions into one decl.
 }
Index: cfe/trunk/unittests/AST/ASTImporterTest.cpp
===
--- cfe/trunk/unittests/AST/ASTImporterTest.cpp
+++ cfe/trunk/unittests/AST/ASTImporterTest.cpp
@@ -2389,6 +2389,49 @@
 functionDecl(hasName("f"), hasDescendant(declRefExpr()));
 }
 
+struct ImportFunctionTemplates : ASTImporterOptionSpecificTestBase {};
+
+TEST_P(ImportFunctionTemplates, ImportFunctionTemplateInRecordDeclTwice) {
+  auto Code =
+  R"(
+  class X {
+template 
+void f(T t);
+  };
+  )";
+  Decl *FromTU1 = getTuDecl(Code, Lang_CXX, "input1.cc");
+  auto *FromD1 = FirstDeclMatcher().match(
+  FromTU1, functionTemplateDecl(hasName("f")));
+  auto *ToD1 = Import(FromD1, Lang_CXX);
+  Decl *FromTU2 = getTuDecl(Code, Lang_CXX, "input2.cc");
+  auto *FromD2 = FirstDeclMatcher().match(
+  FromTU2, functionTemplateDecl(hasName("f")));
+  auto *ToD2 = Import(FromD2, Lang_CXX);
+  EXPECT_EQ(ToD1, ToD2);
+}
+
+TEST_P(ImportFunctionTemplates,
+   ImportFunctionTemplateWithDefInRecordDeclTwice) {
+  auto Code =
+  R"(
+  class X {
+template 
+void f(T t);
+  };
+  template 
+  void X::f(T t) {};
+  )";
+  Decl *FromTU1 = getTuDecl(Code, Lang_CXX, "input1.cc");
+  auto *FromD1 = FirstDeclMatcher().match(
+  FromTU1, functionTemplateDecl(hasName("f")));
+  auto *ToD1 = Import(FromD1, Lang_CXX);
+  Decl *FromTU2 = getTuDecl(Code, Lang_CXX, "input2.cc");
+  auto *FromD2 = FirstDeclMatcher().match(
+  FromTU2, functionTemplateDecl(hasName("f")));
+  auto *ToD2 = Import(FromD2, Lang_CXX);
+  EXPECT_EQ(ToD1, ToD2);
+}
+
 struct ImportFriendFunctions : ImportFunctions {};
 
 TEST_P(ImportFriendFunctions, ImportFriendFunctionRedeclChainProto) {
@@ -5223,6 +5266,9 @@
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportClasses,
 DefaultTestValuesForRunOptions, );
 
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFunctionTemplates,
+DefaultTestValuesForRunOptions, );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFriendFunctions,
 DefaultTestValuesForRunOptions, );
 


Index: cfe/trunk/lib/AST/ASTImporter.cpp
===
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -3118,9 +3118,19 @@
   if (FoundByLookup) {
 if (isa(FoundByLookup)) {
   if (D->getLexicalDeclContext() == D->getDeclContext()) {
-if (!D->doesThisDeclarationHaveABody())
+if (!D->doesThisDeclarationHaveABody()) {
+  if (FunctionTemplateDecl *DescribedD =
+  D->getDescribedFunctionTemplate()) {
+// Handle a "templated" function together with its described
+// template. This avoids need for a similar check at import of the
+// described template.
+assert(FoundByLookup->getDescribedFunctionTemplate() &&
+   "Templated function mapped to non-templated?");
+Importer.MapImported(DescribedD,
+ FoundByLookup->getDescribedFunctionTemplate());

[PATCH] D65866: Code completion should not ignore default parameters in functions.

2019-08-07 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 created this revision.
usaxena95 added a reviewer: sammccall.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous.
Herald added a project: clang.

Inorder to display the default arguments we must process the
CK_Optional chunks of CodeCompletionString while creating the Signature.

We do not create placeholders for default arguments.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65866

Files:
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -10,6 +10,7 @@
 #include "ClangdServer.h"
 #include "CodeComplete.h"
 #include "Compiler.h"
+#include "Logger.h"
 #include "Matchers.h"
 #include "Protocol.h"
 #include "Quality.h"
@@ -939,6 +940,25 @@
 
   EXPECT_TRUE(Results.Completions.empty());
 }
+
+TEST(CompletionTest, DefaultArgs) {
+  clangd::CodeCompleteOptions Opts;
+  std::string Context = R"cpp(
+int X(int A = 0);
+int Y(int A, int B = 0);
+int Z(int A, int B = 0, int C = 0, int D = 0);
+  )cpp";
+  EXPECT_THAT(completions(Context + "int y = X^", {}, Opts).Completions,
+  UnorderedElementsAre(Labeled("X(int A = 0)")));
+  EXPECT_THAT(completions(Context + "int y = Y^", {}, Opts).Completions,
+  UnorderedElementsAre(AllOf(Labeled("Y(int A, int B = 0)"),
+ SnippetSuffix("(${1:int A})";
+  EXPECT_THAT(completions(Context + "int y = Z^", {}, Opts).Completions,
+  UnorderedElementsAre(
+  AllOf(Labeled("Z(int A, int B = 0, int C = 0, int D = 0)"),
+SnippetSuffix("(${1:int A})";
+}
+
 SignatureHelp signatures(llvm::StringRef Text, Position Point,
  std::vector IndexSymbols = {}) {
   std::unique_ptr Index;
Index: clang-tools-extra/clangd/CodeCompletionStrings.cpp
===
--- clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -32,6 +32,21 @@
   }
 }
 
+void appendCodeCompletionString(const CodeCompletionString &CCS, std::string 
*Out) {
+  for (const CodeCompletionString::Chunk &C : CCS) {
+switch (C.Kind) {
+case CodeCompletionString::CK_Optional:
+  assert(C.Optional &&
+ "Expected the optional code completion string to be non-null.");
+  appendCodeCompletionString(*C.Optional, Out);
+  break;
+default:
+  *Out += C.Text;
+  break;
+}
+  }
+}
+
 bool looksLikeDocComment(llvm::StringRef CommentText) {
   // We don't report comments that only contain "special" chars.
   // This avoids reporting various delimiters, like:
@@ -138,6 +153,10 @@
   *Snippet += Chunk.Text;
   break;
 case CodeCompletionString::CK_Optional:
+  assert(Chunk.Optional &&
+ "Expected the optional code completion string to be non-null.");  

+  // No need to create placeholders for default arguments in Snippet.
+  appendCodeCompletionString(*Chunk.Optional, Signature);
   break;
 case CodeCompletionString::CK_Placeholder:
   *Signature += Chunk.Text;


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -10,6 +10,7 @@
 #include "ClangdServer.h"
 #include "CodeComplete.h"
 #include "Compiler.h"
+#include "Logger.h"
 #include "Matchers.h"
 #include "Protocol.h"
 #include "Quality.h"
@@ -939,6 +940,25 @@
 
   EXPECT_TRUE(Results.Completions.empty());
 }
+
+TEST(CompletionTest, DefaultArgs) {
+  clangd::CodeCompleteOptions Opts;
+  std::string Context = R"cpp(
+int X(int A = 0);
+int Y(int A, int B = 0);
+int Z(int A, int B = 0, int C = 0, int D = 0);
+  )cpp";
+  EXPECT_THAT(completions(Context + "int y = X^", {}, Opts).Completions,
+  UnorderedElementsAre(Labeled("X(int A = 0)")));
+  EXPECT_THAT(completions(Context + "int y = Y^", {}, Opts).Completions,
+  UnorderedElementsAre(AllOf(Labeled("Y(int A, int B = 0)"),
+ SnippetSuffix("(${1:int A})";
+  EXPECT_THAT(completions(Context + "int y = Z^", {}, Opts).Completions,
+  UnorderedElementsAre(
+  AllOf(Labeled("Z(int A, int B = 0, int C = 0, int D = 0)"),
+SnippetSuffix("(${1:int A})";
+}
+
 SignatureHelp signatures(llvm::StringRef Text, Position Point,
  std::vector IndexSymbols = {}) {
   std::unique_ptr Index;
Index: clang-tools-extra/clangd/CodeCompletionStrings.cpp
=

r368170 - [OPENMP]Add standard macro value _OPENMP for OpenMP 5.0.

2019-08-07 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Aug  7 07:02:11 2019
New Revision: 368170

URL: http://llvm.org/viewvc/llvm-project?rev=368170&view=rev
Log:
[OPENMP]Add standard macro value _OPENMP for OpenMP 5.0.

According to the OpenMP standard, compiler must define _OPENMP macro,
which has value in format mm, where  is the year of the standard
and mm is the month of the standard. For OpenMP 5.0 this value must be
set to 201811.

Modified:
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/OpenMP/driver.c
cfe/trunk/test/OpenMP/predefined_macro.c

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=368170&r1=368169&r2=368170&view=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Wed Aug  7 07:02:11 2019
@@ -1038,6 +1038,9 @@ static void InitializePredefinedMacros(c
 case 45:
   Builder.defineMacro("_OPENMP", "201511");
   break;
+case 50:
+  Builder.defineMacro("_OPENMP", "201811");
+  break;
 default:
   // Default version is OpenMP 3.1
   Builder.defineMacro("_OPENMP", "201107");

Modified: cfe/trunk/test/OpenMP/driver.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/driver.c?rev=368170&r1=368169&r2=368170&view=diff
==
--- cfe/trunk/test/OpenMP/driver.c (original)
+++ cfe/trunk/test/OpenMP/driver.c Wed Aug  7 07:02:11 2019
@@ -28,6 +28,9 @@
 // CHECK-45-VERSION: #define _OPENMP 201511
 // CHECK-45-VERSION2: #define _OPENMP 201511
 
+// RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=50 | FileCheck 
--check-prefix=CHECK-50-VERSION %s
+// CHECK-50-VERSION: #define _OPENMP 201811
+
 // RUN: %clang %s -c -E -dM -fopenmp-version=1 | FileCheck 
--check-prefix=CHECK-VERSION %s
 // RUN: %clang %s -c -E -dM -fopenmp-version=31 | FileCheck 
--check-prefix=CHECK-VERSION %s
 // RUN: %clang %s -c -E -dM -fopenmp-version=40 | FileCheck 
--check-prefix=CHECK-VERSION %s

Modified: cfe/trunk/test/OpenMP/predefined_macro.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/predefined_macro.c?rev=368170&r1=368169&r2=368170&view=diff
==
--- cfe/trunk/test/OpenMP/predefined_macro.c (original)
+++ cfe/trunk/test/OpenMP/predefined_macro.c Wed Aug  7 07:02:11 2019
@@ -3,6 +3,7 @@
 
 // RUN: %clang_cc1 -fopenmp-simd -verify -o - %s
 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -verify -o - %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=50 -verify -o - %s
 // expected-no-diagnostics
 #ifdef FOPENMP
 // -fopenmp option is specified


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


[PATCH] D65866: Code completion should not ignore default parameters in functions.

2019-08-07 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 213871.
usaxena95 added a comment.

Removed unused include of logger.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65866

Files:
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -939,6 +939,25 @@
 
   EXPECT_TRUE(Results.Completions.empty());
 }
+
+TEST(CompletionTest, DefaultArgs) {
+  clangd::CodeCompleteOptions Opts;
+  std::string Context = R"cpp(
+int X(int A = 0);
+int Y(int A, int B = 0);
+int Z(int A, int B = 0, int C = 0, int D = 0);
+  )cpp";
+  EXPECT_THAT(completions(Context + "int y = X^", {}, Opts).Completions,
+  UnorderedElementsAre(Labeled("X(int A = 0)")));
+  EXPECT_THAT(completions(Context + "int y = Y^", {}, Opts).Completions,
+  UnorderedElementsAre(AllOf(Labeled("Y(int A, int B = 0)"),
+ SnippetSuffix("(${1:int A})";
+  EXPECT_THAT(completions(Context + "int y = Z^", {}, Opts).Completions,
+  UnorderedElementsAre(
+  AllOf(Labeled("Z(int A, int B = 0, int C = 0, int D = 0)"),
+SnippetSuffix("(${1:int A})";
+}
+
 SignatureHelp signatures(llvm::StringRef Text, Position Point,
  std::vector IndexSymbols = {}) {
   std::unique_ptr Index;
Index: clang-tools-extra/clangd/CodeCompletionStrings.cpp
===
--- clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -32,6 +32,21 @@
   }
 }
 
+void appendCodeCompletionString(const CodeCompletionString &CCS, std::string 
*Out) {
+  for (const CodeCompletionString::Chunk &C : CCS) {
+switch (C.Kind) {
+case CodeCompletionString::CK_Optional:
+  assert(C.Optional &&
+ "Expected the optional code completion string to be non-null.");
+  appendCodeCompletionString(*C.Optional, Out);
+  break;
+default:
+  *Out += C.Text;
+  break;
+}
+  }
+}
+
 bool looksLikeDocComment(llvm::StringRef CommentText) {
   // We don't report comments that only contain "special" chars.
   // This avoids reporting various delimiters, like:
@@ -138,6 +153,10 @@
   *Snippet += Chunk.Text;
   break;
 case CodeCompletionString::CK_Optional:
+  assert(Chunk.Optional &&
+ "Expected the optional code completion string to be non-null.");  

+  // No need to create placeholders for default arguments in Snippet.
+  appendCodeCompletionString(*Chunk.Optional, Signature);
   break;
 case CodeCompletionString::CK_Placeholder:
   *Signature += Chunk.Text;


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -939,6 +939,25 @@
 
   EXPECT_TRUE(Results.Completions.empty());
 }
+
+TEST(CompletionTest, DefaultArgs) {
+  clangd::CodeCompleteOptions Opts;
+  std::string Context = R"cpp(
+int X(int A = 0);
+int Y(int A, int B = 0);
+int Z(int A, int B = 0, int C = 0, int D = 0);
+  )cpp";
+  EXPECT_THAT(completions(Context + "int y = X^", {}, Opts).Completions,
+  UnorderedElementsAre(Labeled("X(int A = 0)")));
+  EXPECT_THAT(completions(Context + "int y = Y^", {}, Opts).Completions,
+  UnorderedElementsAre(AllOf(Labeled("Y(int A, int B = 0)"),
+ SnippetSuffix("(${1:int A})";
+  EXPECT_THAT(completions(Context + "int y = Z^", {}, Opts).Completions,
+  UnorderedElementsAre(
+  AllOf(Labeled("Z(int A, int B = 0, int C = 0, int D = 0)"),
+SnippetSuffix("(${1:int A})";
+}
+
 SignatureHelp signatures(llvm::StringRef Text, Position Point,
  std::vector IndexSymbols = {}) {
   std::unique_ptr Index;
Index: clang-tools-extra/clangd/CodeCompletionStrings.cpp
===
--- clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -32,6 +32,21 @@
   }
 }
 
+void appendCodeCompletionString(const CodeCompletionString &CCS, std::string *Out) {
+  for (const CodeCompletionString::Chunk &C : CCS) {
+switch (C.Kind) {
+case CodeCompletionString::CK_Optional:
+  assert(C.Optional &&
+ "Expected the optional code completion string to be non-null.");
+  appendCodeCompletionString(*C.Optional, Out);
+  break;

[PATCH] D65835: [OpenMP] Fix map/is_device_ptr with DSA on combined directive

2019-08-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

`is_device_ptr` can be considered as a kind of mapping clause (see 2.19.7   
Data-Mapping Attribute Rules, Clauses, and Directives), so, I assume, clang 
correct here in terms of OpenMP 4.5.
Thus, I would not call this a "fix", this is just a new feature from OpenMP 5.0.
Plus, these changes are not enough to support this new feature from OpenMP 5.0. 
There definitely must be some changes in the codegen. If the variable is mapped 
in the target construct, we should not generate a code for the private clause 
of this variable on the target construct, since, in this case, private clauses 
are applied for the inner subdirectives, which are the part of the combined 
directive, but not the `target` part of the directive.




Comment at: clang/lib/Sema/SemaOpenMP.cpp:10895
+// combined construct.
+if (CurrDir == OMPD_target) {
   OpenMPClauseKind ConflictKind;

I would suggest to guard this change and limit this new functionality only for 
OpenMP 5.0. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65835



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


[PATCH] D61027: Fix crash on switch conditions of non-integer types in templates

2019-08-07 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews added a comment.

Thanks for taking a look Reid! I rebased the patch and had a conflict with one 
of Richard's patches  and so ran the lit tests again and noticed there are 
several new failures. I am taking a look at those now.


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

https://reviews.llvm.org/D61027



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


r368172 - [OPENMP]Set default version to OpenMP 4.5.

2019-08-07 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Aug  7 07:39:17 2019
New Revision: 368172

URL: http://llvm.org/viewvc/llvm-project?rev=368172&view=rev
Log:
[OPENMP]Set default version to OpenMP 4.5.

Since clang fully supports OpenMP 4.5, set the default version to 4.5
instead of 3.1.

Modified:
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/InitPreprocessor.cpp
cfe/trunk/test/OpenMP/driver.c
cfe/trunk/test/OpenMP/parallel_default_messages.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=368172&r1=368171&r2=368172&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Aug  7 07:39:17 2019
@@ -2894,8 +2894,8 @@ static void ParseLangArgs(LangOptions &O
 }
   }
 
-  // Check if -fopenmp is specified.
-  Opts.OpenMP = Args.hasArg(options::OPT_fopenmp) ? 1 : 0;
+  // Check if -fopenmp is specified and set default version to 4.5.
+  Opts.OpenMP = Args.hasArg(options::OPT_fopenmp) ? 45 : 0;
   // Check if -fopenmp-simd is specified.
   bool IsSimdSpecified =
   Args.hasFlag(options::OPT_fopenmp_simd, options::OPT_fno_openmp_simd,

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=368172&r1=368171&r2=368172&view=diff
==
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Wed Aug  7 07:39:17 2019
@@ -1032,18 +1032,18 @@ static void InitializePredefinedMacros(c
 switch (LangOpts.OpenMP) {
 case 0:
   break;
+case 31:
+  Builder.defineMacro("_OPENMP", "201107");
+  break;
 case 40:
   Builder.defineMacro("_OPENMP", "201307");
   break;
-case 45:
-  Builder.defineMacro("_OPENMP", "201511");
-  break;
 case 50:
   Builder.defineMacro("_OPENMP", "201811");
   break;
 default:
-  // Default version is OpenMP 3.1
-  Builder.defineMacro("_OPENMP", "201107");
+  // Default version is OpenMP 4.5
+  Builder.defineMacro("_OPENMP", "201511");
   break;
 }
   }

Modified: cfe/trunk/test/OpenMP/driver.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/driver.c?rev=368172&r1=368171&r2=368172&view=diff
==
--- cfe/trunk/test/OpenMP/driver.c (original)
+++ cfe/trunk/test/OpenMP/driver.c Wed Aug  7 07:39:17 2019
@@ -15,9 +15,12 @@
 // RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=1 | FileCheck 
--check-prefix=CHECK-DEFAULT-VERSION %s
 // RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=0 | FileCheck 
--check-prefix=CHECK-DEFAULT-VERSION %s
 // RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=100 | FileCheck 
--check-prefix=CHECK-DEFAULT-VERSION %s
-// RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=31 | FileCheck 
--check-prefix=CHECK-DEFAULT-VERSION %s
+// RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=45 | FileCheck 
--check-prefix=CHECK-DEFAULT-VERSION %s
 
-// CHECK-DEFAULT-VERSION: #define _OPENMP 201107
+// CHECK-DEFAULT-VERSION: #define _OPENMP 201511
+
+// RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=31 | FileCheck 
--check-prefix=CHECK-31-VERSION %s
+// CHECK-31-VERSION: #define _OPENMP 201107
 
 // RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=40 | FileCheck 
--check-prefix=CHECK-40-VERSION %s
 // CHECK-40-VERSION: #define _OPENMP 201307

Modified: cfe/trunk/test/OpenMP/parallel_default_messages.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_default_messages.cpp?rev=368172&r1=368171&r2=368172&view=diff
==
--- cfe/trunk/test/OpenMP/parallel_default_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/parallel_default_messages.cpp Wed Aug  7 07:39:17 2019
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 -o - %s -Wuninitialized
+// RUN: %clang_cc1 -verify=expected,ge40 -fopenmp -ferror-limit 100 -o - %s 
-Wuninitialized
 // RUN: %clang_cc1 -verify=expected,ge40 -fopenmp-simd -ferror-limit 100 -o - 
%s -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,ge40 -fopenmp-version=50 -fopenmp 
-ferror-limit 100 -o - %s -Wuninitialized
 // RUN: %clang_cc1 -verify=expected,ge40 -fopenmp-version=40 -fopenmp 
-ferror-limit 100 -o - %s -Wuninitialized


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


[PATCH] D65510: [clangd] Fix implicit template instatiations appearing as topLevelDecls.

2019-08-07 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 213878.
jvikstrom added a comment.

Changed tests to also look at template parameters.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65510

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/ClangdUnit.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -249,6 +249,12 @@
 
   template
   void $Function[[foo]]($TemplateParameter[[T]] ...);
+)cpp",
+R"cpp(
+  template 
+  struct $Class[[Tmpl]] {$TemplateParameter[[T]] $Field[[x]] = 0;};
+  extern template struct $Class[[Tmpl]];
+  template struct $Class[[Tmpl]];
 )cpp"};
   for (const auto &TestCase : TestCases) {
 checkHighlightings(TestCase);
Index: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
@@ -6,13 +6,16 @@
 //
 //===--===//
 
+#include "AST.h"
 #include "Annotations.h"
 #include "ClangdUnit.h"
 #include "SourceCode.h"
 #include "TestTU.h"
+#include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/Support/ScopedPrinter.h"
+#include "gmock/gmock-matchers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -21,6 +24,8 @@
 namespace {
 
 using ::testing::ElementsAre;
+using ::testing::ElementsAreArray;
+using ::testing::AllOf;
 
 TEST(ClangdUnitTest, GetBeginningOfIdentifier) {
   std::string Preamble = R"cpp(
@@ -72,6 +77,28 @@
   return false;
 }
 
+// Matches if the Decl has template args equal to ArgName. If the decl is a
+// NamedDecl and ArgName is an empty string it also matches.
+MATCHER_P(WithTemplateArgs, ArgName, "") {
+  if (const FunctionDecl *FD = dyn_cast(arg)) {
+if (const auto *Args = FD->getTemplateSpecializationArgs()) {
+  std::string SpecializationArgs;
+  // Without the PrintingPolicy "bool" will be printed as "_Bool".
+  LangOptions LO;
+  PrintingPolicy Policy(LO);
+  Policy.adjustForCPlusPlus();
+  for (const auto Arg : Args->asArray()) {
+SpecializationArgs += Arg.getAsType().getAsString(Policy);
+  }
+  return ArgName == SpecializationArgs;
+}
+  }
+  if (const NamedDecl *ND = dyn_cast(arg)) {
+return printTemplateSpecializationArgs(*ND) == ArgName;
+  }
+  return false;
+}
+
 TEST(ClangdUnitTest, TopLevelDecls) {
   TestTU TU;
   TU.HeaderCode = R"(
@@ -103,6 +130,65 @@
   EXPECT_THAT(AST.getLocalTopLevelDecls(), ElementsAre(DeclNamed("main")));
 }
 
+TEST(ClangdUnitTest, DoesNotGetImplicitTemplateTopDecls) {
+  TestTU TU;
+  TU.Code = R"cpp(
+template
+void f(T) {}
+void s() {
+  f(10UL);
+}
+  )cpp";
+
+  auto AST = TU.build();
+  EXPECT_THAT(AST.getLocalTopLevelDecls(),
+  ElementsAre(DeclNamed("f"), DeclNamed("s")));
+}
+
+TEST(ClangdUnitTest,
+ GetsExplicitInstantiationAndSpecializationTemplateTopDecls) {
+  TestTU TU;
+  TU.Code = R"cpp(
+template 
+void f(T) {}
+template<>
+void f(bool);
+template void f(double);
+
+template 
+struct V {};
+template
+struct V {};
+template <>
+struct V {};
+
+template
+T foo = T(10);
+int i = foo;
+double d = foo;
+
+template 
+int foo = 0;
+template <>
+int foo = 0;
+  )cpp";
+
+  auto AST = TU.build();
+  EXPECT_THAT(
+  AST.getLocalTopLevelDecls(),
+  ElementsAreArray({AllOf(DeclNamed("f"), WithTemplateArgs("")),
+AllOf(DeclNamed("f"), WithTemplateArgs("bool")),
+AllOf(DeclNamed("f"), WithTemplateArgs("double")),
+AllOf(DeclNamed("V"), WithTemplateArgs("")),
+AllOf(DeclNamed("V"), WithTemplateArgs("")),
+AllOf(DeclNamed("V"), WithTemplateArgs("")),
+AllOf(DeclNamed("foo"), WithTemplateArgs("")),
+AllOf(DeclNamed("i"), WithTemplateArgs("")),
+AllOf(DeclNamed("d"), WithTemplateArgs("")),
+AllOf(DeclNamed("foo"), WithTemplateArgs("<>")),
+AllOf(DeclNamed("foo"), WithTemplateArgs(""))}));
+}
+
 TEST(ClangdUnitTest, TokensAfterPreamble) {
   TestTU TU;
   TU.AdditionalFiles["foo.h"] = R"(
Index: clang-tools-extra/clangd/CodeComplete.cpp
==

r368173 - Remove LLVM mutexes from clang in favor of std::mutex

2019-08-07 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Aug  7 07:44:40 2019
New Revision: 368173

URL: http://llvm.org/viewvc/llvm-project?rev=368173&view=rev
Log:
Remove LLVM mutexes from clang in favor of std::mutex

None of those need to be recursive mutexes. No functionality change
intended.

Modified:
cfe/trunk/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CIndexer.h
cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Modified: cfe/trunk/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp?rev=368173&r1=368172&r2=368173&view=diff
==
--- cfe/trunk/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp (original)
+++ cfe/trunk/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp Wed Aug  7 
07:44:40 2019
@@ -14,7 +14,6 @@
 #include "llvm/Support/AlignOf.h"
 #include "llvm/Support/Errno.h"
 #include "llvm/Support/Error.h"
-#include "llvm/Support/Mutex.h"
 #include "llvm/Support/Path.h"
 #include 
 #include 

Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=368173&r1=368172&r2=368173&view=diff
==
--- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original)
+++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Wed Aug  7 07:44:40 2019
@@ -27,7 +27,6 @@
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/FileSystem.h"
-#include "llvm/Support/Mutex.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include 
@@ -96,7 +95,7 @@ public:
   void removeFile(StringRef File);
 
 private:
-  llvm::sys::SmartMutex Mutex;
+  std::mutex Mutex;
   llvm::StringSet<> Files;
 };
 
@@ -106,20 +105,20 @@ TemporaryFiles &TemporaryFiles::getInsta
 }
 
 TemporaryFiles::~TemporaryFiles() {
-  std::lock_guard Guard(Mutex);
+  std::lock_guard Guard(Mutex);
   for (const auto &File : Files)
 llvm::sys::fs::remove(File.getKey());
 }
 
 void TemporaryFiles::addFile(StringRef File) {
-  std::lock_guard Guard(Mutex);
+  std::lock_guard Guard(Mutex);
   auto IsInserted = Files.insert(File).second;
   (void)IsInserted;
   assert(IsInserted && "File has already been added");
 }
 
 void TemporaryFiles::removeFile(StringRef File) {
-  std::lock_guard Guard(Mutex);
+  std::lock_guard Guard(Mutex);
   auto WasPresent = Files.erase(File);
   (void)WasPresent;
   assert(WasPresent && "File was not tracked");

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=368173&r1=368172&r2=368173&view=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Wed Aug  7 07:44:40 2019
@@ -45,7 +45,6 @@
 #include "llvm/Support/Format.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Mutex.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/Signals.h"
@@ -53,6 +52,7 @@
 #include "llvm/Support/Threading.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 
 #if LLVM_ENABLE_THREADS != 0 && defined(__APPLE__)
 #define USE_DARWIN_THREADS
@@ -8943,10 +8943,10 @@ Logger &cxindex::Logger::operator<<(cons
   return *this;
 }
 
-static llvm::ManagedStatic LoggingMutex;
+static llvm::ManagedStatic LoggingMutex;
 
 cxindex::Logger::~Logger() {
-  llvm::sys::ScopedLock L(*LoggingMutex);
+  std::lock_guard L(*LoggingMutex);
 
   static llvm::TimeRecord sBeginTR = llvm::TimeRecord::getCurrentTime();
 

Modified: cfe/trunk/tools/libclang/CIndexer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndexer.h?rev=368173&r1=368172&r2=368173&view=diff
==
--- cfe/trunk/tools/libclang/CIndexer.h (original)
+++ cfe/trunk/tools/libclang/CIndexer.h Wed Aug  7 07:44:40 2019
@@ -17,7 +17,6 @@
 #include "clang-c/Index.h"
 #include "clang/Frontend/PCHContainerOperations.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/Mutex.h"
 #include 
 
 namespace llvm {

Modified: cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp?rev=368173&r1=368172&r2=368173&view=diff
==
--- cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp (original)
+++ cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp Wed Aug

[PATCH] D65866: Code completion should not ignore default parameters in functions.

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



Comment at: clang-tools-extra/clangd/CodeCompletionStrings.cpp:35
 
+void appendCodeCompletionString(const CodeCompletionString &CCS, std::string 
*Out) {
+  for (const CodeCompletionString::Chunk &C : CCS) {

maybe appendOptionalChunk? if in doubt, better to describe the semantics of the 
param than its type, since the type appears in the signature



Comment at: clang-tools-extra/clangd/CodeCompletionStrings.cpp:156
 case CodeCompletionString::CK_Optional:
+  assert(Chunk.Optional &&
+ "Expected the optional code completion string to be non-null.");  


please drop the extra message from the assert unless there's something 
additional to say (it just echoes the expression here)

(I don't have a strong opinion on this assert - I'm fine with keeping it but 
you could also drop it as we're enforcing someone else's clearly documented 
invariant)



Comment at: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:943
+
+TEST(CompletionTest, DefaultArgs) {
+  clangd::CodeCompleteOptions Opts;

for completeness, could you also add a unit test to 
CodeCompletionStringsTests.cpp?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65866



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


[PATCH] D65510: [clangd] Fix implicit template instatiations appearing as topLevelDecls.

2019-08-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:85
+if (const auto *Args = FD->getTemplateSpecializationArgs()) {
+  std::string SpecializationArgs;
+  // Without the PrintingPolicy "bool" will be printed as "_Bool".

Could you wrap the result with `<` and `>`, add `,` as a separator?
To make sure the output format for functions is not different for other decls



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:91
+  for (const auto Arg : Args->asArray()) {
+SpecializationArgs += Arg.getAsType().getAsString(Policy);
+  }

NIT: remove braces



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:97
+  if (const NamedDecl *ND = dyn_cast(arg)) {
+return printTemplateSpecializationArgs(*ND) == ArgName;
+  }

NIT: remove braces



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:186
+AllOf(DeclNamed("foo"), WithTemplateArgs("")),
+AllOf(DeclNamed("i"), WithTemplateArgs("")),
+AllOf(DeclNamed("d"), WithTemplateArgs("")),

NIT: do not match `WithTemplateArgs` for non-template names (like `i` and `d` 
here)?



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:188
+AllOf(DeclNamed("d"), WithTemplateArgs("")),
+AllOf(DeclNamed("foo"), WithTemplateArgs("<>")),
+AllOf(DeclNamed("foo"), WithTemplateArgs(""))}));

NIT: add `// FIXME: this should be '', not '<>'`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65510



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


[PATCH] D65510: [clangd] Fix implicit template instatiations appearing as topLevelDecls.

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



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:144
+  EXPECT_THAT(AST.getLocalTopLevelDecls(),
+  ElementsAre(DeclNamed("f"), DeclNamed("f"), DeclNamed("f"),
+  DeclNamed("V"), DeclNamed("V"), DeclNamed("foo"),

ilya-biryukov wrote:
> jvikstrom wrote:
> > ilya-biryukov wrote:
> > > Is there a way to check we are seeing the explicit instantiations? (e.g. 
> > > by looking at template arguments?)
> > > 
> > > It's not clear whether multiple `DeclNamed("foo")` refer to the decls we 
> > > expect.
> > Well in this case all the expressions in the top level should be in 
> > topLevelDecls so unless say `void f(T) {}` somehow starts duplicating while 
> > `void f(bool)` disappears from topLevelDecls they should all be visible.
> > I could add a gtest matcher that also checks the types but I think that 
> > would become a pretty large matcher (would have to handle FunctionDecls 
> > with template arguments, VarDecls, TemplateClassSpecializationDecls etc.) 
> > and I'm not sure it would really add anything to the tests.
> > 
> > A thing we  we could do is shuffle the order of the decls in the test so we 
> > never have two decls of the same name after each other (because the matcher 
> > cares about the order of the elements). Which should give us pretty high 
> > confidence we are getting the correct decls... Or maybe I'm 
> > misunderstanding you?
> The tests should be easy to read and understand, we should definitely find a 
> way to distinguish decls with different arguments.
> Adding a matcher for template args should be easy enough:
> ```
> AllOf(DeclNamed("f"), WithTemplateArgs(""))
> ```
> 
> Implementing the matcher is easy with `printTemplateSpecializationArgs` from 
> `AST.h`
Will fix the partial specialization in a separate CL


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65510



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


[PATCH] D65510: [clangd] Fix implicit template instatiations appearing as topLevelDecls.

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



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:188
+AllOf(DeclNamed("d"), WithTemplateArgs("")),
+AllOf(DeclNamed("foo"), WithTemplateArgs("<>")),
+AllOf(DeclNamed("foo"), WithTemplateArgs(""))}));

ilya-biryukov wrote:
> NIT: add `// FIXME: this should be '', not '<>'`
Already have a fix for it (it's a 2 line fix without the tests, should I just 
add do it in a separate CL or add it to this?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65510



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


[PATCH] D65877: [libTooling] In Transformer, generalize `applyFirst` to admit rules with incompatible matchers.

2019-08-07 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: gribozavr.
Herald added a project: clang.

This patch removes an (artificial) limitation of `applyFirst`, which requires
that all of the rules' matchers can be grouped together in a single `anyOf()`.
This change generalizes the code to group the matchers into separate `anyOf`s
based on compatibility. Correspondingly, `buildMatcher` is changed to
`buildMatchers`, to allow for returning a set of matchers rather than just one.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65877

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

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -482,16 +482,17 @@
   testRule(applyFirst({ruleStrlenSize(), FlagRule}), Input, Expected);
 }
 
-// Version of ruleStrlenSizeAny that inserts a method with a different name than
+// Version of ruleStrlenSize that doesn't check the type of the targeted
+// object. Note that we insert a method with a different name than
 // ruleStrlenSize, so we can tell their effect apart.
-RewriteRule ruleStrlenSizeDistinct() {
+RewriteRule ruleStrlenSizeAny() {
   StringRef S;
   return makeRule(
   callExpr(callee(functionDecl(hasName("strlen"))),
hasArgument(0, cxxMemberCallExpr(
   on(expr().bind(S)),
   callee(cxxMethodDecl(hasName("c_str")),
-  change(text("DISTINCT")));
+  change(text("ANY")));
 }
 
 TEST_F(TransformerTest, OrderedRuleRelated) {
@@ -509,16 +510,18 @@
 struct mystring {
   char* c_str();
 };
-int f(mystring s) { return DISTINCT; }
+int f(mystring s) { return ANY; }
 }  // namespace foo
 int g(string s) { return REPLACED; }
   )cc";
 
-  testRule(applyFirst({ruleStrlenSize(), ruleStrlenSizeDistinct()}), Input,
+  testRule(applyFirst({ruleStrlenSize(), ruleStrlenSizeAny()}), Input,
Expected);
 }
 
-// Change the order of the rules to get a different result.
+// Change the order of the rules to get a different result. When
+// `ruleStrlenSizeAny` comes first, it applies for both uses, so
+// `ruleStrlenSize` never applies.
 TEST_F(TransformerTest, OrderedRuleRelatedSwapped) {
   std::string Input = R"cc(
 namespace foo {
@@ -534,15 +537,51 @@
 struct mystring {
   char* c_str();
 };
-int f(mystring s) { return DISTINCT; }
+int f(mystring s) { return ANY; }
 }  // namespace foo
-int g(string s) { return DISTINCT; }
+int g(string s) { return ANY; }
   )cc";
 
-  testRule(applyFirst({ruleStrlenSizeDistinct(), ruleStrlenSize()}), Input,
+  testRule(applyFirst({ruleStrlenSizeAny(), ruleStrlenSize()}), Input,
Expected);
 }
 
+// Verify that a set of rules whose matchers have different base kinds works
+// properly, including that `applyFirst` produces multiple matchers.
+TEST_F(TransformerTest, OrderedRuleMultipleKinds) {
+  RewriteRule DeclRule = makeRule(functionDecl(hasName("bad")).bind("fun"),
+  change(name("fun"), text("good")));
+  // We test two different kinds of rules: Expr and Decl. We place the Decl rule
+  // in the middle to test that `buildMatchers` works even when the kinds aren't
+  // grouped together.
+  RewriteRule Rule =
+  applyFirst({ruleStrlenSize(), DeclRule, ruleStrlenSizeAny()});
+
+  std::string Input = R"cc(
+namespace foo {
+struct mystring {
+  char* c_str();
+};
+int f(mystring s) { return strlen(s.c_str()); }
+}  // namespace foo
+int g(string s) { return strlen(s.c_str()); }
+int bad(int x);
+  )cc";
+  std::string Expected = R"cc(
+namespace foo {
+struct mystring {
+  char* c_str();
+};
+int f(mystring s) { return ANY; }
+}  // namespace foo
+int g(string s) { return REPLACED; }
+int good(int x);
+  )cc";
+
+  EXPECT_EQ(tooling::detail::buildMatchers(Rule).size(), 2UL);
+  testRule(Rule, Input, Expected);
+}
+
 //
 // Negative tests (where we expect no transformation to occur).
 //
Index: clang/lib/Tooling/Refactoring/Transformer.cpp
===
--- clang/lib/Tooling/Refactoring/Transformer.cpp
+++ clang/lib/Tooling/Refactoring/Transformer.cpp
@@ -91,41 +91,53 @@
   return (A.isSame(TypeKind) && B.isSame(QualKind)) || A.isBaseOf(B);
 }
 
-// Try to find a common kind to which all of the rule's matchers can be
-// converted.
-static ASTNodeKind
-findCommonKind(const SmallVectorImpl &Cases) {
-  assert(!Cases.empty() && "Rule must have at least one case.");
-  ASTNodeKind JoinKind = Cases[0].Matcher.getSupportedKind();
-  // Find a (least) Kind K, for which M.canConvertTo(K) holds, for all matchers
-  // M in Rules.
-  for (c

[PATCH] D65461: [OPENMP]Add support for analysis of linear variables and step.

2019-08-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 213888.
ABataev added a comment.

Rebase


Repository:
  rC Clang

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

https://reviews.llvm.org/D65461

Files:
  include/clang/AST/OpenMPClause.h
  lib/AST/OpenMPClause.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/Analysis/cfg-openmp.cpp
  test/OpenMP/distribute_parallel_for_simd_linear_messages.cpp
  test/OpenMP/distribute_simd_linear_messages.cpp
  test/OpenMP/for_linear_messages.cpp
  test/OpenMP/for_simd_linear_messages.cpp
  test/OpenMP/parallel_for_linear_messages.cpp
  test/OpenMP/parallel_for_simd_linear_messages.cpp
  test/OpenMP/simd_linear_messages.cpp
  test/OpenMP/target_parallel_for_linear_messages.cpp
  test/OpenMP/target_parallel_for_simd_linear_messages.cpp
  test/OpenMP/target_simd_linear_messages.cpp
  test/OpenMP/target_teams_distribute_parallel_for_simd_linear_messages.cpp
  test/OpenMP/target_teams_distribute_simd_linear_messages.cpp
  test/OpenMP/taskloop_simd_linear_messages.cpp
  test/OpenMP/teams_distribute_parallel_for_simd_linear_messages.cpp
  test/OpenMP/teams_distribute_simd_linear_messages.cpp

Index: test/OpenMP/teams_distribute_simd_linear_messages.cpp
===
--- test/OpenMP/teams_distribute_simd_linear_messages.cpp
+++ test/OpenMP/teams_distribute_simd_linear_messages.cpp
@@ -3,6 +3,14 @@
 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
 
 extern int omp_default_mem_alloc;
+void xxx(int argc) {
+  int i, step; // expected-note {{initialize the variable 'step' to silence this warning}} expected-note {{initialize the variable 'i' to silence this warning}}
+#pragma omp target
+#pragma omp teams distribute simd linear(i : step) // expected-warning {{variable 'i' is uninitialized when used here}} expected-warning {{variable 'step' is uninitialized when used here}}
+  for (i = 0; i < 10; ++i)
+;
+}
+
 namespace X {
   int x;
 };
Index: test/OpenMP/teams_distribute_parallel_for_simd_linear_messages.cpp
===
--- test/OpenMP/teams_distribute_parallel_for_simd_linear_messages.cpp
+++ test/OpenMP/teams_distribute_parallel_for_simd_linear_messages.cpp
@@ -3,6 +3,14 @@
 // RUN: %clang_cc1 -verify -fopenmp-simd %s -Wuninitialized
 
 extern int omp_default_mem_alloc;
+void xxx(int argc) {
+  int i, step; // expected-note {{initialize the variable 'step' to silence this warning}} expected-note {{initialize the variable 'i' to silence this warning}}
+#pragma omp target
+#pragma omp teams distribute parallel for simd linear(i : step) // expected-warning {{variable 'i' is uninitialized when used here}} expected-warning {{variable 'step' is uninitialized when used here}}
+  for (i = 0; i < 10; ++i)
+;
+}
+
 namespace X {
   int x;
 };
Index: test/OpenMP/taskloop_simd_linear_messages.cpp
===
--- test/OpenMP/taskloop_simd_linear_messages.cpp
+++ test/OpenMP/taskloop_simd_linear_messages.cpp
@@ -12,6 +12,13 @@
 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
 extern const omp_allocator_handle_t omp_thread_mem_alloc;
 
+void xxx(int argc) {
+  int i, lin, step; // expected-note {{initialize the variable 'lin' to silence this warning}} expected-note {{initialize the variable 'step' to silence this warning}}
+#pragma omp taskloop simd linear(i, lin : step) // expected-warning {{variable 'lin' is uninitialized when used here}} expected-warning {{variable 'step' is uninitialized when used here}}
+  for (i = 0; i < 10; ++i)
+;
+}
+
 namespace X {
   int x;
 };
Index: test/OpenMP/target_teams_distribute_simd_linear_messages.cpp
===
--- test/OpenMP/target_teams_distribute_simd_linear_messages.cpp
+++ test/OpenMP/target_teams_distribute_simd_linear_messages.cpp
@@ -12,6 +12,13 @@
 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
 extern const omp_allocator_handle_t omp_thread_mem_alloc;
 
+void xxx(int argc) {
+  int i, step; // expected-note {{initialize the variable 'step' to silence this warning}}
+#pragma omp target teams distribute simd linear(i : step) // expected-warning {{variable 'step' is uninitialized when used here}}
+  for (i = 0; i < 10; ++i)
+;
+}
+
 namespace X {
   int x;
 };
Index: test/OpenMP/target_teams_distribute_parallel_for_simd_linear_messages.cpp
===
--- test/OpenMP/target_teams_distribute_parallel_for_simd_linear_messages.cpp
+++ test/OpenMP/target_teams_distribute_parallel_for_simd_linear_messages.cpp
@@ -12,6 +12,13 @@
 extern const omp_allocator_handle_t omp_pteam_mem_alloc;
 extern const omp_allocator_handle_t omp_thread_mem_alloc;
 
+void xxx(int argc) {
+  int i, step; // expected-note {{initialize the variable 'step' to silence this warning}}
+#pragma omp tar

[PATCH] D65878: [Refactor] Moving SourceExtraction header from lib to include

2019-08-07 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah created this revision.
SureYeaah added a reviewer: arphaman.
Herald added subscribers: cfe-commits, kadircet, dexonsmith, ilya-biryukov.
Herald added a project: clang.

- Moved the SourceExtraction header from lib to include so that it can

be used in clangd.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65878

Files:
  clang/include/clang/Tooling/Refactoring/Extract/SourceExtraction.h
  clang/lib/Tooling/Refactoring/Extract/Extract.cpp
  clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
  clang/lib/Tooling/Refactoring/Extract/SourceExtraction.h


Index: clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
===
--- clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
+++ clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
@@ -6,7 +6,7 @@
 //
 
//===--===//
 
-#include "SourceExtraction.h"
+#include "clang/Tooling/Refactoring/Extract/SourceExtraction.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
Index: clang/lib/Tooling/Refactoring/Extract/Extract.cpp
===
--- clang/lib/Tooling/Refactoring/Extract/Extract.cpp
+++ clang/lib/Tooling/Refactoring/Extract/Extract.cpp
@@ -13,12 +13,12 @@
 
//===--===//
 
 #include "clang/Tooling/Refactoring/Extract/Extract.h"
-#include "SourceExtraction.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/Refactoring/Extract/SourceExtraction.h"
 
 namespace clang {
 namespace tooling {
Index: clang/include/clang/Tooling/Refactoring/Extract/SourceExtraction.h
===
--- clang/include/clang/Tooling/Refactoring/Extract/SourceExtraction.h
+++ clang/include/clang/Tooling/Refactoring/Extract/SourceExtraction.h
@@ -6,8 +6,8 @@
 //
 
//===--===//
 
-#ifndef LLVM_CLANG_LIB_TOOLING_REFACTORING_EXTRACT_SOURCE_EXTRACTION_H
-#define LLVM_CLANG_LIB_TOOLING_REFACTORING_EXTRACT_SOURCE_EXTRACTION_H
+#ifndef LLVM_CLANG_TOOLING_REFACTORING_EXTRACT_SOURCE_EXTRACTION_H
+#define LLVM_CLANG_TOOLING_REFACTORING_EXTRACT_SOURCE_EXTRACTION_H
 
 #include "clang/Basic/LLVM.h"
 


Index: clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
===
--- clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
+++ clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "SourceExtraction.h"
+#include "clang/Tooling/Refactoring/Extract/SourceExtraction.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
Index: clang/lib/Tooling/Refactoring/Extract/Extract.cpp
===
--- clang/lib/Tooling/Refactoring/Extract/Extract.cpp
+++ clang/lib/Tooling/Refactoring/Extract/Extract.cpp
@@ -13,12 +13,12 @@
 //===--===//
 
 #include "clang/Tooling/Refactoring/Extract/Extract.h"
-#include "SourceExtraction.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/Refactoring/Extract/SourceExtraction.h"
 
 namespace clang {
 namespace tooling {
Index: clang/include/clang/Tooling/Refactoring/Extract/SourceExtraction.h
===
--- clang/include/clang/Tooling/Refactoring/Extract/SourceExtraction.h
+++ clang/include/clang/Tooling/Refactoring/Extract/SourceExtraction.h
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#ifndef LLVM_CLANG_LIB_TOOLING_REFACTORING_EXTRACT_SOURCE_EXTRACTION_H
-#define LLVM_CLANG_LIB_TOOLING_REFACTORING_EXTRACT_SOURCE_EXTRACTION_H
+#ifndef LLVM_CLANG_TOOLING_REFACTORING_EXTRACT_SOURCE_EXTRACTION_H
+#define LLVM_CLANG_TOOLING_REFACTORING_EXTRACT_SOURCE_EXTRACTION_H
 
 #include "clang/Basic/LLVM.h"
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65879: [clang-tidy] Update `TransformerClangTidyCheck` to use new `buildMatchers` functionality.

2019-08-07 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.

`buildMatchers` is the new, more general way to extract the matcher from a rule.
This change migrates the code to use it instead of `buildMatcher`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65879

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


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
@@ -62,7 +62,8 @@
 void TransformerClangTidyCheck::registerMatchers(
 ast_matchers::MatchFinder *Finder) {
   if (Rule)
-Finder->addDynamicMatcher(tooling::detail::buildMatcher(*Rule), this);
+for (auto &Matcher : tooling::detail::buildMatchers(*Rule))
+  Finder->addDynamicMatcher(Matcher, this);
 }
 
 void TransformerClangTidyCheck::check(


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
@@ -62,7 +62,8 @@
 void TransformerClangTidyCheck::registerMatchers(
 ast_matchers::MatchFinder *Finder) {
   if (Rule)
-Finder->addDynamicMatcher(tooling::detail::buildMatcher(*Rule), this);
+for (auto &Matcher : tooling::detail::buildMatchers(*Rule))
+  Finder->addDynamicMatcher(Matcher, this);
 }
 
 void TransformerClangTidyCheck::check(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65065: [clang-tidy] Possibility of displaying duplicate warnings

2019-08-07 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

In D65065#1617031 , @gribozavr wrote:

> > This suggestion would result another strange behavior: if the user disables 
> > cert-err09-cpp because he or she doesn't want to see its reports, the other 
> > one (cert-err61-cpp) will still report the issue. So he or she has to 
> > disable both (or as many aliases it has).
>
> That seems to be the case regardless of the implementation strategy in this 
> patch.


The difference is that without the patch the user will initially see only one 
of the warnings, but after disabling the corresponding check the other warning 
will start appearing. Thus, the behavior with more granular deduplication 
results in a more consistent and less surprising experience.

As noted earlier, warning deduplication can hide different issues in checks 
that would usually better be fixed in the check itself. For example, the 
google-explicit-constructor check used in the test for deduplication 
(https://reviews.llvm.org/D2989) has been fixed since then as were a number of 
other checks.




Comment at: clang-tools-extra/test/clang-tidy/duplicate-reports.cpp:6-7
+  // At this location both cert-err09-cpp and cert-err61-cpp report the
+  // message. The order of the reports is unknown, that's why the checker name
+  // is not included in the expected warning.
+

I believe, this is not true anymore. Including the check name into the 
comparison key should make the order deterministic.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D65065



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


[PATCH] D65880: [Driver] Move LIBRARY_PATH before user inputs

2019-08-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: lichray, phosek, void.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes PR16786

Currently, library paths specified by LIBRARY_PATH are placed after inputs: 
`inputs LIBRARY_PATH stdlib`
In gcc, the order is: `inputs LIBRARY_PATH stdlib` if not cross compiling.
(On Darwin targets, isCrossCompiling() always returns false.)

This patch changes the behavior to match gcc.


Repository:
  rC Clang

https://reviews.llvm.org/D65880

Files:
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/linker-opts.c


Index: test/Driver/linker-opts.c
===
--- test/Driver/linker-opts.c
+++ test/Driver/linker-opts.c
@@ -1,8 +1,10 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
 //
-// RUN: env LIBRARY_PATH=%t/test1 %clang -x c %s -### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target %itanium_abi_triple %s -la 
-### 2>&1 | FileCheck %s
 // CHECK: "-L{{.*}}/test1"
+// CHECK: "{{[^"]+}}.o"
+// CHECK: "-la"
 
 // GCC driver is used as linker on cygming. It should be aware of LIBRARY_PATH.
 // XFAIL: windows-msvc
@@ -10,8 +12,8 @@
 // REQUIRES: native
 
 // Make sure that LIBRARY_PATH works for both i386 and x86_64 on Darwin.
-// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -### 
2>&1 | FileCheck %s
-// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin  %s -### 
2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -la 
-### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin %s -la -### 
2>&1 | FileCheck %s
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -145,6 +145,11 @@
   // (constructed via -Xarch_).
   Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
 
+  // LIBRARY_PATH - included following the user specified library paths.
+  //and only supported on native toolchains.
+  if (!TC.isCrossCompiling())
+addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
+
   for (const auto &II : Inputs) {
 // If the current tool chain refers to an OpenMP or HIP offloading host, we
 // should ignore inputs that refer to OpenMP or HIP offloading devices -
@@ -182,12 +187,6 @@
   A.renderAsInput(Args, CmdArgs);
 }
   }
-
-  // LIBRARY_PATH - included following the user specified library paths.
-  //and only supported on native toolchains.
-  if (!TC.isCrossCompiling()) {
-addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
-  }
 }
 
 void tools::AddTargetFeature(const ArgList &Args,


Index: test/Driver/linker-opts.c
===
--- test/Driver/linker-opts.c
+++ test/Driver/linker-opts.c
@@ -1,8 +1,10 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
 //
-// RUN: env LIBRARY_PATH=%t/test1 %clang -x c %s -### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target %itanium_abi_triple %s -la -### 2>&1 | FileCheck %s
 // CHECK: "-L{{.*}}/test1"
+// CHECK: "{{[^"]+}}.o"
+// CHECK: "-la"
 
 // GCC driver is used as linker on cygming. It should be aware of LIBRARY_PATH.
 // XFAIL: windows-msvc
@@ -10,8 +12,8 @@
 // REQUIRES: native
 
 // Make sure that LIBRARY_PATH works for both i386 and x86_64 on Darwin.
-// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -### 2>&1 | FileCheck %s
-// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin  %s -### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -la -### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin %s -la -### 2>&1 | FileCheck %s
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -145,6 +145,11 @@
   // (constructed via -Xarch_).
   Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
 
+  // LIBRARY_PATH - included following the user specified library paths.
+  //and only supported on native toolchains.
+  if (!TC.isCrossCompiling())
+addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
+
   for (const auto &II : Inputs) {
 // If the current tool chain refers to an OpenMP or HIP offloading host, we
 // should ignore inputs that refer to OpenMP or HIP offloading devices -
@@ -182,12 +187,6 @@
   A.renderAsInput(Args, CmdArgs);
 }
   }
-
-  // LIBRARY_PATH - included following the user specified library paths.
-  //

[PATCH] D65881: [Driver] Move LIBRARY_PATH before user inputs

2019-08-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: lichray, phosek, void.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes PR16786

Currently, library paths specified by LIBRARY_PATH are placed after inputs: 
`inputs LIBRARY_PATH stdlib`
In gcc, the order is: `inputs LIBRARY_PATH stdlib` if not cross compiling.
(On Darwin targets, isCrossCompiling() always returns false.)

This patch changes the behavior to match gcc.


Repository:
  rC Clang

https://reviews.llvm.org/D65881

Files:
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/linker-opts.c


Index: test/Driver/linker-opts.c
===
--- test/Driver/linker-opts.c
+++ test/Driver/linker-opts.c
@@ -1,8 +1,10 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
 //
-// RUN: env LIBRARY_PATH=%t/test1 %clang -x c %s -### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target %itanium_abi_triple %s -la 
-### 2>&1 | FileCheck %s
 // CHECK: "-L{{.*}}/test1"
+// CHECK: "{{[^"]+}}.o"
+// CHECK: "-la"
 
 // GCC driver is used as linker on cygming. It should be aware of LIBRARY_PATH.
 // XFAIL: windows-msvc
@@ -10,8 +12,8 @@
 // REQUIRES: native
 
 // Make sure that LIBRARY_PATH works for both i386 and x86_64 on Darwin.
-// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -### 
2>&1 | FileCheck %s
-// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin  %s -### 
2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -la 
-### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin %s -la -### 
2>&1 | FileCheck %s
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -145,6 +145,11 @@
   // (constructed via -Xarch_).
   Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
 
+  // LIBRARY_PATH are included before user inputs and only supported on native
+  // toolchains.
+  if (!TC.isCrossCompiling())
+addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
+
   for (const auto &II : Inputs) {
 // If the current tool chain refers to an OpenMP or HIP offloading host, we
 // should ignore inputs that refer to OpenMP or HIP offloading devices -
@@ -182,12 +187,6 @@
   A.renderAsInput(Args, CmdArgs);
 }
   }
-
-  // LIBRARY_PATH - included following the user specified library paths.
-  //and only supported on native toolchains.
-  if (!TC.isCrossCompiling()) {
-addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
-  }
 }
 
 void tools::AddTargetFeature(const ArgList &Args,


Index: test/Driver/linker-opts.c
===
--- test/Driver/linker-opts.c
+++ test/Driver/linker-opts.c
@@ -1,8 +1,10 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
 //
-// RUN: env LIBRARY_PATH=%t/test1 %clang -x c %s -### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target %itanium_abi_triple %s -la -### 2>&1 | FileCheck %s
 // CHECK: "-L{{.*}}/test1"
+// CHECK: "{{[^"]+}}.o"
+// CHECK: "-la"
 
 // GCC driver is used as linker on cygming. It should be aware of LIBRARY_PATH.
 // XFAIL: windows-msvc
@@ -10,8 +12,8 @@
 // REQUIRES: native
 
 // Make sure that LIBRARY_PATH works for both i386 and x86_64 on Darwin.
-// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -### 2>&1 | FileCheck %s
-// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin  %s -### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -la -### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin %s -la -### 2>&1 | FileCheck %s
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -145,6 +145,11 @@
   // (constructed via -Xarch_).
   Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
 
+  // LIBRARY_PATH are included before user inputs and only supported on native
+  // toolchains.
+  if (!TC.isCrossCompiling())
+addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
+
   for (const auto &II : Inputs) {
 // If the current tool chain refers to an OpenMP or HIP offloading host, we
 // should ignore inputs that refer to OpenMP or HIP offloading devices -
@@ -182,12 +187,6 @@
   A.renderAsInput(Args, CmdArgs);
 }
   }
-
-  // LIBRARY_PATH - included following the user specified library paths.
-  //and only supported on native toolchains.
-  if (!TC.isCrossCompiling

[PATCH] D65881: [Driver] Move LIBRARY_PATH before user inputs

2019-08-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay abandoned this revision.
MaskRay added a comment.

Sorry. Accidentally created a duplicate one by my arc diff..


Repository:
  rC Clang

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

https://reviews.llvm.org/D65881



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


[PATCH] D65883: [Extract] Fixed SemicolonExtractionPolicy for Do and Switch Stmt

2019-08-07 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah created this revision.
SureYeaah added reviewers: arphaman, sammccall.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65883

Files:
  clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp


Index: clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
===
--- clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
+++ clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
@@ -36,12 +36,17 @@
 return isSemicolonRequiredAfter(While->getBody());
   if (const auto *For = dyn_cast(S))
 return isSemicolonRequiredAfter(For->getBody());
+  if (const auto *Do = dyn_cast(S))
+return isSemicolonRequiredAfter(Do->getBody());
   if (const auto *CXXFor = dyn_cast(S))
 return isSemicolonRequiredAfter(CXXFor->getBody());
   if (const auto *ObjCFor = dyn_cast(S))
 return isSemicolonRequiredAfter(ObjCFor->getBody());
+  if(const auto *Switch = dyn_cast(S))
+return isSemicolonRequiredAfter(Switch->getBody());
+  if(const auto *Case = dyn_cast(S))
+return isSemicolonRequiredAfter(Case->getSubStmt());
   switch (S->getStmtClass()) {
-  case Stmt::SwitchStmtClass:
   case Stmt::CXXTryStmtClass:
   case Stmt::ObjCAtSynchronizedStmtClass:
   case Stmt::ObjCAutoreleasePoolStmtClass:


Index: clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
===
--- clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
+++ clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
@@ -36,12 +36,17 @@
 return isSemicolonRequiredAfter(While->getBody());
   if (const auto *For = dyn_cast(S))
 return isSemicolonRequiredAfter(For->getBody());
+  if (const auto *Do = dyn_cast(S))
+return isSemicolonRequiredAfter(Do->getBody());
   if (const auto *CXXFor = dyn_cast(S))
 return isSemicolonRequiredAfter(CXXFor->getBody());
   if (const auto *ObjCFor = dyn_cast(S))
 return isSemicolonRequiredAfter(ObjCFor->getBody());
+  if(const auto *Switch = dyn_cast(S))
+return isSemicolonRequiredAfter(Switch->getBody());
+  if(const auto *Case = dyn_cast(S))
+return isSemicolonRequiredAfter(Case->getSubStmt());
   switch (S->getStmtClass()) {
-  case Stmt::SwitchStmtClass:
   case Stmt::CXXTryStmtClass:
   case Stmt::ObjCAtSynchronizedStmtClass:
   case Stmt::ObjCAutoreleasePoolStmtClass:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65456: [OpenCL] Add generic type handling for builtin functions

2019-08-07 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh marked 23 inline comments as done.
svenvh added a subscriber: Pierre.
svenvh added inline comments.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:51
-// Helper class to store type access qualifiers (volatile, const, ...).
-class Qualifier {
-  string QualName = _QualName;

Anastasia wrote:
> Are the qualifiers added elsewhere?
Good point, this change should be part of the next patch (D63442).  I've taken 
it out of this patch.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:221
+
+// GenType definitions.
+def FGenTypeN   : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;

Anastasia wrote:
> Is this float GenType?
We will be adding more definitions for integers here in followup patches.



Comment at: clang/lib/Sema/OpenCLBuiltins.td:222
+// GenType definitions.
+def FGenTypeN   : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
+// Generate basic GenTypes.  Names are like: GenTypeFloatVecAndScalar.

Anastasia wrote:
> Would it make sense to use the same name scheme as below?
No, because FGenType is for all floating point types (half / float / double), 
as it uses the `TLFloat` type list.  `GenTypeFloatVecAndScalar` is for the 
float type (i.e. fp32) only.

I will update the comments of both definitions to clarify the difference.



Comment at: clang/lib/Sema/SemaLookup.cpp:680
+/// \param OpenCLBuiltin (in) The signature currently handled.
+/// \param GenTypeMaxCnt (out) Maximum number of types contained in a generic
+///type used as return type or as argument.

Anastasia wrote:
> What if both return and args use GenType, does `GenTypeMaxCnt` return max of 
> all? Or do they have to align?
They have to be compatible, otherwise we will hit the `llvm_reachable` below.



Comment at: clang/lib/Sema/SemaLookup.cpp:708
+  }
+  for (unsigned Index = 0; Index < ArgTypes.size(); Index++) {
+unsigned TypeCntAtIndex = ArgTypes[Index].size();

Anastasia wrote:
> I don't get this logic?
While trying to clarify this, I realized this checking should probably be moved 
to the TableGen emitter, as this is checking validity of the .td input so 
ideally we should check that at compiler compile time.  @Pierre mentioned that 
this might not be trivial, but I'll have a look at it.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:70
 namespace {
 class BuiltinNameEmitter {
 public:

Anastasia wrote:
> Perhaps not something for this patch, but I am wondering if a better name for 
> this class would be `OpenCLBuiltinTrieEmitter`?
It's emitting more than a trie; also tables and structs.  How about 
`OpenCLBuiltinEmitter` (which aligns nicely with the file name)?



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:94
+  // \param List (out) List to fill with the extracted types.
+  void ExtractEnumTypes(std::vector &Types,
+StringMap &TypesSeen, std::string &Output,

Anastasia wrote:
> I am a bit confused about the purpose of this function as input and output 
> seem to be both vectors of the Record. It might make sense to explain the 
> difference. :)
Clarified comment.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:225
+
+  // Generic types are defined at the end of the enum.
+  std::vector GenTypes =

Anastasia wrote:
> I find this comment confusing... may be because it belongs to the code later. 
> I am not sure it adds any value.
Elaborated.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:281
 auto it =
-std::find_if(SignatureSet.begin(), SignatureSet.end(),
+std::find_if(SignaturesList.begin(), SignaturesList.end(),
  [&](const std::pair, unsigned> &a) {

Anastasia wrote:
> Is this logic to avoid duplicate signatures? If so it might be worth 
> explaining it.
Added comment.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:377
+// is returned.
+static void OCL2Qual(ASTContext &Context, const OpenCLTypeStruct &Ty,
+ std::vector &QT) {

Anastasia wrote:
> I feel it would be good to explain the structure of the function we are 
> trying to generate i.e something like:
> - We first generate switch/case statement over all type names that populates 
> the list of type IDs
> - Then we walk over the type IDs from the list and map them to the AST type 
> and attributes accordingly.
Added comment.



Comment at: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp:404
+// the plain scalar types for now; the ExtVector type will be added after
+// the switch statement such that it is only added for the case matching
+// the input to the OCL2Qual function.

Anastasia wrote:
> I am not sure what you

[PATCH] D65456: [OpenCL] Add generic type handling for builtin functions

2019-08-07 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh updated this revision to Diff 213904.
svenvh marked 9 inline comments as done.
svenvh added a comment.

Addressing review comments.


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

https://reviews.llvm.org/D65456

Files:
  clang/lib/Sema/OpenCLBuiltins.td
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
  clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Index: clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
===
--- clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -15,12 +15,39 @@
 //
 // For a successful lookup of e.g. the "cos" builtin, isOpenCLBuiltin("cos")
 // returns a pair .
-// OpenCLBuiltins[Index] to OpenCLBuiltins[Index + Len] contains the pairs
+// BuiltinTable[Index] to BuiltinTable[Index + Len] contains the pairs
 //  of the overloads of "cos".
-// OpenCLSignature[SigIndex] to OpenCLSignature[SigIndex + SigLen] contains
-// one of the signatures of "cos". The OpenCLSignature entry can be
-// referenced by other functions, i.e. "sin", since multiple OpenCL builtins
-// share the same signature.
+// SignatureTable[SigIndex] to SignatureTable[SigIndex + SigLen] contains
+// one of the signatures of "cos". The SignatureTable entry can be
+// referenced by other functions, e.g. "sin", to exploit the fact that
+// many OpenCL builtins share the same signature.
+//
+// The file generated by this TableGen emitter contains the following:
+//
+//  * Structs and enums to represent types and function signatures.
+//
+//  * OpenCLTypeStruct TypeTable[]
+//Type information for return types and arguments.
+//
+//  * unsigned SignatureTable[]
+//A list of types representing function signatures.  Each entry is an index
+//into the above TypeTable.  Multiple entries following each other form a
+//signature, where the first entry is the return type and subsequent
+//entries are the argument types.
+//
+//  * OpenCLBuiltinStruct BuiltinTable[]
+//Each entry represents one overload of an OpenCL builtin function and
+//consists of an index into the SignatureTable and the number of arguments.
+//
+//  * std::pair isOpenCLBuiltin(llvm::StringRef Name)
+//Find out whether a string matches an existing OpenCL builtin function
+//name and return an index into BuiltinTable and the number of overloads.
+//
+//  * void OCL2Qual(ASTContext&, OpenCLTypeStruct, std::vector&)
+//Convert an OpenCLTypeStruct type to a list of QualType instances.
+//One OpenCLTypeStruct can represent multiple types, primarily when using
+//GenTypes.
+//
 //===--===//
 
 #include "llvm/ADT/MapVector.h"
@@ -57,34 +84,47 @@
   // The output file.
   raw_ostream &OS;
 
-  // Emit the enums and structs.
+  // Helper function for BuiltinNameEmitter::EmitDeclarations.  Generate enum
+  // definitions in the Output string parameter, and save their Record instances
+  // in the List parameter.
+  // \param Types (in) List containing the Types to extract.
+  // \param TypesSeen (inout) List containing the Types already extracted.
+  // \param Output (out) String containing the enums to emit in the output file.
+  // \param List (out) List containing the extracted Types, except the Types in
+  //TypesSeen.
+  void ExtractEnumTypes(std::vector &Types,
+StringMap &TypesSeen, std::string &Output,
+std::vector &List);
+
+  // Emit the enum or struct used in the generated file.
+  // Populate the TypeList at the same time.
   void EmitDeclarations();
 
-  // Parse the Records generated by TableGen and populate OverloadInfo and
-  // SignatureSet.
+  // Parse the Records generated by TableGen to populate the SignaturesList,
+  // FctOverloadMap and TypeMap.
   void GetOverloads();
 
-  // Emit the OpenCLSignature table. This table contains all possible
-  // signatures, and is a struct OpenCLType. A signature is composed of a
-  // return type (mandatory), followed by zero or more argument types.
+  // Emit the TypeTable containing all types used by OpenCL builtins.
+  void EmitTypeTable();
+
+  // Emit the SignatureTable. This table contains all the possible signatures.
+  // A signature is stored as a list of indexes of the TypeTable.
+  // The first index references the return type (mandatory), and the followings
+  // reference its arguments.
   // E.g.:
-  // // 12
-  // { OCLT_uchar, 4, clang::LangAS::Default, false },
-  // { OCLT_float, 4, clang::LangAS::Default, false },
-  // This means that index 12 represents a signature
-  //   - returning a uchar vector of 4 elements, and
-  //   - taking as first argument a float vector of 4 elements.
+  // 15, 2, 15 can represent a function with the signature:
+  // int func(float, int)
+  // The "int" type being at the index 15 in the TypeTable.
   void Emit

[PATCH] D65880: [Driver] Move LIBRARY_PATH before user inputs

2019-08-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 213908.
MaskRay added a comment.

Fix a comment


Repository:
  rC Clang

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

https://reviews.llvm.org/D65880

Files:
  lib/Driver/ToolChains/CommonArgs.cpp
  test/Driver/linker-opts.c


Index: test/Driver/linker-opts.c
===
--- test/Driver/linker-opts.c
+++ test/Driver/linker-opts.c
@@ -1,8 +1,10 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
 //
-// RUN: env LIBRARY_PATH=%t/test1 %clang -x c %s -### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target %itanium_abi_triple %s -la 
-### 2>&1 | FileCheck %s
 // CHECK: "-L{{.*}}/test1"
+// CHECK: "{{[^"]+}}.o"
+// CHECK: "-la"
 
 // GCC driver is used as linker on cygming. It should be aware of LIBRARY_PATH.
 // XFAIL: windows-msvc
@@ -10,8 +12,8 @@
 // REQUIRES: native
 
 // Make sure that LIBRARY_PATH works for both i386 and x86_64 on Darwin.
-// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -### 
2>&1 | FileCheck %s
-// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin  %s -### 
2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -la 
-### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin %s -la -### 
2>&1 | FileCheck %s
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -145,6 +145,11 @@
   // (constructed via -Xarch_).
   Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
 
+  // LIBRARY_PATH are included before user inputs and only supported on native
+  // toolchains.
+  if (!TC.isCrossCompiling())
+addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
+
   for (const auto &II : Inputs) {
 // If the current tool chain refers to an OpenMP or HIP offloading host, we
 // should ignore inputs that refer to OpenMP or HIP offloading devices -
@@ -182,12 +187,6 @@
   A.renderAsInput(Args, CmdArgs);
 }
   }
-
-  // LIBRARY_PATH - included following the user specified library paths.
-  //and only supported on native toolchains.
-  if (!TC.isCrossCompiling()) {
-addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
-  }
 }
 
 void tools::AddTargetFeature(const ArgList &Args,


Index: test/Driver/linker-opts.c
===
--- test/Driver/linker-opts.c
+++ test/Driver/linker-opts.c
@@ -1,8 +1,10 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
 //
-// RUN: env LIBRARY_PATH=%t/test1 %clang -x c %s -### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target %itanium_abi_triple %s -la -### 2>&1 | FileCheck %s
 // CHECK: "-L{{.*}}/test1"
+// CHECK: "{{[^"]+}}.o"
+// CHECK: "-la"
 
 // GCC driver is used as linker on cygming. It should be aware of LIBRARY_PATH.
 // XFAIL: windows-msvc
@@ -10,8 +12,8 @@
 // REQUIRES: native
 
 // Make sure that LIBRARY_PATH works for both i386 and x86_64 on Darwin.
-// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -### 2>&1 | FileCheck %s
-// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin  %s -### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target x86_64-apple-darwin %s -la -### 2>&1 | FileCheck %s
+// RUN: env LIBRARY_PATH=%t/test1 %clang -target i386-apple-darwin %s -la -### 2>&1 | FileCheck %s
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -145,6 +145,11 @@
   // (constructed via -Xarch_).
   Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
 
+  // LIBRARY_PATH are included before user inputs and only supported on native
+  // toolchains.
+  if (!TC.isCrossCompiling())
+addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
+
   for (const auto &II : Inputs) {
 // If the current tool chain refers to an OpenMP or HIP offloading host, we
 // should ignore inputs that refer to OpenMP or HIP offloading devices -
@@ -182,12 +187,6 @@
   A.renderAsInput(Args, CmdArgs);
 }
   }
-
-  // LIBRARY_PATH - included following the user specified library paths.
-  //and only supported on native toolchains.
-  if (!TC.isCrossCompiling()) {
-addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
-  }
 }
 
 void tools::AddTargetFeature(const ArgList &Args,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65883: [Extract] Fixed SemicolonExtractionPolicy for SwitchStmt and SwitchCase

2019-08-07 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah updated this revision to Diff 213909.
SureYeaah added a comment.

Removed Do


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65883

Files:
  clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp


Index: clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
===
--- clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
+++ clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
@@ -40,8 +40,11 @@
 return isSemicolonRequiredAfter(CXXFor->getBody());
   if (const auto *ObjCFor = dyn_cast(S))
 return isSemicolonRequiredAfter(ObjCFor->getBody());
+  if(const auto *Switch = dyn_cast(S))
+return isSemicolonRequiredAfter(Switch->getBody());
+  if(const auto *Case = dyn_cast(S))
+return isSemicolonRequiredAfter(Case->getSubStmt());
   switch (S->getStmtClass()) {
-  case Stmt::SwitchStmtClass:
   case Stmt::CXXTryStmtClass:
   case Stmt::ObjCAtSynchronizedStmtClass:
   case Stmt::ObjCAutoreleasePoolStmtClass:


Index: clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
===
--- clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
+++ clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
@@ -40,8 +40,11 @@
 return isSemicolonRequiredAfter(CXXFor->getBody());
   if (const auto *ObjCFor = dyn_cast(S))
 return isSemicolonRequiredAfter(ObjCFor->getBody());
+  if(const auto *Switch = dyn_cast(S))
+return isSemicolonRequiredAfter(Switch->getBody());
+  if(const auto *Case = dyn_cast(S))
+return isSemicolonRequiredAfter(Case->getSubStmt());
   switch (S->getStmtClass()) {
-  case Stmt::SwitchStmtClass:
   case Stmt::CXXTryStmtClass:
   case Stmt::ObjCAtSynchronizedStmtClass:
   case Stmt::ObjCAutoreleasePoolStmtClass:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65234: [CodeGen]: don't treat structures returned in registers as memory inputs

2019-08-07 Thread Alexander Potapenko via Phabricator via cfe-commits
glider marked an inline comment as done.
glider added a comment.

In D65234#1615649 , @efriedma wrote:

> For the "=x" thing I was talking about, try the following testcase:
>
>   void a() { struct S { unsigned x[4]; } z; asm volatile("%0":"=x"(z)); }
>   void a2() { struct S { unsigned x[8]; } z; asm volatile("%0":"=x"(z)); }
>
>
> clang trunk gives "error: couldn't allocate output register for constraint 
> 'x'" in the backend for both functions.  gcc prints "%xmm0" for the first, 
> and rejects the second; not exactly sure why it's rejecting the second, 
> though.  It would be nice if both worked, although I guess it's okay if we 
> print a reasonable error message.  Please add a testcase, at least.


Note that this is invalid assembly, as it emits a register name instead of an 
assembly instruction. I don't think it should work at all.
If we replace "%0" with a "nop", Clang will reject the second test, but will 
accept the first one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65234



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


[PATCH] D65234: [CodeGen]: don't treat structures returned in registers as memory inputs

2019-08-07 Thread Alexander Potapenko via Phabricator via cfe-commits
glider updated this revision to Diff 213920.
glider added a comment.

Added test cases for =x, replaced grep with not


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65234

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/asm-attrs.c
  clang/test/CodeGen/x86_64-PR42672.c

Index: clang/test/CodeGen/x86_64-PR42672.c
===
--- /dev/null
+++ clang/test/CodeGen/x86_64-PR42672.c
@@ -0,0 +1,102 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -DSTRUCT -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-STRUCT
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -USTRUCT -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NOSTRUCT
+// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_ODD -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_ODD
+// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_BIG -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_BIG
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -DPOSSIBLE_X -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-X
+// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_X -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_X
+
+// Make sure Clang doesn't treat |lockval| as asm input.
+void _raw_spin_lock(void) {
+#ifdef STRUCT
+  struct {
+unsigned short owner, next;
+  } lockval;
+  lockval.owner = 1;
+  lockval.next = 2;
+#else
+  int lockval;
+  lockval = 3;
+#endif
+  asm("nop"
+  : "=r"(lockval));
+}
+// CHECK-LABEL: _raw_spin_lock
+// CHECK-LABEL: entry:
+
+// CHECK-STRUCT:  %lockval = alloca %struct.anon, align 2
+// CHECK-STRUCT:  store i16 1
+// CHECK-STRUCT:  store i16 2
+// CHECK-STRUCT: [[RES:%[0-9]+]] = call i32 asm "nop", "=r,~{dirflag},~{fpsr},~{flags}"()
+// CHECK-STRUCT: [[CAST:%[0-9]+]] = bitcast %struct.anon* %lockval to i32*
+// CHECK-STRUCT: store i32 [[RES]], i32* [[CAST]], align 2
+
+// CHECK-NOSTRUCT: %lockval = alloca i32, align 4
+// CHECK-NOSTRUCT: store i32 3
+// CHECK-NOSTRUCT:  [[RES:%[0-9]+]] = call i32 asm "nop", "=r,~{dirflag},~{fpsr},~{flags}"()
+// CHECK-NOSTRUCT: store i32 [[RES]], i32* %lockval, align 4
+
+// Check Clang correctly handles a structure with padding.
+void unusual_struct(void) {
+  struct {
+unsigned short first;
+unsigned char second;
+  } str;
+  asm("nop"
+  : "=r"(str));
+}
+
+// Check Clang reports an error if attempting to return a structure for which
+// no direct conversion to a register is possible.
+void odd_struct(void) {
+#ifdef IMPOSSIBLE_ODD
+  struct __attribute__((__packed__)) {
+unsigned short first;
+unsigned char second;
+  } str;
+  asm("nop"
+  : "=r"(str));
+#endif
+}
+// CHECK-IMPOSSIBLE_ODD: impossible constraint in asm
+
+// Check Clang reports an error if attempting to return a big structure via a register.
+void big_struct(void) {
+#ifdef IMPOSSIBLE_BIG
+  struct {
+long long int v1, v2, v3, v4;
+  } str;
+  asm("nop"
+  : "=r"(str));
+#endif
+}
+// CHECK-IMPOSSIBLE_BIG: impossible constraint in asm
+
+// Clang is able to emit LLVM IR for an 16-byte structure.
+void x_constraint_fit() {
+#ifdef POSSIBLE_X
+  struct S {
+unsigned x[4];
+  } z;
+  asm volatile("nop"
+   : "=x"(z));
+#endif
+}
+// CHECK-LABEL: x_constraint_fit
+// CHECK-X: %z = alloca %struct.S, align 4
+// CHECK-X: [[RES:%[0-9]+]] = call i128 asm sideeffect "nop", "=x,~{dirflag},~{fpsr},~{flags}"()
+// CHECK-X: [[CAST:%[0-9]+]] = bitcast %struct.S* %z to i128*
+// CHECK-X: store i128 [[RES]], i128* [[CAST]], align 4
+// CHECK-X: ret
+
+// Clang is unable to emit LLVM IR for a 32-byte structure.
+void x_constraint_nofit() {
+#ifdef IMPOSSIBLE_X
+  struct S {
+unsigned x[8];
+  } z;
+  asm volatile("nop"
+   : "=x"(z));
+#endif
+}
+
+// CHECK-IMPOSSIBLE_X: invalid output size for constraint
Index: clang/test/CodeGen/asm-attrs.c
===
--- clang/test/CodeGen/asm-attrs.c
+++ clang/test/CodeGen/asm-attrs.c
@@ -8,7 +8,7 @@
 // CHECK: call i32 asm "foo5", {{.*}} [[READONLY]]
 // CHECK: call i32 asm "foo6", {{.*}} [[NOATTRS]]
 // CHECK: call void asm sideeffect "foo7", {{.*}} [[NOATTRS]]
-// CHECK: call void asm "foo8", {{.*}} [[NOATTRS]]
+// CHECK: call i32 asm "foo8", {{.*}} [[READNONE]]
 
 // CHECK: attributes [[READNONE]] = { nounwind readnone }
 // CHECK: attributes [[NOATTRS]] = { nounwind }
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -1984,6 +1984,7 @@
   std::vector ResultTruncRegTypes;
   std::vector ArgTypes;
   std::vector Args;
+  llvm::BitVector ResultTypeRequiresCast;
 
   // Keep track of inout constraints.
   std::string InOutConstraints;
@@ -2022,13 +2023,23 @@
 
 

[PATCH] D65889: [analyzer] CastValueChecker: Model castAs(), getAs()

2019-08-07 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso created this revision.
Charusso added a reviewer: NoQ.
Charusso added a project: clang.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.

Thanks to Kristóf Umann for the great idea!


Repository:
  rC Clang

https://reviews.llvm.org/D65889

Files:
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/test/Analysis/cast-value.cpp

Index: clang/test/Analysis/cast-value.cpp
===
--- clang/test/Analysis/cast-value.cpp
+++ clang/test/Analysis/cast-value.cpp
@@ -23,11 +23,20 @@
 const X *dyn_cast_or_null(Y Value);
 } // namespace llvm
 
-using namespace llvm;
-
-class Shape {};
+namespace clang {
+struct Shape {
+  template 
+  const T *castAs() const;
+
+  template 
+  const T *getAs() const;
+};
 class Triangle : public Shape {};
 class Circle : public Shape {};
+} // namespace clang
+
+using namespace llvm;
+using namespace clang;
 
 namespace test_cast {
 void evalLogic(const Shape *S) {
@@ -91,7 +100,45 @@
   if (!S)
 clang_analyzer_eval(!C); // logic-warning {{TRUE}}
 }
+} // namespace test_dyn_cast_or_null
+
+namespace test_cast_as {
+void evalLogic(const Shape *S) {
+  const Circle *C = S->castAs();
+  clang_analyzer_numTimesReached(); // logic-warning {{1}}
+
+  if (S && C)
+clang_analyzer_eval(C == S);
+  // logic-warning@-1 {{TRUE}}
+  // logic-warning@-2 {{FALSE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // no-warning
+
+  if (!S)
+clang_analyzer_warnIfReached(); // no-warning
+}
+} // namespace test_cast_as
+
+namespace test_get_as {
+void evalLogic(const Shape *S) {
+  const Circle *C = S->getAs();
+  clang_analyzer_numTimesReached(); // logic-warning {{2}}
+
+  if (S && C)
+clang_analyzer_eval(C == S);
+  // logic-warning@-1 {{TRUE}}
+  // logic-warning@-2 {{FALSE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // logic-warning {{REACHABLE}}
+
+  if (!S)
+clang_analyzer_warnIfReached(); // no-warning
+}
+} // namespace test_get_as
 
+namespace test_notes {
 void evalNonNullParamNonNullReturn(const Shape *S) {
   const auto *C = dyn_cast_or_null(S);
   // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' succeeds}}
@@ -134,4 +181,15 @@
   // expected-warning@-2 {{Division by zero}}
   // logic-warning@-3 {{Division by zero}}
 }
-} // namespace test_dyn_cast_or_null
+
+void evalZeroParamNonNullReturn(const Shape *S) {
+  const auto *C = S->castAs();
+  // expected-note@-1 {{Assuming dynamic cast to 'Circle' succeeds}}
+  // expected-note@-2 {{'C' initialized to a null pointer value}}
+
+  (void)(1 / !(bool)C);
+  // expected-note@-1 {{Division by zero}}
+  // expected-warning@-2 {{Division by zero}}
+  // logic-warning@-3 {{Division by zero}}
+}
+} // namespace test_notes
Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -714,7 +714,8 @@
 return UnknownVal();
 
   SVal ThisVal = getSVal(Base);
-  assert(ThisVal.isUnknownOrUndef() || ThisVal.getAs());
+  assert(ThisVal.isUnknownOrUndef() || ThisVal.getAs() ||
+ ThisVal.getAs()->getValue().getExtValue() == 1);
   return ThisVal;
 }
 
Index: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
@@ -22,27 +22,35 @@
 
 namespace {
 class CastValueChecker : public Checker {
+  enum class CastKind { Checking, Sugar };
+
   using CastCheck =
   std::function;
 
 public:
-  // We have three cases to evaluate a cast:
+  // We have five cases to evaluate a cast:
   // 1) The parameter is non-null, the return value is non-null
   // 2) The parameter is non-null, the return value is null
   // 3) The parameter is null, the return value is null
-  //
   // cast: 1;  dyn_cast: 1, 2;  cast_or_null: 1, 3;  dyn_cast_or_null: 1, 2, 3.
+  //
+  // 4) castAs: has no parameter, the return value is non-null.
+  // 5) getAs:  has no parameter, the return value is null or non-null.
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
 
 private:
-  // These are known in the LLVM project.
-  const CallDescriptionMap CDM = {
-  {{{"llvm", "cast"}, 1}, &CastValueChecker::evalCast},
-  {{{"llvm", "dyn_cast"}, 1}, &CastValueChecker::evalDynCast},
+  // These are known in the LLVM project. The pairs are in the following form:
+  // {{{namespace, call}, argument-count}, callback}
+  const CallDescriptionMap CheckingCastCDM = {
+  {{{"llvm", "dyn_cast_or_null"}, 1}, &CastValueChecker::evalDynCastOrNull},
   {{{"llvm", "cast_or_null"}, 1}, &CastValueChecker::evalCastOrNull},
-  {{{"llvm", "dyn_cast_or_null"}, 1},
-

[PATCH] D65889: [analyzer] CastValueChecker: Model castAs(), getAs()

2019-08-07 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked 4 inline comments as done.
Charusso added a comment.

This is a little-bit WIP as the symbol conjuring is very naive.




Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:111
+QualType Ty = CE->getCallReturnType(C.getASTContext());
+V = C.getSValBuilder().makeTruthVal(true, Ty);
+  }

That is a very lame way to conjure a symbol, but with a cool wrapper I believe 
this would be okay. Do we have a better way to create a non-null symbol?



Comment at: clang/lib/StaticAnalyzer/Core/CallEvent.cpp:718
+  assert(ThisVal.isUnknownOrUndef() || ThisVal.getAs() ||
+ ThisVal.getAs()->getValue().getExtValue() == 1);
   return ThisVal;

This is the only necessary addition to make it usable.



Comment at: clang/test/Analysis/cast-value.cpp:113
+  // logic-warning@-1 {{TRUE}}
+  // logic-warning@-2 {{FALSE}}
+

I am not sure what is going on here,



Comment at: clang/test/Analysis/cast-value.cpp:131
+  // logic-warning@-1 {{TRUE}}
+  // logic-warning@-2 {{FALSE}}
+

and here.



Comment at: clang/test/Analysis/cast-value.cpp:193
+  // expected-warning@-2 {{Division by zero}}
+  // logic-warning@-3 {{Division by zero}}
+}

Known-value printing fails, but at least it is working well.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65889



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


[PATCH] D64374: [analyzer] CastValueChecker: Model casts

2019-08-07 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In D64374#1594617 , @Szelethus wrote:

> I guess `getAs` and `castAs` methods could join the party too. I'm evaluating 
> plenty of results on LLVM, and those seem to be in the same problem category.




In D64374#1618694 , @Szelethus wrote:

> Do you have plans to extend this checker with the modeling of `isa<>`? I 
> might take that off your shoulder if not :)


Hey! Sorry for the late response, just it is a heavy change. This patch creates 
about 200 TP, I have checked out every of the new reports.
https://reviews.llvm.org/D65889 creates about 400 TP as an estimation, then 
`isa()` is the next goal. Thanks you for the ideas!


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

https://reviews.llvm.org/D64374



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


[PATCH] D65883: [Extract] Fixed SemicolonExtractionPolicy for SwitchStmt and SwitchCase

2019-08-07 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah updated this revision to Diff 213925.
SureYeaah added a comment.

Added tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65883

Files:
  clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
  clang/test/Refactor/Extract/ExtractionSemicolonPolicy.cpp


Index: clang/test/Refactor/Extract/ExtractionSemicolonPolicy.cpp
===
--- clang/test/Refactor/Extract/ExtractionSemicolonPolicy.cpp
+++ clang/test/Refactor/Extract/ExtractionSemicolonPolicy.cpp
@@ -64,6 +64,7 @@
 // CHECK-NEXT: extracted();{{$}}
 // CHECK-NEXT: }
 
+
 void extractStatementNotSemiWhile() {
   /*range eextract=->+2:4*/while (true) {
 int x = 0;
@@ -190,3 +191,15 @@
 // CHECK-NEXT: extracted();{{$}}
 // CHECK-NEXT: //
 // CHECK-NEXT: }
+
+void careForSwitchSemicolon() {
+  /*range mextract=->+0:51*/switch(0) default: break;
+}
+// CHECK: 1 'mextract' results:
+// CHECK:  static void extracted() {
+// CHECK-NEXT: switch(0) default: break;{{$}}
+// CHECK-NEXT: }{{[[:space:]].*}}
+// CHECK-NEXT: void careForSwitchSemicolon() {
+// CHECK-NEXT: extracted();{{$}}
+// CHECK-NEXT: }
+
Index: clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
===
--- clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
+++ clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
@@ -40,8 +40,11 @@
 return isSemicolonRequiredAfter(CXXFor->getBody());
   if (const auto *ObjCFor = dyn_cast(S))
 return isSemicolonRequiredAfter(ObjCFor->getBody());
+  if(const auto *Switch = dyn_cast(S))
+return isSemicolonRequiredAfter(Switch->getBody());
+  if(const auto *Case = dyn_cast(S))
+return isSemicolonRequiredAfter(Case->getSubStmt());
   switch (S->getStmtClass()) {
-  case Stmt::SwitchStmtClass:
   case Stmt::CXXTryStmtClass:
   case Stmt::ObjCAtSynchronizedStmtClass:
   case Stmt::ObjCAutoreleasePoolStmtClass:


Index: clang/test/Refactor/Extract/ExtractionSemicolonPolicy.cpp
===
--- clang/test/Refactor/Extract/ExtractionSemicolonPolicy.cpp
+++ clang/test/Refactor/Extract/ExtractionSemicolonPolicy.cpp
@@ -64,6 +64,7 @@
 // CHECK-NEXT: extracted();{{$}}
 // CHECK-NEXT: }
 
+
 void extractStatementNotSemiWhile() {
   /*range eextract=->+2:4*/while (true) {
 int x = 0;
@@ -190,3 +191,15 @@
 // CHECK-NEXT: extracted();{{$}}
 // CHECK-NEXT: //
 // CHECK-NEXT: }
+
+void careForSwitchSemicolon() {
+  /*range mextract=->+0:51*/switch(0) default: break;
+}
+// CHECK: 1 'mextract' results:
+// CHECK:  static void extracted() {
+// CHECK-NEXT: switch(0) default: break;{{$}}
+// CHECK-NEXT: }{{[[:space:]].*}}
+// CHECK-NEXT: void careForSwitchSemicolon() {
+// CHECK-NEXT: extracted();{{$}}
+// CHECK-NEXT: }
+
Index: clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
===
--- clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
+++ clang/lib/Tooling/Refactoring/Extract/SourceExtraction.cpp
@@ -40,8 +40,11 @@
 return isSemicolonRequiredAfter(CXXFor->getBody());
   if (const auto *ObjCFor = dyn_cast(S))
 return isSemicolonRequiredAfter(ObjCFor->getBody());
+  if(const auto *Switch = dyn_cast(S))
+return isSemicolonRequiredAfter(Switch->getBody());
+  if(const auto *Case = dyn_cast(S))
+return isSemicolonRequiredAfter(Case->getSubStmt());
   switch (S->getStmtClass()) {
-  case Stmt::SwitchStmtClass:
   case Stmt::CXXTryStmtClass:
   case Stmt::ObjCAtSynchronizedStmtClass:
   case Stmt::ObjCAutoreleasePoolStmtClass:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65866: Code completion should not ignore default parameters in functions.

2019-08-07 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 213926.
usaxena95 marked 3 inline comments as done.
usaxena95 added a comment.

Added tests in CodeCompletionStringsTests.cpp
Resolved comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65866

Files:
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp

Index: clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
@@ -90,6 +90,30 @@
   EXPECT_EQ(formatDocumentation(*CCS, "Foo's comment"), "Foo's comment");
 }
 
+TEST_F(CompletionStringTest, FunctionWithDefaultParams) {
+  // return_type foo(p1, p2 = 0, p3 = 0)
+  Builder.AddChunk(CodeCompletionString::CK_Comma);
+  Builder.AddTypedTextChunk("p3 = 0");
+  auto *DefaultParam2 = Builder.TakeString();
+
+  Builder.AddChunk(CodeCompletionString::CK_Comma);
+  Builder.AddTypedTextChunk("p2 = 0");
+  Builder.AddOptionalChunk(DefaultParam2);
+  auto* DefaultParam1 = Builder.TakeString();
+
+  Builder.AddResultTypeChunk("return_type");
+  Builder.AddTypedTextChunk("Foo");
+  Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+  Builder.AddPlaceholderChunk("p1");
+  Builder.AddOptionalChunk(DefaultParam1);
+  Builder.AddChunk(CodeCompletionString::CK_RightParen);
+
+  auto *CCS = Builder.TakeString();
+  computeSignature(*CCS);
+  EXPECT_EQ(Signature, "(p1, p2 = 0, p3 = 0)");
+  EXPECT_EQ(Snippet, "(${1:p1})");
+}
+
 TEST_F(CompletionStringTest, EscapeSnippet) {
   Builder.AddTypedTextChunk("Foo");
   Builder.AddChunk(CodeCompletionString::CK_LeftParen);
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -939,6 +939,25 @@
 
   EXPECT_TRUE(Results.Completions.empty());
 }
+
+TEST(CompletionTest, DefaultArgs) {
+  clangd::CodeCompleteOptions Opts;
+  std::string Context = R"cpp(
+int X(int A = 0);
+int Y(int A, int B = 0);
+int Z(int A, int B = 0, int C = 0, int D = 0);
+  )cpp";
+  EXPECT_THAT(completions(Context + "int y = X^", {}, Opts).Completions,
+  UnorderedElementsAre(Labeled("X(int A = 0)")));
+  EXPECT_THAT(completions(Context + "int y = Y^", {}, Opts).Completions,
+  UnorderedElementsAre(AllOf(Labeled("Y(int A, int B = 0)"),
+ SnippetSuffix("(${1:int A})";
+  EXPECT_THAT(completions(Context + "int y = Z^", {}, Opts).Completions,
+  UnorderedElementsAre(
+  AllOf(Labeled("Z(int A, int B = 0, int C = 0, int D = 0)"),
+SnippetSuffix("(${1:int A})";
+}
+
 SignatureHelp signatures(llvm::StringRef Text, Position Point,
  std::vector IndexSymbols = {}) {
   std::unique_ptr Index;
Index: clang-tools-extra/clangd/CodeCompletionStrings.cpp
===
--- clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -32,6 +32,21 @@
   }
 }
 
+void appendOptionalChunk(const CodeCompletionString &CCS, std::string *Out) {
+  for (const CodeCompletionString::Chunk &C : CCS) {
+switch (C.Kind) {
+case CodeCompletionString::CK_Optional:
+  assert(C.Optional &&
+ "Expected the optional code completion string to be non-null.");
+  appendOptionalChunk(*C.Optional, Out);
+  break;
+default:
+  *Out += C.Text;
+  break;
+}
+  }
+}
+
 bool looksLikeDocComment(llvm::StringRef CommentText) {
   // We don't report comments that only contain "special" chars.
   // This avoids reporting various delimiters, like:
@@ -138,6 +153,9 @@
   *Snippet += Chunk.Text;
   break;
 case CodeCompletionString::CK_Optional:
+  assert(Chunk.Optional);  
+  // No need to create placeholders for default arguments in Snippet.
+  appendOptionalChunk(*Chunk.Optional, Signature);
   break;
 case CodeCompletionString::CK_Placeholder:
   *Signature += Chunk.Text;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65866: Code completion should not ignore default parameters in functions.

2019-08-07 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 213927.
usaxena95 added a comment.

Formatted new test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65866

Files:
  clang-tools-extra/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp

Index: clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompletionStringsTests.cpp
@@ -90,6 +90,30 @@
   EXPECT_EQ(formatDocumentation(*CCS, "Foo's comment"), "Foo's comment");
 }
 
+TEST_F(CompletionStringTest, FunctionWithDefaultParams) {
+  // return_type foo(p1, p2 = 0, p3 = 0)
+  Builder.AddChunk(CodeCompletionString::CK_Comma);
+  Builder.AddTypedTextChunk("p3 = 0");
+  auto *DefaultParam2 = Builder.TakeString();
+
+  Builder.AddChunk(CodeCompletionString::CK_Comma);
+  Builder.AddTypedTextChunk("p2 = 0");
+  Builder.AddOptionalChunk(DefaultParam2);
+  auto *DefaultParam1 = Builder.TakeString();
+
+  Builder.AddResultTypeChunk("return_type");
+  Builder.AddTypedTextChunk("Foo");
+  Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+  Builder.AddPlaceholderChunk("p1");
+  Builder.AddOptionalChunk(DefaultParam1);
+  Builder.AddChunk(CodeCompletionString::CK_RightParen);
+
+  auto *CCS = Builder.TakeString();
+  computeSignature(*CCS);
+  EXPECT_EQ(Signature, "(p1, p2 = 0, p3 = 0)");
+  EXPECT_EQ(Snippet, "(${1:p1})");
+}
+
 TEST_F(CompletionStringTest, EscapeSnippet) {
   Builder.AddTypedTextChunk("Foo");
   Builder.AddChunk(CodeCompletionString::CK_LeftParen);
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -939,6 +939,25 @@
 
   EXPECT_TRUE(Results.Completions.empty());
 }
+
+TEST(CompletionTest, DefaultArgs) {
+  clangd::CodeCompleteOptions Opts;
+  std::string Context = R"cpp(
+int X(int A = 0);
+int Y(int A, int B = 0);
+int Z(int A, int B = 0, int C = 0, int D = 0);
+  )cpp";
+  EXPECT_THAT(completions(Context + "int y = X^", {}, Opts).Completions,
+  UnorderedElementsAre(Labeled("X(int A = 0)")));
+  EXPECT_THAT(completions(Context + "int y = Y^", {}, Opts).Completions,
+  UnorderedElementsAre(AllOf(Labeled("Y(int A, int B = 0)"),
+ SnippetSuffix("(${1:int A})";
+  EXPECT_THAT(completions(Context + "int y = Z^", {}, Opts).Completions,
+  UnorderedElementsAre(
+  AllOf(Labeled("Z(int A, int B = 0, int C = 0, int D = 0)"),
+SnippetSuffix("(${1:int A})";
+}
+
 SignatureHelp signatures(llvm::StringRef Text, Position Point,
  std::vector IndexSymbols = {}) {
   std::unique_ptr Index;
Index: clang-tools-extra/clangd/CodeCompletionStrings.cpp
===
--- clang-tools-extra/clangd/CodeCompletionStrings.cpp
+++ clang-tools-extra/clangd/CodeCompletionStrings.cpp
@@ -32,6 +32,21 @@
   }
 }
 
+void appendOptionalChunk(const CodeCompletionString &CCS, std::string *Out) {
+  for (const CodeCompletionString::Chunk &C : CCS) {
+switch (C.Kind) {
+case CodeCompletionString::CK_Optional:
+  assert(C.Optional &&
+ "Expected the optional code completion string to be non-null.");
+  appendOptionalChunk(*C.Optional, Out);
+  break;
+default:
+  *Out += C.Text;
+  break;
+}
+  }
+}
+
 bool looksLikeDocComment(llvm::StringRef CommentText) {
   // We don't report comments that only contain "special" chars.
   // This avoids reporting various delimiters, like:
@@ -138,6 +153,9 @@
   *Snippet += Chunk.Text;
   break;
 case CodeCompletionString::CK_Optional:
+  assert(Chunk.Optional);  
+  // No need to create placeholders for default arguments in Snippet.
+  appendOptionalChunk(*Chunk.Optional, Signature);
   break;
 case CodeCompletionString::CK_Placeholder:
   *Signature += Chunk.Text;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65880: [Driver] Move LIBRARY_PATH before user inputs

2019-08-07 Thread Hal Finkel via Phabricator via cfe-commits
hfinkel accepted this revision.
hfinkel added a comment.
This revision is now accepted and ready to land.

LGTM.

Local flags should certainly override LIBRARY_PATH.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65880



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


[clang-tools-extra] r368186 - Code completion should not ignore default parameters in functions.

2019-08-07 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Wed Aug  7 09:52:21 2019
New Revision: 368186

URL: http://llvm.org/viewvc/llvm-project?rev=368186&view=rev
Log:
Code completion should not ignore default parameters in functions.

Summary:
Inorder to display the default arguments we must process the
CK_Optional chunks of CodeCompletionString while creating the Signature.

We do not create placeholders for default arguments.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
clang-tools-extra/trunk/clangd/unittests/CodeCompletionStringsTests.cpp

Modified: clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp?rev=368186&r1=368185&r2=368186&view=diff
==
--- clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp Wed Aug  7 
09:52:21 2019
@@ -32,6 +32,21 @@ void appendEscapeSnippet(const llvm::Str
   }
 }
 
+void appendOptionalChunk(const CodeCompletionString &CCS, std::string *Out) {
+  for (const CodeCompletionString::Chunk &C : CCS) {
+switch (C.Kind) {
+case CodeCompletionString::CK_Optional:
+  assert(C.Optional &&
+ "Expected the optional code completion string to be non-null.");
+  appendOptionalChunk(*C.Optional, Out);
+  break;
+default:
+  *Out += C.Text;
+  break;
+}
+  }
+}
+
 bool looksLikeDocComment(llvm::StringRef CommentText) {
   // We don't report comments that only contain "special" chars.
   // This avoids reporting various delimiters, like:
@@ -138,6 +153,9 @@ void getSignature(const CodeCompletionSt
   *Snippet += Chunk.Text;
   break;
 case CodeCompletionString::CK_Optional:
+  assert(Chunk.Optional);  
+  // No need to create placeholders for default arguments in Snippet.
+  appendOptionalChunk(*Chunk.Optional, Signature);
   break;
 case CodeCompletionString::CK_Placeholder:
   *Signature += Chunk.Text;

Modified: clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp?rev=368186&r1=368185&r2=368186&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp Wed Aug  7 
09:52:21 2019
@@ -939,6 +939,25 @@ TEST(CompletionTest, IgnoreCompleteInExc
 
   EXPECT_TRUE(Results.Completions.empty());
 }
+
+TEST(CompletionTest, DefaultArgs) {
+  clangd::CodeCompleteOptions Opts;
+  std::string Context = R"cpp(
+int X(int A = 0);
+int Y(int A, int B = 0);
+int Z(int A, int B = 0, int C = 0, int D = 0);
+  )cpp";
+  EXPECT_THAT(completions(Context + "int y = X^", {}, Opts).Completions,
+  UnorderedElementsAre(Labeled("X(int A = 0)")));
+  EXPECT_THAT(completions(Context + "int y = Y^", {}, Opts).Completions,
+  UnorderedElementsAre(AllOf(Labeled("Y(int A, int B = 0)"),
+ SnippetSuffix("(${1:int A})";
+  EXPECT_THAT(completions(Context + "int y = Z^", {}, Opts).Completions,
+  UnorderedElementsAre(
+  AllOf(Labeled("Z(int A, int B = 0, int C = 0, int D = 0)"),
+SnippetSuffix("(${1:int A})";
+}
+
 SignatureHelp signatures(llvm::StringRef Text, Position Point,
  std::vector IndexSymbols = {}) {
   std::unique_ptr Index;

Modified: 
clang-tools-extra/trunk/clangd/unittests/CodeCompletionStringsTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/CodeCompletionStringsTests.cpp?rev=368186&r1=368185&r2=368186&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/CodeCompletionStringsTests.cpp 
(original)
+++ clang-tools-extra/trunk/clangd/unittests/CodeCompletionStringsTests.cpp Wed 
Aug  7 09:52:21 2019
@@ -90,6 +90,30 @@ TEST_F(CompletionStringTest, Function) {
   EXPECT_EQ(formatDocumentation(*CCS, "Foo's comment"), "Foo's comment");
 }
 
+TEST_F(CompletionStringTest, FunctionWithDefaultParams) {
+  // return_type foo(p1, p2 = 0, p3 = 0)
+  Builder.AddChunk(CodeCompletionString::CK_Comma);
+  Builder.AddTypedTextChunk("p3 = 0");
+  auto *DefaultParam2 = Builder.TakeString();
+
+  Builder.AddChunk(CodeCompletionString::CK_Comma);
+  Builder.AddTypedTextChunk("p2 = 0");
+  Builder.AddOptionalChunk(DefaultParam2);
+  auto *DefaultParam1 = Builder.TakeString();
+
+  Builder.AddResultTy

[PATCH] D65866: Code completion should not ignore default parameters in functions.

2019-08-07 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368186: Code completion should not ignore default parameters 
in functions. (authored by sammccall, committed by ).
Herald added subscribers: llvm-commits, ilya-biryukov.
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D65866?vs=213927&id=213931#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65866

Files:
  clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
  clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/trunk/clangd/unittests/CodeCompletionStringsTests.cpp

Index: clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
===
--- clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
+++ clang-tools-extra/trunk/clangd/CodeCompletionStrings.cpp
@@ -32,6 +32,21 @@
   }
 }
 
+void appendOptionalChunk(const CodeCompletionString &CCS, std::string *Out) {
+  for (const CodeCompletionString::Chunk &C : CCS) {
+switch (C.Kind) {
+case CodeCompletionString::CK_Optional:
+  assert(C.Optional &&
+ "Expected the optional code completion string to be non-null.");
+  appendOptionalChunk(*C.Optional, Out);
+  break;
+default:
+  *Out += C.Text;
+  break;
+}
+  }
+}
+
 bool looksLikeDocComment(llvm::StringRef CommentText) {
   // We don't report comments that only contain "special" chars.
   // This avoids reporting various delimiters, like:
@@ -138,6 +153,9 @@
   *Snippet += Chunk.Text;
   break;
 case CodeCompletionString::CK_Optional:
+  assert(Chunk.Optional);  
+  // No need to create placeholders for default arguments in Snippet.
+  appendOptionalChunk(*Chunk.Optional, Signature);
   break;
 case CodeCompletionString::CK_Placeholder:
   *Signature += Chunk.Text;
Index: clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
@@ -939,6 +939,25 @@
 
   EXPECT_TRUE(Results.Completions.empty());
 }
+
+TEST(CompletionTest, DefaultArgs) {
+  clangd::CodeCompleteOptions Opts;
+  std::string Context = R"cpp(
+int X(int A = 0);
+int Y(int A, int B = 0);
+int Z(int A, int B = 0, int C = 0, int D = 0);
+  )cpp";
+  EXPECT_THAT(completions(Context + "int y = X^", {}, Opts).Completions,
+  UnorderedElementsAre(Labeled("X(int A = 0)")));
+  EXPECT_THAT(completions(Context + "int y = Y^", {}, Opts).Completions,
+  UnorderedElementsAre(AllOf(Labeled("Y(int A, int B = 0)"),
+ SnippetSuffix("(${1:int A})";
+  EXPECT_THAT(completions(Context + "int y = Z^", {}, Opts).Completions,
+  UnorderedElementsAre(
+  AllOf(Labeled("Z(int A, int B = 0, int C = 0, int D = 0)"),
+SnippetSuffix("(${1:int A})";
+}
+
 SignatureHelp signatures(llvm::StringRef Text, Position Point,
  std::vector IndexSymbols = {}) {
   std::unique_ptr Index;
Index: clang-tools-extra/trunk/clangd/unittests/CodeCompletionStringsTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/CodeCompletionStringsTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/CodeCompletionStringsTests.cpp
@@ -90,6 +90,30 @@
   EXPECT_EQ(formatDocumentation(*CCS, "Foo's comment"), "Foo's comment");
 }
 
+TEST_F(CompletionStringTest, FunctionWithDefaultParams) {
+  // return_type foo(p1, p2 = 0, p3 = 0)
+  Builder.AddChunk(CodeCompletionString::CK_Comma);
+  Builder.AddTypedTextChunk("p3 = 0");
+  auto *DefaultParam2 = Builder.TakeString();
+
+  Builder.AddChunk(CodeCompletionString::CK_Comma);
+  Builder.AddTypedTextChunk("p2 = 0");
+  Builder.AddOptionalChunk(DefaultParam2);
+  auto *DefaultParam1 = Builder.TakeString();
+
+  Builder.AddResultTypeChunk("return_type");
+  Builder.AddTypedTextChunk("Foo");
+  Builder.AddChunk(CodeCompletionString::CK_LeftParen);
+  Builder.AddPlaceholderChunk("p1");
+  Builder.AddOptionalChunk(DefaultParam1);
+  Builder.AddChunk(CodeCompletionString::CK_RightParen);
+
+  auto *CCS = Builder.TakeString();
+  computeSignature(*CCS);
+  EXPECT_EQ(Signature, "(p1, p2 = 0, p3 = 0)");
+  EXPECT_EQ(Snippet, "(${1:p1})");
+}
+
 TEST_F(CompletionStringTest, EscapeSnippet) {
   Builder.AddTypedTextChunk("Foo");
   Builder.AddChunk(CodeCompletionString::CK_LeftParen);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65877: [libTooling] In Transformer, generalize `applyFirst` to admit rules with incompatible matchers.

2019-08-07 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 213932.
ymandel added a comment.

fix comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65877

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

Index: clang/unittests/Tooling/TransformerTest.cpp
===
--- clang/unittests/Tooling/TransformerTest.cpp
+++ clang/unittests/Tooling/TransformerTest.cpp
@@ -482,16 +482,17 @@
   testRule(applyFirst({ruleStrlenSize(), FlagRule}), Input, Expected);
 }
 
-// Version of ruleStrlenSizeAny that inserts a method with a different name than
+// Version of ruleStrlenSize that doesn't check the type of the targeted
+// object. Note that we insert a method with a different name than
 // ruleStrlenSize, so we can tell their effect apart.
-RewriteRule ruleStrlenSizeDistinct() {
+RewriteRule ruleStrlenSizeAny() {
   StringRef S;
   return makeRule(
   callExpr(callee(functionDecl(hasName("strlen"))),
hasArgument(0, cxxMemberCallExpr(
   on(expr().bind(S)),
   callee(cxxMethodDecl(hasName("c_str")),
-  change(text("DISTINCT")));
+  change(text("ANY")));
 }
 
 TEST_F(TransformerTest, OrderedRuleRelated) {
@@ -509,16 +510,18 @@
 struct mystring {
   char* c_str();
 };
-int f(mystring s) { return DISTINCT; }
+int f(mystring s) { return ANY; }
 }  // namespace foo
 int g(string s) { return REPLACED; }
   )cc";
 
-  testRule(applyFirst({ruleStrlenSize(), ruleStrlenSizeDistinct()}), Input,
+  testRule(applyFirst({ruleStrlenSize(), ruleStrlenSizeAny()}), Input,
Expected);
 }
 
-// Change the order of the rules to get a different result.
+// Change the order of the rules to get a different result. When
+// `ruleStrlenSizeAny` comes first, it applies for both uses, so
+// `ruleStrlenSize` never applies.
 TEST_F(TransformerTest, OrderedRuleRelatedSwapped) {
   std::string Input = R"cc(
 namespace foo {
@@ -534,15 +537,51 @@
 struct mystring {
   char* c_str();
 };
-int f(mystring s) { return DISTINCT; }
+int f(mystring s) { return ANY; }
 }  // namespace foo
-int g(string s) { return DISTINCT; }
+int g(string s) { return ANY; }
   )cc";
 
-  testRule(applyFirst({ruleStrlenSizeDistinct(), ruleStrlenSize()}), Input,
+  testRule(applyFirst({ruleStrlenSizeAny(), ruleStrlenSize()}), Input,
Expected);
 }
 
+// Verify that a set of rules whose matchers have different base kinds works
+// properly, including that `applyFirst` produces multiple matchers.
+TEST_F(TransformerTest, OrderedRuleMultipleKinds) {
+  RewriteRule DeclRule = makeRule(functionDecl(hasName("bad")).bind("fun"),
+  change(name("fun"), text("good")));
+  // We test two different kinds of rules: Expr and Decl. We place the Decl rule
+  // in the middle to test that `buildMatchers` works even when the kinds aren't
+  // grouped together.
+  RewriteRule Rule =
+  applyFirst({ruleStrlenSize(), DeclRule, ruleStrlenSizeAny()});
+
+  std::string Input = R"cc(
+namespace foo {
+struct mystring {
+  char* c_str();
+};
+int f(mystring s) { return strlen(s.c_str()); }
+}  // namespace foo
+int g(string s) { return strlen(s.c_str()); }
+int bad(int x);
+  )cc";
+  std::string Expected = R"cc(
+namespace foo {
+struct mystring {
+  char* c_str();
+};
+int f(mystring s) { return ANY; }
+}  // namespace foo
+int g(string s) { return REPLACED; }
+int good(int x);
+  )cc";
+
+  EXPECT_EQ(tooling::detail::buildMatchers(Rule).size(), 2UL);
+  testRule(Rule, Input, Expected);
+}
+
 //
 // Negative tests (where we expect no transformation to occur).
 //
Index: clang/lib/Tooling/Refactoring/Transformer.cpp
===
--- clang/lib/Tooling/Refactoring/Transformer.cpp
+++ clang/lib/Tooling/Refactoring/Transformer.cpp
@@ -91,41 +91,53 @@
   return (A.isSame(TypeKind) && B.isSame(QualKind)) || A.isBaseOf(B);
 }
 
-// Try to find a common kind to which all of the rule's matchers can be
-// converted.
-static ASTNodeKind
-findCommonKind(const SmallVectorImpl &Cases) {
-  assert(!Cases.empty() && "Rule must have at least one case.");
-  ASTNodeKind JoinKind = Cases[0].Matcher.getSupportedKind();
-  // Find a (least) Kind K, for which M.canConvertTo(K) holds, for all matchers
-  // M in Rules.
-  for (const auto &Case : Cases) {
-auto K = Case.Matcher.getSupportedKind();
-if (isBaseOf(JoinKind, K)) {
-  JoinKind = K;
-  continue;
+namespace {
+struct KindBucket {
+  // Common kind which all of the bucket's matchers can support. Specifically, a
+  // (least) Kind K, for which M.canConvertTo(K) holds, for all matcher

[PATCH] D65846: Improve error message from FrontendAction

2019-08-07 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

Sorry, it's not clear to me what is the issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65846



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


r368188 - [clang][NFC] Fix typo in matcher comment

2019-08-07 Thread Yitzhak Mandelbaum via cfe-commits
Author: ymandel
Date: Wed Aug  7 10:01:31 2019
New Revision: 368188

URL: http://llvm.org/viewvc/llvm-project?rev=368188&view=rev
Log:
[clang][NFC] Fix typo in matcher comment

Also updates corresponding html doc.

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=368188&r1=368187&r2=368188&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Wed Aug  7 10:01:31 2019
@@ -6819,7 +6819,7 @@ F& operator=(const F& o) {
 }
 returnStmt(forFunction(hasName("operator=")))
   matches 'return *this'
-  but does match 'return > 0'
+  but does not match 'return v > 0'
 
 
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=368188&r1=368187&r2=368188&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Aug  7 10:01:31 2019
@@ -6410,7 +6410,7 @@ AST_MATCHER_FUNCTION(internal::Matcherhttps://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65043: [Format] Add C++20 standard to style options

2019-08-07 Thread Brian Gesiak via Phabricator via cfe-commits
modocache added a comment.

Friendly ping! @sammccall is this what you had in mind?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65043



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


[PATCH] D65043: [Format] Add C++20 standard to style options

2019-08-07 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

FWIW, looks unobjectionable to me, except for some nitpicks on the test cases 
(which are easy to fix so I'm hoping you just will :)).




Comment at: clang/unittests/Format/FormatTest.cpp:13780
+  // In C++2a, it is interpreted as a prefix increment on 'i'.
+  verifyFormat("co_yield++ i;");
+  verifyFormat("co_yield ++i;", Cpp2a);

My comment https://reviews.llvm.org/D65043#inline-582865 still stands. Please 
just write

verifyFormat("f(co_yield - 1);");
verifyFormat("f(co_yield -1);", Cpp2a);




Comment at: clang/unittests/Format/FormatTest.cpp:13783
+
+  verifyFormat("co_await []() { co_return; }();", Cpp2a);
+}

FWIW, `[]() { co_return; }` is not valid C++2a either. You can't have a lambda 
that is a coroutine and //also// has a deduced return type. Make this

verifyFormat("co_await []() -> g { co_return; }();", Cpp2a);

if you want it to be plausible C++2a.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65043



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


[PATCH] D65889: [analyzer] CastValueChecker: Model castAs(), getAs()

2019-08-07 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:111
+QualType Ty = CE->getCallReturnType(C.getASTContext());
+V = C.getSValBuilder().makeTruthVal(true, Ty);
+  }

Charusso wrote:
> That is a very lame way to conjure a symbol, but with a cool wrapper I 
> believe this would be okay. Do we have a better way to create a non-null 
> symbol?
This creates a concrete `1` rather than a symbol. That's the right behavior for 
`isa`, but it's not the right behavior for `getAs`. In case of `getAs` we need 
to return our `this`.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65889



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


[PATCH] D65889: [analyzer] CastValueChecker: Model castAs(), getAs()

2019-08-07 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:111
+QualType Ty = CE->getCallReturnType(C.getASTContext());
+V = C.getSValBuilder().makeTruthVal(true, Ty);
+  }

NoQ wrote:
> Charusso wrote:
> > That is a very lame way to conjure a symbol, but with a cool wrapper I 
> > believe this would be okay. Do we have a better way to create a non-null 
> > symbol?
> This creates a concrete `1` rather than a symbol. That's the right behavior 
> for `isa`, but it's not the right behavior for `getAs`. In case of `getAs` we 
> need to return our `this`.
Could you explain what is `this`, please? At this case we are working with a 
`CXXMemberCallExpr`. Do you mean its `getImplicitObjectArgument()`?


Repository:
  rC Clang

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

https://reviews.llvm.org/D65889



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


[PATCH] D65889: [analyzer] CastValueChecker: Model castAs(), getAs()

2019-08-07 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:111
+QualType Ty = CE->getCallReturnType(C.getASTContext());
+V = C.getSValBuilder().makeTruthVal(true, Ty);
+  }

Charusso wrote:
> NoQ wrote:
> > Charusso wrote:
> > > That is a very lame way to conjure a symbol, but with a cool wrapper I 
> > > believe this would be okay. Do we have a better way to create a non-null 
> > > symbol?
> > This creates a concrete `1` rather than a symbol. That's the right behavior 
> > for `isa`, but it's not the right behavior for `getAs`. In case of `getAs` 
> > we need to return our `this`.
> Could you explain what is `this`, please? At this case we are working with a 
> `CXXMemberCallExpr`. Do you mean its `getImplicitObjectArgument()`?
Yeah, its value.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65889



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


[PATCH] D65854: [diagtool] Use `operator<<(Colors)` to print out colored output.

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

LGTM with Fangrui's comment addressed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65854



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


[PATCH] D65510: [clangd] Fix implicit template instatiations appearing as topLevelDecls.

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

LGTM, but please print the function template arguments uniformly before landing 
this (to avoid different forms of outputs inside the same test).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65510



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


[PATCH] D65889: [analyzer] CastValueChecker: Model castAs(), getAs()

2019-08-07 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso updated this revision to Diff 213952.
Charusso marked 5 inline comments as done.
Charusso added a comment.

- Remove symbol-conjuring.
- Add a forgotten test case.


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

https://reviews.llvm.org/D65889

Files:
  clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/test/Analysis/cast-value.cpp

Index: clang/test/Analysis/cast-value.cpp
===
--- clang/test/Analysis/cast-value.cpp
+++ clang/test/Analysis/cast-value.cpp
@@ -23,11 +23,20 @@
 const X *dyn_cast_or_null(Y Value);
 } // namespace llvm
 
-using namespace llvm;
-
-class Shape {};
+namespace clang {
+struct Shape {
+  template 
+  const T *castAs() const;
+
+  template 
+  const T *getAs() const;
+};
 class Triangle : public Shape {};
 class Circle : public Shape {};
+} // namespace clang
+
+using namespace llvm;
+using namespace clang;
 
 namespace test_cast {
 void evalLogic(const Shape *S) {
@@ -91,7 +100,43 @@
   if (!S)
 clang_analyzer_eval(!C); // logic-warning {{TRUE}}
 }
+} // namespace test_dyn_cast_or_null
+
+namespace test_cast_as {
+void evalLogic(const Shape *S) {
+  const Circle *C = S->castAs();
+  clang_analyzer_numTimesReached(); // logic-warning {{1}}
+
+  if (S && C)
+clang_analyzer_eval(C == S);
+  // logic-warning@-1 {{TRUE}}
+
+  if (S && !C)
+clang_analyzer_warnIfReached(); // no-warning
+
+  if (!S)
+clang_analyzer_warnIfReached(); // no-warning
+}
+} // namespace test_cast_as
+
+namespace test_get_as {
+void evalLogic(const Shape *S) {
+  const Circle *C = S->getAs();
+  clang_analyzer_numTimesReached(); // logic-warning {{2}}
+
+  if (S && C)
+clang_analyzer_eval(C == S);
+  // logic-warning@-1 {{TRUE}}
 
+  if (S && !C)
+clang_analyzer_warnIfReached(); // logic-warning {{REACHABLE}}
+
+  if (!S)
+clang_analyzer_warnIfReached(); // no-warning
+}
+} // namespace test_get_as
+
+namespace test_notes {
 void evalNonNullParamNonNullReturn(const Shape *S) {
   const auto *C = dyn_cast_or_null(S);
   // expected-note@-1 {{Assuming dynamic cast from 'Shape' to 'Circle' succeeds}}
@@ -134,4 +179,28 @@
   // expected-warning@-2 {{Division by zero}}
   // logic-warning@-3 {{Division by zero}}
 }
-} // namespace test_dyn_cast_or_null
+
+void evalZeroParamNonNullReturn(const Shape *S) {
+  const auto *C = S->castAs();
+  // expected-note@-1 {{Assuming pointer value is null}}
+  // expected-note@-2 {{Assuming dynamic cast to 'Circle' succeeds}}
+  // expected-note@-3 {{'C' initialized here}}
+
+  (void)(1 / !(bool)C);
+  // expected-note@-1 {{'C' is non-null}}
+  // expected-note@-2 {{Division by zero}}
+  // expected-warning@-3 {{Division by zero}}
+  // logic-warning@-4 {{Division by zero}}
+}
+
+void evalZeroParamNullReturn(const Shape *S) {
+  const auto *C = S->getAs();
+  // expected-note@-1 {{Assuming dynamic cast to 'Circle' fails}}
+  // expected-note@-2 {{'C' initialized to a null pointer value}}
+
+  (void)(1 / (bool)C);
+  // expected-note@-1 {{Division by zero}}
+  // expected-warning@-2 {{Division by zero}}
+  // logic-warning@-3 {{Division by zero}}
+}
+} // namespace test_notes
Index: clang/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- clang/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ clang/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -714,7 +714,8 @@
 return UnknownVal();
 
   SVal ThisVal = getSVal(Base);
-  assert(ThisVal.isUnknownOrUndef() || ThisVal.getAs());
+  assert(ThisVal.isUnknownOrUndef() || ThisVal.getAs() ||
+ ThisVal.getAs()->getValue().getExtValue() == 1);
   return ThisVal;
 }
 
Index: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
@@ -22,27 +22,35 @@
 
 namespace {
 class CastValueChecker : public Checker {
+  enum class CastKind { Checking, Sugar };
+
   using CastCheck =
   std::function;
 
 public:
-  // We have three cases to evaluate a cast:
+  // We have five cases to evaluate a cast:
   // 1) The parameter is non-null, the return value is non-null
   // 2) The parameter is non-null, the return value is null
   // 3) The parameter is null, the return value is null
-  //
   // cast: 1;  dyn_cast: 1, 2;  cast_or_null: 1, 3;  dyn_cast_or_null: 1, 2, 3.
+  //
+  // 4) castAs: has no parameter, the return value is non-null.
+  // 5) getAs:  has no parameter, the return value is null or non-null.
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
 
 private:
-  // These are known in the LLVM project.
-  const CallDescriptionMap CDM = {
-  {{{"llvm", "cast"}, 1}, &CastValueChecker::evalCast},
-  {{{"llvm", "dyn_cast"}, 1}, &CastValueChecker::evalDynCast},
+  // These are known in the LLVM project. The pairs 

[PATCH] D65889: [analyzer] CastValueChecker: Model castAs(), getAs()

2019-08-07 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:111
+QualType Ty = CE->getCallReturnType(C.getASTContext());
+V = C.getSValBuilder().makeTruthVal(true, Ty);
+  }

NoQ wrote:
> Charusso wrote:
> > NoQ wrote:
> > > Charusso wrote:
> > > > That is a very lame way to conjure a symbol, but with a cool wrapper I 
> > > > believe this would be okay. Do we have a better way to create a 
> > > > non-null symbol?
> > > This creates a concrete `1` rather than a symbol. That's the right 
> > > behavior for `isa`, but it's not the right behavior for `getAs`. In case 
> > > of `getAs` we need to return our `this`.
> > Could you explain what is `this`, please? At this case we are working with 
> > a `CXXMemberCallExpr`. Do you mean its `getImplicitObjectArgument()`?
> Yeah, its value.
Hm, I have not understand why it is not working as I definitely wanted to use 
`this`. I believe I had forgotten an early-return at a wrong place. Thanks!


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

https://reviews.llvm.org/D65889



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


[PATCH] D64256: Teach some warnings to respect gsl::Pointer and gsl::Owner attributes

2019-08-07 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun marked an inline comment as done.
xazax.hun added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:7077
+//   someContainer.add(std::move(localOWner));
+//   return p;
+if (!IsTempGslOwner && pathOnlyInitializesGslPointer(Path) &&

gribozavr wrote:
> xazax.hun wrote:
> > gribozavr wrote:
> > > Why is it a false positive? `std::move` left memory owned by `localOwner` 
> > > in unspecified state.
> > I saw user code relying on the semantics of certain classes. E.g. they 
> > assume if a `std::unique_ptr` is moved the pointee is still in place, so it 
> > is safe to return a reference to the pointee. Do you think those cases 
> > should be diagnosed too?
> It is... debatable. It is not obvious whether the lifetime of the pointed-to 
> memory has ended or not without more detailed lifetime annotations. I think 
> it is fair to silence it, however, I think the comment should be updated to 
> explain the situation in a more detailed way, since without context it looks 
> like a use-after-move.
Do you think renaming `localOwner` to `uniquePtr` would be sufficient or do you 
want me to extend the text too?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D64256



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


r368196 - [Tooling] Expose ExecutorConcurrency option.

2019-08-07 Thread Diego Astiazaran via cfe-commits
Author: diegoastiazaran
Date: Wed Aug  7 11:35:28 2019
New Revision: 368196

URL: http://llvm.org/viewvc/llvm-project?rev=368196&view=rev
Log:
[Tooling] Expose ExecutorConcurrency option.

D65628 requires a flag to specify the number of threads for a clang-doc step. 
It would be good to use ExecutorConcurrency after exposing it instead of 
creating a new one that has the same purpose.

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

Modified:
cfe/trunk/include/clang/Tooling/AllTUsExecution.h
cfe/trunk/lib/Tooling/AllTUsExecution.cpp

Modified: cfe/trunk/include/clang/Tooling/AllTUsExecution.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/AllTUsExecution.h?rev=368196&r1=368195&r2=368196&view=diff
==
--- cfe/trunk/include/clang/Tooling/AllTUsExecution.h (original)
+++ cfe/trunk/include/clang/Tooling/AllTUsExecution.h Wed Aug  7 11:35:28 2019
@@ -71,6 +71,7 @@ private:
   unsigned ThreadCount;
 };
 
+extern llvm::cl::opt ExecutorConcurrency;
 extern llvm::cl::opt Filter;
 
 } // end namespace tooling

Modified: cfe/trunk/lib/Tooling/AllTUsExecution.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/AllTUsExecution.cpp?rev=368196&r1=368195&r2=368196&view=diff
==
--- cfe/trunk/lib/Tooling/AllTUsExecution.cpp (original)
+++ cfe/trunk/lib/Tooling/AllTUsExecution.cpp Wed Aug  7 11:35:28 2019
@@ -147,7 +147,7 @@ llvm::Error AllTUsToolExecutor::execute(
   return llvm::Error::success();
 }
 
-static llvm::cl::opt ExecutorConcurrency(
+llvm::cl::opt ExecutorConcurrency(
 "execute-concurrency",
 llvm::cl::desc("The number of threads used to process all files in "
"parallel. Set to 0 for hardware concurrency. "


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


[PATCH] D65833: [Tooling] Expose ExecutorConcurrency option.

2019-08-07 Thread Diego Astiazarán via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL368196: [Tooling] Expose ExecutorConcurrency option. 
(authored by DiegoAstiazaran, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65833?vs=213745&id=213959#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65833

Files:
  cfe/trunk/include/clang/Tooling/AllTUsExecution.h
  cfe/trunk/lib/Tooling/AllTUsExecution.cpp


Index: cfe/trunk/include/clang/Tooling/AllTUsExecution.h
===
--- cfe/trunk/include/clang/Tooling/AllTUsExecution.h
+++ cfe/trunk/include/clang/Tooling/AllTUsExecution.h
@@ -71,6 +71,7 @@
   unsigned ThreadCount;
 };
 
+extern llvm::cl::opt ExecutorConcurrency;
 extern llvm::cl::opt Filter;
 
 } // end namespace tooling
Index: cfe/trunk/lib/Tooling/AllTUsExecution.cpp
===
--- cfe/trunk/lib/Tooling/AllTUsExecution.cpp
+++ cfe/trunk/lib/Tooling/AllTUsExecution.cpp
@@ -147,7 +147,7 @@
   return llvm::Error::success();
 }
 
-static llvm::cl::opt ExecutorConcurrency(
+llvm::cl::opt ExecutorConcurrency(
 "execute-concurrency",
 llvm::cl::desc("The number of threads used to process all files in "
"parallel. Set to 0 for hardware concurrency. "


Index: cfe/trunk/include/clang/Tooling/AllTUsExecution.h
===
--- cfe/trunk/include/clang/Tooling/AllTUsExecution.h
+++ cfe/trunk/include/clang/Tooling/AllTUsExecution.h
@@ -71,6 +71,7 @@
   unsigned ThreadCount;
 };
 
+extern llvm::cl::opt ExecutorConcurrency;
 extern llvm::cl::opt Filter;
 
 } // end namespace tooling
Index: cfe/trunk/lib/Tooling/AllTUsExecution.cpp
===
--- cfe/trunk/lib/Tooling/AllTUsExecution.cpp
+++ cfe/trunk/lib/Tooling/AllTUsExecution.cpp
@@ -147,7 +147,7 @@
   return llvm::Error::success();
 }
 
-static llvm::cl::opt ExecutorConcurrency(
+llvm::cl::opt ExecutorConcurrency(
 "execute-concurrency",
 llvm::cl::desc("The number of threads used to process all files in "
"parallel. Set to 0 for hardware concurrency. "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64943: [Clang][OpenMP offload] Eliminate use of OpenMP linker script

2019-08-07 Thread Sergey Dmitriev via Phabricator via cfe-commits
sdmitriev marked 3 inline comments as done.
sdmitriev added inline comments.



Comment at: clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp:226
+// Add this function to global destructors.
+appendToGlobalDtors(M, Func, 0);
+  }

vzakhari wrote:
> FYI, llvm.global_dtors does not work on Windows.  The symbol will be placed 
> into .CRT$XC[A-Z] portion of .CRT in TargetLoweringObjectFileImpl.cpp, so, 
> basically, __tgt_unregister_lib will be called right after 
> __tgt_register_lib.  We can either use a trick from ASAN, i.e. put 
> llvm.global_dtors into .CRT$XT[A-Z] (I am not sure how solid this solution 
> is) or call atexit() inside __tgt_register_lib to register 
> __tgt_unregister_lib terminator.
It works as expected on Linux, so I guess this is just a bug in lowering code 
for Windows that need to be fixed.


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

https://reviews.llvm.org/D64943



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


[PATCH] D65835: [OpenMP] Fix map/is_device_ptr with DSA on combined directive

2019-08-07 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/test/OpenMP/target_parallel_for_is_device_ptr_messages.cpp:93
   ;
-#pragma omp target parallel for private(ps) is_device_ptr(ps) // 
expected-error{{private variable cannot be in a is_device_ptr clause in 
'#pragma omp target parallel for' directive}} expected-note{{defined as 
private}}
+#pragma omp target parallel for private(ps) is_device_ptr(ps)
 for (int ii=0; ii<10; ii++)

I think this should cause an error or at least a warning. Telling the compiler 
`ps` is a device pointer only to create a local uninitialized shadowing 
variable seems like an error to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65835



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


[PATCH] D64943: [Clang][OpenMP offload] Eliminate use of OpenMP linker script

2019-08-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp:226
+// Add this function to global destructors.
+appendToGlobalDtors(M, Func, 0);
+  }

sdmitriev wrote:
> vzakhari wrote:
> > FYI, llvm.global_dtors does not work on Windows.  The symbol will be placed 
> > into .CRT$XC[A-Z] portion of .CRT in TargetLoweringObjectFileImpl.cpp, so, 
> > basically, __tgt_unregister_lib will be called right after 
> > __tgt_register_lib.  We can either use a trick from ASAN, i.e. put 
> > llvm.global_dtors into .CRT$XT[A-Z] (I am not sure how solid this solution 
> > is) or call atexit() inside __tgt_register_lib to register 
> > __tgt_unregister_lib terminator.
> It works as expected on Linux, so I guess this is just a bug in lowering code 
> for Windows that need to be fixed.
Still, better to call atexit(), this is common solution to call a global 
destructor/deinitializer


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

https://reviews.llvm.org/D64943



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


[PATCH] D64943: [Clang][OpenMP offload] Eliminate use of OpenMP linker script

2019-08-07 Thread Vyacheslav Zakharin via Phabricator via cfe-commits
vzakhari added inline comments.



Comment at: clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp:226
+// Add this function to global destructors.
+appendToGlobalDtors(M, Func, 0);
+  }

ABataev wrote:
> sdmitriev wrote:
> > vzakhari wrote:
> > > FYI, llvm.global_dtors does not work on Windows.  The symbol will be 
> > > placed into .CRT$XC[A-Z] portion of .CRT in 
> > > TargetLoweringObjectFileImpl.cpp, so, basically, __tgt_unregister_lib 
> > > will be called right after __tgt_register_lib.  We can either use a trick 
> > > from ASAN, i.e. put llvm.global_dtors into .CRT$XT[A-Z] (I am not sure 
> > > how solid this solution is) or call atexit() inside __tgt_register_lib to 
> > > register __tgt_unregister_lib terminator.
> > It works as expected on Linux, so I guess this is just a bug in lowering 
> > code for Windows that need to be fixed.
> Still, better to call atexit(), this is common solution to call a global 
> destructor/deinitializer
I agree.  One other thing: if `__tgt_register_lib` is never called do we want 
to call `__tgt_unregister_lib`?  It is possible with global_ctors/global_dtors, 
but not possible with atexit/cxa_atexit.


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

https://reviews.llvm.org/D64943



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


[PATCH] D65835: [OpenMP] Fix map/is_device_ptr with DSA on combined directive

2019-08-07 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny marked an inline comment as done.
jdenny added a comment.

In D65835#1618865 , @ABataev wrote:

> `is_device_ptr` can be considered as a kind of mapping clause (see 2.19.7   
> Data-Mapping Attribute Rules, Clauses, and Directives), so, I assume, clang 
> correct here in terms of OpenMP 4.5.


Maybe, but I haven't found any statement in either version that states that map 
restrictions apply to is_device_ptr.

Another question is whether the restriction would make sense.  For example, 
does it ever make sense to specify both is_device_ptr and firstprivate for the 
same variable on a target construct?  I think that would mean that 
modifications that are made to that device pointer within the target region 
should not be seen after the target region.  I think that's reasonable, but 
that combination is not possible with the restriction.  As Johannes points out, 
private plus is_device_ptr probably doesn't make sense.

> Thus, I would not call this a "fix", this is just a new feature from OpenMP 
> 5.0.

Understood.

I should have reported that the current implementation isn't complete for 
OpenMP 4.5.  For example, on `target teams`, `reduction(+:x) map(x)` is an 
error but not `map(x) reduction(+:x)`.  So there are bugs to fix, and maybe 
this will evolve into multiple patches, but I want to be sure I'm on the right 
path first.

> Plus, these changes are not enough to support this new feature from OpenMP 
> 5.0. There definitely must be some changes in the codegen. If the variable is 
> mapped in the target construct, we should not generate a code for the private 
> clause of this variable on the target construct, since, in this case, private 
> clauses are applied for the inner subdirectives, which are the part of the 
> combined directive, but not the `target` part of the directive.

I'll look into it.

Thanks for the quick review.




Comment at: clang/lib/Sema/SemaOpenMP.cpp:10895
+// combined construct.
+if (CurrDir == OMPD_target) {
   OpenMPClauseKind ConflictKind;

ABataev wrote:
> I would suggest to guard this change and limit this new functionality only 
> for OpenMP 5.0. 
Do you agree that this is strictly an extension to 4.5 that won't alter the 
behavior of 4.5-conforming applications?

Do we generally want to complain about the use of extensions, or is there 
another reason for the guard you suggest?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65835



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


[PATCH] D65835: [OpenMP] Fix map/is_device_ptr with DSA on combined directive

2019-08-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/target_parallel_for_is_device_ptr_messages.cpp:93
   ;
-#pragma omp target parallel for private(ps) is_device_ptr(ps) // 
expected-error{{private variable cannot be in a is_device_ptr clause in 
'#pragma omp target parallel for' directive}} expected-note{{defined as 
private}}
+#pragma omp target parallel for private(ps) is_device_ptr(ps)
 for (int ii=0; ii<10; ii++)

jdoerfert wrote:
> I think this should cause an error or at least a warning. Telling the 
> compiler `ps` is a device pointer only to create a local uninitialized 
> shadowing variable seems like an error to me.
It is allowed according to OpenMP 5.0. Private copy must be created in the 
context of the parallel region, not the target region. So, for OpenMP 5.0 we 
should not emit error here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65835



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


[PATCH] D65889: [analyzer] CastValueChecker: Model castAs(), getAs()

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

Cheers! :)


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

https://reviews.llvm.org/D65889



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


[PATCH] D65019: [ARM] push LR before __gnu_mcount_nc

2019-08-07 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

This seems better.

I'm not sure I follow why this needs special handling in 
SelectionDAGBuilder::visitIntrinsicCall, as opposed to just using 
ISD::INTRINSIC_VOID like other similar target-specific intrinsics.  (You can 
custom-lower INTRINSIC_VOID in ARMTargetLowering::LowerOperation, if that makes 
it easier.)

I'd just skip changing fast-isel; with an intrinsic, if fast-isel misses, we 
just fall back to the SelectionDAG code that does the right thing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65019



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


[PATCH] D65835: [OpenMP] Fix map/is_device_ptr with DSA on combined directive

2019-08-07 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/test/OpenMP/target_parallel_for_is_device_ptr_messages.cpp:93
   ;
-#pragma omp target parallel for private(ps) is_device_ptr(ps) // 
expected-error{{private variable cannot be in a is_device_ptr clause in 
'#pragma omp target parallel for' directive}} expected-note{{defined as 
private}}
+#pragma omp target parallel for private(ps) is_device_ptr(ps)
 for (int ii=0; ii<10; ii++)

ABataev wrote:
> jdoerfert wrote:
> > I think this should cause an error or at least a warning. Telling the 
> > compiler `ps` is a device pointer only to create a local uninitialized 
> > shadowing variable seems like an error to me.
> It is allowed according to OpenMP 5.0. Private copy must be created in the 
> context of the parallel region, not the target region. So, for OpenMP 5.0 we 
> should not emit error here.
What does that mean and how does that affect my reasoning?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65835



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


[PATCH] D65835: [OpenMP] Fix map/is_device_ptr with DSA on combined directive

2019-08-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

> Maybe, but I haven't found any statement in either version that states that 
> map restrictions apply to is_device_ptr.

`is_device_ptr` is a kind of mapping clause. I assume we can extend the 
restrictions for `map` clause to this clause too.

> Another question is whether the restriction would make sense. For example, 
> does it ever make sense to specify both is_device_ptr and firstprivate for 
> the same variable on a target construct?

On a `target` construct - no. On a `target parallel` - yes. This may be 
important especially in unified shared memory mode.




Comment at: clang/test/OpenMP/target_parallel_for_is_device_ptr_messages.cpp:93
   ;
-#pragma omp target parallel for private(ps) is_device_ptr(ps) // 
expected-error{{private variable cannot be in a is_device_ptr clause in 
'#pragma omp target parallel for' directive}} expected-note{{defined as 
private}}
+#pragma omp target parallel for private(ps) is_device_ptr(ps)
 for (int ii=0; ii<10; ii++)

jdoerfert wrote:
> ABataev wrote:
> > jdoerfert wrote:
> > > I think this should cause an error or at least a warning. Telling the 
> > > compiler `ps` is a device pointer only to create a local uninitialized 
> > > shadowing variable seems like an error to me.
> > It is allowed according to OpenMP 5.0. Private copy must be created in the 
> > context of the parallel region, not the target region. So, for OpenMP 5.0 
> > we should not emit error here.
> What does that mean and how does that affect my reasoning?
It means, that for OpenMP 5.0 we should emit a warning/error here. It is 
allowed according to the standard, we should allow it too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65835



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


[PATCH] D65835: [OpenMP] Fix map/is_device_ptr with DSA on combined directive

2019-08-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

> I should have reported that the current implementation isn't complete for 
> OpenMP 4.5. For example, on target teams, reduction(+:x) map(x) is an error 
> but not map(x) reduction(+:x). So there are bugs to fix, and maybe this will 
> evolve into multiple patches, but I want to be sure I'm on the right path 
> first.

It is just a bug, not a missing feature. Just file a bug report for it.




Comment at: clang/lib/Sema/SemaOpenMP.cpp:10895
+// combined construct.
+if (CurrDir == OMPD_target) {
   OpenMPClauseKind ConflictKind;

jdenny wrote:
> ABataev wrote:
> > I would suggest to guard this change and limit this new functionality only 
> > for OpenMP 5.0. 
> Do you agree that this is strictly an extension to 4.5 that won't alter the 
> behavior of 4.5-conforming applications?
> 
> Do we generally want to complain about the use of extensions, or is there 
> another reason for the guard you suggest?
No. It is incorrect according to OpenMP 4.5 and we shall emit diagnostics here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65835



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


[PATCH] D65835: [OpenMP] Fix map/is_device_ptr with DSA on combined directive

2019-08-07 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In D65835#1619526 , @ABataev wrote:

> > Maybe, but I haven't found any statement in either version that states that 
> > map restrictions apply to is_device_ptr.
>
> `is_device_ptr` is a kind of mapping clause. I assume we can extend the 
> restrictions for `map` clause to this clause too.


I'd like to understand this better.  Is there something from the spec we can 
quote in the code?

>> Another question is whether the restriction would make sense. For example, 
>> does it ever make sense to specify both is_device_ptr and firstprivate for 
>> the same variable on a target construct?
> 
> On a `target` construct - no.

Why not?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65835



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


[PATCH] D65835: [OpenMP] Fix map/is_device_ptr with DSA on combined directive

2019-08-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D65835#1619549 , @jdenny wrote:

> In D65835#1619526 , @ABataev wrote:
>
> > > Maybe, but I haven't found any statement in either version that states 
> > > that map restrictions apply to is_device_ptr.
> >
> > `is_device_ptr` is a kind of mapping clause. I assume we can extend the 
> > restrictions for `map` clause to this clause too.
>
>
> I'd like to understand this better.  Is there something from the spec we can 
> quote in the code?


See 2.19.7 Data-Mapping Attribute Rules, Clauses, and Directives

> 
> 
>>> Another question is whether the restriction would make sense. For example, 
>>> does it ever make sense to specify both is_device_ptr and firstprivate for 
>>> the same variable on a target construct?
>> 
>> On a `target` construct - no.
> 
> Why not?

It is meaningless. That's why it is prohibited in OpenMP 5.0 and allowed only 
for the combined constructs. These private clauses are applied to inner 
subconstructs.
For example, `target parallel map(p) private(p)`. In the context of `target` 
region the variable is mapped while in the `parallel` context it is private.
For `target map(p) private(p)` it is absolutely meaningless.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65835



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


[PATCH] D60943: Delay diagnosing asm constraints that require immediates until after inlining

2019-08-07 Thread James Nagurne via Phabricator via cfe-commits
JamesNagurne added a comment.

In case you haven't seen, this commit breaks non-x86 build bots due to the 
combination of '-triple x86_64*' and '-S'. Some tests that use this target are 
only looking for AST dumps, and do not actually require such a target. This is 
not one of those tests, as it's inspecting assembly.
See clang/test/CodeGen/addrsig.c to see how that is handled (via REQUIRES: 
x86-registered-target).

Oddly enough, other tests that use -triple x86_64* and only inspect the AST 
don't require the registered target.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D60943



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


[PATCH] D65545: Handle some fs::remove failures

2019-08-07 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

I have no other comments but for the fatal error in `FileRemover` I'd like to 
loop in Jonas as he was touching module cache in LLDB fairly recently.




Comment at: clang/lib/Frontend/CompilerInstance.cpp:1444-1445
   // Remove the file.
-  llvm::sys::fs::remove(File->path());
+  if ((EC = llvm::sys::fs::remove(File->path(
+break;
 

jfb wrote:
> vsapsai wrote:
> > jfb wrote:
> > > vsapsai wrote:
> > > > Why are you interrupting the loop when cannot remove a file? Don't know 
> > > > which option is the right one, just want to know your reasons.
> > > The loops already bail when `EC` is set, and here I figure if we can't 
> > > remove the base file we shouldn't try to remove its corresponding 
> > > timestamp.
> > I was thinking about using `continue` instead of `break`. After some 
> > thinking I believe `continue` is better because this way we'll try to 
> > remove all stale module files that we can. Otherwise one bad file can 
> > prevent the module cache pruning from working.
> > 
> > And I agree with your logic about not removing the timestamp when cannot 
> > remove the base file.
> `continue` will hit `File != FileEnd && !EC`, so it's equivalent to `break`. 
> Your thinking makes sense, but I think we'd want to do it in a separate patch.
OK, I see now. Thanks for explanation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65545



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


  1   2   >