[clang-tools-extra] r365632 - [clangd] Trim spaces around parsed include in include extractor

2019-07-10 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Wed Jul 10 06:59:13 2019
New Revision: 365632

URL: http://llvm.org/viewvc/llvm-project?rev=365632=rev
Log:
[clangd] Trim spaces around parsed include in include extractor

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

Modified: clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp?rev=365632=365631=365632=diff
==
--- clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp Wed Jul 10 06:59:13 
2019
@@ -76,7 +76,7 @@ std::vector parseDriverOutp
   }
 
   for (llvm::StringRef Line : llvm::make_range(StartIt, EndIt)) {
-SystemIncludes.push_back(Line.str());
+SystemIncludes.push_back(Line.trim().str());
 vlog("System include extraction: adding {0}", Line);
   }
   return SystemIncludes;


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


[PATCH] D64487: [clang, test] Fix Clang :: Headers/max_align.c on 64-bit SPARC

2019-07-10 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: venkatra, fedor.sergeev.
Herald added subscribers: jrtc27, jyknight.
Herald added a project: clang.

`Clang :: Headers/max_align.c` currently FAILs on 64-bit SPARC:

  error: 'error' diagnostics seen but not expected: 
File /vol/llvm/src/clang/dist/test/Headers/max_align.c Line 12: 
static_assert failed due to requirement '8 == _Alignof(max_align_t)' ""
  1 error generated.

This happens because `SuitableAlign` isn't defined for SPARCv9 unlike SPARCv8
(which uses the default of 64 bits).  gcc's `sparc/sparc.h` has

  #define BIGGEST_ALIGNMENT (TARGET_ARCH64 ? 128 : 64)

This patch sets `SuitableAlign` to match and updates the corresponding testcase.

Tested on `sparcv9-sun-solaris2.11` .  Ok for trunk?


Repository:
  rC Clang

https://reviews.llvm.org/D64487

Files:
  lib/Basic/Targets/Sparc.h
  test/Preprocessor/init.c


Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -9599,6 +9599,7 @@
 // X86-64-DECLSPEC: #define __declspec{{.*}}
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc64-none-none < /dev/null 
| FileCheck -match-full-lines -check-prefix SPARCV9 %s
+// SPARCV9:#define __BIGGEST_ALIGNMENT__ 16
 // SPARCV9:#define __INT64_TYPE__ long int
 // SPARCV9:#define __INTMAX_C_SUFFIX__ L
 // SPARCV9:#define __INTMAX_TYPE__ long int
Index: lib/Basic/Targets/Sparc.h
===
--- lib/Basic/Targets/Sparc.h
+++ lib/Basic/Targets/Sparc.h
@@ -208,6 +208,7 @@
 // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
+SuitableAlign = 128;
 LongDoubleFormat = ::APFloat::IEEEquad();
 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
   }


Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -9599,6 +9599,7 @@
 // X86-64-DECLSPEC: #define __declspec{{.*}}
 //
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=sparc64-none-none < /dev/null | FileCheck -match-full-lines -check-prefix SPARCV9 %s
+// SPARCV9:#define __BIGGEST_ALIGNMENT__ 16
 // SPARCV9:#define __INT64_TYPE__ long int
 // SPARCV9:#define __INTMAX_C_SUFFIX__ L
 // SPARCV9:#define __INTMAX_TYPE__ long int
Index: lib/Basic/Targets/Sparc.h
===
--- lib/Basic/Targets/Sparc.h
+++ lib/Basic/Targets/Sparc.h
@@ -208,6 +208,7 @@
 // aligned. The SPARCv9 SCD 2.4.1 says 16-byte aligned.
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
+SuitableAlign = 128;
 LongDoubleFormat = ::APFloat::IEEEquad();
 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64481: [clangd] Add a flag to clangdServer rename function to control whether we want format the replacements.

2019-07-10 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365631: [clangd] Add a flag to clangdServer rename function 
to control whether we want… (authored by hokein, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64481?vs=208940=208943#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64481

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


Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp
@@ -283,23 +283,25 @@
 }
 
 void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  Callback> CB) {
-  auto Action = [Pos, this](Path File, std::string NewName,
-Callback> CB,
-llvm::Expected InpAST) {
+  bool WantFormat, Callback> CB) 
{
+  auto Action = [Pos, WantFormat, this](Path File, std::string NewName,
+Callback> CB,
+llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
 auto Changes = renameWithinFile(InpAST->AST, File, Pos, NewName, Index);
 if (!Changes)
   return CB(Changes.takeError());
 
-auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
-   InpAST->Inputs.FS.get());
-if (auto Formatted =
-cleanupAndFormat(InpAST->Inputs.Contents, *Changes, Style))
-  *Changes = std::move(*Formatted);
-else
-  elog("Failed to format replacements: {0}", Formatted.takeError());
+if (WantFormat) {
+  auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
+ InpAST->Inputs.FS.get());
+  if (auto Formatted =
+  cleanupAndFormat(InpAST->Inputs.Contents, *Changes, Style))
+*Changes = std::move(*Formatted);
+  else
+elog("Failed to format replacements: {0}", Formatted.takeError());
+}
 
 std::vector Edits;
 for (const auto  : *Changes)
Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
@@ -577,7 +577,7 @@
 "onRename called for non-added file", ErrorCode::InvalidParams));
 
   Server->rename(
-  File, Params.position, Params.newName,
+  File, Params.position, Params.newName, /*WantFormat=*/true,
   Bind(
   [File, Code, Params](decltype(Reply) Reply,
llvm::Expected> Edits) {
Index: clang-tools-extra/trunk/clangd/ClangdServer.h
===
--- clang-tools-extra/trunk/clangd/ClangdServer.h
+++ clang-tools-extra/trunk/clangd/ClangdServer.h
@@ -240,8 +240,11 @@
 
   /// Rename all occurrences of the symbol at the \p Pos in \p File to
   /// \p NewName.
+  /// If WantFormat is false, the final TextEdit will be not formatted,
+  /// embedders could use this method to get all occurrences of the symbol 
(e.g.
+  /// highlighting them in prepare stage).
   void rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  Callback> CB);
+  bool WantFormat, Callback> CB);
 
   struct TweakRef {
 std::string ID;/// ID to pass for applyTweak.
Index: clang-tools-extra/trunk/clangd/unittests/SyncAPI.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SyncAPI.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SyncAPI.cpp
@@ -102,7 +102,7 @@
 PathRef File, Position Pos,
 llvm::StringRef NewName) {
   llvm::Optional>> Result;
-  Server.rename(File, Pos, NewName, capture(Result));
+  Server.rename(File, Pos, NewName, /*WantFormat=*/true, capture(Result));
   return std::move(*Result);
 }
 


Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp
@@ -283,23 +283,25 @@
 }
 
 void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  Callback> CB) {
-  auto Action = [Pos, this](Path File, std::string NewName,
-Callback> CB,
-

[clang-tools-extra] r365631 - [clangd] Add a flag to clangdServer rename function to control whether we want format the replacements.

2019-07-10 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Jul 10 06:44:22 2019
New Revision: 365631

URL: http://llvm.org/viewvc/llvm-project?rev=365631=rev
Log:
[clangd] Add a flag to clangdServer rename function to control whether we want 
format the replacements.

Summary:
This would allow clangd embedders to use the ClangdServer::rename for other
purposes (highlighting all the occurrences of the symbol in prepare
stage).

Reviewers: sammccall, ilya-biryukov

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

Tags: #clang

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

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

Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=365631=365630=365631=diff
==
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Wed Jul 10 06:44:22 2019
@@ -577,7 +577,7 @@ void ClangdLSPServer::onRename(const Ren
 "onRename called for non-added file", ErrorCode::InvalidParams));
 
   Server->rename(
-  File, Params.position, Params.newName,
+  File, Params.position, Params.newName, /*WantFormat=*/true,
   Bind(
   [File, Code, Params](decltype(Reply) Reply,
llvm::Expected> Edits) {

Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=365631=365630=365631=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Wed Jul 10 06:44:22 2019
@@ -283,23 +283,25 @@ ClangdServer::formatOnType(llvm::StringR
 }
 
 void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  Callback> CB) {
-  auto Action = [Pos, this](Path File, std::string NewName,
-Callback> CB,
-llvm::Expected InpAST) {
+  bool WantFormat, Callback> CB) 
{
+  auto Action = [Pos, WantFormat, this](Path File, std::string NewName,
+Callback> CB,
+llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
 auto Changes = renameWithinFile(InpAST->AST, File, Pos, NewName, Index);
 if (!Changes)
   return CB(Changes.takeError());
 
-auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
-   InpAST->Inputs.FS.get());
-if (auto Formatted =
-cleanupAndFormat(InpAST->Inputs.Contents, *Changes, Style))
-  *Changes = std::move(*Formatted);
-else
-  elog("Failed to format replacements: {0}", Formatted.takeError());
+if (WantFormat) {
+  auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
+ InpAST->Inputs.FS.get());
+  if (auto Formatted =
+  cleanupAndFormat(InpAST->Inputs.Contents, *Changes, Style))
+*Changes = std::move(*Formatted);
+  else
+elog("Failed to format replacements: {0}", Formatted.takeError());
+}
 
 std::vector Edits;
 for (const auto  : *Changes)

Modified: clang-tools-extra/trunk/clangd/ClangdServer.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.h?rev=365631=365630=365631=diff
==
--- clang-tools-extra/trunk/clangd/ClangdServer.h (original)
+++ clang-tools-extra/trunk/clangd/ClangdServer.h Wed Jul 10 06:44:22 2019
@@ -240,8 +240,11 @@ public:
 
   /// Rename all occurrences of the symbol at the \p Pos in \p File to
   /// \p NewName.
+  /// If WantFormat is false, the final TextEdit will be not formatted,
+  /// embedders could use this method to get all occurrences of the symbol 
(e.g.
+  /// highlighting them in prepare stage).
   void rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  Callback> CB);
+  bool WantFormat, Callback> CB);
 
   struct TweakRef {
 std::string ID;/// ID to pass for applyTweak.

Modified: clang-tools-extra/trunk/clangd/unittests/SyncAPI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/SyncAPI.cpp?rev=365631=365630=365631=diff
==
--- clang-tools-extra/trunk/clangd/unittests/SyncAPI.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/SyncAPI.cpp Wed Jul 10 06:44:22 
2019
@@ -102,7 +102,7 @@ 

[PATCH] D64481: [clangd] Add a flag to clangdServer rename function to control whether we want format the replacements.

2019-07-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 208940.
hokein marked an inline comment as done.
hokein added a comment.

Address review comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64481

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/unittests/SyncAPI.cpp


Index: clang-tools-extra/clangd/unittests/SyncAPI.cpp
===
--- clang-tools-extra/clangd/unittests/SyncAPI.cpp
+++ clang-tools-extra/clangd/unittests/SyncAPI.cpp
@@ -102,7 +102,7 @@
 PathRef File, Position Pos,
 llvm::StringRef NewName) {
   llvm::Optional>> Result;
-  Server.rename(File, Pos, NewName, capture(Result));
+  Server.rename(File, Pos, NewName, /*WantFormat=*/true, capture(Result));
   return std::move(*Result);
 }
 
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -240,8 +240,11 @@
 
   /// Rename all occurrences of the symbol at the \p Pos in \p File to
   /// \p NewName.
+  /// If WantFormat is false, the final TextEdit will be not formatted,
+  /// embedders could use this method to get all occurrences of the symbol 
(e.g.
+  /// highlighting them in prepare stage).
   void rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  Callback> CB);
+  bool WantFormat, Callback> CB);
 
   struct TweakRef {
 std::string ID;/// ID to pass for applyTweak.
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -283,23 +283,25 @@
 }
 
 void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  Callback> CB) {
-  auto Action = [Pos, this](Path File, std::string NewName,
-Callback> CB,
-llvm::Expected InpAST) {
+  bool WantFormat, Callback> CB) 
{
+  auto Action = [Pos, WantFormat, this](Path File, std::string NewName,
+Callback> CB,
+llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
 auto Changes = renameWithinFile(InpAST->AST, File, Pos, NewName, Index);
 if (!Changes)
   return CB(Changes.takeError());
 
-auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
-   InpAST->Inputs.FS.get());
-if (auto Formatted =
-cleanupAndFormat(InpAST->Inputs.Contents, *Changes, Style))
-  *Changes = std::move(*Formatted);
-else
-  elog("Failed to format replacements: {0}", Formatted.takeError());
+if (WantFormat) {
+  auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
+ InpAST->Inputs.FS.get());
+  if (auto Formatted =
+  cleanupAndFormat(InpAST->Inputs.Contents, *Changes, Style))
+*Changes = std::move(*Formatted);
+  else
+elog("Failed to format replacements: {0}", Formatted.takeError());
+}
 
 std::vector Edits;
 for (const auto  : *Changes)
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -577,7 +577,7 @@
 "onRename called for non-added file", ErrorCode::InvalidParams));
 
   Server->rename(
-  File, Params.position, Params.newName,
+  File, Params.position, Params.newName, /*WantFormat=*/true,
   Bind(
   [File, Code, Params](decltype(Reply) Reply,
llvm::Expected> Edits) {


Index: clang-tools-extra/clangd/unittests/SyncAPI.cpp
===
--- clang-tools-extra/clangd/unittests/SyncAPI.cpp
+++ clang-tools-extra/clangd/unittests/SyncAPI.cpp
@@ -102,7 +102,7 @@
 PathRef File, Position Pos,
 llvm::StringRef NewName) {
   llvm::Optional>> Result;
-  Server.rename(File, Pos, NewName, capture(Result));
+  Server.rename(File, Pos, NewName, /*WantFormat=*/true, capture(Result));
   return std::move(*Result);
 }
 
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -240,8 +240,11 @@
 
   /// Rename all 

[PATCH] D64471: Loop pragma parsing. NFC.

2019-07-10 Thread Sjoerd Meijer via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365629: Loop pragma parsing. NFC. (authored by SjoerdMeijer, 
committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64471?vs=20=208939#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64471

Files:
  cfe/trunk/lib/Sema/SemaStmtAttr.cpp


Index: cfe/trunk/lib/Sema/SemaStmtAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaStmtAttr.cpp
+++ cfe/trunk/lib/Sema/SemaStmtAttr.cpp
@@ -82,22 +82,17 @@
   IdentifierLoc *StateLoc = A.getArgAsIdent(2);
   Expr *ValueExpr = A.getArgAsExpr(3);
 
-  bool PragmaUnroll = PragmaNameLoc->Ident->getName() == "unroll";
-  bool PragmaNoUnroll = PragmaNameLoc->Ident->getName() == "nounroll";
-  bool PragmaUnrollAndJam = PragmaNameLoc->Ident->getName() == 
"unroll_and_jam";
-  bool PragmaNoUnrollAndJam =
-  PragmaNameLoc->Ident->getName() == "nounroll_and_jam";
+  StringRef PragmaName =
+  llvm::StringSwitch(PragmaNameLoc->Ident->getName())
+  .Cases("unroll", "nounroll", "unroll_and_jam", "nounroll_and_jam",
+ PragmaNameLoc->Ident->getName())
+  .Default("clang loop");
+
   if (St->getStmtClass() != Stmt::DoStmtClass &&
   St->getStmtClass() != Stmt::ForStmtClass &&
   St->getStmtClass() != Stmt::CXXForRangeStmtClass &&
   St->getStmtClass() != Stmt::WhileStmtClass) {
-const char *Pragma =
-llvm::StringSwitch(PragmaNameLoc->Ident->getName())
-.Case("unroll", "#pragma unroll")
-.Case("nounroll", "#pragma nounroll")
-.Case("unroll_and_jam", "#pragma unroll_and_jam")
-.Case("nounroll_and_jam", "#pragma nounroll_and_jam")
-.Default("#pragma clang loop");
+std::string Pragma = "#pragma " + std::string(PragmaName);
 S.Diag(St->getBeginLoc(), diag::err_pragma_loop_precedes_nonloop) << 
Pragma;
 return nullptr;
   }
@@ -106,34 +101,29 @@
   LoopHintAttr::Spelling(A.getAttributeSpellingListIndex());
   LoopHintAttr::OptionType Option;
   LoopHintAttr::LoopHintState State;
-  if (PragmaNoUnroll) {
-// #pragma nounroll
-Option = LoopHintAttr::Unroll;
-State = LoopHintAttr::Disable;
-  } else if (PragmaUnroll) {
-if (ValueExpr) {
-  // #pragma unroll N
-  Option = LoopHintAttr::UnrollCount;
-  State = LoopHintAttr::Numeric;
-} else {
-  // #pragma unroll
-  Option = LoopHintAttr::Unroll;
-  State = LoopHintAttr::Enable;
-}
-  } else if (PragmaNoUnrollAndJam) {
-// #pragma nounroll_and_jam
-Option = LoopHintAttr::UnrollAndJam;
-State = LoopHintAttr::Disable;
-  } else if (PragmaUnrollAndJam) {
-if (ValueExpr) {
-  // #pragma unroll_and_jam N
-  Option = LoopHintAttr::UnrollAndJamCount;
-  State = LoopHintAttr::Numeric;
-} else {
-  // #pragma unroll_and_jam
-  Option = LoopHintAttr::UnrollAndJam;
-  State = LoopHintAttr::Enable;
-}
+
+  auto SetHints = [, ](LoopHintAttr::OptionType O,
+LoopHintAttr::LoopHintState S) {
+Option = O;
+State = S;
+  };
+
+  if (PragmaName == "nounroll") {
+SetHints(LoopHintAttr::Unroll, LoopHintAttr::Disable);
+  } else if (PragmaName == "unroll") {
+// #pragma unroll N
+if (ValueExpr)
+  SetHints(LoopHintAttr::UnrollCount, LoopHintAttr::Numeric);
+else
+  SetHints(LoopHintAttr::Unroll, LoopHintAttr::Enable);
+  } else if (PragmaName == "nounroll_and_jam") {
+SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Disable);
+  } else if (PragmaName == "unroll_and_jam") {
+// #pragma unroll_and_jam N
+if (ValueExpr)
+  SetHints(LoopHintAttr::UnrollAndJamCount, LoopHintAttr::Numeric);
+else
+  SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Enable);
   } else {
 // #pragma clang loop ...
 assert(OptionLoc && OptionLoc->Ident &&


Index: cfe/trunk/lib/Sema/SemaStmtAttr.cpp
===
--- cfe/trunk/lib/Sema/SemaStmtAttr.cpp
+++ cfe/trunk/lib/Sema/SemaStmtAttr.cpp
@@ -82,22 +82,17 @@
   IdentifierLoc *StateLoc = A.getArgAsIdent(2);
   Expr *ValueExpr = A.getArgAsExpr(3);
 
-  bool PragmaUnroll = PragmaNameLoc->Ident->getName() == "unroll";
-  bool PragmaNoUnroll = PragmaNameLoc->Ident->getName() == "nounroll";
-  bool PragmaUnrollAndJam = PragmaNameLoc->Ident->getName() == "unroll_and_jam";
-  bool PragmaNoUnrollAndJam =
-  PragmaNameLoc->Ident->getName() == "nounroll_and_jam";
+  StringRef PragmaName =
+  llvm::StringSwitch(PragmaNameLoc->Ident->getName())
+  .Cases("unroll", "nounroll", "unroll_and_jam", "nounroll_and_jam",
+ PragmaNameLoc->Ident->getName())
+  .Default("clang loop");
+
   if (St->getStmtClass() != Stmt::DoStmtClass &&

r365629 - Loop pragma parsing. NFC.

2019-07-10 Thread Sjoerd Meijer via cfe-commits
Author: sjoerdmeijer
Date: Wed Jul 10 06:34:57 2019
New Revision: 365629

URL: http://llvm.org/viewvc/llvm-project?rev=365629=rev
Log:
Loop pragma parsing. NFC.

I would like to add some pragma handling here, but couldn't resist a little NFC
and tidy up first.

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

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

Modified: cfe/trunk/lib/Sema/SemaStmtAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmtAttr.cpp?rev=365629=365628=365629=diff
==
--- cfe/trunk/lib/Sema/SemaStmtAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmtAttr.cpp Wed Jul 10 06:34:57 2019
@@ -82,22 +82,17 @@ static Attr *handleLoopHintAttr(Sema ,
   IdentifierLoc *StateLoc = A.getArgAsIdent(2);
   Expr *ValueExpr = A.getArgAsExpr(3);
 
-  bool PragmaUnroll = PragmaNameLoc->Ident->getName() == "unroll";
-  bool PragmaNoUnroll = PragmaNameLoc->Ident->getName() == "nounroll";
-  bool PragmaUnrollAndJam = PragmaNameLoc->Ident->getName() == 
"unroll_and_jam";
-  bool PragmaNoUnrollAndJam =
-  PragmaNameLoc->Ident->getName() == "nounroll_and_jam";
+  StringRef PragmaName =
+  llvm::StringSwitch(PragmaNameLoc->Ident->getName())
+  .Cases("unroll", "nounroll", "unroll_and_jam", "nounroll_and_jam",
+ PragmaNameLoc->Ident->getName())
+  .Default("clang loop");
+
   if (St->getStmtClass() != Stmt::DoStmtClass &&
   St->getStmtClass() != Stmt::ForStmtClass &&
   St->getStmtClass() != Stmt::CXXForRangeStmtClass &&
   St->getStmtClass() != Stmt::WhileStmtClass) {
-const char *Pragma =
-llvm::StringSwitch(PragmaNameLoc->Ident->getName())
-.Case("unroll", "#pragma unroll")
-.Case("nounroll", "#pragma nounroll")
-.Case("unroll_and_jam", "#pragma unroll_and_jam")
-.Case("nounroll_and_jam", "#pragma nounroll_and_jam")
-.Default("#pragma clang loop");
+std::string Pragma = "#pragma " + std::string(PragmaName);
 S.Diag(St->getBeginLoc(), diag::err_pragma_loop_precedes_nonloop) << 
Pragma;
 return nullptr;
   }
@@ -106,34 +101,29 @@ static Attr *handleLoopHintAttr(Sema ,
   LoopHintAttr::Spelling(A.getAttributeSpellingListIndex());
   LoopHintAttr::OptionType Option;
   LoopHintAttr::LoopHintState State;
-  if (PragmaNoUnroll) {
-// #pragma nounroll
-Option = LoopHintAttr::Unroll;
-State = LoopHintAttr::Disable;
-  } else if (PragmaUnroll) {
-if (ValueExpr) {
-  // #pragma unroll N
-  Option = LoopHintAttr::UnrollCount;
-  State = LoopHintAttr::Numeric;
-} else {
-  // #pragma unroll
-  Option = LoopHintAttr::Unroll;
-  State = LoopHintAttr::Enable;
-}
-  } else if (PragmaNoUnrollAndJam) {
-// #pragma nounroll_and_jam
-Option = LoopHintAttr::UnrollAndJam;
-State = LoopHintAttr::Disable;
-  } else if (PragmaUnrollAndJam) {
-if (ValueExpr) {
-  // #pragma unroll_and_jam N
-  Option = LoopHintAttr::UnrollAndJamCount;
-  State = LoopHintAttr::Numeric;
-} else {
-  // #pragma unroll_and_jam
-  Option = LoopHintAttr::UnrollAndJam;
-  State = LoopHintAttr::Enable;
-}
+
+  auto SetHints = [, ](LoopHintAttr::OptionType O,
+LoopHintAttr::LoopHintState S) {
+Option = O;
+State = S;
+  };
+
+  if (PragmaName == "nounroll") {
+SetHints(LoopHintAttr::Unroll, LoopHintAttr::Disable);
+  } else if (PragmaName == "unroll") {
+// #pragma unroll N
+if (ValueExpr)
+  SetHints(LoopHintAttr::UnrollCount, LoopHintAttr::Numeric);
+else
+  SetHints(LoopHintAttr::Unroll, LoopHintAttr::Enable);
+  } else if (PragmaName == "nounroll_and_jam") {
+SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Disable);
+  } else if (PragmaName == "unroll_and_jam") {
+// #pragma unroll_and_jam N
+if (ValueExpr)
+  SetHints(LoopHintAttr::UnrollAndJamCount, LoopHintAttr::Numeric);
+else
+  SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Enable);
   } else {
 // #pragma clang loop ...
 assert(OptionLoc && OptionLoc->Ident &&


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


[PATCH] D64482: [Driver] Define _FILE_OFFSET_BITS=64 on Solaris

2019-07-10 Thread Rainer Orth via Phabricator via cfe-commits
ro created this revision.
ro added reviewers: fedor.sergeev, rsmith.
ro added a project: clang.

`make check-all` currently fails on `x86_64-pc-solaris2.11` when building with 
GCC 9:

  Undefined   first referenced
   symbol in file
  _ZN11__sanitizer14internal_lseekEimi 
SANITIZER_TEST_OBJECTS.sanitizer_libc_test.cc.i386.o
  _ZN11__sanitizer23MapWritableFileToMemoryEPvmim 
SANITIZER_TEST_OBJECTS.sanitizer_libc_test.cc.i386.o
  ld: fatal: symbol referencing errors
  clang-9: error: linker command failed with exit code 1 (use -v to see 
invocation)
  make[3]: *** 
[projects/compiler-rt/lib/sanitizer_common/tests/CMakeFiles/TSanitizer-i386-Test.dir/build.make:92:
 projects/compiler-rt/lib/sanitizer_common/tests/Sanitizer-i386-Test] Error 1

While e.g. `__sanitizer::internal_lseek` is defined in `sanitizer_solaris.cc`, 
g++ 9
predefines `_FILE_OFFSET_BITS=64` while clang++ currently does not.

This patch resolves this inconsistency by following the gcc lead, which allows
`make check-all` to finish successfully.

There's one caveat: gcc defines `_LARGEFILE_SOURCE` and `_LARGEFILE64_SOURCE` 
for C++ only, while clang has long been doing it for
all languages.  I'd like to keep it this way because those macros do is to make
declarations of `fseek`/`ftello` (`_LARGEFILE_SOURCE`) resp. the 64-bit versions
of largefile functions (`*64` with `_LARGEFILE64_SOURCE`) visible additionally.
However, `_FILE_OFFSET_BITS=64` changes all affected functions to be 
largefile-aware.
I'd like to restrict this to C++, just like gcc does.

To avoid a similar inconsistence with host compilers that don't predefine 
`_FILE_OFFSET_BITS=64`
(e.g. clang < 9, gcc < 9), this needs a compantion patch to be submitted 
shortly.

Tested on `x86_64-pc-solaris2.11`.  Ok for trunk?


Repository:
  rC Clang

https://reviews.llvm.org/D64482

Files:
  lib/Basic/Targets/OSTargets.h


Index: lib/Basic/Targets/OSTargets.h
===
--- lib/Basic/Targets/OSTargets.h
+++ lib/Basic/Targets/OSTargets.h
@@ -618,8 +618,11 @@
   Builder.defineMacro("_XOPEN_SOURCE", "600");
 else
   Builder.defineMacro("_XOPEN_SOURCE", "500");
-if (Opts.CPlusPlus)
+if (Opts.CPlusPlus) {
   Builder.defineMacro("__C99FEATURES__");
+  Builder.defineMacro("_FILE_OFFSET_BITS", "64");
+}
+// GCC restricts the next two to C++.
 Builder.defineMacro("_LARGEFILE_SOURCE");
 Builder.defineMacro("_LARGEFILE64_SOURCE");
 Builder.defineMacro("__EXTENSIONS__");


Index: lib/Basic/Targets/OSTargets.h
===
--- lib/Basic/Targets/OSTargets.h
+++ lib/Basic/Targets/OSTargets.h
@@ -618,8 +618,11 @@
   Builder.defineMacro("_XOPEN_SOURCE", "600");
 else
   Builder.defineMacro("_XOPEN_SOURCE", "500");
-if (Opts.CPlusPlus)
+if (Opts.CPlusPlus) {
   Builder.defineMacro("__C99FEATURES__");
+  Builder.defineMacro("_FILE_OFFSET_BITS", "64");
+}
+// GCC restricts the next two to C++.
 Builder.defineMacro("_LARGEFILE_SOURCE");
 Builder.defineMacro("_LARGEFILE64_SOURCE");
 Builder.defineMacro("__EXTENSIONS__");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63835: [Syntax] Add nodes for most common statements

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



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:185
+/// if (cond)  else 
+class IfStatement final : public Statement {
+public:

sammccall wrote:
> I guess the missing cond here (and similar below) are due to complexities 
> around the variable declaring variants?
> 
> Warrants a FIXME I think
Yes. Added a FIXME



Comment at: clang/include/clang/Tooling/Syntax/Nodes.h:265
+/// return ;
+class ReturnStatement final : public Statement {
+public:

sammccall wrote:
> (any reason we can't already have the expr here?)
Added a getter for it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63835



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


[PATCH] D63835: [Syntax] Add nodes for most common statements

2019-07-10 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 208937.
ilya-biryukov marked 5 inline comments as done.
ilya-biryukov added a comment.

- Rebase
- Address comments
- Restructure the roles
- Remove the role from tree dumps for now With too many roles it is annoying to 
update the test outputs on incremental changes. I tried using the symbolic role 
names there, but they end up being too verbose.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63835

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/lib/Tooling/Syntax/Tree.cpp
  clang/unittests/Tooling/Syntax/TreeTest.cpp

Index: clang/unittests/Tooling/Syntax/TreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -136,19 +136,326 @@
 | |-(
 | |-)
 | `-CompoundStatement
-|   |-2: {
-|   `-3: }
+|   |-{
+|   `-}
 |-TopLevelDeclaration
 | |-void
 | |-foo
 | |-(
 | |-)
 | `-CompoundStatement
-|   |-2: {
-|   `-3: }
+|   |-{
+|   `-}
 `-
 )txt"},
-  };
+  // if.
+  {
+  R"cpp(
+int main() {
+  if (true) {}
+  if (true) {} else if (false) {}
+}
+)cpp",
+  R"txt(
+*: TranslationUnit
+|-TopLevelDeclaration
+| |-int
+| |-main
+| |-(
+| |-)
+| `-CompoundStatement
+|   |-{
+|   |-IfStatement
+|   | |-if
+|   | |-(
+|   | |-UnknownExpression
+|   | | `-true
+|   | |-)
+|   | `-CompoundStatement
+|   |   |-{
+|   |   `-}
+|   |-IfStatement
+|   | |-if
+|   | |-(
+|   | |-UnknownExpression
+|   | | `-true
+|   | |-)
+|   | |-CompoundStatement
+|   | | |-{
+|   | | `-}
+|   | |-else
+|   | `-IfStatement
+|   |   |-if
+|   |   |-(
+|   |   |-UnknownExpression
+|   |   | `-false
+|   |   |-)
+|   |   `-CompoundStatement
+|   | |-{
+|   | `-}
+|   `-}
+`-
+)txt"},
+  // for.
+  {R"cpp(
+void test() {
+  for (;;)  {}
+}
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-TopLevelDeclaration
+| |-void
+| |-test
+| |-(
+| |-)
+| `-CompoundStatement
+|   |-{
+|   |-ForStatement
+|   | |-for
+|   | |-(
+|   | |-;
+|   | |-;
+|   | |-)
+|   | `-CompoundStatement
+|   |   |-{
+|   |   `-}
+|   `-}
+`-
+)txt"},
+  // declaration statement.
+  {"void test() { int a = 10; }",
+   R"txt(
+*: TranslationUnit
+|-TopLevelDeclaration
+| |-void
+| |-test
+| |-(
+| |-)
+| `-CompoundStatement
+|   |-{
+|   |-DeclarationStatement
+|   | |-int
+|   | |-a
+|   | |-=
+|   | |-10
+|   | `-;
+|   `-}
+`-
+)txt"},
+  {"void test() { ; }", R"txt(
+*: TranslationUnit
+|-TopLevelDeclaration
+| |-void
+| |-test
+| |-(
+| |-)
+| `-CompoundStatement
+|   |-{
+|   |-EmptyStatement
+|   | `-;
+|   `-}
+`-
+)txt"},
+  // switch, case and default.
+  {R"cpp(
+void test() {
+  switch (true) {
+case 0:
+default:;
+  }
+}
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-TopLevelDeclaration
+| |-void
+| |-test
+| |-(
+| |-)
+| `-CompoundStatement
+|   |-{
+|   |-SwitchStatement
+|   | |-switch
+|   | |-(
+|   | |-UnknownExpression
+|   | | `-true
+|   | |-)
+|   | `-CompoundStatement
+|   |   |-{
+|   |   |-CaseStatement
+|   |   | |-case
+|   |   | |-UnknownExpression
+|   |   | | `-0
+|   |   | |-:
+|   |   | `-DefaultStatement
+|   |   |   |-default
+|   |   |   |-:
+|   |   |   `-EmptyStatement
+|   |   | `-;
+|   |   `-}
+|   `-}
+`-
+)txt"},
+  // while.
+  {R"cpp(
+void test() {
+  while (true) { continue; break; }
+}
+)cpp",
+   R"txt(
+*: TranslationUnit
+|-TopLevelDeclaration
+| |-void
+| |-test
+| |-(
+| |-)
+| `-CompoundStatement
+|   |-{
+|   |-WhileStatement
+|   | |-while
+|   | |-(
+|   | |-UnknownExpression
+|   | | `-true
+|   | |-)
+|   | `-CompoundStatement
+|   |   |-{
+|   |   |-ContinueStatement
+|   |   | |-continue
+|   |   | `-;
+|   |   |-BreakStatement
+|   |   | |-break
+|   |   | `-;
+|   |   `-}
+|   `-}
+`-
+)txt"},
+  // return.
+  {R"cpp(
+int test() { return 1; }
+  )cpp",
+   R"txt(
+*: TranslationUnit
+|-TopLevelDeclaration
+| |-int
+| |-test
+| |-(
+| |-)
+| `-CompoundStatement
+|   |-{
+|   |-ReturnStatement
+|   | |-return
+|   | |-UnknownExpression
+|   | | `-1
+|   | `-;
+|   `-}
+`-
+   )txt"},
+  // Range-based for.
+  {R"cpp(
+void test() {
+  int a[3];
+  for (int x : a) ;
+}
+  )cpp",
+   R"txt(
+*: TranslationUnit
+|-TopLevelDeclaration
+| |-void
+| |-test
+| |-(
+| |-)
+| `-CompoundStatement
+|   |-{
+|   |-DeclarationStatement
+|   | |-int
+|   | |-a
+|   | |-[
+|   | |-3
+|   | |-]
+|   | `-;
+|   |-RangeBasedForStatement
+|   | |-for
+|   | |-(
+|   | |-int
+|   | |-x
+|   | |-:
+|   | |-UnknownExpression
+|   | | `-a
+|   | |-)
+|   | `-EmptyStatement
+|   |   `-;
+|   `-}
+`-
+   )txt"},
+  // Unhandled statements should end up as 'unknown statement'.
+  // This example uses a 'label statement', which does not yet have a 

[PATCH] D64481: [clangd] Add a flag to clangdServer rename function to control whether we want format the replacements.

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

LGTM with a small NIT.

Was also thinking about adding a test for this, but the amount of work required 
to do so seems to outweigh the usefulness. Therefore seems ok to land without 
the test too.
But up to you.




Comment at: clang-tools-extra/clangd/ClangdServer.h:244
   void rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  Callback> CB);
+  bool WantFormat, Callback> CB);
 

Could you add a short comment mentioning the highlight use-case? (the review 
description seems to be a good fit)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64481



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


[PATCH] D63932: [GlobalDCE] Dead Virtual Function Elimination

2019-07-10 Thread Oliver Stannard (Linaro) via Phabricator via cfe-commits
ostannard added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63932



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


[PATCH] D61749: [clang-tidy] initial version of readability-const-method

2019-07-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp:96
+CheckFactories.registerCheck(
+"readability-static-method");
 CheckFactories.registerCheck(

mgehre wrote:
> aaron.ballman wrote:
> > I'm not super keen on the check name. It's not very descriptive -- does 
> > this operate on static methods, does it make methods static, does it turn 
> > global dynamic initialization into static method initialization?
> > 
> > How about: `readability-convert-functions-to-static` or something more 
> > descriptive of the functionality?
> I agree that we should find a better name. With 
> `readability-convert-functions-to-static`, I miss the difference between 
> adding `static` linkage to a free function versus making a member function 
> static.
> How about `readability-convert-member-functions-to-static` or 
> `readability-convert-method-to-static`?
I think `readability-convert-member-functions-to-static` would be a good name.



Comment at: 
clang-tools-extra/clang-tidy/readability/StaticMethodCheck.cpp:136-149
+  if (Definition->isConst()) {
+// Make sure that we either remove 'const' on both declaration and
+// definition or emit no fix-it at all.
+SourceRange DefConst = getLocationOfConst(Definition->getTypeSourceInfo(),
+   *Result.SourceManager,
+   Result.Context->getLangOpts());
+

mgehre wrote:
> aaron.ballman wrote:
> > `const` isn't the only thing to worry about though, no? You need to handle 
> > things like:
> > ```
> > struct S {
> >   void f() volatile;
> >   void g() &;
> >   void h() &&;
> > };
> > ```
> > Another one I am curious about are computed noexcept specifications and 
> > whether those are handled properly. e.g.,
> > ```
> > struct S {
> >   int i;
> >   void foo(SomeClass C) noexcept(noexcept(C + i));
> > };
> > ```
> I added tests for those cases and disabled fix-it generation for them to keep 
> the code simple (for now).
There's an obscure edge case missing:
```
struct S {
  void f() __restrict;
};
```



Comment at: clang-tools-extra/clang-tidy/readability/StaticMethodCheck.cpp:35-45
+AST_MATCHER(CXXMethodDecl, isConstructor) {
+  return isa(Node);
+}
+
+AST_MATCHER(CXXMethodDecl, isDestructor) {
+  return isa(Node);
+}

Is there a reason we can't use `cxxConstructorDecl()`, `cxxDestructorDecl()`, 
and `cxxConversionDecl()` instead?



Comment at: clang-tools-extra/clang-tidy/readability/StaticMethodCheck.cpp:130
+  StringRef Text = getStringFromRange(SourceMgr, LangOpts, Range);
+  size_t Offset = Text.find("const");
+  if (Offset == StringRef::npos)

What does this do for code like:
```
#define constantly_annoying volatile

struct S {
  void func() constantly_annoying {}
};
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61749



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


[PATCH] D64480: [ASTImporter] Added visibility context check for TypedefNameDecl.

2019-07-10 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp.
Herald added a reviewer: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: clang.
balazske added a parent revision: D64477: [ASTImporter] Using Lang_CXX11 in 
ASTImporterVisibilityTest..
Herald added a subscriber: rnkovacs.

ASTImporter makes now difference between typedefs and type aliases
with same name in different translation units
if these are not visible outside.


Repository:
  rC Clang

https://reviews.llvm.org/D64480

Files:
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterVisibilityTest.cpp

Index: unittests/AST/ASTImporterVisibilityTest.cpp
===
--- unittests/AST/ASTImporterVisibilityTest.cpp
+++ unittests/AST/ASTImporterVisibilityTest.cpp
@@ -39,6 +39,14 @@
   using DeclTy = EnumDecl;
   BindableMatcher operator()() { return enumDecl(hasName("E")); }
 };
+struct GetTypedefPattern {
+  using DeclTy = TypedefDecl;
+  BindableMatcher operator()() { return typedefDecl(hasName("T")); }
+};
+struct GetTypeAliasPattern {
+  using DeclTy = TypeAliasDecl;
+  BindableMatcher operator()() { return typeAliasDecl(hasName("T")); }
+};
 
 // Values for the value-parameterized test fixtures.
 // FunctionDecl:
@@ -55,6 +63,11 @@
 // EnumDecl:
 const auto *ExternE = "enum E {};";
 const auto *AnonE = "namespace { enum E {}; }";
+// TypedefNameDecl:
+auto *ExternTypedef = "typedef int T;";
+auto *AnonTypedef = "namespace { typedef int T; }";
+auto *ExternUsing = "using T = int;";
+auto *AnonUsing = "namespace { using T = int; }";
 
 // First value in tuple: Compile options.
 // Second value in tuple: Source code to be used in the test.
@@ -237,6 +250,8 @@
 using ImportVariablesVisibility = ImportVisibility;
 using ImportClassesVisibility = ImportVisibility;
 using ImportEnumsVisibility = ImportVisibility;
+using ImportTypedefVisibility = ImportVisibility;
+using ImportTypeAliasVisibility = ImportVisibility;
 
 // FunctionDecl.
 TEST_P(ImportFunctionsVisibility, ImportAfter) {
@@ -266,6 +281,19 @@
 TEST_P(ImportEnumsVisibility, ImportAfterImport) {
   TypedTest_ImportAfterImportWithMerge();
 }
+// TypedefNameDecl.
+TEST_P(ImportTypedefVisibility, ImportAfter) {
+  TypedTest_ImportAfterWithMerge();
+}
+TEST_P(ImportTypedefVisibility, ImportAfterImport) {
+  TypedTest_ImportAfterImportWithMerge();
+}
+TEST_P(ImportTypeAliasVisibility, ImportAfter) {
+  TypedTest_ImportAfterWithMerge();
+}
+TEST_P(ImportTypeAliasVisibility, ImportAfterImport) {
+  TypedTest_ImportAfterImportWithMerge();
+}
 
 const bool ExpectLink = true;
 const bool ExpectNotLink = false;
@@ -312,6 +340,24 @@
   std::make_tuple(ExternE, AnonE, ExpectNotLink),
   std::make_tuple(AnonE, ExternE, ExpectNotLink),
   std::make_tuple(AnonE, AnonE, ExpectNotLink))), );
+INSTANTIATE_TEST_CASE_P(
+ParameterizedTests, ImportTypedefVisibility,
+::testing::Combine(
+DefaultTestValuesForRunOptions,
+::testing::Values(
+std::make_tuple(ExternTypedef, ExternTypedef, ExpectLink),
+std::make_tuple(ExternTypedef, AnonTypedef, ExpectNotLink),
+std::make_tuple(AnonTypedef, ExternTypedef, ExpectNotLink),
+std::make_tuple(AnonTypedef, AnonTypedef, ExpectNotLink))), );
+INSTANTIATE_TEST_CASE_P(
+ParameterizedTests, ImportTypeAliasVisibility,
+::testing::Combine(
+DefaultTestValuesForRunOptions,
+::testing::Values(
+std::make_tuple(ExternUsing, ExternUsing, ExpectLink),
+std::make_tuple(ExternUsing, AnonUsing, ExpectNotLink),
+std::make_tuple(AnonUsing, ExternUsing, ExpectNotLink),
+std::make_tuple(AnonUsing, AnonUsing, ExpectNotLink))), );
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -927,6 +927,28 @@
   EllipsisLoc);
 }
 
+template 
+bool ASTNodeImporter::hasSameVisibilityContext(T *Found, T *From) {
+  if (From->hasExternalFormalLinkage())
+return Found->hasExternalFormalLinkage();
+  else if (Importer.GetFromTU(Found) == From->getTranslationUnitDecl()) {
+if (From->isInAnonymousNamespace())
+  return Found->isInAnonymousNamespace();
+else
+  return !Found->isInAnonymousNamespace() &&
+ !Found->hasExternalFormalLinkage();
+  }
+  return false;
+}
+
+template <>
+bool ASTNodeImporter::hasSameVisibilityContext(TypedefNameDecl *Found,
+   TypedefNameDecl *From) {
+  if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
+return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
+  return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
+}
+
 } // 

[PATCH] D64481: [clangd] Add a flag to clangdServer rename function to control whether we want format the replacements.

2019-07-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: sammccall, ilya-biryukov.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay.
Herald added a project: clang.

This would allow clangd embedders to use the ClangdServer::rename for other
purposes (highlighting all the occurrences of the symbol in prepare
stage).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64481

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/ClangdServer.h
  clang-tools-extra/clangd/unittests/SyncAPI.cpp


Index: clang-tools-extra/clangd/unittests/SyncAPI.cpp
===
--- clang-tools-extra/clangd/unittests/SyncAPI.cpp
+++ clang-tools-extra/clangd/unittests/SyncAPI.cpp
@@ -102,7 +102,7 @@
 PathRef File, Position Pos,
 llvm::StringRef NewName) {
   llvm::Optional>> Result;
-  Server.rename(File, Pos, NewName, capture(Result));
+  Server.rename(File, Pos, NewName, /*WantFormat=*/true, capture(Result));
   return std::move(*Result);
 }
 
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -241,7 +241,7 @@
   /// Rename all occurrences of the symbol at the \p Pos in \p File to
   /// \p NewName.
   void rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  Callback> CB);
+  bool WantFormat, Callback> CB);
 
   struct TweakRef {
 std::string ID;/// ID to pass for applyTweak.
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -283,23 +283,25 @@
 }
 
 void ClangdServer::rename(PathRef File, Position Pos, llvm::StringRef NewName,
-  Callback> CB) {
-  auto Action = [Pos, this](Path File, std::string NewName,
-Callback> CB,
-llvm::Expected InpAST) {
+  bool WantFormat, Callback> CB) 
{
+  auto Action = [Pos, WantFormat, this](Path File, std::string NewName,
+Callback> CB,
+llvm::Expected InpAST) {
 if (!InpAST)
   return CB(InpAST.takeError());
 auto Changes = renameWithinFile(InpAST->AST, File, Pos, NewName, Index);
 if (!Changes)
   return CB(Changes.takeError());
 
-auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
-   InpAST->Inputs.FS.get());
-if (auto Formatted =
-cleanupAndFormat(InpAST->Inputs.Contents, *Changes, Style))
-  *Changes = std::move(*Formatted);
-else
-  elog("Failed to format replacements: {0}", Formatted.takeError());
+if (WantFormat) {
+  auto Style = getFormatStyleForFile(File, InpAST->Inputs.Contents,
+ InpAST->Inputs.FS.get());
+  if (auto Formatted =
+  cleanupAndFormat(InpAST->Inputs.Contents, *Changes, Style))
+*Changes = std::move(*Formatted);
+  else
+elog("Failed to format replacements: {0}", Formatted.takeError());
+}
 
 std::vector Edits;
 for (const auto  : *Changes)
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -577,7 +577,7 @@
 "onRename called for non-added file", ErrorCode::InvalidParams));
 
   Server->rename(
-  File, Params.position, Params.newName,
+  File, Params.position, Params.newName, /*WantFormat=*/true,
   Bind(
   [File, Code, Params](decltype(Reply) Reply,
llvm::Expected> Edits) {


Index: clang-tools-extra/clangd/unittests/SyncAPI.cpp
===
--- clang-tools-extra/clangd/unittests/SyncAPI.cpp
+++ clang-tools-extra/clangd/unittests/SyncAPI.cpp
@@ -102,7 +102,7 @@
 PathRef File, Position Pos,
 llvm::StringRef NewName) {
   llvm::Optional>> Result;
-  Server.rename(File, Pos, NewName, capture(Result));
+  Server.rename(File, Pos, NewName, /*WantFormat=*/true, capture(Result));
   return std::move(*Result);
 }
 
Index: clang-tools-extra/clangd/ClangdServer.h
===
--- clang-tools-extra/clangd/ClangdServer.h
+++ clang-tools-extra/clangd/ClangdServer.h
@@ -241,7 +241,7 @@
   /// Rename all occurrences of the symbol at the \p Pos in \p File to
   /// \p NewName.
   

[PATCH] D63954: Add lifetime categories attributes

2019-07-10 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:2770
+def Owner : InheritableAttr {
+  let Spellings = [CXX11<"gsl", "Owner">];
+  let Subjects = SubjectList<[CXXRecord]>;

xazax.hun wrote:
> aaron.ballman wrote:
> > Has Microsoft already added support for this? We had an unfortunate problem 
> > with `gsl::suppress` where we introduced the attribute first and MSVC 
> > introduced it under a different, incompatible syntax. I would strongly like 
> > to avoid repeating that.
> I will double check this. Her Sutter's paper have this spelling and I believe 
> that the Microsoft implementation is following the same spelling. The main 
> difference is that the MSVC version does not have a type argument at this 
> point but they do plan to add it as an optional argument. (They want to infer 
> the pointee type when it is not provided.) The clang community do not want 
> the inference, hence we made the type argument required. Always providing the 
> type argument should be compatible with future versions of the MSVC 
> implementation.
I take this to mean that we're not implementing the same attribute as MSVC is, 
and that worries me.

> Always providing the type argument should be compatible with future versions 
> of the MSVC implementation.

The problem is that code written for MSVC (where the type argument is not 
required) will not compile with Clang (where the type argument is required), if 
I understand properly.

Generally speaking, when we implement an attribute from another vendor 
namespace, we expect the attribute to have the same semantics as whoever "owns" 
that vendor namespace. It's a bit trickier here because `gsl` isn't really a 
vendor so much as a collective, so I don't know who is the authority to turn to.

On a completely different note: would this attribute also make sense within C 
with a C2x spelling?



Comment at: clang/lib/Parse/ParseDecl.cpp:335-341
+  if (attributeIsTypeArgAttr(*AttrName)) {
+ParseAttributeWithTypeArg(*AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName,
+  ScopeLoc, Syntax);
+// FIXME: when attributeIsTypeArgAttr() is true, assumes that the attribute
+// takes a single parameter.
+return 1;
+  }

I don't like how this short-circuits the remainder of the logic in this 
function. I'd rather see this one-off logic handled in 
`ParseClangAttributeArgs()` if we have to treat it as a one-off. A better 
approach would be to implement type arguments within 
`ParseAttributeArgsCommon()`.



Comment at: clang/lib/Sema/SemaDecl.cpp:2618-2619
+} else if (isa(NewAttribute) || isa(NewAttribute)) 
{
+  // gsl::Owner and gsl::Pointer are allowed to be added to a class after 
it
+  // is defined.
+  ++I;

I'd like to see some tests for this.

I'm a bit worried about whether this will do good things in practice or not. 
I'm concerned about situations like:
```
struct S;

void func(S *s) {
  // Interesting things happen here.
}

struct [[gsl::Pointer]] S {};
```
and whether the "interesting things" will be properly [un]diagnosed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63954



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


[PATCH] D64477: [ASTImporter] Using Lang_CXX11 in ASTImporterVisibilityTest.

2019-07-10 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp.
Herald added a reviewer: martong.
Herald added a reviewer: a.sidorin.
Herald added a project: clang.

These tests may work with language constructs in C++11 in the future.
To avoid warnings about language version C++ version constants in the tests
are updated.


Repository:
  rC Clang

https://reviews.llvm.org/D64477

Files:
  unittests/AST/ASTImporterVisibilityTest.cpp


Index: unittests/AST/ASTImporterVisibilityTest.cpp
===
--- unittests/AST/ASTImporterVisibilityTest.cpp
+++ unittests/AST/ASTImporterVisibilityTest.cpp
@@ -80,13 +80,13 @@
 std::string Code = getCode() + getCode();
 auto Pattern = getPattern();
 
-TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX, "input0.cc");
+TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX11, "input0.cc");
 
 auto *FromD0 = FirstDeclMatcher().match(FromTu, Pattern);
 auto *FromD1 = LastDeclMatcher().match(FromTu, Pattern);
 
-auto *ToD0 = Import(FromD0, Lang_CXX);
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD0 = Import(FromD0, Lang_CXX11);
+auto *ToD1 = Import(FromD1, Lang_CXX11);
 
 EXPECT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
@@ -157,13 +157,14 @@
   BindableMatcher getPattern() const { return PatternFactory()(); }
 
   void TypedTest_ImportAfter() {
-TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX);
-TranslationUnitDecl *FromTu = getTuDecl(getCode1(), Lang_CXX, "input1.cc");
+TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX11);
+TranslationUnitDecl *FromTu =
+getTuDecl(getCode1(), Lang_CXX11, "input1.cc");
 
 auto *ToD0 = FirstDeclMatcher().match(ToTu, getPattern());
 auto *FromD1 = FirstDeclMatcher().match(FromTu, getPattern());
 
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD1 = Import(FromD1, Lang_CXX11);
 
 ASSERT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
@@ -176,12 +177,14 @@
   }
 
   void TypedTest_ImportAfterImport() {
-TranslationUnitDecl *FromTu0 = getTuDecl(getCode0(), Lang_CXX, 
"input0.cc");
-TranslationUnitDecl *FromTu1 = getTuDecl(getCode1(), Lang_CXX, 
"input1.cc");
+TranslationUnitDecl *FromTu0 =
+getTuDecl(getCode0(), Lang_CXX11, "input0.cc");
+TranslationUnitDecl *FromTu1 =
+getTuDecl(getCode1(), Lang_CXX11, "input1.cc");
 auto *FromD0 = FirstDeclMatcher().match(FromTu0, getPattern());
 auto *FromD1 = FirstDeclMatcher().match(FromTu1, getPattern());
-auto *ToD0 = Import(FromD0, Lang_CXX);
-auto *ToD1 = Import(FromD1, Lang_CXX);
+auto *ToD0 = Import(FromD0, Lang_CXX11);
+auto *ToD1 = Import(FromD1, Lang_CXX11);
 ASSERT_TRUE(ToD0);
 ASSERT_TRUE(ToD1);
 EXPECT_NE(ToD0, ToD1);
@@ -192,13 +195,14 @@
   }
 
   void TypedTest_ImportAfterWithMerge() {
-TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX);
-TranslationUnitDecl *FromTu = getTuDecl(getCode1(), Lang_CXX, "input1.cc");
+TranslationUnitDecl *ToTu = getToTuDecl(getCode0(), Lang_CXX11);
+TranslationUnitDecl *FromTu =
+getTuDecl(getCode1(), Lang_CXX11, "input1.cc");
 
 auto *ToF0 = FirstDeclMatcher().match(ToTu, getPattern());
 auto *FromF1 = FirstDeclMatcher().match(FromTu, getPattern());
 
-auto *ToF1 = Import(FromF1, Lang_CXX);
+auto *ToF1 = Import(FromF1, Lang_CXX11);
 
 ASSERT_TRUE(ToF0);
 ASSERT_TRUE(ToF1);
@@ -213,12 +217,14 @@
   }
 
   void TypedTest_ImportAfterImportWithMerge() {
-TranslationUnitDecl *FromTu0 = getTuDecl(getCode0(), Lang_CXX, 
"input0.cc");
-TranslationUnitDecl *FromTu1 = getTuDecl(getCode1(), Lang_CXX, 
"input1.cc");
+TranslationUnitDecl *FromTu0 =
+getTuDecl(getCode0(), Lang_CXX11, "input0.cc");
+TranslationUnitDecl *FromTu1 =
+getTuDecl(getCode1(), Lang_CXX11, "input1.cc");
 auto *FromF0 = FirstDeclMatcher().match(FromTu0, getPattern());
 auto *FromF1 = FirstDeclMatcher().match(FromTu1, getPattern());
-auto *ToF0 = Import(FromF0, Lang_CXX);
-auto *ToF1 = Import(FromF1, Lang_CXX);
+auto *ToF0 = Import(FromF0, Lang_CXX11);
+auto *ToF1 = Import(FromF1, Lang_CXX11);
 ASSERT_TRUE(ToF0);
 ASSERT_TRUE(ToF1);
 if (shouldBeLinked())


Index: unittests/AST/ASTImporterVisibilityTest.cpp
===
--- unittests/AST/ASTImporterVisibilityTest.cpp
+++ unittests/AST/ASTImporterVisibilityTest.cpp
@@ -80,13 +80,13 @@
 std::string Code = getCode() + getCode();
 auto Pattern = getPattern();
 
-TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX, "input0.cc");
+TranslationUnitDecl *FromTu = getTuDecl(Code, Lang_CXX11, "input0.cc");
 
 auto *FromD0 = FirstDeclMatcher().match(FromTu, Pattern);
 auto *FromD1 = LastDeclMatcher().match(FromTu, Pattern);
 
-auto *ToD0 = Import(FromD0, Lang_CXX);
-auto *ToD1 = Import(FromD1, 

[PATCH] D64083: [OpenCL][Sema] Improve address space support for blocks

2019-07-10 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: cfe/trunk/lib/Sema/SemaExprCXX.cpp:4229
+LangAS AddrSpaceR =
+RHSType->getAs()->getPointeeType().getAddressSpace();
+CastKind Kind =

rjmccall wrote:
> All of this can be much simpler:
> 
> ```
> LangAS AddrSpaceL = 
> ToType->castAs()->getPointeeType().getAddressSpace();
> LangAS AddrSpaceR = 
> FromType->castAs()->getPointeeType().getAddressSpace();
> ```
> 
> Is there something actually checking the validity of this address-space cast 
> somewhere?
> Is there something actually checking the validity of this address-space cast 
> somewhere?

The address spaces for blocks are currently added by clang implicitly. It 
doesn't seem possible to write kernel code qualifying blocks with address 
spaces. Although I have to say the error is not given properly because the 
parser gets confused at least for the examples I have tried. The OpenCL spec 
doesn't detail much regarding this use case. Potentially this is the area for 
improvement.

So for now we can add an assert to check the cast validity if you think it 
makes sense and maybe a FIXME in the  code to explain that address spaces 
aren't working with blocks


Repository:
  rL LLVM

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

https://reviews.llvm.org/D64083



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


[PATCH] D62855: [clangd] Implementation of auto type expansion.

2019-07-10 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 208923.
kuhnel marked 13 inline comments as done.
kuhnel added a comment.

fixed parts of the 3rd round of review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D62855

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/Selection.h
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/test/code-action-request.test
  clang-tools-extra/clangd/unittests/ASTTests.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/TweakTests.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2108,6 +2108,28 @@
   }
 }
 
+TEST(GetDeducedType, KwAutoExpansion) {
+  struct Test {
+StringRef AnnotatedCode;
+const char *DeducedType;
+  } Tests[] = {
+  {"^auto i = 0;", "int"},
+  {"^auto f(){ return 1;};", "int"}
+  };
+  for (Test T : Tests) {
+Annotations File(T.AnnotatedCode);
+auto AST = TestTU::withCode(File.code()).build();
+ASSERT_TRUE(AST.getDiagnostics().empty()) << AST.getDiagnostics().begin()->Message;
+SourceManagerForFile SM("foo.cpp", File.code());
+
+for (Position Pos : File.points()) {
+  auto Location = sourceLocationInMainFile(SM.get(), Pos);
+  auto DeducedType = getDeducedType(AST, *Location);
+  EXPECT_EQ(DeducedType->getAsString(), T.DeducedType);
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -11,6 +11,7 @@
 #include "TestTU.h"
 #include "refactor/Tweak.h"
 #include "clang/AST/Expr.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/StringRef.h"
@@ -126,6 +127,19 @@
   EXPECT_EQ(Output, std::string(*Result)) << Input;
 }
 
+/// Check if apply returns an error and that the @ErrorMessage is contained
+/// in that error
+void checkApplyContainsError(llvm::StringRef ID, llvm::StringRef Input,
+ const std::string& ErrorMessage) {
+  auto Result = apply(ID, Input);
+  EXPECT_FALSE(Result) << "expected error message:\n   " << ErrorMessage <<
+   "\non input:" << Input;
+  EXPECT_NE(std::string::npos,
+llvm::toString(Result.takeError()).find(ErrorMessage))
+<< "Wrong error message:\n  " << llvm::toString(Result.takeError())
+<< "\nexpected:\n  " << ErrorMessage;
+}
+
 TEST(TweakTest, SwapIfBranches) {
   llvm::StringLiteral ID = "SwapIfBranches";
 
@@ -509,6 +523,132 @@
   )cpp");
 }
 
+TEST(TweakTest, ExpandAutoType) {
+  llvm::StringLiteral ID = "ExpandAutoType";
+
+  checkAvailable(ID, R"cpp(
+^a^u^t^o^ i = 0;
+  )cpp");
+
+  checkNotAvailable(ID, R"cpp(
+auto ^i^ ^=^ ^0^;^
+  )cpp");
+
+  llvm::StringLiteral Input = R"cpp(
+[[auto]] i = 0;
+  )cpp";
+  llvm::StringLiteral Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check primitive type
+  Input = R"cpp(
+au^to i = 0;
+  )cpp";
+  Output = R"cpp(
+int i = 0;
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check classes and namespaces
+  Input = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+^auto C = testns::TestClass::SubClass();
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+  class TestClass {
+class SubClass {};
+  };
+}
+testns::TestClass::SubClass C = testns::TestClass::SubClass();
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // check that namespaces are shortened
+  Input = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { ^auto C = TestClass(); }
+}
+  )cpp";
+  Output = R"cpp(
+namespace testns {
+class TestClass {
+};
+void func() { TestClass C = TestClass(); }
+}
+  )cpp";
+  checkTransform(ID, Input, Output);
+
+  // unknown types in a template should not be replaced
+  Input = R"cpp(
+template  void x() {
+^auto y =  T::z();
+}
+  )cpp";
+  checkApplyContainsError(ID, Input, "Could not deduce type for 'auto' type");
+
+  // undefined functions should not be replaced
+  Input = R"cpp(
+a^uto x = doesnt_exist();
+  )cpp";
+  checkApplyContainsError(ID, Input, "Could not 

[PATCH] D64471: Loop pragma parsing. NFC.

2019-07-10 Thread Sam Parker via Phabricator via cfe-commits
samparker accepted this revision.
samparker added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D64471



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


[PATCH] D64475: [clangd] Duplicate lines of semantic highlightings sent removed.

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

Added a class for diffing highlightings and removing duplicate lines. 
Integrated into the highlighting generation flow. Only works correctly if all 
tokens are on a single line. Also returns empty lines if the IDE should remove 
previous highlightings on a line.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64475

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/SemanticHighlighting.h
  clang-tools-extra/clangd/test/semantic-highlighting.test
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -29,14 +29,17 @@
   return Tokens;
 }
 
-void checkHighlightings(llvm::StringRef Code) {
+std::tuple,
+   std::vector>
+getHighlightingsAnnotated(llvm::StringRef Code) {
   Annotations Test(Code);
   auto AST = TestTU::withCode(Test.code()).build();
   static const std::map KindToString{
   {HighlightingKind::Variable, "Variable"},
   {HighlightingKind::Function, "Function"},
   {HighlightingKind::Class, "Class"},
-  {HighlightingKind::Enum, "Enum"}};
+  {HighlightingKind::Enum, "Enum"},
+  {HighlightingKind::Empty, "Empty"}};
   std::vector ExpectedTokens;
   for (const auto  : KindToString) {
 std::vector Toks = makeHighlightingTokens(
@@ -45,6 +48,14 @@
   }
 
   auto ActualTokens = getSemanticHighlightings(AST);
+  return {std::move(AST), ActualTokens, ExpectedTokens};
+}
+
+void checkHighlightings(llvm::StringRef Code) {
+  std::vector ActualTokens;
+  std::vector ExpectedTokens;
+  std::tie(std::ignore, ActualTokens, ExpectedTokens) =
+  getHighlightingsAnnotated(Code);
   EXPECT_THAT(ActualTokens, testing::UnorderedElementsAreArray(ExpectedTokens));
 }
 
@@ -161,6 +172,68 @@
   EXPECT_EQ(ActualResults, ExpectedResults);
 }
 
+TEST(SemanticHighlighting, HighlightingDiffer) {
+  std::vector> TestCases{{
+   R"cpp(
+struct $Class[[Alpha]] {
+  double SomeVariable = 9483.301;
+};
+struct $Class[[Beta]] {};
+int $Variable[[A]] = 121;
+$Class[[Alpha]] $Variable[[Var]];
+  )cpp",
+   R"cpp(
+struct Alpha {
+  double SomeVariable = 9483.301;
+};
+struct Beta   {}; // Some changes that don't change the tokens' position.
+intA$Empty[[]] = 121;
+$Class[[Beta]] $Variable[[Var]];
+  )cpp"},
+   {
+   R"cpp(
+  int $Variable[[A]] = 121; int $Variable[[B]];
+)cpp",
+   R"cpp(
+  intA = 121; int $Variable[[B]];
+)cpp"},
+   {
+   R"cpp(
+  int $Variable[[A]] = 213;
+)cpp",
+   R"cpp(
+  int C = 312;
+  int $Variable[[B]] = 213;
+)cpp",
+   R"cpp(
+  int C = 213;
+  int B = 412;
+)cpp"},
+   {
+   R"cpp(
+  int $Variable[[A]];
+)cpp",
+   R"cpp(
+  int $Variable[[A]]; int $Variable[[B]];
+)cpp"}};
+
+  for (auto Test : TestCases) {
+HighlightingDiffer Differ;
+for (const auto  : Test) {
+  ParsedAST AST =
+  TestTU::withCode("").build(); // Can't default construct a ParsedAST.
+  std::vector CompleteTokens;
+  std::vector ExpectedTokens;
+  std::tie(AST, CompleteTokens, ExpectedTokens) =
+  getHighlightingsAnnotated(Code);
+  std::vector DiffedTokens =
+  Differ.diffHighlightings(AST, CompleteTokens);
+  EXPECT_THAT(DiffedTokens,
+  testing::UnorderedElementsAreArray(ExpectedTokens));
+}
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/test/semantic-highlighting.test
===
--- clang-tools-extra/clangd/test/semantic-highlighting.test
+++ clang-tools-extra/clangd/test/semantic-highlighting.test
@@ -34,6 +34,21 @@
 # CHECK-NEXT:  }
 # CHECK-NEXT:}
 ---

[PATCH] D64211: [AArch64] Fix vector vuqadd intrinsics operands

2019-07-10 Thread Diogo N. Sampaio via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365609: [AArch64] Fix vector vuqadd intrinsics operands 
(authored by dnsampaio, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64211

Files:
  cfe/trunk/include/clang/Basic/arm_neon.td
  cfe/trunk/test/CodeGen/aarch64-neon-intrinsics.c


Index: cfe/trunk/include/clang/Basic/arm_neon.td
===
--- cfe/trunk/include/clang/Basic/arm_neon.td
+++ cfe/trunk/include/clang/Basic/arm_neon.td
@@ -703,7 +703,7 @@
 
 

 // Signed Saturating Accumulated of Unsigned Value
-def SUQADD : SInst<"vuqadd", "ddd", "csilQcQsQiQl">;
+def SUQADD : SInst<"vuqadd", "ddu", "csilQcQsQiQl">;
 
 

 // Unsigned Saturating Accumulated of Signed Value
Index: cfe/trunk/test/CodeGen/aarch64-neon-intrinsics.c
===
--- cfe/trunk/test/CodeGen/aarch64-neon-intrinsics.c
+++ cfe/trunk/test/CodeGen/aarch64-neon-intrinsics.c
@@ -17528,6 +17528,50 @@
   return vabdd_f64(a, b);
 }
 
+// CHECK-LABEL: @test_vuqaddq_s8(
+// CHECK: entry:
+// CHECK-NEXT:  [[V:%.*]] = call <16 x i8> @llvm.aarch64.neon.suqadd.v16i8(<16 
x i8> %a, <16 x i8> %b)
+// CHECK-NEXT:  ret <16 x i8> [[V]]
+int8x16_t test_vuqaddq_s8(int8x16_t a, uint8x16_t b) {
+  return vuqaddq_s8(a, b);
+}
+
+// CHECK-LABEL: @test_vuqaddq_s32(
+// CHECK: [[V:%.*]] = call <4 x i32> @llvm.aarch64.neon.suqadd.v4i32(<4 x i32> 
%a, <4 x i32> %b)
+// CHECK-NEXT:  ret <4 x i32> [[V]]
+int32x4_t test_vuqaddq_s32(int32x4_t a, uint32x4_t b) {
+  return vuqaddq_s32(a, b);
+}
+
+// CHECK-LABEL: @test_vuqaddq_s64(
+// CHECK: [[V:%.*]] = call <2 x i64> @llvm.aarch64.neon.suqadd.v2i64(<2 x i64> 
%a, <2 x i64> %b)
+// CHECK-NEXT:  ret <2 x i64> [[V]]
+int64x2_t test_vuqaddq_s64(int64x2_t a, uint64x2_t b) {
+  return vuqaddq_s64(a, b);
+}
+
+// CHECK-LABEL: @test_vuqaddq_s16(
+// CHECK: [[V:%.*]] = call <8 x i16> @llvm.aarch64.neon.suqadd.v8i16(<8 x i16> 
%a, <8 x i16> %b)
+// CHECK-NEXT:  ret <8 x i16> [[V]]
+int16x8_t test_vuqaddq_s16(int16x8_t a, uint16x8_t b) {
+  return vuqaddq_s16(a, b);
+}
+
+// CHECK-LABEL: @test_vuqadd_s8(
+// CHECK: entry:
+// CHECK-NEXT: [[V:%.*]] = call <8 x i8> @llvm.aarch64.neon.suqadd.v8i8(<8 x 
i8> %a, <8 x i8> %b)
+// CHECK-NEXT: ret <8 x i8> [[V]]
+int8x8_t test_vuqadd_s8(int8x8_t a, uint8x8_t b) {
+  return vuqadd_s8(a, b);
+}
+
+// CHECK-LABEL: @test_vuqadd_s32(
+// CHECK: [[V:%.*]] = call <2 x i32> @llvm.aarch64.neon.suqadd.v2i32(<2 x i32> 
%a, <2 x i32> %b)
+// CHECK-NEXT:  ret <2 x i32> [[V]]
+int32x2_t test_vuqadd_s32(int32x2_t a, uint32x2_t b) {
+  return vuqadd_s32(a, b);
+}
+
 // CHECK-LABEL: @test_vuqadd_s64(
 // CHECK:   [[TMP0:%.*]] = bitcast <1 x i64> %a to <8 x i8>
 // CHECK:   [[TMP1:%.*]] = bitcast <1 x i64> %b to <8 x i8>
@@ -17537,6 +17581,13 @@
   return vuqadd_s64(a, b);
 }
 
+// CHECK-LABEL: @test_vuqadd_s16(
+// CHECK: [[V:%.*]] = call <4 x i16> @llvm.aarch64.neon.suqadd.v4i16(<4 x i16> 
%a, <4 x i16> %b)
+// CHECK-NEXT:  ret <4 x i16> [[V]]
+int16x4_t test_vuqadd_s16(int16x4_t a, uint16x4_t b) {
+  return vuqadd_s16(a, b);
+}
+
 // CHECK-LABEL: @test_vsqadd_u64(
 // CHECK:   [[TMP0:%.*]] = bitcast <1 x i64> %a to <8 x i8>
 // CHECK:   [[TMP1:%.*]] = bitcast <1 x i64> %b to <8 x i8>


Index: cfe/trunk/include/clang/Basic/arm_neon.td
===
--- cfe/trunk/include/clang/Basic/arm_neon.td
+++ cfe/trunk/include/clang/Basic/arm_neon.td
@@ -703,7 +703,7 @@
 
 
 // Signed Saturating Accumulated of Unsigned Value
-def SUQADD : SInst<"vuqadd", "ddd", "csilQcQsQiQl">;
+def SUQADD : SInst<"vuqadd", "ddu", "csilQcQsQiQl">;
 
 
 // Unsigned Saturating Accumulated of Signed Value
Index: cfe/trunk/test/CodeGen/aarch64-neon-intrinsics.c
===
--- cfe/trunk/test/CodeGen/aarch64-neon-intrinsics.c
+++ cfe/trunk/test/CodeGen/aarch64-neon-intrinsics.c
@@ -17528,6 +17528,50 @@
   return vabdd_f64(a, b);
 }
 
+// CHECK-LABEL: @test_vuqaddq_s8(
+// CHECK: entry:
+// CHECK-NEXT:  [[V:%.*]] = call <16 x i8> @llvm.aarch64.neon.suqadd.v16i8(<16 x i8> %a, <16 x i8> %b)
+// CHECK-NEXT:  ret <16 x i8> [[V]]
+int8x16_t test_vuqaddq_s8(int8x16_t a, uint8x16_t b) {
+  return vuqaddq_s8(a, b);
+}
+
+// CHECK-LABEL: @test_vuqaddq_s32(
+// CHECK: [[V:%.*]] = call <4 x i32> @llvm.aarch64.neon.suqadd.v4i32(<4 x i32> %a, <4 x i32> %b)
+// CHECK-NEXT:  ret <4 x i32> [[V]]
+int32x4_t 

[PATCH] D64210: [NFC][AArch64] Fix vector vsqadd intrinsics operands

2019-07-10 Thread Diogo N. Sampaio via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365608: [NFC][AArch64] Fix vector vsqadd intrinsics operands 
(authored by dnsampaio, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64210

Files:
  cfe/trunk/include/clang/Basic/arm_neon.td


Index: cfe/trunk/include/clang/Basic/arm_neon.td
===
--- cfe/trunk/include/clang/Basic/arm_neon.td
+++ cfe/trunk/include/clang/Basic/arm_neon.td
@@ -707,7 +707,7 @@
 
 

 // Unsigned Saturating Accumulated of Signed Value
-def USQADD : SInst<"vsqadd", "ddd", "UcUsUiUlQUcQUsQUiQUl">;
+def USQADD : SInst<"vsqadd", "ddx", "UcUsUiUlQUcQUsQUiQUl">;
 
 

 // Reciprocal/Sqrt


Index: cfe/trunk/include/clang/Basic/arm_neon.td
===
--- cfe/trunk/include/clang/Basic/arm_neon.td
+++ cfe/trunk/include/clang/Basic/arm_neon.td
@@ -707,7 +707,7 @@
 
 
 // Unsigned Saturating Accumulated of Signed Value
-def USQADD : SInst<"vsqadd", "ddd", "UcUsUiUlQUcQUsQUiQUl">;
+def USQADD : SInst<"vsqadd", "ddx", "UcUsUiUlQUcQUsQUiQUl">;
 
 
 // Reciprocal/Sqrt
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r365609 - [AArch64] Fix vector vuqadd intrinsics operands

2019-07-10 Thread Diogo N. Sampaio via cfe-commits
Author: dnsampaio
Date: Wed Jul 10 02:58:51 2019
New Revision: 365609

URL: http://llvm.org/viewvc/llvm-project?rev=365609=rev
Log:
[AArch64] Fix vector vuqadd intrinsics operands

Summary:
Change the vuqadd vector instrinsics to have the second argument as unsigned 
values, not signed,
accordingly to 
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics

Reviewers: LukeCheeseman, ostannard

Reviewed By: ostannard

Subscribers: javed.absar, kristof.beyls, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Basic/arm_neon.td
cfe/trunk/test/CodeGen/aarch64-neon-intrinsics.c

Modified: cfe/trunk/include/clang/Basic/arm_neon.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/arm_neon.td?rev=365609=365608=365609=diff
==
--- cfe/trunk/include/clang/Basic/arm_neon.td (original)
+++ cfe/trunk/include/clang/Basic/arm_neon.td Wed Jul 10 02:58:51 2019
@@ -703,7 +703,7 @@ def QNEG   : SInst<"vqneg", "dd", "lQl">
 
 

 // Signed Saturating Accumulated of Unsigned Value
-def SUQADD : SInst<"vuqadd", "ddd", "csilQcQsQiQl">;
+def SUQADD : SInst<"vuqadd", "ddu", "csilQcQsQiQl">;
 
 

 // Unsigned Saturating Accumulated of Signed Value

Modified: cfe/trunk/test/CodeGen/aarch64-neon-intrinsics.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/aarch64-neon-intrinsics.c?rev=365609=365608=365609=diff
==
--- cfe/trunk/test/CodeGen/aarch64-neon-intrinsics.c (original)
+++ cfe/trunk/test/CodeGen/aarch64-neon-intrinsics.c Wed Jul 10 02:58:51 2019
@@ -17528,6 +17528,50 @@ float64_t test_vabdd_f64(float64_t a, fl
   return vabdd_f64(a, b);
 }
 
+// CHECK-LABEL: @test_vuqaddq_s8(
+// CHECK: entry:
+// CHECK-NEXT:  [[V:%.*]] = call <16 x i8> @llvm.aarch64.neon.suqadd.v16i8(<16 
x i8> %a, <16 x i8> %b)
+// CHECK-NEXT:  ret <16 x i8> [[V]]
+int8x16_t test_vuqaddq_s8(int8x16_t a, uint8x16_t b) {
+  return vuqaddq_s8(a, b);
+}
+
+// CHECK-LABEL: @test_vuqaddq_s32(
+// CHECK: [[V:%.*]] = call <4 x i32> @llvm.aarch64.neon.suqadd.v4i32(<4 x i32> 
%a, <4 x i32> %b)
+// CHECK-NEXT:  ret <4 x i32> [[V]]
+int32x4_t test_vuqaddq_s32(int32x4_t a, uint32x4_t b) {
+  return vuqaddq_s32(a, b);
+}
+
+// CHECK-LABEL: @test_vuqaddq_s64(
+// CHECK: [[V:%.*]] = call <2 x i64> @llvm.aarch64.neon.suqadd.v2i64(<2 x i64> 
%a, <2 x i64> %b)
+// CHECK-NEXT:  ret <2 x i64> [[V]]
+int64x2_t test_vuqaddq_s64(int64x2_t a, uint64x2_t b) {
+  return vuqaddq_s64(a, b);
+}
+
+// CHECK-LABEL: @test_vuqaddq_s16(
+// CHECK: [[V:%.*]] = call <8 x i16> @llvm.aarch64.neon.suqadd.v8i16(<8 x i16> 
%a, <8 x i16> %b)
+// CHECK-NEXT:  ret <8 x i16> [[V]]
+int16x8_t test_vuqaddq_s16(int16x8_t a, uint16x8_t b) {
+  return vuqaddq_s16(a, b);
+}
+
+// CHECK-LABEL: @test_vuqadd_s8(
+// CHECK: entry:
+// CHECK-NEXT: [[V:%.*]] = call <8 x i8> @llvm.aarch64.neon.suqadd.v8i8(<8 x 
i8> %a, <8 x i8> %b)
+// CHECK-NEXT: ret <8 x i8> [[V]]
+int8x8_t test_vuqadd_s8(int8x8_t a, uint8x8_t b) {
+  return vuqadd_s8(a, b);
+}
+
+// CHECK-LABEL: @test_vuqadd_s32(
+// CHECK: [[V:%.*]] = call <2 x i32> @llvm.aarch64.neon.suqadd.v2i32(<2 x i32> 
%a, <2 x i32> %b)
+// CHECK-NEXT:  ret <2 x i32> [[V]]
+int32x2_t test_vuqadd_s32(int32x2_t a, uint32x2_t b) {
+  return vuqadd_s32(a, b);
+}
+
 // CHECK-LABEL: @test_vuqadd_s64(
 // CHECK:   [[TMP0:%.*]] = bitcast <1 x i64> %a to <8 x i8>
 // CHECK:   [[TMP1:%.*]] = bitcast <1 x i64> %b to <8 x i8>
@@ -17537,6 +17581,13 @@ int64x1_t test_vuqadd_s64(int64x1_t a, u
   return vuqadd_s64(a, b);
 }
 
+// CHECK-LABEL: @test_vuqadd_s16(
+// CHECK: [[V:%.*]] = call <4 x i16> @llvm.aarch64.neon.suqadd.v4i16(<4 x i16> 
%a, <4 x i16> %b)
+// CHECK-NEXT:  ret <4 x i16> [[V]]
+int16x4_t test_vuqadd_s16(int16x4_t a, uint16x4_t b) {
+  return vuqadd_s16(a, b);
+}
+
 // CHECK-LABEL: @test_vsqadd_u64(
 // CHECK:   [[TMP0:%.*]] = bitcast <1 x i64> %a to <8 x i8>
 // CHECK:   [[TMP1:%.*]] = bitcast <1 x i64> %b to <8 x i8>


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


r365608 - [NFC][AArch64] Fix vector vsqadd intrinsics operands

2019-07-10 Thread Diogo N. Sampaio via cfe-commits
Author: dnsampaio
Date: Wed Jul 10 02:58:03 2019
New Revision: 365608

URL: http://llvm.org/viewvc/llvm-project?rev=365608=rev
Log:
[NFC][AArch64] Fix vector vsqadd intrinsics operands

Summary:
Change the vsqadd vector instrinsics to have the second argument as signed 
values, not unsigned,
accordingly to 
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics

Reviewers: LukeCheeseman, ostannard

Reviewed By: ostannard

Subscribers: javed.absar, kristof.beyls, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Basic/arm_neon.td

Modified: cfe/trunk/include/clang/Basic/arm_neon.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/arm_neon.td?rev=365608=365607=365608=diff
==
--- cfe/trunk/include/clang/Basic/arm_neon.td (original)
+++ cfe/trunk/include/clang/Basic/arm_neon.td Wed Jul 10 02:58:03 2019
@@ -707,7 +707,7 @@ def SUQADD : SInst<"vuqadd", "ddd", "csi
 
 

 // Unsigned Saturating Accumulated of Signed Value
-def USQADD : SInst<"vsqadd", "ddd", "UcUsUiUlQUcQUsQUiQUl">;
+def USQADD : SInst<"vsqadd", "ddx", "UcUsUiUlQUcQUsQUiQUl">;
 
 

 // Reciprocal/Sqrt


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


Re: r365499 - [OpenCL][Sema] Fix builtin rewriting

2019-07-10 Thread Marco Antognini via cfe-commits
Hello Reid,

Thanks for reporting it. I filed a bug to fix that (http://llvm.org/PR42560). 
However, I'm not sure I'll have time this week to look at it, especially given 
that we have no Windows builder around here. If you are critically blocked by 
this, could you check that adding '// UNSUPPORTED: system-windows' properly 
disables the test? And if so, feel free to commit for now.

Marco

From: Reid Kleckner 
Sent: 09 July 2019 21:47
To: Marco Antognini
Cc: cfe-commits
Subject: Re: r365499 - [OpenCL][Sema] Fix builtin rewriting

FYI, your test seems to fail on Windows:
FAIL: Clang :: CodeGenOpenCL/pipe_builtin.cl (4679 of 
15176)
 TEST 'Clang :: 
CodeGenOpenCL/pipe_builtin.cl' FAILED 

Script:
--
: 'RUN: at line 1';   
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\clang.exe -cc1 
-internal-isystem 
c:\b\slave\clang-x64-windows-msvc\build\build\stage1\lib\clang\9.0.0\include 
-nostdsysteminc -emit-llvm -cl-ext=+cl_khr_subgroups -O0 -cl-std=c++ -o - 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\CodeGenOpenCL\pipe_builtin.cl
 | c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\filecheck.exe 
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\CodeGenOpenCL\pipe_builtin.cl
--
Exit Code: 2

Command Output (stdout):
--
$ ":" "RUN: at line 1"
$ "c:\b\slave\clang-x64-windows-msvc\build\build\stage1\bin\clang.exe" "-cc1" 
"-internal-isystem" 
"c:\b\slave\clang-x64-windows-msvc\build\build\stage1\lib\clang\9.0.0\include" 
"-nostdsysteminc" "-emit-llvm" "-cl-ext=+cl_khr_subgroups" "-O0" "-cl-std=c++" 
"-o" "-" 
"C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\CodeGenOpenCL\pipe_builtin.cl"
# command stderr:
C:\b\slave\clang-x64-windows-msvc\build\llvm.src\tools\clang\test\CodeGenOpenCL\pipe_builtin.cl:9:1:
 error: cannot mangle this OpenCL pipe type yet

void test1(read_only pipe int p, global int *ptr) {

^~~

1 error generated.

On Tue, Jul 9, 2019 at 8:04 AM Marco Antognini via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Author: mantognini
Date: Tue Jul  9 08:04:23 2019
New Revision: 365499

URL: http://llvm.org/viewvc/llvm-project?rev=365499=rev
Log:
[OpenCL][Sema] Fix builtin rewriting

This patch ensures built-in functions are rewritten using the proper
parent declaration.

Existing tests are modified to run in C++ mode to ensure the
functionality works also with C++ for OpenCL while not increasing the
testing runtime.

Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CodeGenOpenCL/builtins.cl
cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
cfe/trunk/test/CodeGenOpenCL/to_addr_builtin.cl

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=365499=365498=365499=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Tue Jul  9 08:04:23 2019
@@ -1478,6 +1478,7 @@ BUILTIN(__builtin_coro_begin, "v*v*", "n
 BUILTIN(__builtin_coro_end, "bv*Ib", "n")
 BUILTIN(__builtin_coro_suspend, "cIb", "n")
 BUILTIN(__builtin_coro_param, "bv*v*", "n")
+
 // OpenCL v2.0 s6.13.16, s9.17.3.5 - Pipe functions.
 // We need the generic prototype, since the packet type could be anything.
 LANGBUILTIN(read_pipe, "i.", "tn", OCLC20_LANG)
@@ -1513,6 +1514,8 @@ LANGBUILTIN(get_kernel_max_sub_group_siz
 LANGBUILTIN(get_kernel_sub_group_count_for_ndrange, "Ui.", "tn", OCLC20_LANG)

 // OpenCL v2.0 s6.13.9 - Address space qualifier functions.
+// FIXME: Pointer parameters of OpenCL builtins should have their address space
+// requirement defined.
 LANGBUILTIN(to_global, "v*v*", "tn", OCLC20_LANG)
 LANGBUILTIN(to_local, "v*v*", "tn", OCLC20_LANG)
 LANGBUILTIN(to_private, "v*v*", "tn", OCLC20_LANG)

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=365499=365498=365499=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jul  9 08:04:23 2019
@@ -5360,7 +5360,7 @@ static bool checkArgsForPlaceholders(Sem
 ///  FunctionDecl is returned.
 /// TODO: Handle pointer return types.
 static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext 
,
-const FunctionDecl *FDecl,
+FunctionDecl *FDecl,
 MultiExprArg ArgExprs) {

   

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

2019-07-10 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

Just as Sidenote in case you were not aware: There is a check in clang-tidy for 
`gsl::owner` 
(https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-owning-memory.html)
It will benefit from your annotation and can be simplified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64448



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


[clang-tools-extra] r365607 - [clangd] Stop recording tokens before running clang-tidy

2019-07-10 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Jul 10 02:28:35 2019
New Revision: 365607

URL: http://llvm.org/viewvc/llvm-project?rev=365607=rev
Log:
[clangd] Stop recording tokens before running clang-tidy

modernize-trailing-return-type runs the preprocessor, breaking the token
collection logic.

This lead to a crash before, see the new test for a repro.

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

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=365607=365606=365607=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Wed Jul 10 02:28:35 2019
@@ -421,12 +421,16 @@ ParsedAST::build(std::unique_ptrgetPreprocessor().addCommentHandler(IWYUHandler.get());
 
   // Collect tokens of the main file.
-  syntax::TokenCollector Tokens(Clang->getPreprocessor());
+  syntax::TokenCollector CollectTokens(Clang->getPreprocessor());
 
   if (llvm::Error Err = Action->Execute())
 log("Execute() failed when building AST for {0}: {1}", MainInput.getFile(),
 toString(std::move(Err)));
 
+  // We have to consume the tokens before running clang-tidy to avoid 
collecting
+  // tokens from running the preprocessor inside the checks (only
+  // modernize-use-trailing-return-type does that today).
+  syntax::TokenBuffer Tokens = std::move(CollectTokens).consume();
   std::vector ParsedDecls = Action->takeTopLevelDecls();
   // AST traversals should exclude the preamble, to avoid performance cliffs.
   Clang->getASTContext().setTraversalScope(ParsedDecls);
@@ -452,9 +456,8 @@ ParsedAST::build(std::unique_ptrDiags.begin(), 
Preamble->Diags.end());
   return ParsedAST(std::move(Preamble), std::move(Clang), std::move(Action),
-   std::move(Tokens).consume(), std::move(ParsedDecls),
-   std::move(Diags), std::move(Includes),
-   std::move(CanonIncludes));
+   std::move(Tokens), std::move(ParsedDecls), std::move(Diags),
+   std::move(Includes), std::move(CanonIncludes));
 }
 
 ParsedAST::ParsedAST(ParsedAST &) = default;

Modified: clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp?rev=365607=365606=365607=diff
==
--- clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/ClangdUnitTests.cpp Wed Jul 10 
02:28:35 2019
@@ -134,6 +134,27 @@ TEST(ClangdUnitTest, TokensAfterPreamble
   EXPECT_EQ(Spelled.back().text(SM), "last_token");
 }
 
+
+TEST(ClangdUnitTest, NoCrashOnTokensWithTidyCheck) {
+  TestTU TU;
+  // this check runs the preprocessor, we need to make sure it does not break
+  // our recording logic.
+  TU.ClangTidyChecks = "modernize-use-trailing-return-type";
+  TU.Code = "inline int foo() {}";
+
+  auto AST = TU.build();
+  const syntax::TokenBuffer  = AST.getTokens();
+  const auto  = AST.getSourceManager();
+
+  ASSERT_GT(T.expandedTokens().size(), 7u);
+  // Check first token after the preamble.
+  EXPECT_EQ(T.expandedTokens().front().text(SM), "inline");
+  // Last token is always 'eof'.
+  EXPECT_EQ(T.expandedTokens().back().kind(), tok::eof);
+  // Check the token before 'eof'.
+  EXPECT_EQ(T.expandedTokens().drop_back().back().text(SM), "}");
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


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


[clang-tools-extra] r365606 - [clangd] Consume error to avoid assertion failures

2019-07-10 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Jul 10 02:18:09 2019
New Revision: 365606

URL: http://llvm.org/viewvc/llvm-project?rev=365606=rev
Log:
[clangd] Consume error to avoid assertion failures

When we fail to calculate #include insertion for a completion item.
Note that this change does not add a test, although that would be good.

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

Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=365606=365605=365606=diff
==
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Wed Jul 10 02:18:09 2019
@@ -346,8 +346,9 @@ struct CodeCompletionBuilder {
 Completion.Includes.push_back(std::move(Include));
   } else
 log("Failed to generate include insertion edits for adding header "
-"(FileURI='{0}', IncludeHeader='{1}') into {2}",
-C.IndexResult->CanonicalDeclaration.FileURI, Inc, FileName);
+"(FileURI='{0}', IncludeHeader='{1}') into {2}: {3}",
+C.IndexResult->CanonicalDeclaration.FileURI, Inc, FileName,
+ToInclude.takeError());
 }
 // Prefer includes that do not need edits (i.e. already exist).
 std::stable_partition(Completion.Includes.begin(),


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


[PATCH] D63954: Add lifetime categories attributes

2019-07-10 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:4164
+  let Content = [{
+When annotating a class ``O`` with ``[[gsl::Owner(T)]]``, then each function
+that returns cv-qualified ``T&`` or ``T*`` is assumed to return a

Slightly better: "In a class annotated with ..., each function that returns ... 
is assumed to ..."

However, the "is assumed" part throws me off. There's no assumption here -- 
this is what this attribute means, intentionally, by design, no guessing 
involved.

So how about this?

The attribute `[[gsl::Owner(T)]]` applies to structs and classes that own an 
object of type `T`:

```
[[gsl::Owner(int)]] class IntOwner {
private:
  int value;
public:
  int *getInt() { return  }
  long *getLong();
};
```

In a class annotated like this each member function that returns `T&` or `T*` 
returns a pointer/reference to the data owned by the class instance:

```
IntOwner int_owner;
int *x = int_owner.getInt();
// `x` points to memory owned by `int_owner`.
```

Therefore, that the lifetime of that data ends when ... For example:

```
int *x = IntOwner().getInt();
// `x` points to memory owned by the temporary `IntOwner()`, which has been 
destroyed now.

long *y = IntOwner().getLong();
// Can't make any conclusion about validity of `y`.
```




Comment at: clang/include/clang/Basic/AttrDocs.td:4177
+  let Content = [{
+When annotating a class ``P`` with ``[[gsl::Pointer(T)]]``, it assumed to be a
+non-owning type whose objects can point to ``T`` type objects or dangle.

Ditto, "A class annotated with ... is assumed to be ..."

However, again, I feel like "assume" is the wrong word to use.

"The attribute `[[gsl::Pointer(T)]]` applies to structs and classes that behave 
like pointers to an object of type `T`:

```
class [[gsl::Pointer(int)]] IntPointer {
private:
  int *valuePointer;
public:
  // fill it in with appropriate APIs
};
```

Classes annotated like this behave like regular pointers: they can either point 
to objects of type `T`, or dangle (<<>>).

For example: ... sample code and a static analysis message...



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:4546-4547
+
+  if (ParmType->isVoidType()) {
+S.Diag(AL.getLoc(), diag::err_attribute_invalid_argument) << "'void'" << 
AL;
+return;

xazax.hun wrote:
> aaron.ballman wrote:
> > Is `void` really the only problematic type? What about incomplete types, 
> > for instance?
> I think incomplete types are fine. The only information we actually need here 
> is the name the pointee types. E.g. for a `SomeOwner` which is 
> annotated `Owner(Incomplete)`, we will assume that a method returning 
> `Incomplete*`, `std::reference_wrapper` etc will return an object 
> pointing to the memory owned by `SomeOwner`.
What about array types? References?

gsl::Owner(int[])
gsl::Owner(int&)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63954



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


[PATCH] D64257: [clangd] Added highlighting for class and enum types

2019-07-10 Thread Johan Vikström via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365602: [clangd] Added highlighting for class and enum 
types. (authored by jvikstrom, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64257?vs=208708=208895#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64257

Files:
  clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
  clang-tools-extra/trunk/clangd/SemanticHighlighting.h
  clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
  clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp

Index: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
===
--- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
+++ clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
@@ -10,6 +10,12 @@
 # CHECK-NEXT:  [
 # CHECK-NEXT:"entity.name.function.cpp"
 # CHECK-NEXT:  ]
+# CHECK-NEXT:  [
+# CHECK-NEXT:"entity.name.type.class.cpp"
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  [
+# CHECK-NEXT:"entity.name.type.enum.cpp"
+# CHECK-NEXT:  ]
 # CHECK-NEXT:]
 # CHECK-NEXT:  },
 ---
Index: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
@@ -11,6 +11,8 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclarationName.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 
 namespace clang {
@@ -35,13 +37,18 @@
   }
 
   bool VisitNamedDecl(NamedDecl *ND) {
-// FIXME: (De)Constructors/operator need to be highlighted some other way.
-if (ND->getDeclName().getNameKind() != DeclarationName::Identifier)
+// Constructors' TypeLoc has a TypePtr that is a FunctionProtoType. It has
+// no tag decl and therefore constructors must be gotten as NamedDecls
+// instead.
+if (ND->getDeclName().getNameKind() ==
+DeclarationName::CXXConstructorName) {
+  addToken(ND->getLocation(), ND);
   return true;
+}
 
-if (ND->getDeclName().isEmpty())
-  // Don't add symbols that don't have any length.
+if (ND->getDeclName().getNameKind() != DeclarationName::Identifier)
   return true;
+
 addToken(ND->getLocation(), ND);
 return true;
   }
@@ -56,8 +63,39 @@
 return true;
   }
 
+  bool VisitTypeLoc(TypeLoc ) {
+// This check is for not getting two entries when there are anonymous
+// structs. It also makes us not highlight namespace qualifiers. For
+// elaborated types the actual type is highlighted as an inner TypeLoc.
+if (TL.getTypeLocClass() == TypeLoc::TypeLocClass::Elaborated)
+  return true;
+
+if (const Type *TP = TL.getTypePtr())
+  if (const TagDecl *TD = TP->getAsTagDecl())
+  addToken(TL.getBeginLoc(), TD);
+return true;
+  }
+
 private:
-  void addToken(SourceLocation Loc, const Decl *D) {
+  void addToken(SourceLocation Loc, const NamedDecl *D) {
+if (D->getDeclName().isIdentifier() && D->getName().empty())
+  // Don't add symbols that don't have any length.
+  return;
+// We highlight class decls, constructor decls and destructor decls as
+// `Class` type. The destructor decls are handled in `VisitTypeLoc` (we will
+// visit a TypeLoc where the underlying Type is a CXXRecordDecl).
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::Class);
+  return;
+}
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::Class);
+  return;
+}
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::Enum);
+  return;
+}
 if (isa(D)) {
   addToken(Loc, HighlightingKind::Variable);
   return;
@@ -176,6 +214,10 @@
 return "entity.name.function.cpp";
   case HighlightingKind::Variable:
 return "variable.cpp";
+  case HighlightingKind::Class:
+return "entity.name.type.class.cpp";
+  case HighlightingKind::Enum:
+return "entity.name.type.enum.cpp";
   case HighlightingKind::NumKinds:
 llvm_unreachable("must not pass NumKinds to the function");
   }
Index: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
@@ -34,11 +34,13 @@
   auto AST = TestTU::withCode(Test.code()).build();
   static const std::map KindToString{
   {HighlightingKind::Variable, "Variable"},
-  {HighlightingKind::Function, "Function"}};
+  {HighlightingKind::Function, 

[clang-tools-extra] r365602 - [clangd] Added highlighting for class and enum types.

2019-07-10 Thread Johan Vikstrom via cfe-commits
Author: jvikstrom
Date: Wed Jul 10 01:41:25 2019
New Revision: 365602

URL: http://llvm.org/viewvc/llvm-project?rev=365602=rev
Log:
[clangd] Added highlighting for class and enum types.

Summary: Added highlighting for non-builtin types using VisitTypeLoc. Ignoring 
namespace qualifiers as for now.

Reviewers: hokein, sammccall, ilya-biryukov

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

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
clang-tools-extra/trunk/clangd/SemanticHighlighting.h
clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp?rev=365602=365601=365602=diff
==
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.cpp Wed Jul 10 01:41:25 
2019
@@ -11,6 +11,8 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclarationName.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 
 namespace clang {
@@ -35,13 +37,18 @@ public:
   }
 
   bool VisitNamedDecl(NamedDecl *ND) {
-// FIXME: (De)Constructors/operator need to be highlighted some other way.
-if (ND->getDeclName().getNameKind() != DeclarationName::Identifier)
+// Constructors' TypeLoc has a TypePtr that is a FunctionProtoType. It has
+// no tag decl and therefore constructors must be gotten as NamedDecls
+// instead.
+if (ND->getDeclName().getNameKind() ==
+DeclarationName::CXXConstructorName) {
+  addToken(ND->getLocation(), ND);
   return true;
+}
 
-if (ND->getDeclName().isEmpty())
-  // Don't add symbols that don't have any length.
+if (ND->getDeclName().getNameKind() != DeclarationName::Identifier)
   return true;
+
 addToken(ND->getLocation(), ND);
 return true;
   }
@@ -56,8 +63,39 @@ public:
 return true;
   }
 
+  bool VisitTypeLoc(TypeLoc ) {
+// This check is for not getting two entries when there are anonymous
+// structs. It also makes us not highlight namespace qualifiers. For
+// elaborated types the actual type is highlighted as an inner TypeLoc.
+if (TL.getTypeLocClass() == TypeLoc::TypeLocClass::Elaborated)
+  return true;
+
+if (const Type *TP = TL.getTypePtr())
+  if (const TagDecl *TD = TP->getAsTagDecl())
+  addToken(TL.getBeginLoc(), TD);
+return true;
+  }
+
 private:
-  void addToken(SourceLocation Loc, const Decl *D) {
+  void addToken(SourceLocation Loc, const NamedDecl *D) {
+if (D->getDeclName().isIdentifier() && D->getName().empty())
+  // Don't add symbols that don't have any length.
+  return;
+// We highlight class decls, constructor decls and destructor decls as
+// `Class` type. The destructor decls are handled in `VisitTypeLoc` (we 
will
+// visit a TypeLoc where the underlying Type is a CXXRecordDecl).
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::Class);
+  return;
+}
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::Class);
+  return;
+}
+if (isa(D)) {
+  addToken(Loc, HighlightingKind::Enum);
+  return;
+}
 if (isa(D)) {
   addToken(Loc, HighlightingKind::Variable);
   return;
@@ -176,6 +214,10 @@ llvm::StringRef toTextMateScope(Highligh
 return "entity.name.function.cpp";
   case HighlightingKind::Variable:
 return "variable.cpp";
+  case HighlightingKind::Class:
+return "entity.name.type.class.cpp";
+  case HighlightingKind::Enum:
+return "entity.name.type.enum.cpp";
   case HighlightingKind::NumKinds:
 llvm_unreachable("must not pass NumKinds to the function");
   }

Modified: clang-tools-extra/trunk/clangd/SemanticHighlighting.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/SemanticHighlighting.h?rev=365602=365601=365602=diff
==
--- clang-tools-extra/trunk/clangd/SemanticHighlighting.h (original)
+++ clang-tools-extra/trunk/clangd/SemanticHighlighting.h Wed Jul 10 01:41:25 
2019
@@ -26,6 +26,8 @@ namespace clangd {
 enum class HighlightingKind {
   Variable = 0,
   Function,
+  Class,
+  Enum,
 
   NumKinds,
 };

Modified: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/semantic-highlighting.test?rev=365602=365601=365602=diff
==
--- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test (original)
+++ 

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

2019-07-10 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added a comment.

> Those are already there in clang/test/SemaCXX/attr-gsl-owner-pointer.cpp.

I see. Sorry, but that seems insufficient to me -- different libraries use 
different patterns. For example, libc++ wraps everything in std in an inline 
namespace. I don't know how various versions of libstdc++ differ.




Comment at: clang/include/clang/Basic/TokenKinds.def:486
+TYPE_TRAIT_1(__is_gsl_owner, IsGslOwner, KEYCXX)
+TYPE_TRAIT_1(__is_gsl_pointer, IsGslPointer, KEYCXX)
 KEYWORD(__underlying_type   , KEYCXX)

I'd suggest to split type trait implementations into a separate patch.

Are these type traits being exposed only for testing? I'm not sure it is a good 
idea to do that -- people will end up using them in production code -- is that 
a concern? If so, maybe it would be better to test through warnings.



Comment at: clang/test/AST/ast-dump-attr.cpp:222
+
+class [[gsl::Pointer]] PointerWithoutArgument{};
+// CHECK: CXXRecordDecl{{.*}} class PointerWithoutArgument

This test and related code changes could be split off into a separate patch.



Comment at: clang/test/SemaCXX/attr-gsl-owner-pointer.cpp:86
+
+// Test builtin annotation for std types.
+namespace std {

I feel like these tests would be better off in a separate file.

It would be also good to explain which exact library we are trying to imitate 
in this test. Different libraries use different coding patterns.



Comment at: clang/test/SemaCXX/attr-gsl-owner-pointer.cpp:103
+template 
+class set_iterator {};
+

Is it actually defined like that?



Comment at: clang/test/SemaCXX/attr-gsl-owner-pointer.cpp:140
+
+class thread;
+static_assert(!__is_gsl_pointer(thread), "");

Unclear what this test is testing.

If there's something special about thread (e.g., it looks very much like an 
owner or a pointer, and a buggy implementation can easily declare thread to be 
an owner or a pointer), please explain that in a comment.

If you're testing that some random name is not being picked up by inference 
rules, I'd suggest to use an obviously-fictional name ("class 
type_unknown_to_compiler;")


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64448



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


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

2019-07-10 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr accepted this revision.
gribozavr added a comment.
This revision is now accepted and ready to land.

I'm not an expert in SemaInit code, but this change LGTM.




Comment at: clang/test/Sema/warn-lifetime-analysis-nocfg.cpp:8
+
+struct OwnerWithConv;
+

Not needed anymore.



Comment at: clang/test/Sema/warn-lifetime-analysis-nocfg.cpp:25
+
+struct [[gsl::Owner(int)]] OwnerWithConv {
+  OwnerWithConv();

Would be nice if the second pair of types had clearly related names, like the 
first pair (MyOwner/MyPointer).


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

https://reviews.llvm.org/D64256



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


[PATCH] D64257: [clangd] Added highlighting for class and enum types

2019-07-10 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D64257#1577347 , @nridge wrote:

> are you testing these patches against a client-side implementation of 
> semantic highlighting? If so, which one?


Looks like Theia is the only LSP client supporting the semantic highlighting 
proposal, we use it to verify the behavior.

And we also have a hidden tweak (run clangd with `-hidden-feature`) to annotate 
all the highlighting tokens, we use it to verify whether the token is being 
highlighted in a correct TextMate scope (it is triggered via the codeAction in 
VSCode).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64257



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


[PATCH] D64247: [clangd] Filter out non-governed files from broadcast

2019-07-10 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 208890.
kadircet marked 3 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64247

Files:
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/clangd/QueryDriverDatabase.cpp
  clang-tools-extra/clangd/index/Background.cpp
  clang-tools-extra/clangd/unittests/ClangdTests.cpp
  clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
  clang-tools-extra/clangd/unittests/TestFS.cpp
  clang-tools-extra/clangd/unittests/TestFS.h

Index: clang-tools-extra/clangd/unittests/TestFS.h
===
--- clang-tools-extra/clangd/unittests/TestFS.h
+++ clang-tools-extra/clangd/unittests/TestFS.h
@@ -12,6 +12,8 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTFS_H
 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_TESTFS_H
 #include "ClangdServer.h"
+#include "GlobalCompilationDatabase.h"
+#include "Path.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/VirtualFileSystem.h"
@@ -48,7 +50,9 @@
   StringRef RelPathPrefix = StringRef());
 
   llvm::Optional
-  getCompileCommand(PathRef File, ProjectInfo * = nullptr) const override;
+  getCompileCommand(PathRef File) const override;
+
+  llvm::Optional getProjectInfo(PathRef File) const override;
 
   std::vector ExtraClangFlags;
 
Index: clang-tools-extra/clangd/unittests/TestFS.cpp
===
--- clang-tools-extra/clangd/unittests/TestFS.cpp
+++ clang-tools-extra/clangd/unittests/TestFS.cpp
@@ -6,7 +6,11 @@
 //
 //===--===//
 #include "TestFS.h"
+#include "GlobalCompilationDatabase.h"
+#include "Path.h"
 #include "URI.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Path.h"
@@ -36,9 +40,13 @@
   // -ffreestanding avoids implicit stdc-predef.h.
 }
 
+llvm::Optional
+MockCompilationDatabase::getProjectInfo(PathRef File) const {
+  return ProjectInfo{Directory};
+};
+
 llvm::Optional
-MockCompilationDatabase::getCompileCommand(PathRef File,
-   ProjectInfo *Project) const {
+MockCompilationDatabase::getCompileCommand(PathRef File) const {
   if (ExtraClangFlags.empty())
 return None;
 
@@ -57,8 +65,6 @@
 CommandLine.push_back(RelativeFilePath.str());
   }
 
-  if (Project)
-Project->SourceRoot = Directory;
   return {tooling::CompileCommand(Directory != llvm::StringRef()
   ? Directory
   : llvm::sys::path::parent_path(File),
Index: clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
===
--- clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
+++ clang-tools-extra/clangd/unittests/GlobalCompilationDatabaseTests.cpp
@@ -8,10 +8,21 @@
 
 #include "GlobalCompilationDatabase.h"
 
+#include "Path.h"
 #include "TestFS.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -20,8 +31,10 @@
 using ::testing::Contains;
 using ::testing::ElementsAre;
 using ::testing::EndsWith;
+using ::testing::IsEmpty;
 using ::testing::Not;
 using ::testing::StartsWith;
+using ::testing::UnorderedElementsAre;
 
 TEST(GlobalCompilationDatabaseTest, FallbackCommand) {
   DirectoryBasedGlobalCompilationDatabase DB(None);
@@ -50,13 +63,9 @@
   class BaseCDB : public GlobalCompilationDatabase {
   public:
 llvm::Optional
-getCompileCommand(llvm::StringRef File,
-  ProjectInfo *Project) const override {
-  if (File == testPath("foo.cc")) {
-if (Project)
-  Project->SourceRoot = testRoot();
+getCompileCommand(llvm::StringRef File) const override {
+  if (File == testPath("foo.cc"))
 return cmd(File, "-DA=1");
-  }
   return None;
 }
 
@@ -64,6 +73,10 @@
 getFallbackCommand(llvm::StringRef File) const override {
   return cmd(File, "-DA=2");
 }
+
+llvm::Optional getProjectInfo(PathRef File) const override {
+  return ProjectInfo{testRoot()};
+}
   };
 
 protected:
@@ -153,6 +166,109 @@
 Not(Contains("random-plugin";
 }
 

r365599 - [Syntax] Add assertion to catch invalid tokens early. NFC

2019-07-10 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Wed Jul 10 01:24:42 2019
New Revision: 365599

URL: http://llvm.org/viewvc/llvm-project?rev=365599=rev
Log:
[Syntax] Add assertion to catch invalid tokens early. NFC

To help with identifiying root cause of a crash we are seeing.

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

Modified: cfe/trunk/include/clang/Tooling/Syntax/Tokens.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Syntax/Tokens.h?rev=365599=365598=365599=diff
==
--- cfe/trunk/include/clang/Tooling/Syntax/Tokens.h (original)
+++ cfe/trunk/include/clang/Tooling/Syntax/Tokens.h Wed Jul 10 01:24:42 2019
@@ -99,8 +99,7 @@ llvm::raw_ostream <<(llvm::raw_
 /// Can represent both expanded and spelled tokens.
 class Token {
 public:
-  Token(SourceLocation Location, unsigned Length, tok::TokenKind Kind)
-  : Location(Location), Length(Length), Kind(Kind) {}
+  Token(SourceLocation Location, unsigned Length, tok::TokenKind Kind);
   /// EXPECTS: clang::Token is not an annotation token.
   explicit Token(const clang::Token );
 

Modified: cfe/trunk/lib/Tooling/Syntax/Tokens.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Syntax/Tokens.cpp?rev=365599=365598=365599=diff
==
--- cfe/trunk/lib/Tooling/Syntax/Tokens.cpp (original)
+++ cfe/trunk/lib/Tooling/Syntax/Tokens.cpp Wed Jul 10 01:24:42 2019
@@ -35,6 +35,12 @@
 using namespace clang;
 using namespace clang::syntax;
 
+syntax::Token::Token(SourceLocation Location, unsigned Length,
+ tok::TokenKind Kind)
+: Location(Location), Length(Length), Kind(Kind) {
+  assert(Location.isValid());
+}
+
 syntax::Token::Token(const clang::Token )
 : Token(T.getLocation(), T.getLength(), T.getKind()) {
   assert(!T.isAnnotation());


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


[PATCH] D64257: [clangd] Added highlighting for class and enum types

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

thanks, looks good.




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:83
+// `Class` type. The destructor decls are handled in `VisitTypeLoc` (we 
will
+// visit a TypeLoc where the underlying Type is a CXXRecordDecl).
+if (D->getDeclName().isIdentifier() && D->getName().empty())

this comment doesn't belong to the if statement below, should move to Line 87.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64257



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


[PATCH] D64294: [Driver] Consolidate shouldUseFramePointer() and shouldUseLeafFramePointer()

2019-07-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:585
+  (A && A->getOption().matches(options::OPT_fno_omit_frame_pointer)) ||
+  (!(A && A->getOption().matches(options::OPT_fomit_frame_pointer)) &&
+   (Args.hasArg(options::OPT_pg) ||

ychen wrote:
> It looks better if  `frame_pointer` is represented using tri-state. Something 
> like this?
> 
> It would be great to have comments for conditions that are not obvious such 
> as the overriding rules.
> 
> ```
>   // There are three states for frame_pointer.
>   enum class FpFlag {true, false, none};
>   FpFlag FPF = FpFlag::none;
>   if (Arg *A = Args.getLastArg(options::OPT_fomit_frame_pointer,
>options::OPT_fno_omit_frame_pointer))
> FPF = A->getOption().matches(options::OPT_fno_omit_frame_pointer)) ?
>  FpFlag::true : FpFlag::false;
> 
>   if (!mustUseNonLeaf && FPF == FpFlag::false)
> return FramePointerKind::None;
> 
>   if (mustUseNonLeaf || FPF == FpFlag::true || Args.hasArg(options::OPT_pg) ||
>   useFramePointerForTargetByDefault(Args, Triple)) {
> if (Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
>  options::OPT_mno_omit_leaf_frame_pointer,
>  Triple.isPS4CPU()))
>   return FramePointerKind::NonLeaf;
> return FramePointerKind::All;
>   }
>   return FramePointerKind::None;
> ```
I actually think the current version is clearer.. The local `enum class FpFlag 
{true, false, none};` doesn't improve readability in my opinion.


I can define separate variables for:

* A && A->getOption().matches(options::OPT_fno_omit_frame_pointer)
* A && A->getOption().matches(options::OPT_fomit_frame_pointer)

If reviewers think that makes the code easier to read.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64294



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


[PATCH] D64243: [NFC][AArch64] Fix vector vqtb[lx][1-4]_s8 operand

2019-07-10 Thread Diogo N. Sampaio via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365598: [NFC][AArch64] Fix vector vqtb[lx][1-4]_s8 operand 
(authored by dnsampaio, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

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

https://reviews.llvm.org/D64243

Files:
  cfe/trunk/include/clang/Basic/arm_neon.td
  cfe/trunk/test/CodeGen/aarch64-neon-tbl.c

Index: cfe/trunk/include/clang/Basic/arm_neon.td
===
--- cfe/trunk/include/clang/Basic/arm_neon.td
+++ cfe/trunk/include/clang/Basic/arm_neon.td
@@ -1070,16 +1070,16 @@
 
 // Table lookup
 let InstName = "vtbl" in {
-def VQTBL1_A64 : WInst<"vqtbl1", "djt",  "UccPcQUcQcQPc">;
-def VQTBL2_A64 : WInst<"vqtbl2", "dBt",  "UccPcQUcQcQPc">;
-def VQTBL3_A64 : WInst<"vqtbl3", "dCt",  "UccPcQUcQcQPc">;
-def VQTBL4_A64 : WInst<"vqtbl4", "dDt",  "UccPcQUcQcQPc">;
+def VQTBL1_A64 : WInst<"vqtbl1", "dju",  "UccPcQUcQcQPc">;
+def VQTBL2_A64 : WInst<"vqtbl2", "dBu",  "UccPcQUcQcQPc">;
+def VQTBL3_A64 : WInst<"vqtbl3", "dCu",  "UccPcQUcQcQPc">;
+def VQTBL4_A64 : WInst<"vqtbl4", "dDu",  "UccPcQUcQcQPc">;
 }
 let InstName = "vtbx" in {
-def VQTBX1_A64 : WInst<"vqtbx1", "ddjt", "UccPcQUcQcQPc">;
-def VQTBX2_A64 : WInst<"vqtbx2", "ddBt", "UccPcQUcQcQPc">;
-def VQTBX3_A64 : WInst<"vqtbx3", "ddCt", "UccPcQUcQcQPc">;
-def VQTBX4_A64 : WInst<"vqtbx4", "ddDt", "UccPcQUcQcQPc">;
+def VQTBX1_A64 : WInst<"vqtbx1", "ddju", "UccPcQUcQcQPc">;
+def VQTBX2_A64 : WInst<"vqtbx2", "ddBu", "UccPcQUcQcQPc">;
+def VQTBX3_A64 : WInst<"vqtbx3", "ddCu", "UccPcQUcQcQPc">;
+def VQTBX4_A64 : WInst<"vqtbx4", "ddDu", "UccPcQUcQcQPc">;
 }
 
 
Index: cfe/trunk/test/CodeGen/aarch64-neon-tbl.c
===
--- cfe/trunk/test/CodeGen/aarch64-neon-tbl.c
+++ cfe/trunk/test/CodeGen/aarch64-neon-tbl.c
@@ -16,7 +16,7 @@
 // CHECK-LABEL: define <8 x i8> @test_vqtbl1_s8(<16 x i8> %a, <8 x i8> %b) #1 {
 // CHECK:   [[VTBL1_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.tbl1.v8i8(<16 x i8> %a, <8 x i8> %b) #3
 // CHECK:   ret <8 x i8> [[VTBL1_I]]
-int8x8_t test_vqtbl1_s8(int8x16_t a, int8x8_t b) {
+int8x8_t test_vqtbl1_s8(int8x16_t a, uint8x8_t b) {
   return vqtbl1_s8(a, b);
 }
 
@@ -59,7 +59,7 @@
 // CHECK:   [[TMP2:%.*]] = load <16 x i8>, <16 x i8>* [[ARRAYIDX2_I]], align 16
 // CHECK:   [[VTBL2_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.tbl2.v8i8(<16 x i8> [[TMP1]], <16 x i8> [[TMP2]], <8 x i8> %b) #3
 // CHECK:   ret <8 x i8> [[VTBL2_I]]
-int8x8_t test_vqtbl2_s8(int8x16x2_t a, int8x8_t b) {
+int8x8_t test_vqtbl2_s8(int8x16x2_t a, uint8x8_t b) {
   return vqtbl2_s8(a, b);
 }
 
@@ -109,7 +109,7 @@
 // CHECK:   [[TMP3:%.*]] = load <16 x i8>, <16 x i8>* [[ARRAYIDX4_I]], align 16
 // CHECK:   [[VTBL3_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.tbl3.v8i8(<16 x i8> [[TMP1]], <16 x i8> [[TMP2]], <16 x i8> [[TMP3]], <8 x i8> %b) #3
 // CHECK:   ret <8 x i8> [[VTBL3_I]]
-int8x8_t test_vqtbl3_s8(int8x16x3_t a, int8x8_t b) {
+int8x8_t test_vqtbl3_s8(int8x16x3_t a, uint8x8_t b) {
   return vqtbl3_s8(a, b);
 }
 
@@ -165,7 +165,7 @@
 // CHECK:   [[TMP4:%.*]] = load <16 x i8>, <16 x i8>* [[ARRAYIDX6_I]], align 16
 // CHECK:   [[VTBL4_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.tbl4.v8i8(<16 x i8> [[TMP1]], <16 x i8> [[TMP2]], <16 x i8> [[TMP3]], <16 x i8> [[TMP4]], <8 x i8> %b) #3
 // CHECK:   ret <8 x i8> [[VTBL4_I]]
-int8x8_t test_vqtbl4_s8(int8x16x4_t a, int8x8_t b) {
+int8x8_t test_vqtbl4_s8(int8x16x4_t a, uint8x8_t b) {
   return vqtbl4_s8(a, b);
 }
 
@@ -348,7 +348,7 @@
 // CHECK-LABEL: define <8 x i8> @test_vqtbx1_s8(<8 x i8> %a, <16 x i8> %b, <8 x i8> %c) #1 {
 // CHECK:   [[VTBX1_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.tbx1.v8i8(<8 x i8> %a, <16 x i8> %b, <8 x i8> %c) #3
 // CHECK:   ret <8 x i8> [[VTBX1_I]]
-int8x8_t test_vqtbx1_s8(int8x8_t a, int8x16_t b, int8x8_t c) {
+int8x8_t test_vqtbx1_s8(int8x8_t a, int8x16_t b, uint8x8_t c) {
   return vqtbx1_s8(a, b, c);
 }
 
@@ -369,7 +369,7 @@
 // CHECK:   [[TMP2:%.*]] = load <16 x i8>, <16 x i8>* [[ARRAYIDX2_I]], align 16
 // CHECK:   [[VTBX2_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.tbx2.v8i8(<8 x i8> %a, <16 x i8> [[TMP1]], <16 x i8> [[TMP2]], <8 x i8> %c) #3
 // CHECK:   ret <8 x i8> [[VTBX2_I]]
-int8x8_t test_vqtbx2_s8(int8x8_t a, int8x16x2_t b, int8x8_t c) {
+int8x8_t test_vqtbx2_s8(int8x8_t a, int8x16x2_t b, uint8x8_t c) {
   return vqtbx2_s8(a, b, c);
 }
 
@@ -393,7 +393,7 @@
 // CHECK:   [[TMP3:%.*]] = load <16 x i8>, <16 x i8>* [[ARRAYIDX4_I]], align 16
 // CHECK:   [[VTBX3_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.tbx3.v8i8(<8 x i8> %a, <16 x i8> [[TMP1]], <16 x i8> [[TMP2]], <16 x i8> [[TMP3]], <8 x i8> %c) #3
 // CHECK:   ret <8 x i8> [[VTBX3_I]]
-int8x8_t 

[PATCH] D64471: Loop pragma parsing. NFC.

2019-07-10 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: Meinersbur, dmgreen, samparker.

I would like to add some pragma handling here, but couldn't resist a little NFC 
and tidy up first.


https://reviews.llvm.org/D64471

Files:
  clang/lib/Sema/SemaStmtAttr.cpp


Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -82,22 +82,17 @@
   IdentifierLoc *StateLoc = A.getArgAsIdent(2);
   Expr *ValueExpr = A.getArgAsExpr(3);
 
-  bool PragmaUnroll = PragmaNameLoc->Ident->getName() == "unroll";
-  bool PragmaNoUnroll = PragmaNameLoc->Ident->getName() == "nounroll";
-  bool PragmaUnrollAndJam = PragmaNameLoc->Ident->getName() == 
"unroll_and_jam";
-  bool PragmaNoUnrollAndJam =
-  PragmaNameLoc->Ident->getName() == "nounroll_and_jam";
+  StringRef PragmaName =
+  llvm::StringSwitch(PragmaNameLoc->Ident->getName())
+  .Cases("unroll", "nounroll", "unroll_and_jam", "nounroll_and_jam",
+ PragmaNameLoc->Ident->getName())
+  .Default("clang loop");
+
   if (St->getStmtClass() != Stmt::DoStmtClass &&
   St->getStmtClass() != Stmt::ForStmtClass &&
   St->getStmtClass() != Stmt::CXXForRangeStmtClass &&
   St->getStmtClass() != Stmt::WhileStmtClass) {
-const char *Pragma =
-llvm::StringSwitch(PragmaNameLoc->Ident->getName())
-.Case("unroll", "#pragma unroll")
-.Case("nounroll", "#pragma nounroll")
-.Case("unroll_and_jam", "#pragma unroll_and_jam")
-.Case("nounroll_and_jam", "#pragma nounroll_and_jam")
-.Default("#pragma clang loop");
+std::string Pragma = "#pragma " + std::string(PragmaName);
 S.Diag(St->getBeginLoc(), diag::err_pragma_loop_precedes_nonloop) << 
Pragma;
 return nullptr;
   }
@@ -106,34 +101,29 @@
   LoopHintAttr::Spelling(A.getAttributeSpellingListIndex());
   LoopHintAttr::OptionType Option;
   LoopHintAttr::LoopHintState State;
-  if (PragmaNoUnroll) {
-// #pragma nounroll
-Option = LoopHintAttr::Unroll;
-State = LoopHintAttr::Disable;
-  } else if (PragmaUnroll) {
-if (ValueExpr) {
-  // #pragma unroll N
-  Option = LoopHintAttr::UnrollCount;
-  State = LoopHintAttr::Numeric;
-} else {
-  // #pragma unroll
-  Option = LoopHintAttr::Unroll;
-  State = LoopHintAttr::Enable;
-}
-  } else if (PragmaNoUnrollAndJam) {
-// #pragma nounroll_and_jam
-Option = LoopHintAttr::UnrollAndJam;
-State = LoopHintAttr::Disable;
-  } else if (PragmaUnrollAndJam) {
-if (ValueExpr) {
-  // #pragma unroll_and_jam N
-  Option = LoopHintAttr::UnrollAndJamCount;
-  State = LoopHintAttr::Numeric;
-} else {
-  // #pragma unroll_and_jam
-  Option = LoopHintAttr::UnrollAndJam;
-  State = LoopHintAttr::Enable;
-}
+
+  auto SetHints = [, ](LoopHintAttr::OptionType O,
+LoopHintAttr::LoopHintState S) {
+Option = O;
+State = S;
+  };
+
+  if (PragmaName == "nounroll") {
+SetHints(LoopHintAttr::Unroll, LoopHintAttr::Disable);
+  } else if (PragmaName == "unroll") {
+// #pragma unroll N
+if (ValueExpr)
+  SetHints(LoopHintAttr::UnrollCount, LoopHintAttr::Numeric);
+else
+  SetHints(LoopHintAttr::Unroll, LoopHintAttr::Enable);
+  } else if (PragmaName == "nounroll_and_jam") {
+SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Disable);
+  } else if (PragmaName == "unroll_and_jam") {
+// #pragma unroll_and_jam N
+if (ValueExpr)
+  SetHints(LoopHintAttr::UnrollAndJamCount, LoopHintAttr::Numeric);
+else
+  SetHints(LoopHintAttr::UnrollAndJam, LoopHintAttr::Enable);
   } else {
 // #pragma clang loop ...
 assert(OptionLoc && OptionLoc->Ident &&


Index: clang/lib/Sema/SemaStmtAttr.cpp
===
--- clang/lib/Sema/SemaStmtAttr.cpp
+++ clang/lib/Sema/SemaStmtAttr.cpp
@@ -82,22 +82,17 @@
   IdentifierLoc *StateLoc = A.getArgAsIdent(2);
   Expr *ValueExpr = A.getArgAsExpr(3);
 
-  bool PragmaUnroll = PragmaNameLoc->Ident->getName() == "unroll";
-  bool PragmaNoUnroll = PragmaNameLoc->Ident->getName() == "nounroll";
-  bool PragmaUnrollAndJam = PragmaNameLoc->Ident->getName() == "unroll_and_jam";
-  bool PragmaNoUnrollAndJam =
-  PragmaNameLoc->Ident->getName() == "nounroll_and_jam";
+  StringRef PragmaName =
+  llvm::StringSwitch(PragmaNameLoc->Ident->getName())
+  .Cases("unroll", "nounroll", "unroll_and_jam", "nounroll_and_jam",
+ PragmaNameLoc->Ident->getName())
+  .Default("clang loop");
+
   if (St->getStmtClass() != Stmt::DoStmtClass &&
   St->getStmtClass() != Stmt::ForStmtClass &&
   St->getStmtClass() != Stmt::CXXForRangeStmtClass &&
   St->getStmtClass() != Stmt::WhileStmtClass) {
-const char *Pragma =
-

r365598 - [NFC][AArch64] Fix vector vqtb[lx][1-4]_s8 operand

2019-07-10 Thread Diogo N. Sampaio via cfe-commits
Author: dnsampaio
Date: Wed Jul 10 01:16:49 2019
New Revision: 365598

URL: http://llvm.org/viewvc/llvm-project?rev=365598=rev
Log:
[NFC][AArch64] Fix vector vqtb[lx][1-4]_s8 operand

Summary:
Change the vqtb[lx][1-4]_s8 instrinsics to have the last argument as vector of 
unsigned valuse, not
signed, accordingly to 
https://developer.arm.com/architectures/instruction-sets/simd-isas/neon/intrinsics

Reviewers: LukeCheeseman, DavidSpickett

Reviewed By: DavidSpickett

Subscribers: DavidSpickett, javed.absar, kristof.beyls, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Basic/arm_neon.td
cfe/trunk/test/CodeGen/aarch64-neon-tbl.c

Modified: cfe/trunk/include/clang/Basic/arm_neon.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/arm_neon.td?rev=365598=365597=365598=diff
==
--- cfe/trunk/include/clang/Basic/arm_neon.td (original)
+++ cfe/trunk/include/clang/Basic/arm_neon.td Wed Jul 10 01:16:49 2019
@@ -1070,16 +1070,16 @@ def VUZP2 : SOpInst<"vuzp2", "ddd",
 

 // Table lookup
 let InstName = "vtbl" in {
-def VQTBL1_A64 : WInst<"vqtbl1", "djt",  "UccPcQUcQcQPc">;
-def VQTBL2_A64 : WInst<"vqtbl2", "dBt",  "UccPcQUcQcQPc">;
-def VQTBL3_A64 : WInst<"vqtbl3", "dCt",  "UccPcQUcQcQPc">;
-def VQTBL4_A64 : WInst<"vqtbl4", "dDt",  "UccPcQUcQcQPc">;
+def VQTBL1_A64 : WInst<"vqtbl1", "dju",  "UccPcQUcQcQPc">;
+def VQTBL2_A64 : WInst<"vqtbl2", "dBu",  "UccPcQUcQcQPc">;
+def VQTBL3_A64 : WInst<"vqtbl3", "dCu",  "UccPcQUcQcQPc">;
+def VQTBL4_A64 : WInst<"vqtbl4", "dDu",  "UccPcQUcQcQPc">;
 }
 let InstName = "vtbx" in {
-def VQTBX1_A64 : WInst<"vqtbx1", "ddjt", "UccPcQUcQcQPc">;
-def VQTBX2_A64 : WInst<"vqtbx2", "ddBt", "UccPcQUcQcQPc">;
-def VQTBX3_A64 : WInst<"vqtbx3", "ddCt", "UccPcQUcQcQPc">;
-def VQTBX4_A64 : WInst<"vqtbx4", "ddDt", "UccPcQUcQcQPc">;
+def VQTBX1_A64 : WInst<"vqtbx1", "ddju", "UccPcQUcQcQPc">;
+def VQTBX2_A64 : WInst<"vqtbx2", "ddBu", "UccPcQUcQcQPc">;
+def VQTBX3_A64 : WInst<"vqtbx3", "ddCu", "UccPcQUcQcQPc">;
+def VQTBX4_A64 : WInst<"vqtbx4", "ddDu", "UccPcQUcQcQPc">;
 }
 
 


Modified: cfe/trunk/test/CodeGen/aarch64-neon-tbl.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/aarch64-neon-tbl.c?rev=365598=365597=365598=diff
==
--- cfe/trunk/test/CodeGen/aarch64-neon-tbl.c (original)
+++ cfe/trunk/test/CodeGen/aarch64-neon-tbl.c Wed Jul 10 01:16:49 2019
@@ -16,7 +16,7 @@ int8x8_t test_vtbl1_s8(int8x8_t a, int8x
 // CHECK-LABEL: define <8 x i8> @test_vqtbl1_s8(<16 x i8> %a, <8 x i8> %b) #1 {
 // CHECK:   [[VTBL1_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.tbl1.v8i8(<16 x 
i8> %a, <8 x i8> %b) #3
 // CHECK:   ret <8 x i8> [[VTBL1_I]]
-int8x8_t test_vqtbl1_s8(int8x16_t a, int8x8_t b) {
+int8x8_t test_vqtbl1_s8(int8x16_t a, uint8x8_t b) {
   return vqtbl1_s8(a, b);
 }
 
@@ -59,7 +59,7 @@ int8x8_t test_vtbl2_s8(int8x8x2_t a, int
 // CHECK:   [[TMP2:%.*]] = load <16 x i8>, <16 x i8>* [[ARRAYIDX2_I]], align 16
 // CHECK:   [[VTBL2_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.tbl2.v8i8(<16 x 
i8> [[TMP1]], <16 x i8> [[TMP2]], <8 x i8> %b) #3
 // CHECK:   ret <8 x i8> [[VTBL2_I]]
-int8x8_t test_vqtbl2_s8(int8x16x2_t a, int8x8_t b) {
+int8x8_t test_vqtbl2_s8(int8x16x2_t a, uint8x8_t b) {
   return vqtbl2_s8(a, b);
 }
 
@@ -109,7 +109,7 @@ int8x8_t test_vtbl3_s8(int8x8x3_t a, int
 // CHECK:   [[TMP3:%.*]] = load <16 x i8>, <16 x i8>* [[ARRAYIDX4_I]], align 16
 // CHECK:   [[VTBL3_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.tbl3.v8i8(<16 x 
i8> [[TMP1]], <16 x i8> [[TMP2]], <16 x i8> [[TMP3]], <8 x i8> %b) #3
 // CHECK:   ret <8 x i8> [[VTBL3_I]]
-int8x8_t test_vqtbl3_s8(int8x16x3_t a, int8x8_t b) {
+int8x8_t test_vqtbl3_s8(int8x16x3_t a, uint8x8_t b) {
   return vqtbl3_s8(a, b);
 }
 
@@ -165,7 +165,7 @@ int8x8_t test_vtbl4_s8(int8x8x4_t a, int
 // CHECK:   [[TMP4:%.*]] = load <16 x i8>, <16 x i8>* [[ARRAYIDX6_I]], align 16
 // CHECK:   [[VTBL4_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.tbl4.v8i8(<16 x 
i8> [[TMP1]], <16 x i8> [[TMP2]], <16 x i8> [[TMP3]], <16 x i8> [[TMP4]], <8 x 
i8> %b) #3
 // CHECK:   ret <8 x i8> [[VTBL4_I]]
-int8x8_t test_vqtbl4_s8(int8x16x4_t a, int8x8_t b) {
+int8x8_t test_vqtbl4_s8(int8x16x4_t a, uint8x8_t b) {
   return vqtbl4_s8(a, b);
 }
 
@@ -348,7 +348,7 @@ int8x8_t test_vtbx4_s8(int8x8_t a, int8x
 // CHECK-LABEL: define <8 x i8> @test_vqtbx1_s8(<8 x i8> %a, <16 x i8> %b, <8 
x i8> %c) #1 {
 // CHECK:   [[VTBX1_I:%.*]] = call <8 x i8> @llvm.aarch64.neon.tbx1.v8i8(<8 x 
i8> %a, <16 x i8> %b, <8 x i8> %c) #3
 // CHECK:   ret <8 x i8> [[VTBX1_I]]
-int8x8_t test_vqtbx1_s8(int8x8_t a, int8x16_t b, int8x8_t c) {
+int8x8_t test_vqtbx1_s8(int8x8_t a, int8x16_t b, uint8x8_t 

[PATCH] D61001: [clang-format][tests] Explicitly specify style in some tests

2019-07-10 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl marked 2 inline comments as done.
r.stahl added inline comments.



Comment at: test/Format/language-detection.cpp:2
 // RUN: grep -Ev "// *[A-Z0-9_]+:" %s \
-// RUN:   | clang-format -style=llvm -assume-filename=foo.js \
 // RUN:   | FileCheck -strict-whitespace -check-prefix=CHECK1 %s

lebedev.ri wrote:
> What's wrong with `-style=llvm`?
I looked at all the tests in that folder and saw that LLVM is the more common 
usage and unified it.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61001



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


[PATCH] D64257: [clangd] Added highlighting for class and enum types

2019-07-10 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom added a comment.

In D64257#1577347 , @nridge wrote:

> @jvikstrom out of curiosity, are you testing these patches against a 
> client-side implementation of semantic highlighting? If so, which one?


Yes, I am testing against Theia. Just modified the Theia c++ language client to 
include the semantic highlighting service.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64257



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


[PATCH] D61001: [clang-format][tests] Explicitly specify style in some tests

2019-07-10 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: test/Format/language-detection.cpp:2
 // RUN: grep -Ev "// *[A-Z0-9_]+:" %s \
-// RUN:   | clang-format -style=llvm -assume-filename=foo.js \
 // RUN:   | FileCheck -strict-whitespace -check-prefix=CHECK1 %s

What's wrong with `-style=llvm`?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61001



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


[PATCH] D61001: [clang-format][tests] Explicitly specify style in some tests

2019-07-10 Thread Rafael Stahl via Phabricator via cfe-commits
r.stahl added reviewers: MyDeveloperDay, krasimir.
r.stahl added a comment.

This should be trivial enough to just commit, but I'd just be more comfortable 
if someone looked at it before, because this is my first commit in this area of 
clang.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61001



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


[PATCH] D63085: Provide a fix-it hint for -Wswitch, which adds missing cases. If there are >3 cases, the inserted text will contain newlines so it will not be shown in console output (but will be appl

2019-07-10 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

One major drawback that I see is the lack of indentation (and other format 
options) in the added code.
Should we have this fix at a higher level that can have formatting (either now 
or in the future)? E.g. in `clangd` directly?




Comment at: lib/Sema/SemaStmt.cpp:1208
+llvm::raw_string_ostream NewCasesOS(NewCases);
+// Include \n to separate new cases added if there are many.
+// This suppresses printing the (long) insert text.

Maybe always put each `case` on a new line?
From my experience, having multiple cases on the same line is not very common.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63085



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


[PATCH] D64123: Add clang-llvm-rename tool.

2019-07-10 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu updated this revision to Diff 208883.
ruiu added a comment.

- Add a comment as to how to build and run clang-llvm-rename tool


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D64123

Files:
  clang-tools-extra/CMakeLists.txt
  clang-tools-extra/clang-llvm-rename/CMakeLists.txt
  clang-tools-extra/clang-llvm-rename/ClangLLVMRename.cpp

Index: clang-tools-extra/clang-llvm-rename/ClangLLVMRename.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-llvm-rename/ClangLLVMRename.cpp
@@ -0,0 +1,287 @@
+//=== ClangLLVMRename.cpp -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This is a refactoring tool to rename variables so that they start with a
+// lowercase letter. This tool is intended to be used to rename variables in
+// LLVM codebase in which variable names start with an uppercase letter at
+// the moment.
+//
+//   Usage:
+//   clang-llmv-rename   ...
+//
+//  ... specify the paths of files in the CMake source tree. This
+// path is looked up in the compile command database. Here is how to build
+// the tool and apply that to all files under "lld" directory.
+//
+//   $ git clone https://github.com/llvm/llvm-project.git
+//   $ mkdir llvm-project/build
+//   $ cd llvm-project/build
+//   $ cmake -GNinja -DCMAKE_BUILD_TYPE=Release \
+//   -DLLVM_ENABLE_PROJECTS='clang-tools-extra;lld' \
+//   -DCMAKE_EXPORT_COMPILE_COMMANDS=On \
+//   ../llvm
+//   $ ninja
+//   $ bin/clang-llvm-rename ../lld/**/*.{cpp,h}
+//
+// For each variable in given files, the tool first check whether the
+// variable's definition is in one of given files or not, and rename it if
+// and only if it can find a definition of the variable. If the tool cannot
+// modify a definition of a variable, it doesn't rename it, in order to keep
+// a program compiles.
+//
+// Note that this tool is not perfect; it doesn't resolve or even detect
+// name conflicts caused by renaming. You may need to rename variables
+// before using this tool so that your program is free from name conflicts
+// due to lowercase/uppercase renaming.
+//
+//===--===//
+
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Execution.h"
+#include "clang/Tooling/Refactoring.h"
+#include "clang/Tooling/Refactoring/AtomicChange.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Signals.h"
+
+using namespace clang;
+using namespace clang::ast_matchers;
+using namespace clang::tooling;
+using namespace llvm;
+
+namespace {
+class RenameCallback : public MatchFinder::MatchCallback {
+public:
+  RenameCallback(
+  std::map ,
+  ArrayRef Paths)
+  : FileToReplacements(FileToReplacements) {
+for (StringRef S : Paths)
+  InputFiles.insert(canonicalizePath(S));
+  }
+
+  // This function is called for each AST pattern matche.
+  void run(const MatchFinder::MatchResult ) override {
+SourceManager  = *Result.SourceManager;
+
+if (auto *D = Result.Nodes.getNodeAs("VarDecl")) {
+  if (isa(D))
+return;
+  if (isGlobalConst(D))
+return;
+  convert(SM, D->getLocation(), D->getName());
+  return;
+}
+
+if (auto *D = Result.Nodes.getNodeAs("ParmVarDecl")) {
+  if (auto *Fn =
+  dyn_cast_or_null(D->getParentFunctionOrMethod()))
+if (Fn->isImplicit())
+  return;
+  convert(SM, D->getLocation(), "");
+  return;
+}
+
+if (auto *D = Result.Nodes.getNodeAs("FieldDecl")) {
+  convert(SM, D->getLocation(), "");
+  return;
+}
+
+if (auto *D = Result.Nodes.getNodeAs("DeclRefExpr")) {
+  if (!isInGivenFiles(SM, D->getFoundDecl()->getLocation()))
+return;
+  if (isa(D->getDecl()) ||
+  isa(D->getDecl()))
+return;
+  if (auto *Decl = dyn_cast(D->getFoundDecl()))
+if (isGlobalConst(Decl))
+  return;
+  if (D->getDecl()->getName().empty())
+return;
+  convert(SM, D->getLocation(), "");
+  return;
+}
+
+if (auto *D = 

[PATCH] D64400: [OpenCL][PR42390] Deduce addr space for templ specialization

2019-07-10 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: include/clang/AST/Type.h:6512
+inline bool Type::isTemplateSpecializationType() const {
+  return isa(this);
+}

This is a sugar type.  What are you trying to do?



Comment at: lib/Sema/SemaType.cpp:7417
   // up instantiating to a type with an explicit address space qualifier.
-  // Expect for pointer or reference types because the addr space in
-  // template argument can only belong to a pointee.
-  (T->isDependentType() && !T->isPointerType() && !T->isReferenceType()) ||
+  // Expect for:
+  // - pointer or reference types because the addr space in template

"Except"?



Comment at: lib/Sema/SemaType.cpp:7421
+  // - template specialization as addr space in template argument doesn't
+  //   affect specialization.
+  (T->isDependentType() && (!T->isPointerType() && !T->isReferenceType() &&

I don't understand what you're saying here.  Why does inference depend on 
whether the type is a template specialization?  And what does this have to do 
with template arguments?  Also, address spaces in template arguments are 
definitely part of the template argument and affect which specialization you're 
naming.


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

https://reviews.llvm.org/D64400



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


[PATCH] D62584: [OpenCL][PR42033] Deducing addr space with template parameter types

2019-07-10 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/TreeTransform.h:5363
+if (ResultType.getAddressSpace() != LangAS::Default &&
+(ResultType.getAddressSpace() != LangAS::opencl_private)) {
   SemaRef.Diag(TL.getReturnLoc().getBeginLoc(),

Anastasia wrote:
> Anastasia wrote:
> > rjmccall wrote:
> > > Anastasia wrote:
> > > > I am trying to be a bit more helpful here although I am not sure if we 
> > > > should instead require explicit template parameter and fail the 
> > > > template deduction instead.
> > > > 
> > > > Basically, do we want the following code to always require specifying 
> > > > template argument explicitly:
> > > > 
> > > > 
> > > > ```
> > > > template 
> > > > T xxx(T *in) {
> > > >   T *i = in;
> > > >   return *i;
> > > > }
> > > > 
> > > > __kernel void test() {
> > > >   int foo[10];
> > > >   xxx([0]); // if we deduce type from foo, it ends up being 
> > > > qualified by __private that we currently diagnose. However private is 
> > > > default (implicit) address space for return type so technically there 
> > > > is no danger in just allowing xxx([0])
> > > > }
> > > > ```
> > > Implicitly ignoring all address-space qualifiers on the return type seems 
> > > like the right thing to do; I don't think it needs to be limited to 
> > > `__private`.  That's probably also the right thing to do for locals, but 
> > > I'm less certain about it.
> > Just to clarify by "Implicitly ignoring" you mean ignoring if the templ 
> > parameters were deduced?
> > 
> > Although I am a bit concerned about allowing other than `__private` address 
> > spaces in return types as we reject them in return types of functions 
> > generally. Would it not be somehow inconsistent?
> Ok, I have removed the diagnostic completely. At least we don't seem to 
> generate any incorrect IR.
They should be diagnosed somehow when written explicitly on a return type, but 
if you just do that on the parser path you don't have to worry about it during 
template instantiation.  They should probably otherwise be ignored no matter 
where they came from — if someone typedefs `private_int_t` to `__private int`, 
you should just treat that as `int` in a return type.  Stripping the qualifier 
from the type is probably the right thing to do so that it doesn't further 
impact semantic analysis.

I definitely don't think you want a model where the qualifier actually means 
that the return is somehow done via an object in that address space.


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

https://reviews.llvm.org/D62584



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


[PATCH] D58418: [clang][DirectoryWatcher] Upstream DirectoryWatcher

2019-07-10 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added subscribers: beanz, smeenai.
smeenai added a comment.

In D58418#1577349 , @jkorous wrote:

> Thanks for the revert.
>
> There's actually one more problem - seems like ninja doesn't like the 
> generated build.ninja file on Linux.
>
>   ninja: error: build.ninja:52390: bad $-escape (literal $ must be written as 
> $$)
>
>
> http://lab.llvm.org:8011/builders/clang-with-lto-ubuntu/builds/13617/steps/build-stage1-compiler/logs/stdio


We ran into this as well, and I was curious about what was going on, so I dug 
into it.

When you add a private dependency to static library target, as you're doing in 
this change with `${DIRECTORY_WATCHER_LINK_LIBS}`, CMake adds the dependency to 
the target's INTERFACE_LINK_LIBRARIES property using the `$` 
generator expression. The code for clang-shlib iterates through all the clang 
libraries and uses generator expressions to gather their 
INTERFACE_LINK_LIBRARIES, but if those generator expressions themselves 
evaluate to generator expressions (`$` in this case), the second 
level of generator expressions won't get evaluated and will just end up in the 
ninja file directly, hence the complaint about the dollar. The clang-shlib code 
in question is 
https://github.com/llvm/llvm-project/blob/3837f4273fcc40cc519035479aefe78e5cbd3055/clang/tools/clang-shlib/CMakeLists.txt#L10.

Here's a simple repro (where `empty.c` is literally an empty file). Running 
`cmake -G Ninja` on this and then running `ninja` should demonstrate the issue.

  cmake_minimum_required(VERSION 3.4.3)
  project(dollartest C)
  
  add_library(a STATIC empty.c)
  add_library(b_obj OBJECT empty.c)
  add_library(b STATIC empty.c)
  target_link_libraries(b PRIVATE a)
  
  add_library(c SHARED empty.c)
  target_link_libraries(c PRIVATE
b_object
$
$
)

@beanz, thoughts on how best to handle this?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D58418



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


<    1   2   3