[PATCH] D50945: [Lex] Make HeaderMaps a unique_ptr vector

2018-08-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: Eugene.Zelenko, dblaikie.
Herald added a subscriber: cfe-commits.

unique_ptr makes the ownership clearer than a raw pointer container.


Repository:
  rC Clang

https://reviews.llvm.org/D50945

Files:
  include/clang/Lex/HeaderMap.h
  include/clang/Lex/HeaderSearch.h
  lib/Lex/HeaderMap.cpp
  lib/Lex/HeaderSearch.cpp

Index: lib/Lex/HeaderSearch.cpp
===
--- lib/Lex/HeaderSearch.cpp
+++ lib/Lex/HeaderSearch.cpp
@@ -75,12 +75,6 @@
   FileMgr(SourceMgr.getFileManager()), FrameworkMap(64),
   ModMap(SourceMgr, Diags, LangOpts, Target, *this) {}
 
-HeaderSearch::~HeaderSearch() {
-  // Delete headermaps.
-  for (unsigned i = 0, e = HeaderMaps.size(); i != e; ++i)
-delete HeaderMaps[i].second;
-}
-
 void HeaderSearch::PrintStats() {
   fprintf(stderr, "\n*** HeaderSearch Stats:\n");
   fprintf(stderr, "%d files tracked.\n", (int)FileInfo.size());
@@ -113,12 +107,12 @@
   // Pointer equality comparison of FileEntries works because they are
   // already uniqued by inode.
   if (HeaderMaps[i].first == FE)
-return HeaderMaps[i].second;
+return HeaderMaps[i].second.get();
   }
 
-  if (const HeaderMap *HM = HeaderMap::Create(FE, FileMgr)) {
-HeaderMaps.push_back(std::make_pair(FE, HM));
-return HM;
+  if (std::unique_ptr HM = HeaderMap::Create(FE, FileMgr)) {
+HeaderMaps.emplace_back(FE, std::move(HM));
+return HeaderMaps.back().second.get();
   }
 
   return nullptr;
Index: lib/Lex/HeaderMap.cpp
===
--- lib/Lex/HeaderMap.cpp
+++ lib/Lex/HeaderMap.cpp
@@ -48,7 +48,8 @@
 /// map.  If it doesn't look like a HeaderMap, it gives up and returns null.
 /// If it looks like a HeaderMap but is obviously corrupted, it puts a reason
 /// into the string error argument and returns null.
-const HeaderMap *HeaderMap::Create(const FileEntry *FE, FileManager &FM) {
+std::unique_ptr HeaderMap::Create(const FileEntry *FE,
+ FileManager &FM) {
   // If the file is too small to be a header map, ignore it.
   unsigned FileSize = FE->getSize();
   if (FileSize <= sizeof(HMapHeader)) return nullptr;
@@ -59,7 +60,7 @@
   bool NeedsByteSwap;
   if (!checkHeader(**FileBuffer, NeedsByteSwap))
 return nullptr;
-  return new HeaderMap(std::move(*FileBuffer), NeedsByteSwap);
+  return std::unique_ptr(new HeaderMap(std::move(*FileBuffer), NeedsByteSwap));
 }
 
 bool HeaderMapImpl::checkHeader(const llvm::MemoryBuffer &File,
Index: include/clang/Lex/HeaderSearch.h
===
--- include/clang/Lex/HeaderSearch.h
+++ include/clang/Lex/HeaderSearch.h
@@ -17,6 +17,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/DirectoryLookup.h"
+#include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/ModuleMap.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -38,7 +39,6 @@
 class ExternalPreprocessorSource;
 class FileEntry;
 class FileManager;
-class HeaderMap;
 class HeaderSearchOptions;
 class IdentifierInfo;
 class LangOptions;
@@ -226,9 +226,8 @@
   llvm::StringMap;
   std::unique_ptr IncludeAliases;
 
-  /// HeaderMaps - This is a mapping from FileEntry -> HeaderMap, uniquing
-  /// headermaps.  This vector owns the headermap.
-  std::vector> HeaderMaps;
+  /// This is a mapping from FileEntry -> HeaderMap, uniquing headermaps.
+  std::vector>> HeaderMaps;
 
   /// The mapping between modules and headers.
   mutable ModuleMap ModMap;
@@ -264,7 +263,6 @@
const LangOptions &LangOpts, const TargetInfo *Target);
   HeaderSearch(const HeaderSearch &) = delete;
   HeaderSearch &operator=(const HeaderSearch &) = delete;
-  ~HeaderSearch();
 
   /// Retrieve the header-search options with which this header search
   /// was initialized.
Index: include/clang/Lex/HeaderMap.h
===
--- include/clang/Lex/HeaderMap.h
+++ include/clang/Lex/HeaderMap.h
@@ -71,7 +71,8 @@
 public:
   /// This attempts to load the specified file as a header map.  If it doesn't
   /// look like a HeaderMap, it gives up and returns null.
-  static const HeaderMap *Create(const FileEntry *FE, FileManager &FM);
+  static std::unique_ptr Create(const FileEntry *FE,
+   FileManager &FM);
 
   /// Check to see if the specified relative filename is located in this
   /// HeaderMap.  If so, open it and return its FileEntry.  If RawPath is not
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50945: [Lex] Make HeaderMaps a unique_ptr vector

2018-08-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D50945



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


[PATCH] D50945: [Lex] Make HeaderMaps a unique_ptr vector

2018-08-20 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC340198: [Lex] Make HeaderMaps a unique_ptr vector (authored 
by MaskRay, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50945?vs=161391&id=161530#toc

Repository:
  rC Clang

https://reviews.llvm.org/D50945

Files:
  include/clang/Lex/HeaderMap.h
  include/clang/Lex/HeaderSearch.h
  lib/Lex/HeaderMap.cpp
  lib/Lex/HeaderSearch.cpp

Index: lib/Lex/HeaderMap.cpp
===
--- lib/Lex/HeaderMap.cpp
+++ lib/Lex/HeaderMap.cpp
@@ -48,7 +48,8 @@
 /// map.  If it doesn't look like a HeaderMap, it gives up and returns null.
 /// If it looks like a HeaderMap but is obviously corrupted, it puts a reason
 /// into the string error argument and returns null.
-const HeaderMap *HeaderMap::Create(const FileEntry *FE, FileManager &FM) {
+std::unique_ptr HeaderMap::Create(const FileEntry *FE,
+ FileManager &FM) {
   // If the file is too small to be a header map, ignore it.
   unsigned FileSize = FE->getSize();
   if (FileSize <= sizeof(HMapHeader)) return nullptr;
@@ -59,7 +60,7 @@
   bool NeedsByteSwap;
   if (!checkHeader(**FileBuffer, NeedsByteSwap))
 return nullptr;
-  return new HeaderMap(std::move(*FileBuffer), NeedsByteSwap);
+  return std::unique_ptr(new HeaderMap(std::move(*FileBuffer), NeedsByteSwap));
 }
 
 bool HeaderMapImpl::checkHeader(const llvm::MemoryBuffer &File,
Index: lib/Lex/HeaderSearch.cpp
===
--- lib/Lex/HeaderSearch.cpp
+++ lib/Lex/HeaderSearch.cpp
@@ -75,12 +75,6 @@
   FileMgr(SourceMgr.getFileManager()), FrameworkMap(64),
   ModMap(SourceMgr, Diags, LangOpts, Target, *this) {}
 
-HeaderSearch::~HeaderSearch() {
-  // Delete headermaps.
-  for (unsigned i = 0, e = HeaderMaps.size(); i != e; ++i)
-delete HeaderMaps[i].second;
-}
-
 void HeaderSearch::PrintStats() {
   fprintf(stderr, "\n*** HeaderSearch Stats:\n");
   fprintf(stderr, "%d files tracked.\n", (int)FileInfo.size());
@@ -113,12 +107,12 @@
   // Pointer equality comparison of FileEntries works because they are
   // already uniqued by inode.
   if (HeaderMaps[i].first == FE)
-return HeaderMaps[i].second;
+return HeaderMaps[i].second.get();
   }
 
-  if (const HeaderMap *HM = HeaderMap::Create(FE, FileMgr)) {
-HeaderMaps.push_back(std::make_pair(FE, HM));
-return HM;
+  if (std::unique_ptr HM = HeaderMap::Create(FE, FileMgr)) {
+HeaderMaps.emplace_back(FE, std::move(HM));
+return HeaderMaps.back().second.get();
   }
 
   return nullptr;
Index: include/clang/Lex/HeaderMap.h
===
--- include/clang/Lex/HeaderMap.h
+++ include/clang/Lex/HeaderMap.h
@@ -71,7 +71,8 @@
 public:
   /// This attempts to load the specified file as a header map.  If it doesn't
   /// look like a HeaderMap, it gives up and returns null.
-  static const HeaderMap *Create(const FileEntry *FE, FileManager &FM);
+  static std::unique_ptr Create(const FileEntry *FE,
+   FileManager &FM);
 
   /// Check to see if the specified relative filename is located in this
   /// HeaderMap.  If so, open it and return its FileEntry.  If RawPath is not
Index: include/clang/Lex/HeaderSearch.h
===
--- include/clang/Lex/HeaderSearch.h
+++ include/clang/Lex/HeaderSearch.h
@@ -17,6 +17,7 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/DirectoryLookup.h"
+#include "clang/Lex/HeaderMap.h"
 #include "clang/Lex/ModuleMap.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -38,7 +39,6 @@
 class ExternalPreprocessorSource;
 class FileEntry;
 class FileManager;
-class HeaderMap;
 class HeaderSearchOptions;
 class IdentifierInfo;
 class LangOptions;
@@ -226,9 +226,8 @@
   llvm::StringMap;
   std::unique_ptr IncludeAliases;
 
-  /// This is a mapping from FileEntry -> HeaderMap, uniquing
-  /// headermaps.  This vector owns the headermap.
-  std::vector> HeaderMaps;
+  /// This is a mapping from FileEntry -> HeaderMap, uniquing headermaps.
+  std::vector>> HeaderMaps;
 
   /// The mapping between modules and headers.
   mutable ModuleMap ModMap;
@@ -264,7 +263,6 @@
const LangOptions &LangOpts, const TargetInfo *Target);
   HeaderSearch(const HeaderSearch &) = delete;
   HeaderSearch &operator=(const HeaderSearch &) = delete;
-  ~HeaderSearch();
 
   /// Retrieve the header-search options with which this header search
   /// was initialized.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51109: [cc1][cc1as] Call OptTable::PrintHelp with explicit " [options] "

2018-08-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: rupprecht, alexshap, jhenderson.
Herald added a subscriber: cfe-commits.

This is to accommodate a change in llvm/lib/Option/OptTable.cpp 
https://reviews.llvm.org/D51009


Repository:
  rC Clang

https://reviews.llvm.org/D51109

Files:
  lib/FrontendTool/ExecuteCompilerInvocation.cpp
  tools/driver/cc1as_main.cpp


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -534,7 +534,8 @@
 
   if (Asm.ShowHelp) {
 std::unique_ptr Opts(driver::createDriverOptTable());
-Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
+Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] ",
+"Clang Integrated Assembler",
 /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
 /*ShowAllAliases=*/false);
 return 0;
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -182,7 +182,7 @@
   // Honor -help.
   if (Clang->getFrontendOpts().ShowHelp) {
 std::unique_ptr Opts = driver::createDriverOptTable();
-Opts->PrintHelp(llvm::outs(), "clang -cc1",
+Opts->PrintHelp(llvm::outs(), "clang -cc1 [options] ",
 "LLVM 'Clang' Compiler: http://clang.llvm.org";,
 /*Include=*/driver::options::CC1Option,
 /*Exclude=*/0, /*ShowAllAliases=*/false);


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -534,7 +534,8 @@
 
   if (Asm.ShowHelp) {
 std::unique_ptr Opts(driver::createDriverOptTable());
-Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
+Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] ",
+"Clang Integrated Assembler",
 /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
 /*ShowAllAliases=*/false);
 return 0;
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -182,7 +182,7 @@
   // Honor -help.
   if (Clang->getFrontendOpts().ShowHelp) {
 std::unique_ptr Opts = driver::createDriverOptTable();
-Opts->PrintHelp(llvm::outs(), "clang -cc1",
+Opts->PrintHelp(llvm::outs(), "clang -cc1 [options] ",
 "LLVM 'Clang' Compiler: http://clang.llvm.org";,
 /*Include=*/driver::options::CC1Option,
 /*Exclude=*/0, /*ShowAllAliases=*/false);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51109: [cc1][cc1as] Call OptTable::PrintHelp with explicit " [options] "

2018-08-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 162478.
MaskRay added a comment.
Herald added subscribers: atanasyan, jrtc27, sdardis.

[Driver] Change MipsLinux default linker from "lld" to "ld.lld"


Repository:
  rC Clang

https://reviews.llvm.org/D51109

Files:
  lib/Driver/ToolChains/MipsLinux.h
  lib/FrontendTool/ExecuteCompilerInvocation.cpp
  tools/driver/cc1as_main.cpp


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -534,7 +534,8 @@
 
   if (Asm.ShowHelp) {
 std::unique_ptr Opts(driver::createDriverOptTable());
-Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
+Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] ",
+"Clang Integrated Assembler",
 /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
 /*ShowAllAliases=*/false);
 return 0;
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -182,7 +182,7 @@
   // Honor -help.
   if (Clang->getFrontendOpts().ShowHelp) {
 std::unique_ptr Opts = driver::createDriverOptTable();
-Opts->PrintHelp(llvm::outs(), "clang -cc1",
+Opts->PrintHelp(llvm::outs(), "clang -cc1 [options] ",
 "LLVM 'Clang' Compiler: http://clang.llvm.org";,
 /*Include=*/driver::options::CC1Option,
 /*Exclude=*/0, /*ShowAllAliases=*/false);
Index: lib/Driver/ToolChains/MipsLinux.h
===
--- lib/Driver/ToolChains/MipsLinux.h
+++ lib/Driver/ToolChains/MipsLinux.h
@@ -49,7 +49,7 @@
   }
 
   const char *getDefaultLinker() const override {
-return "lld";
+return "ld.lld";
   }
 
 private:


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -534,7 +534,8 @@
 
   if (Asm.ShowHelp) {
 std::unique_ptr Opts(driver::createDriverOptTable());
-Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
+Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] ",
+"Clang Integrated Assembler",
 /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
 /*ShowAllAliases=*/false);
 return 0;
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -182,7 +182,7 @@
   // Honor -help.
   if (Clang->getFrontendOpts().ShowHelp) {
 std::unique_ptr Opts = driver::createDriverOptTable();
-Opts->PrintHelp(llvm::outs(), "clang -cc1",
+Opts->PrintHelp(llvm::outs(), "clang -cc1 [options] ",
 "LLVM 'Clang' Compiler: http://clang.llvm.org";,
 /*Include=*/driver::options::CC1Option,
 /*Exclude=*/0, /*ShowAllAliases=*/false);
Index: lib/Driver/ToolChains/MipsLinux.h
===
--- lib/Driver/ToolChains/MipsLinux.h
+++ lib/Driver/ToolChains/MipsLinux.h
@@ -49,7 +49,7 @@
   }
 
   const char *getDefaultLinker() const override {
-return "lld";
+return "ld.lld";
   }
 
 private:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51234: [Driver] Change MipsLinux default linker from "lld" to "ld.lld"

2018-08-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added a reviewer: kzhuravl.
Herald added subscribers: cfe-commits, atanasyan, jrtc27, arichardson, sdardis.

Repository:
  rC Clang

https://reviews.llvm.org/D51234

Files:
  lib/Driver/ToolChains/MipsLinux.h


Index: lib/Driver/ToolChains/MipsLinux.h
===
--- lib/Driver/ToolChains/MipsLinux.h
+++ lib/Driver/ToolChains/MipsLinux.h
@@ -49,7 +49,7 @@
   }
 
   const char *getDefaultLinker() const override {
-return "lld";
+return "ld.lld";
   }
 
 private:


Index: lib/Driver/ToolChains/MipsLinux.h
===
--- lib/Driver/ToolChains/MipsLinux.h
+++ lib/Driver/ToolChains/MipsLinux.h
@@ -49,7 +49,7 @@
   }
 
   const char *getDefaultLinker() const override {
-return "lld";
+return "ld.lld";
   }
 
 private:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51109: [cc1][cc1as] Call OptTable::PrintHelp with explicit " [options] "

2018-08-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 162488.
MaskRay added a comment.

Sorry I messed up with my branches :( I shall create 
https://reviews.llvm.org/D51234 but arc diff'ed to a different one


Repository:
  rC Clang

https://reviews.llvm.org/D51109

Files:
  lib/FrontendTool/ExecuteCompilerInvocation.cpp
  tools/driver/cc1as_main.cpp


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -534,7 +534,8 @@
 
   if (Asm.ShowHelp) {
 std::unique_ptr Opts(driver::createDriverOptTable());
-Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
+Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] ",
+"Clang Integrated Assembler",
 /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
 /*ShowAllAliases=*/false);
 return 0;
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -182,7 +182,7 @@
   // Honor -help.
   if (Clang->getFrontendOpts().ShowHelp) {
 std::unique_ptr Opts = driver::createDriverOptTable();
-Opts->PrintHelp(llvm::outs(), "clang -cc1",
+Opts->PrintHelp(llvm::outs(), "clang -cc1 [options] ",
 "LLVM 'Clang' Compiler: http://clang.llvm.org";,
 /*Include=*/driver::options::CC1Option,
 /*Exclude=*/0, /*ShowAllAliases=*/false);


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -534,7 +534,8 @@
 
   if (Asm.ShowHelp) {
 std::unique_ptr Opts(driver::createDriverOptTable());
-Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
+Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] ",
+"Clang Integrated Assembler",
 /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
 /*ShowAllAliases=*/false);
 return 0;
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -182,7 +182,7 @@
   // Honor -help.
   if (Clang->getFrontendOpts().ShowHelp) {
 std::unique_ptr Opts = driver::createDriverOptTable();
-Opts->PrintHelp(llvm::outs(), "clang -cc1",
+Opts->PrintHelp(llvm::outs(), "clang -cc1 [options] ",
 "LLVM 'Clang' Compiler: http://clang.llvm.org";,
 /*Include=*/driver::options::CC1Option,
 /*Exclude=*/0, /*ShowAllAliases=*/false);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51234: [Driver] Change MipsLinux default linker from "lld" to "ld.lld"

2018-08-26 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340709: [Driver] Change MipsLinux default linker from 
"lld" to "ld.lld" (authored by MaskRay, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D51234

Files:
  cfe/trunk/lib/Driver/ToolChains/MipsLinux.h


Index: cfe/trunk/lib/Driver/ToolChains/MipsLinux.h
===
--- cfe/trunk/lib/Driver/ToolChains/MipsLinux.h
+++ cfe/trunk/lib/Driver/ToolChains/MipsLinux.h
@@ -49,7 +49,7 @@
   }
 
   const char *getDefaultLinker() const override {
-return "lld";
+return "ld.lld";
   }
 
 private:


Index: cfe/trunk/lib/Driver/ToolChains/MipsLinux.h
===
--- cfe/trunk/lib/Driver/ToolChains/MipsLinux.h
+++ cfe/trunk/lib/Driver/ToolChains/MipsLinux.h
@@ -49,7 +49,7 @@
   }
 
   const char *getDefaultLinker() const override {
-return "lld";
+return "ld.lld";
   }
 
 private:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51109: [cc1][cc1as] Call OptTable::PrintHelp with explicit " [options] "

2018-08-30 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Ping


Repository:
  rC Clang

https://reviews.llvm.org/D51109



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


[PATCH] D49722: [CStringSyntaxChecker] Check strlcat sizeof check

2018-09-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp:164
+  // - sizeof(dst)
+  if (Append && isSizeof(LenArg, DstArg))
+return true;

george.karpenkov wrote:
> george.karpenkov wrote:
> > george.karpenkov wrote:
> > > I am confused on what is happening in this branch and why is it bad. 
> > > Could we add a commend?
> > Sorry I'm still confused about this branch: could you clarify?
> Ah, OK, I see it needs one more byte due to null-termination.
I think the `if (isSizeof(LenArg, DstArg))` check is fine so it returns `false`.

`strlcat(dst, src, sizeof dst)` is good.



Comment at: lib/StaticAnalyzer/Checkers/CStringSyntaxChecker.cpp:199
+if (Append)
+  RemainingBufferLen -= 1;
+if (RemainingBufferLen < ILRawVal)

`RemainingBufferLen` is `uint64_t`. Can the `-= 1` overflow?


https://reviews.llvm.org/D49722



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


[PATCH] D49722: [CStringSyntaxChecker] Check strlcat sizeof check

2018-09-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: test/Analysis/cstring-syntax.c:49
+  strlcat(dest, "0123456789", badlen / 2);
+  strlcat(dest, "0123456789", badlen); // expected-warning {{The third 
argument allows to potentially copy more bytes than it should. Replace with the 
value 'badlen' - strlen(dest) - 1 or lower}}
+  strlcat(dest, "0123456789", badlen - strlen(dest) - 1);

devnexen wrote:
> NoQ wrote:
> > The suggested fix is a bit weird.
> > 
> > The correct code for appending `src` to `dst` is either `strlcat(dst, src, 
> > sizeof(dst));` (the approach suggested by the man page) or `strlcat(dst + 
> > strlen(dst) + 1, src, sizeof(dst) - strlen(dst) - 1)` (which is equivalent 
> > but faster if you already know `strlen(dst)`). In both cases you can 
> > specify a smaller value but not a larger value.
> In fact in this case the message is misleading/a bit wrong.
I think `strlcat` is very clumsy to you if you need to add an offset to 
`dest`...

For
`strlcat(dst + strlen(dst) + 1, src, sizeof(dst) - strlen(dst) - 1)`

I suppose you meant:

`strlcpy(dst + strlen(dst), src, sizeof(dst) - strlen(dst))`

... but the suggestion does not look very appealing. `strlcat(dst, ..., 
sizeof(dst)` if good enough as a suggested fix.


https://reviews.llvm.org/D49722



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


[PATCH] D50267: [ASTWriter] Use zlib::compress which operates on std::unique_ptr

2018-08-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: ruiu, rsmith.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D50267

Files:
  lib/Serialization/ASTWriter.cpp


Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -2207,14 +2207,17 @@
 
   // Compress the buffer if possible. We expect that almost all PCM
   // consumers will not want its contents.
-  SmallString<0> CompressedBuffer;
+  std::unique_ptr CompressedData;
+  size_t CompressedSize;
   if (llvm::zlib::isAvailable()) {
-llvm::Error E = llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer);
+llvm::Error E =
+llvm::zlib::compress(Blob.drop_back(1), CompressedData, 
CompressedSize);
 if (!E) {
   RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED,
  Blob.size() - 1};
-  Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
-CompressedBuffer);
+  Stream.EmitRecordWithBlob(
+  SLocBufferBlobCompressedAbbrv, Record,
+  StringRef((char *)CompressedData.get(), CompressedSize));
   return;
 }
 llvm::consumeError(std::move(E));


Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -2207,14 +2207,17 @@
 
   // Compress the buffer if possible. We expect that almost all PCM
   // consumers will not want its contents.
-  SmallString<0> CompressedBuffer;
+  std::unique_ptr CompressedData;
+  size_t CompressedSize;
   if (llvm::zlib::isAvailable()) {
-llvm::Error E = llvm::zlib::compress(Blob.drop_back(1), CompressedBuffer);
+llvm::Error E =
+llvm::zlib::compress(Blob.drop_back(1), CompressedData, CompressedSize);
 if (!E) {
   RecordDataType Record[] = {SM_SLOC_BUFFER_BLOB_COMPRESSED,
  Blob.size() - 1};
-  Stream.EmitRecordWithBlob(SLocBufferBlobCompressedAbbrv, Record,
-CompressedBuffer);
+  Stream.EmitRecordWithBlob(
+  SLocBufferBlobCompressedAbbrv, Record,
+  StringRef((char *)CompressedData.get(), CompressedSize));
   return;
 }
 llvm::consumeError(std::move(E));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50267: [ASTWriter] Use zlib::compress which operates on std::unique_ptr

2018-08-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

This depends on https://reviews.llvm.org/D50223


Repository:
  rC Clang

https://reviews.llvm.org/D50267



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


[PATCH] D50267: [ASTWriter] Use zlib::compress which operates on std::unique_ptr

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

https://reviews.llvm.org/D50223 has been changed to improve zlib::compress's 
current SmallVectorImpl interface. This is no longer relevant.


Repository:
  rC Clang

https://reviews.llvm.org/D50267



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


[PATCH] D50294: [Driver] Use -gdwarf-3 by default for FreeBSD

2018-08-04 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: brad, emaste, khng300.
Herald added subscribers: cfe-commits, JDevlieghere, aprantl.

The imported binutils in base supports DWARF 3.


Repository:
  rC Clang

https://reviews.llvm.org/D50294

Files:
  lib/Driver/ToolChains/FreeBSD.h
  test/CodeGen/dwarf-version.c
  test/Driver/clang-g-opts.c
  test/Driver/debug-options.c


Index: test/Driver/debug-options.c
===
--- test/Driver/debug-options.c
+++ test/Driver/debug-options.c
@@ -105,15 +105,15 @@
 // RUN: %clang -### -c -gline-tables-only %s -target i686-pc-openbsd 2>&1 \
 // RUN: | FileCheck -check-prefix=GLTO_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-tables-only %s -target x86_64-pc-freebsd10.0 
2>&1 \
-// RUN: | FileCheck -check-prefix=GLTO_ONLY_DWARF2 %s
+// RUN: | FileCheck -check-prefix=GLTO_ONLY_DWARF3 %s
 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-linux-gnu 2>&1 \
 // RUN: | FileCheck -check-prefix=G_ONLY %s
 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-apple-darwin16 
2>&1 \
 // RUN: | FileCheck -check-prefix=G_STANDALONE 
-check-prefix=G_DWARF4 %s
 // RUN: %clang -### -c -gline-tables-only -g %s -target i686-pc-openbsd 2>&1 \
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-pc-freebsd10.0 
2>&1 \
-// RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
+// RUN: | FileCheck -check-prefix=G_ONLY_DWARF3 %s
 // RUN: %clang -### -c -gline-tables-only -g %s -target i386-pc-solaris 2>&1 \
 // RUN: | FileCheck -check-prefix=G_ONLY_DWARF2 %s
 // RUN: %clang -### -c -gline-tables-only -g0 %s 2>&1 \
@@ -195,6 +195,10 @@
 // GLTO_ONLY_DWARF2: "-debug-info-kind=line-tables-only"
 // GLTO_ONLY_DWARF2: "-dwarf-version=2"
 //
+// GLTO_ONLY_DWARF3: "-cc1"
+// GLTO_ONLY_DWARF3: "-debug-info-kind=line-tables-only"
+// GLTO_ONLY_DWARF3: "-dwarf-version=3"
+//
 // G_ONLY: "-cc1"
 // G_ONLY: "-debug-info-kind=limited"
 //
@@ -204,6 +208,10 @@
 // G_ONLY_DWARF2: "-debug-info-kind={{standalone|limited}}"
 // G_ONLY_DWARF2: "-dwarf-version=2"
 //
+// G_ONLY_DWARF3: "-cc1"
+// G_ONLY_DWARF3: "-debug-info-kind={{standalone|limited}}"
+// G_ONLY_DWARF3: "-dwarf-version=3"
+//
 // G_STANDALONE: "-cc1"
 // G_STANDALONE: "-debug-info-kind=standalone"
 // G_DWARF4: "-dwarf-version=4"
Index: test/Driver/clang-g-opts.c
===
--- test/Driver/clang-g-opts.c
+++ test/Driver/clang-g-opts.c
@@ -8,7 +8,7 @@
 // RUN: %clang -### -S %s -g -target i686-pc-openbsd 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 // RUN: %clang -### -S %s -g -target x86_64-pc-freebsd10.0 2>&1 \
-// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF3 %s
 
 // 'g0' is the default. Just sanity-test that it does nothing
 // RUN: %clang -### -S %s -g02>&1 | FileCheck 
--check-prefix=CHECK-WITHOUT-G %s
@@ -26,14 +26,15 @@
 // RUN: %clang -### -S %s -g0 -g -target i686-pc-openbsd 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 // RUN: %clang -### -S %s -g0 -g -target x86_64-pc-freebsd10.0 2>&1 \
-// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
+// RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF3 %s
 // RUN: %clang -### -S %s -g0 -g -target i386-pc-solaris 2>&1 \
 // RUN: | FileCheck --check-prefix=CHECK-WITH-G-DWARF2 %s
 
 // CHECK-WITHOUT-G-NOT: -debug-info-kind
 // CHECK-WITH-G: "-debug-info-kind=limited"
 // CHECK-WITH-G: "-dwarf-version=4"
 // CHECK-WITH-G-DWARF2: "-dwarf-version=2"
+// CHECK-WITH-G-DWARF3: "-dwarf-version=3"
 
 // CHECK-WITH-G-STANDALONE: "-debug-info-kind=standalone"
 // CHECK-WITH-G-STANDALONE: "-dwarf-version=2"
Index: test/CodeGen/dwarf-version.c
===
--- test/CodeGen/dwarf-version.c
+++ test/CodeGen/dwarf-version.c
@@ -12,7 +12,7 @@
 // RUN: %clang -target x86_64-apple-darwin14 -g -S -emit-llvm -o - %s 
-isysroot %t | FileCheck %s --check-prefix=VER2
 
 // RUN: %clang -target powerpc-unknown-openbsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER2
-// RUN: %clang -target powerpc-unknown-freebsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER2
+// RUN: %clang -target powerpc-unknown-freebsd -g -S -emit-llvm -o - %s | 
FileCheck %s --check-prefix=VER3
 // RUN: %clang -target i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck %s 
--check-prefix=VER2
 //
 // Test what -gcodeview and -gdwarf do on Windows.
Index: lib/Driver/ToolChains/FreeBSD.h
===
--- lib/Driver/ToolChains/FreeBSD.h
+++ lib/Driver/ToolChains/FreeBSD.h
@@ -70,7 +70,7 @@
   const llvm::opt::Ar

[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133038.
MaskRay added a comment.

Update c-index-test.c and clang/test/Index tests


Repository:
  rC Clang

https://reviews.llvm.org/D42895

Files:
  include/clang-c/Index.h
  test/Index/index-decls.m
  test/Index/index-refs.cpp
  test/Index/index-subscripting-literals.m
  tools/c-index-test/c-index-test.c
  tools/libclang/CXIndexDataConsumer.cpp
  tools/libclang/CXIndexDataConsumer.h

Index: tools/libclang/CXIndexDataConsumer.h
===
--- tools/libclang/CXIndexDataConsumer.h
+++ tools/libclang/CXIndexDataConsumer.h
@@ -436,13 +436,15 @@
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool handleReference(const NamedDecl *D, SourceLocation Loc,
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool isNotFromSourceFile(SourceLocation Loc) const;
 
Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -148,6 +148,29 @@
 return true;
   }
 };
+
+CXSymbolRole getSymbolRole(SymbolRoleSet Roles) {
+  unsigned R = 0;
+  if (Roles & (unsigned)SymbolRole::Declaration)
+R |= CXSymbolRole_Declaration;
+  if (Roles & (unsigned)SymbolRole::Definition)
+R |= CXSymbolRole_Definition;
+  if (Roles & (unsigned)SymbolRole::Reference)
+R |= CXSymbolRole_Reference;
+  if (Roles & (unsigned)SymbolRole::Read)
+R |= CXSymbolRole_Read;
+  if (Roles & (unsigned)SymbolRole::Write)
+R |= CXSymbolRole_Write;
+  if (Roles & (unsigned)SymbolRole::Call)
+R |= CXSymbolRole_Call;
+  if (Roles & (unsigned)SymbolRole::Dynamic)
+R |= CXSymbolRole_Dynamic;
+  if (Roles & (unsigned)SymbolRole::AddressOf)
+R |= CXSymbolRole_AddressOf;
+  if (Roles & (unsigned)SymbolRole::Implicit)
+R |= CXSymbolRole_Implicit;
+  return CXSymbolRole(R);
+}
 }
 
 bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
@@ -184,6 +207,7 @@
 if (Roles & (unsigned)SymbolRole::Implicit) {
   Kind = CXIdxEntityRef_Implicit;
 }
+CXSymbolRole CXRole = getSymbolRole(Roles);
 
 CXCursor Cursor;
 if (ASTNode.OrigE) {
@@ -202,7 +226,7 @@
 }
 handleReference(ND, Loc, Cursor,
 dyn_cast_or_null(ASTNode.Parent),
-ASTNode.ContainerDC, ASTNode.OrigE, Kind);
+ASTNode.ContainerDC, ASTNode.OrigE, Kind, CXRole);
 
   } else {
 const DeclContext *LexicalDC = ASTNode.ContainerDC;
@@ -889,21 +913,23 @@
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
   : getRefCursor(D, Loc);
-  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind);
+  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind, Role);
 }
 
 bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc,
   CXCursor Cursor,
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!CB.indexEntityReference)
 return false;
 
@@ -939,7 +965,8 @@
   getIndexLoc(Loc),
   &RefEntity,
   Parent ? &ParentEntity : nullptr,
-  &Container };
+  &Container,
+  Role };
   CB.indexEntityReference(ClientData, &Info);
   return true;
 }
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -3326,6 +3326,27 @@
   }
 }
 
+static void printSymbo

[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In https://reviews.llvm.org/D42895#998617, @yvvan wrote:

> I feel quite ok about this patch.
>
> Can you please add unit-tests?


Added

  // CHECK:  [indexEntityReference]: kind: field | name: y | {{.*}} | loc: 
70:5 | {{.*}} | role: ref write
  // CHECK:  [indexEntityReference]: kind: field | name: x | {{.*}} | loc: 
70:11 | {{.*}} | role: ref read
  // CHECK:  [indexEntityReference]: kind: function | name: foo3 | {{.*}} | 
loc: 71:10 | {{.*}} | role: ref addressof
  // CHECK:  [indexEntityReference]: kind: function | name: foo4 | {{.*}} | 
loc: 72:3 | {{.*}} | role: ref call

to `clang/test/Index/index-refs.cpp`. I will implement read/write after this 
revision is landed.. https://github.com/cquery-project/cquery/issues/262


Repository:
  rC Clang

https://reviews.llvm.org/D42895



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


[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133050.
MaskRay added a comment.

Simplify


Repository:
  rC Clang

https://reviews.llvm.org/D42895

Files:
  include/clang-c/Index.h
  test/Index/index-decls.m
  test/Index/index-refs.cpp
  test/Index/index-subscripting-literals.m
  tools/c-index-test/c-index-test.c
  tools/libclang/CXIndexDataConsumer.cpp
  tools/libclang/CXIndexDataConsumer.h

Index: tools/libclang/CXIndexDataConsumer.h
===
--- tools/libclang/CXIndexDataConsumer.h
+++ tools/libclang/CXIndexDataConsumer.h
@@ -436,13 +436,15 @@
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool handleReference(const NamedDecl *D, SourceLocation Loc,
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool isNotFromSourceFile(SourceLocation Loc) const;
 
Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -148,6 +148,11 @@
 return true;
   }
 };
+
+CXSymbolRole getSymbolRole(SymbolRoleSet Role) {
+  // CXSymbolRole is synchronized with clang::index::SymbolRole.
+  return CXSymbolRole(static_cast(Role));
+}
 }
 
 bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
@@ -184,6 +189,7 @@
 if (Roles & (unsigned)SymbolRole::Implicit) {
   Kind = CXIdxEntityRef_Implicit;
 }
+CXSymbolRole CXRole = getSymbolRole(Roles);
 
 CXCursor Cursor;
 if (ASTNode.OrigE) {
@@ -202,7 +208,7 @@
 }
 handleReference(ND, Loc, Cursor,
 dyn_cast_or_null(ASTNode.Parent),
-ASTNode.ContainerDC, ASTNode.OrigE, Kind);
+ASTNode.ContainerDC, ASTNode.OrigE, Kind, CXRole);
 
   } else {
 const DeclContext *LexicalDC = ASTNode.ContainerDC;
@@ -889,21 +895,23 @@
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
   : getRefCursor(D, Loc);
-  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind);
+  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind, Role);
 }
 
 bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc,
   CXCursor Cursor,
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!CB.indexEntityReference)
 return false;
 
@@ -939,7 +947,8 @@
   getIndexLoc(Loc),
   &RefEntity,
   Parent ? &ParentEntity : nullptr,
-  &Container };
+  &Container,
+  Role };
   CB.indexEntityReference(ClientData, &Info);
   return true;
 }
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -3326,6 +3326,27 @@
   }
 }
 
+static void printSymbolRole(CXSymbolRole role) {
+  if (role & CXSymbolRole_Declaration)
+printf(" decl");
+  if (role & CXSymbolRole_Definition)
+printf(" def");
+  if (role & CXSymbolRole_Reference)
+printf(" ref");
+  if (role & CXSymbolRole_Read)
+printf(" read");
+  if (role & CXSymbolRole_Write)
+printf(" write");
+  if (role & CXSymbolRole_Call)
+printf(" call");
+  if (role & CXSymbolRole_Dynamic)
+printf(" dyn");
+  if (role & CXSymbolRole_AddressOf)
+printf(" addr");
+  if (role & CXSymbolRole_Implicit)
+printf(" implicit");
+}
+
 static void index_diagnostic(CXClientData client_data,
  CXDiagnosticSet diagSet, void *reserved) {

[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133051.
MaskRay added a comment.

.


Repository:
  rC Clang

https://reviews.llvm.org/D42895

Files:
  include/clang-c/Index.h
  test/Index/index-decls.m
  test/Index/index-refs.cpp
  test/Index/index-subscripting-literals.m
  tools/c-index-test/c-index-test.c
  tools/libclang/CXIndexDataConsumer.cpp
  tools/libclang/CXIndexDataConsumer.h

Index: tools/libclang/CXIndexDataConsumer.h
===
--- tools/libclang/CXIndexDataConsumer.h
+++ tools/libclang/CXIndexDataConsumer.h
@@ -436,13 +436,15 @@
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool handleReference(const NamedDecl *D, SourceLocation Loc,
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool isNotFromSourceFile(SourceLocation Loc) const;
 
Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -148,6 +148,11 @@
 return true;
   }
 };
+
+CXSymbolRole getSymbolRole(SymbolRoleSet Role) {
+  // CXSymbolRole is synchronized with clang::index::SymbolRole.
+  return CXSymbolRole(static_cast(Role));
+}
 }
 
 bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
@@ -184,6 +189,7 @@
 if (Roles & (unsigned)SymbolRole::Implicit) {
   Kind = CXIdxEntityRef_Implicit;
 }
+CXSymbolRole CXRole = getSymbolRole(Roles);
 
 CXCursor Cursor;
 if (ASTNode.OrigE) {
@@ -202,7 +208,7 @@
 }
 handleReference(ND, Loc, Cursor,
 dyn_cast_or_null(ASTNode.Parent),
-ASTNode.ContainerDC, ASTNode.OrigE, Kind);
+ASTNode.ContainerDC, ASTNode.OrigE, Kind, CXRole);
 
   } else {
 const DeclContext *LexicalDC = ASTNode.ContainerDC;
@@ -889,21 +895,23 @@
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
   : getRefCursor(D, Loc);
-  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind);
+  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind, Role);
 }
 
 bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc,
   CXCursor Cursor,
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!CB.indexEntityReference)
 return false;
 
@@ -939,7 +947,8 @@
   getIndexLoc(Loc),
   &RefEntity,
   Parent ? &ParentEntity : nullptr,
-  &Container };
+  &Container,
+  Role };
   CB.indexEntityReference(ClientData, &Info);
   return true;
 }
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -3326,6 +3326,27 @@
   }
 }
 
+static void printSymbolRole(CXSymbolRole role) {
+  if (role & CXSymbolRole_Declaration)
+printf(" decl");
+  if (role & CXSymbolRole_Definition)
+printf(" def");
+  if (role & CXSymbolRole_Reference)
+printf(" ref");
+  if (role & CXSymbolRole_Read)
+printf(" read");
+  if (role & CXSymbolRole_Write)
+printf(" write");
+  if (role & CXSymbolRole_Call)
+printf(" call");
+  if (role & CXSymbolRole_Dynamic)
+printf(" dyn");
+  if (role & CXSymbolRole_AddressOf)
+printf(" addr");
+  if (role & CXSymbolRole_Implicit)
+printf(" implicit");
+}
+
 static void index_diagnostic(CXClientData client_data,
  CXDiagnosticSet diagSet, void *reserved) {
   CXS

[PATCH] D42983: [clang-tidy] Add `readability-simd-intrinsics` check.

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
Herald added subscribers: cfe-commits, hintonda, kristof.beyls, xazax.hun, 
mgorny, aemerson, klimek.

Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
ARM NEON). It is common that SIMD code implementing the same algorithm, is
written in multiple target-dispatching pieces to optimize for different
architectures or micro-architectures.

The C++ standard proposal P0214 and its extensions cover many common SIMD
operations. By migrating from target-dependent intrinsics to P0214 operations,
the SIMD code can be simplified and pieces for different targets can be unified.

Refer to http://wg21.link/p0214 for introduction and motivation for the
data-parallel standard library.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst

Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - simd-readability-intrinsics
+
+simd-readability-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,37 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/readability-simd-intrinsics.html
+class SIMDIntrinsicsCheck : public ClangTidyCheck {
+public:
+  SIMDIntrinsicsCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+ private:
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
Index: clang-tidy/readability/SIMDIntrinsicsCheck.cpp
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.cpp
@@ -0,0 +1,127 @@
+//===--- SIMDIntrinsicsCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "SIMDIntrinsicsCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringMap

[PATCH] D42983: [clang-tidy] Add `readability-simd-intrinsics` check.

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133083.
MaskRay added a comment.

Add test/clang-tidy/readability-simd-intrinsics.cpp


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,32 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+// CHECK-MESSAGES: :[[@LINE+1]]:3: warning: '_mm_add_epi32' can be replaced by std::experimental::simd::operator+ [readability-simd-intrinsics]
+  _mm_add_epi32(i0, i1);
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - simd-readability-intrinsics
+
+simd-readability-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,37 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/readability-simd-intrinsics.html
+class SIMDIntrinsicsCheck : public ClangTidyCheck {
+public:
+  SIMDIntrinsicsCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+ private:
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
Index: clang-tidy/readability/SIMDIntrinsicsCheck.cpp
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.cpp
@@ -0,0 +1,132 @

[PATCH] D42983: [clang-tidy] Add `readability-simd-intrinsics` check.

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I haven't used clang-tidy before :) Do you have any suggestions on my workflow?

  % ninja -C ~/Dev/llvm/build clangTidyReadabilityModule
  % ~/Dev/llvm/build/bin/clang-tidy -checks='-*,readability-simd-intrinsics' 
a.cc
  # for local testing
  
  # Ensure tests are correct
  % PATH=~/Dev/llvm/build/bin:$PATH test/clang-tidy/check_clang_tidy.py 
test/clang-tidy/readability-simd-intrinsics.cpp readability-simd-intrinsics 
/tmp/t

I check `llvm::Triple::ArchType` to reduce number of target-dependent string 
matching. But in the test I don't know how to enable `-target ppc64le 
-maltivec` so that I can test PPC.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


[PATCH] D42983: [clang-tidy] Add `readability-simd-intrinsics` check.

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133091.
MaskRay added a comment.

Move CHECK-MESSAGES: to comform to the prevaling style


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by std::experimental::simd::operator+ [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - simd-readability-intrinsics
+
+simd-readability-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,37 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/readability-simd-intrinsics.html
+class SIMDIntrinsicsCheck : public ClangTidyCheck {
+public:
+  SIMDIntrinsicsCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+ private:
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
Index: clang-tidy/readability/SIMDIntrinsicsCheck.cpp
===
--- /dev/null
+++ clang-tidy/readability

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133107.
MaskRay marked 5 inline comments as done.
MaskRay added a comment.

LLVM Style


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by std::experimental::simd::operator+ [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - simd-readability-intrinsics
+
+simd-readability-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,37 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/readability-simd-intrinsics.html
+class SIMDIntrinsicsCheck : public ClangTidyCheck {
+public:
+  SIMDIntrinsicsCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+ private:
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
Index: clang-tidy/readability/SIMDIntrinsicsCheck.cpp
===
--- /dev/null
+++ clang-tidy/readability/S

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added inline comments.



Comment at: clang-tidy/readability/SIMDIntrinsicsCheck.cpp:77
+void SIMDIntrinsicsCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  
callExpr(callee(functionDecl(matchesName("^::(_mm_|_mm256_|_mm512_|vec_)"))),

Eugene.Zelenko wrote:
> You should enable this check only when compiling in appropriate C++ version. 
> See getLangOpts() usage in other checks.
Thx, I didn't know getLangOpts() before.

I think even in `-x c` mode, `::` is still the prefix of an identifier.

  matchesName("^(_mm_|_mm256_|_mm512_|vec_)")

doesn't match anything but 

  matchesName("^::(_mm_|_mm256_|_mm512_|vec_)")

matches.

verified via `clang-tidy -checks='-*,readability-simd-intrinsics' a.c -- -xc`



Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133109.
MaskRay added a comment.

Remove private section


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by std::experimental::simd::operator+ [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - simd-readability-intrinsics
+
+simd-readability-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,35 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/readability-simd-intrinsics.html
+class SIMDIntrinsicsCheck : public ClangTidyCheck {
+public:
+  SIMDIntrinsicsCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
Index: clang-tidy/readability/SIMDIntrinsicsCheck.cpp
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.cpp
@@ -0,0 +1,128 @@
+/

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133120.
MaskRay added a comment.

if (!Result.Context->getLangOpts().CPlusPlus11) return;


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by std::experimental::simd::operator+ [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - simd-readability-intrinsics
+
+simd-readability-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,35 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/readability-simd-intrinsics.html
+class SIMDIntrinsicsCheck : public ClangTidyCheck {
+public:
+  SIMDIntrinsicsCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
Index: clang-tidy/readability/SIMDIntrinsicsCheck.cpp
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrins

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133126.
MaskRay added a comment.

docs/ReleaseNotes.rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by std::experimental::simd::operator+ [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - simd-readability-intrinsics
+
+simd-readability-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -94,6 +94,12 @@
   `cppcoreguidelines-avoid-goto `_
   added.
 
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
+
 Improvements to include-fixer
 -
 
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,35 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/readability-simd-intrinsics.html
+class SIMDIntrinsicsCheck : public ClangTidyCheck {

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133133.
MaskRay marked an inline comment as done.
MaskRay added a comment.

docs/ReleaseNotes.rst and use StringRef::consume_front


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by std::experimental::simd::operator+ [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - simd-readability-intrinsics
+
+simd-readability-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,35 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives.
+///
+/// For the user-facin

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133134.
MaskRay marked 2 inline comments as done.
MaskRay added a comment.

Warning messages of operator+ as operator+ operator- .. are free functions on 
simd objects.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - simd-readability-intrinsics
+
+simd-readability-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,35 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find SIMD intrinsics calls and suggest std::experimental:

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133233.
MaskRay marked 2 inline comments as done.
MaskRay added a comment.

Fix word order of readability-simd-intrinsics


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,35 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives.
+///
+/// For the user-faci

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133237.
MaskRay added a comment.

Add check-specific option `Experimental`

  StringRef Std;
  if (Result.Context->getLangOpts().CPlusPlus2a) {
Std = "std";
  } else if (Result.Context->getLangOpts().CPlusPlus11 && Experimental) {
// libcxx implementation backports it to C++11 std::experimental::simd.
Std = "std::experimental";
  } else
return;


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,41 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTR

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133239.
MaskRay added a comment.

Use unnamed namespace to enclose AST_MATCHER and TrySuggest*


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,41 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find SIMD intrinsics calls and suggest std::experimental::simd alternatives.
+///
+/// For the user-facing documentation see:
+/// 

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked 2 inline comments as done.
MaskRay added inline comments.



Comment at: clang-tidy/readability/SIMDIntrinsicsCheck.cpp:75
+  // libcxx implementation of std::experimental::simd requires at least C++11.
+  if (!Result.Context->getLangOpts().CPlusPlus11)
+return;

lebedev.ri wrote:
> Is it reasonable to suggest to use ``?
> I would guess it should be `CPlusPlus2a`
Added a check-specific option `readability-simd-intrinsics.Experiment`.





Comment at: clang-tidy/readability/SIMDIntrinsicsCheck.cpp:84
+  // SIMD intrinsic call.
+  const FunctionDecl *Callee = Call->getDirectCallee();
+  if (!Callee)

lebedev.ri wrote:
> I would refactor this as astmatcher, at least a local one, e.g. something like
> ```
> AST_MATCHER(CallExpr, hasDirectCallee) {
>   return Node.getDirectCallee();
> }
> ```
> +
> ```
> void SIMDIntrinsicsCheck::registerMatchers(MatchFinder *Finder) {
>   Finder->addMatcher(
>   callExpr(callee(
> +allOf(
>  
> functionDecl(matchesName("^::(_mm_|_mm256_|_mm512_|vec_)")
> +  , hasDirectCallee()
> +)
>)),
>unless(isExpansionInSystemHeader()))
>   .bind("call"),
>   this);
> }
> ```
> Unless of course there is already a narrower that does that
```
AST_MATCHER(CallExpr, hasDirectCallee) {
  return Node.getDirectCallee();
}
```

looks too overkill and I still have to call `Call->getDirectCallee()` in 
`SIMDIntrinsicsCheck::check` and then `Callee->getName()`. I decide to keep it 
as is.


That said, I should also study why `AST_MATCHER(CallExpr, hasDirectCallee)` 
does not compile:
```
../tools/clang/tools/extra/clang-tidy/readability/SIMDIntrinsicsCheck.cpp:95:16:
 error: call to 'callee' is ambiguous
  callExpr(callee(allOf(functionDecl(allOf(
   ^~
../tools/clang/include/clang/ASTMatchers/ASTMatchers.h:2811:25: note: candidate 
function
AST_MATCHER_P(CallExpr, callee, internal::Matcher,
^
../tools/clang/include/clang/ASTMatchers/ASTMatchers.h:2827:34: note: candidate 
function
AST_MATCHER_P_OVERLOAD(CallExpr, callee, internal::Matcher, InnerMatcher,
```



Comment at: clang-tidy/readability/SIMDIntrinsicsCheck.cpp:87
+return;
+  bool IsVector = Callee->getReturnType()->isVectorType();
+  for (const ParmVarDecl *Parm : Callee->parameters()) {

lebedev.ri wrote:
> Same here, i *think* something like this would be better?
> ```
> AST_MATCHER(FunctionDecl, isVectorFunction) {
>  bool IsVector = Node.getReturnType()->isVectorType();
>   for (const ParmVarDecl *Parm : Node.parameters()) {
> QualType Type = Parm->getType();
> if (Type->isPointerType())
>   Type = Type->getPointeeType();
> if (Type->isVectorType())
>   IsVector = true;
> 
>   return IsVector;
> }
> ```
> +
> ```
> void SIMDIntrinsicsCheck::registerMatchers(MatchFinder *Finder) {
>   Finder->addMatcher(
>   callExpr(callee(
> allOf(
>  functionDecl(
> +   allOf(
>  matchesName("^::(_mm_|_mm256_|_mm512_|vec_)")
> + , isVectorFunction()
> +   )
>   , hasDirectCallee()
> )
>)),
>unless(isExpansionInSystemHeader()))
>   .bind("call"),
>   this);
> }
> ```
Thanks! Added isVectorFunction. I guess I may should use unnamed namespace for 
AST_MATCHER, but do I also need the unnamed namespace to enclose TrySuggestPPC 
and TrySuggestX86?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked 3 inline comments as done.
MaskRay added inline comments.



Comment at: clang-tidy/readability/SIMDIntrinsicsCheck.cpp:26
+
+  static const llvm::StringMap Mapping{
+// [simd.alg]

lebedev.ri wrote:
> You probably want to move `Mapping` out of the function.
Does keeping `  static const llvm::StringMap Mapping{ ... }` 
inside the function avoid a global constructor? The blacklist will surely be 
modified to cover more operations after the revision 



Comment at: clang-tidy/readability/SIMDIntrinsicsCheck.cpp:34
+{"sub", "operator- on std::experimental::simd objects"},
+{"mul", "operator* on std::experimental::simd objects"},
+  };

lebedev.ri wrote:
> To point the obvious, this is not exhaustive list, at least `div` is missing.
Yes, the blacklist will be modified to cover more instructions.

Another fun fact is that though `_mm_div_epi*` are listed in Intel's intrinsics 
guide, no there are no mapping hardware instructions and the functions only 
exist in ICC/ICPC (I guess) not in clang/lib/Headers/*.h



Comment at: clang-tidy/readability/SIMDIntrinsicsCheck.cpp:55
+  // [simd.binary]
+  if (Name.startswith("add_"))
+return "operator+ on std::experimental::simd objects";

lebedev.ri wrote:
> This function was not updated to use the `Mapping` map.
This is because on Power, these functions are overloaded `vec_add` `vec_sub` ...
But on x86, there are suffixes, e.g. `_mm_add_epi32`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked 2 inline comments as done.
MaskRay added inline comments.



Comment at: include/clang-c/Index.h:6159
+   */
+  CXSymbolRole role;
 } CXIdxEntityRefInfo;

ilya-biryukov wrote:
> Why do we need to store both `CXIdxEntityRefKind` and `CXSymbolRole`? Can we 
> store just `CXSymbolRole`?
> Is this for compatibility with existing clients?
> 
> If so, maybe we could:
> - remove `Implicit` and `Direct` from the `CXSymbolRole`
> - keep it only in `CXIdxEntityRefKind`
> - not deprecate the `CXIdxEntityRefKind`
I think `CXIdxEntityRefKind` should be deprecated but for compatibility we do 
not remove the field for this minor version upgrade. But they can be removed 
after a major version upgrade.

For what I have observed, `Implicit` is only used by Objective-C



Comment at: tools/libclang/CXIndexDataConsumer.cpp:154
+  // CXSymbolRole is synchronized with clang::index::SymbolRole.
+  return CXSymbolRole(static_cast(Role));
+}

ilya-biryukov wrote:
> `SymbolRoleSet` seems to have more roles not covered by `CXSymbolRole`.
> Should they be accepted by this function? 
> If yes, maybe zero those bits?
> If no, maybe add an assert?
> 
> 
> The extra roles are:
> ```
>   RelationChildOf = 1 << 9,
>   RelationBaseOf  = 1 << 10,
>   RelationOverrideOf  = 1 << 11,
>   RelationReceivedBy  = 1 << 12,
>   RelationCalledBy= 1 << 13,
>   RelationExtendedBy  = 1 << 14,
>   RelationAccessorOf  = 1 << 15,
>   RelationContainedBy = 1 << 16,
>   RelationIBTypeOf= 1 << 17,
>   RelationSpecializationOf = 1 << 18,
> ```
Yes, it has more relations, but most are only used by Objective-C. In all 
test/Index tests, I have only seen `RelationContainedBy` used for .cpp files. 
Many have not occurred in .m files. So I do not want to expose them, at least 
for now.




Repository:
  rC Clang

https://reviews.llvm.org/D42895



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133255.
MaskRay marked an inline comment as done.
MaskRay added a comment.

readability-simd-intrinsics.rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,42 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+For
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Experimental
+
+   If set to zero, the check will be enabled for ``-std=c++2a``. If non-zero,
+   the check will be enabled for ``-std=c++11`` or above (libc++
+   ``std::experimental::simd`` implementation backports `P0214`_ to C++11).
+   Default is ``1``.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,41 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS

[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133441.
MaskRay added a comment.

Don't deprecate CXIdxEntityRefInfo


Repository:
  rC Clang

https://reviews.llvm.org/D42895

Files:
  include/clang-c/Index.h
  include/clang/Index/IndexSymbol.h
  test/Index/index-decls.m
  test/Index/index-refs.cpp
  test/Index/index-subscripting-literals.m
  tools/c-index-test/c-index-test.c
  tools/libclang/CXIndexDataConsumer.cpp
  tools/libclang/CXIndexDataConsumer.h

Index: tools/libclang/CXIndexDataConsumer.h
===
--- tools/libclang/CXIndexDataConsumer.h
+++ tools/libclang/CXIndexDataConsumer.h
@@ -436,13 +436,15 @@
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool handleReference(const NamedDecl *D, SourceLocation Loc,
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool isNotFromSourceFile(SourceLocation Loc) const;
 
Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -148,6 +148,11 @@
 return true;
   }
 };
+
+CXSymbolRole getSymbolRole(SymbolRoleSet Role) {
+  // CXSymbolRole mirrors low 9 bits of clang::index::SymbolRole.
+  return CXSymbolRole(static_cast(Role) & ((1 << 9) - 1));
+}
 }
 
 bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
@@ -184,6 +189,7 @@
 if (Roles & (unsigned)SymbolRole::Implicit) {
   Kind = CXIdxEntityRef_Implicit;
 }
+CXSymbolRole CXRole = getSymbolRole(Roles);
 
 CXCursor Cursor;
 if (ASTNode.OrigE) {
@@ -202,7 +208,7 @@
 }
 handleReference(ND, Loc, Cursor,
 dyn_cast_or_null(ASTNode.Parent),
-ASTNode.ContainerDC, ASTNode.OrigE, Kind);
+ASTNode.ContainerDC, ASTNode.OrigE, Kind, CXRole);
 
   } else {
 const DeclContext *LexicalDC = ASTNode.ContainerDC;
@@ -889,21 +895,23 @@
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
   : getRefCursor(D, Loc);
-  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind);
+  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind, Role);
 }
 
 bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc,
   CXCursor Cursor,
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!CB.indexEntityReference)
 return false;
 
@@ -939,7 +947,8 @@
   getIndexLoc(Loc),
   &RefEntity,
   Parent ? &ParentEntity : nullptr,
-  &Container };
+  &Container,
+  Role };
   CB.indexEntityReference(ClientData, &Info);
   return true;
 }
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -3326,6 +3326,27 @@
   }
 }
 
+static void printSymbolRole(CXSymbolRole role) {
+  if (role & CXSymbolRole_Declaration)
+printf(" decl");
+  if (role & CXSymbolRole_Definition)
+printf(" def");
+  if (role & CXSymbolRole_Reference)
+printf(" ref");
+  if (role & CXSymbolRole_Read)
+printf(" read");
+  if (role & CXSymbolRole_Write)
+printf(" write");
+  if (role & CXSymbolRole_Call)
+printf(" call");
+  if (role & CXSymbolRole_Dynamic)
+printf(" dyn");
+  if (role & CXSymbolRole_AddressOf)
+printf(" addr");
+  if (role & CXSymbolRole_Implicit)
+printf(" implicit");
+}
+
 static void index_diagnostic(CXClientData clien

[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked 4 inline comments as done.
MaskRay added inline comments.



Comment at: include/clang-c/Index.h:6159
+   */
+  CXSymbolRole role;
 } CXIdxEntityRefInfo;

ilya-biryukov wrote:
> MaskRay wrote:
> > ilya-biryukov wrote:
> > > Why do we need to store both `CXIdxEntityRefKind` and `CXSymbolRole`? Can 
> > > we store just `CXSymbolRole`?
> > > Is this for compatibility with existing clients?
> > > 
> > > If so, maybe we could:
> > > - remove `Implicit` and `Direct` from the `CXSymbolRole`
> > > - keep it only in `CXIdxEntityRefKind`
> > > - not deprecate the `CXIdxEntityRefKind`
> > I think `CXIdxEntityRefKind` should be deprecated but for compatibility we 
> > do not remove the field for this minor version upgrade. But they can be 
> > removed after a major version upgrade.
> > 
> > For what I have observed, `Implicit` is only used by Objective-C
> We should definitely loop the owners of libclang in if we want to deprecate 
> the API, I'm not familiar with the contract of libclang regarding the API 
> deprecation.
> I'm not sure who's responsible for that, asking at the cfe-dev mailing list 
> could be your best bet for that.
> 
> The alternative I suggest is removing `Implicit` from `CXSymbolRole`, making 
> this change an extension of existing API. I expect that this could be done 
> without more through discussion.
I'll keep `CXSymbolRole_Implicit` and make it duplicate the functionality 
provided by CXIdxEntityRefKind, with a comment that CXIdxEntityRefKind may be 
deprecated in a future version.

Thanks, I'll also ask the cfe-dev mailing list.



Comment at: tools/libclang/CXIndexDataConsumer.cpp:154
+  // CXSymbolRole is synchronized with clang::index::SymbolRole.
+  return CXSymbolRole(static_cast(Role));
+}

ilya-biryukov wrote:
> MaskRay wrote:
> > ilya-biryukov wrote:
> > > `SymbolRoleSet` seems to have more roles not covered by `CXSymbolRole`.
> > > Should they be accepted by this function? 
> > > If yes, maybe zero those bits?
> > > If no, maybe add an assert?
> > > 
> > > 
> > > The extra roles are:
> > > ```
> > >   RelationChildOf = 1 << 9,
> > >   RelationBaseOf  = 1 << 10,
> > >   RelationOverrideOf  = 1 << 11,
> > >   RelationReceivedBy  = 1 << 12,
> > >   RelationCalledBy= 1 << 13,
> > >   RelationExtendedBy  = 1 << 14,
> > >   RelationAccessorOf  = 1 << 15,
> > >   RelationContainedBy = 1 << 16,
> > >   RelationIBTypeOf= 1 << 17,
> > >   RelationSpecializationOf = 1 << 18,
> > > ```
> > Yes, it has more relations, but most are only used by Objective-C. In all 
> > test/Index tests, I have only seen `RelationContainedBy` used for .cpp 
> > files. Many have not occurred in .m files. So I do not want to expose them, 
> > at least for now.
> > 
> > 
> It's fine, but let's add a comment and zero those bits out.
> 
> Could you also a comments to both `SymbolRoleSet` and `CXSymbolRole` that 
> they mirror each other and need to be updated together?
zeroed high bits of CXSymbolRole and left comments.


Repository:
  rC Clang

https://reviews.llvm.org/D42895



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133455.
MaskRay added a comment.

Add option `Enabled` which defaults to 0.
Suggest std::simd (-std=c++2a) or std::experimental::std (-std=c++11) only if 
enabled.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,33 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,39 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+In C++11 mode, if the option ``Enabled`` is turned on, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Enabled
+
+   If set to non-zero, the check will enabled. Default is ``0``.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,40 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHEC

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked 9 inline comments as done.
MaskRay added a comment.

The check must be manually enabled now:

  % clang-tidy -checks='-*,readability-simd-intrinsics' a.cc -- -std=c++2a
  # Not enabled by default
  
  % clang-tidy -checks='-*,readability-simd-intrinsics' -config='{CheckOptions: 
[{key: readability-simd-intrinsics.Enabled, value: 1}]}' a.cc -- -std=c++11
  # warn and suggest std::experimental::simd
  
  % clang-tidy -checks='-*,readability-simd-intrinsics' -config='{CheckOptions: 
[{key: readability-simd-intrinsics.Enabled, value: 1}]}' a.cc -- -std=c++2a
  # warn and suggest std::simd


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133457.
MaskRay added a comment.

Set `Enabled` to 1 in test/clang-tidy/readability-simd-intrinsics.cpp


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics.cpp

Index: test/clang-tidy/readability-simd-intrinsics.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics.cpp
@@ -0,0 +1,36 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Enabled, value: 1} \
+// RUN:  ]}' -- -std=c++2a
+
+/ X86
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
+
+/ PPC
+// vector/__vector requires -maltivec, but this typedef is similar.
+typedef int vector_int __attribute__((vector_size(16)));
+
+vector_int vec_add(vector_int, vector_int);
+
+void PPC() {
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,39 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+In C++11 mode, if the option ``Enabled`` is turned on, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Enabled
+
+   If set to non-zero, the check will enabled. Default is ``0``.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
===
--- /dev/null
+++ clang-tidy/readability/SIMDIntrinsicsCheck.h
@@ -0,0 +1,40 @@
+//===--- SIMDIntrinsicsCheck.h - clang-tidy--*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_SIMD_INTRINSICS_CHECK_H

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133474.
MaskRay added a comment.
Herald added subscribers: kbarton, nemanjai.

Split test/clang-tidy/readability-simd-intrinsics.cpp to x86 and ppc


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/readability-simd-intrinsics-x86.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-x86.cpp
@@ -0,0 +1,26 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Enabled, value: 1} \
+// RUN:  ]}' -- -target x86_64 -std=c++2a
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
Index: test/clang-tidy/readability-simd-intrinsics-ppc.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-ppc.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Enabled, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++2a
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+  vector int i0, i1;
+
+  vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::simd objects [readability-simd-intrinsics]
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,39 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+In C++11 mode, if the option ``Enabled`` is turned on, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b);
+
+the check suggests an alternative:
+
+.. code-block:: c++
+
+  simd::experimental::simd::operator+
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Enabled
+
+   If set to non-zero, the check will enabled. Default is ``0``.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readabi

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133476.
MaskRay added a comment.

.rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/readability-simd-intrinsics-x86.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-x86.cpp
@@ -0,0 +1,26 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Enabled, value: 1} \
+// RUN:  ]}' -- -target x86_64 -std=c++2a
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
Index: test/clang-tidy/readability-simd-intrinsics-ppc.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-ppc.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Enabled, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++2a
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+  vector int i0, i1;
+
+  vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::simd objects [readability-simd-intrinsics]
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,41 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+If the option ``Enabled`` is set to non-zero, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b); // x86
+  vec_add(a, b);   // Power
+
+the check suggests an alternative:
+
+.. code-block::
+
+  operator+ on std::experimental::simd objects // -std=c++11
+  operator+ on std::simd objects   // -std=c++2a
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Enabled
+
+   If set to non-zero, the check will be enabled. Default is ``0``.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/r

[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133632.
MaskRay added a comment.

Bring back refkind:


Repository:
  rC Clang

https://reviews.llvm.org/D42895

Files:
  include/clang-c/Index.h
  include/clang/Index/IndexSymbol.h
  test/Index/index-refs.cpp
  test/Index/index-subscripting-literals.m
  tools/c-index-test/c-index-test.c
  tools/libclang/CXIndexDataConsumer.cpp
  tools/libclang/CXIndexDataConsumer.h

Index: tools/libclang/CXIndexDataConsumer.h
===
--- tools/libclang/CXIndexDataConsumer.h
+++ tools/libclang/CXIndexDataConsumer.h
@@ -436,13 +436,15 @@
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool handleReference(const NamedDecl *D, SourceLocation Loc,
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool isNotFromSourceFile(SourceLocation Loc) const;
 
Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -148,6 +148,11 @@
 return true;
   }
 };
+
+CXSymbolRole getSymbolRole(SymbolRoleSet Role) {
+  // CXSymbolRole mirrors low 9 bits of clang::index::SymbolRole.
+  return CXSymbolRole(static_cast(Role) & ((1 << 9) - 1));
+}
 }
 
 bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
@@ -184,6 +189,7 @@
 if (Roles & (unsigned)SymbolRole::Implicit) {
   Kind = CXIdxEntityRef_Implicit;
 }
+CXSymbolRole CXRole = getSymbolRole(Roles);
 
 CXCursor Cursor;
 if (ASTNode.OrigE) {
@@ -202,7 +208,7 @@
 }
 handleReference(ND, Loc, Cursor,
 dyn_cast_or_null(ASTNode.Parent),
-ASTNode.ContainerDC, ASTNode.OrigE, Kind);
+ASTNode.ContainerDC, ASTNode.OrigE, Kind, CXRole);
 
   } else {
 const DeclContext *LexicalDC = ASTNode.ContainerDC;
@@ -889,21 +895,23 @@
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
   : getRefCursor(D, Loc);
-  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind);
+  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind, Role);
 }
 
 bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc,
   CXCursor Cursor,
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!CB.indexEntityReference)
 return false;
 
@@ -939,7 +947,8 @@
   getIndexLoc(Loc),
   &RefEntity,
   Parent ? &ParentEntity : nullptr,
-  &Container };
+  &Container,
+  Role };
   CB.indexEntityReference(ClientData, &Info);
   return true;
 }
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -3326,6 +3326,27 @@
   }
 }
 
+static void printSymbolRole(CXSymbolRole role) {
+  if (role & CXSymbolRole_Declaration)
+printf(" decl");
+  if (role & CXSymbolRole_Definition)
+printf(" def");
+  if (role & CXSymbolRole_Reference)
+printf(" ref");
+  if (role & CXSymbolRole_Read)
+printf(" read");
+  if (role & CXSymbolRole_Write)
+printf(" write");
+  if (role & CXSymbolRole_Call)
+printf(" call");
+  if (role & CXSymbolRole_Dynamic)
+printf(" dyn");
+  if (role & CXSymbolRole_AddressOf)
+printf(" addr");
+  if (role & CXSymbolRole_Implicit)
+printf(" implicit");
+}
+
 static void index_diagnostic(CXClientData client_data,
  CXDi

[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-10 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Ping. Now this is a pure API extension to current implicit/direct roles. Is it 
possible to see this landed before clang+llvm 6 is released?


Repository:
  rC Clang

https://reviews.llvm.org/D42895



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


[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-12 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324914: [libclang] Add `CXSymbolRole role` to 
CXIdxEntityRefInfo (authored by MaskRay, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42895?vs=133632&id=133889#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42895

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/include/clang/Index/IndexSymbol.h
  cfe/trunk/test/Index/index-refs.cpp
  cfe/trunk/test/Index/index-subscripting-literals.m
  cfe/trunk/tools/c-index-test/c-index-test.c
  cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
  cfe/trunk/tools/libclang/CXIndexDataConsumer.h

Index: cfe/trunk/tools/libclang/CXIndexDataConsumer.h
===
--- cfe/trunk/tools/libclang/CXIndexDataConsumer.h
+++ cfe/trunk/tools/libclang/CXIndexDataConsumer.h
@@ -436,13 +436,15 @@
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool handleReference(const NamedDecl *D, SourceLocation Loc,
const NamedDecl *Parent,
const DeclContext *DC,
const Expr *E = nullptr,
-   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct);
+   CXIdxEntityRefKind Kind = CXIdxEntityRef_Direct,
+   CXSymbolRole Role = CXSymbolRole_None);
 
   bool isNotFromSourceFile(SourceLocation Loc) const;
 
Index: cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
===
--- cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
+++ cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
@@ -148,6 +148,11 @@
 return true;
   }
 };
+
+CXSymbolRole getSymbolRole(SymbolRoleSet Role) {
+  // CXSymbolRole mirrors low 9 bits of clang::index::SymbolRole.
+  return CXSymbolRole(static_cast(Role) & ((1 << 9) - 1));
+}
 }
 
 bool CXIndexDataConsumer::handleDeclOccurence(const Decl *D,
@@ -184,6 +189,7 @@
 if (Roles & (unsigned)SymbolRole::Implicit) {
   Kind = CXIdxEntityRef_Implicit;
 }
+CXSymbolRole CXRole = getSymbolRole(Roles);
 
 CXCursor Cursor;
 if (ASTNode.OrigE) {
@@ -202,7 +208,7 @@
 }
 handleReference(ND, Loc, Cursor,
 dyn_cast_or_null(ASTNode.Parent),
-ASTNode.ContainerDC, ASTNode.OrigE, Kind);
+ASTNode.ContainerDC, ASTNode.OrigE, Kind, CXRole);
 
   } else {
 const DeclContext *LexicalDC = ASTNode.ContainerDC;
@@ -889,21 +895,23 @@
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
   : getRefCursor(D, Loc);
-  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind);
+  return handleReference(D, Loc, Cursor, Parent, DC, E, Kind, Role);
 }
 
 bool CXIndexDataConsumer::handleReference(const NamedDecl *D, SourceLocation Loc,
   CXCursor Cursor,
   const NamedDecl *Parent,
   const DeclContext *DC,
   const Expr *E,
-  CXIdxEntityRefKind Kind) {
+  CXIdxEntityRefKind Kind,
+  CXSymbolRole Role) {
   if (!CB.indexEntityReference)
 return false;
 
@@ -939,7 +947,8 @@
   getIndexLoc(Loc),
   &RefEntity,
   Parent ? &ParentEntity : nullptr,
-  &Container };
+  &Container,
+  Role };
   CB.indexEntityReference(ClientData, &Info);
   return true;
 }
Index: cfe/trunk/tools/c-index-test/c-index-test.c
===
--- cfe/trunk/tools/c-index-test/c-index-test.c
+++ cfe/trunk/tools/c-index-test/c-index-test.c
@@ -3326,6 +3326,27 @@
   }
 }
 
+static void printSymbolRole(CXSymbolRole role) {
+  if (role & CXSymbolRole_Declaration)
+printf(" decl");
+  if (role & CXSymbolRole_Definition)
+printf(" def");
+  if (role & CXSymbolRole_Reference)
+printf(" ref");
+  if (role & CXSymbolRole_Read)
+printf(" read");

[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-12 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC324914: [libclang] Add `CXSymbolRole role` to 
CXIdxEntityRefInfo (authored by MaskRay, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42895?vs=133632&id=133890#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42895

Files:
  include/clang-c/Index.h
  include/clang/Index/IndexSymbol.h
  test/Index/index-refs.cpp
  test/Index/index-subscripting-literals.m
  tools/c-index-test/c-index-test.c
  tools/libclang/CXIndexDataConsumer.cpp
  tools/libclang/CXIndexDataConsumer.h

Index: include/clang-c/Index.h
===
--- include/clang-c/Index.h
+++ include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 47
+#define CINDEX_VERSION_MINOR 48
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -6092,6 +6092,9 @@
 
 /**
  * \brief Data for IndexerCallbacks#indexEntityReference.
+ *
+ * This may be deprecated in a future version as this duplicates
+ * the \c CXSymbolRole_Implicit bit in \c CXSymbolRole.
  */
 typedef enum {
   /**
@@ -6106,6 +6109,25 @@
 } CXIdxEntityRefKind;
 
 /**
+ * \brief Roles that are attributed to symbol occurrences.
+ *
+ * Internal: this currently mirrors low 9 bits of clang::index::SymbolRole with
+ * higher bits zeroed. These high bits may be exposed in the future.
+ */
+typedef enum {
+  CXSymbolRole_None = 0,
+  CXSymbolRole_Declaration = 1 << 0,
+  CXSymbolRole_Definition = 1 << 1,
+  CXSymbolRole_Reference = 1 << 2,
+  CXSymbolRole_Read = 1 << 3,
+  CXSymbolRole_Write = 1 << 4,
+  CXSymbolRole_Call = 1 << 5,
+  CXSymbolRole_Dynamic = 1 << 6,
+  CXSymbolRole_AddressOf = 1 << 7,
+  CXSymbolRole_Implicit = 1 << 8
+} CXSymbolRole;
+
+/**
  * \brief Data for IndexerCallbacks#indexEntityReference.
  */
 typedef struct {
@@ -6135,6 +6157,10 @@
* \brief Lexical container context of the reference.
*/
   const CXIdxContainerInfo *container;
+  /**
+   * \brief Sets of symbol roles of the reference.
+   */
+  CXSymbolRole role;
 } CXIdxEntityRefInfo;
 
 /**
Index: include/clang/Index/IndexSymbol.h
===
--- include/clang/Index/IndexSymbol.h
+++ include/clang/Index/IndexSymbol.h
@@ -89,6 +89,8 @@
 static const unsigned SymbolPropertyBitNum = 8;
 
 /// Set of roles that are attributed to symbol occurrences.
+///
+/// Low 9 bits of clang-c/include/Index.h CXSymbolRole mirrors this enum.
 enum class SymbolRole : uint32_t {
   Declaration = 1 << 0,
   Definition  = 1 << 1,
Index: test/Index/index-refs.cpp
===
--- test/Index/index-refs.cpp
+++ test/Index/index-refs.cpp
@@ -67,6 +67,9 @@
 
 void foo5() {
   struct S2 s = { .y = 1, .x = 4};
+  s.y = s.x + 1;
+  (void)&foo3;
+  foo4(s.y);
 }
 
 int ginitlist[] = {EnumVal};
@@ -105,7 +108,7 @@
 // CHECK:  [indexDeclaration]: kind: c++-class-template | name: TS | {{.*}} | loc: 47:8
 // CHECK-NEXT: [indexDeclaration]: kind: struct-template-partial-spec | name: TS | USR: c:@SP>1#T@TS>#t0.0#I | {{.*}} | loc: 50:8
 // CHECK-NEXT: [indexDeclaration]: kind: typedef | name: MyInt | USR: c:index-refs.cpp@SP>1#T@TS>#t0.0#I@T@MyInt | {{.*}} | loc: 51:15 | semantic-container: [TS:50:8] | lexical-container: [TS:50:8]
-// CHECK-NEXT: [indexEntityReference]: kind: c++-class-template | name: TS | USR: c:@ST>2#T#T@TS | lang: C++ | cursor: TemplateRef=TS:47:8 | loc: 50:8 | :: <> | container: [TU] | refkind: direct
+// CHECK-NEXT: [indexEntityReference]: kind: c++-class-template | name: TS | USR: c:@ST>2#T#T@TS | lang: C++ | cursor: TemplateRef=TS:47:8 | loc: 50:8 | :: <> | container: [TU] | refkind: direct | role: ref
 /* when indexing implicit instantiations
   [indexDeclaration]: kind: struct-template-spec | name: TS | USR: c:@S@TS>#I | {{.*}} | loc: 50:8
   [indexDeclaration]: kind: typedef | name: MyInt | USR: c:index-refs.cpp@593@S@TS>#I@T@MyInt | {{.*}} | loc: 51:15 | semantic-container: [TS:50:8] | lexical-container: [TS:50:8]
@@ -117,14 +120,19 @@
 // CHECK-NEXT: [indexEntityReference]: kind: c++-class-template | name: TS | USR: c:@ST>2#T#T@TS | {{.*}} | loc: 55:3
 
 // CHECK:  [indexEntityReference]: kind: variable | name: array_size | {{.*}} | loc: 59:22
-// CHECK:  [indexEntityReference]: kind: variable | name: default_param | {{.*}} | loc: 62:19
+// CHECK:  [indexEntityReference]: kind: variable | name: default_param | {{.*}} | loc: 62:19 | {{.*}} | role: ref read
 // CHECK-NOT:  [indexEntityReference]: kind: variable | name: default_param | {{.*}} | loc: 62:19
 
 // CHECK:  [indexEntityReference]: kind: field | name: y | {{.*}} | loc: 69:20
 // CHECK-NEXT: [indexEntityReference]: kind: field | name: x | {{.*}} | loc: 69:28
 // CHECK-NOT:  [indexEntityReference]: k

[PATCH] D42895: [libclang] Add `CXSymbolRole role` to CXIdxEntityRefInfo

2018-02-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Thx!


Repository:
  rL LLVM

https://reviews.llvm.org/D42895



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 133902.
MaskRay marked an inline comment as done.
MaskRay added a comment.

Rename `Enabled` to `UseStdExperimental` and only suggest std::experimental:: 
(not `std::`)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/readability-simd-intrinsics-x86.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-x86.cpp
@@ -0,0 +1,26 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.UseStdExperimental, value: 1} \
+// RUN:  ]}' -- -target x86_64 -std=c++11
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
Index: test/clang-tidy/readability-simd-intrinsics-ppc.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-ppc.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.UseStdExperimental, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+  vector int i0, i1;
+
+  vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,40 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+If the option ``UseStdExperimental`` is set to non-zero, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b); // x86
+  vec_add(a, b);   // Power
+
+the check suggests an alternative:
+
+.. code-block::
+
+  operator+ on std::experimental::simd objects
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: UseStdExperimental
+
+   If set to non-zero, the check will be enabled and it will suggest ``std::experimental`` alternatives. Default is ``0``.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced 

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 134076.
MaskRay marked an inline comment as done.
MaskRay added a comment.

Remove UseStdExperimental


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/readability-simd-intrinsics-x86.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-x86.cpp
@@ -0,0 +1,26 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.UseStdExperimental, value: 1} \
+// RUN:  ]}' -- -target x86_64 -std=c++11
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
Index: test/clang-tidy/readability-simd-intrinsics-ppc.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-ppc.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.UseStdExperimental, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+  vector int i0, i1;
+
+  vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,33 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+If the option ``UseStdExperimental`` is set to non-zero, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b); // x86
+  vec_add(a, b);   // Power
+
+the check suggests an alternative:
+
+.. code-block::
+
+  operator+ on std::experimental::simd objects
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experimental::simd`` operations.
 
 - New alias `hicpp-avoid-goto
   `_ to 
Index: clang-tidy/readability/SIMDIntrinsicsCheck.h
=

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-13 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked 8 inline comments as done.
MaskRay added inline comments.



Comment at: clang-tidy/readability/SIMDIntrinsicsCheck.cpp:46
+
+  static const llvm::StringMap Mapping{
+// [simd.alg]

hokein wrote:
> consider using `llvm::StringSwitch`?
The list is currently a scaffold and more operations will be added. It may be 
more efficient to use a lookup table instead of cascading `.Case("add", ...)`?



Comment at: docs/clang-tidy/checks/readability-simd-intrinsics.rst:38
+
+   If set to non-zero, the check will be enabled and it will suggest 
``std::experimental`` alternatives. Default is ``0``.
+

hokein wrote:
> We don't use check's option to enable the check in clang-tidy, if users want 
> to enable the check, they need to pass the check explicitly to clang-tidy 
> (e.g. -checks=""). I'd suggest to remove this option.
Removed.I don't think the option is necessary.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 134305.
MaskRay marked 2 inline comments as done.
MaskRay added a comment.

Add an option `Suggest`.

Only suggest P0214 alternatives if it is true.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/readability-simd-intrinsics-x86.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-x86.cpp
@@ -0,0 +1,26 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target x86_64 -std=c++11
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
Index: test/clang-tidy/readability-simd-intrinsics-ppc.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-ppc.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+  vector int i0, i1;
+
+  vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,40 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+If the option ``UseStdExperimental`` is set to non-zero, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b); // x86
+  vec_add(a, b);   // Power
+
+the check suggests an alternative:
+
+.. code-block::
+
+  operator+ on std::experimental::simd objects
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Suggest
+
+   If this option is set to non-zero (default is `0`), the check will suggest P0214 alternatives, otherwise it only points out the intrinsic function is non-portable.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -216,6 +216,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``s

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 134446.
MaskRay marked 4 inline comments as done.
MaskRay added a comment.

Update .rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/readability-simd-intrinsics-x86.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-x86.cpp
@@ -0,0 +1,26 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target x86_64 -std=c++11
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+// CHECK-MESSAGES-NOT: :[[@LINE-1]]:
+}
Index: test/clang-tidy/readability-simd-intrinsics-ppc.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-ppc.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+  vector int i0, i1;
+
+  vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,42 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+If the option ``Suggest`` is set to non-zero, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b); // x86
+  vec_add(a, b);   // Power
+
+the check suggests an alternative:
+
+.. code-block::
+
+  operator+ on std::experimental::simd objects
+
+Otherwise, it just complains the intrinsics are non-portable (and there are `P0214`_ alternatives).
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Suggest
+
+   If this option is set to non-zero (default is `0`), the check will suggest P0214 alternatives, otherwise it only points out the intrinsic function is non-portable.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -217,6 +217,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used 

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 134447.
MaskRay marked 2 inline comments as done.
MaskRay added a comment.

Update


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/readability-simd-intrinsics-x86.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-x86.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target x86_64 -std=c++11
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+}
Index: test/clang-tidy/readability-simd-intrinsics-ppc.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-simd-intrinsics-ppc.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+  vector int i0, i1;
+
+  vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+}
Index: docs/clang-tidy/checks/readability-simd-intrinsics.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-simd-intrinsics.rst
@@ -0,0 +1,42 @@
+.. title:: clang-tidy - readability-simd-intrinsics
+
+readability-simd-intrinsics
+===
+
+Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_) alternatives.
+
+If the option ``Suggest`` is set to non-zero, for
+
+.. code-block:: c++
+
+  _mm_add_epi32(a, b); // x86
+  vec_add(a, b);   // Power
+
+the check suggests an alternative:
+
+.. code-block::
+
+  operator+ on std::experimental::simd objects
+
+Otherwise, it just complains the intrinsics are non-portable (and there are `P0214`_ alternatives).
+
+Many architectures provide SIMD operations (e.g. x86 SSE/AVX, Power AltiVec/VSX,
+ARM NEON). It is common that SIMD code implementing the same algorithm, is
+written in multiple target-dispatching pieces to optimize for different
+architectures or micro-architectures.
+
+The C++ standard proposal `P0214`_ and its extensions cover many common SIMD
+operations. By migrating from target-dependent intrinsics to `P0214` operations,
+the SIMD code can be simplified and pieces for different targets can be unified.
+
+Refer to `P0214`_ for introduction and motivation for the data-parallel standard
+library.
+
+Options
+---
+
+.. option:: Suggest
+
+   If this option is set to non-zero (default is `0`), the check will suggest P0214 alternatives, otherwise it only points out the intrinsic function is non-portable.
+
+.. _P0214: http://wg21.link/p0214
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -217,6 +217,7 @@
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
+   readability-simd-intrinsics
readability-simplify-boolean-expr
readability-static-accessed-through-instance
readability-static-definition-in-anonymous-namespace
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -88,6 +88,12 @@
   Functions that have trailing returns are disallowed, except for those 
   using decltype specifiers and lambda with otherwise unutterable 
   return types.
+
+- New `readability-simd-intrinsics
+  `_ check
+
+  Warns if SIMD intrinsics are used which can be replaced by
+  ``std::experime

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-15 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: test/clang-tidy/readability-simd-intrinsics-ppc.cpp:3
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++11

hokein wrote:
> consider adding test when Suggest is 0?
I'll have to duplicate the CHECK-MESSAGE lines for each intrinsic, which seems 
a lot of boilerplate.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-02-15 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE325272: [clang-tidy] Add `readability-simd-intrinsics` 
check. (authored by MaskRay, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42983?vs=134447&id=134448#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: clang-tidy/readability/SIMDIntrinsicsCheck.cpp
===
--- clang-tidy/readability/SIMDIntrinsicsCheck.cpp
+++ clang-tidy/readability/SIMDIntrinsicsCheck.cpp
@@ -0,0 +1,152 @@
+//===--- SIMDIntrinsicsCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "SIMDIntrinsicsCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Support/Regex.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+namespace {
+
+// If the callee has parameter of VectorType or pointer to VectorType,
+// or the return type is VectorType, we consider it a vector function
+// and a candidate for checking.
+AST_MATCHER(FunctionDecl, isVectorFunction) {
+  bool IsVector = Node.getReturnType()->isVectorType();
+  for (const ParmVarDecl *Parm : Node.parameters()) {
+QualType Type = Parm->getType();
+if (Type->isPointerType())
+  Type = Type->getPointeeType();
+if (Type->isVectorType())
+  IsVector = true;
+  }
+  return IsVector;
+}
+
+} // namespace
+
+static StringRef TrySuggestPPC(StringRef Name) {
+  if (!Name.consume_front("vec_"))
+return {};
+
+  static const llvm::StringMap Mapping{
+// [simd.alg]
+{"max", "$std::max"},
+{"min", "$std::min"},
+
+// [simd.binary]
+{"add", "operator+ on $simd objects"},
+{"sub", "operator- on $simd objects"},
+{"mul", "operator* on $simd objects"},
+  };
+
+  auto It = Mapping.find(Name);
+  if (It != Mapping.end())
+return It->second;
+  return {};
+}
+
+static StringRef TrySuggestX86(StringRef Name) {
+  if (!(Name.consume_front("_mm_") || Name.consume_front("_mm256_") ||
+Name.consume_front("_mm512_")))
+return {};
+
+  // [simd.alg]
+  if (Name.startswith("max_"))
+return "$simd::max";
+  if (Name.startswith("min_"))
+return "$simd::min";
+
+  // [simd.binary]
+  if (Name.startswith("add_"))
+return "operator+ on $simd objects";
+  if (Name.startswith("sub_"))
+return "operator- on $simd objects";
+  if (Name.startswith("mul_"))
+return "operator* on $simd objects";
+
+  return {};
+}
+
+SIMDIntrinsicsCheck::SIMDIntrinsicsCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), Suggest(Options.get("Suggest", 0) != 0) {}
+
+void SIMDIntrinsicsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "Suggest", 0);
+}
+
+void SIMDIntrinsicsCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus11)
+return;
+  // libcxx implementation backports it to C++11 std::experimental::simd.
+  Std = getLangOpts().CPlusPlus2a ? "std" : "std::experimental";
+
+  Finder->addMatcher(callExpr(callee(functionDecl(allOf(
+  matchesName("^::(_mm_|_mm256_|_mm512_|vec_)"),
+  isVectorFunction(,
+  unless(isExpansionInSystemHeader()))
+ .bind("call"),
+ this);
+}
+
+void SIMDIntrinsicsCheck::check(const MatchFinder::MatchResult &Result) {
+  const auto *Call = Result.Nodes.getNodeAs("call");
+  assert(Call != nullptr);
+  const FunctionDecl *Callee = Call->getDirectCallee();
+  if (!Callee)
+return;
+
+  StringRef Old = Callee->getName();
+  StringRef New;
+  llvm::Triple::ArchType Arch =
+  Result.Context->getTargetInfo().getTriple().getArch();
+
+  switch (Arch) {
+default:
+  break;
+case llvm::Triple::ppc:
+case llvm::Triple::ppc64:
+case llvm::Triple::ppc64le:
+  New = TrySuggestPPC(Old);
+  break;
+case llvm::Triple::x86:
+case llvm::Triple::x86_64:
+  New = TrySuggestX86(Old);
+  break;
+  }
+
+  if (!New.empty()) {
+std::string Message;
+// If Su

[PATCH] D41575: [index] Return when DC is null in handleReference

2017-12-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
Herald added a subscriber: cfe-commits.

DC may sometimes be NULL and getContainerInfo(DC, Container) will fail.


Repository:
  rC Clang

https://reviews.llvm.org/D41575

Files:
  tools/libclang/CXIndexDataConsumer.cpp


Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -890,7 +890,7 @@
   const DeclContext *DC,
   const Expr *E,
   CXIdxEntityRefKind Kind) {
-  if (!D)
+  if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
@@ -907,7 +907,7 @@
   if (!CB.indexEntityReference)
 return false;
 
-  if (!D)
+  if (!D || !DC)
 return false;
   if (Loc.isInvalid())
 return false;


Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -890,7 +890,7 @@
   const DeclContext *DC,
   const Expr *E,
   CXIdxEntityRefKind Kind) {
-  if (!D)
+  if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
@@ -907,7 +907,7 @@
   if (!CB.indexEntityReference)
 return false;
 
-  if (!D)
+  if (!D || !DC)
 return false;
   if (Loc.isInvalid())
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41575: [index] Return when DC is null in handleReference

2017-12-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 128148.
MaskRay added a comment.

DC -> Parent


Repository:
  rC Clang

https://reviews.llvm.org/D41575

Files:
  tools/libclang/CXIndexDataConsumer.cpp


Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -907,7 +907,7 @@
   if (!CB.indexEntityReference)
 return false;
 
-  if (!D)
+  if (!D || !Parent)
 return false;
   if (Loc.isInvalid())
 return false;


Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -907,7 +907,7 @@
   if (!CB.indexEntityReference)
 return false;
 
-  if (!D)
+  if (!D || !Parent)
 return false;
   if (Loc.isInvalid())
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41575: [index] Return when DC is null in handleReference

2017-12-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 128149.
MaskRay added a comment.

DC -> Parent


Repository:
  rC Clang

https://reviews.llvm.org/D41575

Files:
  tools/libclang/CXIndexDataConsumer.cpp


Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -907,7 +907,7 @@
   if (!CB.indexEntityReference)
 return false;
 
-  if (!D)
+  if (!D || !Parent)
 return false;
   if (Loc.isInvalid())
 return false;


Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -907,7 +907,7 @@
   if (!CB.indexEntityReference)
 return false;
 
-  if (!D)
+  if (!D || !Parent)
 return false;
   if (Loc.isInvalid())
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41575: [index] Return when Parent is null in handleReference

2017-12-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 128150.
MaskRay added a comment.

Sorry for changing this back and forth. But I do not have a powerful 
workstation and have to reverse engineer this.


Repository:
  rC Clang

https://reviews.llvm.org/D41575

Files:
  tools/libclang/CXIndexDataConsumer.cpp


Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -890,7 +890,7 @@
   const DeclContext *DC,
   const Expr *E,
   CXIdxEntityRefKind Kind) {
-  if (!D)
+  if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
@@ -907,7 +907,7 @@
   if (!CB.indexEntityReference)
 return false;
 
-  if (!D)
+  if (!D || !DC)
 return false;
   if (Loc.isInvalid())
 return false;


Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -890,7 +890,7 @@
   const DeclContext *DC,
   const Expr *E,
   CXIdxEntityRefKind Kind) {
-  if (!D)
+  if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
@@ -907,7 +907,7 @@
   if (!CB.indexEntityReference)
 return false;
 
-  if (!D)
+  if (!D || !DC)
 return false;
   if (Loc.isInvalid())
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41575: [index] Return when DC is null in handleReference

2018-01-03 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

HighCommander4 narrowed it down 
https://github.com/jacobdufault/cquery/issues/219#issuecomment-354903152  to a 
much simpler reproduce:

  c++
  template 
  struct actor;
  
  template  class Actor = actor>
  struct terminal;

This may trigger null pointer dereference of `DC` (because it calls `cast`). If 
the default template argument is removed, the crash goes away.


Repository:
  rC Clang

https://reviews.llvm.org/D41575



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


[PATCH] D41575: [index] Return when DC is null in handleReference

2018-01-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Ping


Repository:
  rC Clang

https://reviews.llvm.org/D41575



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


[PATCH] D41575: [index] Return when DC is null in handleReference

2018-01-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

@akyrtzi When I run `c-index-test core -print-source-symbols -- a.cc` on

  template 
  struct actor;
  
  template  class Actor = actor>
  struct terminal;

the issue disappears. It emerges only when `clang_indexTranslationUnit` is 
called with interactions of other things.


Repository:
  rC Clang

https://reviews.llvm.org/D41575



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


[PATCH] D41575: [index] Return when DC is null in handleReference

2018-01-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 128953.
MaskRay added a comment.

rebase


Repository:
  rC Clang

https://reviews.llvm.org/D41575

Files:
  tools/libclang/CXIndexDataConsumer.cpp


Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -890,7 +890,7 @@
   const DeclContext *DC,
   const Expr *E,
   CXIdxEntityRefKind Kind) {
-  if (!D)
+  if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
@@ -907,7 +907,7 @@
   if (!CB.indexEntityReference)
 return false;
 
-  if (!D)
+  if (!D || !DC)
 return false;
   if (Loc.isInvalid())
 return false;


Index: tools/libclang/CXIndexDataConsumer.cpp
===
--- tools/libclang/CXIndexDataConsumer.cpp
+++ tools/libclang/CXIndexDataConsumer.cpp
@@ -890,7 +890,7 @@
   const DeclContext *DC,
   const Expr *E,
   CXIdxEntityRefKind Kind) {
-  if (!D)
+  if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
@@ -907,7 +907,7 @@
   if (!CB.indexEntityReference)
 return false;
 
-  if (!D)
+  if (!D || !DC)
 return false;
   if (Loc.isInvalid())
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41575: [index] Return when DC is null in handleReference

2018-01-08 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322017: [index] Return when DC is null in handleReference 
(authored by MaskRay, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D41575

Files:
  cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp


Index: cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
===
--- cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
+++ cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
@@ -890,7 +890,7 @@
   const DeclContext *DC,
   const Expr *E,
   CXIdxEntityRefKind Kind) {
-  if (!D)
+  if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
@@ -907,7 +907,7 @@
   if (!CB.indexEntityReference)
 return false;
 
-  if (!D)
+  if (!D || !DC)
 return false;
   if (Loc.isInvalid())
 return false;


Index: cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
===
--- cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
+++ cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
@@ -890,7 +890,7 @@
   const DeclContext *DC,
   const Expr *E,
   CXIdxEntityRefKind Kind) {
-  if (!D)
+  if (!D || !DC)
 return false;
 
   CXCursor Cursor = E ? MakeCXCursor(E, cast(DC), CXTU)
@@ -907,7 +907,7 @@
   if (!CB.indexEntityReference)
 return false;
 
-  if (!D)
+  if (!D || !DC)
 return false;
   if (Loc.isInvalid())
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41575: [index] Return when DC is null in handleReference

2018-01-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In https://reviews.llvm.org/D41575#970412, @akyrtzi wrote:

> Ah, sorry I mislead you. To test this try using `c-index-test -index-file 
> /path/to/file`, see other examples in `test/Index`, e.g. 
> `test/Index/index-file.cpp`


Thanks for the command. It is really helpful. I have re-run cquery with or 
without the `!DC` patch (on git-svn HEAD) and see no libclang crash. I guess 
this issue was in somewhere else and in these weeks it has been fixed.

  zsh
  % cat a.cc
  template 
  struct actor;
  
  template  class Actor = actor>
  struct terminal;
  
  # Arch Linux extra/clang 5.0.1-1
  % c-index-test -index-file a.cc
  [startedTranslationUnit]
  [enteredMainFile]: a.cc
  [indexEntityReference]: kind: c++-class-template | name: actor | USR: 
c:@ST>1#T@actor | lang: C++ | cursor: TypeRef=actor:2:8 | 
loc: 2:8 | :: <> | container: [TU] | refkind: direct
  libclang: crash detected during indexing source file: {
'source_filename' : '(null)'
'command_line_args' : ['clang', 'a.cc'],
'unsaved_files' : [],
'options' : 1,
  }
  Failure (no details available)
  
  
  # llvm+clang git-svn HEAD
  % ~/Dev/llvm/release/bin/c-index-test -index-file a.cc
  # no failure
  
  % ~/Dev/llvm/release/bin/c-index-test -index-file test/src/unit-cbor.cpp 
-Isrc -Itest/thirdparty/catch -std=c++11 -resource-dir 
~/Dev/llvm/release/lib/clang/7.0.0
  # no failure


Repository:
  rL LLVM

https://reviews.llvm.org/D41575



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


[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName

2018-02-28 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

ping


Repository:
  rC Clang

https://reviews.llvm.org/D42893



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


[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-03-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In https://reviews.llvm.org/D42983#1025179, @alexfh wrote:

> A late comment here: should this check start a new "portability" module? This 
> seems to be the main focus of the check rather than making code more readable.


SG. Should I rename it?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


[PATCH] D44173: [clang-tidy] Add "portability" module and move readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added a reviewer: alexfh.
Herald added subscribers: cfe-commits, kbarton, xazax.hun, mgorny, nemanjai, 
klimek.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -95,8 +95,8 @@
   Finds and replaces deprecated uses of ``std::uncaught_exception`` to
   ``std::uncaught_exceptions``.
 
-- New `readability-simd-intrinsics
-  `_ check
+- New `portability-simd-intrinsics
+  `_ check
 
   Warns if SIMD intrinsics are used which can be replaced by
   ``std::experimental::simd`` operations.
Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -554,6 +554,11 @@
 static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
 PerformanceModuleAnchorSource;
 
+// This anchor is used to force the linker to link the PortabilityModule.
+extern volatile int PortabilityModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED PortabilityModuleAnchorDestination =
+PortabilityModuleAnchorSour

[PATCH] D44173: [clang-tidy] Add "portability" module and move readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137256.
MaskRay added a comment.

.rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -95,8 +95,8 @@
   Finds and replaces deprecated uses of ``std::uncaught_exception`` to
   ``std::uncaught_exceptions``.
 
-- New `readability-simd-intrinsics
-  `_ check
+- New `portability-simd-intrinsics
+  `_ check
 
   Warns if SIMD intrinsics are used which can be replaced by
   ``std::experimental::simd`` operations.
Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -554,6 +554,11 @@
 static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
 PerformanceModuleAnchorSource;
 
+// This 

[PATCH] D42983: [clang-tidy] Add readability-simd-intrinsics check.

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In https://reviews.llvm.org/D42983#1028241, @alexfh wrote:

> In https://reviews.llvm.org/D42983#1028093, @MaskRay wrote:
>
> > In https://reviews.llvm.org/D42983#1025179, @alexfh wrote:
> >
> > > A late comment here: should this check start a new "portability" module? 
> > > This seems to be the main focus of the check rather than making code more 
> > > readable.
> >
> >
> > SG. Should I rename it?
>
>
> If nobody objects, yes, please. You'll need create the module manually and 
> then use the rename_check.py script for the actual renaming.


I just created https://reviews.llvm.org/D44173 . Didn't know `rename_check.py` 
and manually renamed a bunch of files...


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42983



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


[PATCH] D44173: [clang-tidy] Add "portability" module and move readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137259.
MaskRay added a comment.

index.rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -71,6 +71,8 @@
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
 ``performance-``   Checks that target performance-related issues.
+``portability-``   Checks that target portability-related issues that don't
+   relate to any particular coding style.
 ``readability-``   Checks that target readability-related issues that don't
relate to any particular coding style.
 == =
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -95,8 +

[PATCH] D44173: [clang-tidy] Add "portability" module and move readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137260.
MaskRay added a comment.

comment


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -71,6 +71,8 @@
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
 ``performance-``   Checks that target performance-related issues.
+``portability-``   Checks that target portability-related issues that don't
+   relate to any particular coding style.
 ``readability-``   Checks that target readability-related issues that don't
relate to any particular coding style.
 == =
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -95,8 +95

[PATCH] D44173: [clang-tidy] Add "portability" module and move readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137262.
MaskRay added a comment.

.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -71,6 +71,8 @@
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
 ``performance-``   Checks that target performance-related issues.
+``portability-``   Checks that target portability-related issues that don't
+   relate to any particular coding style.
 ``readability-``   Checks that target readability-related issues that don't
relate to any particular coding style.
 == =
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -95,8 +95,8 @@

[PATCH] D44173: [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137275.
MaskRay added a comment.

std::string -> llvm::SmallString


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -71,6 +71,8 @@
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
 ``performance-``   Checks that target performance-related issues.
+``portability-``   Checks that target portability-related issues that don't
+   relate to any particular coding style.
 ``readability-``   Checks that target readability-related issues that don't
relate to any particular coding style.
 == =
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/Rele

[PATCH] D44173: [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked 2 inline comments as done.
MaskRay added inline comments.



Comment at: clang-tidy/portability/SIMDIntrinsicsCheck.cpp:141
   if (!New.empty()) {
 std::string Message;
 // If Suggest is true, give a P0214 alternative, otherwise point it out it

lebedev.ri wrote:
> Here too, surely some sane static size can be picked?
Changed to   `llvm::SmallString<32> Std;`

The choices can be:

"std::experimental"
"std"
"dimsum" (https://github.com/google/dimsum)

strlen("std::experimental") = 17 is the longest. Raise to 32 because the <32u> 
template instantiation has been used elsewhere.



Comment at: clang-tidy/portability/SIMDIntrinsicsCheck.h:32
  private:
+  std::string Std;
   const bool Suggest;

lebedev.ri wrote:
> This could be `llvm::SmallString<32> Std;`, actually. (or 
> `strlen("std::experimental")`)
Answered above.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173



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


[PATCH] D44173: [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics

2018-03-06 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137293.
MaskRay marked 2 inline comments as done.
MaskRay added a comment.

Mention new module `portability` in docs/ReleaseNotes.rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -71,6 +71,8 @@
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
 ``performance-``   Checks that target performance-related issues.
+``portability-``   Checks that target portability-related issues that don't
+   relate to any particular coding style.
 ``readability-``   Checks that target readability-related issues that don't
relate to any particular coding style.
 == =
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst

[PATCH] D44173: [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics

2018-03-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 137406.
MaskRay added a comment.

ReleaseNotes.rst


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44173

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/portability/CMakeLists.txt
  clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/portability-simd-intrinsics.rst
  docs/clang-tidy/checks/readability-simd-intrinsics.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  test/clang-tidy/portability-simd-intrinsics-x86.cpp
  test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -1,6 +1,6 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target x86_64 -std=c++11
 
 typedef long long __m128i __attribute__((vector_size(16)));
@@ -17,7 +17,7 @@
   __m256 d0;
 
   _mm_add_epi32(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
   d0 = _mm256_load_pd(0);
   _mm256_store_pd(0, d0);
 
Index: test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -1,13 +1,13 @@
-// RUN: %check_clang_tidy %s readability-simd-intrinsics %t -- \
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
 // RUN:  -config='{CheckOptions: [ \
-// RUN:{key: readability-simd-intrinsics.Suggest, value: 1} \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
 // RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
 
 vector int vec_add(vector int, vector int);
 
 void PPC() {
   vector int i0, i1;
 
   vec_add(i0, i1);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [readability-simd-intrinsics]
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
 }
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -71,6 +71,8 @@
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
 ``performance-``   Checks that target performance-related issues.
+``portability-``   Checks that target portability-related issues that don't
+   relate to any particular coding style.
 ``readability-``   Checks that target readability-related issues that don't
relate to any particular coding style.
 == =
Index: docs/clang-tidy/checks/portability-simd-intrinsics.rst
===
--- docs/clang-tidy/checks/portability-simd-intrinsics.rst
+++ docs/clang-tidy/checks/portability-simd-intrinsics.rst
@@ -1,6 +1,6 @@
-.. title:: clang-tidy - readability-simd-intrinsics
+.. title:: clang-tidy - portability-simd-intrinsics
 
-readability-simd-intrinsics
+portability-simd-intrinsics
 ===
 
 Finds SIMD intrinsics calls and suggests ``std::experimental::simd`` (`P0214`_)
@@ -41,4 +41,9 @@
`P0214`_ alternatives, otherwise it only points out the intrinsic function is
non-portable.
 
+.. option:: Std
+
+   The namespace used to suggest `P0214`_ alternatives. If not specified, `std::`
+   for `-std=c++2a` and `std::experimental::` for `-std=c++11`.
+
 .. _P0214: http://wg21.link/p0214
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ 

[PATCH] D44173: [clang-tidy] Add "portability" module and rename readability-simd-intrinsics to portability-simd-intrinsics

2018-03-07 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326909: [clang-tidy] Add "portability" module and 
rename readability-simd-intrinsics to… (authored by MaskRay, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44173?vs=137406&id=137407#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44173

Files:
  clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tools-extra/trunk/clang-tidy/portability/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/portability/PortabilityTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.cpp
  clang-tools-extra/trunk/clang-tidy/portability/SIMDIntrinsicsCheck.h
  clang-tools-extra/trunk/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.cpp
  clang-tools-extra/trunk/clang-tidy/readability/SIMDIntrinsicsCheck.h
  clang-tools-extra/trunk/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/portability-simd-intrinsics.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/readability-simd-intrinsics.rst
  clang-tools-extra/trunk/docs/clang-tidy/index.rst
  clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-ppc.cpp
  clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-x86.cpp
  clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-ppc.cpp
  clang-tools-extra/trunk/test/clang-tidy/readability-simd-intrinsics-x86.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-x86.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-x86.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-x86.cpp
@@ -0,0 +1,25 @@
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target x86_64 -std=c++11
+
+typedef long long __m128i __attribute__((vector_size(16)));
+typedef double __m256 __attribute__((vector_size(32)));
+
+__m128i _mm_add_epi32(__m128i, __m128i);
+__m256 _mm256_load_pd(double const *);
+void _mm256_store_pd(double *, __m256);
+
+int _mm_add_fake(int, int);
+
+void X86() {
+  __m128i i0, i1;
+  __m256 d0;
+
+  _mm_add_epi32(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: '_mm_add_epi32' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+  d0 = _mm256_load_pd(0);
+  _mm256_store_pd(0, d0);
+
+  _mm_add_fake(0, 1);
+}
Index: clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-ppc.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-ppc.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/portability-simd-intrinsics-ppc.cpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s portability-simd-intrinsics %t -- \
+// RUN:  -config='{CheckOptions: [ \
+// RUN:{key: portability-simd-intrinsics.Suggest, value: 1} \
+// RUN:  ]}' -- -target ppc64le -maltivec -std=c++11
+
+vector int vec_add(vector int, vector int);
+
+void PPC() {
+  vector int i0, i1;
+
+  vec_add(i0, i1);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'vec_add' can be replaced by operator+ on std::experimental::simd objects [portability-simd-intrinsics]
+}
Index: clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp
===
--- clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp
+++ clang-tools-extra/trunk/clang-tidy/plugin/ClangTidyPlugin.cpp
@@ -118,6 +118,11 @@
 static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
 PerformanceModuleAnchorSource;
 
+// This anchor is used to force the linker to link the PortabilityModule.
+extern volatile int PortabilityModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED PortabilityModuleAnchorDestination =
+PortabilityModuleAnchorSource;
+
 // This anchor is used to force the linker to link the ReadabilityModule.
 extern volatile int ReadabilityModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
Index: clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/plugin/CMakeLists.txt
@@ -19,6 +19,7 @@
   clangTidyMPIModule
   clangTidyObjCModule
   clangTidyPerformanceModule
+  clangTidyPortabilityModule
  

[PATCH] D51109: [cc1][cc1as] Call OptTable::PrintHelp with explicit " [options] file..."

2018-10-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 168898.
MaskRay retitled this revision from "[cc1][cc1as] Call OptTable::PrintHelp with 
explicit " [options] "" to "[cc1][cc1as] Call OptTable::PrintHelp with 
explicit " [options] file..."".
MaskRay removed a reviewer: clang.
MaskRay removed subscribers: sdardis, atanasyan.
MaskRay added a comment.

Refresh the commit and update title


Repository:
  rC Clang

https://reviews.llvm.org/D51109

Files:
  lib/FrontendTool/ExecuteCompilerInvocation.cpp
  tools/driver/cc1as_main.cpp


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -534,7 +534,8 @@
 
   if (Asm.ShowHelp) {
 std::unique_ptr Opts(driver::createDriverOptTable());
-Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
+Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] file...",
+"Clang Integrated Assembler",
 /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
 /*ShowAllAliases=*/false);
 return 0;
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -183,7 +183,7 @@
   // Honor -help.
   if (Clang->getFrontendOpts().ShowHelp) {
 std::unique_ptr Opts = driver::createDriverOptTable();
-Opts->PrintHelp(llvm::outs(), "clang -cc1",
+Opts->PrintHelp(llvm::outs(), "clang -cc1 [options] file...",
 "LLVM 'Clang' Compiler: http://clang.llvm.org";,
 /*Include=*/driver::options::CC1Option,
 /*Exclude=*/0, /*ShowAllAliases=*/false);


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -534,7 +534,8 @@
 
   if (Asm.ShowHelp) {
 std::unique_ptr Opts(driver::createDriverOptTable());
-Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
+Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] file...",
+"Clang Integrated Assembler",
 /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
 /*ShowAllAliases=*/false);
 return 0;
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -183,7 +183,7 @@
   // Honor -help.
   if (Clang->getFrontendOpts().ShowHelp) {
 std::unique_ptr Opts = driver::createDriverOptTable();
-Opts->PrintHelp(llvm::outs(), "clang -cc1",
+Opts->PrintHelp(llvm::outs(), "clang -cc1 [options] file...",
 "LLVM 'Clang' Compiler: http://clang.llvm.org";,
 /*Include=*/driver::options::CC1Option,
 /*Exclude=*/0, /*ShowAllAliases=*/false);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51109: [Driver][cc1][cc1as] Call OptTable::PrintHelp with explicit " [options] file..."

2018-10-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 168913.
MaskRay retitled this revision from "[cc1][cc1as] Call OptTable::PrintHelp with 
explicit " [options] file..."" to "[Driver][cc1][cc1as] Call 
OptTable::PrintHelp with explicit " [options] file..."".
MaskRay added a comment.

Another reference in driver


Repository:
  rC Clang

https://reviews.llvm.org/D51109

Files:
  lib/Driver/Driver.cpp
  lib/FrontendTool/ExecuteCompilerInvocation.cpp
  tools/driver/cc1as_main.cpp


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -534,7 +534,8 @@
 
   if (Asm.ShowHelp) {
 std::unique_ptr Opts(driver::createDriverOptTable());
-Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
+Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] file...",
+"Clang Integrated Assembler",
 /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
 /*ShowAllAliases=*/false);
 return 0;
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -183,7 +183,7 @@
   // Honor -help.
   if (Clang->getFrontendOpts().ShowHelp) {
 std::unique_ptr Opts = driver::createDriverOptTable();
-Opts->PrintHelp(llvm::outs(), "clang -cc1",
+Opts->PrintHelp(llvm::outs(), "clang -cc1 [options] file...",
 "LLVM 'Clang' Compiler: http://clang.llvm.org";,
 /*Include=*/driver::options::CC1Option,
 /*Exclude=*/0, /*ShowAllAliases=*/false);
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -68,6 +68,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
@@ -1433,7 +1434,8 @@
   if (!ShowHidden)
 ExcludedFlagsBitmask |= HelpHidden;
 
-  getOpts().PrintHelp(llvm::outs(), Name.c_str(), DriverTitle.c_str(),
+  std::string Usage = llvm::formatv("{0} [options] file...", Name).str();
+  getOpts().PrintHelp(llvm::outs(), Usage.c_str(), DriverTitle.c_str(),
   IncludedFlagsBitmask, ExcludedFlagsBitmask,
   /*ShowAllAliases=*/false);
 }


Index: tools/driver/cc1as_main.cpp
===
--- tools/driver/cc1as_main.cpp
+++ tools/driver/cc1as_main.cpp
@@ -534,7 +534,8 @@
 
   if (Asm.ShowHelp) {
 std::unique_ptr Opts(driver::createDriverOptTable());
-Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
+Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] file...",
+"Clang Integrated Assembler",
 /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
 /*ShowAllAliases=*/false);
 return 0;
Index: lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -183,7 +183,7 @@
   // Honor -help.
   if (Clang->getFrontendOpts().ShowHelp) {
 std::unique_ptr Opts = driver::createDriverOptTable();
-Opts->PrintHelp(llvm::outs(), "clang -cc1",
+Opts->PrintHelp(llvm::outs(), "clang -cc1 [options] file...",
 "LLVM 'Clang' Compiler: http://clang.llvm.org";,
 /*Include=*/driver::options::CC1Option,
 /*Exclude=*/0, /*ShowAllAliases=*/false);
Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -68,6 +68,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
@@ -1433,7 +1434,8 @@
   if (!ShowHidden)
 ExcludedFlagsBitmask |= HelpHidden;
 
-  getOpts().PrintHelp(llvm::outs(), Name.c_str(), DriverTitle.c_str(),
+  std::string Usage = llvm::formatv("{0} [options] file...", Name).str();
+  getOpts().PrintHelp(llvm::outs(), Usage.c_str(), DriverTitle.c_str(),
   IncludedFlagsBitmask, ExcludedFlagsBitmask,
   /*ShowAllAliases=*/false);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51109: [Driver][cc1][cc1as] Call OptTable::PrintHelp with explicit " [options] file..."

2018-10-09 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL344098: [Driver][cc1][cc1as] Call OptTable::PrintHelp with 
explicit " [options] file..." (authored by MaskRay, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D51109

Files:
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  cfe/trunk/tools/driver/cc1as_main.cpp


Index: cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -183,7 +183,7 @@
   // Honor -help.
   if (Clang->getFrontendOpts().ShowHelp) {
 std::unique_ptr Opts = driver::createDriverOptTable();
-Opts->PrintHelp(llvm::outs(), "clang -cc1",
+Opts->PrintHelp(llvm::outs(), "clang -cc1 [options] file...",
 "LLVM 'Clang' Compiler: http://clang.llvm.org";,
 /*Include=*/driver::options::CC1Option,
 /*Exclude=*/0, /*ShowAllAliases=*/false);
Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -68,6 +68,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
@@ -1433,7 +1434,8 @@
   if (!ShowHidden)
 ExcludedFlagsBitmask |= HelpHidden;
 
-  getOpts().PrintHelp(llvm::outs(), Name.c_str(), DriverTitle.c_str(),
+  std::string Usage = llvm::formatv("{0} [options] file...", Name).str();
+  getOpts().PrintHelp(llvm::outs(), Usage.c_str(), DriverTitle.c_str(),
   IncludedFlagsBitmask, ExcludedFlagsBitmask,
   /*ShowAllAliases=*/false);
 }
Index: cfe/trunk/tools/driver/cc1as_main.cpp
===
--- cfe/trunk/tools/driver/cc1as_main.cpp
+++ cfe/trunk/tools/driver/cc1as_main.cpp
@@ -534,7 +534,8 @@
 
   if (Asm.ShowHelp) {
 std::unique_ptr Opts(driver::createDriverOptTable());
-Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
+Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] file...",
+"Clang Integrated Assembler",
 /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
 /*ShowAllAliases=*/false);
 return 0;


Index: cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -183,7 +183,7 @@
   // Honor -help.
   if (Clang->getFrontendOpts().ShowHelp) {
 std::unique_ptr Opts = driver::createDriverOptTable();
-Opts->PrintHelp(llvm::outs(), "clang -cc1",
+Opts->PrintHelp(llvm::outs(), "clang -cc1 [options] file...",
 "LLVM 'Clang' Compiler: http://clang.llvm.org";,
 /*Include=*/driver::options::CC1Option,
 /*Exclude=*/0, /*ShowAllAliases=*/false);
Index: cfe/trunk/lib/Driver/Driver.cpp
===
--- cfe/trunk/lib/Driver/Driver.cpp
+++ cfe/trunk/lib/Driver/Driver.cpp
@@ -68,6 +68,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
@@ -1433,7 +1434,8 @@
   if (!ShowHidden)
 ExcludedFlagsBitmask |= HelpHidden;
 
-  getOpts().PrintHelp(llvm::outs(), Name.c_str(), DriverTitle.c_str(),
+  std::string Usage = llvm::formatv("{0} [options] file...", Name).str();
+  getOpts().PrintHelp(llvm::outs(), Usage.c_str(), DriverTitle.c_str(),
   IncludedFlagsBitmask, ExcludedFlagsBitmask,
   /*ShowAllAliases=*/false);
 }
Index: cfe/trunk/tools/driver/cc1as_main.cpp
===
--- cfe/trunk/tools/driver/cc1as_main.cpp
+++ cfe/trunk/tools/driver/cc1as_main.cpp
@@ -534,7 +534,8 @@
 
   if (Asm.ShowHelp) {
 std::unique_ptr Opts(driver::createDriverOptTable());
-Opts->PrintHelp(llvm::outs(), "clang -cc1as", "Clang Integrated Assembler",
+Opts->PrintHelp(llvm::outs(), "clang -cc1as [options] file...",
+"Clang Integrated Assembler",
 /*Include=*/driver::options::CC1AsOption, /*Exclude=*/0,
 /*ShowAllAliases=*/false);
 return 0;
___
cf

[PATCH] D53060: [clang-move] Remove clang:: qualifier

2018-10-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added a reviewer: hokein.
Herald added subscribers: cfe-commits, ioeric.

The use sites are enclosed by `namespace clang`, so clang:: is not
necessary. Many unqualified names have already been used, e.g. SourceManager 
SourceLocation LangOptions. This change makes the code terser and more 
consistent.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53060

Files:
  clang-move/ClangMove.cpp

Index: clang-move/ClangMove.cpp
===
--- clang-move/ClangMove.cpp
+++ clang-move/ClangMove.cpp
@@ -128,18 +128,17 @@
  AbsoluteFilePath;
 }
 
-class FindAllIncludes : public clang::PPCallbacks {
+class FindAllIncludes : public PPCallbacks {
 public:
   explicit FindAllIncludes(SourceManager *SM, ClangMoveTool *const MoveTool)
   : SM(*SM), MoveTool(MoveTool) {}
 
-  void InclusionDirective(clang::SourceLocation HashLoc,
-  const clang::Token & /*IncludeTok*/,
+  void InclusionDirective(SourceLocation HashLoc, const Token & /*IncludeTok*/,
   StringRef FileName, bool IsAngled,
-  clang::CharSourceRange FilenameRange,
-  const clang::FileEntry * /*File*/,
-  StringRef SearchPath, StringRef /*RelativePath*/,
-  const clang::Module * /*Imported*/,
+  CharSourceRange FilenameRange,
+  const FileEntry * /*File*/, StringRef SearchPath,
+  StringRef /*RelativePath*/,
+  const Module * /*Imported*/,
   SrcMgr::CharacteristicKind /*FileType*/) override {
 if (const auto *FileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc)))
   MoveTool->addIncludes(FileName, IsAngled, SearchPath,
@@ -165,9 +164,9 @@
   : MoveTool(MoveTool) {}
 
   void run(const MatchFinder::MatchResult &Result) override {
-const auto *FD = Result.Nodes.getNodeAs("function");
+const auto *FD = Result.Nodes.getNodeAs("function");
 assert(FD);
-const clang::NamedDecl *D = FD;
+const NamedDecl *D = FD;
 if (const auto *FTD = FD->getDescribedFunctionTemplate())
   D = FTD;
 MoveDeclFromOldFileToNewFile(MoveTool, D);
@@ -183,7 +182,7 @@
   : MoveTool(MoveTool) {}
 
   void run(const MatchFinder::MatchResult &Result) override {
-const auto *VD = Result.Nodes.getNodeAs("var");
+const auto *VD = Result.Nodes.getNodeAs("var");
 assert(VD);
 MoveDeclFromOldFileToNewFile(MoveTool, VD);
   }
@@ -198,10 +197,10 @@
   : MoveTool(MoveTool) {}
 
   void run(const MatchFinder::MatchResult &Result) override {
-if (const auto *TD = Result.Nodes.getNodeAs("typedef"))
+if (const auto *TD = Result.Nodes.getNodeAs("typedef"))
   MoveDeclFromOldFileToNewFile(MoveTool, TD);
 else if (const auto *TAD =
- Result.Nodes.getNodeAs("type_alias")) {
+ Result.Nodes.getNodeAs("type_alias")) {
   const NamedDecl * D = TAD;
   if (const auto * TD = TAD->getDescribedAliasTemplate())
 D = TD;
@@ -219,7 +218,7 @@
   : MoveTool(MoveTool) {}
 
   void run(const MatchFinder::MatchResult &Result) override {
-const auto *ED = Result.Nodes.getNodeAs("enum");
+const auto *ED = Result.Nodes.getNodeAs("enum");
 assert(ED);
 MoveDeclFromOldFileToNewFile(MoveTool, ED);
   }
@@ -233,21 +232,19 @@
   explicit ClassDeclarationMatch(ClangMoveTool *MoveTool)
   : MoveTool(MoveTool) {}
   void run(const MatchFinder::MatchResult &Result) override {
-clang::SourceManager* SM = &Result.Context->getSourceManager();
-if (const auto *CMD =
-Result.Nodes.getNodeAs("class_method"))
+SourceManager *SM = &Result.Context->getSourceManager();
+if (const auto *CMD = Result.Nodes.getNodeAs("class_method"))
   MatchClassMethod(CMD, SM);
-else if (const auto *VD = Result.Nodes.getNodeAs(
-   "class_static_var_decl"))
+else if (const auto *VD =
+ Result.Nodes.getNodeAs("class_static_var_decl"))
   MatchClassStaticVariable(VD, SM);
-else if (const auto *CD = Result.Nodes.getNodeAs(
-   "moved_class"))
+else if (const auto *CD =
+ Result.Nodes.getNodeAs("moved_class"))
   MatchClassDeclaration(CD, SM);
   }
 
 private:
-  void MatchClassMethod(const clang::CXXMethodDecl* CMD,
-clang::SourceManager* SM) {
+  void MatchClassMethod(const CXXMethodDecl *CMD, SourceManager *SM) {
 // Skip inline class methods. isInline() ast matcher doesn't ignore this
 // case.
 if (!CMD->isInlined()) {
@@ -262,13 +259,11 @@
 }
   }
 
-  void MatchClassStaticVariable(const clang::NamedDecl *VD,
-clang::SourceManager* SM) {
+  void MatchClassStaticVariable(const NamedDecl *VD, SourceManager *SM) {
 MoveDeclFromOldFileToNew

[PATCH] D53060: [clang-move] Remove clang:: qualifier

2018-10-11 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL344256: [clang-move] Remove clang:: qualifier (authored by 
MaskRay, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D53060

Files:
  clang-tools-extra/trunk/clang-move/ClangMove.cpp

Index: clang-tools-extra/trunk/clang-move/ClangMove.cpp
===
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp
@@ -128,18 +128,17 @@
  AbsoluteFilePath;
 }
 
-class FindAllIncludes : public clang::PPCallbacks {
+class FindAllIncludes : public PPCallbacks {
 public:
   explicit FindAllIncludes(SourceManager *SM, ClangMoveTool *const MoveTool)
   : SM(*SM), MoveTool(MoveTool) {}
 
-  void InclusionDirective(clang::SourceLocation HashLoc,
-  const clang::Token & /*IncludeTok*/,
+  void InclusionDirective(SourceLocation HashLoc, const Token & /*IncludeTok*/,
   StringRef FileName, bool IsAngled,
-  clang::CharSourceRange FilenameRange,
-  const clang::FileEntry * /*File*/,
-  StringRef SearchPath, StringRef /*RelativePath*/,
-  const clang::Module * /*Imported*/,
+  CharSourceRange FilenameRange,
+  const FileEntry * /*File*/, StringRef SearchPath,
+  StringRef /*RelativePath*/,
+  const Module * /*Imported*/,
   SrcMgr::CharacteristicKind /*FileType*/) override {
 if (const auto *FileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc)))
   MoveTool->addIncludes(FileName, IsAngled, SearchPath,
@@ -165,9 +164,9 @@
   : MoveTool(MoveTool) {}
 
   void run(const MatchFinder::MatchResult &Result) override {
-const auto *FD = Result.Nodes.getNodeAs("function");
+const auto *FD = Result.Nodes.getNodeAs("function");
 assert(FD);
-const clang::NamedDecl *D = FD;
+const NamedDecl *D = FD;
 if (const auto *FTD = FD->getDescribedFunctionTemplate())
   D = FTD;
 MoveDeclFromOldFileToNewFile(MoveTool, D);
@@ -183,7 +182,7 @@
   : MoveTool(MoveTool) {}
 
   void run(const MatchFinder::MatchResult &Result) override {
-const auto *VD = Result.Nodes.getNodeAs("var");
+const auto *VD = Result.Nodes.getNodeAs("var");
 assert(VD);
 MoveDeclFromOldFileToNewFile(MoveTool, VD);
   }
@@ -198,10 +197,10 @@
   : MoveTool(MoveTool) {}
 
   void run(const MatchFinder::MatchResult &Result) override {
-if (const auto *TD = Result.Nodes.getNodeAs("typedef"))
+if (const auto *TD = Result.Nodes.getNodeAs("typedef"))
   MoveDeclFromOldFileToNewFile(MoveTool, TD);
 else if (const auto *TAD =
- Result.Nodes.getNodeAs("type_alias")) {
+ Result.Nodes.getNodeAs("type_alias")) {
   const NamedDecl * D = TAD;
   if (const auto * TD = TAD->getDescribedAliasTemplate())
 D = TD;
@@ -219,7 +218,7 @@
   : MoveTool(MoveTool) {}
 
   void run(const MatchFinder::MatchResult &Result) override {
-const auto *ED = Result.Nodes.getNodeAs("enum");
+const auto *ED = Result.Nodes.getNodeAs("enum");
 assert(ED);
 MoveDeclFromOldFileToNewFile(MoveTool, ED);
   }
@@ -233,21 +232,19 @@
   explicit ClassDeclarationMatch(ClangMoveTool *MoveTool)
   : MoveTool(MoveTool) {}
   void run(const MatchFinder::MatchResult &Result) override {
-clang::SourceManager* SM = &Result.Context->getSourceManager();
-if (const auto *CMD =
-Result.Nodes.getNodeAs("class_method"))
+SourceManager *SM = &Result.Context->getSourceManager();
+if (const auto *CMD = Result.Nodes.getNodeAs("class_method"))
   MatchClassMethod(CMD, SM);
-else if (const auto *VD = Result.Nodes.getNodeAs(
-   "class_static_var_decl"))
+else if (const auto *VD =
+ Result.Nodes.getNodeAs("class_static_var_decl"))
   MatchClassStaticVariable(VD, SM);
-else if (const auto *CD = Result.Nodes.getNodeAs(
-   "moved_class"))
+else if (const auto *CD =
+ Result.Nodes.getNodeAs("moved_class"))
   MatchClassDeclaration(CD, SM);
   }
 
 private:
-  void MatchClassMethod(const clang::CXXMethodDecl* CMD,
-clang::SourceManager* SM) {
+  void MatchClassMethod(const CXXMethodDecl *CMD, SourceManager *SM) {
 // Skip inline class methods. isInline() ast matcher doesn't ignore this
 // case.
 if (!CMD->isInlined()) {
@@ -262,13 +259,11 @@
 }
   }
 
-  void MatchClassStaticVariable(const clang::NamedDecl *VD,
-clang::SourceManager* SM) {
+  void MatchClassStaticVariable(const NamedDecl *VD, SourceManager *SM) {
 MoveDeclFromOldFileToNewFile(MoveTool, VD);
   }
 
-  void MatchCla

[PATCH] D37726: clang: alias -static-{libstdc++, libgcc} for LLVM variants

2018-10-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In https://reviews.llvm.org/D37726#1264233, @rsmith wrote:

> It would be nice to have a flag here that's agnostic to the value supplied to 
> `-rtlib` or `-stdlib`. Perhaps `-static-rtlib` (for either libgcc or 
> compiler-rt) and `-static-stdlib` (for either libc++ or libstdc++). (Yes, 
> it's bad that we use `stdlib` to mean "the C++ standard library", but that is 
> the status quo.)


https://reviews.llvm.org/rC113891 introduced `-stdlib`... yes it would be nice 
if it were named `-c++stdlib` or `-cxxstdlib`... (I'm not good at naming)

We don't need to be 100% compatible with gcc here.. `--push-state` `-Bstatic` 
`-lc++/-lstdc++` `--pop-state` can also be used. `--pop-state` works with 
ld.bfd/gold/lld


Repository:
  rL LLVM

https://reviews.llvm.org/D37726



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


[PATCH] D53238: [Driver] Add -static-{rtlib, stdlib} and make -static-{libgcc, libstdc++} their aliases

2018-10-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: martell, rsmith.
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D53238

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/CommonArgs.cpp
  lib/Driver/ToolChains/Darwin.cpp
  lib/Driver/ToolChains/DragonFly.cpp
  lib/Driver/ToolChains/Fuchsia.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Hexagon.cpp
  lib/Driver/ToolChains/MinGW.cpp
  lib/Driver/ToolChains/Myriad.cpp
  lib/Driver/ToolChains/NaCl.cpp

Index: lib/Driver/ToolChains/NaCl.cpp
===
--- lib/Driver/ToolChains/NaCl.cpp
+++ lib/Driver/ToolChains/NaCl.cpp
@@ -134,12 +134,12 @@
   if (D.CCCIsCXX() &&
   !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
 if (ToolChain.ShouldLinkCXXStdlib(Args)) {
-  bool OnlyLibstdcxxStatic =
-  Args.hasArg(options::OPT_static_libstdcxx) && !IsStatic;
-  if (OnlyLibstdcxxStatic)
+  bool OnlyCXXstdlib =
+  Args.hasArg(options::OPT_static_stdlib) && !IsStatic;
+  if (OnlyCXXstdlib)
 CmdArgs.push_back("-Bstatic");
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
-  if (OnlyLibstdcxxStatic)
+  if (OnlyCXXstdlib)
 CmdArgs.push_back("-Bdynamic");
 }
 CmdArgs.push_back("-lm");
Index: lib/Driver/ToolChains/Myriad.cpp
===
--- lib/Driver/ToolChains/Myriad.cpp
+++ lib/Driver/ToolChains/Myriad.cpp
@@ -145,7 +145,7 @@
   // Eat some arguments that may be present but have no effect.
   Args.ClaimAllArgs(options::OPT_g_Group);
   Args.ClaimAllArgs(options::OPT_w);
-  Args.ClaimAllArgs(options::OPT_static_libgcc);
+  Args.ClaimAllArgs(options::OPT_static_rtlib);
 
   if (Args.hasArg(options::OPT_s)) // Pass the 'strip' option.
 CmdArgs.push_back("-s");
Index: lib/Driver/ToolChains/MinGW.cpp
===
--- lib/Driver/ToolChains/MinGW.cpp
+++ lib/Driver/ToolChains/MinGW.cpp
@@ -66,7 +66,7 @@
   // Make use of compiler-rt if --rtlib option is used
   ToolChain::RuntimeLibType RLT = getToolChain().GetRuntimeLibType(Args);
   if (RLT == ToolChain::RLT_Libgcc) {
-bool Static = Args.hasArg(options::OPT_static_libgcc) ||
+bool Static = Args.hasArg(options::OPT_static_rtlib) ||
   Args.hasArg(options::OPT_static);
 bool Shared = Args.hasArg(options::OPT_shared);
 bool CXX = getToolChain().getDriver().CCCIsCXX();
@@ -192,12 +192,12 @@
   // TODO: Add profile stuff here
 
   if (TC.ShouldLinkCXXStdlib(Args)) {
-bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
-   !Args.hasArg(options::OPT_static);
-if (OnlyLibstdcxxStatic)
+bool OnlyCXXstdlib = Args.hasArg(options::OPT_static_stdlib) &&
+ !Args.hasArg(options::OPT_static);
+if (OnlyCXXstdlib)
   CmdArgs.push_back("-Bstatic");
 TC.AddCXXStdlibLibArgs(Args, CmdArgs);
-if (OnlyLibstdcxxStatic)
+if (OnlyCXXstdlib)
   CmdArgs.push_back("-Bdynamic");
   }
 
Index: lib/Driver/ToolChains/Hexagon.cpp
===
--- lib/Driver/ToolChains/Hexagon.cpp
+++ lib/Driver/ToolChains/Hexagon.cpp
@@ -218,7 +218,7 @@
   Args.ClaimAllArgs(options::OPT_emit_llvm);
   Args.ClaimAllArgs(options::OPT_w); // Other warning options are already
  // handled somewhere else.
-  Args.ClaimAllArgs(options::OPT_static_libgcc);
+  Args.ClaimAllArgs(options::OPT_static_rtlib);
 
   //
   //
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -445,12 +445,12 @@
   if (D.CCCIsCXX() &&
   !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
 if (ToolChain.ShouldLinkCXXStdlib(Args)) {
-  bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
- !Args.hasArg(options::OPT_static);
-  if (OnlyLibstdcxxStatic)
+  bool OnlyCXXstdlib = Args.hasArg(options::OPT_static_stdlib) &&
+   !Args.hasArg(options::OPT_static);
+  if (OnlyCXXstdlib)
 CmdArgs.push_back("-Bstatic");
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
-  if (OnlyLibstdcxxStatic)
+  if (OnlyCXXstdlib)
 CmdArgs.push_back("-Bdynamic");
 }
 CmdArgs.push_back("-lm");
Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -117,12 +117,12 @@
 
 if (D.CCCIsCXX()) {
   if (ToolChain.ShouldLinkCXXStdlib(Args)) {
-bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_st

[PATCH] D53238: [Driver] Add -static-{rtlib, stdlib} and make -static-{libgcc, libstdc++} their aliases

2018-10-12 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 169538.
MaskRay added a comment.

Rename local variables


Repository:
  rC Clang

https://reviews.llvm.org/D53238

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/CommonArgs.cpp
  lib/Driver/ToolChains/Darwin.cpp
  lib/Driver/ToolChains/DragonFly.cpp
  lib/Driver/ToolChains/Fuchsia.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Hexagon.cpp
  lib/Driver/ToolChains/MinGW.cpp
  lib/Driver/ToolChains/Myriad.cpp
  lib/Driver/ToolChains/NaCl.cpp

Index: lib/Driver/ToolChains/NaCl.cpp
===
--- lib/Driver/ToolChains/NaCl.cpp
+++ lib/Driver/ToolChains/NaCl.cpp
@@ -134,12 +134,12 @@
   if (D.CCCIsCXX() &&
   !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
 if (ToolChain.ShouldLinkCXXStdlib(Args)) {
-  bool OnlyLibstdcxxStatic =
-  Args.hasArg(options::OPT_static_libstdcxx) && !IsStatic;
-  if (OnlyLibstdcxxStatic)
+  bool StaticCXXStdlib =
+  Args.hasArg(options::OPT_static_stdlib) && !IsStatic;
+  if (StaticCXXStdlib)
 CmdArgs.push_back("-Bstatic");
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
-  if (OnlyLibstdcxxStatic)
+  if (StaticCXXStdlib)
 CmdArgs.push_back("-Bdynamic");
 }
 CmdArgs.push_back("-lm");
Index: lib/Driver/ToolChains/Myriad.cpp
===
--- lib/Driver/ToolChains/Myriad.cpp
+++ lib/Driver/ToolChains/Myriad.cpp
@@ -145,7 +145,7 @@
   // Eat some arguments that may be present but have no effect.
   Args.ClaimAllArgs(options::OPT_g_Group);
   Args.ClaimAllArgs(options::OPT_w);
-  Args.ClaimAllArgs(options::OPT_static_libgcc);
+  Args.ClaimAllArgs(options::OPT_static_rtlib);
 
   if (Args.hasArg(options::OPT_s)) // Pass the 'strip' option.
 CmdArgs.push_back("-s");
Index: lib/Driver/ToolChains/MinGW.cpp
===
--- lib/Driver/ToolChains/MinGW.cpp
+++ lib/Driver/ToolChains/MinGW.cpp
@@ -66,7 +66,7 @@
   // Make use of compiler-rt if --rtlib option is used
   ToolChain::RuntimeLibType RLT = getToolChain().GetRuntimeLibType(Args);
   if (RLT == ToolChain::RLT_Libgcc) {
-bool Static = Args.hasArg(options::OPT_static_libgcc) ||
+bool Static = Args.hasArg(options::OPT_static_rtlib) ||
   Args.hasArg(options::OPT_static);
 bool Shared = Args.hasArg(options::OPT_shared);
 bool CXX = getToolChain().getDriver().CCCIsCXX();
@@ -192,12 +192,12 @@
   // TODO: Add profile stuff here
 
   if (TC.ShouldLinkCXXStdlib(Args)) {
-bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
-   !Args.hasArg(options::OPT_static);
-if (OnlyLibstdcxxStatic)
+bool StaticCXXStdlib = Args.hasArg(options::OPT_static_stdlib) &&
+   !Args.hasArg(options::OPT_static);
+if (StaticCXXStdlib)
   CmdArgs.push_back("-Bstatic");
 TC.AddCXXStdlibLibArgs(Args, CmdArgs);
-if (OnlyLibstdcxxStatic)
+if (StaticCXXStdlib)
   CmdArgs.push_back("-Bdynamic");
   }
 
Index: lib/Driver/ToolChains/Hexagon.cpp
===
--- lib/Driver/ToolChains/Hexagon.cpp
+++ lib/Driver/ToolChains/Hexagon.cpp
@@ -218,7 +218,7 @@
   Args.ClaimAllArgs(options::OPT_emit_llvm);
   Args.ClaimAllArgs(options::OPT_w); // Other warning options are already
  // handled somewhere else.
-  Args.ClaimAllArgs(options::OPT_static_libgcc);
+  Args.ClaimAllArgs(options::OPT_static_rtlib);
 
   //
   //
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -445,12 +445,12 @@
   if (D.CCCIsCXX() &&
   !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
 if (ToolChain.ShouldLinkCXXStdlib(Args)) {
-  bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
- !Args.hasArg(options::OPT_static);
-  if (OnlyLibstdcxxStatic)
+  bool StaticCXXStdlib = Args.hasArg(options::OPT_static_stdlib) &&
+ !Args.hasArg(options::OPT_static);
+  if (StaticCXXStdlib)
 CmdArgs.push_back("-Bstatic");
   ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
-  if (OnlyLibstdcxxStatic)
+  if (StaticCXXStdlib)
 CmdArgs.push_back("-Bdynamic");
 }
 CmdArgs.push_back("-lm");
Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -117,12 +117,12 @@
 
 if (D.CCCIsCXX()) {
   if (ToolChain.ShouldLinkCXXStdlib(Args)) {
-bool OnlyLibstdcxxStatic = Args.hasArg(options::O

[PATCH] D53238: [Driver] Add -static-{rtlib, stdlib} and make -static-{libgcc, libstdc++} their aliases

2018-10-18 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Greeting from a dev meeting attendee :)


Repository:
  rC Clang

https://reviews.llvm.org/D53238



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


[PATCH] D56554: [ELF] Add '-z nognustack' opt to suppress emitting PT_GNU_STACK

2019-01-14 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Should `ZNognustack` and `ZExecstack` be unified to a tri-state enum variable?


Repository:
  rLLD LLVM Linker

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

https://reviews.llvm.org/D56554



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


[PATCH] D54428: [clangd] XPC transport layer, framework, test-client

2019-01-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D54428#1359333 , @tamur wrote:

> This patch seems to have broken the compilation. I get the following error on 
> a linux platform:
>  [12/14] Linking CXX executable bin/clangd
>  FAILED: bin/clangd 
>  : && 
> /usr/local/google/home/tamur/src/llvm/2018_nov_12/llvm/Stable/bin/clang++  
> -fPIC -fvisibility-inlines-hidden -Werror=date-time 
> -Werror=unguarded-availability-new -std=c++11 -Wall -Wextra 
> -Wno-unused-parameter -Wwrite-strings -Wcast-qual 
> -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough 
> -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
> -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color 
> -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
> -Wno-nested-anon-types  -fuse-ld=lld -Wl,--color-diagnostics 
> -Wl,-allow-shlib-undefined -Wl,-O3 -Wl,--gc-sections 
> tools/clang/tools/extra/clangd/tool/CMakeFiles/clangd.dir/ClangdMain.cpp.o  
> -o bin/clangd  -Wl,-rpath,"\$ORIGIN/../lib" lib/libLLVMSupport.so.8svn 
> -lpthread lib/libclangBasic.so.8svn lib/libclangDaemon.so.8svn 
> lib/libclangFormat.so.8svn lib/libclangFrontend.so.8svn 
> lib/libclangSema.so.8svn lib/libclangTooling.so.8svn 
> lib/libclangToolingCore.so.8svn && :
>  ld.lld: error: undefined symbol: clang::clangd::newXPCTransport()


Fixed by rCTE351306 


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D54428



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


[PATCH] D55878: [Driver] Use --hash-style=gnu instead of both on FreeBSD

2019-01-27 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Friendly ping :) (This is related to FreeBSD, not OpenBSD)


Repository:
  rC Clang

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

https://reviews.llvm.org/D55878



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


[PATCH] D56554: [ELF] Add '-z nognustack' opt to suppress emitting PT_GNU_STACK

2019-01-30 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> This segment is not supported at all on NetBSD (stack is always 
> non-executable), and the option is meant to be used to disable emitting it.

The string `.note.GNU-stack` takes only a few bytes in `.shstrtab` and a few 
for an `Elf64_Shdr` instance. Are there any tools warning about unknown section 
`.note.GNU-stack` on NetBSD?


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

https://reviews.llvm.org/D56554



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


[PATCH] D53922: [clangd] fix non linux build

2018-11-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I don't even know if this actually does any good. In some libc implementations 
`pthread_setschedparam` may be a no-op (e.g. in musl)


Repository:
  rL LLVM

https://reviews.llvm.org/D53922



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


[PATCH] D53854: [Driver] Use -push-/-pop-state and -as-needed for libc++ on Fuchsia

2018-11-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: lib/Driver/ToolChains/Fuchsia.cpp:128
 if (OnlyLibstdcxxStatic)
-  CmdArgs.push_back("-Bstatic");
+  CmdArgs.push_back("-static");
 ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);

If Fuchsia doesn't use gold, it is fine. gold diverges from ld.bfd (lld) in 
that `-static` switches the whole link to its special static mode. (as usually 
while you link libstdc++/libc++ statically, you can still link other libraries 
normally)

In ld.bfd/lld, `-Bstatic` is synonym with `-static`.


Repository:
  rC Clang

https://reviews.llvm.org/D53854



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


[PATCH] D54112: [Driver] Delete redundant -Bdynamic for libc++ on Fuchsia

2018-11-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: phosek, EricWF, mcgrathr.
Herald added a subscriber: cfe-commits.

The surrounding --push-state saves the "-Bdynamic" state across ld.bfd, gold 
and lld.
lld saves the least states, but the intersection of these linkers is 
--as-needed -Bdynamic --whole-archive

ld/ldlang.h: lang_input_statement_flags::dynamic
gold/options.h: Position_dependent_options::copy_from_options
lld/ELF/Driver.cpp: Stack.emplace_back(Config->AsNeeded, Config->Static, 
InWholeArchive);


Repository:
  rC Clang

https://reviews.llvm.org/D54112

Files:
  lib/Driver/ToolChains/Fuchsia.cpp
  test/Driver/fuchsia.cpp


Index: test/Driver/fuchsia.cpp
===
--- test/Driver/fuchsia.cpp
+++ test/Driver/fuchsia.cpp
@@ -39,7 +39,6 @@
 // CHECK-STATIC: "--as-needed"
 // CHECK-STATIC: "-Bstatic"
 // CHECK-STATIC: "-lc++"
-// CHECK-STATIC: "-Bdynamic"
 // CHECK-STATIC: "-lm"
 // CHECK-STATIC: "--pop-state"
 // CHECK-STATIC: "-lc"
Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -127,8 +127,6 @@
 if (OnlyLibstdcxxStatic)
   CmdArgs.push_back("-Bstatic");
 ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
-if (OnlyLibstdcxxStatic)
-  CmdArgs.push_back("-Bdynamic");
 CmdArgs.push_back("-lm");
 CmdArgs.push_back("--pop-state");
   }


Index: test/Driver/fuchsia.cpp
===
--- test/Driver/fuchsia.cpp
+++ test/Driver/fuchsia.cpp
@@ -39,7 +39,6 @@
 // CHECK-STATIC: "--as-needed"
 // CHECK-STATIC: "-Bstatic"
 // CHECK-STATIC: "-lc++"
-// CHECK-STATIC: "-Bdynamic"
 // CHECK-STATIC: "-lm"
 // CHECK-STATIC: "--pop-state"
 // CHECK-STATIC: "-lc"
Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -127,8 +127,6 @@
 if (OnlyLibstdcxxStatic)
   CmdArgs.push_back("-Bstatic");
 ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs);
-if (OnlyLibstdcxxStatic)
-  CmdArgs.push_back("-Bdynamic");
 CmdArgs.push_back("-lm");
 CmdArgs.push_back("--pop-state");
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54112: [Driver] Delete redundant -Bdynamic for libc++ on Fuchsia

2018-11-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

I'm unclear if you also want as-needed `-lm` or if you accept static `-lm`


Repository:
  rC Clang

https://reviews.llvm.org/D54112



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


[PATCH] D53427: [clangd] Replace StringRef in SymbolLocation with a char pointer.

2018-11-07 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clangd/index/Index.h:84
 inline bool operator==(const SymbolLocation &L, const SymbolLocation &R) {
-  return std::tie(L.FileURI, L.Start, L.End) ==
- std::tie(R.FileURI, R.Start, R.End);
+  return std::make_tuple(llvm::StringRef(L.FileURI), L.Start, L.End) ==
+ std::make_tuple(llvm::StringRef(R.FileURI), R.Start, R.End);

The `StringRef(const char*)` constructor calls `strlen`. Do you believe this 
does not have noticeable performance issue?

(A minor point: `tuple::operator<` calls `operator<` of its components in a not 
very efficient way. The compiler does not know `compare(a, b) < 0` implies 
`compare(b, a) > 0` and `strcmp` may end up being called twice.)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53427



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


[PATCH] D54805: [Driver] Use --push/pop-state with Sanitizer link deps

2018-11-21 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In https://reviews.llvm.org/D54805#1305749, @pcc wrote:

> Unfortunately it looks like the Android NDK uses some ancient version of gold 
> that doesn't support `--push-state`, so we probably can't rely on being able 
> to use it.
>  
> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-android/builds/17287/steps/run%20lit%20tests%20%5Bi686%2Ffugu-userdebug%2FN2G48C%5D/logs/stdio
>  As an alternative solution, could we add these flags at the start of the 
> linker command line? That way, we're guaranteed that the linker will be in 
> the `--no-as-needed` state.


`gold --push-state` seems a new thing. It is available since Dec 2016 (version 
1.14)

I'm also interested in the history of

  // Force linking against the system libraries sanitizers depends on
  // (see PR15823 why this is necessary).
  CmdArgs.push_back("--no-as-needed");

PR15823 leans slightly to the user-error side to me. Shouldn't the user ensure 
the use of `-Wl,--as-needed` is eventually closed so that system libraries 
start with the `-Wl--no-as-needed` state?


Repository:
  rC Clang

https://reviews.llvm.org/D54805



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


[PATCH] D54355: Use is.constant intrinsic for __builtin_constant_p

2018-11-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

https://reviews.llvm.org/rC347417 makes `constexpr string_view service = "HELLO 
WORD SERVICE"` (P0426) broken with libstdc++

  % cat a.cc
  constexpr bool __constant_string_p(const char *__s) {
while (__builtin_constant_p(*__s) && *__s)
  __s++;
return __builtin_constant_p(*__s);
  }
  
  constexpr bool n = __constant_string_p("a");



  % fclang++ -std=c++17 -fsyntax-only a.cc
  a.cc:1:16: error: constexpr function never produces a constant expression 
[-Winvalid-constexpr]
  constexpr bool __constant_string_p(const char *__s) {
 ^
  a.cc:2:10: note: subexpression not valid in a constant expression
while (__builtin_constant_p(*__s) && *__s)
   ^
  a.cc:7:16: error: constexpr variable 'n' must be initialized by a constant 
expression
  constexpr bool n = __constant_string_p("a");
 ^   
  a.cc:2:10: note: subexpression not valid in a constant expression
while (__builtin_constant_p(*__s) && *__s)
   ^
  a.cc:7:20: note: in call to '__constant_string_p(&"a"[0])'
  constexpr bool n = __constant_string_p("a");
 ^
  2 errors generated.

Fourth time should be a charm...


Repository:
  rC Clang

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

https://reviews.llvm.org/D54355



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


  1   2   3   4   5   6   7   8   9   10   >