[PATCH] D41491: [clangd] Add a tool to build YAML-format global symbols.

2017-12-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/CMakeLists.txt:50
 add_subdirectory(tool)
+add_subdirectory(global-symbol-builder)

I think generally we run `check-clang-tools` before committing - I guess it's 
OK not to have tests for this experimental tool, but we should at least keep it 
building. Can you make check-clang-tools build it?



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:106
+  std::error_code EC;
+  SymbolSlab Result;
+  std::mutex SymbolMutex;

FYI D41506 changes this API, adding `SymbolSlab::Builder`. Shouldn't be a 
problem, but we'll need to merge.



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:112
+for (const auto &Symbol : NewSymbols) {
+  auto it = Result.find(Symbol.second.ID);
+  if (it == Result.end())

This seems like you might end up overwriting good declarations with bad ones 
(e.g. forward decls). Picking one with a simple heuristic like "longest range" 
would get classes right.



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:175
+  *Executor->get()->getExecutionContext()));
+  auto Err = Executor->get()->execute(std::move(T));
+  if (Err) {

I don't understand why we need to plumb callbacks through SymbolCollector.
Can't we just write the slab after this line?



Comment at: clangd/global-symbol-builder/run-global-symbol-builder.py:1
+#!/usr/bin/env python
+#

So we now have three copies of this script...
I'm probably missing something, but what's here that's hard to do in a single 
binary?
I'd have to think it'd be faster if we weren't constantly spawning new 
processes and roundtripping all the data through YAML-on-disk.

(If this is just expedience because we have an existing template to copy, I'm 
happy to try to combine it into one binary myself)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41491



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


[PATCH] D41491: [clangd] Add a tool to build YAML-format global symbols.

2017-12-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

This looks like it does the right thing, ISTM it has a few too many moving 
parts.
I might be missing why they're necessary, or we might not want to bother 
polishing this - maybe you can give me more context offline.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41491



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


[clang-tools-extra] r321348 - [clangd] Improve packing of Symbol struct. NFC

2017-12-22 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Fri Dec 22 00:12:39 2017
New Revision: 321348

URL: http://llvm.org/viewvc/llvm-project?rev=321348&view=rev
Log:
[clangd] Improve packing of Symbol struct. NFC

Modified:
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp

Modified: clang-tools-extra/trunk/clangd/index/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Index.h?rev=321348&r1=321347&r2=321348&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Fri Dec 22 00:12:39 2017
@@ -82,13 +82,13 @@ void operator>>(llvm::StringRef HexStr,
 struct Symbol {
   // The ID of the symbol.
   SymbolID ID;
+  // The symbol information, like symbol kind.
+  index::SymbolInfo SymInfo;
   // The unqualified name of the symbol, e.g. "bar" (for "n1::n2::bar").
   llvm::StringRef Name;
   // The scope (e.g. namespace) of the symbol, e.g. "n1::n2" (for
   // "n1::n2::bar").
   llvm::StringRef Scope;
-  // The symbol information, like symbol kind.
-  index::SymbolInfo SymInfo;
   // The location of the canonical declaration of the symbol.
   //
   // A C++ symbol could have multiple declarations and one definition (e.g.

Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp?rev=321348&r1=321347&r2=321348&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Fri Dec 22 
00:12:39 2017
@@ -101,8 +101,14 @@ bool SymbolCollector::handleDeclOccurenc
SM.getFileOffset(D->getLocEnd())};
 std::string QName = ND->getQualifiedNameAsString();
 auto ScopeAndName = splitQualifiedName(QName);
-Symbols.insert({std::move(ID), ScopeAndName.second, ScopeAndName.first,
-index::getSymbolInfo(D), std::move(Location)});
+
+Symbol S;
+S.ID = std::move(ID);
+S.Scope = ScopeAndName.first;
+S.Name = ScopeAndName.second;
+S.SymInfo = index::getSymbolInfo(D);
+S.CanonicalDeclaration = Location;
+Symbols.insert(S);
   }
 
   return true;


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


Re: [clang-tools-extra] r321286 - [clangd] Fix use after free.

2017-12-22 Thread Sam McCall via cfe-commits
Thanks Ben!

This was my r321272 - in hindsight I really should have run the tests with
asan for that type of change.

On Thu, Dec 21, 2017 at 6:51 PM, Benjamin Kramer via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: d0k
> Date: Thu Dec 21 09:51:35 2017
> New Revision: 321286
>
> URL: http://llvm.org/viewvc/llvm-project?rev=321286&view=rev
> Log:
> [clangd] Fix use after free.
>
> Found by asan.
>
> Modified:
> clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
>
> Modified: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clangd/index/SymbolCollector.cpp?rev=321286&r1=321285&r2=321286&
> view=diff
> 
> ==
> --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
> +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Thu Dec 21
> 09:51:35 2017
> @@ -95,9 +95,10 @@ bool SymbolCollector::handleDeclOccurenc
>return true;
>
>  auto &SM = ND->getASTContext().getSourceManager();
> -SymbolLocation Location = {
> -makeAbsolutePath(SM, SM.getFilename(D->getLocation())),
> -SM.getFileOffset(D->getLocStart()),
> SM.getFileOffset(D->getLocEnd())};
> +std::string FilePath =
> +makeAbsolutePath(SM, SM.getFilename(D->getLocation()));
> +SymbolLocation Location = {FilePath, SM.getFileOffset(D->
> getLocStart()),
> +   SM.getFileOffset(D->getLocEnd())};
>  std::string QName = ND->getQualifiedNameAsString();
>  auto ScopeAndName = splitQualifiedName(QName);
>  Symbols.insert({std::move(ID), ScopeAndName.second,
> ScopeAndName.first,
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r321350 - [clangd] Simplify GlobalCompilationDatabase, cache missing GCDs

2017-12-22 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Fri Dec 22 01:47:34 2017
New Revision: 321350

URL: http://llvm.org/viewvc/llvm-project?rev=321350&view=rev
Log:
[clangd] Simplify GlobalCompilationDatabase, cache missing GCDs

Modified:
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp?rev=321350&r1=321349&r2=321350&view=diff
==
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp Fri Dec 22 
01:47:34 2017
@@ -31,12 +31,15 @@ DirectoryBasedGlobalCompilationDatabase:
 
 llvm::Optional
 DirectoryBasedGlobalCompilationDatabase::getCompileCommand(PathRef File) const 
{
-  if (auto CDB = getCompilationDatabase(File)) {
+  if (auto CDB = getCDBForFile(File)) {
 auto Candidates = CDB->getCompileCommands(File);
 if (!Candidates.empty()) {
   addExtraFlags(File, Candidates.front());
   return std::move(Candidates.front());
 }
+  } else {
+log(Context::empty(), // FIXME(ibiryukov): pass a proper Context here.
+"Failed to find compilation database for " + Twine(File));
   }
   return llvm::None;
 }
@@ -71,59 +74,32 @@ void DirectoryBasedGlobalCompilationData
 }
 
 tooling::CompilationDatabase *
-DirectoryBasedGlobalCompilationDatabase::tryLoadDatabaseFromPath(
-PathRef File) const {
-
-  namespace path = llvm::sys::path;
-  auto CachedIt = CompilationDatabases.find(File);
-
-  assert((path::is_absolute(File, path::Style::posix) ||
-  path::is_absolute(File, path::Style::windows)) &&
- "path must be absolute");
-
+DirectoryBasedGlobalCompilationDatabase::getCDBInDirLocked(PathRef Dir) const {
+  // FIXME(ibiryukov): Invalidate cached compilation databases on changes
+  auto CachedIt = CompilationDatabases.find(Dir);
   if (CachedIt != CompilationDatabases.end())
 return CachedIt->second.get();
   std::string Error = "";
-  auto CDB = tooling::CompilationDatabase::loadFromDirectory(File, Error);
-  if (CDB) {
-auto Result = CDB.get();
-CompilationDatabases.insert(std::make_pair(File, std::move(CDB)));
-return Result;
-  }
-
-  return nullptr;
+  auto CDB = tooling::CompilationDatabase::loadFromDirectory(Dir, Error);
+  auto Result = CDB.get();
+  CompilationDatabases.insert(std::make_pair(Dir, std::move(CDB)));
+  return Result;
 }
 
 tooling::CompilationDatabase *
-DirectoryBasedGlobalCompilationDatabase::getCompilationDatabase(
-PathRef File) const {
-  std::lock_guard Lock(Mutex);
-
+DirectoryBasedGlobalCompilationDatabase::getCDBForFile(PathRef File) const {
   namespace path = llvm::sys::path;
-  if (CompileCommandsDir.hasValue()) {
-tooling::CompilationDatabase *ReturnValue =
-tryLoadDatabaseFromPath(CompileCommandsDir.getValue());
-if (ReturnValue == nullptr) {
-  // FIXME(ibiryukov): pass a proper Context here.
-  log(Context::empty(), "Failed to find compilation database for " +
-Twine(File) + "in overriden directory " +
-CompileCommandsDir.getValue());
-}
-return ReturnValue;
-  }
+  assert((path::is_absolute(File, path::Style::posix) ||
+  path::is_absolute(File, path::Style::windows)) &&
+ "path must be absolute");
 
+  std::lock_guard Lock(Mutex);
+  if (CompileCommandsDir)
+return getCDBInDirLocked(*CompileCommandsDir);
   for (auto Path = path::parent_path(File); !Path.empty();
-   Path = path::parent_path(Path)) {
-auto CDB = tryLoadDatabaseFromPath(Path);
-if (!CDB)
-  continue;
-// FIXME(ibiryukov): Invalidate cached compilation databases on changes
-return CDB;
-  }
-
-  // FIXME(ibiryukov): pass a proper Context here.
-  log(Context::empty(),
-  "Failed to find compilation database for " + Twine(File));
+   Path = path::parent_path(Path))
+if (auto CDB = getCDBInDirLocked(Path))
+  return CDB;
   return nullptr;
 }
 

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h?rev=321350&r1=321349&r2=321350&view=diff
==
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h Fri Dec 22 
01:47:34 2017
@@ -65,8 +65,8 @@ public:
   void setExtraFlagsForFile(PathRef File, std::vector ExtraFlags);
 
 private:
-  tooling::CompilationDatabase *getCompilationDatabase(PathRef File) const;
-  tooling::CompilationDatabase *tryLoadDatabaseFromPath(PathRef File) const;
+  tooling::CompilationDatabase *getCDBForFile(PathRef File) const;
+  too

[PATCH] D41394: [CodeGen] Support generation of TBAA info in the new format

2017-12-22 Thread Ivan Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321351: [CodeGen] Support generation of TBAA info in the new 
format (authored by kosarev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41394?vs=127838&id=127993#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41394

Files:
  cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
  cfe/trunk/test/CodeGen/tbaa.cpp

Index: cfe/trunk/test/CodeGen/tbaa.cpp
===
--- cfe/trunk/test/CodeGen/tbaa.cpp
+++ cfe/trunk/test/CodeGen/tbaa.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -no-struct-path-tbaa -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s -check-prefix=PATH
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s -check-prefixes=PATH,OLD-PATH
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -new-struct-path-tbaa -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s -check-prefixes=PATH,NEW-PATH
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -O0 -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s -check-prefix=NO-TBAA
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -relaxed-aliasing -disable-llvm-passes %s -emit-llvm -o - | FileCheck %s -check-prefix=NO-TBAA
 // Test TBAA metadata generated by front-end.
@@ -248,29 +249,57 @@
 // CHECK: [[TYPE_i16]] = !{!"short", [[TYPE_char]],
 // CHECK: [[TAG_char]] = !{[[TYPE_char]], [[TYPE_char]], i64 0}
 
-// PATH: [[TYPE_CHAR:!.*]] = !{!"omnipotent char", !
-// PATH: [[TAG_i32]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0}
-// PATH: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR]]
-// PATH: [[TAG_A_f32]] = !{[[TYPE_A:!.*]], [[TYPE_INT]], i64 4}
-// PATH: [[TYPE_A]] = !{!"_ZTS7StructA", [[TYPE_SHORT:!.*]], i64 0, [[TYPE_INT]], i64 4, [[TYPE_SHORT]], i64 8, [[TYPE_INT]], i64 12}
-// PATH: [[TYPE_SHORT:!.*]] = !{!"short", [[TYPE_CHAR]]
-// PATH: [[TAG_A_f16]] = !{[[TYPE_A]], [[TYPE_SHORT]], i64 0}
-// PATH: [[TAG_B_a_f32]] = !{[[TYPE_B:!.*]], [[TYPE_INT]], i64 8}
-// PATH: [[TYPE_B]] = !{!"_ZTS7StructB", [[TYPE_SHORT]], i64 0, [[TYPE_A]], i64 4, [[TYPE_INT]], i64 20}
-// PATH: [[TAG_B_a_f16]] = !{[[TYPE_B]], [[TYPE_SHORT]], i64 4}
-// PATH: [[TAG_B_f32]] = !{[[TYPE_B]], [[TYPE_INT]], i64 20}
-// PATH: [[TAG_B_a_f32_2]] = !{[[TYPE_B]], [[TYPE_INT]], i64 16}
-// PATH: [[TAG_S_f32]] = !{[[TYPE_S:!.*]], [[TYPE_INT]], i64 4}
-// PATH: [[TYPE_S]] = !{!"_ZTS7StructS", [[TYPE_SHORT]], i64 0, [[TYPE_INT]], i64 4}
-// PATH: [[TAG_S_f16]] = !{[[TYPE_S]], [[TYPE_SHORT]], i64 0}
-// PATH: [[TAG_S2_f32]] = !{[[TYPE_S2:!.*]], [[TYPE_INT]], i64 4}
-// PATH: [[TYPE_S2]] = !{!"_ZTS8StructS2", [[TYPE_SHORT]], i64 0, [[TYPE_INT]], i64 4}
-// PATH: [[TAG_S2_f16]] = !{[[TYPE_S2]], [[TYPE_SHORT]], i64 0}
-// PATH: [[TAG_C_b_a_f32]] = !{[[TYPE_C:!.*]], [[TYPE_INT]], i64 12}
-// PATH: [[TYPE_C]] = !{!"_ZTS7StructC", [[TYPE_SHORT]], i64 0, [[TYPE_B]], i64 4, [[TYPE_INT]], i64 28}
-// PATH: [[TAG_D_b_a_f32]] = !{[[TYPE_D:!.*]], [[TYPE_INT]], i64 12}
-// PATH: [[TYPE_D]] = !{!"_ZTS7StructD", [[TYPE_SHORT]], i64 0, [[TYPE_B]], i64 4, [[TYPE_INT]], i64 28, [[TYPE_CHAR]], i64 32}
-// PATH: [[TAG_five_b]] = !{[[TYPE_five:!.*]], [[TYPE_CHAR]], i64 1}
-// PATH: [[TYPE_five]] = !{!"_ZTS4five", [[TYPE_CHAR]], i64 0, [[TYPE_INT]], i64 1, [[TYPE_CHAR]], i64 1, [[TYPE_CHAR]], i64 2}
-// PATH: [[TAG_six_b]] = !{[[TYPE_six:!.*]], [[TYPE_CHAR]], i64 4}
-// PATH: [[TYPE_six]] = !{!"_ZTS3six", [[TYPE_CHAR]], i64 0, [[TYPE_INT]], i64 4, [[TYPE_CHAR]], i64 4, [[TYPE_CHAR]], i64 5}
+// OLD-PATH: [[TYPE_CHAR:!.*]] = !{!"omnipotent char", !
+// OLD-PATH: [[TAG_i32]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0}
+// OLD-PATH: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR]]
+// OLD-PATH: [[TAG_A_f32]] = !{[[TYPE_A:!.*]], [[TYPE_INT]], i64 4}
+// OLD-PATH: [[TYPE_A]] = !{!"_ZTS7StructA", [[TYPE_SHORT:!.*]], i64 0, [[TYPE_INT]], i64 4, [[TYPE_SHORT]], i64 8, [[TYPE_INT]], i64 12}
+// OLD-PATH: [[TYPE_SHORT:!.*]] = !{!"short", [[TYPE_CHAR]]
+// OLD-PATH: [[TAG_A_f16]] = !{[[TYPE_A]], [[TYPE_SHORT]], i64 0}
+// OLD-PATH: [[TAG_B_a_f32]] = !{[[TYPE_B:!.*]], [[TYPE_INT]], i64 8}
+// OLD-PATH: [[TYPE_B]] = !{!"_ZTS7StructB", [[TYPE_SHORT]], i64 0, [[TYPE_A]], i64 4, [[TYPE_INT]], i64 20}
+// OLD-PATH: [[TAG_B_a_f16]] = !{[[TYPE_B]], [[TYPE_SHORT]], i64 4}
+// OLD-PATH: [[TAG_B_f32]] = !{[[TYPE_B]], [[TYPE_INT]], i64 20}
+// OLD-PATH: [[TAG_B_a_f32_2]] = !{[[TYPE_B]], [[TYPE_INT]], i64 16}
+// OLD-PATH: [[TAG_S_f32]] = !{[[TYPE_S:!.*]], [[TYPE_INT]], i64 4}
+// OLD-PATH: [[TYPE_S]] = !{!"_ZTS7StructS", [[TYPE_SHORT]], i64 0, [[TYPE_INT]], i64 4}
+// OLD-PATH: [[TAG_S_f16]] = !{[[TYPE_S]], [[TYPE_SHORT]], i64 0}
+// OLD-PATH: [[TAG_S2_f32]] = !{[[TYPE_S2:!.*]], [[TYPE_INT]], i64 4}
+// OLD-PATH: [[TYPE_S2]] = !{!"_ZTS8StructS2", [[TYPE_SHORT]], i64 0, [[TYPE_INT]], i64 4}
+// OLD-PATH: [[TA

r321351 - [CodeGen] Support generation of TBAA info in the new format

2017-12-22 Thread Ivan A. Kosarev via cfe-commits
Author: kosarev
Date: Fri Dec 22 01:54:23 2017
New Revision: 321351

URL: http://llvm.org/viewvc/llvm-project?rev=321351&view=rev
Log:
[CodeGen] Support generation of TBAA info in the new format

Now that the MDBuilder helpers generating TBAA type and access
descriptors in the new format are in place, we can teach clang to
use them when requested.

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

Modified:
cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
cfe/trunk/test/CodeGen/tbaa.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp?rev=321351&r1=321350&r2=321351&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Fri Dec 22 01:54:23 2017
@@ -59,7 +59,10 @@ llvm::MDNode *CodeGenTBAA::getRoot() {
 llvm::MDNode *CodeGenTBAA::createScalarTypeNode(StringRef Name,
 llvm::MDNode *Parent,
 uint64_t Size) {
-  (void)Size; // TODO: Support generation of size-aware type nodes.
+  if (CodeGenOpts.NewStructPathTBAA) {
+llvm::Metadata *Id = MDHelper.createString(Name);
+return MDHelper.createTBAATypeNode(Parent, Size, Id);
+  }
   return MDHelper.createTBAAScalarTypeNode(Name, Parent);
 }
 
@@ -300,8 +303,12 @@ llvm::MDNode *CodeGenTBAA::getBaseTypeIn
   OutName = RD->getName();
 }
 
-// TODO: Support size-aware type nodes and create one here for the
-// given aggregate type.
+if (CodeGenOpts.NewStructPathTBAA) {
+  llvm::MDNode *Parent = getChar();
+  uint64_t Size = Context.getTypeSizeInChars(Ty).getQuantity();
+  llvm::Metadata *Id = MDHelper.createString(OutName);
+  return MDHelper.createTBAATypeNode(Parent, Size, Id, Fields);
+}
 
 // Create the struct type node with a vector of pairs (offset, type).
 SmallVector, 4> OffsetsAndTypes;
@@ -348,6 +355,10 @@ llvm::MDNode *CodeGenTBAA::getAccessTagI
 Info.BaseType = Info.AccessType;
 assert(!Info.Offset && "Nonzero offset for an access with no base type!");
   }
+  if (CodeGenOpts.NewStructPathTBAA) {
+return N = MDHelper.createTBAAAccessTag(Info.BaseType, Info.AccessType,
+Info.Offset, Info.Size);
+  }
   return N = MDHelper.createTBAAStructTagNode(Info.BaseType, Info.AccessType,
   Info.Offset);
 }

Modified: cfe/trunk/test/CodeGen/tbaa.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa.cpp?rev=321351&r1=321350&r2=321351&view=diff
==
--- cfe/trunk/test/CodeGen/tbaa.cpp (original)
+++ cfe/trunk/test/CodeGen/tbaa.cpp Fri Dec 22 01:54:23 2017
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -no-struct-path-tbaa 
-disable-llvm-passes %s -emit-llvm -o - | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -disable-llvm-passes %s 
-emit-llvm -o - | FileCheck %s -check-prefix=PATH
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -disable-llvm-passes %s 
-emit-llvm -o - | FileCheck %s -check-prefixes=PATH,OLD-PATH
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -new-struct-path-tbaa 
-disable-llvm-passes %s -emit-llvm -o - | FileCheck %s 
-check-prefixes=PATH,NEW-PATH
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -O0 -disable-llvm-passes %s 
-emit-llvm -o - | FileCheck %s -check-prefix=NO-TBAA
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -O1 -relaxed-aliasing 
-disable-llvm-passes %s -emit-llvm -o - | FileCheck %s -check-prefix=NO-TBAA
 // Test TBAA metadata generated by front-end.
@@ -248,29 +249,57 @@ uint32_t g15(StructS *S, StructS3 *S3, u
 // CHECK: [[TYPE_i16]] = !{!"short", [[TYPE_char]],
 // CHECK: [[TAG_char]] = !{[[TYPE_char]], [[TYPE_char]], i64 0}
 
-// PATH: [[TYPE_CHAR:!.*]] = !{!"omnipotent char", !
-// PATH: [[TAG_i32]] = !{[[TYPE_INT:!.*]], [[TYPE_INT]], i64 0}
-// PATH: [[TYPE_INT]] = !{!"int", [[TYPE_CHAR]]
-// PATH: [[TAG_A_f32]] = !{[[TYPE_A:!.*]], [[TYPE_INT]], i64 4}
-// PATH: [[TYPE_A]] = !{!"_ZTS7StructA", [[TYPE_SHORT:!.*]], i64 0, 
[[TYPE_INT]], i64 4, [[TYPE_SHORT]], i64 8, [[TYPE_INT]], i64 12}
-// PATH: [[TYPE_SHORT:!.*]] = !{!"short", [[TYPE_CHAR]]
-// PATH: [[TAG_A_f16]] = !{[[TYPE_A]], [[TYPE_SHORT]], i64 0}
-// PATH: [[TAG_B_a_f32]] = !{[[TYPE_B:!.*]], [[TYPE_INT]], i64 8}
-// PATH: [[TYPE_B]] = !{!"_ZTS7StructB", [[TYPE_SHORT]], i64 0, [[TYPE_A]], 
i64 4, [[TYPE_INT]], i64 20}
-// PATH: [[TAG_B_a_f16]] = !{[[TYPE_B]], [[TYPE_SHORT]], i64 4}
-// PATH: [[TAG_B_f32]] = !{[[TYPE_B]], [[TYPE_INT]], i64 20}
-// PATH: [[TAG_B_a_f32_2]] = !{[[TYPE_B]], [[TYPE_INT]], i64 16}
-// PATH: [[TAG_S_f32]] = !{[[TYPE_S:!.*]], [[TYPE_INT]], i64 4}
-// PATH: [[TYPE_S]] = !{!"_ZTS7StructS", [[TYPE_SHORT]], i64 0, [[TYPE_INT]], 
i64 4}
-// PATH: [[TAG_S_f16]]

[PATCH] D41399: [CodeGen] Represent array members in new-format TBAA type descriptors

2017-12-22 Thread Ivan Kosarev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321352: [CodeGen] Represent array members in new-format TBAA 
type descriptors (authored by kosarev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41399?vs=127742&id=127994#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41399

Files:
  cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
  cfe/trunk/test/CodeGen/tbaa-array.cpp


Index: cfe/trunk/test/CodeGen/tbaa-array.cpp
===
--- cfe/trunk/test/CodeGen/tbaa-array.cpp
+++ cfe/trunk/test/CodeGen/tbaa-array.cpp
@@ -1,18 +1,52 @@
 // RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \
 // RUN: -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \
+// RUN: -new-struct-path-tbaa -emit-llvm -o - | \
+// RUN: FileCheck -check-prefix=CHECK-NEW %s
 //
 // Check that we generate correct TBAA information for accesses to array
 // elements.
 
 struct A { int i; };
 struct B { A a[1]; };
+struct C { int i; int x[3]; };
 
 int foo(B *b) {
 // CHECK-LABEL: _Z3fooP1B
 // CHECK: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]]
+// CHECK-NEW-LABEL: _Z3fooP1B
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]]
   return b->a->i;
 }
 
+// Check that members of array types are represented correctly.
+int bar(C *c) {
+// CHECK-NEW-LABEL: _Z3barP1C
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_C_i:!.*]]
+  return c->i;
+}
+
+int bar2(C *c) {
+// CHECK-NEW-LABEL: _Z4bar2P1C
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]
+  return c->x[2];
+}
+
+int bar3(C *c, int j) {
+// CHECK-NEW-LABEL: _Z4bar3P1Ci
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]
+  return c->x[j];
+}
+
 // CHECK-DAG: [[TAG_A_i]] = !{[[TYPE_A:!.*]], [[TYPE_int:!.*]], i64 0}
 // CHECK-DAG: [[TYPE_A]] = !{!"_ZTS1A", !{{.*}}, i64 0}
 // CHECK-DAG: [[TYPE_int]] = !{!"int", !{{.*}}, i64 0}
+
+// CHECK-NEW-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"}
+// CHECK-NEW-DAG: [[TYPE_int:!.*]] = !{[[TYPE_char]], i64 4, !"int"}
+// CHECK-NEW-DAG: [[TAG_int]] = !{[[TYPE_int]], [[TYPE_int]], i64 0, i64 4}
+// CHECK-NEW-DAG: [[TYPE_pointer:!.*]] = !{[[TYPE_char]], i64 8, !"any 
pointer"}
+// CHECK-NEW-DAG: [[TYPE_A:!.*]] = !{[[TYPE_char]], i64 4, !"_ZTS1A", 
[[TYPE_int]], i64 0, i64 4}
+// CHECK-NEW-DAG: [[TAG_A_i]] = !{[[TYPE_A]], [[TYPE_int]], i64 0, i64 4}
+// CHECK-NEW-DAG: [[TYPE_C:!.*]] = !{[[TYPE_char]], i64 16, !"_ZTS1C", 
[[TYPE_int]], i64 0, i64 4, [[TYPE_int]], i64 4, i64 12}
+// CHECK-NEW-DAG: [[TAG_C_i]] = !{[[TYPE_C:!.*]], [[TYPE_int:!.*]], i64 0, i64 
4}
Index: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
@@ -161,6 +161,10 @@
   if (Ty->isPointerType() || Ty->isReferenceType())
 return createScalarTypeNode("any pointer", getChar(), Size);
 
+  // Accesses to arrays are accesses to objects of their element types.
+  if (CodeGenOpts.NewStructPathTBAA && Ty->isArrayType())
+return getTypeInfo(cast(Ty)->getElementType());
+
   // Enum types are distinct types. In C++ they have "underlying types",
   // however they aren't related for TBAA.
   if (const EnumType *ETy = dyn_cast(Ty)) {


Index: cfe/trunk/test/CodeGen/tbaa-array.cpp
===
--- cfe/trunk/test/CodeGen/tbaa-array.cpp
+++ cfe/trunk/test/CodeGen/tbaa-array.cpp
@@ -1,18 +1,52 @@
 // RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \
 // RUN: -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \
+// RUN: -new-struct-path-tbaa -emit-llvm -o - | \
+// RUN: FileCheck -check-prefix=CHECK-NEW %s
 //
 // Check that we generate correct TBAA information for accesses to array
 // elements.
 
 struct A { int i; };
 struct B { A a[1]; };
+struct C { int i; int x[3]; };
 
 int foo(B *b) {
 // CHECK-LABEL: _Z3fooP1B
 // CHECK: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]]
+// CHECK-NEW-LABEL: _Z3fooP1B
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]]
   return b->a->i;
 }
 
+// Check that members of array types are represented correctly.
+int bar(C *c) {
+// CHECK-NEW-LABEL: _Z3barP1C
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_C_i:!.*]]
+  return c->i;
+}
+
+int bar2(C *c) {
+// CHECK-NEW-LABEL: _Z4bar2P1C
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]
+  return c->x[2];
+}
+
+int bar3(C *c, int j) {
+// CHECK-NEW-LABEL: _Z4bar3P1Ci
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]
+  return c->x[j];
+}
+
 // CHECK-DAG: [[TAG_A_i]] = !{[[TYPE_A:!.*]], [[TYPE_int:!.*]], i64 0}
 // CHECK-DAG: [[TYPE_A]] = !{!"_ZTS1A", !{{.*}}, i64 0}
 // CHECK-DAG: [[TYPE_int]] = !{!"int", !{{.*}}, i64 0}
+
+// CHECK-NEW-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"}
+// CHECK-NEW-DAG: [[TYPE_int:!.*]] = !{[[TYP

r321352 - [CodeGen] Represent array members in new-format TBAA type descriptors

2017-12-22 Thread Ivan A. Kosarev via cfe-commits
Author: kosarev
Date: Fri Dec 22 01:57:24 2017
New Revision: 321352

URL: http://llvm.org/viewvc/llvm-project?rev=321352&view=rev
Log:
[CodeGen] Represent array members in new-format TBAA type descriptors

Now that in the new TBAA format we allow access types to be of
any object types, including aggregate ones, it becomes critical
to specify types of all sub-objects such aggregates comprise as
their members. In order to meet this requirement, this patch
enables generation of field descriptors for members of array
types.

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

Modified:
cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
cfe/trunk/test/CodeGen/tbaa-array.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp?rev=321352&r1=321351&r2=321352&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Fri Dec 22 01:57:24 2017
@@ -161,6 +161,10 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHe
   if (Ty->isPointerType() || Ty->isReferenceType())
 return createScalarTypeNode("any pointer", getChar(), Size);
 
+  // Accesses to arrays are accesses to objects of their element types.
+  if (CodeGenOpts.NewStructPathTBAA && Ty->isArrayType())
+return getTypeInfo(cast(Ty)->getElementType());
+
   // Enum types are distinct types. In C++ they have "underlying types",
   // however they aren't related for TBAA.
   if (const EnumType *ETy = dyn_cast(Ty)) {

Modified: cfe/trunk/test/CodeGen/tbaa-array.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/tbaa-array.cpp?rev=321352&r1=321351&r2=321352&view=diff
==
--- cfe/trunk/test/CodeGen/tbaa-array.cpp (original)
+++ cfe/trunk/test/CodeGen/tbaa-array.cpp Fri Dec 22 01:57:24 2017
@@ -1,18 +1,52 @@
 // RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \
 // RUN: -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux -O1 -disable-llvm-passes %s \
+// RUN: -new-struct-path-tbaa -emit-llvm -o - | \
+// RUN: FileCheck -check-prefix=CHECK-NEW %s
 //
 // Check that we generate correct TBAA information for accesses to array
 // elements.
 
 struct A { int i; };
 struct B { A a[1]; };
+struct C { int i; int x[3]; };
 
 int foo(B *b) {
 // CHECK-LABEL: _Z3fooP1B
 // CHECK: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]]
+// CHECK-NEW-LABEL: _Z3fooP1B
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_A_i:!.*]]
   return b->a->i;
 }
 
+// Check that members of array types are represented correctly.
+int bar(C *c) {
+// CHECK-NEW-LABEL: _Z3barP1C
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_C_i:!.*]]
+  return c->i;
+}
+
+int bar2(C *c) {
+// CHECK-NEW-LABEL: _Z4bar2P1C
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]
+  return c->x[2];
+}
+
+int bar3(C *c, int j) {
+// CHECK-NEW-LABEL: _Z4bar3P1Ci
+// CHECK-NEW: load i32, {{.*}}, !tbaa [[TAG_int:!.*]]
+  return c->x[j];
+}
+
 // CHECK-DAG: [[TAG_A_i]] = !{[[TYPE_A:!.*]], [[TYPE_int:!.*]], i64 0}
 // CHECK-DAG: [[TYPE_A]] = !{!"_ZTS1A", !{{.*}}, i64 0}
 // CHECK-DAG: [[TYPE_int]] = !{!"int", !{{.*}}, i64 0}
+
+// CHECK-NEW-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"}
+// CHECK-NEW-DAG: [[TYPE_int:!.*]] = !{[[TYPE_char]], i64 4, !"int"}
+// CHECK-NEW-DAG: [[TAG_int]] = !{[[TYPE_int]], [[TYPE_int]], i64 0, i64 4}
+// CHECK-NEW-DAG: [[TYPE_pointer:!.*]] = !{[[TYPE_char]], i64 8, !"any 
pointer"}
+// CHECK-NEW-DAG: [[TYPE_A:!.*]] = !{[[TYPE_char]], i64 4, !"_ZTS1A", 
[[TYPE_int]], i64 0, i64 4}
+// CHECK-NEW-DAG: [[TAG_A_i]] = !{[[TYPE_A]], [[TYPE_int]], i64 0, i64 4}
+// CHECK-NEW-DAG: [[TYPE_C:!.*]] = !{[[TYPE_char]], i64 16, !"_ZTS1C", 
[[TYPE_int]], i64 0, i64 4, [[TYPE_int]], i64 4, i64 12}
+// CHECK-NEW-DAG: [[TAG_C_i]] = !{[[TYPE_C:!.*]], [[TYPE_int:!.*]], i64 0, i64 
4}


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


[PATCH] D41495: [clangd] Skip function bodies when building the preamble

2017-12-22 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/ClangdUnit.cpp:536
+  // so we set SkipFunctionBodies back to false after preamble is built.
+  assert(!CI->getFrontendOpts().SkipFunctionBodies);
+  CI->getFrontendOpts().SkipFunctionBodies = true;

sammccall wrote:
> Nit: I think the comment/assert focus too much on the 'what' at the expense 
> of the 'why' - just the first sentence here is probably enough (without the 
> second and without the assert).
> 
> And below, something like:
> // For the main file, we do want the AST and diagnostics for function 
> bodies. 
That looks better. Updated the comments, thanks.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41495



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


[PATCH] D41495: [clangd] Skip function bodies when building the preamble

2017-12-22 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 127995.
ilya-biryukov marked an inline comment as done.
ilya-biryukov added a comment.

- Updated a comment


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41495

Files:
  clangd/ClangdUnit.cpp


Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -529,12 +529,22 @@
   IntrusiveRefCntPtr PreambleDiagsEngine =
   CompilerInstance::createDiagnostics(
   &CI->getDiagnosticOpts(), &PreambleDiagnosticsConsumer, false);
+
+  // Skip function bodies when building the preamble to speed up building
+  // the preamble and make it smaller.
+  assert(!CI->getFrontendOpts().SkipFunctionBodies);
+  CI->getFrontendOpts().SkipFunctionBodies = true;
+
   CppFilePreambleCallbacks SerializedDeclsCollector;
   auto BuiltPreamble = PrecompiledPreamble::Build(
   *CI, ContentsBuffer.get(), Bounds, *PreambleDiagsEngine, VFS, PCHs,
   /*StoreInMemory=*/That->StorePreamblesInMemory,
   SerializedDeclsCollector);
 
+  // When building the AST for the main file, we do want the function
+  // bodies.
+  CI->getFrontendOpts().SkipFunctionBodies = false;
+
   if (BuiltPreamble) {
 log(Ctx, "Built preamble of size " + Twine(BuiltPreamble->getSize()) +
  " for file " + Twine(That->FileName));


Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -529,12 +529,22 @@
   IntrusiveRefCntPtr PreambleDiagsEngine =
   CompilerInstance::createDiagnostics(
   &CI->getDiagnosticOpts(), &PreambleDiagnosticsConsumer, false);
+
+  // Skip function bodies when building the preamble to speed up building
+  // the preamble and make it smaller.
+  assert(!CI->getFrontendOpts().SkipFunctionBodies);
+  CI->getFrontendOpts().SkipFunctionBodies = true;
+
   CppFilePreambleCallbacks SerializedDeclsCollector;
   auto BuiltPreamble = PrecompiledPreamble::Build(
   *CI, ContentsBuffer.get(), Bounds, *PreambleDiagsEngine, VFS, PCHs,
   /*StoreInMemory=*/That->StorePreamblesInMemory,
   SerializedDeclsCollector);
 
+  // When building the AST for the main file, we do want the function
+  // bodies.
+  CI->getFrontendOpts().SkipFunctionBodies = false;
+
   if (BuiltPreamble) {
 log(Ctx, "Built preamble of size " + Twine(BuiltPreamble->getSize()) +
  " for file " + Twine(That->FileName));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41458: WIP: [libc++][C++17] Elementary string conversions for integral types

2017-12-22 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 127996.
lichray added a comment.

Added std::from_chars


Repository:
  rCXX libc++

https://reviews.llvm.org/D41458

Files:
  .gitignore
  include/charconv
  include/support/itoa/
  include/support/itoa/itoa.h
  lib/CMakeLists.txt
  src/support/itoa/
  src/support/itoa/itoa.cpp
  test/std/utilities/charconv/
  test/std/utilities/charconv/charconv.from.chars/
  test/std/utilities/charconv/charconv.from.chars/integral.bool.fail.cpp
  test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp
  test/std/utilities/charconv/charconv.to.chars/
  test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp
  test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp
  test/support/charconv_test_helpers.h

Index: test/support/charconv_test_helpers.h
===
--- /dev/null
+++ test/support/charconv_test_helpers.h
@@ -0,0 +1,233 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef SUPPORT_CHARCONV_TEST_HELPERS_H
+#define SUPPORT_CHARCONV_TEST_HELPERS_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+using std::false_type;
+using std::true_type;
+
+template 
+constexpr auto
+is_non_narrowing(From a) -> decltype(To{a}, true_type())
+{
+return {};
+}
+
+template 
+constexpr auto
+is_non_narrowing(...) -> false_type
+{
+return {};
+}
+
+template 
+constexpr bool
+_fits_in(T, true_type /* non-narrowing*/, ...)
+{
+return true;
+}
+
+template >
+constexpr bool
+_fits_in(T v, false_type, true_type /* T signed*/, true_type /* X signed */)
+{
+return xl::lowest() <= v && v <= (xl::max)();
+}
+
+template >
+constexpr bool
+_fits_in(T v, false_type, true_type /* T signed */, false_type /* X unsigned*/)
+{
+return 0 <= v && typename std::make_unsigned::type(v) <= (xl::max)();
+}
+
+template >
+constexpr bool
+_fits_in(T v, false_type, false_type /* T unsigned */, ...)
+{
+return v <= typename std::make_unsigned::type((xl::max)());
+}
+
+template 
+constexpr bool
+fits_in(T v)
+{
+return _fits_in(v, is_non_narrowing(v), std::is_signed(),
+   std::is_signed());
+}
+
+template 
+struct to_chars_test_base
+{
+template 
+void test(T v, char const (&expect)[N], Ts... args)
+{
+using std::to_chars;
+std::to_chars_result r;
+
+constexpr size_t len = N - 1;
+static_assert(len > 0, "expected output won't be empty");
+
+if (!fits_in(v))
+return;
+
+r = to_chars(buf, buf + len - 1, X(v), args...);
+LIBCPP_ASSERT(r.ptr == buf + len - 1);
+LIBCPP_ASSERT(r.ec == std::errc::value_too_large);
+
+r = to_chars(buf, buf + sizeof(buf), X(v), args...);
+LIBCPP_ASSERT(r.ptr == buf + len);
+LIBCPP_ASSERT(r.ec == std::errc{});
+LIBCPP_ASSERT(memcmp(buf, expect, len) == 0);
+}
+
+template 
+void test_value(X v, Ts... args)
+{
+using std::to_chars;
+std::to_chars_result r;
+
+r = to_chars(buf, buf + sizeof(buf), v, args...);
+LIBCPP_ASSERT(r.ec == std::errc{});
+*r.ptr = '\0';
+
+auto a = fromchars(buf, r.ptr, args...);
+LIBCPP_ASSERT(v == a);
+
+auto ep = r.ptr - 1;
+r = to_chars(buf, ep, v, args...);
+LIBCPP_ASSERT(r.ptr == ep);
+LIBCPP_ASSERT(r.ec == std::errc::value_too_large);
+}
+
+private:
+using max_t = typename std::conditional::value, long long,
+unsigned long long>::type;
+
+static auto fromchars(char const* p, char const* ep, int base, true_type)
+-> long long
+{
+char* last;
+auto r = strtoll(p, &last, base);
+LIBCPP_ASSERT(last == ep);
+
+return r;
+}
+
+static auto fromchars(char const* p, char const* ep, int base, false_type)
+-> unsigned long long
+{
+char* last;
+auto r = strtoull(p, &last, base);
+LIBCPP_ASSERT(last == ep);
+
+return r;
+}
+
+static auto fromchars(char const* p, char const* ep, int base = 10) -> max_t
+{
+return fromchars(p, ep, base, std::is_signed());
+}
+
+char buf[100];
+};
+
+template 
+struct roundtrip_test_base
+{
+template 
+void test(T v, Ts... args)
+{
+using std::from_chars;
+using std::to_chars;
+std::from_chars_result r2;
+std::to_chars_result r;
+X x = 0xc;
+
+if (fits_in(v))
+{
+r = to_chars(buf, buf + sizeof(buf), v, args...);
+LIBCPP_ASSERT(r.ec == std::errc{});
+
+r2 = from_chars(bu

[PATCH] D41537: Optionally add code completion results for arrow instead of dot

2017-12-22 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: klimek, bkramer, arphaman, ilya-biryukov, erikjv.

Currently getting such completions requires source correction, reparsing and 
calling completion again. And if it shows no results and rollback is required 
then it costs one more reparse.
With this change it's possible to get all results which can be later filtered 
to split changes which require correction.


https://reviews.llvm.org/D41537

Files:
  include/clang-c/Index.h
  include/clang/Sema/CodeCompleteConsumer.h
  include/clang/Sema/CodeCompleteOptions.h
  lib/Frontend/ASTUnit.cpp
  lib/Sema/CodeCompleteConsumer.cpp
  lib/Sema/SemaCodeComplete.cpp
  test/Index/complete-arrow-for-dot.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndexCodeCompletion.cpp

Index: tools/libclang/CIndexCodeCompletion.cpp
===
--- tools/libclang/CIndexCodeCompletion.cpp
+++ tools/libclang/CIndexCodeCompletion.cpp
@@ -238,6 +238,16 @@
   return cxstring::createRef(CCStr->getBriefComment());
 }
 
+unsigned
+clang_getCompletionRequiresDotToArrowCorrection(CXCompletionString completion_string) {
+  CodeCompletionString *CCStr = (CodeCompletionString *)completion_string;
+
+  if (!CCStr)
+return false;
+
+  return CCStr->requiresDotToArrowCorrection();
+}
+
 namespace {
 
 /// \brief The CXCodeCompleteResults structure we allocate internally;
@@ -643,13 +653,13 @@
   ArrayRef unsaved_files,
   unsigned options) {
   bool IncludeBriefComments = options & CXCodeComplete_IncludeBriefComments;
+  bool TryArrowInsteadOfDot = options & CXCodeComplete_TryArrowInsteadOfDot;
 
 #ifdef UDP_CODE_COMPLETION_LOGGER
 #ifdef UDP_CODE_COMPLETION_LOGGER_PORT
   const llvm::TimeRecord &StartTime =  llvm::TimeRecord::getCurrentTime();
 #endif
 #endif
-
   bool EnableLogging = getenv("LIBCLANG_CODE_COMPLETION_LOGGING") != nullptr;
 
   if (cxtu::isNotUsableTU(TU)) {
@@ -689,6 +699,7 @@
   // Create a code-completion consumer to capture the results.
   CodeCompleteOptions Opts;
   Opts.IncludeBriefComments = IncludeBriefComments;
+  Opts.TryArrowInsteadOfDot = TryArrowInsteadOfDot;
   CaptureCompletionResults Capture(Opts, *Results, &TU);
 
   // Perform completion.
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
@@ -2227,7 +2227,13 @@
 fprintf(file, "(brief comment: %s)", BriefCommentCString);
   }
   clang_disposeString(BriefComment);
-  
+
+  unsigned RequiresDotToArrowCorrection =
+  clang_getCompletionRequiresDotToArrowCorrection(
+  completion_result->CompletionString);
+  if (RequiresDotToArrowCorrection) {
+fprintf(file, " (requires correction: \".\" to \"->\")");
+  }
   fprintf(file, "\n");
 }
 
@@ -2324,6 +2330,8 @@
 completionOptions |= CXCodeComplete_IncludeCodePatterns;
   if (getenv("CINDEXTEST_COMPLETION_BRIEF_COMMENTS"))
 completionOptions |= CXCodeComplete_IncludeBriefComments;
+  if (getenv("CINDEXTEST_COMPLETION_TRY_ARROW_INSTEAD_OF_DOT"))
+completionOptions |= CXCodeComplete_TryArrowInsteadOfDot;
   
   if (timing_only)
 input += strlen("-code-completion-timing=");
Index: test/Index/complete-arrow-for-dot.cpp
===
--- /dev/null
+++ test/Index/complete-arrow-for-dot.cpp
@@ -0,0 +1,29 @@
+struct X {
+  void doSomething();
+
+  int field;
+};
+
+void X::doSomething() {
+  // RUN: c-index-test -code-completion-at=%s:10:8 %s | FileCheck %s
+  // RUN: env CINDEXTEST_COMPLETION_TRY_ARROW_INSTEAD_OF_DOT=1 c-index-test -code-completion-at=%s:10:8 %s | FileCheck -check-prefix=CHECK-WITH-CORRECTION %s
+  this.;
+}
+
+// CHECK-NOT: CXXMethod:{ResultType void}{TypedText doSomething}{LeftParen (}{RightParen )} (34) (requires correction: "." to "->")
+// CHECK-NOT: FieldDecl:{ResultType int}{TypedText field} (35) (requires correction: "." to "->")
+// CHECK-NOT: CXXMethod:{ResultType X &}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightParen )} (79) (requires correction: "." to "->")
+// CHECK-NOT: CXXMethod:{ResultType X &}{TypedText operator=}{LeftParen (}{Placeholder X &&}{RightParen )} (79) (requires correction: "." to "->")
+// CHECK-NOT: StructDecl:{TypedText X}{Text ::} (75) (requires correction: "." to "->")
+// CHECK-NOT: CXXDestructor:{ResultType void}{TypedText ~X}{LeftParen (}{RightParen )} (79) (requires correction: "." to "->")
+// CHECK: Completion contexts:
+// CHECK: Dot member access
+
+// CHECK-WITH-CORRECTION: CXXMethod:{ResultType void}{TypedText doSomething}{LeftParen (}{RightParen )} (34) (requires correction: "." to "->")
+// CHECK-WITH-CORRECTION: FieldDecl:{ResultType int}{TypedText field} (35) (requires correction: "." to "->")
+// CHECK-WITH-CORRECTION: CXXMethod:{ResultType X &}{TypedText operator=}{LeftParen (}{Placeholder const X &}{RightPar

[PATCH] D41538: [analyzer] Fix some checker's output plist not containing the checker name #2

2017-12-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun created this revision.
xazax.hun added reviewers: NoQ, dcoughlin, george.karpenkov.
Herald added subscribers: dkrupp, a.sidorin, rnkovacs, szepet, 
baloghadamsoftware, whisperity.

Unfortunately, currently, the analyzer core sets the checker name after the 
constructor was already run. So if we set the BugType in the constructor, the 
output plist will not contain a checker name. Right now the idiomatic solution 
is to create the BugType lazily. This patch moves the lazy initialization from 
the checker side to the analyzer core. I also found some bugs, when some 
checkers were triggered even if they were not enabled or wrong checker name is 
emitted to the plist.

In the future probably it would be better to alter the signature of the 
checkers' constructor to set the name in the constructor so it is possible to 
create the BugType eagerly.

This patch is an alternative approach to https://reviews.llvm.org/D37437.


Repository:
  rC Clang

https://reviews.llvm.org/D41538

Files:
  include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  lib/StaticAnalyzer/Checkers/ValistChecker.cpp
  test/Analysis/malloc.c

Index: test/Analysis/malloc.c
===
--- test/Analysis/malloc.c
+++ test/Analysis/malloc.c
@@ -1720,13 +1720,6 @@
   }
 }
 
-char *dupstrWarn(const char *s) {
-  const int len = strlen(s);
-  char *p = (char*) smallocWarn(len + 1);
-  strcpy(p, s); // expected-warning{{String copy function overflows destination buffer}}
-  return p;
-}
-
 int *radar15580979() {
   int *data = (int *)malloc(32);
   int *p = data ?: (int*)malloc(32); // no warning
Index: lib/StaticAnalyzer/Checkers/ValistChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/ValistChecker.cpp
+++ lib/StaticAnalyzer/Checkers/ValistChecker.cpp
@@ -64,7 +64,7 @@
  CheckerContext &C) const;
   void reportLeakedVALists(const RegionVector &LeakedVALists, StringRef Msg1,
StringRef Msg2, CheckerContext &C, ExplodedNode *N,
-   bool ForceReport = false) const;
+   bool ReportUninit = false) const;
 
   void checkVAListStartCall(const CallEvent &Call, CheckerContext &C,
 bool IsCopy) const;
@@ -267,15 +267,15 @@
 void ValistChecker::reportLeakedVALists(const RegionVector &LeakedVALists,
 StringRef Msg1, StringRef Msg2,
 CheckerContext &C, ExplodedNode *N,
-bool ForceReport) const {
+bool ReportUninit) const {
   if (!(ChecksEnabled[CK_Unterminated] ||
-(ChecksEnabled[CK_Uninitialized] && ForceReport)))
+(ChecksEnabled[CK_Uninitialized] && ReportUninit)))
 return;
   for (auto Reg : LeakedVALists) {
 if (!BT_leakedvalist) {
-  BT_leakedvalist.reset(new BugType(CheckNames[CK_Unterminated],
-"Leaked va_list",
-categories::MemoryError));
+  BT_leakedvalist.reset(new BugType(
+  CheckNames[ReportUninit ? CK_Uninitialized : CK_Unterminated],
+  "Leaked va_list", categories::MemoryError));
   BT_leakedvalist->setSuppressOnSink(true);
 }
 
@@ -375,7 +375,7 @@
 
 std::shared_ptr ValistChecker::ValistBugVisitor::VisitNode(
 const ExplodedNode *N, const ExplodedNode *PrevN, BugReporterContext &BRC,
-BugReport &BR) {
+BugReport &) {
   ProgramStateRef State = N->getState();
   ProgramStateRef StatePrev = PrevN->getState();
 
Index: lib/StaticAnalyzer/Checkers/MallocChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -2900,8 +2900,13 @@
   mgr.getCurrentCheckName();
   // We currently treat NewDeleteLeaks checker as a subchecker of NewDelete
   // checker.
-  if (!checker->ChecksEnabled[MallocChecker::CK_NewDeleteChecker])
+  if (!checker->ChecksEnabled[MallocChecker::CK_NewDeleteChecker]) {
 checker->ChecksEnabled[MallocChecker::CK_NewDeleteChecker] = true;
+// FIXME: This does not set the correct name, but without this workaround
+//no name will be set at all.
+checker->CheckNames[MallocChecker::CK_NewDeleteChecker] =
+mgr.getCurrentCheckName();
+  }
 }
 
 #define REGISTER_CHECKER(name) \
Index: include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
===
--- include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
+++ include/clang/StaticAnalyzer/Core/BugReporter/BugType.h
@@ -29,30 +29,42 @@
 
 class BugType {
 private:
-  const CheckName Check;
+  mutable CheckName Check;
  

[PATCH] D37437: [analyzer] Fix some checker's output plist not containing the checker name

2017-12-22 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.
Herald added subscribers: a.sidorin, rnkovacs.

In case you do not like this solution, I uploaded an alternative approach: 
https://reviews.llvm.org/D41538


https://reviews.llvm.org/D37437



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


[PATCH] D41506: [clangd] Use Builder for symbol slabs, and use sorted-vector for storage

2017-12-22 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clangd/index/Index.cpp:39
+ [](const Symbol &S, const SymbolID &I) {
+   return S.ID == I;
+ });

Should this be `S.ID < I`?



Comment at: clangd/index/Index.cpp:41
+ });
+  if (It != Symbols.end() || It->ID == ID)
+return It;

`&& It->ID == ID`?



Comment at: clangd/index/Index.cpp:72
+  } else
+own(Symbols[R.first->second] = S, Strings, Arena);
+}

NIT: Maybe put assignment into a separate statement?
It's not too hard to see what's going on in the current code, but this line 
certainly gave me a pause.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41506



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


[PATCH] D41539: [CodeGen] Decorate aggregate accesses with TBAA tags

2017-12-22 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev created this revision.
kosarev added reviewers: rjmccall, hfinkel.
kosarev added a project: clang.

Repository:
  rL LLVM

https://reviews.llvm.org/D41539

Files:
  lib/CodeGen/CGExprAgg.cpp
  test/CodeGen/tbaa-struct-new.cpp

Index: test/CodeGen/tbaa-struct-new.cpp
===
--- test/CodeGen/tbaa-struct-new.cpp
+++ test/CodeGen/tbaa-struct-new.cpp
@@ -0,0 +1,85 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -new-struct-path-tbaa \
+// RUN: -emit-llvm -o - -O1 %s | FileCheck %s
+//
+// Check that we generate TBAA metadata for struct copies correctly.
+
+struct A {
+  short s;
+  int i;
+  char c;
+  int j;
+};
+
+void copy(A *a1, A *a2) {
+// CHECK-LABEL: _Z4copyP1AS0_
+// CHECK: call void @llvm.memcpy{{.*}}, !tbaa [[TAG_A:![0-9]*]]
+  *a1 = *a2;
+}
+
+struct B {
+  char c;
+  A a;
+  int i;
+};
+
+void copy2(B *b1, B *b2) {
+// CHECK-LABEL: _Z5copy2P1BS0_
+// CHECK: call void @llvm.memcpy{{.*}}, !tbaa [[TAG_B:![0-9]*]]
+  *b1 = *b2;
+}
+
+struct S {
+  _Complex char cc;
+  _Complex int ci;
+};
+
+union U {
+  _Complex int ci;
+  S s;
+};
+
+void copy3(U *u1, U *u2) {
+// CHECK-LABEL: _Z5copy3P1US0_
+// CHECK: call void @llvm.memcpy{{.*}}, !tbaa [[TAG_U:![0-9]*]]
+  *u1 = *u2;
+}
+
+// Make sure that zero-length bitfield works.
+struct C {
+  char a;
+  int : 0;  // Shall not be ignored; see r185018.
+  char b;
+  char c;
+} __attribute__((ms_struct));
+
+void copy4(C *c1, C *c2) {
+// CHECK-LABEL: _Z5copy4P1CS0_
+// CHECK: call void @llvm.memcpy{{.*}}, !tbaa [[TAG_C:![0-9]*]]
+  *c1 = *c2;
+}
+
+struct D {
+  char a;
+  int : 0;
+  char b;
+  char c;
+};
+
+void copy5(D *d1, D *d2) {
+// CHECK-LABEL: _Z5copy5P1DS0_
+// CHECK: call void @llvm.memcpy{{.*}}, !tbaa [[TAG_D:![0-9]*]]
+  *d1 = *d2;
+}
+
+// CHECK-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"}
+// CHECK-DAG: [[TYPE_short:!.*]] = !{[[TYPE_char]], i64 2, !"short"}
+// CHECK-DAG: [[TYPE_int:!.*]] = !{[[TYPE_char]], i64 4, !"int"}
+// CHECK-DAG: [[TYPE_A:!.*]] = !{[[TYPE_char]], i64 16, !"_ZTS1A", [[TYPE_short]], i64 0, i64 2, [[TYPE_int]], i64 4, i64 4, [[TYPE_char]], i64 8, i64 1, [[TYPE_int]], i64 12, i64 4}
+// CHECK-DAG: [[TAG_A]] = !{[[TYPE_A]], [[TYPE_A]], i64 0, i64 16}
+// CHECK-DAG: [[TYPE_B:!.*]] = !{[[TYPE_char]], i64 24, !"_ZTS1B", [[TYPE_char]], i64 0, i64 1, [[TYPE_A]], i64 4, i64 16, [[TYPE_int]], i64 20, i64 4}
+// CHECK-DAG: [[TAG_B]] = !{[[TYPE_B]], [[TYPE_B]], i64 0, i64 24}
+// CHECK-DAG: [[TAG_U]] = !{[[TYPE_char]], [[TYPE_char]], i64 0, i64 12}
+// CHECK-DAG: [[TYPE_C:!.*]] = !{[[TYPE_char]], i64 3, !"_ZTS1C", [[TYPE_char]], i64 0, i64 1, [[TYPE_int]], i64 1, i64 4, [[TYPE_char]], i64 1, i64 1, [[TYPE_char]], i64 2, i64 1}
+// CHECK-DAG: [[TAG_C]] = !{[[TYPE_C]], [[TYPE_C]], i64 0, i64 3}
+// CHECK-DAG: [[TYPE_D:!.*]] = !{[[TYPE_char]], i64 6, !"_ZTS1D", [[TYPE_char]], i64 0, i64 1, [[TYPE_int]], i64 4, i64 4, [[TYPE_char]], i64 4, i64 1, [[TYPE_char]], i64 5, i64 1}
+// CHECK-DAG: [[TAG_D]] = !{[[TYPE_D]], [[TYPE_D]], i64 0, i64 6}
Index: lib/CodeGen/CGExprAgg.cpp
===
--- lib/CodeGen/CGExprAgg.cpp
+++ lib/CodeGen/CGExprAgg.cpp
@@ -1657,4 +1657,7 @@
   // the optimizer wishes to expand it in to scalar memory operations.
   if (llvm::MDNode *TBAAStructTag = CGM.getTBAAStructInfo(Ty))
 Inst->setMetadata(llvm::LLVMContext::MD_tbaa_struct, TBAAStructTag);
+
+  if (CGM.getCodeGenOpts().NewStructPathTBAA)
+CGM.DecorateInstructionWithTBAA(Inst, CGM.getTBAAAccessInfo(Ty));
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41491: [clangd] Add a tool to build YAML-format global symbols.

2017-12-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 128010.
hokein marked 4 inline comments as done.
hokein added a comment.

Write all map-reduce logic into the global-symbol-builder binary, which makes
the patch much simpler.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41491

Files:
  clangd/CMakeLists.txt
  clangd/global-symbol-builder/CMakeLists.txt
  clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp

Index: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
===
--- /dev/null
+++ clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
@@ -0,0 +1,127 @@
+//===--- GlobalSymbolBuilderMain.cpp -*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// GlobalSymbolBuilder is a tool to generate YAML-format symbols across the
+// whole project. This tools is for **experimental** only. Don't use it in
+// production code.
+//
+//===-===//
+
+#include "index/Index.h"
+#include "index/SymbolCollector.h"
+#include "index/SymbolYAML.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Index/IndexingAction.h"
+#include "clang/Index/IndexDataConsumer.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ThreadPool.h"
+
+using namespace llvm;
+using namespace clang::tooling;
+using clang::clangd::SymbolSlab;
+
+namespace clang {
+namespace clangd {
+
+class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
+public:
+  SymbolIndexActionFactory() = default;
+
+  clang::FrontendAction *create() override {
+index::IndexingOptions IndexOpts;
+IndexOpts.SystemSymbolFilter =
+index::IndexingOptions::SystemSymbolFilterKind::All;
+IndexOpts.IndexFunctionLocals = false;
+Collector = std::make_shared();
+return index::createIndexingAction(Collector, IndexOpts, nullptr).release();
+  }
+
+  std::shared_ptr Collector;
+};
+
+} // namespace clangd
+} // namespace clang
+
+static cl::OptionCategory GlobalSymbolCategory("global-symbol-builder options");
+
+static cl::opt ResultPath("result-path", cl::desc(R"(
+File path for storing global symbols.)"),
+   cl::init("./clangd-global-symbols.yaml"),
+   cl::cat(GlobalSymbolCategory));
+
+bool WriteFile(llvm::StringRef OutputFile, const SymbolSlab& Symbols) {
+  std::error_code EC;
+  llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_None);
+  if (EC) {
+llvm::errs() << "Can't open '" << OutputFile << "': " << EC.message()
+ << '\n';
+return false;
+  }
+  OS << clang::clangd::SymbolToYAML(Symbols);
+  return true;
+}
+
+int main(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+
+  const char* Overview =
+  "This is an **experimental** tool to generate YAML-format "
+  "project-wide symbols for clangd (global code completion). It would be "
+  "changed and deprecated eventually. Don't use it in production code!";
+  CommonOptionsParser OptionsParser(argc, argv, GlobalSymbolCategory,
+/*Overview=*/Overview);
+
+  // No compilation database found, fallback to single TU analysis, this is
+  // mainly for debugging purpose:
+  //   global-symbol-buidler /tmp/t.cc -- -std=c++11.
+  if (OptionsParser.getCompilations().getAllFiles().empty()) {
+ClangTool Tool(OptionsParser.getCompilations(),
+   OptionsParser.getSourcePathList());
+clang::clangd::SymbolIndexActionFactory IndexAction;
+Tool.run(&IndexAction);
+llvm::outs() << SymbolToYAML(IndexAction.Collector->takeSymbols());
+return 0;
+  }
+
+  // Found compilation database, we iterate all TUs from database to get all
+  // symbols, and then merge them into a single SymbolSlab.
+  SymbolSlab GlobalSymbols;
+  std::mutex SymbolMutex;
+  auto AddSymbols = [&](const SymbolSlab& NewSymbols) {
+// Synchronize set accesses.
+std::unique_lock LockGuard(SymbolMutex);
+for (auto It : NewSymbols) {
+  // FIXME: Better handling the overlap symbols, currently we overwrite it
+  // with the latest one, but we always want to good declarations (class
+  // definitions, instead of forward declarations).
+  GlobalSymbols.insert(It.second);
+}
+  };
+
+  {
+llvm::ThreadPool Pool;
+for (auto& file : OptionsParser.getCompilations().getAllFiles()) {
+  Pool.async([&OptionsParser, &AddSymbols](

[PATCH] D41491: [clangd] Add a tool to build YAML-format global symbols.

2017-12-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Thanks for the comments.




Comment at: clangd/CMakeLists.txt:50
 add_subdirectory(tool)
+add_subdirectory(global-symbol-builder)

sammccall wrote:
> I think generally we run `check-clang-tools` before committing - I guess it's 
> OK not to have tests for this experimental tool, but we should at least keep 
> it building. Can you make check-clang-tools build it?
Yeah, it builds.



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:106
+  std::error_code EC;
+  SymbolSlab Result;
+  std::mutex SymbolMutex;

sammccall wrote:
> FYI D41506 changes this API, adding `SymbolSlab::Builder`. Shouldn't be a 
> problem, but we'll need to merge.
Will do it after that patch is landed.



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:112
+for (const auto &Symbol : NewSymbols) {
+  auto it = Result.find(Symbol.second.ID);
+  if (it == Result.end())

sammccall wrote:
> This seems like you might end up overwriting good declarations with bad ones 
> (e.g. forward decls). Picking one with a simple heuristic like "longest 
> range" would get classes right.
Add a FIXME here, will do it in a follow-up -- as the symbol structure would be 
changed.



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:175
+  *Executor->get()->getExecutionContext()));
+  auto Err = Executor->get()->execute(std::move(T));
+  if (Err) {

sammccall wrote:
> I don't understand why we need to plumb callbacks through SymbolCollector.
> Can't we just write the slab after this line?
`ToolExecutor` takes over the lifetime of `FrontendActionFactory`, there is no 
straightforward way to get the internal `SymbolSlab` from the indexAction.

Changed to use `ClangTool`, since it would simplify the code a lot, and no 
changes in `SymbolCollector`.



Comment at: clangd/global-symbol-builder/run-global-symbol-builder.py:1
+#!/usr/bin/env python
+#

sammccall wrote:
> So we now have three copies of this script...
> I'm probably missing something, but what's here that's hard to do in a single 
> binary?
> I'd have to think it'd be faster if we weren't constantly spawning new 
> processes and roundtripping all the data through YAML-on-disk.
> 
> (If this is just expedience because we have an existing template to copy, I'm 
> happy to try to combine it into one binary myself)
Yeah, the script is borrowed from other places for the fast prototype.

We can combine it into the `global-symbol-builder` binary. Done.



Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41491



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


[PATCH] D41506: [clangd] Use Builder for symbol slabs, and use sorted-vector for storage

2017-12-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clangd/index/Index.cpp:76
+SymbolSlab SymbolSlab::Builder::build() && {
+  Symbols = {Symbols.begin(), Symbols.end()}; // Force shrink-to-fit.
+  // Sort symbols so the slab can binary search over them.

 use `Symbols.shrink_to_fit()`?



Comment at: clangd/index/Index.cpp:81
+  // We may have unused strings from overwritten symbols. Build a new arena.
+  BumpPtrAllocator Arena;
+  DenseSet Strings;

Maybe rename it to `NewArena`, we already have a member called `Arena`.



Comment at: clangd/index/Index.h:174
+ std::vector Symbols;
+ llvm::DenseMap SymbolIndex;
+  };

worth a comment saying the value of the map is the vector index of `Symbols`, 
it took me a while to understand.



Comment at: clangd/index/Index.h:182
+  llvm::BumpPtrAllocator Arena;
+  std::vector Symbols;
 };

Mention the Symbols is required to be sorted.



Comment at: clangd/index/SymbolCollector.h:36
   // All Symbols collected from the AST.
-  SymbolSlab Symbols;
+  SymbolSlab::Builder Symbols;
 };

Maybe name it `SymbolBuilder` to avoid confusion -- `Symbols` indicates its 
type is `SymbolSlab`. 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41506



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


[PATCH] D41491: [clangd] Add a tool to build YAML-format global symbols.

2017-12-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks for the simplification!
How long does it take to run over LLVM on your machine?




Comment at: clangd/CMakeLists.txt:50
 add_subdirectory(tool)
+add_subdirectory(global-symbol-builder)

hokein wrote:
> sammccall wrote:
> > I think generally we run `check-clang-tools` before committing - I guess 
> > it's OK not to have tests for this experimental tool, but we should at 
> > least keep it building. Can you make check-clang-tools build it?
> Yeah, it builds.
Can you add it to the deps of the testsuite, so we don't break it?



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:45
+IndexOpts.SystemSymbolFilter =
+index::IndexingOptions::SystemSymbolFilterKind::All;
+IndexOpts.IndexFunctionLocals = false;

out of curiosity, what does this do?



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:57
+
+static cl::OptionCategory GlobalSymbolCategory("global-symbol-builder 
options");
+

you could avoid opt parsing, opening files and dealing with errors etc by just 
writing to llvm::outs() and running with > foo.yaml - up to you



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:90
+  if (OptionsParser.getCompilations().getAllFiles().empty()) {
+ClangTool Tool(OptionsParser.getCompilations(),
+   OptionsParser.getSourcePathList());

if this isn't the typical use case, consider
llvm::errs() << "No compilation database found, processing individual files 
with flags from command-line\n"


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41491



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


[PATCH] D41539: [CodeGen] Decorate aggregate accesses with TBAA tags

2017-12-22 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev updated this revision to Diff 128017.
kosarev added a comment.

Reworked to not add another test file.


https://reviews.llvm.org/D41539

Files:
  lib/CodeGen/CGExprAgg.cpp
  test/CodeGen/tbaa-struct.cpp

Index: test/CodeGen/tbaa-struct.cpp
===
--- test/CodeGen/tbaa-struct.cpp
+++ test/CodeGen/tbaa-struct.cpp
@@ -1,75 +1,105 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - -O1 %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - -O1 %s | \
+// RUN: FileCheck -check-prefixes=CHECK,CHECK-OLD %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -new-struct-path-tbaa \
+// RUN: -emit-llvm -o - -O1 %s | \
+// RUN: FileCheck -check-prefixes=CHECK,CHECK-NEW %s
 //
-// Check that we generate !tbaa.struct metadata for struct copies.
+// Check that we generate TBAA metadata for struct copies correctly.
+
 struct A {
   short s;
   int i;
   char c;
   int j;
 };
 
-void copy(struct A *a, struct A *b) {
-  *a = *b;
+void copy(A *a1, A *a2) {
+// CHECK-LABEL: _Z4copyP1AS0_
+// CHECK-OLD: call void @llvm.memcpy{{.*}}, !tbaa.struct [[TS:!.*]]
+// CHECK-NEW: call void @llvm.memcpy{{.*}}, !tbaa [[TAG_A:![0-9]*]]
+  *a1 = *a2;
 }
 
-// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 16, i32 4, i1 false), !tbaa.struct [[TS:!.*]]
-
 struct B {
-  char c1;
-  struct A a;
-  int ii;
+  char c;
+  A a;
+  int i;
 };
 
-void copy2(struct B *a, struct B *b) {
-  *a = *b;
+void copy2(B *b1, B *b2) {
+// CHECK-LABEL: _Z5copy2P1BS0_
+// CHECK-OLD: call void @llvm.memcpy{{.*}}, !tbaa.struct [[TS2:!.*]]
+// CHECK-NEW: call void @llvm.memcpy{{.*}}, !tbaa [[TAG_B:![0-9]*]]
+  *b1 = *b2;
 }
 
-// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 24, i32 4, i1 false), !tbaa.struct [[TS2:!.*]]
+struct S {
+  _Complex char cc;
+  _Complex int ci;
+};
 
-typedef _Complex int T2;
-typedef _Complex char T5;
-typedef _Complex int T7;
-typedef struct T4 { T5 field0; T7 field1; } T4;
-typedef union T1 { T2 field0; T4 field1; } T1;
+union U {
+  _Complex int ci;
+  S s;
+};
 
-void copy3 (T1 *a, T1 *b) {
-  *a = *b;
+void copy3(U *u1, U *u2) {
+// CHECK-LABEL: _Z5copy3P1US0_
+// CHECK-OLD: call void @llvm.memcpy{{.*}}, !tbaa.struct [[TS3:!.*]]
+// CHECK-NEW: call void @llvm.memcpy{{.*}}, !tbaa [[TAG_U:![0-9]*]]
+  *u1 = *u2;
 }
 
-// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 12, i32 4, i1 false), !tbaa.struct [[TS3:!.*]]
-
 // Make sure that zero-length bitfield works.
-#define ATTR __attribute__ ((ms_struct))
-struct five {
+struct C {
   char a;
-  int :0;/* ignored; prior field is not a bitfield. */
+  int : 0;  // Shall not be ignored; see r185018.
   char b;
   char c;
-} ATTR;
-void copy4(struct five *a, struct five *b) {
-  *a = *b;
+} __attribute__((ms_struct));
+
+void copy4(C *c1, C *c2) {
+// CHECK-LABEL: _Z5copy4P1CS0_
+// CHECK-OLD: call void @llvm.memcpy{{.*}}, !tbaa.struct [[TS4:!.*]]
+// CHECK-NEW: call void @llvm.memcpy{{.*}}, !tbaa [[TAG_C:![0-9]*]]
+  *c1 = *c2;
 }
-// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 3, i32 1, i1 false), !tbaa.struct [[TS4:!.*]]
 
-struct six {
+struct D {
   char a;
-  int :0;
+  int : 0;
   char b;
   char c;
 };
-void copy5(struct six *a, struct six *b) {
-  *a = *b;
+
+void copy5(D *d1, D *d2) {
+// CHECK-LABEL: _Z5copy5P1DS0_
+// CHECK-OLD: call void @llvm.memcpy{{.*}}, !tbaa.struct [[TS5:!.*]]
+// CHECK-NEW: call void @llvm.memcpy{{.*}}, !tbaa [[TAG_D:![0-9]*]]
+  *d1 = *d2;
 }
-// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 6, i32 1, i1 false), !tbaa.struct [[TS5:!.*]]
 
-// CHECK: [[TS]] = !{i64 0, i64 2, !{{.*}}, i64 4, i64 4, !{{.*}}, i64 8, i64 1, !{{.*}}, i64 12, i64 4, !{{.*}}}
-// CHECK: [[CHAR:!.*]] = !{!"omnipotent char", !{{.*}}}
-// CHECK: [[TAG_INT:!.*]] = !{[[INT:!.*]], [[INT]], i64 0}
-// CHECK: [[INT]] = !{!"int", [[CHAR]]
-// CHECK: [[TAG_CHAR:!.*]] = !{[[CHAR]], [[CHAR]], i64 0}
+// CHECK-OLD: [[TS]] = !{i64 0, i64 2, !{{.*}}, i64 4, i64 4, !{{.*}}, i64 8, i64 1, !{{.*}}, i64 12, i64 4, !{{.*}}}
+// CHECK-OLD: [[CHAR:!.*]] = !{!"omnipotent char", !{{.*}}}
+// CHECK-OLD: [[TAG_INT:!.*]] = !{[[INT:!.*]], [[INT]], i64 0}
+// CHECK-OLD: [[INT]] = !{!"int", [[CHAR]]
+// CHECK-OLD: [[TAG_CHAR:!.*]] = !{[[CHAR]], [[CHAR]], i64 0}
 // (offset, size) = (0,1) char; (4,2) short; (8,4) int; (12,1) char; (16,4) int; (20,4) int
-// CHECK: [[TS2]] = !{i64 0, i64 1, !{{.*}}, i64 4, i64 2, !{{.*}}, i64 8, i64 4, !{{.*}}, i64 12, i64 1, !{{.*}}, i64 16, i64 4, {{.*}}, i64 20, i64 4, {{.*}}}
+// CHECK-OLD: [[TS2]] = !{i64 0, i64 1, !{{.*}}, i64 4, i64 2, !{{.*}}, i64 8, i64 4, !{{.*}}, i64 12, i64 1, !{{.*}}, i64 16, i64 4, {{.*}}, i64 20, i64 4, {{.*}}}
 // (offset, size) = (0,8) char; (0,2) char; (4,8) char
-// CHECK: [[TS3]] = !{i64 0, i64 8, !{{.*}}, i64 0, i64 2, !{{.*}}, i64 4, i64 8, !{{.*}}}
-// CHECK: [[TS4]] = !

[PATCH] D41363: [clang-tidy] Adding Fuchsia checker for overloaded operators

2017-12-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

In https://reviews.llvm.org/D41363#962727, @juliehockett wrote:

> > Are the Fuchsia library headers intended to also comply with this rule? I 
> > notice there's mention of a unique_ptr class, and I can't imagine that 
> > working without overloading more operators than just assignment. Perhaps 
> > this check should not be triggered for system headers?
>
> It would make sense for it to be run on the system headers when clang-tidy's 
> -system-headers flag is included, otherwise not -- does that logic need to go 
> into the checker though?


Ah, I forgot about that detail, so no, I don't think you need to make 
modifications here for that.

One more tiny nit with the test case, otherwise LGTM.




Comment at: test/clang-tidy/fuchsia-overloaded-operator.cpp:17
+
+A operator-(const A& a, const A& b);
+// CHECK-MESSAGES: [[@LINE-1]]:1: warning: cannot overload 'operator-' 
[fuchsia-overloaded-operator]

Missed these.


https://reviews.llvm.org/D41363



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


Re: r315984 - [CodeGen] EmitPointerWithAlignment() to generate TBAA info along with LValue base info

2017-12-22 Thread Ivan Kosarev via cfe-commits

Hello Alex,

I'm working on it.

Thanks,


On 22/12/17 00:07, Alex L wrote:

Hi,

This commit has caused a new regression in LLVM 6. I filed the 
following PR: https://bugs.llvm.org/show_bug.cgi?id=35724 .

Could you please take a look?

Thanks,
Alex

On 17 October 2017 at 02:12, Ivan A. Kosarev via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:


Author: kosarev
Date: Tue Oct 17 02:12:13 2017
New Revision: 315984

URL: http://llvm.org/viewvc/llvm-project?rev=315984&view=rev

Log:
[CodeGen] EmitPointerWithAlignment() to generate TBAA info along
with LValue base info

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


Added:
    cfe/trunk/test/CodeGen/tbaa-cast.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h
    cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
    cfe/trunk/lib/CodeGen/CodeGenTBAA.h

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

http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=315984&r1=315983&r2=315984&view=diff



==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Oct 17 02:12:13 2017
@@ -916,7 +916,8 @@ void CodeGenModule::EmitExplicitCastExpr
 /// EmitPointerWithAlignment - Given an expression of pointer
type, try to
 /// derive a more accurate bound on the alignment of the pointer.
 Address CodeGenFunction::EmitPointerWithAlignment(const Expr *E,
- LValueBaseInfo *BaseInfo) {
+ LValueBaseInfo *BaseInfo,
+ TBAAAccessInfo *TBAAInfo) {
   // We allow this with ObjC object pointers because of fragile ABIs.
   assert(E->getType()->isPointerType() ||
          E->getType()->isObjCObjectPointerType());
@@ -936,20 +937,30 @@ Address CodeGenFunction::EmitPointerWith
         if (PtrTy->getPointeeType()->isVoidType())
           break;

-        LValueBaseInfo InnerInfo;
-        Address Addr = EmitPointerWithAlignment(CE->getSubExpr(),
&InnerInfo);
-        if (BaseInfo) *BaseInfo = InnerInfo;
-
-        // If this is an explicit bitcast, and the source l-value is
-        // opaque, honor the alignment of the casted-to type.
-        if (isa(CE) &&
-            InnerInfo.getAlignmentSource() !=
AlignmentSource::Decl) {
-          LValueBaseInfo ExpInfo;
+        LValueBaseInfo InnerBaseInfo;
+        TBAAAccessInfo InnerTBAAInfo;
+        Address Addr = EmitPointerWithAlignment(CE->getSubExpr(),
+ &InnerBaseInfo,
+ &InnerTBAAInfo);
+        if (BaseInfo) *BaseInfo = InnerBaseInfo;
+        if (TBAAInfo) *TBAAInfo = InnerTBAAInfo;
+
+        if (isa(CE)) {
+          LValueBaseInfo TargetTypeBaseInfo;
+          TBAAAccessInfo TargetTypeTBAAInfo;
           CharUnits Align =
getNaturalPointeeTypeAlignment(E->getType(),
-  &ExpInfo);
-          if (BaseInfo)
-            BaseInfo->mergeForCast(ExpInfo);
-          Addr = Address(Addr.getPointer(), Align);
+  &TargetTypeBaseInfo,
+  &TargetTypeTBAAInfo);
+          if (TBAAInfo)
+            *TBAAInfo = CGM.mergeTBAAInfoForCast(*TBAAInfo,
+  TargetTypeTBAAInfo);
+          // If the source l-value is opaque, honor the alignment
of the
+          // casted-to type.
+          if (InnerBaseInfo.getAlignmentSource() !=
AlignmentSource::Decl) {
+            if (BaseInfo)
+              BaseInfo->mergeForCast(TargetTypeBaseInfo);
+            Addr = Address(Addr.getPointer(), Align);
+          }
         }

         if (SanOpts.has(SanitizerKind::CFIUnrelatedCast) &&
@@ -969,12 +980,13 @@ Address CodeGenFunction::EmitPointerWith

     // Array-to-pointer decay.
     case CK_ArrayToPointerDecay:
-      return EmitArrayToPointerDecay(CE->getSubExpr(), BaseInfo);
+      return EmitArrayToPointerDecay(CE->getSubExpr(), BaseInfo,
TBAAInfo);

     // Derived-to-base conversions.
     case CK_UncheckedDerivedToBase:
     case CK_DerivedToBase: {
-      Address Addr = EmitPointerWithAlignment(CE->getSubExpr(),
BaseInfo);
+      Address Addr = EmitPointerWithAlignment(CE->getSubExpr(),
BaseInfo,
+                                              TBAAInfo);
       auto Derived =
CE->getSubExpr()->getType()->getPointeeCXXRecordDecl();
       return GetAddressOfBaseClass(Addr, Derived,
                                    CE->path_begin(), CE->

[PATCH] D41491: [clangd] Add a tool to build YAML-format global symbols.

2017-12-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In https://reviews.llvm.org/D41491#963103, @sammccall wrote:

> Thanks for the simplification!
>  How long does it take to run over LLVM on your machine?


It took < 10 minutes (vs 20 minutes with python script) to run over LLVM.




Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:45
+IndexOpts.SystemSymbolFilter =
+index::IndexingOptions::SystemSymbolFilterKind::All;
+IndexOpts.IndexFunctionLocals = false;

sammccall wrote:
> out of curiosity, what does this do?
No official document on this :(
IIUC, this is a filter option to control whether we get symbols from the system 
code (like std library). `All` means we index all of them.



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:57
+
+static cl::OptionCategory GlobalSymbolCategory("global-symbol-builder 
options");
+

sammccall wrote:
> you could avoid opt parsing, opening files and dealing with errors etc by 
> just writing to llvm::outs() and running with > foo.yaml - up to you
Good idea. Done.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41491



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


[PATCH] D41491: [clangd] Add a tool to build YAML-format global symbols.

2017-12-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 128020.
hokein marked 4 inline comments as done.
hokein added a comment.

Address remaining review comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41491

Files:
  clangd/CMakeLists.txt
  clangd/global-symbol-builder/CMakeLists.txt
  clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
  test/CMakeLists.txt

Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -49,6 +49,9 @@
   modularize
   pp-trace
 
+  # These indiviual tools have no tests, add them here to make them compile
+  # together with chec-clang-tools, so that we won't break them in the future.
+  global-symbol-builder
   # Unit tests
   ExtraToolsUnitTests
   )
Index: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
===
--- /dev/null
+++ clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
@@ -0,0 +1,112 @@
+//===--- GlobalSymbolBuilderMain.cpp -*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// GlobalSymbolBuilder is a tool to generate YAML-format symbols across the
+// whole project. This tools is for **experimental** only. Don't use it in
+// production code.
+//
+//===-===//
+
+#include "index/Index.h"
+#include "index/SymbolCollector.h"
+#include "index/SymbolYAML.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Index/IndexingAction.h"
+#include "clang/Index/IndexDataConsumer.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ThreadPool.h"
+
+using namespace llvm;
+using namespace clang::tooling;
+using clang::clangd::SymbolSlab;
+
+namespace clang {
+namespace clangd {
+
+class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
+public:
+  SymbolIndexActionFactory() = default;
+
+  clang::FrontendAction *create() override {
+index::IndexingOptions IndexOpts;
+IndexOpts.SystemSymbolFilter =
+index::IndexingOptions::SystemSymbolFilterKind::All;
+IndexOpts.IndexFunctionLocals = false;
+Collector = std::make_shared();
+return index::createIndexingAction(Collector, IndexOpts, nullptr).release();
+  }
+
+  std::shared_ptr Collector;
+};
+
+} // namespace clangd
+} // namespace clang
+
+static cl::OptionCategory GlobalSymbolCategory("global-symbol-builder options");
+
+int main(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+
+  const char* Overview =
+  "This is an **experimental** tool to generate YAML-format "
+  "project-wide symbols for clangd (global code completion). It would be "
+  "changed and deprecated eventually. Don't use it in production code!";
+  CommonOptionsParser OptionsParser(argc, argv, GlobalSymbolCategory,
+/*Overview=*/Overview);
+
+  // No compilation database found, fallback to single TU analysis, this is
+  // mainly for debugging purpose:
+  //   global-symbol-buidler /tmp/t.cc -- -std=c++11.
+  if (OptionsParser.getCompilations().getAllFiles().empty()) {
+llvm::errs() << "No compilation database found, processing individual "
+"files with flags from command-line\n.";
+ClangTool Tool(OptionsParser.getCompilations(),
+   OptionsParser.getSourcePathList());
+clang::clangd::SymbolIndexActionFactory IndexAction;
+Tool.run(&IndexAction);
+llvm::outs() << SymbolToYAML(IndexAction.Collector->takeSymbols());
+return 0;
+  }
+
+  // Found compilation database, we iterate all TUs from database to get all
+  // symbols, and then merge them into a single SymbolSlab.
+  SymbolSlab GlobalSymbols;
+  std::mutex SymbolMutex;
+  auto AddSymbols = [&](const SymbolSlab& NewSymbols) {
+// Synchronize set accesses.
+std::unique_lock LockGuard(SymbolMutex);
+for (auto It : NewSymbols) {
+  // FIXME: Better handling the overlap symbols, currently we overwrite it
+  // with the latest one, but we always want to good declarations (class
+  // definitions, instead of forward declarations).
+  GlobalSymbols.insert(It.second);
+}
+  };
+
+  {
+llvm::ThreadPool Pool;
+for (auto& file : OptionsParser.getCompilations().getAllFiles()) {
+  Pool.async([&OptionsParser, &AddSymbols](llvm::StringRef Path) {
+ClangTool Tool(OptionsParser.getCompilations(), {Path});
+clang::clangd::S

[PATCH] D41491: [clangd] Add a tool to build YAML-format global symbols.

2017-12-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:45
+IndexOpts.SystemSymbolFilter =
+index::IndexingOptions::SystemSymbolFilterKind::All;
+IndexOpts.IndexFunctionLocals = false;

hokein wrote:
> sammccall wrote:
> > out of curiosity, what does this do?
> No official document on this :(
> IIUC, this is a filter option to control whether we get symbols from the 
> system code (like std library). `All` means we index all of them.
Ah, that sounds fine. Later we may actually want to index stdlib separately.



Comment at: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp:57
+
+static cl::OptionCategory GlobalSymbolCategory("global-symbol-builder 
options");
+

(remove this and use GeneralCategory as default?)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41491



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


[PATCH] D41491: [clangd] Add a tool to build YAML-format global symbols.

2017-12-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 128021.
hokein marked an inline comment as done.
hokein added a comment.

Use GeneralCateogry.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41491

Files:
  clangd/CMakeLists.txt
  clangd/global-symbol-builder/CMakeLists.txt
  clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
  test/CMakeLists.txt

Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -49,6 +49,9 @@
   modularize
   pp-trace
 
+  # These indiviual tools have no tests, add them here to make them compile
+  # together with chec-clang-tools, so that we won't break them in the future.
+  global-symbol-builder
   # Unit tests
   ExtraToolsUnitTests
   )
Index: clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
===
--- /dev/null
+++ clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
@@ -0,0 +1,110 @@
+//===--- GlobalSymbolBuilderMain.cpp -*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// GlobalSymbolBuilder is a tool to generate YAML-format symbols across the
+// whole project. This tools is for **experimental** only. Don't use it in
+// production code.
+//
+//===-===//
+
+#include "index/Index.h"
+#include "index/SymbolCollector.h"
+#include "index/SymbolYAML.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Index/IndexingAction.h"
+#include "clang/Index/IndexDataConsumer.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ThreadPool.h"
+
+using namespace llvm;
+using namespace clang::tooling;
+using clang::clangd::SymbolSlab;
+
+namespace clang {
+namespace clangd {
+
+class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
+public:
+  SymbolIndexActionFactory() = default;
+
+  clang::FrontendAction *create() override {
+index::IndexingOptions IndexOpts;
+IndexOpts.SystemSymbolFilter =
+index::IndexingOptions::SystemSymbolFilterKind::All;
+IndexOpts.IndexFunctionLocals = false;
+Collector = std::make_shared();
+return index::createIndexingAction(Collector, IndexOpts, nullptr).release();
+  }
+
+  std::shared_ptr Collector;
+};
+
+} // namespace clangd
+} // namespace clang
+
+int main(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+
+  const char* Overview =
+  "This is an **experimental** tool to generate YAML-format "
+  "project-wide symbols for clangd (global code completion). It would be "
+  "changed and deprecated eventually. Don't use it in production code!";
+  CommonOptionsParser OptionsParser(argc, argv, cl::GeneralCategory,
+/*Overview=*/Overview);
+
+  // No compilation database found, fallback to single TU analysis, this is
+  // mainly for debugging purpose:
+  //   global-symbol-buidler /tmp/t.cc -- -std=c++11.
+  if (OptionsParser.getCompilations().getAllFiles().empty()) {
+llvm::errs() << "No compilation database found, processing individual "
+"files with flags from command-line\n.";
+ClangTool Tool(OptionsParser.getCompilations(),
+   OptionsParser.getSourcePathList());
+clang::clangd::SymbolIndexActionFactory IndexAction;
+Tool.run(&IndexAction);
+llvm::outs() << SymbolToYAML(IndexAction.Collector->takeSymbols());
+return 0;
+  }
+
+  // Found compilation database, we iterate all TUs from database to get all
+  // symbols, and then merge them into a single SymbolSlab.
+  SymbolSlab GlobalSymbols;
+  std::mutex SymbolMutex;
+  auto AddSymbols = [&](const SymbolSlab& NewSymbols) {
+// Synchronize set accesses.
+std::unique_lock LockGuard(SymbolMutex);
+for (auto It : NewSymbols) {
+  // FIXME: Better handling the overlap symbols, currently we overwrite it
+  // with the latest one, but we always want to good declarations (class
+  // definitions, instead of forward declarations).
+  GlobalSymbols.insert(It.second);
+}
+  };
+
+  {
+llvm::ThreadPool Pool;
+for (auto& file : OptionsParser.getCompilations().getAllFiles()) {
+  Pool.async([&OptionsParser, &AddSymbols](llvm::StringRef Path) {
+ClangTool Tool(OptionsParser.getCompilations(), {Path});
+clang::clangd::SymbolIndexActionFactory IndexAction;
+Tool.run(&IndexAction);
+AddSymbols(IndexActi

[PATCH] D41326: [clang-tidy] Added diagnostics about incorrect usage of NOLINT comment

2017-12-22 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:21-22
 #include "ClangTidyOptions.h"
+#include "ClangTidy.h"
+#include "ClangTidyModule.h"
 #include "clang/AST/ASTDiagnostic.h"

Please keep the includes in sorted order.



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:132
+++BracketIndex;
+const size_t BracketEndIndex = Line.find(')', BracketIndex);
+if ((ClosingBracketFound = BracketEndIndex != StringRef::npos)) {

We don't typically mark local, non-pointer types as `const`.



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:161
+
+  const SmallVector& getCheckNames() const {
+assert(isNolintFound());

The `&` should bind to the right. However, instead of returning the concrete 
container, why not expose a range interface instead?



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:261
+  struct NolintTargetInfoHasher {
+size_t operator() (const NolintTargetInfo &i) const {
+  return llvm::hash_combine(i.LineNumber, i.CheckName);

Spurious space after `operator()`. `i` does not match our coding conventions 
(and could use a better name).



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:266-267
+  struct NolintTargetInfoEq {
+bool operator()(const NolintTargetInfo &i1,
+const NolintTargetInfo &i2) const {
+  return i1.LineNumber == i2.LineNumber && i1.CheckName == i2.CheckName;

The parameter names don't match our coding conventions.



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:273
+public:
+  NolintCommentsCollector(ClangTidyContext *Context)
+: Context(Context) {}

Mark the constructor `explicit`?



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:276
+
+  using NolintMap = std::unordered_mapdiag(NolintCheckName, NolintLoc,
+  "unknown check name '%0' is specified for %1 comment")
+  << CheckName << CommentName;

I'd reword this slightly to: "unknown check name '%0' specified in %1 directive"



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:325-326
+Context->diag(NolintCheckName, NolintLoc,
+"%0 comment has an opening parenthesis and no closing one, "
+"so all the diagnostics will be silenced for the line")
+<< CommentName;

How about: "unbalanced parentheses in %0 comment; all diagnostics silenced for 
this line" ?



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:381
 
+void ClangTidyContext::setPreprocessor(Preprocessor *preprocessor) {
+  if (preprocessor && isCheckEnabled(NolintCheckName)) {

Name does not match coding standard.



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:424
+// This method is not const, because it fills cache on first demand.
+// It is possible to fill cache in constructor or make cache volatile
+// and make this method const, but they seem like worse solutions.

Making the cache volatile will have no impact on this.

Any reason not to make the cache `mutable`, however? That's quite common for 
implementation details.



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:495
+  }
+  const SmallVector& CheckNames = NolintParser.getCheckNames();
+  return llvm::find(CheckNames, CheckName) != CheckNames.end();

Formatting.



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:566
+// This is necessary for finding redundant NOLINT comments. Fill collection
+// here, as there won't be another change if diagnostics is filtered.
+DiagIDsToLineNumbers[Info.getID()].push_back(

s/change/chance?

Also: if diagnostics is filtered -> if diagnostics are filtered



Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:839-840
+case NolintCommentType::Nolint:
+  Message = "there is no diagnostics on this line, "
+"the NOLINT comment is redundant";
+  break;

I don't think the user is going to care about the distinction between no 
diagnostics being triggered and the expected diagnostic not being triggered. 
Also, it's dangerous to claim the lint comment is redundant because it's 
possible the user has NOLINT(foo, bar) and while foo is not triggered, bar 
still is. The NOLINT comment itself isn't redundant, it's that the check 
specified doesn't occur.

I would consolidate those scenarios into a single diagnostic: "expected 
diagnostic '%0' not generated" and "expected diagnostic '%0' not generated for 
the following line".

One concern I have with this functionality is: how should users silence a lint 
diagnostic that's target sensitive? e.g., a diagnosti

[clang-tools-extra] r321358 - [clangd] Add a tool to build YAML-format global symbols.

2017-12-22 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Fri Dec 22 06:38:05 2017
New Revision: 321358

URL: http://llvm.org/viewvc/llvm-project?rev=321358&view=rev
Log:
[clangd] Add a tool to build YAML-format global symbols.

Summary:
The tools is used to generate global symbols for clangd (global code 
completion),
The format is YAML, which is only for **experiment**.

Usage:
./bin/global-symbol-builder  > global-symbols.yaml

TEST:
used the tool to generate global symbols for LLVM (~72MB).

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: klimek, mgorny, ilya-biryukov, cfe-commits

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

Added:
clang-tools-extra/trunk/clangd/global-symbol-builder/
clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt

clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/test/CMakeLists.txt

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=321358&r1=321357&r2=321358&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Fri Dec 22 06:38:05 2017
@@ -47,3 +47,4 @@ if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_
   add_subdirectory(fuzzer)
 endif()
 add_subdirectory(tool)
+add_subdirectory(global-symbol-builder)

Added: clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt?rev=321358&view=auto
==
--- clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt (added)
+++ clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt Fri Dec 
22 06:38:05 2017
@@ -0,0 +1,19 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
+
+set(LLVM_LINK_COMPONENTS
+Support
+)
+
+add_clang_executable(global-symbol-builder
+  GlobalSymbolBuilderMain.cpp
+  )
+
+target_link_libraries(global-symbol-builder
+  PRIVATE
+  clangAST
+  clangIndex
+  clangDaemon
+  clangBasic
+  clangFrontend
+  clangTooling
+)

Added: 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp?rev=321358&view=auto
==
--- 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 (added)
+++ 
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
 Fri Dec 22 06:38:05 2017
@@ -0,0 +1,110 @@
+//===--- GlobalSymbolBuilderMain.cpp -*- 
C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// GlobalSymbolBuilder is a tool to generate YAML-format symbols across the
+// whole project. This tools is for **experimental** only. Don't use it in
+// production code.
+//
+//===-===//
+
+#include "index/Index.h"
+#include "index/SymbolCollector.h"
+#include "index/SymbolYAML.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Index/IndexingAction.h"
+#include "clang/Index/IndexDataConsumer.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ThreadPool.h"
+
+using namespace llvm;
+using namespace clang::tooling;
+using clang::clangd::SymbolSlab;
+
+namespace clang {
+namespace clangd {
+
+class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
+public:
+  SymbolIndexActionFactory() = default;
+
+  clang::FrontendAction *create() override {
+index::IndexingOptions IndexOpts;
+IndexOpts.SystemSymbolFilter =
+index::IndexingOptions::SystemSymbolFilterKind::All;
+IndexOpts.IndexFunctionLocals = false;
+Collector = std::make_shared();
+return index::createIndexingAction(Collector, IndexOpts, 
nullptr).release();
+  }
+
+  std::shared_ptr Collector;
+};
+
+} // namespace clangd
+} // namespace clang
+
+int main(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+
+  const char* Overview =
+  "This is an **experimental** tool to generate YAML-format "
+  "project-wide symbols for clangd (global code completion). It would be "
+  "ch

[PATCH] D41491: [clangd] Add a tool to build YAML-format global symbols.

2017-12-22 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321358: [clangd] Add a tool to build YAML-format global 
symbols. (authored by hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41491?vs=128021&id=128022#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41491

Files:
  clang-tools-extra/trunk/clangd/CMakeLists.txt
  clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt
  
clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
  clang-tools-extra/trunk/test/CMakeLists.txt

Index: clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt
===
--- clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt
+++ clang-tools-extra/trunk/clangd/global-symbol-builder/CMakeLists.txt
@@ -0,0 +1,19 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../)
+
+set(LLVM_LINK_COMPONENTS
+Support
+)
+
+add_clang_executable(global-symbol-builder
+  GlobalSymbolBuilderMain.cpp
+  )
+
+target_link_libraries(global-symbol-builder
+  PRIVATE
+  clangAST
+  clangIndex
+  clangDaemon
+  clangBasic
+  clangFrontend
+  clangTooling
+)
Index: clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
===
--- clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
+++ clang-tools-extra/trunk/clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
@@ -0,0 +1,110 @@
+//===--- GlobalSymbolBuilderMain.cpp -*- C++-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// GlobalSymbolBuilder is a tool to generate YAML-format symbols across the
+// whole project. This tools is for **experimental** only. Don't use it in
+// production code.
+//
+//===-===//
+
+#include "index/Index.h"
+#include "index/SymbolCollector.h"
+#include "index/SymbolYAML.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Index/IndexingAction.h"
+#include "clang/Index/IndexDataConsumer.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ThreadPool.h"
+
+using namespace llvm;
+using namespace clang::tooling;
+using clang::clangd::SymbolSlab;
+
+namespace clang {
+namespace clangd {
+
+class SymbolIndexActionFactory : public tooling::FrontendActionFactory {
+public:
+  SymbolIndexActionFactory() = default;
+
+  clang::FrontendAction *create() override {
+index::IndexingOptions IndexOpts;
+IndexOpts.SystemSymbolFilter =
+index::IndexingOptions::SystemSymbolFilterKind::All;
+IndexOpts.IndexFunctionLocals = false;
+Collector = std::make_shared();
+return index::createIndexingAction(Collector, IndexOpts, nullptr).release();
+  }
+
+  std::shared_ptr Collector;
+};
+
+} // namespace clangd
+} // namespace clang
+
+int main(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
+
+  const char* Overview =
+  "This is an **experimental** tool to generate YAML-format "
+  "project-wide symbols for clangd (global code completion). It would be "
+  "changed and deprecated eventually. Don't use it in production code!";
+  CommonOptionsParser OptionsParser(argc, argv, cl::GeneralCategory,
+/*Overview=*/Overview);
+
+  // No compilation database found, fallback to single TU analysis, this is
+  // mainly for debugging purpose:
+  //   global-symbol-buidler /tmp/t.cc -- -std=c++11.
+  if (OptionsParser.getCompilations().getAllFiles().empty()) {
+llvm::errs() << "No compilation database found, processing individual "
+"files with flags from command-line\n.";
+ClangTool Tool(OptionsParser.getCompilations(),
+   OptionsParser.getSourcePathList());
+clang::clangd::SymbolIndexActionFactory IndexAction;
+Tool.run(&IndexAction);
+llvm::outs() << SymbolToYAML(IndexAction.Collector->takeSymbols());
+return 0;
+  }
+
+  // Found compilation database, we iterate all TUs from database to get all
+  // symbols, and then merge them into a single SymbolSlab.
+  SymbolSlab GlobalSymbols;
+  std::mutex SymbolMutex;
+  auto AddSymbols = [&](const SymbolSlab& NewSymbols) {
+// Synchronize set accesses.
+std::unique_lock LockGuard(SymbolMutex);
+for (auto It : NewSymbols) {
+  // FIXME: Better handling the overlap symbols, currently we 

r321360 - Unit tests for TBAA metadata generation.

2017-12-22 Thread Serge Pavlov via cfe-commits
Author: sepavloff
Date: Fri Dec 22 07:22:45 2017
New Revision: 321360

URL: http://llvm.org/viewvc/llvm-project?rev=321360&view=rev
Log:
Unit tests for TBAA metadata generation.

Now tests for metadata created by clang involve compiling code snippets
placed into c/c++ source files and matching interesting patterns in the
obtained textual representation of IR. Writting such tests is a painful
process as metadata often form complex tree-like structures but textual
representation of IR contains only a pile of metadata at the module end.

This change implements IR matchers that may be used to match required
patterns in the binary IR representation. In this case the metadata
structure is not broken and creation of match patterns is easier.

The change adds unit tests for TBAA metadata generation.

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

Added:
cfe/trunk/unittests/CodeGen/IRMatchers.h
cfe/trunk/unittests/CodeGen/TBAAMetadataTest.cpp
Modified:
cfe/trunk/unittests/CodeGen/CMakeLists.txt

Modified: cfe/trunk/unittests/CodeGen/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/CodeGen/CMakeLists.txt?rev=321360&r1=321359&r2=321360&view=diff
==
--- cfe/trunk/unittests/CodeGen/CMakeLists.txt (original)
+++ cfe/trunk/unittests/CodeGen/CMakeLists.txt Fri Dec 22 07:22:45 2017
@@ -7,6 +7,7 @@ add_clang_unittest(ClangCodeGenTests
   BufferSourceTest.cpp
   CodeGenExternalTest.cpp
   IncrementalProcessingTest.cpp
+  TBAAMetadataTest.cpp
   )
 
 target_link_libraries(ClangCodeGenTests

Added: cfe/trunk/unittests/CodeGen/IRMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/CodeGen/IRMatchers.h?rev=321360&view=auto
==
--- cfe/trunk/unittests/CodeGen/IRMatchers.h (added)
+++ cfe/trunk/unittests/CodeGen/IRMatchers.h Fri Dec 22 07:22:45 2017
@@ -0,0 +1,453 @@
+//=== unittests/CodeGen/IRMatchers.h - Match on the LLVM IR -*- C++ 
-*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+/// \file
+/// This file provides a simple mechanism for performing search operations over
+/// IR including metadata and types. It allows writing complex search patterns
+/// using understandable syntax. For instance, the code:
+///
+/// \code
+///   const BasicBlock *BB = ...
+///   const Instruction *I = match(BB,
+///   MInstruction(Instruction::Store,
+///   MConstInt(4, 8),
+///   MMTuple(
+///   MMTuple(
+///   MMString("omnipotent char"),
+///   MMTuple(
+///   MMString("Simple C/C++ TBAA")),
+///   MConstInt(0, 64)),
+///   MSameAs(0),
+///   MConstInt(0;
+/// \endcode
+///
+/// searches the basic block BB for the 'store' instruction, first argument of
+/// which is 'i8 4', and the attached metadata has an item described by the
+/// given tree.
+//===--===//
+
+#ifndef CLANG_UNITTESTS_CODEGEN_IRMATCHERS_H
+#define CLANG_UNITTESTS_CODEGEN_IRMATCHERS_H
+
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Instruction.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Value.h"
+
+namespace llvm {
+
+/// Keeps information about pending match queries.
+///
+/// This class stores state of all unfinished match actions. It allows to
+/// use queries like "this operand is the same as n-th operand", which are
+/// hard to implement otherwise.
+///
+class MatcherContext {
+public:
+
+  /// Describes pending match query.
+  ///
+  /// The query is represented by the current entity being investigated (type,
+  /// value or metadata). If the entity is a member of a list (like arguments),
+  /// the query also keeps the entity number in that list.
+  ///
+  class Query {
+PointerUnion3 Entity;
+unsigned OperandNo;
+
+  public:
+Query(const Value *V, unsigned N) : Entity(V), OperandNo(N) {}
+Query(const Metadata *M, unsigned N) : Entity(M), OperandNo(N) {}
+Query(const Type *T, unsigned N) : Entity(T), OperandNo(N) {}
+
+template
+const T *get() const {
+  return Entity.dyn_cast();
+}
+
+unsigned getOperandNo() const { return OperandNo; }
+  };
+
+  template
+  void push(const T *V, unsigned N = ~0) {
+MatchStack.push_back(Query(V, N));
+  }
+
+  void pop() { MatchStack.pop_back(); }
+
+  template
+  const T *top() const { return MatchStack.back().get(); }
+
+  size_t size() const { return MatchStack.size(); }
+
+  unsigned getOperandNo() const { return MatchStack

[PATCH] D41433: Unit tests for TBAA metadata generation.

2017-12-22 Thread Serge Pavlov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321360: Unit tests for TBAA metadata generation. (authored 
by sepavloff, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D41433

Files:
  cfe/trunk/unittests/CodeGen/CMakeLists.txt
  cfe/trunk/unittests/CodeGen/IRMatchers.h
  cfe/trunk/unittests/CodeGen/TBAAMetadataTest.cpp

Index: cfe/trunk/unittests/CodeGen/CMakeLists.txt
===
--- cfe/trunk/unittests/CodeGen/CMakeLists.txt
+++ cfe/trunk/unittests/CodeGen/CMakeLists.txt
@@ -7,6 +7,7 @@
   BufferSourceTest.cpp
   CodeGenExternalTest.cpp
   IncrementalProcessingTest.cpp
+  TBAAMetadataTest.cpp
   )
 
 target_link_libraries(ClangCodeGenTests
Index: cfe/trunk/unittests/CodeGen/TBAAMetadataTest.cpp
===
--- cfe/trunk/unittests/CodeGen/TBAAMetadataTest.cpp
+++ cfe/trunk/unittests/CodeGen/TBAAMetadataTest.cpp
@@ -0,0 +1,1299 @@
+//=== unittests/CodeGen/TBAAMetadataTest.cpp - Checks metadata generation -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "IRMatchers.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Parse/ParseAST.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "gtest/gtest.h"
+#include 
+
+using namespace llvm;
+
+namespace {
+
+struct TestCompiler {
+  LLVMContext Context;
+  clang::CompilerInstance compiler;
+  clang::CodeGenerator *CG = nullptr;
+  llvm::Module *M = nullptr;
+  unsigned PtrSize = 0;
+
+  void init(const char *TestProgram) {
+compiler.createDiagnostics();
+compiler.getCodeGenOpts().StructPathTBAA = 1;
+compiler.getCodeGenOpts().OptimizationLevel = 1;
+
+std::string TrStr = llvm::Triple::normalize(llvm::sys::getProcessTriple());
+llvm::Triple Tr(TrStr);
+Tr.setOS(Triple::Linux);
+Tr.setVendor(Triple::VendorType::UnknownVendor);
+Tr.setEnvironment(Triple::EnvironmentType::UnknownEnvironment);
+compiler.getTargetOpts().Triple = Tr.getTriple();
+compiler.setTarget(clang::TargetInfo::CreateTargetInfo(
+compiler.getDiagnostics(),
+std::make_shared(compiler.getTargetOpts(;
+
+const clang::TargetInfo &TInfo = compiler.getTarget();
+PtrSize = TInfo.getPointerWidth(0) / 8;
+
+compiler.createFileManager();
+compiler.createSourceManager(compiler.getFileManager());
+compiler.createPreprocessor(clang::TU_Prefix);
+
+compiler.createASTContext();
+
+CG = CreateLLVMCodeGen(
+compiler.getDiagnostics(),
+"main-module",
+compiler.getHeaderSearchOpts(),
+compiler.getPreprocessorOpts(),
+compiler.getCodeGenOpts(),
+Context);
+compiler.setASTConsumer(std::unique_ptr(CG));
+
+compiler.createSema(clang::TU_Prefix, nullptr);
+
+clang::SourceManager &sm = compiler.getSourceManager();
+sm.setMainFileID(sm.createFileID(
+llvm::MemoryBuffer::getMemBuffer(TestProgram), clang::SrcMgr::C_User));
+  }
+
+  const BasicBlock *compile() {
+clang::ParseAST(compiler.getSema(), false, false);
+M = CG->GetModule();
+
+// Do not expect more than one function definition.
+auto FuncPtr = M->begin();
+for (; FuncPtr != M->end(); ++FuncPtr)
+  if (!FuncPtr->isDeclaration())
+break;
+assert(FuncPtr != M->end());
+const llvm::Function &Func = *FuncPtr;
+++FuncPtr;
+for (; FuncPtr != M->end(); ++FuncPtr)
+  if (!FuncPtr->isDeclaration())
+break;
+assert(FuncPtr == M->end());
+
+// The function must consist of single basic block.
+auto BBPtr = Func.begin();
+assert(Func.begin() != Func.end());
+const BasicBlock &BB = *BBPtr;
+++BBPtr;
+assert(BBPtr == Func.end());
+
+return &BB;
+  }
+};
+
+
+auto OmnipotentCharC = MMTuple(
+  MMString("omnipotent char"),
+  MMTuple(
+MMString("Simple C/C++ TBAA")),
+  MConstInt(0, 64)
+);
+
+
+auto OmnipotentCharCXX = MMTuple(
+  MMString("omnipotent char"),
+  MMTuple(
+MMString("Simple C++ TBAA")),
+  MConstInt(0, 64)
+);
+
+
+TEST(TBAAMetadataTest, BasicTypes) {
+  const char TestProgram[] = R"**(
+void func(char *CP, short *SP, int *IP, long long *LP, void **VPP,
+  int **IPP) {
+  *CP = 4;
+  *SP = 11;
+  *IP = 601;
+  *LP = 604;
+  *VPP = CP;
+  *IPP = IP;
+}
+  )**";
+
+  TestCompiler Compiler;
+  Compiler.compiler.getLangOpts().C11 = 1;
+  Compiler.init(TestProgram);
+  const BasicBlock *BB = Compiler.compile();
+
+  cons

[PATCH] D41520: smmintrin.h documentation fixes and updates

2017-12-22 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D41520



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


[PATCH] D41518: pmmintrin.h documentation fixes and updates

2017-12-22 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D41518



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


Re: [PATCH] D41318: Start setting dso_local in clang

2017-12-22 Thread Rafael Avila de Espindola via cfe-commits
Ping.

Is this direction OK? Should a put the time to update the existing tests
to account for dso_local?

I do volunteer to implement the rest of ELF, COFF and MachO once this is
in.

Cheers,
Rafael

Rafael Avila de Espindola  writes:

> Reid Kleckner via Phabricator  writes:
>
>> rnk added inline comments.
>>
>>
>> 
>> Comment at: lib/CodeGen/CodeGenModule.cpp:690-692
>> +  // Only handle ELF for now.
>> +  if (!CGM.getTriple().isOSBinFormatELF())
>> +return false;
>> 
>> Handling COFF here is probably trivial. Everything is dso_local unless it's 
>> dllimport. Does that matter, or is dso_local intended to be an ELF-specific 
>> annotation?
>
> The dso_local attribute is for all file formats. This patch is ELF only
> in the interest of being incremental.
>
> In addition of what this patch shows there will be a lot of test updates
> because of dso_local showing up, so splitting up the patches is probably
> a good thing.
>
> Cheers,
> Rafael
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41363: [clang-tidy] Adding Fuchsia checker for overloaded operators

2017-12-22 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL321363: [clang-tidy] Adding Fuchsia checker for overloaded 
operators (authored by juliehockett, committed by ).
Herald added a subscriber: klimek.

Changed prior to commit:
  https://reviews.llvm.org/D41363?vs=127960&id=128032#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41363

Files:
  clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
  clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-overloaded-operator.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp

Index: clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h
@@ -0,0 +1,35 @@
+//===--- OverloadedOperatorCheck.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_FUCHSIA_OVERLOADED_OPERATOR_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Overloading operators is disallowed by the Fuchsia coding standard.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-overloaded-operator.html
+class OverloadedOperatorCheck : public ClangTidyCheck {
+public:
+  OverloadedOperatorCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_OVERLOADED_OPERATOR_H
Index: clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "DefaultArgumentsCheck.h"
+#include "OverloadedOperatorCheck.h"
 #include "VirtualInheritanceCheck.h"
 
 using namespace clang::ast_matchers;
@@ -25,6 +26,8 @@
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck(
 "fuchsia-default-arguments");
+CheckFactories.registerCheck(
+"fuchsia-overloaded-operator");
 CheckFactories.registerCheck(
 "fuchsia-virtual-inheritance");
   }
Index: clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
@@ -0,0 +1,39 @@
+//===--- OverloadedOperatorCheck.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 "OverloadedOperatorCheck.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) {
+  if (const auto *CXXMethodNode = dyn_cast(&Node)) {
+if (CXXMethodNode->isCopyAssignmentOperator() ||
+CXXMethodNode->isMoveAssignmentOperator())
+  return false;
+  }
+  return Node.isOverloadedOperator();
+}
+
+void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"),
+ this);
+}
+
+void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *D = Result.Nodes.getNodeAs("decl"))
+diag(D->getLocStart(), "cannot overload %0") << D;
+}
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
===

[clang-tools-extra] r321363 - [clang-tidy] Adding Fuchsia checker for overloaded operators

2017-12-22 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Fri Dec 22 08:52:25 2017
New Revision: 321363

URL: http://llvm.org/viewvc/llvm-project?rev=321363&view=rev
Log:
[clang-tidy] Adding Fuchsia checker for overloaded operators

Adds a check to the Fuchsia module to warn if an operator is overloaded,
except move and copy operators.

See https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md for
reference.

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

Added:
clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-overloaded-operator.rst
clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt?rev=321363&r1=321362&r2=321363&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt Fri Dec 22 
08:52:25 2017
@@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
 add_clang_library(clangTidyFuchsiaModule
   DefaultArgumentsCheck.cpp
   FuchsiaTidyModule.cpp
+  OverloadedOperatorCheck.cpp
   VirtualInheritanceCheck.cpp
 
   LINK_LIBS

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp?rev=321363&r1=321362&r2=321363&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp Fri Dec 22 
08:52:25 2017
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 #include "DefaultArgumentsCheck.h"
+#include "OverloadedOperatorCheck.h"
 #include "VirtualInheritanceCheck.h"
 
 using namespace clang::ast_matchers;
@@ -25,6 +26,8 @@ public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
 CheckFactories.registerCheck(
 "fuchsia-default-arguments");
+CheckFactories.registerCheck(
+"fuchsia-overloaded-operator");
 CheckFactories.registerCheck(
 "fuchsia-virtual-inheritance");
   }

Added: clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp?rev=321363&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp Fri 
Dec 22 08:52:25 2017
@@ -0,0 +1,39 @@
+//===--- OverloadedOperatorCheck.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 "OverloadedOperatorCheck.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) {
+  if (const auto *CXXMethodNode = dyn_cast(&Node)) {
+if (CXXMethodNode->isCopyAssignmentOperator() ||
+CXXMethodNode->isMoveAssignmentOperator())
+  return false;
+  }
+  return Node.isOverloadedOperator();
+}
+
+void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"),
+ this);
+}
+
+void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) {
+  if (const auto *D = Result.Nodes.getNodeAs("decl"))
+diag(D->getLocStart(), "cannot overload %0") << D;
+}
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h?rev=321363&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h (added)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h Fri 
Dec 22 08:52:25 2017
@@ -0,0 +1,35 @@
+//===--- OverloadedOperatorCheck.h - clang-tidy

Re: [clang-tools-extra] r321363 - [clang-tidy] Adding Fuchsia checker for overloaded operators

2017-12-22 Thread Aaron Ballman via cfe-commits
On Fri, Dec 22, 2017 at 11:52 AM, Julie Hockett via cfe-commits
 wrote:
> Author: juliehockett
> Date: Fri Dec 22 08:52:25 2017
> New Revision: 321363
>
> URL: http://llvm.org/viewvc/llvm-project?rev=321363&view=rev
> Log:
> [clang-tidy] Adding Fuchsia checker for overloaded operators
>
> Adds a check to the Fuchsia module to warn if an operator is overloaded,
> except move and copy operators.
>
> See https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md for
> reference.
>
> Differential Revision: https://reviews.llvm.org/D41363
>
> Added:
> clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
> clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h
> 
> clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-overloaded-operator.rst
> clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp
> Modified:
> clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
> clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
> clang-tools-extra/trunk/docs/ReleaseNotes.rst
> clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
>
> Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt?rev=321363&r1=321362&r2=321363&view=diff
> ==
> --- clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt (original)
> +++ clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt Fri Dec 22 
> 08:52:25 2017
> @@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS support)
>  add_clang_library(clangTidyFuchsiaModule
>DefaultArgumentsCheck.cpp
>FuchsiaTidyModule.cpp
> +  OverloadedOperatorCheck.cpp
>VirtualInheritanceCheck.cpp
>
>LINK_LIBS
>
> Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp?rev=321363&r1=321362&r2=321363&view=diff
> ==
> --- clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp 
> (original)
> +++ clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp Fri Dec 
> 22 08:52:25 2017
> @@ -11,6 +11,7 @@
>  #include "../ClangTidyModule.h"
>  #include "../ClangTidyModuleRegistry.h"
>  #include "DefaultArgumentsCheck.h"
> +#include "OverloadedOperatorCheck.h"
>  #include "VirtualInheritanceCheck.h"
>
>  using namespace clang::ast_matchers;
> @@ -25,6 +26,8 @@ public:
>void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
>  CheckFactories.registerCheck(
>  "fuchsia-default-arguments");
> +CheckFactories.registerCheck(
> +"fuchsia-overloaded-operator");
>  CheckFactories.registerCheck(
>  "fuchsia-virtual-inheritance");
>}
>
> Added: clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp?rev=321363&view=auto
> ==
> --- clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp 
> (added)
> +++ clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.cpp 
> Fri Dec 22 08:52:25 2017
> @@ -0,0 +1,39 @@
> +//===--- OverloadedOperatorCheck.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 "OverloadedOperatorCheck.h"
> +
> +using namespace clang::ast_matchers;
> +
> +namespace clang {
> +namespace tidy {
> +namespace fuchsia {
> +
> +AST_MATCHER(FunctionDecl, isFuchsiaOverloadedOperator) {
> +  if (const auto *CXXMethodNode = dyn_cast(&Node)) {
> +if (CXXMethodNode->isCopyAssignmentOperator() ||
> +CXXMethodNode->isMoveAssignmentOperator())
> +  return false;
> +  }
> +  return Node.isOverloadedOperator();
> +}
> +
> +void OverloadedOperatorCheck::registerMatchers(MatchFinder *Finder) {
> +  
> Finder->addMatcher(functionDecl(isFuchsiaOverloadedOperator()).bind("decl"),
> + this);
> +}
> +
> +void OverloadedOperatorCheck::check(const MatchFinder::MatchResult &Result) {
> +  if (const auto *D = Result.Nodes.getNodeAs("decl"))
> +diag(D->getLocStart(), "cannot overload %0") << D;
> +}
> +
> +} // namespace fuchsia
> +} // namespace tidy
> +} // namespace clang
>
> Added: clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/OverloadedOperatorCheck.h?rev=321363&view=auto
> =

[PATCH] D41544: Use backslash escape, replacing xargs -0 in test macro-multiline.c

2017-12-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast created this revision.

xargs supports escaping of newline characters with backslash. xargs -0 is 
neither part of POSIX nor the LSB.

This patch removes the -0 option and adjusts the input to xargs accordingly; 
that is, the input is a text file not ending in an incomplete line, and the 
newline of interest is preceded by a backslash.

Note: The treatment of escaped newline characters is not as clearly specified 
by POSIX as for escaped blank characters; however, the same can be said for 
escaped backslashes. It is slightly more clear for the case where the -I option 
is used; however, -I is also of limited portability.


Repository:
  rC Clang

https://reviews.llvm.org/D41544

Files:
  test/Preprocessor/macro-multiline.c


Index: test/Preprocessor/macro-multiline.c
===
--- test/Preprocessor/macro-multiline.c
+++ test/Preprocessor/macro-multiline.c
@@ -1,4 +1,4 @@
-// RUN: printf -- "-DX=A\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT" | xargs -0 
%clang -E %s | FileCheck -strict-whitespace %s
+// RUN: printf -- "-DX=A\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT\n" | xargs 
%clang -E %s | FileCheck -strict-whitespace %s
 
 // Per GCC -D semantics, \n and anything that follows is ignored.
 


Index: test/Preprocessor/macro-multiline.c
===
--- test/Preprocessor/macro-multiline.c
+++ test/Preprocessor/macro-multiline.c
@@ -1,4 +1,4 @@
-// RUN: printf -- "-DX=A\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT" | xargs -0 %clang -E %s | FileCheck -strict-whitespace %s
+// RUN: printf -- "-DX=A\nTHIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT\n" | xargs %clang -E %s | FileCheck -strict-whitespace %s
 
 // Per GCC -D semantics, \n and anything that follows is ignored.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41535: Add -vfsoverlay option for Clang-Tidy

2017-12-22 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

IIUC, you want to pass an overlay so that clang-tidy will read the file opened 
in the IDE from a different directory?

Could you provide add `-ivfsoverlay` option to your compile command instead?

  $ clang --help | grep vfs
  -ivfsoverlay Overlay the virtual filesystem described by file over 
the real file system


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41535



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


[PATCH] D41545: Replace cp -a in various Clang tests

2017-12-22 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast created this revision.

`cp -a` is neither part of POSIX nor the LSB; this patch uses `cp -RPp`, the 
nearest equivalent under POSIX.

The tree being copied in each case currently contains only directories and 
regular files; so the `-P` is superfluous.

`test/Modules/crash-vfs-headermaps.m` is not updated since it requires 
`system-darwin` anyway.


Repository:
  rC Clang

https://reviews.llvm.org/D41545

Files:
  test/Modules/crash-vfs-path-emptydir-entries.m
  test/Modules/crash-vfs-path-symlink-component.m
  test/Modules/crash-vfs-path-symlink-topheader.m
  test/Modules/crash-vfs-umbrella-frameworks.m
  test/VFS/umbrella-framework-import-skipnonexist.m


Index: test/VFS/umbrella-framework-import-skipnonexist.m
===
--- test/VFS/umbrella-framework-import-skipnonexist.m
+++ test/VFS/umbrella-framework-import-skipnonexist.m
@@ -5,7 +5,7 @@
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/vdir %t/outdir %t/cache
-// RUN: cp -a %S/Inputs/Bar.framework %t/outdir/
+// RUN: cp -RPp %S/Inputs/Bar.framework %t/outdir/
 //
 // RUN: sed -e "s:VDIR:%t/vdir:g" -e "s:OUT_DIR:%t/outdir:g" 
%S/Inputs/bar-headers.yaml > %t/vdir/bar-headers.yaml
 // RUN: rm -f %t/outdir/Bar.framework/Headers/B.h
Index: test/Modules/crash-vfs-umbrella-frameworks.m
===
--- test/Modules/crash-vfs-umbrella-frameworks.m
+++ test/Modules/crash-vfs-umbrella-frameworks.m
@@ -5,7 +5,7 @@
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/i %t/m %t
-// RUN: cp -a %S/Inputs/crash-recovery/Frameworks %t/i/
+// RUN: cp -RPp %S/Inputs/crash-recovery/Frameworks %t/i/
 // RUN: mkdir -p %t/i/Frameworks/A.framework/Frameworks
 // RUN: ln -s ../../B.framework 
%t/i/Frameworks/A.framework/Frameworks/B.framework
 
Index: test/Modules/crash-vfs-path-symlink-topheader.m
===
--- test/Modules/crash-vfs-path-symlink-topheader.m
+++ test/Modules/crash-vfs-path-symlink-topheader.m
@@ -8,7 +8,7 @@
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/i %t/m %t %t/sysroot
-// RUN: cp -a %S/Inputs/crash-recovery/usr %t/i/
+// RUN: cp -RPp %S/Inputs/crash-recovery/usr %t/i/
 // RUN: rm -f %t/i/usr/include/pthread_impl.h
 // RUN: ln -s pthread/pthread_impl.h %t/i/usr/include/pthread_impl.h
 
Index: test/Modules/crash-vfs-path-symlink-component.m
===
--- test/Modules/crash-vfs-path-symlink-component.m
+++ test/Modules/crash-vfs-path-symlink-component.m
@@ -8,7 +8,7 @@
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/i %t/m %t %t/sysroot
-// RUN: cp -a %S/Inputs/crash-recovery/usr %t/i/
+// RUN: cp -RPp %S/Inputs/crash-recovery/usr %t/i/
 // RUN: ln -s include/tcl-private %t/i/usr/x
 
 // RUN: not env FORCE_CLANG_DIAGNOSTICS_CRASH= TMPDIR=%t TEMP=%t TMP=%t \
Index: test/Modules/crash-vfs-path-emptydir-entries.m
===
--- test/Modules/crash-vfs-path-emptydir-entries.m
+++ test/Modules/crash-vfs-path-emptydir-entries.m
@@ -8,7 +8,7 @@
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/i %t/m %t %t/sysroot
-// RUN: cp -a %S/Inputs/crash-recovery/usr %t/i/
+// RUN: cp -RPp %S/Inputs/crash-recovery/usr %t/i/
 
 // RUN: not env FORCE_CLANG_DIAGNOSTICS_CRASH= TMPDIR=%t TEMP=%t TMP=%t \
 // RUN: %clang -fsyntax-only %s -I %/t/i -isysroot %/t/sysroot/ \


Index: test/VFS/umbrella-framework-import-skipnonexist.m
===
--- test/VFS/umbrella-framework-import-skipnonexist.m
+++ test/VFS/umbrella-framework-import-skipnonexist.m
@@ -5,7 +5,7 @@
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/vdir %t/outdir %t/cache
-// RUN: cp -a %S/Inputs/Bar.framework %t/outdir/
+// RUN: cp -RPp %S/Inputs/Bar.framework %t/outdir/
 //
 // RUN: sed -e "s:VDIR:%t/vdir:g" -e "s:OUT_DIR:%t/outdir:g" %S/Inputs/bar-headers.yaml > %t/vdir/bar-headers.yaml
 // RUN: rm -f %t/outdir/Bar.framework/Headers/B.h
Index: test/Modules/crash-vfs-umbrella-frameworks.m
===
--- test/Modules/crash-vfs-umbrella-frameworks.m
+++ test/Modules/crash-vfs-umbrella-frameworks.m
@@ -5,7 +5,7 @@
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/i %t/m %t
-// RUN: cp -a %S/Inputs/crash-recovery/Frameworks %t/i/
+// RUN: cp -RPp %S/Inputs/crash-recovery/Frameworks %t/i/
 // RUN: mkdir -p %t/i/Frameworks/A.framework/Frameworks
 // RUN: ln -s ../../B.framework %t/i/Frameworks/A.framework/Frameworks/B.framework
 
Index: test/Modules/crash-vfs-path-symlink-topheader.m
===
--- test/Modules/crash-vfs-path-symlink-topheader.m
+++ test/Modules/crash-vfs-path-symlink-topheader.m
@@ -8,7 +8,7 @@
 
 // RUN: rm -rf %t
 // RUN: mkdir -p %t/i %t/m %t %t/sysroot
-// RUN: cp -a %S/Inputs/crash-recovery/usr %t/i/
+// RUN: cp -RPp %S/Inputs/crash-recovery/usr %t/i/
 // RUN: rm -f %t/i/usr/

[clang-tools-extra] r321378 - Reformatting Fuchsia overloaded operator test

2017-12-22 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Fri Dec 22 11:15:05 2017
New Revision: 321378

URL: http://llvm.org/viewvc/llvm-project?rev=321378&view=rev
Log:
Reformatting Fuchsia overloaded operator test

Fixing parameters in clang-tidy fuchsia-overloaded-operator test case

Modified:
clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp?rev=321378&r1=321377&r2=321378&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/fuchsia-overloaded-operator.cpp Fri 
Dec 22 11:15:05 2017
@@ -14,5 +14,5 @@ public:
   // CHECK-MESSAGES-NOT: [[@LINE-1]]:3: warning: cannot overload 'operator=' 
[fuchsia-overloaded-operator]
 };
 
-A operator-(const A& AA, const A& BB);
+A operator-(const A &A1, const A &A2);
 // CHECK-MESSAGES: [[@LINE-1]]:1: warning: cannot overload 'operator-' 
[fuchsia-overloaded-operator]


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


[PATCH] D41546: [clang-tidy] Adding Fuchsia checker for statically constructed objects

2017-12-22 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: aaron.ballman, alexfh, hokein.
juliehockett added a project: clang-tools-extra.
Herald added subscribers: xazax.hun, mgorny.

Adds a check to the Fuchsia module to warn if statically-stored objects are 
created, unless constructed with `constexpr`.

See https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md for reference.


https://reviews.llvm.org/D41546

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp
  clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-statically-constructed-objects.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-statically-constructed-objects.cpp

Index: test/clang-tidy/fuchsia-statically-constructed-objects.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-statically-constructed-objects.cpp
@@ -0,0 +1,46 @@
+// RUN: %check_clang_tidy %s fuchsia-statically-constructed-objects %t
+
+class AdderClass {
+public:
+  AdderClass(int Value1, int Value2) : Val(Value1 + Value2) {}
+  constexpr AdderClass(int Value) : Val(Value) {}
+
+private:
+  int Val;
+};
+
+struct Simple_Struct {
+  int a;
+};
+
+struct Struct_With_Method {
+  int A;
+  void StructMethod() { A++; }
+};
+
+struct Static_Struct_Container {
+  int A;
+  static int B;
+  static struct Simple_Struct C;
+};
+
+int main() {
+
+  static AdderClass A(1, 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: statically constructed objects are disallowed [fuchsia-statically-constructed-objects]
+  // CHECK-MESSAGES-NEXT:  static AdderClass A(1, 2);
+
+  // Allowed, as it uses the constexpr constructor.
+  static AdderClass B(0);
+
+  static struct Simple_Struct C;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: statically constructed objects are disallowed [fuchsia-statically-constructed-objects]
+  // CHECK-MESSAGES-NEXT:  static struct Simple_Struct C;
+
+  static struct Struct_With_Method D;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: statically constructed objects are disallowed [fuchsia-statically-constructed-objects]
+  // CHECK-MESSAGES-NEXT:  static struct Struct_With_Method D;
+
+  static int E;
+  struct Static_Struct_Container F;
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -70,6 +70,7 @@
cppcoreguidelines-special-member-functions
fuchsia-default-arguments
fuchsia-overloaded-operator
+   fuchsia-statically-constructed-objects
fuchsia-virtual-inheritance
google-build-explicit-make-pair
google-build-namespaces
Index: docs/clang-tidy/checks/fuchsia-statically-constructed-objects.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-statically-constructed-objects.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - fuchsia-statically-constructed-objects
+
+fuchsia-statically-constructed-objects
+==
+
+Warns if statically-stored objects are created, unless constructed with 
+`constexpr`.
+
+For example, creating static classes or structs is not allowed:
+
+.. code-block:: c++
+
+  class AdderClass {
+  public:
+AdderClass(int Value1, int Value2) : Val(Value1 + Value2) {}
+constexpr AdderClass(int Value) : Val(Value) {}
+
+  private:
+int Val;
+  };
+
+  // Will cause warning
+  static AdderClass A(1, 2);
+
+But creation of static objects using `constexpr` constructors is allowed:
+
+.. code-block:: c++
+
+  // No warning
+  static AdderClass B(0);
+
+See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -140,6 +140,11 @@
 
   Warns if an operator is overloaded, except for the assignment (copy and move) operators.
 
+- New `fuchsia-statically-constructed-objects
+  `_ check
+
+  Warns if statically-stored objects are created, unless constructed with `constexpr`.
+
 - New `fuchsia-virtual-inheritance
   `_ check
 
Index: clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h
===
--- /dev/null
+++ clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h
@@ -0,0 +1,35 @@
+//===--- StaticallyConstructedObjectsCheck.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.
+//
+//===--

[PATCH] D41547: [CodeGen] Fix TBAA info for accesses to members of base classes

2017-12-22 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev created this revision.
kosarev added reviewers: rjmccall, hfinkel.
kosarev added a project: clang.

Resolves:
Bug 35724 - regression (r315984): fatal error: error in backend: Broken 
function found (Did not see access type in access path!)
https://bugs.llvm.org/show_bug.cgi?id=35724


Repository:
  rL LLVM

https://reviews.llvm.org/D41547

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGen/tbaa-base.cpp


Index: test/CodeGen/tbaa-base.cpp
===
--- test/CodeGen/tbaa-base.cpp
+++ test/CodeGen/tbaa-base.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O1 %s -emit-llvm -o - | FileCheck 
%s
+//
+// Test generating of TBAA metadata for accesses to members of base classes.
+
+struct A {
+  int x, y, z;
+};
+
+struct B : A {
+  int i;
+};
+
+struct C {
+  int i;
+  B b;
+  int j;
+};
+
+int f1(B *b) {
+// CHECK-LABEL: _Z2f1P1B
+// CHECK: load i32, {{.*}}, !tbaa [[TAG_A_y:!.*]]
+  return b->y;
+}
+
+int f2(C *c) {
+// CHECK-LABEL: _Z2f2P1C
+// CHECK: load i32, {{.*}}, !tbaa [[TAG_A_y]]
+  return (&(c->b))->y;
+}
+
+struct D : virtual A
+{};
+
+struct E {
+  D d;
+};
+
+int f3(D *d) {
+// CHECK-LABEL: _Z2f3P1D
+// CHECK: load i32, {{.*}}, !tbaa [[TAG_A_y]]
+  return d->y;
+}
+
+int f4(E *e) {
+// CHECK-LABEL: _Z2f4P1E
+// CHECK: load i32, {{.*}}, !tbaa [[TAG_A_y]]
+  return (&(e->d))->y;
+}
+
+// CHECK-DAG: [[TYPE_char:!.*]] = !{!"omnipotent char", {{.*}}, i64 0}
+// CHECK-DAG: [[TYPE_int:!.*]] = !{!"int", [[TYPE_char]], i64 0}
+// CHECK-DAG: [[TYPE_A:!.*]] = !{!"_ZTS1A", [[TYPE_int]], i64 0, [[TYPE_int]], 
i64 4, [[TYPE_int]], i64 8}
+// CHECK-DAG: [[TAG_A_y]] = !{[[TYPE_A]], [[TYPE_int]], i64 4}
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1034,8 +1034,12 @@
 // Derived-to-base conversions.
 case CK_UncheckedDerivedToBase:
 case CK_DerivedToBase: {
-  Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), BaseInfo,
-  TBAAInfo);
+  // TODO: Support accesses to members of base classes in TBAA. For now, we
+  // conservatively pretend that the complete object is of the base class
+  // type.
+  if (TBAAInfo)
+*TBAAInfo = CGM.getTBAAAccessInfo(E->getType());
+  Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), BaseInfo);
   auto Derived = CE->getSubExpr()->getType()->getPointeeCXXRecordDecl();
   return GetAddressOfBaseClass(Addr, Derived,
CE->path_begin(), CE->path_end(),


Index: test/CodeGen/tbaa-base.cpp
===
--- test/CodeGen/tbaa-base.cpp
+++ test/CodeGen/tbaa-base.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -O1 %s -emit-llvm -o - | FileCheck %s
+//
+// Test generating of TBAA metadata for accesses to members of base classes.
+
+struct A {
+  int x, y, z;
+};
+
+struct B : A {
+  int i;
+};
+
+struct C {
+  int i;
+  B b;
+  int j;
+};
+
+int f1(B *b) {
+// CHECK-LABEL: _Z2f1P1B
+// CHECK: load i32, {{.*}}, !tbaa [[TAG_A_y:!.*]]
+  return b->y;
+}
+
+int f2(C *c) {
+// CHECK-LABEL: _Z2f2P1C
+// CHECK: load i32, {{.*}}, !tbaa [[TAG_A_y]]
+  return (&(c->b))->y;
+}
+
+struct D : virtual A
+{};
+
+struct E {
+  D d;
+};
+
+int f3(D *d) {
+// CHECK-LABEL: _Z2f3P1D
+// CHECK: load i32, {{.*}}, !tbaa [[TAG_A_y]]
+  return d->y;
+}
+
+int f4(E *e) {
+// CHECK-LABEL: _Z2f4P1E
+// CHECK: load i32, {{.*}}, !tbaa [[TAG_A_y]]
+  return (&(e->d))->y;
+}
+
+// CHECK-DAG: [[TYPE_char:!.*]] = !{!"omnipotent char", {{.*}}, i64 0}
+// CHECK-DAG: [[TYPE_int:!.*]] = !{!"int", [[TYPE_char]], i64 0}
+// CHECK-DAG: [[TYPE_A:!.*]] = !{!"_ZTS1A", [[TYPE_int]], i64 0, [[TYPE_int]], i64 4, [[TYPE_int]], i64 8}
+// CHECK-DAG: [[TAG_A_y]] = !{[[TYPE_A]], [[TYPE_int]], i64 4}
Index: lib/CodeGen/CGExpr.cpp
===
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -1034,8 +1034,12 @@
 // Derived-to-base conversions.
 case CK_UncheckedDerivedToBase:
 case CK_DerivedToBase: {
-  Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), BaseInfo,
-  TBAAInfo);
+  // TODO: Support accesses to members of base classes in TBAA. For now, we
+  // conservatively pretend that the complete object is of the base class
+  // type.
+  if (TBAAInfo)
+*TBAAInfo = CGM.getTBAAAccessInfo(E->getType());
+  Address Addr = EmitPointerWithAlignment(CE->getSubExpr(), BaseInfo);
   auto Derived = CE->getSubExpr()->getType()->getPointeeCXXRecordDecl();
   return GetAddressOfBaseClass(Addr, Derived,
CE->path_begin(), CE->path_end(),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bi

[PATCH] D41506: [clangd] Use Builder for symbol slabs, and use sorted-vector for storage

2017-12-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked 6 inline comments as done.
sammccall added a comment.

Thanks!




Comment at: clangd/index/Index.cpp:39
+ [](const Symbol &S, const SymbolID &I) {
+   return S.ID == I;
+ });

ilya-biryukov wrote:
> Should this be `S.ID < I`?
Wow, good catch (both here and below)!
Added a test (for some reason I thought we had one for this sort of stuff)



Comment at: clangd/index/Index.cpp:76
+SymbolSlab SymbolSlab::Builder::build() && {
+  Symbols = {Symbols.begin(), Symbols.end()}; // Force shrink-to-fit.
+  // Sort symbols so the slab can binary search over them.

hokein wrote:
>  use `Symbols.shrink_to_fit()`?
This is only a hint, and on my system it's a no-op. I think we know enough 
about the lifecycle here to make forcing the shrink worth it.



Comment at: clangd/index/SymbolCollector.h:36
   // All Symbols collected from the AST.
-  SymbolSlab Symbols;
+  SymbolSlab::Builder Symbols;
 };

hokein wrote:
> Maybe name it `SymbolBuilder` to avoid confusion -- `Symbols` indicates its 
> type is `SymbolSlab`. 
Hmm, I'm not sure `SymbolBuilder` is a better name - it doesn't build symbols.
I'm not really seeing the association between `Symbols` and `SymbolSlab` - a 
`SymbolSlab::Builder` is also a collection of symbols. 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41506



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


[PATCH] D41506: [clangd] Use Builder for symbol slabs, and use sorted-vector for storage

2017-12-22 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 128049.
sammccall marked an inline comment as done.
sammccall added a comment.

Address review comments, and update new GlobalSymbolBuilder tool for new API.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41506

Files:
  clangd/global-symbol-builder/GlobalSymbolBuilderMain.cpp
  clangd/index/FileIndex.cpp
  clangd/index/Index.cpp
  clangd/index/Index.h
  clangd/index/SymbolCollector.cpp
  clangd/index/SymbolCollector.h
  clangd/index/SymbolYAML.cpp
  unittests/clangd/CodeCompleteTests.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/IndexTests.cpp
  unittests/clangd/SymbolCollectorTests.cpp

Index: unittests/clangd/SymbolCollectorTests.cpp
===
--- unittests/clangd/SymbolCollectorTests.cpp
+++ unittests/clangd/SymbolCollectorTests.cpp
@@ -32,8 +32,7 @@
 
 // GMock helpers for matching Symbol.
 MATCHER_P(QName, Name, "") {
-  return (arg.second.Scope + (arg.second.Scope.empty() ? "" : "::") +
-  arg.second.Name).str() == Name;
+  return (arg.Scope + (arg.Scope.empty() ? "" : "::") + arg.Name).str() == Name;
 }
 
 namespace clang {
Index: unittests/clangd/IndexTests.cpp
===
--- unittests/clangd/IndexTests.cpp
+++ unittests/clangd/IndexTests.cpp
@@ -13,10 +13,10 @@
 #include "gtest/gtest.h"
 
 using testing::UnorderedElementsAre;
+using testing::Pointee;
 
 namespace clang {
 namespace clangd {
-
 namespace {
 
 Symbol symbol(llvm::StringRef QName) {
@@ -33,6 +33,24 @@
   return Sym;
 }
 
+MATCHER_P(Named, N, "") { return arg.Name == N; }
+
+TEST(SymbolSlab, FindAndIterate) {
+  SymbolSlab::Builder B;
+  B.insert(symbol("Z"));
+  B.insert(symbol("Y"));
+  B.insert(symbol("X"));
+  EXPECT_EQ(nullptr, B.find(SymbolID("W")));
+  for (const char *Sym : {"X", "Y", "Z"})
+EXPECT_THAT(B.find(SymbolID(Sym)), Pointee(Named(Sym)));
+
+  SymbolSlab S = std::move(B).build();
+  EXPECT_THAT(S, UnorderedElementsAre(Named("X"), Named("Y"), Named("Z")));
+  EXPECT_EQ(S.end(), S.find(SymbolID("W")));
+  for (const char *Sym : {"X", "Y", "Z"})
+EXPECT_THAT(*S.find(SymbolID(Sym)), Named(Sym));
+}
+
 struct SlabAndPointers {
   SymbolSlab Slab;
   std::vector Pointers;
@@ -45,18 +63,18 @@
 std::shared_ptr>
 generateSymbols(std::vector QualifiedNames,
 std::weak_ptr *WeakSymbols = nullptr) {
-  auto Slab = std::make_shared();
-  if (WeakSymbols)
-*WeakSymbols = Slab;
-
+  SymbolSlab::Builder Slab;
   for (llvm::StringRef QName : QualifiedNames)
-Slab->Slab.insert(symbol(QName));
-
-  for (const auto &Sym : Slab->Slab)
-Slab->Pointers.push_back(&Sym.second);
+Slab.insert(symbol(QName));
 
-  auto *Pointers = &Slab->Pointers;
-  return {std::move(Slab), Pointers};
+  auto Storage = std::make_shared();
+  Storage->Slab = std::move(Slab).build();
+  for (const auto &Sym : Storage->Slab)
+Storage->Pointers.push_back(&Sym);
+  if (WeakSymbols)
+*WeakSymbols = Storage;
+  auto *Pointers = &Storage->Pointers;
+  return {std::move(Storage), Pointers};
 }
 
 // Create a slab of symbols with IDs and names [Begin, End], otherwise identical
Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -28,9 +28,11 @@
   return Sym;
 }
 
-void addNumSymbolsToSlab(int Begin, int End, SymbolSlab *Slab) {
+std::unique_ptr numSlab(int Begin, int End) {
+  SymbolSlab::Builder Slab;
   for (int i = Begin; i <= End; i++)
-Slab->insert(symbol(std::to_string(i)));
+Slab.insert(symbol(std::to_string(i)));
+  return llvm::make_unique(std::move(Slab).build());
 }
 
 std::vector
@@ -45,46 +47,29 @@
   FileSymbols FS;
   EXPECT_THAT(getSymbolNames(*FS.allSymbols()), UnorderedElementsAre());
 
-  auto Slab = llvm::make_unique();
-  addNumSymbolsToSlab(1, 3, Slab.get());
-
-  FS.update("f1", std::move(Slab));
-
+  FS.update("f1", numSlab(1, 3));
   EXPECT_THAT(getSymbolNames(*FS.allSymbols()),
   UnorderedElementsAre("1", "2", "3"));
 }
 
 TEST(FileSymbolsTest, Overlap) {
   FileSymbols FS;
-
-  auto Slab = llvm::make_unique();
-  addNumSymbolsToSlab(1, 3, Slab.get());
-
-  FS.update("f1", std::move(Slab));
-
-  Slab = llvm::make_unique();
-  addNumSymbolsToSlab(3, 5, Slab.get());
-
-  FS.update("f2", std::move(Slab));
-
+  FS.update("f1", numSlab(1, 3));
+  FS.update("f2", numSlab(3, 5));
   EXPECT_THAT(getSymbolNames(*FS.allSymbols()),
   UnorderedElementsAre("1", "2", "3", "3", "4", "5"));
 }
 
 TEST(FileSymbolsTest, SnapshotAliveAfterRemove) {
   FileSymbols FS;
 
-  auto Slab = llvm::make_unique();
-  addNumSymbolsToSlab(1, 3, Slab.get());
-
-  FS.update("f1", std::move(Slab));
+  FS.update("f1", numSlab(1, 3));
 
   auto Symbols = FS.allSymbols();
   EXPECT_THAT(getSymbolNames(*Symbols), UnorderedElementsAre("1", "2", "3"));
 
   FS.update("f1

[PATCH] D41546: [clang-tidy] Adding Fuchsia checker for statically constructed objects

2017-12-22 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/ReleaseNotes.rst:146
+
+  Warns if statically-stored objects are created, unless constructed with 
`constexpr`.
+

Please highlight constexpr with ``, not `.



Comment at: docs/clang-tidy/checks/fuchsia-statically-constructed-objects.rst:6
+
+Warns if statically-stored objects are created, unless constructed with 
+`constexpr`.

Please highlight constexpr with ``, not `.



Comment at: docs/clang-tidy/checks/fuchsia-statically-constructed-objects.rst:25
+
+But creation of static objects using `constexpr` constructors is allowed:
+

Please highlight constexpr with ``, not `.


https://reviews.llvm.org/D41546



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


[PATCH] D41318: Start setting dso_local in clang

2017-12-22 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

Looks good, sorry for the holiday delay.


https://reviews.llvm.org/D41318



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


r321386 - [OPENMP] Captured arguments of the capturable clauses by value.

2017-12-22 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Dec 22 13:01:52 2017
New Revision: 321386

URL: http://llvm.org/viewvc/llvm-project?rev=321386&view=rev
Log:
[OPENMP] Captured arguments of the capturable clauses by value.

If the clause is applied to the combined construct and has captured
expression, try to capture this expression by value rather than by
reference.

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/parallel_for_codegen.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_num_threads_codegen.cpp

cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_num_threads_codegen.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=321386&r1=321385&r2=321386&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Dec 22 13:01:52 2017
@@ -1290,9 +1290,14 @@ bool Sema::IsOpenMPCapturedByRef(ValueDe
   }
 
   if (IsByRef && Ty.getNonReferenceType()->isScalarType()) {
-IsByRef = !DSAStack->hasExplicitDSA(
-D, [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; },
-Level, /*NotLastprivate=*/true);
+IsByRef =
+!DSAStack->hasExplicitDSA(
+D,
+[](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; },
+Level, /*NotLastprivate=*/true) &&
+// If the variable is artificial and must be captured by value - try to
+// capture by value.
+!(isa(D) && D->hasAttr());
   }
 
   // When passing data by copy, we need to make sure it fits the uintptr size
@@ -2321,10 +2326,11 @@ static OMPCapturedExprDecl *buildCapture
   ASTContext &C = S.getASTContext();
   Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts();
   QualType Ty = Init->getType();
+  Attr *OMPCaptureKind = nullptr;
   if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) 
{
-if (S.getLangOpts().CPlusPlus)
+if (S.getLangOpts().CPlusPlus) {
   Ty = C.getLValueReferenceType(Ty);
-else {
+} else {
   Ty = C.getPointerType(Ty);
   ExprResult Res =
   S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init);
@@ -2333,11 +2339,16 @@ static OMPCapturedExprDecl *buildCapture
   Init = Res.get();
 }
 WithInit = true;
+  } else if (AsExpression) {
+// This variable must be captured by value.
+OMPCaptureKind = OMPCaptureKindAttr::CreateImplicit(C, OMPC_unknown);
   }
   auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty,
   CaptureExpr->getLocStart());
   if (!WithInit)
 CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange()));
+  if (OMPCaptureKind)
+CED->addAttr(OMPCaptureKind);
   S.CurContext->addHiddenDecl(CED);
   S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false);
   return CED;
@@ -2346,31 +2357,34 @@ static OMPCapturedExprDecl *buildCapture
 static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr,
  bool WithInit) {
   OMPCapturedExprDecl *CD;
-  if (auto *VD = S.IsOpenMPCapturedDecl(D))
+  if (auto *VD = S.IsOpenMPCapturedDecl(D)) {
 CD = cast(VD);
-  else
+  } else {
 CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit,
   /*AsExpression=*/false);
+  }
   return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(),
   CaptureExpr->getExprLoc());
 }
 
 static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) {
+  CaptureExpr = S.DefaultLvalueConversion(CaptureExpr).get();
   if (!Ref) {
-auto *CD =
-buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."),
- CaptureExpr, /*WithInit=*/true, 
/*AsExpression=*/true);
+OMPCapturedExprDecl *CD = buildCaptureDecl(
+S, &S.getASTContext().Idents.get(".capture_expr."), CaptureExpr,
+/*WithInit=*/true, /*AsExpression=*/true);
 Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(),
CaptureExpr->getExprLoc());
   }
   ExprResult Res = Ref;
   if (!S.getLangOpts().CPlusPlus &&
   CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() 
&&
-  Ref->getType()->isPointerType())
+  Ref->getType()->isPointerType()) {
 Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref);
-  if (!Res.isUsable())
-return ExprError();
-  return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get());
+if (!Res.isUsable())
+  return ExprError();
+  }
+  return S.DefaultLvalueConversion(Res.get());
 }
 
 namespace {
@@ -8117,12 +8131,13 @@ OMPClause *Sema::ActOnOpenMPIfClause(Ope
 if (Val.isInvalid())
   return nullptr;
 
-ValExpr = MakeFullExpr(Val.get()).get();
+ValExpr = Val.get();
 
 OpenMPDir

r321392 - Add an explicit `LLVM_FALLTHROUGH` annotation to an intentional

2017-12-22 Thread Chandler Carruth via cfe-commits
Author: chandlerc
Date: Fri Dec 22 15:29:49 2017
New Revision: 321392

URL: http://llvm.org/viewvc/llvm-project?rev=321392&view=rev
Log:
Add an explicit `LLVM_FALLTHROUGH` annotation to an intentional
fallthrough. Fixes GCC and Clang warnings about this.

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

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=321392&r1=321391&r2=321392&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Dec 22 15:29:49 2017
@@ -3143,6 +3143,7 @@ static void warnAboutRedundantParens(Sem
 case DeclaratorChunk::Paren:
   if (&C == &Paren)
 continue;
+  LLVM_FALLTHROUGH;
 case DeclaratorChunk::Pointer:
   StartsWithDeclaratorId = false;
   continue;


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


[PATCH] D41546: [clang-tidy] Adding Fuchsia checker for statically constructed objects

2017-12-22 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 128060.
juliehockett marked 3 inline comments as done.

https://reviews.llvm.org/D41546

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.cpp
  clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-statically-constructed-objects.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-statically-constructed-objects.cpp

Index: test/clang-tidy/fuchsia-statically-constructed-objects.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-statically-constructed-objects.cpp
@@ -0,0 +1,46 @@
+// RUN: %check_clang_tidy %s fuchsia-statically-constructed-objects %t
+
+class AdderClass {
+public:
+  AdderClass(int Value1, int Value2) : Val(Value1 + Value2) {}
+  constexpr AdderClass(int Value) : Val(Value) {}
+
+private:
+  int Val;
+};
+
+struct Simple_Struct {
+  int a;
+};
+
+struct Struct_With_Method {
+  int A;
+  void StructMethod() { A++; }
+};
+
+struct Static_Struct_Container {
+  int A;
+  static int B;
+  static struct Simple_Struct C;
+};
+
+int main() {
+
+  static AdderClass A(1, 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: statically constructed objects are disallowed [fuchsia-statically-constructed-objects]
+  // CHECK-MESSAGES-NEXT:  static AdderClass A(1, 2);
+
+  // Allowed, as it uses the constexpr constructor.
+  static AdderClass B(0);
+
+  static struct Simple_Struct C;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: statically constructed objects are disallowed [fuchsia-statically-constructed-objects]
+  // CHECK-MESSAGES-NEXT:  static struct Simple_Struct C;
+
+  static struct Struct_With_Method D;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: statically constructed objects are disallowed [fuchsia-statically-constructed-objects]
+  // CHECK-MESSAGES-NEXT:  static struct Struct_With_Method D;
+
+  static int E;
+  struct Static_Struct_Container F;
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -70,6 +70,7 @@
cppcoreguidelines-special-member-functions
fuchsia-default-arguments
fuchsia-overloaded-operator
+   fuchsia-statically-constructed-objects
fuchsia-virtual-inheritance
google-build-explicit-make-pair
google-build-namespaces
Index: docs/clang-tidy/checks/fuchsia-statically-constructed-objects.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-statically-constructed-objects.rst
@@ -0,0 +1,32 @@
+.. title:: clang-tidy - fuchsia-statically-constructed-objects
+
+fuchsia-statically-constructed-objects
+==
+
+Warns if statically-stored objects are created, unless constructed with 
+``constexpr``.
+
+For example, creating static classes or structs is not allowed:
+
+.. code-block:: c++
+
+  class AdderClass {
+  public:
+AdderClass(int Value1, int Value2) : Val(Value1 + Value2) {}
+constexpr AdderClass(int Value) : Val(Value) {}
+
+  private:
+int Val;
+  };
+
+  // Will cause warning
+  static AdderClass A(1, 2);
+
+But creation of static objects using ``constexpr`` constructors is allowed:
+
+.. code-block:: c++
+
+  // No warning
+  static AdderClass B(0);
+
+See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -140,6 +140,11 @@
 
   Warns if an operator is overloaded, except for the assignment (copy and move) operators.
 
+- New `fuchsia-statically-constructed-objects
+  `_ check
+
+  Warns if statically-stored objects are created, unless constructed with ``constexpr``.
+
 - New `fuchsia-virtual-inheritance
   `_ check
 
Index: clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h
===
--- /dev/null
+++ clang-tidy/fuchsia/StaticallyConstructedObjectsCheck.h
@@ -0,0 +1,35 @@
+//===--- StaticallyConstructedObjectsCheck.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_FUCHSIA_STATICALLY_CONSTRUCTED_OBJECTS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_STATICALLY_CONSTRUCTED_OBJECTS_H
+
+#include "../ClangTidy.h"
+
+namespace clang {

[PATCH] D41228: [ObjC] Enable __strong pointers in structs under ARC

2017-12-22 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 128061.
ahatanak added a comment.

Rename functions. Check whether a non-trivial type passed to 
Sema::isValidVarArgType is a struct.


https://reviews.llvm.org/D41228

Files:
  docs/LanguageExtensions.rst
  include/clang/AST/Decl.h
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/ASTContext.cpp
  lib/AST/Decl.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGNonTrivialStruct.cpp
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenFunction.h
  lib/Lex/PPMacroExpansion.cpp
  lib/Sema/JumpDiagnostics.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  test/ARCMT/checking.m
  test/CodeGenObjC/strong-in-c-struct.m
  test/Lexer/has_feature_objc_arc.m
  test/SemaObjC/arc-decls.m
  test/SemaObjC/arc-system-header.m
  test/SemaObjC/strong-in-c-struct.m

Index: test/SemaObjC/strong-in-c-struct.m
===
--- /dev/null
+++ test/SemaObjC/strong-in-c-struct.m
@@ -0,0 +1,56 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks  -fobjc-runtime=ios-11.0 -fsyntax-only -verify %s
+
+typedef struct {
+  id a;
+} Strong;
+
+void callee_variadic(const char *, ...);
+
+void test_variadic(void) {
+  Strong t;
+  callee_variadic("s", t); // expected-error {{cannot pass non-trivial C object of type 'Strong' by value to variadic function}}
+}
+
+void test_jump0(int cond) {
+  switch (cond) {
+  case 0:
+;
+Strong x; // expected-note {{jump bypasses initialization of variable of non-trivial C struct type}}
+break;
+  case 1: // expected-error {{cannot jump from switch statement to this case label}}
+x.a = 0;
+break;
+  }
+}
+
+void test_jump1(void) {
+  static void *ips[] = { &&L0 };
+L0:  // expected-note {{possible target of indirect goto}}
+  ;
+  Strong x; // expected-note {{jump exits scope of variable with non-trivial destructor}}
+  goto *ips; // expected-error {{cannot jump}}
+}
+
+typedef void (^BlockTy)(void);
+void func(BlockTy);
+void func2(Strong);
+
+void test_block_scope0(int cond) {
+  Strong x; // expected-note {{jump enters lifetime of block which captures a C struct that is non-trivial to destroy}}
+  switch (cond) {
+  case 0:
+func(^{ func2(x); });
+break;
+  default: // expected-error {{cannot jump from switch statement to this case label}}
+break;
+  }
+}
+
+void test_block_scope1(void) {
+  static void *ips[] = { &&L0 };
+L0:  // expected-note {{possible target of indirect goto}}
+  ;
+  Strong x; // expected-note {{jump exits scope of variable with non-trivial destructor}} expected-note {{jump exits lifetime of block which captures a C struct that is non-trivial to destroy}}
+  func(^{ func2(x); });
+  goto *ips; // expected-error {{cannot jump}}
+}
Index: test/SemaObjC/arc-system-header.m
===
--- test/SemaObjC/arc-system-header.m
+++ test/SemaObjC/arc-system-header.m
@@ -23,8 +23,7 @@
 }
 
 void test5(struct Test5 *p) {
-  p->field = 0; // expected-error {{'field' is unavailable in ARC}}
-// expected-note@arc-system-header.h:25 {{field has non-trivial ownership qualification}}
+  p->field = 0;
 }
 
 id test6() {
@@ -49,8 +48,7 @@
 
 extern void doSomething(Test9 arg);
 void test9() {
-Test9 foo2 = {0, 0}; // expected-error {{'field' is unavailable in ARC}}
- // expected-note@arc-system-header.h:56 {{field has non-trivial ownership qualification}}
+Test9 foo2 = {0, 0};
 doSomething(foo2);
 }
 #endif
Index: test/SemaObjC/arc-decls.m
===
--- test/SemaObjC/arc-decls.m
+++ test/SemaObjC/arc-decls.m
@@ -3,7 +3,7 @@
 // rdar://8843524
 
 struct A {
-id x; // expected-error {{ARC forbids Objective-C objects in struct}}
+id x;
 };
 
 union u {
@@ -13,7 +13,7 @@
 @interface I {
struct A a; 
struct B {
-id y[10][20]; // expected-error {{ARC forbids Objective-C objects in struct}}
+id y[10][20];
 id z;
} b;
 
@@ -23,7 +23,7 @@
 
 // rdar://10260525
 struct r10260525 {
-  id (^block) (); // expected-error {{ARC forbids blocks in struct}}
+  id (^block) ();
 };
 
 struct S { 
Index: test/Lexer/has_feature_objc_arc.m
===
--- test/Lexer/has_feature_objc_arc.m
+++ test/Lexer/has_feature_objc_arc.m
@@ -13,8 +13,16 @@
 void no_objc_arc_weak_feature();
 #endif
 
+#if __has_feature(objc_arc_fields)
+void has_objc_arc_fields();
+#else
+void no_objc_arc_fields();
+#endif
+
 // CHECK-ARC: void has_objc_arc_feature();
 // CHECK-ARC: void has_objc_arc_weak_feature();
+// CHECK-ARC: void has_objc_arc_fields();
 
 // CHECK-ARCLITE: void has_objc_arc_feature();
 // CHECK-ARCLITE: void no_objc_arc_weak_feature();
+// CHECK-ARCLITE: void has_objc_arc_fields();
Index: test

[PATCH] D41228: [ObjC] Enable __strong pointers in structs under ARC

2017-12-22 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak marked an inline comment as done.
ahatanak added inline comments.



Comment at: include/clang/AST/Type.h:1152
+NTFK_Struct,  // non-trivial C struct.
+NTFK_Array// array that has non-trivial elements.
+  };

rjmccall wrote:
> ahatanak wrote:
> > rjmccall wrote:
> > > ahatanak wrote:
> > > > rjmccall wrote:
> > > > > We don't actually distinguish arrays in DestructionKind.  Is it 
> > > > > important here?  You can't actually do anything with that information.
> > > > > 
> > > > > Regarding your naming question, I wonder if it would be useful to 
> > > > > just invent a new term here, something meaning "non-trivial" but 
> > > > > without the C++ baggage.  Maybe just "PrimitiveCopyKind", with the 
> > > > > understanding that C++ can never do a "primitive" copy?  And for 
> > > > > consistency with DestructionKind, maybe you should lowercase the 
> > > > > second words.
> > > > > 
> > > > > I'm not sure how isNonTrivialToCopy is supposed to be used.  Where 
> > > > > does the function come from?  And why is a context required when it 
> > > > > isn't required for isDestructedType?
> > > > Enum NonTrivialCopyKind and isNonTrivialToCopy() are used just to 
> > > > distinguish the different types of fields in a C struct. Currently, 
> > > > there are four types that are handled by visitField functions in 
> > > > CGNonTrivialStruct.cpp:
> > > > 
> > > > - struct field
> > > > - array field
> > > > - __strong field
> > > > - trivial field that can be copied using memcpy
> > > > 
> > > > I thought using enums would make the code easier to read, but of course 
> > > > it's possible to remove them and instead just check the field types 
> > > > calling functions like getAsArrayType or getAs. ASTContext 
> > > > is passed to isNonTrivialToCopy so that it can call 
> > > > ASTContext::getAsArrayType to determine whether the type is an array. 
> > > > Maybe there is another way to detect an array that doesn't require 
> > > > ASTContext?
> > > > 
> > > > As for the naming, PrimitiveCopyKind seems find if we want to 
> > > > distinguish it from C++ non-trivial classes (I don't have a better 
> > > > name). If we are going to call non-trivial C structs primitiveCopyKind, 
> > > > what should we call the C structs that are trivial (those that can be 
> > > > copied using memcpy)?
> > > I think "trivial" is a reasonable kind of primitive-copy semantics.  
> > > Basically, we're saying that all complete object types other than 
> > > non-trivial C++ types have some sort of primitive-copy semantics, and 
> > > this enum tells us what those semantics are.
> > > 
> > > DestructionKind has to deal with arrays as well, but it does so by just 
> > > reporting the appropriate value for the underlying element type without 
> > > mentioning that it's specifically an *array* of the type.  I think that's 
> > > a reasonable design, since most places do not need to distinguish arrays 
> > > from non-arrays.  IRGen does, but only when you're actually finally 
> > > emitting code; prior to that (when e.g. deciding that a field is 
> > > non-trivial to copy) you can just use the enum value.
> > > 
> > > You can do without getAsArrayType the same way that isDestructedType() 
> > > does: the more complex operation is only necessary in order to preserve 
> > > qualifiers on the element type, but that's unnecessary for this operation 
> > > because the array type itself is considered to have the same qualifiers 
> > > as its element type.  That is, you can ask the original type whether it's 
> > > __strong/__weak-qualified without having to specifically handle array 
> > > types, and once you've done all of those queries, you can use the 
> > > "unsafe" operations to drill down to the element type because you no 
> > > longer care about qualification.
> > So QualType::hasNonTrivialToDefaultInitializeStruct should be renamed to 
> > QualType::hasPrimitiveDefaultInitializeStruct and 
> > RecordDecl::isNonTrivialToPrimitiveDefaultInitialize to 
> > RecordDecl::isPrimitiveDefaultInitialize, for example?
> > 
> > Also, I realized that, after I made the changes that removed the NonTrivial 
> > flags from RecordDecl, CGNonTrivialStruct.cpp is the only user of enum 
> > NonTrivialCopyKind and the following methods of QualType 
> > (Sema::isValidVarArgType calls nonTrivialToDestroy, but it should call 
> > methods like hasNonTrivialToDestroyStruct that detect non-trivial C structs 
> > instead):
> > 
> > nonTrivialToDefaultInitialize
> > nonTrivialToCopy
> > nonTrivialToDestructiveMove
> > nonTrivialToDestroy
> > 
> > Maybe we should make these enums and functions local to 
> > CGNonTrivialStruct.cpp to avoid adding something that is not used outside 
> > CGNonTrivialStruct.cpp?
> I think the right name would be isNonTrivialToPrimitiveDefaultInitialize(), 
> and like isDestructedType() it would return an enum that happens to have a 
> zero value (and is thus false) for the trivial case.
> 
> I th

r321395 - [ODRHash] Support ODR violation detection in functions.

2017-12-22 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Fri Dec 22 16:41:01 2017
New Revision: 321395

URL: http://llvm.org/viewvc/llvm-project?rev=321395&view=rev
Log:
[ODRHash] Support ODR violation detection in functions.

Extend the hashing to functions, which allows detection of function definition
mismatches across modules.  This is a re-commit of r320230.

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/ODRHash.h
cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/ODRHash.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/Modules/odr_hash.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=321395&r1=321394&r2=321395&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Dec 22 16:41:01 2017
@@ -1759,6 +1759,11 @@ protected:
   unsigned IsCopyDeductionCandidate : 1;
 
 private:
+
+  /// Store the ODRHash after first calculation.
+  unsigned HasODRHash : 1;
+  unsigned ODRHash;
+
   /// \brief End part of this FunctionDecl's source range.
   ///
   /// We could compute the full range in getSourceRange(). However, when we're
@@ -1841,8 +1846,9 @@ protected:
 IsExplicitlyDefaulted(false), HasImplicitReturnZero(false),
 IsLateTemplateParsed(false), IsConstexpr(isConstexprSpecified),
 InstantiationIsPending(false), UsesSEHTry(false), 
HasSkippedBody(false),
-WillHaveBody(false), IsCopyDeductionCandidate(false),
-EndRangeLoc(NameInfo.getEndLoc()), DNLoc(NameInfo.getInfo()) {}
+WillHaveBody(false), IsCopyDeductionCandidate(false), 
HasODRHash(false),
+ODRHash(0), EndRangeLoc(NameInfo.getEndLoc()),
+DNLoc(NameInfo.getInfo()) {}
 
   using redeclarable_base = Redeclarable;
 
@@ -2439,6 +2445,10 @@ public:
   /// returns 0.
   unsigned getMemoryFunctionKind() const;
 
+  /// \brief Returns ODRHash of the function.  This value is calculated and
+  /// stored on first call, then the stored value returned on the other calls.
+  unsigned getODRHash();
+
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) {

Modified: cfe/trunk/include/clang/AST/ODRHash.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ODRHash.h?rev=321395&r1=321394&r2=321395&view=diff
==
--- cfe/trunk/include/clang/AST/ODRHash.h (original)
+++ cfe/trunk/include/clang/AST/ODRHash.h Fri Dec 22 16:41:01 2017
@@ -53,6 +53,10 @@ public:
   // more information than the AddDecl class.
   void AddCXXRecordDecl(const CXXRecordDecl *Record);
 
+  // Use this for ODR checking functions between modules.  This method compares
+  // more information than the AddDecl class.
+  void AddFunctionDecl(const FunctionDecl *Function);
+
   // Process SubDecls of the main Decl.  This method calls the DeclVisitor
   // while AddDecl does not.
   void AddSubDecl(const Decl *D);

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=321395&r1=321394&r2=321395&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Fri Dec 22 
16:41:01 2017
@@ -270,6 +270,29 @@ def note_module_odr_violation_mismatch_d
   "friend function %2|"
   "}1">;
 
+def err_module_odr_violation_function : Error<
+  "%q0 has different definitions in different modules; "
+  "%select{definition in module '%2'|defined here}1 "
+  "first difference is "
+  "%select{"
+  "return type is %4|"
+  "%ordinal4 parameter with name %5|"
+  "%ordinal4 parameter with type %5%select{| decayed from %7}6|"
+  "%ordinal4 parameter with%select{out|}5 a default argument|"
+  "%ordinal4 parameter with a default argument|"
+  "function body"
+  "}3">;
+
+def note_module_odr_violation_function : Note<"but in '%0' found "
+  "%select{"
+  "different return type %2|"
+  "%ordinal2 parameter with name %3|"
+  "%ordinal2 parameter with type %3%select{| decayed from %5}4|"
+  "%ordinal2 parameter with%select{out|}3 a default argument|"
+  "%ordinal2 parameter with a different default argument|"
+  "a different body"
+  "}1">;
+
 def err_module_odr_violation_mismatch_decl_unknown : Error<
   "%q0 %select{with definition in module '%2'|defined here}1 has different "
   "definitions in different modules; first difference is this "

Modified: cfe/tr

r321396 - [ODRHash] Disable hashing on methods.

2017-12-22 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Fri Dec 22 17:35:32 2017
New Revision: 321396

URL: http://llvm.org/viewvc/llvm-project?rev=321396&view=rev
Log:
[ODRHash] Disable hashing on methods.

Turn off hashing for class methods, but leave it on for other functions.  This
should get the buildbot to green for the time being.

Modified:
cfe/trunk/lib/AST/ODRHash.cpp

Modified: cfe/trunk/lib/AST/ODRHash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ODRHash.cpp?rev=321396&r1=321395&r2=321396&view=diff
==
--- cfe/trunk/lib/AST/ODRHash.cpp (original)
+++ cfe/trunk/lib/AST/ODRHash.cpp Fri Dec 22 17:35:32 2017
@@ -476,6 +476,9 @@ void ODRHash::AddFunctionDecl(const Func
   if (!Function->hasBody()) return;
   if (!Function->getBody()) return;
 
+  // TODO: Fix hashing for class methods.
+  if (isa(Function)) return;
+
   // Skip functions that are specializations or in specialization context.
   const DeclContext *DC = Function;
   while (DC) {


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


[PATCH] D41517: mmintrin.h documentation fixes and updates

2017-12-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: lib/Headers/mmintrin.h:88
 ///
-/// This intrinsic corresponds to the  VMOVQ / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVD  instruction.
 ///

Shouldn't this be MOVQ?



Comment at: lib/Headers/mmintrin.h:104
 ///
-/// This intrinsic corresponds to the  VMOVQ / MOVD  instruction.
+/// This intrinsic corresponds to the  MOVD  instruction.
 ///

Shouldn't this be MOVQ?



Comment at: lib/Headers/mmintrin.h:1292
 ///
-/// This intrinsic corresponds to the  VXORPS / XORPS  instruction.
+/// This intrinsic corresponds to the  XOR  instruction.
 ///

PXOR?



Comment at: lib/Headers/mmintrin.h:1384
 ///
-/// This intrinsic corresponds to the  VPSHUFD / PSHUFD  instruction.
+/// This intrinsic corresponds to the  PSHUFD  instruction.
 ///

This is overly specific there is no guarantee we'd use those instructions. If 
it was a constant we'd probably just use a load.



Comment at: lib/Headers/mmintrin.h:1402
 ///
-/// This intrinsic corresponds to the  VPSHUFLW / PSHUFLW  instruction.
+/// This intrinsic corresponds to the  PSHUFLW  instruction.
 ///

This is overly specific



Comment at: lib/Headers/mmintrin.h:1419
 ///
-/// This intrinsic corresponds to the  VPUNPCKLBW + VPSHUFLW / PUNPCKLBW +
-///PSHUFLW  instruction.
+/// This intrinsic corresponds to the  PUNPCKLBW + PSHUFLW  instruction.
 ///

This is overly specific


https://reviews.llvm.org/D41517



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


[PATCH] D41523: xmmintrin.h documentation fixes and updates

2017-12-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: lib/Headers/xmmintrin.h:1706
 ///
-/// This intrinsic corresponds to the  VMOVSS / MOVSS + shuffling 
+/// This intrinsic corresponds to the  VBROADCASTSS / BROADCASTSS 
 ///instruction.

There is no BROADCASTSS instruction. That's an AVX instruction that only exists 
as VBROADCASTSS. The orginal comment was correct for pre-AVX.



Comment at: lib/Headers/xmmintrin.h:2199
 ///
-/// This intrinsic corresponds to the  VPINSRW / PINSRW  instruction.
+/// This intrinsic corresponds to the  PINSRW  instruction.
 ///

Why is VPINSRW removed?



Comment at: lib/Headers/xmmintrin.h:2659
 ///
-/// This intrinsic corresponds to the  VMOVSS / MOVSS  instruction.
+/// This intrinsic corresponds to the  VBLENDPS / BLENDPS  instruction.
 ///

MOVSS is correct for pre SSE4.1 targets.


https://reviews.llvm.org/D41523



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


[PATCH] D41516: emmintrin.h documentation fixes and updates

2017-12-22 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D41516



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


[PATCH] D41506: [clangd] Use Builder for symbol slabs, and use sorted-vector for storage

2017-12-22 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41506



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