[PATCH] D63316: [clangd] Include the diagnostics's code when comparing diagnostics

2019-06-15 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 204939.
nridge added a comment.

Revise fix and add test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63316

Files:
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/test/fixits-duplication.test

Index: clang-tools-extra/clangd/test/fixits-duplication.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/fixits-duplication.test
@@ -0,0 +1,135 @@
+# RUN: clangd -lit-test -clang-tidy-checks=modernize-use-nullptr,hicpp-use-nullptr < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{,"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.cpp","languageId":"cpp","version":1,"text":"void foo() { char* p = 0; }"}}}
+#  CHECK:"method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:  "params": {
+# CHECK-NEXT:"diagnostics": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"code": "hicpp-use-nullptr",
+# CHECK-NEXT:"message": "Use nullptr (fix available)",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 24,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 23,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"severity": 2,
+# CHECK-NEXT:"source": "clang-tidy"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  {
+# CHECK-NEXT:"code": "modernize-use-nullptr",
+# CHECK-NEXT:"message": "Use nullptr (fix available)",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 24,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 23,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"severity": 2,
+# CHECK-NEXT:"source": "clang-tidy"
+# CHECK-NEXT:  }
+# CHECK-NEXT:],
+# CHECK-NEXT:"uri": "file:///{{.*}}/foo.cpp"
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.cpp"},"range":{"start":{"line":0,"character":23},"end":{"line":0,"character":24}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 23}, "end": {"line": 0, "character": 24}},"severity":2,"message":"Use nullptr (fix available)", "code": "hicpp-use-nullptr", "source": "clang-tidy"},{"range":{"start": {"line": 0, "character": 23}, "end": {"line": 0, "character": 24}},"severity":2,"message":"Use nullptr (fix available)", "code": "modernize-use-nullptr", "source": "clang-tidy"}]}}}
+#  CHECK:  "id": 2,
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "diagnostics": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "code": "hicpp-use-nullptr",
+# CHECK-NEXT:  "message": "Use nullptr (fix available)",
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 24,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:},
+# CHECK-NEXT:"start": {
+# CHECK-NEXT:  "character": 23,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "severity": 2,
+# CHECK-NEXT:  "source": "clang-tidy"
+# CHECK-NEXT:}
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  "edit": {
+# CHECK-NEXT:"changes": {
+# CHECK-NEXT:  "file://{{.*}}/foo.cpp": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "newText": "nullptr",
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 24,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:},
+# CHECK-NEXT:"start": {
+# CHECK-NEXT:  "character": 23,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:}
+# CHECK-NEXT:  }
+# CHECK-NEXT:}
+# CHECK-NEXT:  ]
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "kind": "quickfix",
+# CHECK-NEXT:  "title": "change '0' to 'nullptr'"
+# CHECK-NEXT:},
+# CHECK-NEXT:{
+# CHECK-NEXT:  "diagnostics": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "code": "modernize-use-nullptr",
+# CHECK-NEXT:  "message": "Use nullptr (fix available)",
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 24,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:

[PATCH] D63316: [clangd] Include the diagnostics's code when comparing diagnostics

2019-06-15 Thread Nathan Ridge via Phabricator via cfe-commits
nridge marked an inline comment as done.
nridge added a comment.

The fix actually broke another lit test, because in that test the client was 
not sending the diagnostic's code back in the `codeAction` request, resulting 
in a mismatch with the new comparison function.

I think a real client could potentially could this too (not send the code 
back), so I revised the fix to address this case, by only using the code in the 
comparison if it's present in both objects.

Also added the requested new lit test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63316



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


Hello everyone, LLVM buildmaster will be restarted soon

2019-06-15 Thread Galina Kistanova via cfe-commits
 Hello everyone,

LLVM buildmaster will be restarted in the few minutes.

Thanks

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


[PATCH] D58880: [clangd] Type hierarchy subtypes

2019-06-15 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363506: [clangd] Type hierarchy subtypes (authored by 
nridge, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58880?vs=204937=204938#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58880

Files:
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/FindSymbols.cpp
  clang-tools-extra/trunk/clangd/FindSymbols.h
  clang-tools-extra/trunk/clangd/XRefs.cpp
  clang-tools-extra/trunk/clangd/XRefs.h
  clang-tools-extra/trunk/clangd/test/type-hierarchy.test
  clang-tools-extra/trunk/clangd/unittests/TypeHierarchyTests.cpp

Index: clang-tools-extra/trunk/clangd/test/type-hierarchy.test
===
--- clang-tools-extra/trunk/clangd/test/type-hierarchy.test
+++ clang-tools-extra/trunk/clangd/test/type-hierarchy.test
@@ -1,12 +1,39 @@
 # RUN: clangd -lit-test < %s | FileCheck -strict-whitespace %s
 {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 ---
-{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"struct Parent {};\nstruct Child1 : Parent {};\nstruct Child2 : Child1 {};"}}}
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///main.cpp","languageId":"cpp","version":1,"text":"struct Parent {};\nstruct Child1 : Parent {};\nstruct Child2 : Child1 {};\nstruct Child3 : Child2 {};"}}}
 ---
-{"jsonrpc":"2.0","id":1,"method":"textDocument/typeHierarchy","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":2,"character":11},"direction":1,"resolve":1}}
+{"jsonrpc":"2.0","id":1,"method":"textDocument/typeHierarchy","params":{"textDocument":{"uri":"test:///main.cpp"},"position":{"line":2,"character":11},"direction":2,"resolve":1}}
 #  CHECK:  "id": 1
 # CHECK-NEXT:  "jsonrpc": "2.0",
 # CHECK-NEXT:  "result": {
+# CHECK-NEXT:"children": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"kind": 23,
+# CHECK-NEXT:"name": "Child3",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 13,
+# CHECK-NEXT:"line": 3
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 7,
+# CHECK-NEXT:"line": 3
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"selectionRange": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 13,
+# CHECK-NEXT:"line": 3
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 7,
+# CHECK-NEXT:"line": 3
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"uri": "file:///clangd-test/main.cpp"
+# CHECK-NEXT:  }
+# CHECK-NEXT:],
 # CHECK-NEXT:"kind": 23,
 # CHECK-NEXT:"name": "Child2",
 # CHECK-NEXT:"parents": [
Index: clang-tools-extra/trunk/clangd/FindSymbols.cpp
===
--- clang-tools-extra/trunk/clangd/FindSymbols.cpp
+++ clang-tools-extra/trunk/clangd/FindSymbols.cpp
@@ -39,6 +39,37 @@
 
 } // namespace
 
+llvm::Expected symbolToLocation(const Symbol ,
+  llvm::StringRef HintPath) {
+  // Prefer the definition over e.g. a function declaration in a header
+  auto  = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
+  auto Uri = URI::parse(CD.FileURI);
+  if (!Uri) {
+return llvm::make_error(
+formatv("Could not parse URI '{0}' for symbol '{1}'.", CD.FileURI,
+Sym.Name),
+llvm::inconvertibleErrorCode());
+  }
+  auto Path = URI::resolve(*Uri, HintPath);
+  if (!Path) {
+return llvm::make_error(
+formatv("Could not resolve path for URI '{0}' for symbol '{1}'.",
+Uri->toString(), Sym.Name),
+llvm::inconvertibleErrorCode());
+  }
+  Location L;
+  // Use HintPath as TUPath since there is no TU associated with this
+  // request.
+  L.uri = URIForFile::canonicalize(*Path, HintPath);
+  Position Start, End;
+  Start.line = CD.Start.line();
+  Start.character = CD.Start.column();
+  End.line = CD.End.line();
+  End.character = CD.End.column();
+  L.range = {Start, End};
+  return L;
+}
+
 llvm::Expected>
 getWorkspaceSymbols(llvm::StringRef Query, int Limit,
 const SymbolIndex *const Index, llvm::StringRef HintPath) {
@@ -65,37 +96,18 @@
   Req.Limit ? *Req.Limit : std::numeric_limits::max());
   FuzzyMatcher Filter(Req.Query);
   Index->fuzzyFind(Req, [HintPath, , ](const Symbol ) {
-// Prefer the definition over e.g. a function declaration in a header
-auto  = 

[PATCH] D58880: [clangd] Type hierarchy subtypes

2019-06-15 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/XRefs.cpp:1052
+  PathRef TUPath) {
+  // TODO: Pass in ClangdServer::WorkspaceRoot as a HintPath.
+  StringRef HintPath;

kadircet wrote:
> this part looks a little messed up ?
> 
>  I suppose you wanted to propagate TUPath to symbolToLocation right?
Good catch! Fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58880



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


[PATCH] D58880: [clangd] Type hierarchy subtypes

2019-06-15 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 204937.
nridge marked 5 inline comments as done.
nridge added a comment.

Address remaining review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D58880

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/FindSymbols.cpp
  clang-tools-extra/clangd/FindSymbols.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/test/type-hierarchy.test
  clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp

Index: clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
===
--- clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
+++ clang-tools-extra/clangd/unittests/TypeHierarchyTests.cpp
@@ -34,7 +34,7 @@
 using ::testing::IsEmpty;
 using ::testing::Matcher;
 using ::testing::Pointee;
-using ::testing::UnorderedElementsAreArray;
+using ::testing::UnorderedElementsAre;
 
 // GMock helpers for matching TypeHierarchyItem.
 MATCHER_P(WithName, N, "") { return arg.name == N; }
@@ -450,6 +450,158 @@
   SelectionRangeIs(Source.range("SDef")), Parents();
 }
 
+SymbolID findSymbolIDByName(SymbolIndex *Index, llvm::StringRef Name,
+llvm::StringRef TemplateArgs = "") {
+  SymbolID Result;
+  FuzzyFindRequest Request;
+  Request.Query = Name;
+  Request.AnyScope = true;
+  bool GotResult = false;
+  Index->fuzzyFind(Request, [&](const Symbol ) {
+if (TemplateArgs == S.TemplateSpecializationArgs) {
+  EXPECT_FALSE(GotResult);
+  Result = S.ID;
+  GotResult = true;
+}
+  });
+  EXPECT_TRUE(GotResult);
+  return Result;
+}
+
+std::vector collectSubtypes(SymbolID Subject, SymbolIndex *Index) {
+  std::vector Result;
+  RelationsRequest Req;
+  Req.Subjects.insert(Subject);
+  Req.Predicate = index::SymbolRole::RelationBaseOf;
+  Index->relations(Req,
+   [](const SymbolID , const Symbol ) {
+ Result.push_back(Object.ID);
+   });
+  return Result;
+}
+
+TEST(Subtypes, SimpleInheritance) {
+  Annotations Source(R"cpp(
+struct Parent {};
+struct Child1a : Parent {};
+struct Child1b : Parent {};
+struct Child2 : Child1a {};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent = findSymbolIDByName(Index.get(), "Parent");
+  SymbolID Child1a = findSymbolIDByName(Index.get(), "Child1a");
+  SymbolID Child1b = findSymbolIDByName(Index.get(), "Child1b");
+  SymbolID Child2 = findSymbolIDByName(Index.get(), "Child2");
+
+  EXPECT_THAT(collectSubtypes(Parent, Index.get()),
+  UnorderedElementsAre(Child1a, Child1b));
+  EXPECT_THAT(collectSubtypes(Child1a, Index.get()), ElementsAre(Child2));
+}
+
+TEST(Subtypes, MultipleInheritance) {
+  Annotations Source(R"cpp(
+struct Parent1 {};
+struct Parent2 {};
+struct Parent3 : Parent2 {};
+struct Child : Parent1, Parent3 {};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent1 = findSymbolIDByName(Index.get(), "Parent1");
+  SymbolID Parent2 = findSymbolIDByName(Index.get(), "Parent2");
+  SymbolID Parent3 = findSymbolIDByName(Index.get(), "Parent3");
+  SymbolID Child = findSymbolIDByName(Index.get(), "Child");
+
+  EXPECT_THAT(collectSubtypes(Parent1, Index.get()), ElementsAre(Child));
+  EXPECT_THAT(collectSubtypes(Parent2, Index.get()), ElementsAre(Parent3));
+  EXPECT_THAT(collectSubtypes(Parent3, Index.get()), ElementsAre(Child));
+}
+
+TEST(Subtypes, ClassTemplate) {
+  Annotations Source(R"cpp(
+struct Parent {};
+
+template 
+struct Child : Parent {};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent = findSymbolIDByName(Index.get(), "Parent");
+  SymbolID Child = findSymbolIDByName(Index.get(), "Child");
+
+  EXPECT_THAT(collectSubtypes(Parent, Index.get()), ElementsAre(Child));
+}
+
+TEST(Subtypes, TemplateSpec1) {
+  Annotations Source(R"cpp(
+template 
+struct Parent {};
+
+template <>
+struct Parent {};
+
+struct Child1 : Parent {};
+
+struct Child2 : Parent {};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  SymbolID Parent = findSymbolIDByName(Index.get(), "Parent");
+  SymbolID ParentSpec = findSymbolIDByName(Index.get(), "Parent", "");
+  SymbolID Child1 = findSymbolIDByName(Index.get(), "Child1");
+  SymbolID Child2 = findSymbolIDByName(Index.get(), "Child2");
+
+  EXPECT_THAT(collectSubtypes(Parent, Index.get()), ElementsAre(Child1));
+  EXPECT_THAT(collectSubtypes(ParentSpec, Index.get()), ElementsAre(Child2));
+}
+
+TEST(Subtypes, TemplateSpec2) {
+  Annotations Source(R"cpp(
+struct Parent {};
+
+template 
+struct Child {};
+
+template <>
+struct Child : Parent {};
+)cpp");
+
+  TestTU TU = TestTU::withCode(Source.code());
+  auto Index = TU.index();
+
+  

[clang-tools-extra] r363506 - [clangd] Type hierarchy subtypes

2019-06-15 Thread Nathan Ridge via cfe-commits
Author: nridge
Date: Sat Jun 15 19:31:37 2019
New Revision: 363506

URL: http://llvm.org/viewvc/llvm-project?rev=363506=rev
Log:
[clangd] Type hierarchy subtypes

Summary:
This builds on the relations support added in D59407, D62459, D62471,
and D62839 to implement type hierarchy subtypes.

Reviewers: kadircet

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, mgrang, arphaman,
jdoerfert, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/FindSymbols.cpp
clang-tools-extra/trunk/clangd/FindSymbols.h
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/clangd/XRefs.h
clang-tools-extra/trunk/clangd/test/type-hierarchy.test
clang-tools-extra/trunk/clangd/unittests/TypeHierarchyTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=363506=363505=363506=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Sat Jun 15 19:31:37 2019
@@ -339,8 +339,7 @@ void ClangdServer::applyTweak(PathRef Fi
 // out a way to cache the format style.
 auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
InpAST->Inputs.FS.get());
-auto Formatted =
-cleanupAndFormat(InpAST->Inputs.Contents, *Raw, Style);
+auto Formatted = cleanupAndFormat(InpAST->Inputs.Contents, *Raw, Style);
 if (!Formatted)
   return CB(Formatted.takeError());
 return CB(replacementsToEdits(InpAST->Inputs.Contents, *Formatted));
@@ -487,11 +486,13 @@ void ClangdServer::findHover(PathRef Fil
 void ClangdServer::typeHierarchy(PathRef File, Position Pos, int Resolve,
  TypeHierarchyDirection Direction,
  Callback> CB) {
-  auto Action = [Pos, Resolve, Direction](decltype(CB) CB,
-  Expected InpAST) {
+  std::string FileCopy = File; // copy will be captured by the lambda
+  auto Action = [FileCopy, Pos, Resolve, Direction,
+ this](decltype(CB) CB, Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
-CB(clangd::getTypeHierarchy(InpAST->AST, Pos, Resolve, Direction));
+CB(clangd::getTypeHierarchy(InpAST->AST, Pos, Resolve, Direction, Index,
+FileCopy));
   };
 
   WorkScheduler.runWithAST("Type Hierarchy", File, Bind(Action, 
std::move(CB)));

Modified: clang-tools-extra/trunk/clangd/FindSymbols.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FindSymbols.cpp?rev=363506=363505=363506=diff
==
--- clang-tools-extra/trunk/clangd/FindSymbols.cpp (original)
+++ clang-tools-extra/trunk/clangd/FindSymbols.cpp Sat Jun 15 19:31:37 2019
@@ -39,6 +39,37 @@ struct ScoredSymbolGreater {
 
 } // namespace
 
+llvm::Expected symbolToLocation(const Symbol ,
+  llvm::StringRef HintPath) {
+  // Prefer the definition over e.g. a function declaration in a header
+  auto  = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
+  auto Uri = URI::parse(CD.FileURI);
+  if (!Uri) {
+return llvm::make_error(
+formatv("Could not parse URI '{0}' for symbol '{1}'.", CD.FileURI,
+Sym.Name),
+llvm::inconvertibleErrorCode());
+  }
+  auto Path = URI::resolve(*Uri, HintPath);
+  if (!Path) {
+return llvm::make_error(
+formatv("Could not resolve path for URI '{0}' for symbol '{1}'.",
+Uri->toString(), Sym.Name),
+llvm::inconvertibleErrorCode());
+  }
+  Location L;
+  // Use HintPath as TUPath since there is no TU associated with this
+  // request.
+  L.uri = URIForFile::canonicalize(*Path, HintPath);
+  Position Start, End;
+  Start.line = CD.Start.line();
+  Start.character = CD.Start.column();
+  End.line = CD.End.line();
+  End.character = CD.End.column();
+  L.range = {Start, End};
+  return L;
+}
+
 llvm::Expected>
 getWorkspaceSymbols(llvm::StringRef Query, int Limit,
 const SymbolIndex *const Index, llvm::StringRef HintPath) {
@@ -65,37 +96,18 @@ getWorkspaceSymbols(llvm::StringRef Quer
   Req.Limit ? *Req.Limit : std::numeric_limits::max());
   FuzzyMatcher Filter(Req.Query);
   Index->fuzzyFind(Req, [HintPath, , ](const Symbol ) {
-// Prefer the definition over e.g. a function declaration in a header
-auto  = Sym.Definition ? Sym.Definition : Sym.CanonicalDeclaration;
-auto Uri = URI::parse(CD.FileURI);
-if (!Uri) {
-  log("Workspace symbol: Could not parse URI '{0}' for symbol '{1}'.",
-  CD.FileURI, Sym.Name);
-  return;
-}
-auto 

[PATCH] D63331: [clangd] WIP/RFC: Prototype for semantic highlighting proposal

2019-06-15 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

In D63331#1543441 , @hokein wrote:

> To avoid multiple people working on the same feature, I think the plan is 
> that @jvikstrom will pick up the current stuff, and continue 
> working/improving it.


Sounds good! I'm excited to see this moving forward :)

I've had a look at this patch, and it's very similar to my prototype 
implementation in D61842 . Mine handles some 
more cases in the RecursiveASTVIsitor, especially around dependent names inside 
templates, and has corresponding test cases that you may want to reuse 
@jvikstrom.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63331



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


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

2019-06-15 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thanks for fixing that!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D62839



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


[clang-tools-extra] r363504 - Fix gcc-05.4 bot failures caused by in r363481 "[clangd] Index API and implementations for relations"

2019-06-15 Thread Don Hinton via cfe-commits
Author: dhinton
Date: Sat Jun 15 18:09:41 2019
New Revision: 363504

URL: http://llvm.org/viewvc/llvm-project?rev=363504=rev
Log:
Fix gcc-05.4 bot failures caused by in r363481 "[clangd] Index API and 
implementations for relations"

Use std::make_tuple instead of initializer list to make gcc-5.4 happy.

See https://reviews.llvm.org/D62839 for details.

Modified:
clang-tools-extra/trunk/clangd/index/FileIndex.cpp

Modified: clang-tools-extra/trunk/clangd/index/FileIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/FileIndex.cpp?rev=363504=363503=363504=diff
==
--- clang-tools-extra/trunk/clangd/index/FileIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/FileIndex.cpp Sat Jun 15 18:09:41 2019
@@ -72,7 +72,8 @@ static SlabTuple indexSymbols(ASTContext
"  relations slab: {7} relations, {8} bytes",
FileName, IsIndexMainAST, Syms.size(), Syms.bytes(), Refs.size(),
Refs.numRefs(), Refs.bytes(), Relations.size(), Relations.bytes());
-  return {std::move(Syms), std::move(Refs), std::move(Relations)};
+  return std::make_tuple(std::move(Syms), std::move(Refs),
+ std::move(Relations));
 }
 
 SlabTuple indexMainDecls(ParsedAST ) {


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


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

2019-06-15 Thread Don Hinton via Phabricator via cfe-commits
hintonda added a comment.

This seems to have broken gcc 5.4 builds -- for example see 
http://lab.llvm.org:8011/builders/clang-cmake-armv7-lnt/builds/29/steps/build%20stage%201/logs/stdio.

I believe the following patch should fix the problem:

  diff --git a/clang-tools-extra/clangd/index/FileIndex.cpp 
b/clang-tools-extra/clangd/index/FileIndex.cpp
  index a90c51b0990..802e4c4a396 100644
  --- a/clang-tools-extra/clangd/index/FileIndex.cpp
  +++ b/clang-tools-extra/clangd/index/FileIndex.cpp
  @@ -72,7 +72,7 @@ static SlabTuple indexSymbols(ASTContext , 
std::shared_ptr PP,
  "  relations slab: {7} relations, {8} bytes",
  FileName, IsIndexMainAST, Syms.size(), Syms.bytes(), Refs.size(),
  Refs.numRefs(), Refs.bytes(), Relations.size(), Relations.bytes());
  -  return {std::move(Syms), std::move(Refs), std::move(Relations)};
  +  return std::make_tuple(std::move(Syms), std::move(Refs), 
std::move(Relations));
   }
  
   SlabTuple indexMainDecls(ParsedAST ) {


Repository:
  rL LLVM

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

https://reviews.llvm.org/D62839



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


[PATCH] D62873: Avoid building analyzer plugins if CLANG_ENABLE_STATIC_ANALYZER is OFF

2019-06-15 Thread Dimitry Andric via Phabricator via cfe-commits
dim abandoned this revision.
dim added a comment.

No longer needed after rC362328  and 
follow-ups.


Repository:
  rC Clang

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

https://reviews.llvm.org/D62873



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


[PATCH] D63009: [OpenMP] Add target task alloc function with device ID

2019-06-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D63009#1544900 , @gtbercea wrote:

> In D63009#1544758 , @Hahnfeld wrote:
>
> > Am I correct that the second to last revision ("- Fix tests.") removed all 
> > checks for the actual `device_id` argument from the tests? From my point of 
> > view that's not fixing but weakening the tests! Can you explain why they 
> > needed "fixing"?
>
>
> When I was just passing the default value the LLVM-IR was: i64 -1 i.e. 
> constant, easy to check.
>
> With the latest change the emitted code is: i64 %123 i.e. where %123 is a 
> local derived from the expression of the device ID.


If the value is constant, check for the constant. And at least several tests 
with the expressions should check for the correct value of the expression.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63009



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


[PATCH] D62550: [coroutines][PR41909] Don't build dependent coroutine statements for generic lambda

2019-06-15 Thread Brian Gesiak via Phabricator via cfe-commits
modocache added inline comments.



Comment at: cfe/trunk/lib/Sema/TreeTransform.h:7173
+auto *MD = dyn_cast_or_null(FD);
+if (!MD || !MD->getParent()->isGenericLambda()) {
+  assert(!Promise->getType()->isDependentType() &&

rsmith wrote:
> This assert doesn't seem correct to me; there's no reason to assume we have a 
> generic lambda here. (A non-generic lambda inside a generic lambda, whose 
> parameter types are dependent on the generic lambda's parameters, would hit 
> exactly the same issue, for instance.)
> 
> Generally we should write the template instantiation code so it could be used 
> to substitute into the definition of a function template to produce another 
> function template, even if we happen to never call it that way right now 
> (though deduction guide processing gets pretty close). The right thing to do 
> here is to either substitute into the representation we already formed 
> (building a dependent representation if it's still dependent and a 
> non-dependent representation otherwise) or to rebuild the coroutine body from 
> scratch (again, creating a dependent representation if the result is still 
> dependent).
Sorry I missed this! Indeed you're right, the check here is weak, and even with 
this patch the following coroutines code crashes in the same way: 
https://godbolt.org/z/ixLpCq

I'll send a follow-up patch that attempts to implement one of the approaches 
you describe. Thanks for the guidance!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D62550



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


r363502 - Recommit r363298 "[lit] Disable test on darwin when building shared libs."

2019-06-15 Thread Don Hinton via cfe-commits
Author: dhinton
Date: Sat Jun 15 13:09:54 2019
New Revision: 363502

URL: http://llvm.org/viewvc/llvm-project?rev=363502=rev
Log:
Recommit r363298 "[lit] Disable test on darwin when building shared libs."

Was reverted in r363379 due to build breakage.

Thanks to Nico Weber for reverting the original and suggesting the
fix.

Please see https://reviews.llvm.org/D61697

Modified:
cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
cfe/trunk/test/lit.cfg.py

Modified: cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp?rev=363502=363501=363502=diff
==
--- cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp 
(original)
+++ cfe/trunk/test/Tooling/clang-check-mac-libcxx-fixed-compilation-db.cpp Sat 
Jun 15 13:09:54 2019
@@ -16,5 +16,7 @@
 //
 // ^ -ccc-install-dir passed to unbreak tests on *BSD where
 //   getMainExecutable() relies on real argv[0] being passed
+//
+// UNSUPPORTED: enable_shared
 #include 
 vector v;

Modified: cfe/trunk/test/lit.cfg.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/lit.cfg.py?rev=363502=363501=363502=diff
==
--- cfe/trunk/test/lit.cfg.py (original)
+++ cfe/trunk/test/lit.cfg.py Sat Jun 15 13:09:54 2019
@@ -183,3 +183,6 @@ if macOSSDKVersion is not None:
 
 if os.path.exists('/etc/gentoo-release'):
 config.available_features.add('gentoo')
+
+if config.enable_shared:
+config.available_features.add("enable_shared")


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


[PATCH] D62611: [analyzer][Dominators] Add unittests

2019-06-15 Thread Sanaa82016 Najjar via Phabricator via cfe-commits
sanaanajjar231288 added a comment.

In D62611#1521692 , @Szelethus wrote:

> Fixes according to reviewer comments, thanks! :)





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

https://reviews.llvm.org/D62611



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


[PATCH] D63324: [clang-tidy] Replace memcpy by std::copy

2019-06-15 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h:41
+  std::unique_ptr Inserter;
+  const utils::IncludeSorter::IncludeStyle IncludeStyle;
+};

I think this could be determined from .clang-format.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:204
+  
+- New :doc:`modernize-replace-memcpy-by-stdcopy
+  ` check.

Please move into new checks list (in alphabetical order).



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:207
+  
+  Replace all occurences of the C "memcpy" function by "std::copy".
 

Replace**s**. Please use double back-ticks to highlight language constructs.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-memcpy-by-stdcopy.rst:6
+
+This check replaces all occurences of the C "memcpy" function by "std::copy"
+

Please make first sentance same as in Release Notes.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-memcpy-by-stdcopy.rst:35
+
+   A string specifying which include-style is used, `llvm` or `google`. Default
+   is `llvm`.

I think this could be determined from project's .clang-format.


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

https://reviews.llvm.org/D63324



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


[PATCH] D63324: [clang-tidy] Replace memcpy by std::copy

2019-06-15 Thread Thomas Manceau via Phabricator via cfe-commits
Blackhart updated this revision to Diff 204932.

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

https://reviews.llvm.org/D63324

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-memcpy-by-stdcopy.rst

Index: clang-tools-extra/docs/clang-tidy/checks/modernize-replace-memcpy-by-stdcopy.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/modernize-replace-memcpy-by-stdcopy.rst
@@ -0,0 +1,36 @@
+.. title:: clang-tidy - modernize-replace-memcpy-by-stdcopy
+
+modernize-replace-memcpy-by-stdcopy
+===
+
+This check replaces all occurences of the C "memcpy" function by "std::copy"
+
+Example:
+
+.. code-blocK:: c++
+
+  /*!
+   * \param destination Pointer to the destination array where the content is to be copied
+   * \param source Pointer to the source of data to be copied
+   * \param num Number of bytes to copy
+   */
+  memcpy(destination, source, num);
+
+becomes
+
+.. code-block:: c++
+
+  /*!
+   * \param destination Pointer to the destination array where the content is to be copied
+   * \param source Pointer to the source of data to be copied
+   * \param num Number of bytes to copy
+   */
+  std::copy(source, source + (num / sizeof *source), destination);
+
+Options
+---
+
+.. option:: IncludeStyle
+
+   A string specifying which include-style is used, `llvm` or `google`. Default
+   is `llvm`.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -200,6 +200,11 @@
 
   If set to true, the check will provide fix-its with literal initializers
   (``int i = 0;``) instead of curly braces (``int i{};``).
+  
+- New :doc:`modernize-replace-memcpy-by-stdcopy
+  ` check.
+  
+  Replace all occurences of the C "memcpy" function by "std::copy".
 
 Improvements to include-fixer
 -
Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
@@ -0,0 +1,48 @@
+//===--- ReplaceMemcpyByStdCopy.h - clang-tidy*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+/// Replace the C memcpy function by std::copy
+class ReplaceMemcpyByStdCopy : public ClangTidyCheck {
+public:
+  ReplaceMemcpyByStdCopy(StringRef Name, ClangTidyContext *Context);
+  ~ReplaceMemcpyByStdCopy() override = default;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void registerPPCallbacks(const SourceManager , Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
+
+private:
+  void renameFunction(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void reorderArgs(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void insertHeader(DiagnosticBuilder , const CallExpr *MemcpyNode,
+SourceManager *const SM);
+
+private:
+  std::unique_ptr Inserter;
+  const utils::IncludeSorter::IncludeStyle IncludeStyle;
+};
+
+} // namespace modernize
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
@@ -0,0 +1,117 @@
+//===--- ReplaceMemcpyByStdCopy.cpp - clang-tidy--*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//

[PATCH] D63324: [clang-tidy] Replace memcpy by std::copy

2019-06-15 Thread Thomas Manceau via Phabricator via cfe-commits
Blackhart updated this revision to Diff 204930.
Blackhart marked 2 inline comments as done.
Blackhart added a comment.

- Update releasenotes
- Add documentation


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

https://reviews.llvm.org/D63324

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-memcpy-by-stdcopy.rst

Index: clang-tools-extra/docs/clang-tidy/checks/modernize-replace-memcpy-by-stdcopy.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/modernize-replace-memcpy-by-stdcopy.rst
@@ -0,0 +1,36 @@
+.. title:: clang-tidy - modernize-replace-memcpy-by-stdcopy
+
+modernize-replace-memcpy-by-stdcopy
+===
+
+This check all occurences of the C "memcpy" function by "std::copy"
+
+Example:
+
+.. code-blocK:: c++
+
+  /*!
+   * \param destination Pointer to the destination array where the content is to be copied
+   * \param source Pointer to the source of data to be copied
+   * \param num Number of bytes to copy
+   */
+  memcpy(destination, source, num);
+
+becomes
+
+.. code-block:: c++
+
+  /*!
+   * \param destination Pointer to the destination array where the content is to be copied
+   * \param source Pointer to the source of data to be copied
+   * \param num Number of bytes to copy
+   */
+  std::copy(source, source + (num / sizeof *source), destination);
+
+Options
+---
+
+.. option:: IncludeStyle
+
+   A string specifying which include-style is used, `llvm` or `google`. Default
+   is `llvm`.
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -200,6 +200,11 @@
 
   If set to true, the check will provide fix-its with literal initializers
   (``int i = 0;``) instead of curly braces (``int i{};``).
+  
+- New :doc:`modernize-replace-memcpy-by-stdcopy
+  ` check.
+  
+  Replace all occurences of the C "memcpy" function by "std::copy".
 
 Improvements to include-fixer
 -
Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
@@ -0,0 +1,48 @@
+//===--- ReplaceMemcpyByStdCopy.h - clang-tidy*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+/// Replace the C memcpy function by std::copy
+class ReplaceMemcpyByStdCopy : public ClangTidyCheck {
+public:
+  ReplaceMemcpyByStdCopy(StringRef Name, ClangTidyContext *Context);
+  ~ReplaceMemcpyByStdCopy() override = default;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void registerPPCallbacks(const SourceManager , Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
+
+private:
+  void renameFunction(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void reorderArgs(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void insertHeader(DiagnosticBuilder , const CallExpr *MemcpyNode,
+SourceManager *const SM);
+
+private:
+  std::unique_ptr Inserter;
+  const utils::IncludeSorter::IncludeStyle IncludeStyle;
+};
+
+} // namespace modernize
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
@@ -0,0 +1,117 @@
+//===--- ReplaceMemcpyByStdCopy.cpp - clang-tidy--*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: 

[PATCH] D63167: [Clang] Remove unused -split-dwarf and obsolete -enable-split-dwarf

2019-06-15 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:864
   default:
-if (!CodeGenOpts.SplitDwarfOutput.empty() &&
-(CodeGenOpts.getSplitDwarfMode() == CodeGenOptions::SplitFileFission)) 
{
+if (!CodeGenOpts.SplitDwarfOutput.empty()) {
   DwoOS = openOutputFile(CodeGenOpts.SplitDwarfOutput);

Perhaps I should also check whether `SplitDwarfFile` is empty.



Comment at: clang/lib/CodeGen/BackendUtil.cpp:1276
 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
-if (!CodeGenOpts.SplitDwarfOutput.empty() &&
-CodeGenOpts.getSplitDwarfMode() == CodeGenOptions::SplitFileFission) {
+if (!CodeGenOpts.SplitDwarfOutput.empty()) {
   DwoOS = openOutputFile(CodeGenOpts.SplitDwarfOutput);

Dito here.



Comment at: clang/test/CodeGen/split-debug-filename.c:14-16
-// Testing to ensure that the dwo name is not output into the compile unit if
-// it's for vanilla split-dwarf rather than split-dwarf for implicit modules.
-// VANILLA-NOT: splitDebugFilename

We lose that when we remove `-enable-split-dwarf`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63167



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


[PATCH] D63167: [Clang] Remove obsolete -enable-split-dwarf={single,split}

2019-06-15 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert updated this revision to Diff 204928.
aaronpuchert added a comment.

Remove `-enable-split-dwarf` completely, adapting the test case accordingly. 
Also remove `-split-dwarf` which wasn't used at all.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63167

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/CC1Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/split-debug-filename.c
  clang/test/CodeGen/split-debug-output.c
  clang/test/CodeGen/split-debug-single-file.c
  clang/test/Driver/split-debug.c

Index: clang/test/Driver/split-debug.c
===
--- clang/test/Driver/split-debug.c
+++ clang/test/Driver/split-debug.c
@@ -13,7 +13,6 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=single -c -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-ACTIONS-SINGLE-SPLIT < %t %s
 //
-// CHECK-ACTIONS-SINGLE-SPLIT: "-enable-split-dwarf=single"
 // CHECK-ACTIONS-SINGLE-SPLIT: "-split-dwarf-file" "split-debug.o"
 // CHECK-ACTIONS-SINGLE-SPLIT-NOT: "-split-dwarf-output"
 
@@ -58,7 +57,6 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -gmlt -fno-split-dwarf-inlining -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-GMLT-WITH-SPLIT < %t %s
 //
-// CHECK-GMLT-WITH-SPLIT: "-enable-split-dwarf"
 // CHECK-GMLT-WITH-SPLIT: "-debug-info-kind=line-tables-only"
 // CHECK-GMLT-WITH-SPLIT: "-split-dwarf-file"
 // CHECK-GMLT-WITH-SPLIT: "-split-dwarf-output"
@@ -66,28 +64,24 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -g -fno-split-dwarf-inlining -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-NOINLINE-WITHOUT-SPLIT < %t %s
 //
-// CHECK-NOINLINE-WITHOUT-SPLIT-NOT: "-enable-split-dwarf"
 // CHECK-NOINLINE-WITHOUT-SPLIT: "-fno-split-dwarf-inlining"
 // CHECK-NOINLINE-WITHOUT-SPLIT: "-debug-info-kind=limited"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gmlt -gsplit-dwarf -fno-split-dwarf-inlining -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-SPLIT-WITH-GMLT < %t %s
 //
-// CHECK-SPLIT-WITH-GMLT: "-enable-split-dwarf"
 // CHECK-SPLIT-WITH-GMLT: "-debug-info-kind=limited"
 // CHECK-SPLIT-WITH-GMLT: "-split-dwarf-output"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -fno-split-dwarf-inlining -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-SPLIT-WITH-NOINL < %t %s
 //
-// CHECK-SPLIT-WITH-NOINL: "-enable-split-dwarf"
 // CHECK-SPLIT-WITH-NOINL: "-debug-info-kind=limited"
 // CHECK-SPLIT-WITH-NOINL: "-split-dwarf-output"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -gmlt -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-GMLT-OVER-SPLIT < %t %s
 //
-// CHECK-GMLT-OVER-SPLIT-NOT: "-enable-split-dwarf"
 // CHECK-GMLT-OVER-SPLIT: "-debug-info-kind=line-tables-only"
 // CHECK-GMLT-OVER-SPLIT-NOT: "-split-dwarf-file"
 // CHECK-GMLT-OVER-SPLIT-NOT: "-split-dwarf-output"
@@ -95,14 +89,13 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -gmlt -gsplit-dwarf -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-SPLIT-OVER-GMLT < %t %s
 //
-// CHECK-SPLIT-OVER-GMLT: "-enable-split-dwarf" "-debug-info-kind=limited"
+// CHECK-SPLIT-OVER-GMLT: "-debug-info-kind=limited"
 // CHECK-SPLIT-OVER-GMLT: "-split-dwarf-file"
 // CHECK-SPLIT-OVER-GMLT: "-split-dwarf-output"
 
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf -g0 -fno-split-dwarf-inlining -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-G0-OVER-SPLIT < %t %s
 //
-// CHECK-G0-OVER-SPLIT-NOT: "-enable-split-dwarf"
 // CHECK-G0-OVER-SPLIT-NOT: "-debug-info-kind
 // CHECK-G0-OVER-SPLIT-NOT: "-split-dwarf-file"
 // CHECK-G0-OVER-SPLIT-NOT: "-split-dwarf-output"
@@ -112,7 +105,6 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -gsplit-dwarf=split -g0 -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-G0-OVER-SPLIT < %t %s
 //
-// CHECK-G0-OVER-SPLIT-NOT: "-enable-split-dwarf"
 // CHECK-G0-OVER-SPLIT-NOT: "-debug-info-kind
 // CHECK-G0-OVER-SPLIT-NOT: "-split-dwarf-file"
 // CHECK-G0-OVER-SPLIT-NOT: "-split-dwarf-output"
@@ -122,6 +114,6 @@
 // RUN: %clang -target x86_64-unknown-linux-gnu -g0 -gsplit-dwarf=split -S -### %s 2> %t
 // RUN: FileCheck -check-prefix=CHECK-SPLIT-OVER-G0 < %t %s
 //
-// CHECK-SPLIT-OVER-G0: "-enable-split-dwarf" "-debug-info-kind=limited"
+// CHECK-SPLIT-OVER-G0: "-debug-info-kind=limited"
 // CHECK-SPLIT-OVER-G0: "-split-dwarf-file"
 // CHECK-SPLIT-OVER-G0: "-split-dwarf-output"
Index: clang/test/CodeGen/split-debug-single-file.c
===
--- clang/test/CodeGen/split-debug-single-file.c
+++ clang/test/CodeGen/split-debug-single-file.c
@@ -1,20 +1,21 @@
 // REQUIRES: x86-registered-target
 
-// 

[PATCH] D59673: [Clang] Harmonize Split DWARF options with llc

2019-06-15 Thread Aaron Puchert via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
aaronpuchert marked 3 inline comments as done.
Closed by commit rL363496: [Clang] Harmonize Split DWARF options with llc 
(authored by aaronpuchert, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D59673?vs=204661=204927#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D59673

Files:
  cfe/trunk/include/clang/Basic/CodeGenOptions.h
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/split-debug-filename.c
  cfe/trunk/test/CodeGen/split-debug-output.c
  cfe/trunk/test/CodeGen/split-debug-single-file.c
  cfe/trunk/test/CodeGen/thinlto-split-dwarf.c
  cfe/trunk/test/Driver/split-debug.c
  llvm/trunk/include/llvm/LTO/Config.h
  llvm/trunk/lib/LTO/LTOBackend.cpp

Index: llvm/trunk/lib/LTO/LTOBackend.cpp
===
--- llvm/trunk/lib/LTO/LTOBackend.cpp
+++ llvm/trunk/lib/LTO/LTOBackend.cpp
@@ -314,7 +314,7 @@
 return;
 
   std::unique_ptr DwoOut;
-  SmallString<1024> DwoFile(Conf.DwoPath);
+  SmallString<1024> DwoFile(Conf.SplitDwarfOutput);
   if (!Conf.DwoDir.empty()) {
 std::error_code EC;
 if (auto EC = llvm::sys::fs::create_directories(Conf.DwoDir))
@@ -323,11 +323,12 @@
 
 DwoFile = Conf.DwoDir;
 sys::path::append(DwoFile, std::to_string(Task) + ".dwo");
-  }
+TM->Options.MCOptions.SplitDwarfFile = DwoFile.str().str();
+  } else
+TM->Options.MCOptions.SplitDwarfFile = Conf.SplitDwarfFile;
 
   if (!DwoFile.empty()) {
 std::error_code EC;
-TM->Options.MCOptions.SplitDwarfFile = DwoFile.str().str();
 DwoOut = llvm::make_unique(DwoFile, EC, sys::fs::F_None);
 if (EC)
   report_fatal_error("Failed to open " + DwoFile + ": " + EC.message());
Index: llvm/trunk/include/llvm/LTO/Config.h
===
--- llvm/trunk/include/llvm/LTO/Config.h
+++ llvm/trunk/include/llvm/LTO/Config.h
@@ -88,10 +88,16 @@
   /// The directory to store .dwo files.
   std::string DwoDir;
 
+  /// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name
+  /// attribute in the skeleton CU. This should generally only be used when
+  /// running an individual backend directly via thinBackend(), as otherwise
+  /// all objects would use the same .dwo file. Not used as output path.
+  std::string SplitDwarfFile;
+
   /// The path to write a .dwo file to. This should generally only be used when
   /// running an individual backend directly via thinBackend(), as otherwise
-  /// all .dwo files will be written to the same path.
-  std::string DwoPath;
+  /// all .dwo files will be written to the same path. Not used in skeleton CU.
+  std::string SplitDwarfOutput;
 
   /// Optimization remarks file path.
   std::string RemarksFilename = "";
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -472,7 +472,7 @@
   Options.EmitAddrsig = CodeGenOpts.Addrsig;
 
   if (CodeGenOpts.getSplitDwarfMode() != CodeGenOptions::NoFission)
-Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfOutput;
+Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
   Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
   Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
   Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm;
@@ -1428,7 +1428,8 @@
   Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
   Conf.RemarksFilename = CGOpts.OptRecordFile;
   Conf.RemarksPasses = CGOpts.OptRecordPasses;
-  Conf.DwoPath = CGOpts.SplitDwarfOutput;
+  Conf.SplitDwarfFile = CGOpts.SplitDwarfFile;
+  Conf.SplitDwarfOutput = CGOpts.SplitDwarfOutput;
   switch (Action) {
   case Backend_EmitNothing:
 Conf.PreCodeGenModuleHook = [](size_t Task, const Module ) {
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -616,7 +616,7 @@
   CGOpts.DwarfDebugFlags, RuntimeVers,
   (CGOpts.getSplitDwarfMode() != CodeGenOptions::NoFission)
   ? ""
-  : CGOpts.SplitDwarfOutput,
+  : CGOpts.SplitDwarfFile,
   EmissionKind, DwoId, CGOpts.SplitDwarfInlining,
   CGOpts.DebugInfoForProfiling,
   CGM.getTarget().getTriple().isNVPTX()
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -4108,11 +4108,14 @@
 

r363496 - [Clang] Harmonize Split DWARF options with llc

2019-06-15 Thread Aaron Puchert via cfe-commits
Author: aaronpuchert
Date: Sat Jun 15 08:38:51 2019
New Revision: 363496

URL: http://llvm.org/viewvc/llvm-project?rev=363496=rev
Log:
[Clang] Harmonize Split DWARF options with llc

Summary:
With Split DWARF the resulting object file (then called skeleton CU)
contains the file name of another ("DWO") file with the debug info.
This can be a problem for remote compilation, as it will contain the
name of the file on the compilation server, not on the client.

To use Split DWARF with remote compilation, one needs to either

* make sure only relative paths are used, and mirror the build directory
  structure of the client on the server,
* inject the desired file name on the client directly.

Since llc already supports the latter solution, we're just copying that
over. We allow setting the actual output filename separately from the
value of the DW_AT_[GNU_]dwo_name attribute in the skeleton CU.

Fixes PR40276.

Reviewers: dblaikie, echristo, tejohnson

Reviewed By: dblaikie

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

Added:
cfe/trunk/test/CodeGen/split-debug-output.c
Modified:
cfe/trunk/include/clang/Basic/CodeGenOptions.h
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/CodeGen/split-debug-filename.c
cfe/trunk/test/CodeGen/split-debug-single-file.c
cfe/trunk/test/CodeGen/thinlto-split-dwarf.c
cfe/trunk/test/Driver/split-debug.c

Modified: cfe/trunk/include/clang/Basic/CodeGenOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CodeGenOptions.h?rev=363496=363495=363496=diff
==
--- cfe/trunk/include/clang/Basic/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Basic/CodeGenOptions.h Sat Jun 15 08:38:51 2019
@@ -185,8 +185,11 @@ public:
   /// file, for example with -save-temps.
   std::string MainFileName;
 
-  /// The name for the split debug info file that we'll break out. This is used
-  /// in the backend for setting the name in the skeleton cu.
+  /// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name
+  /// attribute in the skeleton CU.
+  std::string SplitDwarfFile;
+
+  /// Output filename for the split debug info, not used in the skeleton CU.
   std::string SplitDwarfOutput;
 
   /// The name of the relocation model to use.

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=363496=363495=363496=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Sat Jun 15 08:38:51 2019
@@ -696,6 +696,8 @@ def enable_split_dwarf : Flag<["-"], "en
   HelpText<"Use DWARF fission in 'split' mode">;
 def enable_split_dwarf_EQ : Joined<["-"], "enable-split-dwarf=">,
   HelpText<"Set DWARF fission mode to either 'split' or 'single'">, 
Values<"split,single">;
+def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
+  HelpText<"Name of the split dwarf debug info file to encode in the object 
file">;
 def fno_wchar : Flag<["-"], "fno-wchar">,
   HelpText<"Disable C++ builtin type wchar_t">;
 def fconstant_string_class : Separate<["-"], "fconstant-string-class">,

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=363496=363495=363496=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Sat Jun 15 08:38:51 2019
@@ -472,7 +472,7 @@ static void initTargetOptions(llvm::Targ
   Options.EmitAddrsig = CodeGenOpts.Addrsig;
 
   if (CodeGenOpts.getSplitDwarfMode() != CodeGenOptions::NoFission)
-Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfOutput;
+Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
   Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
   Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
   Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm;
@@ -1428,7 +1428,8 @@ static void runThinLTOBackend(ModuleSumm
   Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
   Conf.RemarksFilename = CGOpts.OptRecordFile;
   Conf.RemarksPasses = CGOpts.OptRecordPasses;
-  Conf.DwoPath = CGOpts.SplitDwarfOutput;
+  Conf.SplitDwarfFile = CGOpts.SplitDwarfFile;
+  Conf.SplitDwarfOutput = CGOpts.SplitDwarfOutput;
   switch (Action) {
   case Backend_EmitNothing:
 Conf.PreCodeGenModuleHook = [](size_t Task, const Module ) {

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 

[PATCH] D63324: [clang-tidy] Replace memcpy by std::copy

2019-06-15 Thread Thomas Manceau via Phabricator via cfe-commits
Blackhart updated this revision to Diff 204926.
Blackhart marked an inline comment as done.
Blackhart added a comment.

- Remove unnessecary empty line
- Use "array.size()" instead of numerical constant


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

https://reviews.llvm.org/D63324

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h

Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
@@ -0,0 +1,48 @@
+//===--- ReplaceMemcpyByStdCopy.h - clang-tidy*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+/// Replace the C memcpy function by std::copy
+class ReplaceMemcpyByStdCopy : public ClangTidyCheck {
+public:
+  ReplaceMemcpyByStdCopy(StringRef Name, ClangTidyContext *Context);
+  ~ReplaceMemcpyByStdCopy() override = default;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void registerPPCallbacks(const SourceManager , Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
+
+private:
+  void renameFunction(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void reorderArgs(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void insertHeader(DiagnosticBuilder , const CallExpr *MemcpyNode,
+SourceManager *const SM);
+
+private:
+  std::unique_ptr Inserter;
+  const utils::IncludeSorter::IncludeStyle IncludeStyle;
+};
+
+} // namespace modernize
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
@@ -0,0 +1,117 @@
+//===--- ReplaceMemcpyByStdCopy.cpp - clang-tidy--*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ReplaceMemcpyByStdCopy.h"
+#include "../utils/OptionsUtils.h"
+#include 
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+ReplaceMemcpyByStdCopy::ReplaceMemcpyByStdCopy(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
+  Options.getLocalOrGlobal("IncludeStyle", "llvm"))) {}
+
+void ReplaceMemcpyByStdCopy::registerMatchers(MatchFinder *Finder) {
+  assert(Finder != nullptr);
+
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  auto MemcpyMatcher =
+  callExpr(hasDeclaration(functionDecl(hasName("memcpy"),
+   isExpansionInSystemHeader())),
+   isExpansionInMainFile())
+  .bind("memcpy_function");
+
+  Finder->addMatcher(MemcpyMatcher, this);
+}
+
+void ReplaceMemcpyByStdCopy::registerPPCallbacks(
+const SourceManager , Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  Inserter = llvm::make_unique(SM, getLangOpts(),
+   IncludeStyle);
+  PP->addPPCallbacks(Inserter->CreatePPCallbacks());
+}
+
+void ReplaceMemcpyByStdCopy::check(const MatchFinder::MatchResult ) {
+  const auto *MemcpyNode = Result.Nodes.getNodeAs("memcpy_function");
+  assert(MemcpyNode != nullptr);
+
+  DiagnosticBuilder Diag =
+  diag(MemcpyNode->getExprLoc(), "use std::copy instead of memcpy");
+
+  renameFunction(Diag, MemcpyNode);
+  reorderArgs(Diag, MemcpyNode);
+  insertHeader(Diag, MemcpyNode, Result.SourceManager);
+}
+
+void 

[PATCH] D63324: [clang-tidy] Replace memcpy by std::copy

2019-06-15 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp:11
+#include "../utils/OptionsUtils.h"
+
+#include 

Please remove unnecessary empty line.



Comment at: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp:86
+  // Retrieve all the arguments
+  for (uint8_t i = 0; i < 3; i++) {
+llvm::raw_string_ostream s(arg[i]);

Please use arg,size() instead of 3.


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

https://reviews.llvm.org/D63324



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


[PATCH] D63009: [OpenMP] Add target task alloc function with device ID

2019-06-15 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added a comment.

In D63009#1544758 , @Hahnfeld wrote:

> Am I correct that the second to last revision ("- Fix tests.") removed all 
> checks for the actual `device_id` argument from the tests? From my point of 
> view that's not fixing but weakening the tests! Can you explain why they 
> needed "fixing"?


When I was just passing the default value the LLVM-IR was: i64 -1 i.e. 
constant, easy to check.

With the latest change the emitted code is: i64 %123 i.e. where %123 is a local 
derived from the expression of the device ID.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63009



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


[PATCH] D63009: [OpenMP] Add target task alloc function with device ID

2019-06-15 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added a comment.

In D63009#1544784 , @ABataev wrote:

> The tests must check the device ID for target-based calls of the task alloc 
> function.


Since device ID is now an expression I can only do this:

  i64 {{.*}})

Is this what you wanted? @ABataev @Hahnfeld ?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63009



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


[PATCH] D63324: [clang-tidy] Replace memcpy by std::copy

2019-06-15 Thread Thomas Manceau via Phabricator via cfe-commits
Blackhart updated this revision to Diff 204925.
Blackhart marked an inline comment as done.
Blackhart added a comment.

Use "std::array" instead of the raw array


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

https://reviews.llvm.org/D63324

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h

Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
@@ -0,0 +1,48 @@
+//===--- ReplaceMemcpyByStdCopy.h - clang-tidy*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+/// Replace the C memcpy function by std::copy
+class ReplaceMemcpyByStdCopy : public ClangTidyCheck {
+public:
+  ReplaceMemcpyByStdCopy(StringRef Name, ClangTidyContext *Context);
+  ~ReplaceMemcpyByStdCopy() override = default;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void registerPPCallbacks(const SourceManager , Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
+
+private:
+  void renameFunction(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void reorderArgs(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void insertHeader(DiagnosticBuilder , const CallExpr *MemcpyNode,
+SourceManager *const SM);
+
+private:
+  std::unique_ptr Inserter;
+  const utils::IncludeSorter::IncludeStyle IncludeStyle;
+};
+
+} // namespace modernize
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
@@ -0,0 +1,118 @@
+//===--- ReplaceMemcpyByStdCopy.cpp - clang-tidy--*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ReplaceMemcpyByStdCopy.h"
+#include "../utils/OptionsUtils.h"
+
+#include 
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+ReplaceMemcpyByStdCopy::ReplaceMemcpyByStdCopy(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
+  Options.getLocalOrGlobal("IncludeStyle", "llvm"))) {}
+
+void ReplaceMemcpyByStdCopy::registerMatchers(MatchFinder *Finder) {
+  assert(Finder != nullptr);
+
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  auto MemcpyMatcher =
+  callExpr(hasDeclaration(functionDecl(hasName("memcpy"),
+   isExpansionInSystemHeader())),
+   isExpansionInMainFile())
+  .bind("memcpy_function");
+
+  Finder->addMatcher(MemcpyMatcher, this);
+}
+
+void ReplaceMemcpyByStdCopy::registerPPCallbacks(
+const SourceManager , Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  Inserter = llvm::make_unique(SM, getLangOpts(),
+   IncludeStyle);
+  PP->addPPCallbacks(Inserter->CreatePPCallbacks());
+}
+
+void ReplaceMemcpyByStdCopy::check(const MatchFinder::MatchResult ) {
+  const auto *MemcpyNode = Result.Nodes.getNodeAs("memcpy_function");
+  assert(MemcpyNode != nullptr);
+
+  DiagnosticBuilder Diag =
+  diag(MemcpyNode->getExprLoc(), "use std::copy instead of memcpy");
+
+  renameFunction(Diag, MemcpyNode);
+  reorderArgs(Diag, MemcpyNode);
+  insertHeader(Diag, MemcpyNode, Result.SourceManager);
+}
+
+void 

[PATCH] D63324: [clang-tidy] Replace memcpy by std::copy

2019-06-15 Thread Thomas Manceau via Phabricator via cfe-commits
Blackhart updated this revision to Diff 204924.
Blackhart marked an inline comment as done.
Blackhart added a comment.

Remove "auto" keyword when type is created from same statement


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

https://reviews.llvm.org/D63324

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h

Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
@@ -0,0 +1,48 @@
+//===--- ReplaceMemcpyByStdCopy.h - clang-tidy*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+/// Replace the C memcpy function by std::copy
+class ReplaceMemcpyByStdCopy : public ClangTidyCheck {
+public:
+  ReplaceMemcpyByStdCopy(StringRef Name, ClangTidyContext *Context);
+  ~ReplaceMemcpyByStdCopy() override = default;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void registerPPCallbacks(const SourceManager , Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
+
+private:
+  void renameFunction(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void reorderArgs(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void insertHeader(DiagnosticBuilder , const CallExpr *MemcpyNode,
+SourceManager *const SM);
+
+private:
+  std::unique_ptr Inserter;
+  const utils::IncludeSorter::IncludeStyle IncludeStyle;
+};
+
+} // namespace modernize
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
@@ -0,0 +1,116 @@
+//===--- ReplaceMemcpyByStdCopy.cpp - clang-tidy--*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ReplaceMemcpyByStdCopy.h"
+#include "../utils/OptionsUtils.h"
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+ReplaceMemcpyByStdCopy::ReplaceMemcpyByStdCopy(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
+  Options.getLocalOrGlobal("IncludeStyle", "llvm"))) {}
+
+void ReplaceMemcpyByStdCopy::registerMatchers(MatchFinder *Finder) {
+  assert(Finder != nullptr);
+
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  auto MemcpyMatcher =
+  callExpr(hasDeclaration(functionDecl(hasName("memcpy"),
+   isExpansionInSystemHeader())),
+   isExpansionInMainFile())
+  .bind("memcpy_function");
+
+  Finder->addMatcher(MemcpyMatcher, this);
+}
+
+void ReplaceMemcpyByStdCopy::registerPPCallbacks(
+const SourceManager , Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  Inserter = llvm::make_unique(SM, getLangOpts(),
+   IncludeStyle);
+  PP->addPPCallbacks(Inserter->CreatePPCallbacks());
+}
+
+void ReplaceMemcpyByStdCopy::check(const MatchFinder::MatchResult ) {
+  const auto *MemcpyNode = Result.Nodes.getNodeAs("memcpy_function");
+  assert(MemcpyNode != nullptr);
+
+  DiagnosticBuilder Diag =
+  diag(MemcpyNode->getExprLoc(), "use std::copy instead of memcpy");
+
+  renameFunction(Diag, MemcpyNode);
+  reorderArgs(Diag, MemcpyNode);
+  insertHeader(Diag, MemcpyNode, Result.SourceManager);
+}
+
+void 

[PATCH] D63324: [clang-tidy] Replace memcpy by std::copy

2019-06-15 Thread Thomas Manceau via Phabricator via cfe-commits
Blackhart updated this revision to Diff 204922.
Blackhart added a comment.

Add override keyword to the destructor and set it as "= default"


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

https://reviews.llvm.org/D63324

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h

Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
@@ -0,0 +1,48 @@
+//===--- ReplaceMemcpyByStdCopy.h - clang-tidy*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+/// Replace the C memcpy function by std::copy
+class ReplaceMemcpyByStdCopy : public ClangTidyCheck {
+public:
+  ReplaceMemcpyByStdCopy(StringRef Name, ClangTidyContext *Context);
+  ~ReplaceMemcpyByStdCopy() override = default;
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void registerPPCallbacks(const SourceManager , Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
+
+private:
+  void renameFunction(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void reorderArgs(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void insertHeader(DiagnosticBuilder , const CallExpr *MemcpyNode,
+SourceManager *const SM);
+
+private:
+  std::unique_ptr Inserter;
+  const utils::IncludeSorter::IncludeStyle IncludeStyle;
+};
+
+} // namespace modernize
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
@@ -0,0 +1,115 @@
+//===--- ReplaceMemcpyByStdCopy.cpp - clang-tidy--*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ReplaceMemcpyByStdCopy.h"
+#include "../utils/OptionsUtils.h"
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+ReplaceMemcpyByStdCopy::ReplaceMemcpyByStdCopy(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
+  Options.getLocalOrGlobal("IncludeStyle", "llvm"))) {}
+
+void ReplaceMemcpyByStdCopy::registerMatchers(MatchFinder *Finder) {
+  assert(Finder != nullptr);
+
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  auto MemcpyMatcher =
+  callExpr(hasDeclaration(functionDecl(hasName("memcpy"),
+   isExpansionInSystemHeader())),
+   isExpansionInMainFile())
+  .bind("memcpy_function");
+
+  Finder->addMatcher(MemcpyMatcher, this);
+}
+
+void ReplaceMemcpyByStdCopy::registerPPCallbacks(
+const SourceManager , Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  Inserter = llvm::make_unique(SM, getLangOpts(),
+   IncludeStyle);
+  PP->addPPCallbacks(Inserter->CreatePPCallbacks());
+}
+
+void ReplaceMemcpyByStdCopy::check(const MatchFinder::MatchResult ) {
+  const auto *MemcpyNode = Result.Nodes.getNodeAs("memcpy_function");
+  assert(MemcpyNode != nullptr);
+
+  auto Diag = diag(MemcpyNode->getExprLoc(), "use std::copy instead of memcpy");
+
+  renameFunction(Diag, MemcpyNode);
+  reorderArgs(Diag, MemcpyNode);
+  insertHeader(Diag, MemcpyNode, Result.SourceManager);
+}
+
+void ReplaceMemcpyByStdCopy::storeOptions(ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "IncludeStyle",
+ 

[PATCH] D63324: [clang-tidy] Replace memcpy by std::copy

2019-06-15 Thread Thomas Manceau via Phabricator via cfe-commits
Blackhart updated this revision to Diff 204920.
Blackhart added a comment.

Revert "Modernize memcpy only if C++20 is enabled"


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

https://reviews.llvm.org/D63324

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h

Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.h
@@ -0,0 +1,48 @@
+//===--- ReplaceMemcpyByStdCopy.h - clang-tidy*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/IncludeInserter.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+/// Replace the C memcpy function by std::copy
+class ReplaceMemcpyByStdCopy : public ClangTidyCheck {
+public:
+  ReplaceMemcpyByStdCopy(StringRef Name, ClangTidyContext *Context);
+  virtual ~ReplaceMemcpyByStdCopy() {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void registerPPCallbacks(const SourceManager , Preprocessor *PP,
+   Preprocessor *ModuleExpanderPP) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
+
+private:
+  void renameFunction(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void reorderArgs(DiagnosticBuilder , const CallExpr *MemcpyNode);
+  void insertHeader(DiagnosticBuilder , const CallExpr *MemcpyNode,
+SourceManager *const SM);
+
+private:
+  std::unique_ptr Inserter;
+  const utils::IncludeSorter::IncludeStyle IncludeStyle;
+};
+
+} // namespace modernize
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_REPLACE_MEMCPY_BY_STDCOPY_H
Index: clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/modernize/ReplaceMemcpyByStdCopy.cpp
@@ -0,0 +1,115 @@
+//===--- ReplaceMemcpyByStdCopy.cpp - clang-tidy--*- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ReplaceMemcpyByStdCopy.h"
+#include "../utils/OptionsUtils.h"
+
+using namespace clang;
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+ReplaceMemcpyByStdCopy::ReplaceMemcpyByStdCopy(StringRef Name,
+   ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IncludeStyle(utils::IncludeSorter::parseIncludeStyle(
+  Options.getLocalOrGlobal("IncludeStyle", "llvm"))) {}
+
+void ReplaceMemcpyByStdCopy::registerMatchers(MatchFinder *Finder) {
+  assert(Finder != nullptr);
+
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  auto MemcpyMatcher =
+  callExpr(hasDeclaration(functionDecl(hasName("memcpy"),
+   isExpansionInSystemHeader())),
+   isExpansionInMainFile())
+  .bind("memcpy_function");
+
+  Finder->addMatcher(MemcpyMatcher, this);
+}
+
+void ReplaceMemcpyByStdCopy::registerPPCallbacks(
+const SourceManager , Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  Inserter = llvm::make_unique(SM, getLangOpts(),
+   IncludeStyle);
+  PP->addPPCallbacks(Inserter->CreatePPCallbacks());
+}
+
+void ReplaceMemcpyByStdCopy::check(const MatchFinder::MatchResult ) {
+  const auto *MemcpyNode = Result.Nodes.getNodeAs("memcpy_function");
+  assert(MemcpyNode != nullptr);
+
+  auto Diag = diag(MemcpyNode->getExprLoc(), "use std::copy instead of memcpy");
+
+  renameFunction(Diag, MemcpyNode);
+  reorderArgs(Diag, MemcpyNode);
+  insertHeader(Diag, MemcpyNode, Result.SourceManager);
+}
+
+void ReplaceMemcpyByStdCopy::storeOptions(ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "IncludeStyle",
+

[PATCH] D63324: [clang-tidy] Replace memcpy by std::copy

2019-06-15 Thread Thomas Manceau via Phabricator via cfe-commits
Blackhart added a comment.

In D63324#1543782 , @xbolva00 wrote:

> This might not be currently ideal recommendation since std::copy produces 
> memmove with -O3.


What do you recommend ?
There is a way to disable this modernization if the user compile with the -O3 
flag ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63324



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


[PATCH] D63324: [clang-tidy] Replace memcpy by std::copy

2019-06-15 Thread Thomas Manceau via Phabricator via cfe-commits
Blackhart added a comment.

In D63324#1543706 , @lebedev.ri wrote:

> In D63324#1543626 , @Blackhart wrote:
>
> > In D63324#1543609 , @lebedev.ri 
> > wrote:
> >
> > > In D63324#1543607 , @Blackhart 
> > > wrote:
> > >
> > > > Modernize memcpy only if C++20 is enabled
> > >
> > >
> > > ... why?
> > >  This is also missing documentation,releasenotes changes.
> >
> >
> > According with the C++ reference, std::copy is only available since C++20.
>
>
> I don't see it there, can you quote?
>  https://godbolt.org/z/q2ryJi
>
> > There is another std::copy signature available since C++17, but it needs an 
> > extra parameter. I can implement it also.
> >  https://en.cppreference.com/w/cpp/algorithm/copy
> > 
> > I'm working on the unit tests and I'll make documentation/releasenotes 
> > after that.
> > 
> > Thanks for reviewing @lebedev.ri ;)


Sorry, I misread the reference. It's "until" C++20.
So from C++ birth to today ...

I'll revert my changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63324



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


[PATCH] D63130: [Clang] Rename -split-dwarf-file to -split-dwarf-output

2019-06-15 Thread Aaron Puchert via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363494: [Clang] Rename -split-dwarf-file to 
-split-dwarf-output (authored by aaronpuchert, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63130?vs=204010=204917#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63130

Files:
  cfe/trunk/include/clang/Basic/CodeGenOptions.h
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/split-debug-filename.c
  cfe/trunk/test/CodeGen/split-debug-single-file.c
  cfe/trunk/test/CodeGen/thinlto-split-dwarf.c
  cfe/trunk/test/Driver/fuchsia.c
  cfe/trunk/test/Driver/split-debug.c
  cfe/trunk/test/Driver/split-debug.s
  cfe/trunk/test/Misc/cc1as-split-dwarf.s
  cfe/trunk/test/Modules/pch_container.m
  cfe/trunk/tools/driver/cc1as_main.cpp

Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -472,7 +472,7 @@
   Options.EmitAddrsig = CodeGenOpts.Addrsig;
 
   if (CodeGenOpts.getSplitDwarfMode() != CodeGenOptions::NoFission)
-Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
+Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfOutput;
   Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
   Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
   Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm;
@@ -862,9 +862,9 @@
 break;
 
   default:
-if (!CodeGenOpts.SplitDwarfFile.empty() &&
+if (!CodeGenOpts.SplitDwarfOutput.empty() &&
 (CodeGenOpts.getSplitDwarfMode() == CodeGenOptions::SplitFileFission)) {
-  DwoOS = openOutputFile(CodeGenOpts.SplitDwarfFile);
+  DwoOS = openOutputFile(CodeGenOpts.SplitDwarfOutput);
   if (!DwoOS)
 return;
 }
@@ -1275,9 +1275,9 @@
 NeedCodeGen = true;
 CodeGenPasses.add(
 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
-if (!CodeGenOpts.SplitDwarfFile.empty() &&
+if (!CodeGenOpts.SplitDwarfOutput.empty() &&
 CodeGenOpts.getSplitDwarfMode() == CodeGenOptions::SplitFileFission) {
-  DwoOS = openOutputFile(CodeGenOpts.SplitDwarfFile);
+  DwoOS = openOutputFile(CodeGenOpts.SplitDwarfOutput);
   if (!DwoOS)
 return;
 }
@@ -1428,7 +1428,7 @@
   Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
   Conf.RemarksFilename = CGOpts.OptRecordFile;
   Conf.RemarksPasses = CGOpts.OptRecordPasses;
-  Conf.DwoPath = CGOpts.SplitDwarfFile;
+  Conf.DwoPath = CGOpts.SplitDwarfOutput;
   switch (Action) {
   case Backend_EmitNothing:
 Conf.PreCodeGenModuleHook = [](size_t Task, const Module ) {
Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
===
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
@@ -616,7 +616,7 @@
   CGOpts.DwarfDebugFlags, RuntimeVers,
   (CGOpts.getSplitDwarfMode() != CodeGenOptions::NoFission)
   ? ""
-  : CGOpts.SplitDwarfFile,
+  : CGOpts.SplitDwarfOutput,
   EmissionKind, DwoId, CGOpts.SplitDwarfInlining,
   CGOpts.DebugInfoForProfiling,
   CGM.getTarget().getTriple().isNVPTX()
Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp
@@ -4110,7 +4110,7 @@
  isa(JA));
   const char *SplitDWARFOut;
   if (SplitDWARF) {
-CmdArgs.push_back("-split-dwarf-file");
+CmdArgs.push_back("-split-dwarf-output");
 SplitDWARFOut = SplitDebugName(Args, Input, Output);
 CmdArgs.push_back(SplitDWARFOut);
   }
@@ -6180,7 +6180,7 @@
   Arg *A;
   if (getDebugFissionKind(D, Args, A) == DwarfFissionKind::Split &&
   T.isOSBinFormatELF()) {
-CmdArgs.push_back("-split-dwarf-file");
+CmdArgs.push_back("-split-dwarf-output");
 CmdArgs.push_back(SplitDebugName(Args, Input, Output));
   }
 
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -726,7 +726,7 @@
   Opts.MacroDebugInfo = Args.hasArg(OPT_debug_info_macro);
   Opts.WholeProgramVTables = Args.hasArg(OPT_fwhole_program_vtables);
   Opts.LTOVisibilityPublicStd = Args.hasArg(OPT_flto_visibility_public_std);
-  Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
+  Opts.SplitDwarfOutput = 

r363494 - [Clang] Rename -split-dwarf-file to -split-dwarf-output

2019-06-15 Thread Aaron Puchert via cfe-commits
Author: aaronpuchert
Date: Sat Jun 15 07:07:43 2019
New Revision: 363494

URL: http://llvm.org/viewvc/llvm-project?rev=363494=rev
Log:
[Clang] Rename -split-dwarf-file to -split-dwarf-output

Summary:
This is the first in a series of changes trying to align clang -cc1
flags for Split DWARF with those of llc. The unfortunate side effect of
having -split-dwarf-output for single file Split DWARF will disappear
again in a subsequent change.

The change is the result of a discussion in D59673.

Reviewers: dblaikie, echristo

Reviewed By: dblaikie

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

Modified:
cfe/trunk/include/clang/Basic/CodeGenOptions.h
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/CodeGen/split-debug-filename.c
cfe/trunk/test/CodeGen/split-debug-single-file.c
cfe/trunk/test/CodeGen/thinlto-split-dwarf.c
cfe/trunk/test/Driver/fuchsia.c
cfe/trunk/test/Driver/split-debug.c
cfe/trunk/test/Driver/split-debug.s
cfe/trunk/test/Misc/cc1as-split-dwarf.s
cfe/trunk/test/Modules/pch_container.m
cfe/trunk/tools/driver/cc1as_main.cpp

Modified: cfe/trunk/include/clang/Basic/CodeGenOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CodeGenOptions.h?rev=363494=363493=363494=diff
==
--- cfe/trunk/include/clang/Basic/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Basic/CodeGenOptions.h Sat Jun 15 07:07:43 2019
@@ -187,7 +187,7 @@ public:
 
   /// The name for the split debug info file that we'll break out. This is used
   /// in the backend for setting the name in the skeleton cu.
-  std::string SplitDwarfFile;
+  std::string SplitDwarfOutput;
 
   /// The name of the relocation model to use.
   llvm::Reloc::Model RelocationModel;

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=363494=363493=363494=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Sat Jun 15 07:07:43 2019
@@ -683,7 +683,7 @@ def version : Flag<["-"], "version">,
   HelpText<"Print the compiler version">;
 def main_file_name : Separate<["-"], "main-file-name">,
   HelpText<"Main file name to use for debug info">;
-def split_dwarf_file : Separate<["-"], "split-dwarf-file">,
+def split_dwarf_output : Separate<["-"], "split-dwarf-output">,
   HelpText<"File name to use for split dwarf debug info output">;
 
 }

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=363494=363493=363494=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Sat Jun 15 07:07:43 2019
@@ -472,7 +472,7 @@ static void initTargetOptions(llvm::Targ
   Options.EmitAddrsig = CodeGenOpts.Addrsig;
 
   if (CodeGenOpts.getSplitDwarfMode() != CodeGenOptions::NoFission)
-Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
+Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfOutput;
   Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
   Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
   Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm;
@@ -862,9 +862,9 @@ void EmitAssemblyHelper::EmitAssembly(Ba
 break;
 
   default:
-if (!CodeGenOpts.SplitDwarfFile.empty() &&
+if (!CodeGenOpts.SplitDwarfOutput.empty() &&
 (CodeGenOpts.getSplitDwarfMode() == CodeGenOptions::SplitFileFission)) 
{
-  DwoOS = openOutputFile(CodeGenOpts.SplitDwarfFile);
+  DwoOS = openOutputFile(CodeGenOpts.SplitDwarfOutput);
   if (!DwoOS)
 return;
 }
@@ -1275,9 +1275,9 @@ void EmitAssemblyHelper::EmitAssemblyWit
 NeedCodeGen = true;
 CodeGenPasses.add(
 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
-if (!CodeGenOpts.SplitDwarfFile.empty() &&
+if (!CodeGenOpts.SplitDwarfOutput.empty() &&
 CodeGenOpts.getSplitDwarfMode() == CodeGenOptions::SplitFileFission) {
-  DwoOS = openOutputFile(CodeGenOpts.SplitDwarfFile);
+  DwoOS = openOutputFile(CodeGenOpts.SplitDwarfOutput);
   if (!DwoOS)
 return;
 }
@@ -1428,7 +1428,7 @@ static void runThinLTOBackend(ModuleSumm
   Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
   Conf.RemarksFilename = CGOpts.OptRecordFile;
   Conf.RemarksPasses = CGOpts.OptRecordPasses;
-  Conf.DwoPath = CGOpts.SplitDwarfFile;
+  Conf.DwoPath = CGOpts.SplitDwarfOutput;
   switch (Action) {
   case Backend_EmitNothing:
 

[PATCH] D63376: [clang] Small improvments after Adding APValue to ConstantExpr

2019-06-15 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 204916.

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

https://reviews.llvm.org/D63376

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp

Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -5514,7 +5514,12 @@
 
 if (Notes.empty()) {
   // It's a constant expression.
-  return ConstantExpr::Create(S.Context, Result.get(), Value);
+
+  // ExplicitBool wouldn't use the value stored in ConstantExpr.
+  if (CCE != Sema::CCEK_ExplicitBool)
+return ConstantExpr::Create(S.Context, Result.get(), Value);
+  else
+return ConstantExpr::Create(S.Context, Result.get());
 }
   }
 
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -14467,10 +14467,10 @@
   S.Diag(Loc, diag::ext_expr_not_ice) << SR << S.LangOpts.CPlusPlus;
 }
 
-ExprResult
-Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
-  VerifyICEDiagnoser ,
-  bool AllowFold) {
+ExprResult Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
+ VerifyICEDiagnoser ,
+ bool AllowFold,
+ bool StoreResult) {
   SourceLocation DiagLoc = E->getBeginLoc();
 
   if (getLangOpts().CPlusPlus11) {
@@ -14538,14 +14538,13 @@
 return ExprError();
   }
 
-  if (!isa(E))
-E = ConstantExpr::Create(Context, E);
-
   // Circumvent ICE checking in C++11 to avoid evaluating the expression twice
   // in the non-ICE case.
   if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) {
 if (Result)
   *Result = E->EvaluateKnownConstIntCheckOverflow(Context);
+if (!isa(E))
+  E = ConstantExpr::Create(Context, E);
 return E;
   }
 
@@ -14555,8 +14554,13 @@
 
   // Try to evaluate the expression, and produce diagnostics explaining why it's
   // not a constant expression as a side-effect.
-  bool Folded = E->EvaluateAsRValue(EvalResult, Context) &&
-EvalResult.Val.isInt() && !EvalResult.HasSideEffects;
+  bool Folded =
+  E->EvaluateAsRValue(EvalResult, Context, /*isConstantContext*/ true) &&
+  EvalResult.Val.isInt() && !EvalResult.HasSideEffects;
+
+  if (!isa(E))
+if (StoreResult)
+  E = ConstantExpr::Create(Context, E, EvalResult.Val);
 
   // In C++11, we can rely on diagnostics being produced for any expression
   // which is not a constant expression. If no diagnostics were produced, then
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -14006,8 +14006,6 @@
 ExprResult Converted = PerformContextuallyConvertToBool(AssertExpr);
 if (Converted.isInvalid())
   Failed = true;
-else
-  Converted = ConstantExpr::Create(Context, Converted.get());
 
 llvm::APSInt Cond;
 if (!Failed && VerifyIntegerConstantExpression(Converted.get(), ,
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -8963,6 +8963,8 @@
 
 bool IntExprEvaluator::VisitConstantExpr(const ConstantExpr *E) {
   llvm::SaveAndRestore InConstantContext(Info.InConstantContext, true);
+  if (E->getResultStorageKind() != ConstantExpr::RSK_None)
+return Success(E->getAPValueResult(), E);
   return ExprEvaluatorBaseTy::VisitConstantExpr(E);
 }
 
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -239,6 +239,7 @@
 ConstantExpr::getStorageKind(const APValue ) {
   switch (Value.getKind()) {
   case APValue::None:
+  case APValue::Indeterminate:
 return ConstantExpr::RSK_None;
   case APValue::Int:
 if (!Value.getInt().needsCleanup())
@@ -249,9 +250,18 @@
   }
 }
 
+ConstantExpr::ResultStorageKind
+ConstantExpr::getStorageKind(const Type *T, const ASTContext ) {
+  if (T->isIntegralOrEnumerationType() && Context.getTypeInfo(T).Width <= 64)
+return ConstantExpr::RSK_Int64;
+  return ConstantExpr::RSK_APValue;
+}
+
 void ConstantExpr::DefaultInit(ResultStorageKind StorageKind) {
   ConstantExprBits.ResultKind = StorageKind;
-  if (StorageKind == RSK_APValue)
+  ConstantExprBits.APValueKind = APValue::None;
+  

[PATCH] D63376: [clang] Small improvments after Adding APValue to ConstantExpr

2019-06-15 Thread Tyker via Phabricator via cfe-commits
Tyker created this revision.
Tyker added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

this patch has multiple small improvements related to the APValue in 
ConstantExpr.

changes:

- APValue in ConstantExpr are now cleaned up using ASTContext::addDestruction 
instead of there own system.
- ConstantExprBits Stores the ValueKind of the result beaing stored.
- VerifyIntegerConstantExpression now stores the evaluated value in 
ConstantExpr.
- the Constant Evaluator uses the stored value of ConstantExpr when available.


Repository:
  rC Clang

https://reviews.llvm.org/D63376

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp

Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -5514,7 +5514,12 @@
 
 if (Notes.empty()) {
   // It's a constant expression.
-  return ConstantExpr::Create(S.Context, Result.get(), Value);
+
+  // ExplicitBool wouldn't use the value stored in ConstantExpr.
+  if (CCE != Sema::CCEK_ExplicitBool)
+return ConstantExpr::Create(S.Context, Result.get(), Value);
+  else
+return ConstantExpr::Create(S.Context, Result.get());
 }
   }
 
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -14467,10 +14467,10 @@
   S.Diag(Loc, diag::ext_expr_not_ice) << SR << S.LangOpts.CPlusPlus;
 }
 
-ExprResult
-Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
-  VerifyICEDiagnoser ,
-  bool AllowFold) {
+ExprResult Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
+ VerifyICEDiagnoser ,
+ bool AllowFold,
+ bool StoreResult) {
   SourceLocation DiagLoc = E->getBeginLoc();
 
   if (getLangOpts().CPlusPlus11) {
@@ -14538,14 +14538,13 @@
 return ExprError();
   }
 
-  if (!isa(E))
-E = ConstantExpr::Create(Context, E);
-
   // Circumvent ICE checking in C++11 to avoid evaluating the expression twice
   // in the non-ICE case.
   if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) {
 if (Result)
   *Result = E->EvaluateKnownConstIntCheckOverflow(Context);
+if (!isa(E))
+  E = ConstantExpr::Create(Context, E);
 return E;
   }
 
@@ -14555,8 +14554,13 @@
 
   // Try to evaluate the expression, and produce diagnostics explaining why it's
   // not a constant expression as a side-effect.
-  bool Folded = E->EvaluateAsRValue(EvalResult, Context) &&
-EvalResult.Val.isInt() && !EvalResult.HasSideEffects;
+  bool Folded =
+  E->EvaluateAsRValue(EvalResult, Context, /*isConstantContext*/ true) &&
+  EvalResult.Val.isInt() && !EvalResult.HasSideEffects;
+
+  if (!isa(E))
+if (StoreResult)
+  E = ConstantExpr::Create(Context, E, EvalResult.Val);
 
   // In C++11, we can rely on diagnostics being produced for any expression
   // which is not a constant expression. If no diagnostics were produced, then
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -14006,8 +14006,6 @@
 ExprResult Converted = PerformContextuallyConvertToBool(AssertExpr);
 if (Converted.isInvalid())
   Failed = true;
-else
-  Converted = ConstantExpr::Create(Context, Converted.get());
 
 llvm::APSInt Cond;
 if (!Failed && VerifyIntegerConstantExpression(Converted.get(), ,
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -8963,6 +8963,8 @@
 
 bool IntExprEvaluator::VisitConstantExpr(const ConstantExpr *E) {
   llvm::SaveAndRestore InConstantContext(Info.InConstantContext, true);
+  if (E->getResultStorageKind() != ConstantExpr::RSK_None)
+return Success(E->getAPValueResult(), E);
   return ExprEvaluatorBaseTy::VisitConstantExpr(E);
 }
 
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -239,6 +239,7 @@
 ConstantExpr::getStorageKind(const APValue ) {
   switch (Value.getKind()) {
   case APValue::None:
+  case APValue::Indeterminate:
 return ConstantExpr::RSK_None;
   case APValue::Int:
 if (!Value.getInt().needsCleanup())
@@ 

[PATCH] D62399: [clang] Add storage for APValue in ConstantExpr

2019-06-15 Thread Tyker via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363493: [clang] Add storage for APValue in ConstantExpr 
(authored by Tyker, committed by ).
Herald added a subscriber: kristina.

Changed prior to commit:
  https://reviews.llvm.org/D62399?vs=203723=204911#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D62399

Files:
  cfe/trunk/include/clang/AST/APValue.h
  cfe/trunk/include/clang/AST/ASTContext.h
  cfe/trunk/include/clang/AST/Expr.h
  cfe/trunk/include/clang/AST/Stmt.h
  cfe/trunk/include/clang/AST/TextNodeDumper.h
  cfe/trunk/include/clang/Serialization/ASTReader.h
  cfe/trunk/include/clang/Serialization/ASTWriter.h
  cfe/trunk/lib/AST/APValue.cpp
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/lib/AST/Expr.cpp
  cfe/trunk/lib/AST/TextNodeDumper.cpp
  cfe/trunk/lib/Sema/SemaOverload.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
  cfe/trunk/lib/Serialization/ASTWriter.cpp
  cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
  cfe/trunk/test/AST/ast-dump-color.cpp
  llvm/trunk/include/llvm/ADT/APFloat.h
  llvm/trunk/lib/Support/APFloat.cpp

Index: llvm/trunk/lib/Support/APFloat.cpp
===
--- llvm/trunk/lib/Support/APFloat.cpp
+++ llvm/trunk/lib/Support/APFloat.cpp
@@ -113,6 +113,42 @@
   static const fltSemantics semPPCDoubleDoubleLegacy = {1023, -1022 + 53,
 53 + 53, 128};
 
+  const llvm::fltSemantics ::EnumToSemantics(Semantics S) {
+switch (S) {
+case S_IEEEhalf:
+  return IEEEhalf();
+case S_IEEEsingle:
+  return IEEEsingle();
+case S_IEEEdouble:
+  return IEEEdouble();
+case S_x87DoubleExtended:
+  return x87DoubleExtended();
+case S_IEEEquad:
+  return IEEEquad();
+case S_PPCDoubleDouble:
+  return PPCDoubleDouble();
+}
+llvm_unreachable("Unrecognised floating semantics");
+  }
+
+  APFloatBase::Semantics
+  APFloatBase::SemanticsToEnum(const llvm::fltSemantics ) {
+if ( == ::APFloat::IEEEhalf())
+  return S_IEEEhalf;
+else if ( == ::APFloat::IEEEsingle())
+  return S_IEEEsingle;
+else if ( == ::APFloat::IEEEdouble())
+  return S_IEEEdouble;
+else if ( == ::APFloat::x87DoubleExtended())
+  return S_x87DoubleExtended;
+else if ( == ::APFloat::IEEEquad())
+  return S_IEEEquad;
+else if ( == ::APFloat::PPCDoubleDouble())
+  return S_PPCDoubleDouble;
+else
+  llvm_unreachable("Unknown floating semantics");
+  }
+
   const fltSemantics ::IEEEhalf() {
 return semIEEEhalf;
   }
Index: llvm/trunk/include/llvm/ADT/APFloat.h
===
--- llvm/trunk/include/llvm/ADT/APFloat.h
+++ llvm/trunk/include/llvm/ADT/APFloat.h
@@ -147,6 +147,17 @@
 
   /// \name Floating Point Semantics.
   /// @{
+  enum Semantics {
+S_IEEEhalf,
+S_IEEEsingle,
+S_IEEEdouble,
+S_x87DoubleExtended,
+S_IEEEquad,
+S_PPCDoubleDouble
+  };
+
+  static const llvm::fltSemantics (Semantics S);
+  static Semantics SemanticsToEnum(const llvm::fltSemantics );
 
   static const fltSemantics () LLVM_READNONE;
   static const fltSemantics () LLVM_READNONE;
Index: cfe/trunk/lib/AST/ASTImporter.cpp
===
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -6376,6 +6376,13 @@
   Expr *ToSubExpr;
   std::tie(ToSubExpr) = *Imp;
 
+  // TODO : Handle APValue::ValueKind that require importing.
+  APValue::ValueKind Kind = E->getResultAPValueKind();
+  if (Kind == APValue::Int || Kind == APValue::Float ||
+  Kind == APValue::FixedPoint || Kind == APValue::ComplexFloat ||
+  Kind == APValue::ComplexInt)
+return ConstantExpr::Create(Importer.getToContext(), ToSubExpr,
+E->getAPValueResult());
   return ConstantExpr::Create(Importer.getToContext(), ToSubExpr);
 }
 
Index: cfe/trunk/lib/AST/APValue.cpp
===
--- cfe/trunk/lib/AST/APValue.cpp
+++ cfe/trunk/lib/AST/APValue.cpp
@@ -456,7 +456,8 @@
   llvm_unreachable("Unknown APValue kind!");
 }
 
-void APValue::printPretty(raw_ostream , ASTContext , QualType Ty) const{
+void APValue::printPretty(raw_ostream , const ASTContext ,
+  QualType Ty) const {
   switch (getKind()) {
   case APValue::None:
 Out << "";
@@ -675,7 +676,7 @@
   llvm_unreachable("Unknown APValue kind!");
 }
 
-std::string APValue::getAsString(ASTContext , QualType Ty) const {
+std::string APValue::getAsString(const ASTContext , QualType Ty) const {
   std::string Result;
   llvm::raw_string_ostream Out(Result);
   printPretty(Out, Ctx, Ty);
Index: cfe/trunk/lib/AST/ASTContext.cpp

r363493 - [clang] Add storage for APValue in ConstantExpr

2019-06-15 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Sat Jun 15 03:24:47 2019
New Revision: 363493

URL: http://llvm.org/viewvc/llvm-project?rev=363493=rev
Log:
[clang] Add storage for APValue in ConstantExpr

Summary:
When using ConstantExpr we often need the result of the expression to be kept 
in the AST. Currently this is done on a by the node that needs the result and 
has been done multiple times for enumerator, for constexpr variables... . This 
patch adds to ConstantExpr the ability to store the result of evaluating the 
expression. no functional changes expected.

Changes:
 - Add trailling object to ConstantExpr that can hold an APValue or an 
uint64_t. the uint64_t is here because most ConstantExpr yield integral values 
so there is an optimized layout for integral values.
 - Add basic* serialization support for the trailing result.
 - Move conversion functions from an enum to a fltSemantics from 
clang::FloatingLiteral to llvm::APFloatBase. this change is to make it usable 
for serializing APValues.
 - Add basic* Import support for the trailing result.
 - ConstantExpr created in CheckConvertedConstantExpression now stores the 
result in the ConstantExpr Node.
 - Adapt AST dump to print the result when present.

basic* : None, Indeterminate, Int, Float, FixedPoint, ComplexInt, ComplexFloat,
the result is not yet used anywhere but for -ast-dump.

Reviewers: rsmith, martong, shafik

Reviewed By: rsmith

Subscribers: rnkovacs, hiraditya, dexonsmith, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Modified:
cfe/trunk/include/clang/AST/APValue.h
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/AST/TextNodeDumper.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/AST/APValue.cpp
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/TextNodeDumper.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/AST/ast-dump-color.cpp

Modified: cfe/trunk/include/clang/AST/APValue.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=363493=363492=363493=diff
==
--- cfe/trunk/include/clang/AST/APValue.h (original)
+++ cfe/trunk/include/clang/AST/APValue.h Sat Jun 15 03:24:47 2019
@@ -182,6 +182,10 @@ public:
   struct NoLValuePath {};
   struct UninitArray {};
   struct UninitStruct {};
+
+  friend class ASTReader;
+  friend class ASTWriter;
+
 private:
   ValueKind Kind;
 
@@ -326,8 +330,8 @@ public:
   void dump() const;
   void dump(raw_ostream ) const;
 
-  void printPretty(raw_ostream , ASTContext , QualType Ty) const;
-  std::string getAsString(ASTContext , QualType Ty) const;
+  void printPretty(raw_ostream , const ASTContext , QualType Ty) const;
+  std::string getAsString(const ASTContext , QualType Ty) const;
 
   APSInt () {
 assert(isInt() && "Invalid accessor");

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=363493=363492=363493=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Sat Jun 15 03:24:47 2019
@@ -271,6 +271,9 @@ private:
   llvm::DenseMap
 MaterializedTemporaryValues;
 
+  /// Used to cleanups APValues stored in the AST.
+  mutable llvm::SmallVector APValueCleanups;
+
   /// A cache mapping a string value to a StringLiteral object with the same
   /// value.
   ///
@@ -2816,6 +2819,10 @@ public:
   APValue *getMaterializedTemporaryValue(const MaterializeTemporaryExpr *E,
  bool MayCreate);
 
+  /// Adds an APValue that will be destructed during the destruction of the
+  /// ASTContext.
+  void AddAPValueCleanup(APValue *Ptr) const { APValueCleanups.push_back(Ptr); 
}
+
   /// Return a string representing the human readable name for the specified
   /// function declaration or file name. Used by SourceLocExpr and
   /// PredefinedExpr to cache evaluated results.

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=363493=363492=363493=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Jun 15 03:24:47 2019
@@ -943,21 +943,61 @@ public:
   }
 };
 
-/// ConstantExpr - An expression that occurs in a constant context.
-class ConstantExpr : public 

[PATCH] D62926: [analyzer] ReturnVisitor: Bypass everything to see inlined calls

2019-06-15 Thread Csaba Dabis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363491: [analyzer] ReturnVisitor: Bypass everything to see 
inlined calls (authored by Charusso, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62926?vs=204698=204910#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D62926

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp
  cfe/trunk/test/Analysis/new-ctor-null-throw.cpp
  cfe/trunk/test/Analysis/new-ctor-null.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -841,16 +841,38 @@
   return;
 
 // First, find when we processed the statement.
+// If we work with a 'CXXNewExpr' that is going to be purged away before
+// its call take place. We would catch that purge in the last condition
+// as a 'StmtPoint' so we have to bypass it.
+const bool BypassCXXNewExprEval = isa(S);
+
+// This is moving forward when we enter into another context.
+const StackFrameContext *CurrentSFC = Node->getStackFrame();
+
 do {
-  if (auto CEE = Node->getLocationAs())
+  // If that is satisfied we found our statement as an inlined call.
+  if (Optional CEE = Node->getLocationAs())
 if (CEE->getCalleeContext()->getCallSite() == S)
   break;
-  if (auto SP = Node->getLocationAs())
-if (SP->getStmt() == S)
-  break;
 
+  // Try to move forward to the end of the call-chain.
   Node = Node->getFirstPred();
-} while (Node);
+  if (!Node)
+break;
+
+  const StackFrameContext *PredSFC = Node->getStackFrame();
+
+  // If that is satisfied we found our statement.
+  // FIXME: This code currently bypasses the call site for the
+  //conservatively evaluated allocator.
+  if (!BypassCXXNewExprEval)
+if (Optional SP = Node->getLocationAs())
+  // See if we do not enter into another context.
+  if (SP->getStmt() == S && CurrentSFC == PredSFC)
+break;
+
+  CurrentSFC = PredSFC;
+} while (Node->getStackFrame() == CurrentSFC);
 
 // Next, step over any post-statement checks.
 while (Node && Node->getLocation().getAs())
Index: cfe/trunk/test/Analysis/new-ctor-null-throw.cpp
===
--- cfe/trunk/test/Analysis/new-ctor-null-throw.cpp
+++ cfe/trunk/test/Analysis/new-ctor-null-throw.cpp
@@ -1,4 +1,9 @@
-// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -analyzer-config suppress-null-return-paths=false \
+// RUN:  -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core \
+// RUN:  -DSUPPRESSED \
+// RUN:  -verify %s
 
 void clang_analyzer_eval(bool);
 
@@ -9,18 +14,41 @@
 // operator new.
 void *operator new(size_t size) {
   return nullptr;
+  // expected-warning@-1 {{'operator new' should not return a null pointer unless it is declared 'throw()' or 'noexcept'}}
 }
 void *operator new[](size_t size) {
   return nullptr;
+  // expected-warning@-1 {{'operator new[]' should not return a null pointer unless it is declared 'throw()' or 'noexcept'}}
 }
 
 struct S {
   int x;
   S() : x(1) {}
   ~S() {}
+  int getX() const { return x; }
 };
 
 void testArrays() {
   S *s = new S[10]; // no-crash
-  s[0].x = 2; // expected-warning{{Dereference of null pointer}}
+  s[0].x = 2;
+#ifndef SUPPRESSED
+  // expected-warning@-2 {{Dereference of null pointer}}
+#endif
 }
+
+void testCtor() {
+  S *s = new S();
+  s->x = 13;
+#ifndef SUPPRESSED
+  // expected-warning@-2 {{Access to field 'x' results in a dereference of a null pointer (loaded from variable 's')}}
+#endif
+}
+
+void testMethod() {
+  S *s = new S();
+  const int X = s->getX();
+#ifndef SUPPRESSED
+  // expected-warning@-2 {{Called C++ object pointer is null}}
+#endif
+}
+
Index: cfe/trunk/test/Analysis/new-ctor-null.cpp
===
--- cfe/trunk/test/Analysis/new-ctor-null.cpp
+++ cfe/trunk/test/Analysis/new-ctor-null.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core,debug.ExprInspection \
+// RUN:  -verify %s
 
 void clang_analyzer_eval(bool);
 void clang_analyzer_warnIfReached();
@@ -24,7 +26,8 @@
 
 void testArrays() {
   S *s = new S[10]; // no-crash
-  s[0].x = 2; // 

r363491 - [analyzer] ReturnVisitor: Bypass everything to see inlined calls

2019-06-15 Thread Csaba Dabis via cfe-commits
Author: charusso
Date: Sat Jun 15 03:05:49 2019
New Revision: 363491

URL: http://llvm.org/viewvc/llvm-project?rev=363491=rev
Log:
[analyzer] ReturnVisitor: Bypass everything to see inlined calls

Summary:
When we traversed backwards on ExplodedNodes to see where processed the
given statement we `break` too early. With the current approach we do not
miss the CallExitEnd ProgramPoint which stands for an inlined call.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
 dkrupp, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/new-ctor-null-throw.cpp
cfe/trunk/test/Analysis/new-ctor-null.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=363491=363490=363491=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Sat Jun 15 
03:05:49 2019
@@ -841,16 +841,38 @@ public:
   return;
 
 // First, find when we processed the statement.
+// If we work with a 'CXXNewExpr' that is going to be purged away before
+// its call take place. We would catch that purge in the last condition
+// as a 'StmtPoint' so we have to bypass it.
+const bool BypassCXXNewExprEval = isa(S);
+
+// This is moving forward when we enter into another context.
+const StackFrameContext *CurrentSFC = Node->getStackFrame();
+
 do {
-  if (auto CEE = Node->getLocationAs())
+  // If that is satisfied we found our statement as an inlined call.
+  if (Optional CEE = Node->getLocationAs())
 if (CEE->getCalleeContext()->getCallSite() == S)
   break;
-  if (auto SP = Node->getLocationAs())
-if (SP->getStmt() == S)
-  break;
 
+  // Try to move forward to the end of the call-chain.
   Node = Node->getFirstPred();
-} while (Node);
+  if (!Node)
+break;
+
+  const StackFrameContext *PredSFC = Node->getStackFrame();
+
+  // If that is satisfied we found our statement.
+  // FIXME: This code currently bypasses the call site for the
+  //conservatively evaluated allocator.
+  if (!BypassCXXNewExprEval)
+if (Optional SP = Node->getLocationAs())
+  // See if we do not enter into another context.
+  if (SP->getStmt() == S && CurrentSFC == PredSFC)
+break;
+
+  CurrentSFC = PredSFC;
+} while (Node->getStackFrame() == CurrentSFC);
 
 // Next, step over any post-statement checks.
 while (Node && Node->getLocation().getAs())

Added: cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp?rev=363491=auto
==
--- cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp (added)
+++ cfe/trunk/test/Analysis/inlining/placement-new-fp-suppression.cpp Sat Jun 
15 03:05:49 2019
@@ -0,0 +1,137 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core.CallAndMessage \
+// RUN:  -analyzer-config suppress-null-return-paths=false \
+// RUN:  -verify %s
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=core.CallAndMessage \
+// RUN:  -DSUPPRESSED \
+// RUN:  -verify %s
+
+#ifdef SUPPRESSED
+// expected-no-diagnostics
+#endif
+
+#include "../Inputs/system-header-simulator-cxx.h"
+
+typedef unsigned long uintptr_t;
+
+void error();
+void *malloc(size_t);
+
+
+// From llvm/include/llvm/Support/MathExtras.h
+inline uintptr_t alignAddr(const void *Addr, size_t Alignment) {
+  return (((uintptr_t)Addr + Alignment - 1) & ~(uintptr_t)(Alignment - 1));
+}
+
+inline size_t alignmentAdjustment(const void *Ptr, size_t Alignment) {
+  return alignAddr(Ptr, Alignment) - (uintptr_t)Ptr;
+}
+
+
+// From llvm/include/llvm/Support/MemAlloc.h
+inline void *safe_malloc(size_t Sz) {
+  void *Result = malloc(Sz);
+  if (Result == nullptr)
+error();
+
+  return Result;
+}
+
+
+// From llvm/include/llvm/Support/Allocator.h
+class MallocAllocator {
+public:
+  void *Allocate(size_t Size, size_t /*Alignment*/) {
+return safe_malloc(Size);
+  }
+};
+
+class BumpPtrAllocator {
+public:
+  void *Allocate(size_t Size, size_t Alignment) {
+BytesAllocated += Size;
+size_t Adjustment = alignmentAdjustment(CurPtr, Alignment);
+size_t SizeToAllocate = Size;
+
+size_t PaddedSize = SizeToAllocate + Alignment - 1;
+uintptr_t AlignedAddr = alignAddr(Allocator.Allocate(PaddedSize, 

r363464 - Add --print-supported-cpus flag for clang.

2019-06-15 Thread Ziang Wan via cfe-commits
Author: ziangwan725
Date: Fri Jun 14 14:42:21 2019
New Revision: 363464

URL: http://llvm.org/viewvc/llvm-project?rev=363464=rev
Log:
Add --print-supported-cpus flag for clang.

This patch allows clang users to print out a list of supported CPU models using
clang [--target=] --print-supported-cpus

Then, users can select the CPU model to compile to using
clang --target= -mcpu= a.c

It is a handy feature to help cross compilation.

Added:
cfe/trunk/test/Driver/print-supported-cpus.c
Modified:
cfe/trunk/docs/ClangCommandLineReference.rst
cfe/trunk/docs/CommandGuide/clang.rst
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/FrontendOptions.h
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/tools/driver/cc1_main.cpp

Modified: cfe/trunk/docs/ClangCommandLineReference.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangCommandLineReference.rst?rev=363464=363463=363464=diff
==
--- cfe/trunk/docs/ClangCommandLineReference.rst (original)
+++ cfe/trunk/docs/ClangCommandLineReference.rst Fri Jun 14 14:42:21 2019
@@ -610,6 +610,10 @@ C++ standard library to use
 
 Generate code for the given target
 
+.. option:: --print-supported-cpus
+
+Print supported cpu models for the given target
+
 .. option:: -time
 
 Time individual commands

Modified: cfe/trunk/docs/CommandGuide/clang.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/CommandGuide/clang.rst?rev=363464=363463=363464=diff
==
--- cfe/trunk/docs/CommandGuide/clang.rst (original)
+++ cfe/trunk/docs/CommandGuide/clang.rst Fri Jun 14 14:42:21 2019
@@ -324,6 +324,12 @@ number of cross compilers, or may only s
   When building for iPhone OS, specify the minimum version supported by your
   application.
 
+.. option:: --print-supported-cpus
+
+  Print out a list of supported processors for the given target (specified 
+  through --target= or -arch ). If no target is 
+  specified, the system default target will be used.
+
 .. option:: -march=
 
   Specify that Clang should generate code for a specific processor family

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=363464=363463=363464=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Jun 14 14:42:21 2019
@@ -2632,6 +2632,10 @@ def : Separate<["--"], "no-system-header
 def s : Flag<["-"], "s">, Group;
 def target : Joined<["--"], "target=">, Flags<[DriverOption, CoreOption]>,
   HelpText<"Generate code for the given target">;
+def _print_supported_cpus : Flag<["-", "--"], "print-supported-cpus">,
+  Group, Flags<[CC1Option, CoreOption]>,
+  HelpText<"Print supported cpu models for the given target (if target is not 
specified,"
+   " it will print the supported cpus for the default target)">;
 def gcc_toolchain : Joined<["--"], "gcc-toolchain=">, Flags<[DriverOption]>,
   HelpText<"Use the gcc toolchain at the given directory">;
 def time : Flag<["-"], "time">,

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=363464=363463=363464=diff
==
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Fri Jun 14 14:42:21 2019
@@ -260,6 +260,9 @@ public:
   /// Show timers for individual actions.
   unsigned ShowTimers : 1;
 
+  /// print the supported cpus for the current target
+  unsigned PrintSupportedCPUs : 1;
+
   /// Output time trace profile.
   unsigned TimeTrace : 1;
 

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=363464=363463=363464=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Fri Jun 14 14:42:21 2019
@@ -1671,7 +1671,8 @@ bool Driver::HandleImmediateArgs(const C
   }
 
   if (C.getArgs().hasArg(options::OPT_v) ||
-  C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
+  C.getArgs().hasArg(options::OPT__HASH_HASH_HASH) ||
+  C.getArgs().hasArg(options::OPT__print_supported_cpus)) {
 PrintVersion(C, llvm::errs());
 SuppressMissingInputWarning = true;
   }
@@ -3375,6 +3376,17 @@ void Driver::BuildActions(Compilation 
 Args.ClaimAllArgs(options::OPT_cl_compile_Group);
   }
 
+  // If the use specify --print-supported-cpus, clang will only print out
+  // supported cpu names without doing compilation.
+  if (Arg *A = 

[clang-tools-extra] r363365 - Test commit

2019-06-15 Thread Shaurya Gupta via cfe-commits
Author: sureyeaah
Date: Fri Jun 14 02:40:42 2019
New Revision: 363365

URL: http://llvm.org/viewvc/llvm-project?rev=363365=rev
Log:
Test commit

Modified:
clang-tools-extra/trunk/clangd/refactor/tweaks/RawStringLiteral.cpp

Modified: clang-tools-extra/trunk/clangd/refactor/tweaks/RawStringLiteral.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/tweaks/RawStringLiteral.cpp?rev=363365=363364=363365=diff
==
--- clang-tools-extra/trunk/clangd/refactor/tweaks/RawStringLiteral.cpp 
(original)
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/RawStringLiteral.cpp Fri Jun 
14 02:40:42 2019
@@ -99,4 +99,3 @@ std::string RawStringLiteral::title() co
 } // namespace
 } // namespace clangd
 } // namespace clang
-


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


r363488 - [clang] perform semantic checking in constant context

2019-06-15 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Sat Jun 15 01:32:56 2019
New Revision: 363488

URL: http://llvm.org/viewvc/llvm-project?rev=363488=rev
Log:
[clang] perform semantic checking in constant context

Summary:
Since the addition of __builtin_is_constant_evaluated the result of an 
expression can change based on whether it is evaluated in constant context. a 
lot of semantic checking performs evaluations with out specifying context. 
which can lead to wrong diagnostics.
for example:
```
constexpr int i0 = (long long)__builtin_is_constant_evaluated() * (1ll << 33); 
//#1
constexpr int i1 = (long long)!__builtin_is_constant_evaluated() * (1ll << 33); 
//#2
```
before the patch, #2 was diagnosed incorrectly and #1 wasn't diagnosed.
after the patch #1 is diagnosed as it should and #2 isn't.

Changes:
 - add a flag to Sema to passe in constant context mode.
 - in SemaChecking.cpp calls to Expr::Evaluate* are now done in constant 
context when they should.
 - in SemaChecking.cpp diagnostics for UB are not checked for in constant 
context because an error will be emitted by the constant evaluator.
 - in SemaChecking.cpp diagnostics for construct that cannot appear in constant 
context are not checked for in constant context.
 - in SemaChecking.cpp diagnostics on constant expression are always emitted 
because constant expression are always evaluated.
 - semantic checking for initialization of constexpr variables is now done in 
constant context.
 - adapt test that were depending on warning changes.
 - add test.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/attr-nonnull.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=363488=363487=363488=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Jun 15 01:32:56 2019
@@ -599,7 +599,8 @@ public:
   /// which we can fold and convert to a boolean condition using
   /// any crazy technique that we want to, even if the expression has
   /// side-effects.
-  bool EvaluateAsBooleanCondition(bool , const ASTContext ) const;
+  bool EvaluateAsBooleanCondition(bool , const ASTContext ,
+  bool InConstantContext = false) const;
 
   enum SideEffectsKind {
 SE_NoSideEffects,  ///< Strictly evaluate the expression.
@@ -611,20 +612,21 @@ public:
   /// EvaluateAsInt - Return true if this is a constant which we can fold and
   /// convert to an integer, using any crazy technique that we want to.
   bool EvaluateAsInt(EvalResult , const ASTContext ,
- SideEffectsKind AllowSideEffects = SE_NoSideEffects) 
const;
+ SideEffectsKind AllowSideEffects = SE_NoSideEffects,
+ bool InConstantContext = false) const;
 
   /// EvaluateAsFloat - Return true if this is a constant which we can fold and
   /// convert to a floating point value, using any crazy technique that we
   /// want to.
-  bool
-  EvaluateAsFloat(llvm::APFloat , const ASTContext ,
-  SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
+  bool EvaluateAsFloat(llvm::APFloat , const ASTContext ,
+   SideEffectsKind AllowSideEffects = SE_NoSideEffects,
+   bool InConstantContext = false) const;
 
   /// EvaluateAsFloat - Return true if this is a constant which we can fold and
   /// convert to a fixed point value.
-  bool EvaluateAsFixedPoint(
-  EvalResult , const ASTContext ,
-  SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
+  bool EvaluateAsFixedPoint(EvalResult , const ASTContext ,
+SideEffectsKind AllowSideEffects = 
SE_NoSideEffects,
+bool InConstantContext = false) const;
 
   /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
   /// constant folded without side-effects, but discard the result.
@@ -660,7 +662,8 @@ public:
 
   /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
   /// lvalue with link time known address, with no side-effects.
-  bool EvaluateAsLValue(EvalResult , const ASTContext ) const;
+  bool EvaluateAsLValue(EvalResult , const ASTContext ,
+bool InConstantContext = false) const;
 
   /// EvaluateAsInitializer - Evaluate an expression as if it were the
   /// initializer of the given declaration. Returns true if the initializer

Modified: 

r363475 - Fixed the --print-supported-cpus test

2019-06-15 Thread Ziang Wan via cfe-commits
Author: ziangwan725
Date: Fri Jun 14 16:34:40 2019
New Revision: 363475

URL: http://llvm.org/viewvc/llvm-project?rev=363475=rev
Log:
Fixed the --print-supported-cpus test

Add constraints for the test that require specific backend targets
to be registered.

Remove trailing whitespace in the doc.

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

Modified:
cfe/trunk/docs/CommandGuide/clang.rst
cfe/trunk/test/Driver/print-supported-cpus.c

Modified: cfe/trunk/docs/CommandGuide/clang.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/CommandGuide/clang.rst?rev=363475=363474=363475=diff
==
--- cfe/trunk/docs/CommandGuide/clang.rst (original)
+++ cfe/trunk/docs/CommandGuide/clang.rst Fri Jun 14 16:34:40 2019
@@ -326,8 +326,8 @@ number of cross compilers, or may only s
 
 .. option:: --print-supported-cpus
 
-  Print out a list of supported processors for the given target (specified 
-  through --target= or -arch ). If no target is 
+  Print out a list of supported processors for the given target (specified
+  through --target= or -arch ). If no target is
   specified, the system default target will be used.
 
 .. option:: -march=

Modified: cfe/trunk/test/Driver/print-supported-cpus.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/print-supported-cpus.c?rev=363475=363474=363475=diff
==
--- cfe/trunk/test/Driver/print-supported-cpus.c (original)
+++ cfe/trunk/test/Driver/print-supported-cpus.c Fri Jun 14 16:34:40 2019
@@ -1,5 +1,6 @@
 // Test that the --print-supported-cpus flag works
 
+// REQUIRES: x86-registered-target
 // RUN: %clang --target=x86_64-unknown-linux-gnu \
 // RUN:   --print-supported-cpus 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-X86
@@ -7,6 +8,7 @@
 // CHECK-X86: corei7
 // CHECK-X86: Use -mcpu or -mtune to specify the target's processor.
 
+// REQUIRES: arm-registered-target
 // RUN: %clang --target=arm-unknown-linux-android \
 // RUN:   --print-supported-cpus 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-ARM


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


r363362 - [C++20] add Basic consteval specifier

2019-06-15 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Fri Jun 14 01:56:20 2019
New Revision: 363362

URL: http://llvm.org/viewvc/llvm-project?rev=363362=rev
Log:
[C++20] add Basic consteval specifier

Summary:
this revision adds Lexing, Parsing and Basic Semantic for the consteval 
specifier as specified by 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1073r3.html

with this patch, the consteval specifier is treated as constexpr but can only 
be applied to function declaration.

Changes:
 - add the consteval keyword.
 - add parsing of consteval specifier for normal declarations and lambdas 
expressions.
 - add the whether a declaration is constexpr is now represented by and enum 
everywhere except for variable because they can't be consteval.
 - adapt diagnostic about constexpr to print constexpr or consteval depending 
on the case.
 - add tests for basic semantic.

Reviewers: rsmith, martong, shafik

Reviewed By: rsmith

Subscribers: eraman, efriedma, rnkovacs, cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/SemaCXX/cxx2a-consteval.cpp
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/include/clang/Basic/TokenKinds.def
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/AST/TextNodeDumper.cpp
cfe/trunk/lib/Parse/ParseCXXInlineMethods.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaCoroutine.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/SemaCXX/cxx2a-compat.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=363362=363361=363362=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Jun 14 01:56:20 2019
@@ -1861,7 +1861,7 @@ protected:
   FunctionDecl(Kind DK, ASTContext , DeclContext *DC, SourceLocation 
StartLoc,
const DeclarationNameInfo , QualType T,
TypeSourceInfo *TInfo, StorageClass S, bool isInlineSpecified,
-   bool isConstexprSpecified);
+   ConstexprSpecKind ConstexprKind);
 
   using redeclarable_base = Redeclarable;
 
@@ -1891,29 +1891,24 @@ public:
   using redeclarable_base::getMostRecentDecl;
   using redeclarable_base::isFirstDecl;
 
-  static FunctionDecl *Create(ASTContext , DeclContext *DC,
-  SourceLocation StartLoc, SourceLocation NLoc,
-  DeclarationName N, QualType T,
-  TypeSourceInfo *TInfo,
-  StorageClass SC,
-  bool isInlineSpecified = false,
-  bool hasWrittenPrototype = true,
-  bool isConstexprSpecified = false) {
+  static FunctionDecl *
+  Create(ASTContext , DeclContext *DC, SourceLocation StartLoc,
+ SourceLocation NLoc, DeclarationName N, QualType T,
+ TypeSourceInfo *TInfo, StorageClass SC, bool isInlineSpecified = 
false,
+ bool hasWrittenPrototype = true,
+ ConstexprSpecKind ConstexprKind = CSK_unspecified) {
 DeclarationNameInfo NameInfo(N, NLoc);
-return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo,
-SC,
+return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, SC,
 isInlineSpecified, hasWrittenPrototype,
-isConstexprSpecified);
+ConstexprKind);
   }
 
   static FunctionDecl *Create(ASTContext , DeclContext *DC,
   SourceLocation StartLoc,
-  const DeclarationNameInfo ,
-  QualType T, TypeSourceInfo *TInfo,
-  StorageClass SC,
-  bool 

r363361 - [clang] Fixing incorrect implicit deduction guides (PR41549)

2019-06-15 Thread Gauthier Harnisch via cfe-commits
Author: tyker
Date: Fri Jun 14 01:40:04 2019
New Revision: 363361

URL: http://llvm.org/viewvc/llvm-project?rev=363361=rev
Log:
[clang] Fixing incorrect implicit deduction guides (PR41549)

Summary:
[[ https://bugs.llvm.org/show_bug.cgi?id=41549 | bug report ]]

Before this patch, implicit deduction guides were generated from the first 
declaration found by lookup.
With this patch implicit deduction guides are generated from the definition of 
the class template.
Also added test that was previously failing.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits, Quuxplusone

Tags: #clang

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

Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=363361=363360=363361=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Fri Jun 14 01:40:04 2019
@@ -2052,6 +2052,12 @@ private:
 
 void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,
   SourceLocation Loc) {
+  if (CXXRecordDecl *DefRecord =
+  cast(Template->getTemplatedDecl())->getDefinition()) {
+TemplateDecl *DescribedTemplate = DefRecord->getDescribedClassTemplate();
+Template = DescribedTemplate ? DescribedTemplate : Template;
+  }
+
   DeclContext *DC = Template->getDeclContext();
   if (DC->isDependentContext())
 return;

Modified: cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp?rev=363361=363360=363361=diff
==
--- cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp 
(original)
+++ cfe/trunk/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp Fri Jun 
14 01:40:04 2019
@@ -489,6 +489,21 @@ static_assert(__is_same(decltype(ta), Te
 }
 #pragma clang diagnostic pop
 
+namespace PR41549 {
+
+template  struct umm;
+
+template 
+struct umm {
+  umm(H h = 0, P p = 0);
+};
+
+template  struct umm;
+
+umm m(1);
+
+}
+
 #else
 
 // expected-no-diagnostics


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


[PATCH] D62009: [clang] perform semantic checking in constant context

2019-06-15 Thread Tyker via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363488: [clang] perform semantic checking in constant 
context (authored by Tyker, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62009?vs=200662=204906#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D62009

Files:
  cfe/trunk/include/clang/AST/Expr.h
  cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/AST/ExprConstant.cpp
  cfe/trunk/lib/Sema/Sema.cpp
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/SemaCXX/attr-nonnull.cpp
  cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Index: cfe/trunk/include/clang/AST/Expr.h
===
--- cfe/trunk/include/clang/AST/Expr.h
+++ cfe/trunk/include/clang/AST/Expr.h
@@ -599,7 +599,8 @@
   /// which we can fold and convert to a boolean condition using
   /// any crazy technique that we want to, even if the expression has
   /// side-effects.
-  bool EvaluateAsBooleanCondition(bool , const ASTContext ) const;
+  bool EvaluateAsBooleanCondition(bool , const ASTContext ,
+  bool InConstantContext = false) const;
 
   enum SideEffectsKind {
 SE_NoSideEffects,  ///< Strictly evaluate the expression.
@@ -611,20 +612,21 @@
   /// EvaluateAsInt - Return true if this is a constant which we can fold and
   /// convert to an integer, using any crazy technique that we want to.
   bool EvaluateAsInt(EvalResult , const ASTContext ,
- SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
+ SideEffectsKind AllowSideEffects = SE_NoSideEffects,
+ bool InConstantContext = false) const;
 
   /// EvaluateAsFloat - Return true if this is a constant which we can fold and
   /// convert to a floating point value, using any crazy technique that we
   /// want to.
-  bool
-  EvaluateAsFloat(llvm::APFloat , const ASTContext ,
-  SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
+  bool EvaluateAsFloat(llvm::APFloat , const ASTContext ,
+   SideEffectsKind AllowSideEffects = SE_NoSideEffects,
+   bool InConstantContext = false) const;
 
   /// EvaluateAsFloat - Return true if this is a constant which we can fold and
   /// convert to a fixed point value.
-  bool EvaluateAsFixedPoint(
-  EvalResult , const ASTContext ,
-  SideEffectsKind AllowSideEffects = SE_NoSideEffects) const;
+  bool EvaluateAsFixedPoint(EvalResult , const ASTContext ,
+SideEffectsKind AllowSideEffects = SE_NoSideEffects,
+bool InConstantContext = false) const;
 
   /// isEvaluatable - Call EvaluateAsRValue to see if this expression can be
   /// constant folded without side-effects, but discard the result.
@@ -660,7 +662,8 @@
 
   /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
   /// lvalue with link time known address, with no side-effects.
-  bool EvaluateAsLValue(EvalResult , const ASTContext ) const;
+  bool EvaluateAsLValue(EvalResult , const ASTContext ,
+bool InConstantContext = false) const;
 
   /// EvaluateAsInitializer - Evaluate an expression as if it were the
   /// initializer of the given declaration. Returns true if the initializer
Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -797,6 +797,15 @@
 }
   };
 
+  /// Used to change context to isConstantEvaluated without pushing a heavy
+  /// ExpressionEvaluationContextRecord object.
+  bool isConstantEvaluatedOverride;
+
+  bool isConstantEvaluated() {
+return ExprEvalContexts.back().isConstantEvaluated() ||
+   isConstantEvaluatedOverride;
+  }
+
   /// RAII object to handle the state changes required to synthesize
   /// a function body.
   class SynthesizedFunctionScope {
Index: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
@@ -85,6 +85,8 @@
   "access array element of|ERROR|"
   "access real component of|access imaginary component of}0 "
   "pointer past the end of object">;
+def note_non_null_attribute_failed : Note<
+  "null passed to a callee that requires a non-null argument">;
 def note_constexpr_null_subobject : Note<
   "cannot %select{access base class of|access derived class of|access field of|"
   "access array element of|perform pointer arithmetic on|"
Index: cfe/trunk/test/SemaCXX/attr-nonnull.cpp

[PATCH] D63009: [OpenMP] Add target task alloc function with device ID

2019-06-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev requested changes to this revision.
ABataev added a comment.
This revision now requires changes to proceed.

The tests must check the device ID for target-based calls of the task alloc 
function.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63009



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


[PATCH] D63009: [OpenMP] Add target task alloc function with device ID

2019-06-15 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D63009#1544758 , @Hahnfeld wrote:

> Am I correct that the second to last revision ("- Fix tests.") removed all 
> checks for the actual `device_id` argument from the tests? From my point of 
> view that's not fixing but weakening the tests! Can you explain why they 
> needed "fixing"?
>
> If I had to guess this is because some directives have the `device` clause, 
> so the tests should check that the generated code passes the correct argument 
> in that case.


+1. Missed the test checks, tests must be fixed


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63009



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


[PATCH] D63009: [OpenMP] Add target task alloc function with device ID

2019-06-15 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

Am I correct that the second to last revision ("- Fix tests.") removed all 
checks for the actual `device_id` argument from the tests? From my point of 
view that's not fixing but weakening the tests! Can you explain why they needed 
"fixing"?

If I had to guess this is because some directives have the `device` clause, so 
the tests should check that the generated code passes the correct argument in 
that case.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63009



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


[PATCH] D63080: [analyzer] Track indices of arrays

2019-06-15 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware accepted this revision.
baloghadamsoftware added a comment.
This revision is now accepted and ready to land.

LGTM!


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

https://reviews.llvm.org/D63080



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