[PATCH] D53244: [Coverage] Fix PR39258: support coverage regions that start deeper than they end

2018-10-15 Thread Orivej Desh via Phabricator via cfe-commits
orivej added a comment.

Thanks! Could you merge this (after a while to let others review)?




Comment at: test/CoverageMapping/macros.c:60
 
+// CHECK-NEXT: func6
+void func6(unsigned count) { // CHECK-NEXT: File 0, [[@LINE]]:28 -> 
[[@LINE+4]]:2 = #0

vsk wrote:
> Please use CHECK-LABEL here.
`CHECK-LABEL` would accept unchecked output between the previous `CHECK-NEXT` 
and `func6`. It seems that the intention of this test is to check all lines of 
output, so I used `CHECK-NEXT` as in other tests in this file.


Repository:
  rC Clang

https://reviews.llvm.org/D53244



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


[PATCH] D53272: Add target requirement to profile remap test.

2018-10-15 Thread Yvan Roux via Phabricator via cfe-commits
yroux created this revision.
yroux added a reviewer: rsmith.
Herald added a reviewer: javed.absar.
Herald added a subscriber: kristof.beyls.

Fix bots which don't have x86_64 target built (ARM/AArch64).


Repository:
  rC Clang

https://reviews.llvm.org/D53272

Files:
  test/CodeGenCXX/profile-remap.cpp


Index: test/CodeGenCXX/profile-remap.cpp
===
--- test/CodeGenCXX/profile-remap.cpp
+++ test/CodeGenCXX/profile-remap.cpp
@@ -1,3 +1,5 @@
+// REQUIRES: x86-registered-target
+//
 // RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fprofile-sample-use=%S/Inputs/profile-remap.samples 
-fprofile-remapping-file=%S/Inputs/profile-remap.map 
-fexperimental-new-pass-manager -O2 %s -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-SAMPLES
 // RUN: llvm-profdata merge -output %T.profdata 
%S/Inputs/profile-remap.proftext
 // RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fprofile-instrument-use-path=%T.profdata 
-fprofile-remapping-file=%S/Inputs/profile-remap.map 
-fexperimental-new-pass-manager -O2 %s -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-INSTR


Index: test/CodeGenCXX/profile-remap.cpp
===
--- test/CodeGenCXX/profile-remap.cpp
+++ test/CodeGenCXX/profile-remap.cpp
@@ -1,3 +1,5 @@
+// REQUIRES: x86-registered-target
+//
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fprofile-sample-use=%S/Inputs/profile-remap.samples -fprofile-remapping-file=%S/Inputs/profile-remap.map -fexperimental-new-pass-manager -O2 %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-SAMPLES
 // RUN: llvm-profdata merge -output %T.profdata %S/Inputs/profile-remap.proftext
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -fprofile-instrument-use-path=%T.profdata -fprofile-remapping-file=%S/Inputs/profile-remap.map -fexperimental-new-pass-manager -O2 %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,CHECK-INSTR
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53273: [clangd] Fix some references missing in dynamic index.

2018-10-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ioeric, 
ilya-biryukov.

Previously, SymbolCollector postfilters all references at the end to
find all references of interesting symbols.
It was incorrect when indxing main AST where we don't see locations
of symbol declarations and definitions in the main AST (as those are in
preamble AST).

The fix is to do earily check during collecting references.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53273

Files:
  clangd/index/SymbolCollector.cpp
  unittests/clangd/FileIndexTests.cpp

Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -8,13 +8,15 @@
 //===--===//
 
 #include "Annotations.h"
+#include "AST.h"
 #include "ClangdUnit.h"
 #include "TestFS.h"
 #include "TestTU.h"
 #include "gmock/gmock.h"
 #include "index/FileIndex.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/PCHContainerOperations.h"
+#include "clang/Frontend/Utils.h"
 #include "clang/Index/IndexSymbol.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/CompilationDatabase.h"
@@ -346,6 +348,55 @@
   EXPECT_TRUE(SeenSymbol);
 }
 
+TEST(FileIndexTest, ReferencesInMainFileWithPreamble) {
+  const std::string Header = R"cpp(
+class Foo {};
+  )cpp";
+  Annotations Main(R"cpp(
+#include "foo.h"
+void f() {
+  [[Foo]] foo;
+}
+  )cpp");
+  auto MainFile = testPath("foo.cpp");
+  auto HeaderFile = testPath("foo.h");
+  std::vector Cmd = {"clang", "-xc++", MainFile.c_str()};
+  // Preparse ParseInputs.
+  ParseInputs PI;
+  PI.CompileCommand.Directory = testRoot();
+  PI.CompileCommand.Filename = MainFile;
+  PI.CompileCommand.CommandLine = {Cmd.begin(), Cmd.end()};
+  PI.Contents = Main.code();
+  PI.FS = buildTestFS({{MainFile, Main.code()}, {HeaderFile, Header}});
+
+  // Prepare preamble.
+  auto CI = buildCompilerInvocation(PI);
+  auto PreambleData = buildPreamble(
+  MainFile,
+  *buildCompilerInvocation(PI), /*OldPreamble=*/nullptr,
+  tooling::CompileCommand(), PI,
+  std::make_shared(), /*StoreInMemory=*/true,
+  [&](ASTContext &Ctx, std::shared_ptr PP) {});
+  // Build AST for main file with preamble.
+  auto AST = ParsedAST::build(
+  createInvocationFromCommandLine(Cmd), PreambleData,
+  llvm::MemoryBuffer::getMemBufferCopy(Main.code()),
+  std::make_shared(),
+  PI.FS);
+  ASSERT_TRUE(AST);
+  FileIndex Index;
+  Index.updateMain(MainFile, *AST);
+
+  auto Foo =
+  findSymbol(TestTU::withHeaderCode(Header).headerSymbols(), "Foo");
+  RefsRequest Request;
+  Request.IDs.insert(Foo.ID);
+
+  // Expect to see references in main file, references in headers are excluded
+  // because we only index main AST.
+  EXPECT_THAT(getRefs(Index, Foo.ID), RefsAre({RefRange(Main.range())}));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/index/SymbolCollector.cpp
===
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -345,16 +345,17 @@
   SM.getFileID(SpellingLoc) == SM.getMainFileID())
 ReferencedDecls.insert(ND);
 
+  if (!shouldCollectSymbol(*ND, *ASTCtx, Opts))
+return true;
+
   if ((static_cast(Opts.RefFilter) & Roles) &&
   SM.getFileID(SpellingLoc) == SM.getMainFileID())
 DeclRefs[ND].emplace_back(SpellingLoc, Roles);
 
   // Don't continue indexing if this is a mere reference.
   if (!(Roles & static_cast(index::SymbolRole::Declaration) ||
 Roles & static_cast(index::SymbolRole::Definition)))
 return true;
-  if (!shouldCollectSymbol(*ND, *ASTCtx, Opts))
-return true;
 
   auto ID = getSymbolID(ND);
   if (!ID)
@@ -476,17 +477,15 @@
 std::string MainURI = *MainFileURI;
 for (const auto &It : DeclRefs) {
   if (auto ID = getSymbolID(It.first)) {
-if (Symbols.find(*ID)) {
-  for (const auto &LocAndRole : It.second) {
-Ref R;
-auto Range =
-getTokenRange(LocAndRole.first, SM, ASTCtx->getLangOpts());
-R.Location.Start = Range.first;
-R.Location.End = Range.second;
-R.Location.FileURI = MainURI;
-R.Kind = toRefKind(LocAndRole.second);
-Refs.insert(*ID, R);
-  }
+for (const auto &LocAndRole : It.second) {
+  Ref R;
+  auto Range =
+  getTokenRange(LocAndRole.first, SM, ASTCtx->getLangOpts());
+  R.Location.Start = Range.first;
+  R.Location.End = Range.second;
+  R.Location.FileURI = MainURI;
+  R.Kind = toRefKind(LocAndRole.second);
+  Refs.insert(*ID, R);
 }
   }
 }
___
c

[PATCH] D53273: [clangd] Fix some references missing in dynamic index.

2018-10-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Nice fix, just performance concerns.

(I do think this might be significant, but measuring dynamic index time 
before/after for a big TU might show this to be unimportant)




Comment at: clangd/index/SymbolCollector.cpp:348
 
+  if (!shouldCollectSymbol(*ND, *ASTCtx, Opts))
+return true;

This seems better for the main-AST case, but substantially more expensive for 
indexing preambles: we may not want references at all, so paying for 
shouldCollectSymbol for every reference seems wasteful.

what about
```
bool RefMayBeInteresting = RefFilter & Roles;
bool IsOnlyRef = !(Roles & (Declaration | Definition));
if (IsOnlyRef && !RefMayBeInteresting)
  return;
if (!shouldCollectSymbol())
  return;
if (RefMayBeInteresting && File == getMainFileID())
  // add ref
if (IsOnlyRef) // don't continue if mere reference
  return;
```



Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53273



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


[PATCH] D53274: [analyzer][NFC] Tighten up AnalyzerOptions

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, george.karpenkov, xazax.hun, MTC, rnkovacs.
Herald added subscribers: cfe-commits, donat.nagy, mikhail.ramalho, a.sidorin, 
szepet, whisperity.

I was a little unsure about the title, but it is what it is.

I'm in the process of refactoring `AnalyzerOptions`. The main motivation behind 
here is to emit warnings if an invalid `-analyzer-config` option is given from 
the command line, and be able to list them all.

This first NFC patch contains small modifications to make `AnalyzerOptions.cpp` 
a little more consistent.


Repository:
  rC Clang

https://reviews.llvm.org/D53274

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp

Index: lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -68,8 +68,6 @@
   return WorkList::makeUnexploredFirstPriorityQueue();
 case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstLocationQueue:
   return WorkList::makeUnexploredFirstPriorityLocationQueue();
-default:
-  llvm_unreachable("Unexpected case");
   }
 }
 
Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -50,27 +50,24 @@
 }
 
 AnalyzerOptions::UserModeKind AnalyzerOptions::getUserMode() {
-  if (UserMode == UMK_NotSet) {
-StringRef ModeStr =
-Config.insert(std::make_pair("mode", "deep")).first->second;
-UserMode = llvm::StringSwitch(ModeStr)
+  if (!UserMode.hasValue()) {
+StringRef ModeStr = getOptionAsString("mode", "deep");
+UserMode = llvm::StringSwitch>(ModeStr)
   .Case("shallow", UMK_Shallow)
   .Case("deep", UMK_Deep)
-  .Default(UMK_NotSet);
-assert(UserMode != UMK_NotSet && "User mode is invalid.");
+  .Default(None);
+assert(UserMode.getValue() && "User mode is invalid.");
   }
-  return UserMode;
+  return UserMode.getValue();
 }
 
 AnalyzerOptions::ExplorationStrategyKind
 AnalyzerOptions::getExplorationStrategy() {
-  if (ExplorationStrategy == ExplorationStrategyKind::NotSet) {
-StringRef StratStr =
-Config
-.insert(std::make_pair("exploration_strategy", "unexplored_first_queue"))
-.first->second;
+  if (!ExplorationStrategy.hasValue()) {
+StringRef StratStr = getOptionAsString("exploration_strategy",
+   "unexplored_first_queue");
 ExplorationStrategy =
-llvm::StringSwitch(StratStr)
+llvm::StringSwitch>(StratStr)
 .Case("dfs", ExplorationStrategyKind::DFS)
 .Case("bfs", ExplorationStrategyKind::BFS)
 .Case("unexplored_first",
@@ -81,15 +78,15 @@
   ExplorationStrategyKind::UnexploredFirstLocationQueue)
 .Case("bfs_block_dfs_contents",
   ExplorationStrategyKind::BFSBlockDFSContents)
-.Default(ExplorationStrategyKind::NotSet);
-assert(ExplorationStrategy != ExplorationStrategyKind::NotSet &&
+.Default(None);
+assert(ExplorationStrategy.hasValue() &&
"User mode is invalid.");
   }
-  return ExplorationStrategy;
+  return ExplorationStrategy.getValue();
 }
 
 IPAKind AnalyzerOptions::getIPAMode() {
-  if (IPAMode == IPAK_NotSet) {
+  if (!IPAMode.hasValue()) {
 // Use the User Mode to set the default IPA value.
 // Note, we have to add the string to the Config map for the ConfigDumper
 // checker to function properly.
@@ -102,53 +99,40 @@
 assert(DefaultIPA);
 
 // Lookup the ipa configuration option, use the default from User Mode.
-StringRef ModeStr =
-Config.insert(std::make_pair("ipa", DefaultIPA)).first->second;
-IPAKind IPAConfig = llvm::StringSwitch(ModeStr)
+StringRef ModeStr = getOptionAsString("ipa", DefaultIPA);
+IPAMode = llvm::StringSwitch>(ModeStr)
 .Case("none", IPAK_None)
 .Case("basic-inlining", IPAK_BasicInlining)
 .Case("inlining", IPAK_Inlining)
 .Case("dynamic", IPAK_DynamicDispatch)
 .Case("dynamic-bifurcate", IPAK_DynamicDispatchBifurcate)
-.Default(IPAK_NotSet);
-assert(IPAConfig != IPAK_NotSet && "IPA Mode is invalid.");
-
-// Set the member variable.
-IPAMode = IPAConfig;
+.Default(None);
+assert(IPAMode.hasValue() && "IPA Mode is invalid.");
   }
 
-  return IPAMode;
+  return IPAMode.getValue();
 }
 
 bool
 AnalyzerOptions::mayInlineCXXMemberFunction(CXXInlineableMemberKind K) {
   if (getIPAMode() < IPAK_Inlining)
 return false;
 
   if (!CXXMemberInliningMode) {
-static const char *ModeKey = "c++-inlining";
-
-StringRef ModeStr =
-Config.insert(std::make_

[PATCH] D53276: [analyzer][NFC] Fix some incorrect uses of AnalyzerOptions

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, george.karpenkov, xazax.hun, MTC, rnkovacs.
Herald added subscribers: cfe-commits, donat.nagy, mikhail.ramalho, a.sidorin, 
szepet, whisperity.

I'm in the process of refactoring AnalyzerOptions. The main motivation behind 
here is to emit warnings if an invalid -analyzer-config option is given from 
the command line, and be able to list them all.

In this patch, I found some flags that should've been used as checker options, 
or have absolutely no mention of in `AnalyzerOptions`, or are nonexistent.

- `NonLocalizedStringChecker` now uses its `"AggressiveReport"` flag as a 
checker option
- `lib/StaticAnalyzer/Frontend/ModelInjector.cpp` now accesses the 
`"model-path"` option through a getter in `AnalyzerOptions`
- `-analyzer-config path-diagnostics-alternate=false` is not a thing, I removed 
it.


Repository:
  rC Clang

https://reviews.llvm.org/D53276

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Frontend/ModelInjector.cpp
  test/Analysis/cstring-plist.c
  test/Analysis/localization-aggressive.m


Index: test/Analysis/localization-aggressive.m
===
--- test/Analysis/localization-aggressive.m
+++ test/Analysis/localization-aggressive.m
@@ -1,6 +1,10 @@
 // RUN: %clang_cc1 -fblocks -x objective-c-header -emit-pch -o %t.pch 
%S/Inputs/localization-pch.h
 
-// RUN: %clang_analyze_cc1 -fblocks -analyzer-store=region  
-analyzer-checker=optin.osx.cocoa.localizability.NonLocalizedStringChecker 
-analyzer-checker=optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
 -include-pch %t.pch -verify  -analyzer-config AggressiveReport=true %s
+// RUN: %clang_analyze_cc1 -fblocks -analyzer-store=region \
+// RUN:   -analyzer-config 
optin.osx.cocoa.localizability.NonLocalizedStringChecker:AggressiveReport=true \
+// RUN:   
-analyzer-checker=optin.osx.cocoa.localizability.NonLocalizedStringChecker \
+// RUN:   
-analyzer-checker=optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
 \
+// RUN:   -include-pch %t.pch -verify  %s
 
 // These declarations were reduced using Delta-Debugging from Foundation.h
 // on Mac OS X.
Index: test/Analysis/cstring-plist.c
===
--- test/Analysis/cstring-plist.c
+++ test/Analysis/cstring-plist.c
@@ -1,5 +1,8 @@
 // RUN: rm -f %t
-// RUN: %clang_analyze_cc1 -fblocks 
-analyzer-checker=core,unix.Malloc,unix.cstring.NullArg 
-analyzer-disable-checker=alpha.unix.cstring.OutOfBounds -analyzer-output=plist 
-analyzer-config path-diagnostics-alternate=false -o %t %s
+// RUN: %clang_analyze_cc1 -fblocks \
+// RUN:   -analyzer-checker=core,unix.Malloc,unix.cstring.NullArg \
+// RUN:   -analyzer-disable-checker=alpha.unix.cstring.OutOfBounds \
+// RUN:   -analyzer-output=plist -o %t %s
 // RUN: FileCheck -input-file %t %s
 
 typedef __typeof(sizeof(int)) size_t;
Index: lib/StaticAnalyzer/Frontend/ModelInjector.cpp
===
--- lib/StaticAnalyzer/Frontend/ModelInjector.cpp
+++ lib/StaticAnalyzer/Frontend/ModelInjector.cpp
@@ -48,7 +48,7 @@
   FileID mainFileID = SM.getMainFileID();
 
   AnalyzerOptionsRef analyzerOpts = CI.getAnalyzerOpts();
-  llvm::StringRef modelPath = analyzerOpts->Config["model-path"];
+  llvm::StringRef modelPath = analyzerOpts->getModelPath();
 
   llvm::SmallString<128> fileName;
 
Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -502,3 +502,9 @@
 CTUIndexName = getOptionAsString("ctu-index-name", "externalFnMap.txt");
   return CTUIndexName.getValue();
 }
+
+StringRef AnalyzerOptions::getModelPath() {
+  if (!ModelPath.hasValue())
+ModelPath = getOptionAsString("model-path", "");
+  return ModelPath.getValue();
+}
Index: lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
+++ lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
@@ -1398,7 +1398,8 @@
   NonLocalizedStringChecker *checker =
   mgr.registerChecker();
   checker->IsAggressive =
-  mgr.getAnalyzerOptions().getBooleanOption("AggressiveReport", false);
+  mgr.getAnalyzerOptions().getBooleanOption("AggressiveReport", false,
+checker);
 }
 
 void ento::registerEmptyLocalizationContextChecker(CheckerManager &mgr) {
Index: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===
--- include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -330,6 +33

[PATCH] D53019: [clangd] dump xrefs information in dexp tool.

2018-10-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 169668.
hokein marked 2 inline comments as done.
hokein added a comment.

Address review comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53019

Files:
  clangd/index/dex/dexp/CMakeLists.txt
  clangd/index/dex/dexp/Dexp.cpp

Index: clangd/index/dex/dexp/Dexp.cpp
===
--- clangd/index/dex/dexp/Dexp.cpp
+++ clangd/index/dex/dexp/Dexp.cpp
@@ -12,13 +12,15 @@
 //
 //===--===//
 
-#include "../../Serialization.h"
-#include "../Dex.h"
+#include "Dex.h"
+#include "Serialization.h"
+#include "SourceCode.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/LineEditor/LineEditor.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Signals.h"
 
 using clang::clangd::FuzzyFindRequest;
@@ -52,6 +54,22 @@
   llvm::outs() << llvm::formatv("{0} took {1:ms+n}.\n", Name, Duration);
 }
 
+std::vector
+getSymbolIDsFromIndex(llvm::StringRef QualifiedName, const SymbolIndex *Index) {
+  FuzzyFindRequest Request;
+  Request.Scopes.emplace_back();
+  std::tie(Request.Scopes.back(), Request.Query) =
+  clang::clangd::splitQualifiedName(QualifiedName);
+  std::vector SymIDs;
+  // We choose the first one if there are overloaded symbols.
+  Index->fuzzyFind(Request, [&](const Symbol &Sym) {
+std::string SymQualifiedName = (Sym.Scope + Sym.Name).str();
+if (QualifiedName == SymQualifiedName)
+  SymIDs.push_back(Sym.ID);
+  });
+  return SymIDs;
+}
+
 // REPL commands inherit from Command and contain their options as members.
 // Creating a Command populates parser options, parseAndRun() resets them.
 class Command {
@@ -88,7 +106,6 @@
 };
 
 // FIXME(kbobyrev): Ideas for more commands:
-// * find symbol references: print set of reference locations
 // * load/swap/reload index: this would make it possible to get rid of llvm::cl
 //   usages in the tool driver and actually use llvm::cl library in the REPL.
 // * show posting list density histogram (our dump data somewhere so that user
@@ -139,19 +156,33 @@
   cl::opt ID{
   "id",
   cl::Positional,
-  cl::Required,
   cl::desc("Symbol ID to look up (hex)"),
   };
+  cl::opt Name{
+  "name", cl::desc("Qualified name to look up."),
+  };
 
   void run() override {
-auto SID = clang::clangd::SymbolID::fromStr(ID);
-if (!SID) {
-  llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
+  llvm::outs()
+  << "Missing required argument: please provide id or -name.\n";
   return;
 }
+std::vector IDs;
+if (ID.getNumOccurrences()) {
+  auto SID = clang::clangd::SymbolID::fromStr(ID);
+  if (!SID) {
+llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+return;
+  }
+  IDs.push_back(*SID);
+}
+else {
+  IDs = getSymbolIDsFromIndex(Name, Index);
+}
 
 clang::clangd::LookupRequest Request;
-Request.IDs = {*SID};
+Request.IDs.insert(IDs.begin(), IDs.end());
 bool FoundSymbol = false;
 Index->lookup(Request, [&](const Symbol &Sym) {
   FoundSymbol = true;
@@ -162,13 +193,64 @@
   }
 };
 
+class Refs : public Command {
+  cl::opt ID{
+  "id", cl::Positional,
+  cl::desc("Symbol ID of the symbol being queried (hex)."),
+  };
+  cl::opt Name{
+  "name", cl::desc("Qualified name of the symbol being queried."),
+  };
+  cl::opt Filter{
+  "filter",
+  cl::init(".*"),
+  cl::desc(
+  "Print all results from files matching this regular expression."),
+  };
+
+  void run() override {
+if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
+  llvm::outs()
+  << "Missing required argument: please provide id or -name.\n";
+  return;
+}
+std::vector IDs;
+if (ID.getNumOccurrences()) {
+  auto SID = clang::clangd::SymbolID::fromStr(ID);
+  if (!SID) {
+llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+return;
+  }
+  IDs.push_back(*SID);
+}
+else {
+  IDs = getSymbolIDsFromIndex(Name, Index);
+}
+clang::clangd::RefsRequest RefRequest;
+RefRequest.IDs.insert(IDs.begin(), IDs.end());
+llvm::Regex RegexFilter(Filter);
+Index->refs(RefRequest, [&RegexFilter](const clang::clangd::Ref &R) {
+  auto U = clang::clangd::URI::parse(R.Location.FileURI);
+  if (!U) {
+llvm::outs() << U.takeError();
+return;
+  }
+  if (RegexFilter.match(U->body()))
+llvm::outs() << R << "\n";
+});
+  }
+};
+
 struct {
   const char *Name;
   const char *Description;
   std::function()> Implementation;
 } CommandInfo[] = {
 {"find", "Search for symbols with fuzzyFind", llvm::make_unique},
-{"lookup", "Dump symbol deta

[PATCH] D53277: [analyzer][NFC][WIP] Collect all -analyzer-config options in a .def file

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, george.karpenkov, xazax.hun, rnkovacs, MTC.
Herald added subscribers: cfe-commits, donat.nagy, mikhail.ramalho, a.sidorin, 
szepet, whisperity.

I'm in the process of refactoring AnalyzerOptions. The main motivation behind 
here is to emit warnings if an invalid -analyzer-config option is given from 
the command line, and be able to list them all.

In this patch, I'm moving **//all//** analyzer options to a def file, and move 
2 enums to global namespace.

This patch is WIP, because I didn't add descriptions just yet.


Repository:
  rC Clang

https://reviews.llvm.org/D53277

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp

Index: lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -56,17 +56,17 @@
 static std::unique_ptr generateWorkList(AnalyzerOptions &Opts,
   SubEngine &subengine) {
   switch (Opts.getExplorationStrategy()) {
-case AnalyzerOptions::ExplorationStrategyKind::DFS:
+case ExplorationStrategyKind::DFS:
   return WorkList::makeDFS();
-case AnalyzerOptions::ExplorationStrategyKind::BFS:
+case ExplorationStrategyKind::BFS:
   return WorkList::makeBFS();
-case AnalyzerOptions::ExplorationStrategyKind::BFSBlockDFSContents:
+case ExplorationStrategyKind::BFSBlockDFSContents:
   return WorkList::makeBFSBlockDFSContents();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirst:
+case ExplorationStrategyKind::UnexploredFirst:
   return WorkList::makeUnexploredFirst();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstQueue:
+case ExplorationStrategyKind::UnexploredFirstQueue:
   return WorkList::makeUnexploredFirstPriorityQueue();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstLocationQueue:
+case ExplorationStrategyKind::UnexploredFirstLocationQueue:
   return WorkList::makeUnexploredFirstPriorityLocationQueue();
   }
 }
Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -49,7 +49,7 @@
   return Result;
 }
 
-AnalyzerOptions::UserModeKind AnalyzerOptions::getUserMode() {
+UserModeKind AnalyzerOptions::getUserMode() {
   if (!UserMode.hasValue()) {
 StringRef ModeStr = getOptionAsString("mode", "deep");
 UserMode = llvm::StringSwitch>(ModeStr)
@@ -61,7 +61,7 @@
   return UserMode.getValue();
 }
 
-AnalyzerOptions::ExplorationStrategyKind
+ExplorationStrategyKind
 AnalyzerOptions::getExplorationStrategy() {
   if (!ExplorationStrategy.hasValue()) {
 StringRef StratStr = getOptionAsString("exploration_strategy",
@@ -182,137 +182,6 @@
   return V.getValue();
 }
 
-bool AnalyzerOptions::includeTemporaryDtorsInCFG() {
-  return getBooleanOption(IncludeTemporaryDtorsInCFG,
-  "cfg-temporary-dtors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeImplicitDtorsInCFG() {
-  return getBooleanOption(IncludeImplicitDtorsInCFG,
-  "cfg-implicit-dtors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeLifetimeInCFG() {
-  return getBooleanOption(IncludeLifetimeInCFG, "cfg-lifetime",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::includeLoopExitInCFG() {
-  return getBooleanOption(IncludeLoopExitInCFG, "cfg-loopexit",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::includeRichConstructorsInCFG() {
-  return getBooleanOption(IncludeRichConstructorsInCFG,
-  "cfg-rich-constructors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeScopesInCFG() {
-  return getBooleanOption(IncludeScopesInCFG,
-  "cfg-scopes",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::mayInlineCXXStandardLibrary() {
-  return getBooleanOption(InlineCXXStandardLibrary,
-  "c++-stdlib-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineTemplateFunctions() {
-  return getBooleanOption(InlineTemplateFunctions,
-  "c++-template-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineCXXAllocator() {
-  return getBooleanOption(InlineCXXAllocator,
-  "c++-allocator-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineCXXContainerMethods() {
-  return getBooleanOption(InlineCXXCont

[PATCH] D53273: [clangd] Fix some references missing in dynamic index.

2018-10-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clangd/index/SymbolCollector.cpp:348
 
+  if (!shouldCollectSymbol(*ND, *ASTCtx, Opts))
+return true;

sammccall wrote:
> This seems better for the main-AST case, but substantially more expensive for 
> indexing preambles: we may not want references at all, so paying for 
> shouldCollectSymbol for every reference seems wasteful.
> 
> what about
> ```
> bool RefMayBeInteresting = RefFilter & Roles;
> bool IsOnlyRef = !(Roles & (Declaration | Definition));
> if (IsOnlyRef && !RefMayBeInteresting)
>   return;
> if (!shouldCollectSymbol())
>   return;
> if (RefMayBeInteresting && File == getMainFileID())
>   // add ref
> if (IsOnlyRef) // don't continue if mere reference
>   return;
> ```
> 
I thought `shouldCollectSymbol` is not as expensive as before (since we have 
removed AST matchers stuff there), but I'm definitely +1 on the idea of avoid 
calling it for every reference. 


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53273



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


[PATCH] D53273: [clangd] Fix some references missing in dynamic index.

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

avoid calling shouldCollectSymbol every time during indexing.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53273

Files:
  clangd/index/SymbolCollector.cpp
  unittests/clangd/FileIndexTests.cpp

Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -8,13 +8,15 @@
 //===--===//
 
 #include "Annotations.h"
+#include "AST.h"
 #include "ClangdUnit.h"
 #include "TestFS.h"
 #include "TestTU.h"
 #include "gmock/gmock.h"
 #include "index/FileIndex.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/PCHContainerOperations.h"
+#include "clang/Frontend/Utils.h"
 #include "clang/Index/IndexSymbol.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/CompilationDatabase.h"
@@ -346,6 +348,55 @@
   EXPECT_TRUE(SeenSymbol);
 }
 
+TEST(FileIndexTest, ReferencesInMainFileWithPreamble) {
+  const std::string Header = R"cpp(
+class Foo {};
+  )cpp";
+  Annotations Main(R"cpp(
+#include "foo.h"
+void f() {
+  [[Foo]] foo;
+}
+  )cpp");
+  auto MainFile = testPath("foo.cpp");
+  auto HeaderFile = testPath("foo.h");
+  std::vector Cmd = {"clang", "-xc++", MainFile.c_str()};
+  // Preparse ParseInputs.
+  ParseInputs PI;
+  PI.CompileCommand.Directory = testRoot();
+  PI.CompileCommand.Filename = MainFile;
+  PI.CompileCommand.CommandLine = {Cmd.begin(), Cmd.end()};
+  PI.Contents = Main.code();
+  PI.FS = buildTestFS({{MainFile, Main.code()}, {HeaderFile, Header}});
+
+  // Prepare preamble.
+  auto CI = buildCompilerInvocation(PI);
+  auto PreambleData = buildPreamble(
+  MainFile,
+  *buildCompilerInvocation(PI), /*OldPreamble=*/nullptr,
+  tooling::CompileCommand(), PI,
+  std::make_shared(), /*StoreInMemory=*/true,
+  [&](ASTContext &Ctx, std::shared_ptr PP) {});
+  // Build AST for main file with preamble.
+  auto AST = ParsedAST::build(
+  createInvocationFromCommandLine(Cmd), PreambleData,
+  llvm::MemoryBuffer::getMemBufferCopy(Main.code()),
+  std::make_shared(),
+  PI.FS);
+  ASSERT_TRUE(AST);
+  FileIndex Index;
+  Index.updateMain(MainFile, *AST);
+
+  auto Foo =
+  findSymbol(TestTU::withHeaderCode(Header).headerSymbols(), "Foo");
+  RefsRequest Request;
+  Request.IDs.insert(Foo.ID);
+
+  // Expect to see references in main file, references in headers are excluded
+  // because we only index main AST.
+  EXPECT_THAT(getRefs(Index, Foo.ID), RefsAre({RefRange(Main.range())}));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/index/SymbolCollector.cpp
===
--- clangd/index/SymbolCollector.cpp
+++ clangd/index/SymbolCollector.cpp
@@ -345,16 +345,20 @@
   SM.getFileID(SpellingLoc) == SM.getMainFileID())
 ReferencedDecls.insert(ND);
 
-  if ((static_cast(Opts.RefFilter) & Roles) &&
-  SM.getFileID(SpellingLoc) == SM.getMainFileID())
-DeclRefs[ND].emplace_back(SpellingLoc, Roles);
+  bool CollectRef = static_cast(Opts.RefFilter) & Roles;
+  bool IsOnlyRef =
+  !(Roles & (static_cast(index::SymbolRole::Declaration) |
+ static_cast(index::SymbolRole::Definition)));
 
-  // Don't continue indexing if this is a mere reference.
-  if (!(Roles & static_cast(index::SymbolRole::Declaration) ||
-Roles & static_cast(index::SymbolRole::Definition)))
+  if (IsOnlyRef && !CollectRef)
 return true;
   if (!shouldCollectSymbol(*ND, *ASTCtx, Opts))
 return true;
+  if (CollectRef && SM.getFileID(SpellingLoc) == SM.getMainFileID())
+DeclRefs[ND].emplace_back(SpellingLoc, Roles);
+  // Don't continue indexing if this is a mere reference.
+  if (IsOnlyRef)
+return true;
 
   auto ID = getSymbolID(ND);
   if (!ID)
@@ -476,17 +480,15 @@
 std::string MainURI = *MainFileURI;
 for (const auto &It : DeclRefs) {
   if (auto ID = getSymbolID(It.first)) {
-if (Symbols.find(*ID)) {
-  for (const auto &LocAndRole : It.second) {
-Ref R;
-auto Range =
-getTokenRange(LocAndRole.first, SM, ASTCtx->getLangOpts());
-R.Location.Start = Range.first;
-R.Location.End = Range.second;
-R.Location.FileURI = MainURI;
-R.Kind = toRefKind(LocAndRole.second);
-Refs.insert(*ID, R);
-  }
+for (const auto &LocAndRole : It.second) {
+  Ref R;
+  auto Range =
+  getTokenRange(LocAndRole.first, SM, ASTCtx->getLangOpts());
+  R.Location.Start = Range.first;
+  R.Location.End = Range.second;
+  R.Location.FileURI = MainURI;
+  R.Kind = toRefKind(LocAndRole.second);
+  Refs.insert(*ID, R);

[PATCH] D53019: [clangd] dump xrefs information in dexp tool.

2018-10-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clangd/index/dex/dexp/Dexp.cpp:61
+  Request.Scopes.emplace_back();
+  std::tie(Request.Scopes.back(), Request.Query) =
+  clang::clangd::splitQualifiedName(QualifiedName);

Are you sure you want both `foo` to mean `::foo` only, rather than accept any 
scope and the user can type `::foo` for explicitly global scope?



Comment at: clangd/index/dex/dexp/Dexp.cpp:64
+  std::vector SymIDs;
+  // We choose the first one if there are overloaded symbols.
+  Index->fuzzyFind(Request, [&](const Symbol &Sym) {

stale comment



Comment at: clangd/index/dex/dexp/Dexp.cpp:180
+}
+else {
+  IDs = getSymbolIDsFromIndex(Name, Index);

clang-format



Comment at: clangd/index/dex/dexp/Dexp.cpp:185
 clang::clangd::LookupRequest Request;
-Request.IDs = {*SID};
+Request.IDs.insert(IDs.begin(), IDs.end());
 bool FoundSymbol = false;

(nit: why not just initialize in place above?)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53019



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


[PATCH] D50616: [Fixed Point Arithmetic] FixedPointCast

2018-10-15 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: lib/CodeGen/CGExprScalar.cpp:1019
+  assert(!SrcType->isFixedPointType() && !DstType->isFixedPointType() &&
+ "Use the TargetCodeGenInfo::emitFixedPoint family functions for "
+ "handling conversions involving fixed point types.");

It's not in TargetCodeGenInfo any more.


Repository:
  rC Clang

https://reviews.llvm.org/D50616



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


[PATCH] D50250: [clang][ubsan] Implicit Conversion Sanitizer - integer sign change - clang part

2018-10-15 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Ping.
The prerequisite "split truncation sanitizer into unsigned and signed cases" 
has landed.
I believe i have replied/addressed all the points previously raised here.
Would be awesome to get this going at long last :)


Repository:
  rC Clang

https://reviews.llvm.org/D50250



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


[PATCH] D53277: [analyzer][NFC][WIP] Collect all -analyzer-config options in a .def file

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.

Also, this patch does not contain checker options. That I would suspect be a 
little more invasive, so I'll do that in a followup patch.


Repository:
  rC Clang

https://reviews.llvm.org/D53277



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


r344504 - [TI removal] Make `getTerminator()` return a generic `Instruction`.

2018-10-15 Thread Chandler Carruth via cfe-commits
Author: chandlerc
Date: Mon Oct 15 03:42:50 2018
New Revision: 344504

URL: http://llvm.org/viewvc/llvm-project?rev=344504&view=rev
Log:
[TI removal] Make `getTerminator()` return a generic `Instruction`.

This removes the primary remaining API producing `TerminatorInst` which
will reduce the rate at which code is introduced trying to use it and
generally make it much easier to remove the remaining APIs across the
codebase.

Also clean up some of the stragglers that the previous mechanical update
of variables missed.

Users of LLVM and out-of-tree code generally will need to update any
explicit variable types to handle this. Replacing `TerminatorInst` with
`Instruction` (or `auto`) almost always works. Most of these edits were
made in prior commits using the perl one-liner:
```
perl -i -ple 's/TerminatorInst(\b.* = .*getTerminator\(\))/Instruction\1/g'
```

This also my break some rare use cases where people overload for both
`Instruction` and `TerminatorInst`, but these should be easily fixed by
removing the `TerminatorInst` overload.

Modified:
cfe/trunk/lib/CodeGen/CGCleanup.cpp
cfe/trunk/lib/CodeGen/CGException.cpp

Modified: cfe/trunk/lib/CodeGen/CGCleanup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCleanup.cpp?rev=344504&r1=344503&r2=344504&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCleanup.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCleanup.cpp Mon Oct 15 03:42:50 2018
@@ -366,7 +366,7 @@ static llvm::SwitchInst *TransitionToCle
llvm::BasicBlock *Block) {
   // If it's a branch, turn it into a switch whose default
   // destination is its original target.
-  llvm::TerminatorInst *Term = Block->getTerminator();
+  llvm::Instruction *Term = Block->getTerminator();
   assert(Term && "can't transition block without terminator");
 
   if (llvm::BranchInst *Br = dyn_cast(Term)) {
@@ -589,7 +589,7 @@ static void ForwardPrebranchedFallthroug
   llvm::BasicBlock *To) {
   // Exit is the exit block of a cleanup, so it always terminates in
   // an unconditional branch or a switch.
-  llvm::TerminatorInst *Term = Exit->getTerminator();
+  llvm::Instruction *Term = Exit->getTerminator();
 
   if (llvm::BranchInst *Br = dyn_cast(Term)) {
 assert(Br->isUnconditional() && Br->getSuccessor(0) == From);

Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=344504&r1=344503&r2=344504&view=diff
==
--- cfe/trunk/lib/CodeGen/CGException.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGException.cpp Mon Oct 15 03:42:50 2018
@@ -1248,7 +1248,7 @@ void CodeGenFunction::ExitCXXTryStmt(con
 // we follow the false destination for each of the cond branches to reach
 // the rethrow block.
 llvm::BasicBlock *RethrowBlock = WasmCatchStartBlock;
-while (llvm::TerminatorInst *TI = RethrowBlock->getTerminator()) {
+while (llvm::Instruction *TI = RethrowBlock->getTerminator()) {
   auto *BI = cast(TI);
   assert(BI->isConditional());
   RethrowBlock = BI->getSuccessor(1);


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


[PATCH] D53280: [analyzer] Emit a warning for unknown -analyzer-config options

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, george.karpenkov, xazax.hun, rnkovacs, MTC.
Herald added subscribers: cfe-commits, donat.nagy, mikhail.ramalho, a.sidorin, 
szepet, whisperity.

I'm in the process of refactoring AnalyzerOptions. The main motivation behind 
here is to emit warnings if an invalid -analyzer-config option is given from 
the command line, and be able to list them all.

In this patch, I'll implement the warning.


Repository:
  rC Clang

https://reviews.llvm.org/D53280

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/Frontend/CompilerInvocation.cpp


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -314,6 +314,8 @@
   Opts.CheckersControlList.emplace_back(checker, enable);
   }
 
+  std::vector RegisteredOptions = Opts.getConfigOptionList();
+
   // Go through the analyzer configuration options.
   for (const auto *A : Args.filtered(OPT_analyzer_config)) {
 A->claim();
@@ -338,6 +340,13 @@
 Success = false;
 break;
   }
+  // Check whether this really is a valid -analyzer-condfig option.
+  // TODO: We should check whether all options are valid or not, but for
+  // now, skip checker options.
+  if (key.count(':') == 0) {
+if (llvm::find(RegisteredOptions, key) == RegisteredOptions.end())
+  Diags.Report(diag::warn_analyzer_config_unknown_config) << key;
+  }
   Opts.Config[key] = val;
 }
   }
Index: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===
--- include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -320,6 +320,15 @@
   template 
   T getDefaultValForUserMode(T ShallowVal, T DeepVal);
 
+  std::vector getConfigOptionList() const {
+return {
+#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \
+  CMDFLAG,
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
+#undef ANALYZER_OPTION
+};
+  }
+
 #define ANALYZER_OPTION_WITH_FN(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL, \
 CREATE_FN)  \
   TYPE CREATE_FN();
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -291,6 +291,9 @@
   "analyzer-config option '%0' has a key but no value">;
 def err_analyzer_config_multiple_values : Error<
   "analyzer-config option '%0' should contain only one '='">;
+def warn_analyzer_config_unknown_config : Warning<
+  "unkown -analyzer-config option '%0'">,
+  InGroup;
 
 def err_drv_invalid_hvx_length : Error<
   "-mhvx-length is not supported without a -mhvx/-mhvx= flag">;


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -314,6 +314,8 @@
   Opts.CheckersControlList.emplace_back(checker, enable);
   }
 
+  std::vector RegisteredOptions = Opts.getConfigOptionList();
+
   // Go through the analyzer configuration options.
   for (const auto *A : Args.filtered(OPT_analyzer_config)) {
 A->claim();
@@ -338,6 +340,13 @@
 Success = false;
 break;
   }
+  // Check whether this really is a valid -analyzer-condfig option.
+  // TODO: We should check whether all options are valid or not, but for
+  // now, skip checker options.
+  if (key.count(':') == 0) {
+if (llvm::find(RegisteredOptions, key) == RegisteredOptions.end())
+  Diags.Report(diag::warn_analyzer_config_unknown_config) << key;
+  }
   Opts.Config[key] = val;
 }
   }
Index: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===
--- include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -320,6 +320,15 @@
   template 
   T getDefaultValForUserMode(T ShallowVal, T DeepVal);
 
+  std::vector getConfigOptionList() const {
+return {
+#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL) \
+  CMDFLAG,
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
+#undef ANALYZER_OPTION
+};
+  }
+
 #define ANALYZER_OPTION_WITH_FN(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL, \
 CREATE_FN)  \
   TYPE CREATE_FN();
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -291,6 +291,9 @@
   "analyzer-config option '%0' has a

[PATCH] D53280: [analyzer] Emit a warning for unknown -analyzer-config options

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.

@whisperity @xazax.hun A worry of mine is shared libraries, for example, we've 
got an array of Ericsson-specific checkers that we load run-time. Do we support 
(or should we) support acquiring non-checker `-analyzer-config` options?


Repository:
  rC Clang

https://reviews.llvm.org/D53280



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


[PATCH] D51633: [ASTImporter] Added error handling for AST import.

2018-10-15 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 9 inline comments as done.
balazske added inline comments.



Comment at: lib/AST/ASTImporter.cpp:2683
+continue;
+  } else if (isa(Found))
+continue;

a_sidorin wrote:
> Same here.
I do not know exactly why this was made, it looks like a bugfix for a problem 
encountered during the tests. Maybe I can undo this change (there are other 
related problem fixes so this is probably not needed).



Comment at: lib/AST/ASTImporter.cpp:4604
+  if (Error Err = ImportDeclContext(D))
+// FIXME: Really ignore the error?
+consumeError(std::move(Err));

a_sidorin wrote:
> I think we can just `return std::move(Err);` as it was done below.
Changed to return the error.



Comment at: lib/AST/ASTImporter.cpp:5657
+  if (!ToSemiLocOrErr)
+return nullptr;
+  return new (Importer.getToContext()) NullStmt(

a_sidorin wrote:
> Shouldn't we return an error here?
Good catch, this looks like the change was missed.


Repository:
  rC Clang

https://reviews.llvm.org/D51633



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


[clang-tools-extra] r344507 - [clangd] Fix some references missing in dynamic index.

2018-10-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Oct 15 04:46:26 2018
New Revision: 344507

URL: http://llvm.org/viewvc/llvm-project?rev=344507&view=rev
Log:
[clangd] Fix some references missing in dynamic index.

Summary:
Previously, SymbolCollector postfilters all references at the end to
find all references of interesting symbols.
It was incorrect when indxing main AST where we don't see locations
of symbol declarations and definitions in the main AST (as those are in
preamble AST).

The fix is to do earily check during collecting references.

Reviewers: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.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=344507&r1=344506&r2=344507&view=diff
==
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp Mon Oct 15 
04:46:26 2018
@@ -345,16 +345,20 @@ bool SymbolCollector::handleDeclOccurenc
   SM.getFileID(SpellingLoc) == SM.getMainFileID())
 ReferencedDecls.insert(ND);
 
-  if ((static_cast(Opts.RefFilter) & Roles) &&
-  SM.getFileID(SpellingLoc) == SM.getMainFileID())
-DeclRefs[ND].emplace_back(SpellingLoc, Roles);
+  bool CollectRef = static_cast(Opts.RefFilter) & Roles;
+  bool IsOnlyRef =
+  !(Roles & (static_cast(index::SymbolRole::Declaration) |
+ static_cast(index::SymbolRole::Definition)));
 
-  // Don't continue indexing if this is a mere reference.
-  if (!(Roles & static_cast(index::SymbolRole::Declaration) ||
-Roles & static_cast(index::SymbolRole::Definition)))
+  if (IsOnlyRef && !CollectRef)
 return true;
   if (!shouldCollectSymbol(*ND, *ASTCtx, Opts))
 return true;
+  if (CollectRef && SM.getFileID(SpellingLoc) == SM.getMainFileID())
+DeclRefs[ND].emplace_back(SpellingLoc, Roles);
+  // Don't continue indexing if this is a mere reference.
+  if (IsOnlyRef)
+return true;
 
   auto ID = getSymbolID(ND);
   if (!ID)
@@ -476,17 +480,15 @@ void SymbolCollector::finish() {
 std::string MainURI = *MainFileURI;
 for (const auto &It : DeclRefs) {
   if (auto ID = getSymbolID(It.first)) {
-if (Symbols.find(*ID)) {
-  for (const auto &LocAndRole : It.second) {
-Ref R;
-auto Range =
-getTokenRange(LocAndRole.first, SM, ASTCtx->getLangOpts());
-R.Location.Start = Range.first;
-R.Location.End = Range.second;
-R.Location.FileURI = MainURI;
-R.Kind = toRefKind(LocAndRole.second);
-Refs.insert(*ID, R);
-  }
+for (const auto &LocAndRole : It.second) {
+  Ref R;
+  auto Range =
+  getTokenRange(LocAndRole.first, SM, ASTCtx->getLangOpts());
+  R.Location.Start = Range.first;
+  R.Location.End = Range.second;
+  R.Location.FileURI = MainURI;
+  R.Kind = toRefKind(LocAndRole.second);
+  Refs.insert(*ID, R);
 }
   }
 }

Modified: clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp?rev=344507&r1=344506&r2=344507&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp Mon Oct 15 
04:46:26 2018
@@ -8,6 +8,7 @@
 
//===--===//
 
 #include "Annotations.h"
+#include "AST.h"
 #include "ClangdUnit.h"
 #include "TestFS.h"
 #include "TestTU.h"
@@ -15,6 +16,7 @@
 #include "index/FileIndex.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/PCHContainerOperations.h"
+#include "clang/Frontend/Utils.h"
 #include "clang/Index/IndexSymbol.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/CompilationDatabase.h"
@@ -346,6 +348,55 @@ TEST(FileIndexTest, CollectMacros) {
   EXPECT_TRUE(SeenSymbol);
 }
 
+TEST(FileIndexTest, ReferencesInMainFileWithPreamble) {
+  const std::string Header = R"cpp(
+class Foo {};
+  )cpp";
+  Annotations Main(R"cpp(
+#include "foo.h"
+void f() {
+  [[Foo]] foo;
+}
+  )cpp");
+  auto MainFile = testPath("foo.cpp");
+  auto HeaderFile = testPath("foo.h");
+  std::vector Cmd = {"clang", "-xc++", MainFile.c_str()};
+  // Preparse ParseInputs.
+  ParseInputs PI;
+  PI.CompileCommand.Directory = testRoot();
+  PI.CompileCommand.Filename = MainFile;
+  PI.CompileCommand.CommandLine = {Cmd.begin(),

[PATCH] D53273: [clangd] Fix some references missing in dynamic index.

2018-10-15 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL344507: [clangd] Fix some references missing in dynamic 
index. (authored by hokein, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D53273

Files:
  clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
  clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp

Index: clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
@@ -8,13 +8,15 @@
 //===--===//
 
 #include "Annotations.h"
+#include "AST.h"
 #include "ClangdUnit.h"
 #include "TestFS.h"
 #include "TestTU.h"
 #include "gmock/gmock.h"
 #include "index/FileIndex.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/PCHContainerOperations.h"
+#include "clang/Frontend/Utils.h"
 #include "clang/Index/IndexSymbol.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/CompilationDatabase.h"
@@ -346,6 +348,55 @@
   EXPECT_TRUE(SeenSymbol);
 }
 
+TEST(FileIndexTest, ReferencesInMainFileWithPreamble) {
+  const std::string Header = R"cpp(
+class Foo {};
+  )cpp";
+  Annotations Main(R"cpp(
+#include "foo.h"
+void f() {
+  [[Foo]] foo;
+}
+  )cpp");
+  auto MainFile = testPath("foo.cpp");
+  auto HeaderFile = testPath("foo.h");
+  std::vector Cmd = {"clang", "-xc++", MainFile.c_str()};
+  // Preparse ParseInputs.
+  ParseInputs PI;
+  PI.CompileCommand.Directory = testRoot();
+  PI.CompileCommand.Filename = MainFile;
+  PI.CompileCommand.CommandLine = {Cmd.begin(), Cmd.end()};
+  PI.Contents = Main.code();
+  PI.FS = buildTestFS({{MainFile, Main.code()}, {HeaderFile, Header}});
+
+  // Prepare preamble.
+  auto CI = buildCompilerInvocation(PI);
+  auto PreambleData = buildPreamble(
+  MainFile,
+  *buildCompilerInvocation(PI), /*OldPreamble=*/nullptr,
+  tooling::CompileCommand(), PI,
+  std::make_shared(), /*StoreInMemory=*/true,
+  [&](ASTContext &Ctx, std::shared_ptr PP) {});
+  // Build AST for main file with preamble.
+  auto AST = ParsedAST::build(
+  createInvocationFromCommandLine(Cmd), PreambleData,
+  llvm::MemoryBuffer::getMemBufferCopy(Main.code()),
+  std::make_shared(),
+  PI.FS);
+  ASSERT_TRUE(AST);
+  FileIndex Index;
+  Index.updateMain(MainFile, *AST);
+
+  auto Foo =
+  findSymbol(TestTU::withHeaderCode(Header).headerSymbols(), "Foo");
+  RefsRequest Request;
+  Request.IDs.insert(Foo.ID);
+
+  // Expect to see references in main file, references in headers are excluded
+  // because we only index main AST.
+  EXPECT_THAT(getRefs(Index, Foo.ID), RefsAre({RefRange(Main.range())}));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
===
--- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
+++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp
@@ -345,16 +345,20 @@
   SM.getFileID(SpellingLoc) == SM.getMainFileID())
 ReferencedDecls.insert(ND);
 
-  if ((static_cast(Opts.RefFilter) & Roles) &&
-  SM.getFileID(SpellingLoc) == SM.getMainFileID())
-DeclRefs[ND].emplace_back(SpellingLoc, Roles);
+  bool CollectRef = static_cast(Opts.RefFilter) & Roles;
+  bool IsOnlyRef =
+  !(Roles & (static_cast(index::SymbolRole::Declaration) |
+ static_cast(index::SymbolRole::Definition)));
 
-  // Don't continue indexing if this is a mere reference.
-  if (!(Roles & static_cast(index::SymbolRole::Declaration) ||
-Roles & static_cast(index::SymbolRole::Definition)))
+  if (IsOnlyRef && !CollectRef)
 return true;
   if (!shouldCollectSymbol(*ND, *ASTCtx, Opts))
 return true;
+  if (CollectRef && SM.getFileID(SpellingLoc) == SM.getMainFileID())
+DeclRefs[ND].emplace_back(SpellingLoc, Roles);
+  // Don't continue indexing if this is a mere reference.
+  if (IsOnlyRef)
+return true;
 
   auto ID = getSymbolID(ND);
   if (!ID)
@@ -476,17 +480,15 @@
 std::string MainURI = *MainFileURI;
 for (const auto &It : DeclRefs) {
   if (auto ID = getSymbolID(It.first)) {
-if (Symbols.find(*ID)) {
-  for (const auto &LocAndRole : It.second) {
-Ref R;
-auto Range =
-getTokenRange(LocAndRole.first, SM, ASTCtx->getLangOpts());
-R.Location.Start = Range.first;
-R.Location.End = Range.second;
-R.Location.FileURI = MainURI;
-R.Kind = toRefKind(LocAndRole.second);
-Refs.insert(*ID, R);
-  }
+for (const auto &LocAndRole : It.second) {
+  Ref R;
+  auto Range =
+  getTokenRange(LocAndRole.first

[PATCH] D53284: [CodeComplete] Make sure keyword 'template' is added even when code pattern is disabled.

2018-10-15 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added reviewers: sammccall, hokein.
Herald added subscribers: cfe-commits, arphaman.

Repository:
  rC Clang

https://reviews.llvm.org/D53284

Files:
  lib/Sema/SemaCodeComplete.cpp
  test/Index/complete-template-keywords.cpp


Index: test/Index/complete-template-keywords.cpp
===
--- /dev/null
+++ test/Index/complete-template-keywords.cpp
@@ -0,0 +1,5 @@
+templ
+// RUN: env c-index-test -code-completion-at=%s:1:5 %s | FileCheck 
-check-prefix=CHECK-NO-PATTERN %s
+// CHECK-NO-PATTERN: {TypedText template} (1)
+// RUN: env CINDEXTEST_CODE_COMPLETE_PATTERNS=1 c-index-test 
-code-completion-at=%s:1:5 %s | FileCheck -check-prefix=CHECK-PATTERN %s
+// CHECK-PATTERN: {TypedText template}{LeftAngle <}
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -1731,6 +1731,8 @@
 Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
 Builder.AddPlaceholderChunk("declaration");
 Results.AddResult(Result(Builder.TakeString()));
+  } else {
+Results.AddResult(Result("template", 
CodeCompletionResult::RK_Keyword));
   }
 }
 
@@ -1805,6 +1807,8 @@
   Builder.AddPlaceholderChunk("parameters");
   Builder.AddChunk(CodeCompletionString::CK_RightAngle);
   Results.AddResult(Result(Builder.TakeString()));
+} else {
+  Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword));
 }
 
 AddStorageSpecifiers(CCC, SemaRef.getLangOpts(), Results);


Index: test/Index/complete-template-keywords.cpp
===
--- /dev/null
+++ test/Index/complete-template-keywords.cpp
@@ -0,0 +1,5 @@
+templ
+// RUN: env c-index-test -code-completion-at=%s:1:5 %s | FileCheck -check-prefix=CHECK-NO-PATTERN %s
+// CHECK-NO-PATTERN: {TypedText template} (1)
+// RUN: env CINDEXTEST_CODE_COMPLETE_PATTERNS=1 c-index-test -code-completion-at=%s:1:5 %s | FileCheck -check-prefix=CHECK-PATTERN %s
+// CHECK-PATTERN: {TypedText template}{LeftAngle <}
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -1731,6 +1731,8 @@
 Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
 Builder.AddPlaceholderChunk("declaration");
 Results.AddResult(Result(Builder.TakeString()));
+  } else {
+Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword));
   }
 }
 
@@ -1805,6 +1807,8 @@
   Builder.AddPlaceholderChunk("parameters");
   Builder.AddChunk(CodeCompletionString::CK_RightAngle);
   Results.AddResult(Result(Builder.TakeString()));
+} else {
+  Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword));
 }
 
 AddStorageSpecifiers(CCC, SemaRef.getLangOpts(), Results);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53019: [clangd] dump xrefs information in dexp tool.

2018-10-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 169683.
hokein marked 3 inline comments as done.
hokein added a comment.

Fix global scope, and clang-format.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53019

Files:
  clangd/index/dex/dexp/CMakeLists.txt
  clangd/index/dex/dexp/Dexp.cpp

Index: clangd/index/dex/dexp/Dexp.cpp
===
--- clangd/index/dex/dexp/Dexp.cpp
+++ clangd/index/dex/dexp/Dexp.cpp
@@ -12,8 +12,9 @@
 //
 //===--===//
 
-#include "../../Serialization.h"
-#include "../Dex.h"
+#include "Dex.h"
+#include "Serialization.h"
+#include "SourceCode.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -52,6 +53,26 @@
   llvm::outs() << llvm::formatv("{0} took {1:ms+n}.\n", Name, Duration);
 }
 
+std::vector
+getSymbolIDsFromIndex(llvm::StringRef QualifiedName, const SymbolIndex *Index) {
+  FuzzyFindRequest Request;
+  // Remove leading "::" qualifier as FuzzyFind doesn't need leading "::"
+  // qualifier for global scope.
+  bool IsGlobalScope = QualifiedName.consume_front("::");
+  auto Names = clang::clangd::splitQualifiedName(QualifiedName);
+  if (IsGlobalScope || !Names.first.empty())
+Request.Scopes = {Names.first};
+
+  Request.Query = Names.second;
+  std::vector SymIDs;
+  Index->fuzzyFind(Request, [&](const Symbol &Sym) {
+std::string SymQualifiedName = (Sym.Scope + Sym.Name).str();
+if (QualifiedName == SymQualifiedName)
+  SymIDs.push_back(Sym.ID);
+  });
+  return SymIDs;
+}
+
 // REPL commands inherit from Command and contain their options as members.
 // Creating a Command populates parser options, parseAndRun() resets them.
 class Command {
@@ -88,7 +109,6 @@
 };
 
 // FIXME(kbobyrev): Ideas for more commands:
-// * find symbol references: print set of reference locations
 // * load/swap/reload index: this would make it possible to get rid of llvm::cl
 //   usages in the tool driver and actually use llvm::cl library in the REPL.
 // * show posting list density histogram (our dump data somewhere so that user
@@ -139,19 +159,32 @@
   cl::opt ID{
   "id",
   cl::Positional,
-  cl::Required,
   cl::desc("Symbol ID to look up (hex)"),
   };
+  cl::opt Name{
+  "name", cl::desc("Qualified name to look up."),
+  };
 
   void run() override {
-auto SID = clang::clangd::SymbolID::fromStr(ID);
-if (!SID) {
-  llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
+  llvm::outs()
+  << "Missing required argument: please provide id or -name.\n";
   return;
 }
+std::vector IDs;
+if (ID.getNumOccurrences()) {
+  auto SID = clang::clangd::SymbolID::fromStr(ID);
+  if (!SID) {
+llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+return;
+  }
+  IDs.push_back(*SID);
+} else {
+  IDs = getSymbolIDsFromIndex(Name, Index);
+}
 
 clang::clangd::LookupRequest Request;
-Request.IDs = {*SID};
+Request.IDs.insert(IDs.begin(), IDs.end());
 bool FoundSymbol = false;
 Index->lookup(Request, [&](const Symbol &Sym) {
   FoundSymbol = true;
@@ -162,13 +195,62 @@
   }
 };
 
+class Refs : public Command {
+  cl::opt ID{
+  "id", cl::Positional,
+  cl::desc("Symbol ID of the symbol being queried (hex)."),
+  };
+  cl::opt Name{
+  "name", cl::desc("Qualified name of the symbol being queried."),
+  };
+  cl::opt Filter{
+  "filter", cl::init(".*"),
+  cl::desc(
+  "Print all results from files matching this regular expression."),
+  };
+
+  void run() override {
+if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
+  llvm::outs()
+  << "Missing required argument: please provide id or -name.\n";
+  return;
+}
+std::vector IDs;
+if (ID.getNumOccurrences()) {
+  auto SID = clang::clangd::SymbolID::fromStr(ID);
+  if (!SID) {
+llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+return;
+  }
+  IDs.push_back(*SID);
+} else {
+  IDs = getSymbolIDsFromIndex(Name, Index);
+}
+clang::clangd::RefsRequest RefRequest;
+RefRequest.IDs.insert(IDs.begin(), IDs.end());
+llvm::Regex RegexFilter(Filter);
+Index->refs(RefRequest, [&RegexFilter](const clang::clangd::Ref &R) {
+  auto U = clang::clangd::URI::parse(R.Location.FileURI);
+  if (!U) {
+llvm::outs() << U.takeError();
+return;
+  }
+  if (RegexFilter.match(U->body()))
+llvm::outs() << R << "\n";
+});
+  }
+};
+
 struct {
   const char *Name;
   const char *Description;
   std::function()> Implementation;
 } CommandInfo[] = {
 {"find", "Search for symbols with fuzzyFind", llvm::make_unique},
-{"lookup", "Dump symbol details by ID", llvm::make_unique},
+{"lookup", "Dum

[PATCH] D53019: [clangd] dump xrefs information in dexp tool.

2018-10-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clangd/index/dex/dexp/Dexp.cpp:61
+  Request.Scopes.emplace_back();
+  std::tie(Request.Scopes.back(), Request.Query) =
+  clang::clangd::splitQualifiedName(QualifiedName);

sammccall wrote:
> Are you sure you want both `foo` to mean `::foo` only, rather than accept any 
> scope and the user can type `::foo` for explicitly global scope?
Oops, this is not intended. "foo" and "::foo" are different.



Comment at: clangd/index/dex/dexp/Dexp.cpp:185
 clang::clangd::LookupRequest Request;
-Request.IDs = {*SID};
+Request.IDs.insert(IDs.begin(), IDs.end());
 bool FoundSymbol = false;

sammccall wrote:
> (nit: why not just initialize in place above?)
In fact, Request.IDs and IDs are different types, and DenseSet is missing such 
constructor :(


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53019



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


[clang-tools-extra] r344508 - [clangd] dump xrefs information in dexp tool.

2018-10-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Oct 15 05:32:49 2018
New Revision: 344508

URL: http://llvm.org/viewvc/llvm-project?rev=344508&view=rev
Log:
[clangd] dump xrefs information in dexp tool.

Reviewers: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt
clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp

Modified: clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt?rev=344508&r1=344507&r2=344508&view=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt Mon Oct 15 
05:32:49 2018
@@ -1,3 +1,5 @@
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../..)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../)
 
 set(LLVM_LINK_COMPONENTS

Modified: clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp?rev=344508&r1=344507&r2=344508&view=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp Mon Oct 15 05:32:49 
2018
@@ -12,8 +12,9 @@
 //
 
//===--===//
 
-#include "../../Serialization.h"
-#include "../Dex.h"
+#include "Dex.h"
+#include "Serialization.h"
+#include "SourceCode.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -52,6 +53,26 @@ void reportTime(StringRef Name, llvm::fu
   llvm::outs() << llvm::formatv("{0} took {1:ms+n}.\n", Name, Duration);
 }
 
+std::vector
+getSymbolIDsFromIndex(llvm::StringRef QualifiedName, const SymbolIndex *Index) 
{
+  FuzzyFindRequest Request;
+  // Remove leading "::" qualifier as FuzzyFind doesn't need leading "::"
+  // qualifier for global scope.
+  bool IsGlobalScope = QualifiedName.consume_front("::");
+  auto Names = clang::clangd::splitQualifiedName(QualifiedName);
+  if (IsGlobalScope || !Names.first.empty())
+Request.Scopes = {Names.first};
+
+  Request.Query = Names.second;
+  std::vector SymIDs;
+  Index->fuzzyFind(Request, [&](const Symbol &Sym) {
+std::string SymQualifiedName = (Sym.Scope + Sym.Name).str();
+if (QualifiedName == SymQualifiedName)
+  SymIDs.push_back(Sym.ID);
+  });
+  return SymIDs;
+}
+
 // REPL commands inherit from Command and contain their options as members.
 // Creating a Command populates parser options, parseAndRun() resets them.
 class Command {
@@ -88,7 +109,6 @@ public:
 };
 
 // FIXME(kbobyrev): Ideas for more commands:
-// * find symbol references: print set of reference locations
 // * load/swap/reload index: this would make it possible to get rid of llvm::cl
 //   usages in the tool driver and actually use llvm::cl library in the REPL.
 // * show posting list density histogram (our dump data somewhere so that user
@@ -139,19 +159,32 @@ class Lookup : public Command {
   cl::opt ID{
   "id",
   cl::Positional,
-  cl::Required,
   cl::desc("Symbol ID to look up (hex)"),
   };
+  cl::opt Name{
+  "name", cl::desc("Qualified name to look up."),
+  };
 
   void run() override {
-auto SID = clang::clangd::SymbolID::fromStr(ID);
-if (!SID) {
-  llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
+  llvm::outs()
+  << "Missing required argument: please provide id or -name.\n";
   return;
 }
+std::vector IDs;
+if (ID.getNumOccurrences()) {
+  auto SID = clang::clangd::SymbolID::fromStr(ID);
+  if (!SID) {
+llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+return;
+  }
+  IDs.push_back(*SID);
+} else {
+  IDs = getSymbolIDsFromIndex(Name, Index);
+}
 
 clang::clangd::LookupRequest Request;
-Request.IDs = {*SID};
+Request.IDs.insert(IDs.begin(), IDs.end());
 bool FoundSymbol = false;
 Index->lookup(Request, [&](const Symbol &Sym) {
   FoundSymbol = true;
@@ -162,13 +195,62 @@ class Lookup : public Command {
   }
 };
 
+class Refs : public Command {
+  cl::opt ID{
+  "id", cl::Positional,
+  cl::desc("Symbol ID of the symbol being queried (hex)."),
+  };
+  cl::opt Name{
+  "name", cl::desc("Qualified name of the symbol being queried."),
+  };
+  cl::opt Filter{
+  "filter", cl::init(".*"),
+  cl::desc(
+  "Print all results from files matching this regular expression."),
+  };
+
+  void run() override {
+ 

[PATCH] D53019: [clangd] dump xrefs information in dexp tool.

2018-10-15 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE344508: [clangd] dump xrefs information in dexp tool. 
(authored by hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53019?vs=169683&id=169684#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53019

Files:
  clangd/index/dex/dexp/CMakeLists.txt
  clangd/index/dex/dexp/Dexp.cpp

Index: clangd/index/dex/dexp/Dexp.cpp
===
--- clangd/index/dex/dexp/Dexp.cpp
+++ clangd/index/dex/dexp/Dexp.cpp
@@ -12,8 +12,9 @@
 //
 //===--===//
 
-#include "../../Serialization.h"
-#include "../Dex.h"
+#include "Dex.h"
+#include "Serialization.h"
+#include "SourceCode.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -52,6 +53,26 @@
   llvm::outs() << llvm::formatv("{0} took {1:ms+n}.\n", Name, Duration);
 }
 
+std::vector
+getSymbolIDsFromIndex(llvm::StringRef QualifiedName, const SymbolIndex *Index) {
+  FuzzyFindRequest Request;
+  // Remove leading "::" qualifier as FuzzyFind doesn't need leading "::"
+  // qualifier for global scope.
+  bool IsGlobalScope = QualifiedName.consume_front("::");
+  auto Names = clang::clangd::splitQualifiedName(QualifiedName);
+  if (IsGlobalScope || !Names.first.empty())
+Request.Scopes = {Names.first};
+
+  Request.Query = Names.second;
+  std::vector SymIDs;
+  Index->fuzzyFind(Request, [&](const Symbol &Sym) {
+std::string SymQualifiedName = (Sym.Scope + Sym.Name).str();
+if (QualifiedName == SymQualifiedName)
+  SymIDs.push_back(Sym.ID);
+  });
+  return SymIDs;
+}
+
 // REPL commands inherit from Command and contain their options as members.
 // Creating a Command populates parser options, parseAndRun() resets them.
 class Command {
@@ -88,7 +109,6 @@
 };
 
 // FIXME(kbobyrev): Ideas for more commands:
-// * find symbol references: print set of reference locations
 // * load/swap/reload index: this would make it possible to get rid of llvm::cl
 //   usages in the tool driver and actually use llvm::cl library in the REPL.
 // * show posting list density histogram (our dump data somewhere so that user
@@ -139,19 +159,32 @@
   cl::opt ID{
   "id",
   cl::Positional,
-  cl::Required,
   cl::desc("Symbol ID to look up (hex)"),
   };
+  cl::opt Name{
+  "name", cl::desc("Qualified name to look up."),
+  };
 
   void run() override {
-auto SID = clang::clangd::SymbolID::fromStr(ID);
-if (!SID) {
-  llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
+  llvm::outs()
+  << "Missing required argument: please provide id or -name.\n";
   return;
 }
+std::vector IDs;
+if (ID.getNumOccurrences()) {
+  auto SID = clang::clangd::SymbolID::fromStr(ID);
+  if (!SID) {
+llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+return;
+  }
+  IDs.push_back(*SID);
+} else {
+  IDs = getSymbolIDsFromIndex(Name, Index);
+}
 
 clang::clangd::LookupRequest Request;
-Request.IDs = {*SID};
+Request.IDs.insert(IDs.begin(), IDs.end());
 bool FoundSymbol = false;
 Index->lookup(Request, [&](const Symbol &Sym) {
   FoundSymbol = true;
@@ -162,13 +195,62 @@
   }
 };
 
+class Refs : public Command {
+  cl::opt ID{
+  "id", cl::Positional,
+  cl::desc("Symbol ID of the symbol being queried (hex)."),
+  };
+  cl::opt Name{
+  "name", cl::desc("Qualified name of the symbol being queried."),
+  };
+  cl::opt Filter{
+  "filter", cl::init(".*"),
+  cl::desc(
+  "Print all results from files matching this regular expression."),
+  };
+
+  void run() override {
+if (ID.getNumOccurrences() == 0 && Name.getNumOccurrences() == 0) {
+  llvm::outs()
+  << "Missing required argument: please provide id or -name.\n";
+  return;
+}
+std::vector IDs;
+if (ID.getNumOccurrences()) {
+  auto SID = clang::clangd::SymbolID::fromStr(ID);
+  if (!SID) {
+llvm::outs() << llvm::toString(SID.takeError()) << "\n";
+return;
+  }
+  IDs.push_back(*SID);
+} else {
+  IDs = getSymbolIDsFromIndex(Name, Index);
+}
+clang::clangd::RefsRequest RefRequest;
+RefRequest.IDs.insert(IDs.begin(), IDs.end());
+llvm::Regex RegexFilter(Filter);
+Index->refs(RefRequest, [&RegexFilter](const clang::clangd::Ref &R) {
+  auto U = clang::clangd::URI::parse(R.Location.FileURI);
+  if (!U) {
+llvm::outs() << U.takeError();
+return;
+  }
+  if (RegexFilter.match(U->body()))
+llvm::outs() << R << "\n";
+});
+  }
+};
+
 struct {
   const char *Name;
   const char *Description;
   std::function()> Implementation;
 } CommandInfo[] = {
 {"find", "Search for symbols

r344509 - [CodeComplete] Make sure keyword 'template' is added even when code pattern is disabled.

2018-10-15 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Mon Oct 15 05:37:23 2018
New Revision: 344509

URL: http://llvm.org/viewvc/llvm-project?rev=344509&view=rev
Log:
[CodeComplete] Make sure keyword 'template' is added even when code pattern is 
disabled.

Reviewers: sammccall, hokein

Subscribers: arphaman, cfe-commits

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

Added:
cfe/trunk/test/Index/complete-template-keywords.cpp
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=344509&r1=344508&r2=344509&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Mon Oct 15 05:37:23 2018
@@ -1731,6 +1731,8 @@ static void AddOrdinaryNameResults(Sema:
 Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
 Builder.AddPlaceholderChunk("declaration");
 Results.AddResult(Result(Builder.TakeString()));
+  } else {
+Results.AddResult(Result("template", 
CodeCompletionResult::RK_Keyword));
   }
 }
 
@@ -1805,6 +1807,8 @@ static void AddOrdinaryNameResults(Sema:
   Builder.AddPlaceholderChunk("parameters");
   Builder.AddChunk(CodeCompletionString::CK_RightAngle);
   Results.AddResult(Result(Builder.TakeString()));
+} else {
+  Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword));
 }
 
 AddStorageSpecifiers(CCC, SemaRef.getLangOpts(), Results);

Added: cfe/trunk/test/Index/complete-template-keywords.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-template-keywords.cpp?rev=344509&view=auto
==
--- cfe/trunk/test/Index/complete-template-keywords.cpp (added)
+++ cfe/trunk/test/Index/complete-template-keywords.cpp Mon Oct 15 05:37:23 2018
@@ -0,0 +1,5 @@
+templ
+// RUN: env c-index-test -code-completion-at=%s:1:5 %s | FileCheck 
-check-prefix=CHECK-NO-PATTERN %s
+// CHECK-NO-PATTERN: {TypedText template} (1)
+// RUN: env CINDEXTEST_CODE_COMPLETE_PATTERNS=1 c-index-test 
-code-completion-at=%s:1:5 %s | FileCheck -check-prefix=CHECK-PATTERN %s
+// CHECK-PATTERN: {TypedText template}{LeftAngle <}


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


[PATCH] D53284: [CodeComplete] Make sure keyword 'template' is added even when code pattern is disabled.

2018-10-15 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC344509: [CodeComplete] Make sure keyword 
'template' is added even when code pattern is… (authored by ioeric, 
committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53284?vs=169681&id=169685#toc

Repository:
  rC Clang

https://reviews.llvm.org/D53284

Files:
  lib/Sema/SemaCodeComplete.cpp
  test/Index/complete-template-keywords.cpp


Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -1731,6 +1731,8 @@
 Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
 Builder.AddPlaceholderChunk("declaration");
 Results.AddResult(Result(Builder.TakeString()));
+  } else {
+Results.AddResult(Result("template", 
CodeCompletionResult::RK_Keyword));
   }
 }
 
@@ -1805,6 +1807,8 @@
   Builder.AddPlaceholderChunk("parameters");
   Builder.AddChunk(CodeCompletionString::CK_RightAngle);
   Results.AddResult(Result(Builder.TakeString()));
+} else {
+  Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword));
 }
 
 AddStorageSpecifiers(CCC, SemaRef.getLangOpts(), Results);
Index: test/Index/complete-template-keywords.cpp
===
--- test/Index/complete-template-keywords.cpp
+++ test/Index/complete-template-keywords.cpp
@@ -0,0 +1,5 @@
+templ
+// RUN: env c-index-test -code-completion-at=%s:1:5 %s | FileCheck 
-check-prefix=CHECK-NO-PATTERN %s
+// CHECK-NO-PATTERN: {TypedText template} (1)
+// RUN: env CINDEXTEST_CODE_COMPLETE_PATTERNS=1 c-index-test 
-code-completion-at=%s:1:5 %s | FileCheck -check-prefix=CHECK-PATTERN %s
+// CHECK-PATTERN: {TypedText template}{LeftAngle <}


Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -1731,6 +1731,8 @@
 Builder.AddChunk(CodeCompletionString::CK_HorizontalSpace);
 Builder.AddPlaceholderChunk("declaration");
 Results.AddResult(Result(Builder.TakeString()));
+  } else {
+Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword));
   }
 }
 
@@ -1805,6 +1807,8 @@
   Builder.AddPlaceholderChunk("parameters");
   Builder.AddChunk(CodeCompletionString::CK_RightAngle);
   Results.AddResult(Result(Builder.TakeString()));
+} else {
+  Results.AddResult(Result("template", CodeCompletionResult::RK_Keyword));
 }
 
 AddStorageSpecifiers(CCC, SemaRef.getLangOpts(), Results);
Index: test/Index/complete-template-keywords.cpp
===
--- test/Index/complete-template-keywords.cpp
+++ test/Index/complete-template-keywords.cpp
@@ -0,0 +1,5 @@
+templ
+// RUN: env c-index-test -code-completion-at=%s:1:5 %s | FileCheck -check-prefix=CHECK-NO-PATTERN %s
+// CHECK-NO-PATTERN: {TypedText template} (1)
+// RUN: env CINDEXTEST_CODE_COMPLETE_PATTERNS=1 c-index-test -code-completion-at=%s:1:5 %s | FileCheck -check-prefix=CHECK-PATTERN %s
+// CHECK-PATTERN: {TypedText template}{LeftAngle <}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53286: [clangd] Refactor JSON-over-stdin/stdout code into Transport abstraction.

2018-10-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: jkorous, ioeric, hokein.
Herald added subscribers: cfe-commits, kadircet, arphaman, MaskRay, 
ilya-biryukov, mgorny.

This paves the way for alternative transports (mac XPC, maybe messagepack?),
and also generally improves layering: testing ClangdLSPServer becomes less of
a pipe dream, we split up the JSONOutput monolith, etc.

This isn't a final state, much of what remains in JSONRPCDispatcher can go away,
handlers can call reply() on the transport directly, JSONOutput can be renamed
to StreamLogger and removed, etc. But this patch is sprawling already.

The main observable change (see tests) is that hitting EOF on input is now an
error: the client should send the 'exit' notification.
This is defensible: the protocol doesn't spell this case out. Reproducing the
current behavior for all combinations of shutdown/exit/EOF clutters interfaces.
We can iterate on this if desired.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53286

Files:
  clangd/CMakeLists.txt
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/JSONRPCDispatcher.cpp
  clangd/JSONRPCDispatcher.h
  clangd/JSONTransport.cpp
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/Transport.h
  clangd/tool/ClangdMain.cpp
  test/clangd/compile-commands-path-in-initialize.test
  test/clangd/compile-commands-path.test
  test/clangd/completion-snippets.test
  test/clangd/completion.test
  test/clangd/crash-non-added-files.test
  test/clangd/execute-command.test
  test/clangd/input-mirror.test
  test/clangd/signature-help.test
  test/clangd/textdocument-didchange-fail.test
  test/clangd/trace.test
  test/clangd/xrefs.test

Index: test/clangd/xrefs.test
===
--- test/clangd/xrefs.test
+++ test/clangd/xrefs.test
@@ -55,3 +55,5 @@
 # CHECK-NEXT: ]
 ---
 {"jsonrpc":"2.0","id":1,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: test/clangd/trace.test
===
--- test/clangd/trace.test
+++ test/clangd/trace.test
@@ -21,3 +21,5 @@
 # CHECK: },
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: test/clangd/textdocument-didchange-fail.test
===
--- test/clangd/textdocument-didchange-fail.test
+++ test/clangd/textdocument-didchange-fail.test
@@ -35,3 +35,5 @@
 # CHECK-NEXT:}
 ---
 {"jsonrpc":"2.0","id":4,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: test/clangd/signature-help.test
===
--- test/clangd/signature-help.test
+++ test/clangd/signature-help.test
@@ -23,3 +23,5 @@
 # CHECK-NEXT: }
 ---
 {"jsonrpc":"2.0","id":10,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: test/clangd/input-mirror.test
===
--- test/clangd/input-mirror.test
+++ test/clangd/input-mirror.test
@@ -12,3 +12,6 @@
 Content-Length: 44
 
 {"jsonrpc":"2.0","id":3,"method":"shutdown"}
+Content-Length: 33
+
+{"jsonrpc":"2.0","method":"exit"}
Index: test/clangd/execute-command.test
===
--- test/clangd/execute-command.test
+++ test/clangd/execute-command.test
@@ -62,3 +62,5 @@
 {"jsonrpc":"2.0","id":9,"method":"workspace/executeCommand","params":{"arguments":[{"custom":"foo", "changes":{"test:///foo.c":[{"range":{"start":{"line":0,"character":32},"end":{"line":0,"character":32}},"newText":"("},{"range":{"start":{"line":0,"character":37},"end":{"line":0,"character":37}},"newText":")"}]}}],"command":"clangd.applyFix"}}
 ---
 {"jsonrpc":"2.0","id":3,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: test/clangd/crash-non-added-files.test
===
--- test/clangd/crash-non-added-files.test
+++ test/clangd/crash-non-added-files.test
@@ -32,3 +32,5 @@
 {"jsonrpc":"2.0","id":6,"method":"shutdown"}
 ---
 {"jsonrpc":"2.0","method":"exit"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: test/clangd/completion.test
===
--- test/clangd/completion.test
+++ test/clangd/completion.test
@@ -68,3 +68,5 @@
 # CHECK-NEXT:  ]
 ---
 {"jsonrpc":"2.0","id":4,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: test/clangd/completion-snippets.test
===
--- test/clangd/completion-snippets.test
+++ test/clangd/completion-snippets.test
@@ -52,3 +52,5 @@
 # CHECK-NEXT:  }
 ---
 {"jsonrpc":"2.0","id":4,"method":"shutdown"}
+---
+{"jsonrpc":"2.0","method":"exit"}
Index: test/clangd/compile-commands-path.test
===
--- test/clangd/compile-commands-path.tes

[clang-tools-extra] r344510 - [clangd] Remove an unused include header, NFC.

2018-10-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Oct 15 05:39:45 2018
New Revision: 344510

URL: http://llvm.org/viewvc/llvm-project?rev=344510&view=rev
Log:
[clangd] Remove an unused include header, NFC.

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

Modified: clang-tools-extra/trunk/clangd/index/Merge.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Merge.cpp?rev=344510&r1=344509&r2=344510&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Merge.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/Merge.cpp Mon Oct 15 05:39:45 2018
@@ -13,7 +13,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/raw_ostream.h"
-#include 
 
 namespace clang {
 namespace clangd {


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


[PATCH] D53019: [clangd] dump xrefs information in dexp tool.

2018-10-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/index/dex/dexp/Dexp.cpp:185
 clang::clangd::LookupRequest Request;
-Request.IDs = {*SID};
+Request.IDs.insert(IDs.begin(), IDs.end());
 bool FoundSymbol = false;

hokein wrote:
> sammccall wrote:
> > (nit: why not just initialize in place above?)
> In fact, Request.IDs and IDs are different types, and DenseSet is missing 
> such constructor :(
I meant, why does the local variable "IDs" exist at all? Why not just populate 
`Request.IDs` directly?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53019



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


[PATCH] D52784: [ARM][AArch64] Pass through endianness flags to the GNU assembler and linker

2018-10-15 Thread Peter Smith via Phabricator via cfe-commits
peter.smith marked 7 inline comments as done.
peter.smith added a comment.

Thanks very much for the comments. I'll post an update shortly.




Comment at: lib/Driver/ToolChains/Gnu.cpp:357-364
+const char* EndianFlag = "-EL";
+if (isArmBigEndian(Triple, Args)) {
+  EndianFlag = "-EB";
+  arm::appendBE8LinkFlag(Args, CmdArgs, Triple);
+}
+else if (Arch == llvm::Triple::aarch64_be)
+  EndianFlag = "-EB";

nickdesaulniers wrote:
> nickdesaulniers wrote:
> > ```
> > bool IsBigEndian = isArmBigEndian(Triple, Args);
> > if (IsBigEndian)
> >   arm::appendBE8LinkFlag(Args, CmdArgs, Triple);
> > IsBigEndian |= Arch == llvm::Triple::aarch64_be;
> > CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL");
> > ```
> `IsBigEndian |= Arch == llvm::Triple::aarch64_be;`
> 
> should be:
> 
> `IsBigEndian = IsBigEndian || Arch == llvm::Triple::aarch64_be;`
> 
> in order to not evaluate `Arch == llvm::Triple::aarch64_b` if `IsBigEndian` 
> is already true.
Thanks for the suggestion. One thing it highlighted was that isArmBigEndian 
could return true for an aarch64_be arch with -mbig-endian so I've rewritten 
isArmBigEndian to always return false if the architecture isn't Arm and have 
added some test cases to check that "--be8" doesn't sneak in.



Comment at: lib/Driver/ToolChains/Gnu.cpp:362
+}
+else if (Arch == llvm::Triple::aarch64_be)
+  EndianFlag = "-EB";

nickdesaulniers wrote:
> is having the `else if` on its own line what the formatter chose?
I'd forgot to run clang-format over that part of the code. I've adopted the 
snippet below which replaces it.



Comment at: lib/Driver/ToolChains/Gnu.cpp:703
   case llvm::Triple::aarch64_be: {
+if (getToolChain().getTriple().isLittleEndian())
+  CmdArgs.push_back("-EL");

nickdesaulniers wrote:
> earlier (L362), you check the endianess of the triple with:
> 
> ```
> Arch == llvm::Triple::aarch64_be
> ```
> where `Arch` is `ToolChain.getArch()`.
> 
> I don't have a preference, but these two seem inconsistent.  Can we either 
> check the explicit `llvm::Triple::` or call 
> `getToolChain().getTriple().isLittleEndian()` in both, rather than mix?
I originally took that part from the Mips code, I've replaced it with a check 
against aarch64_be which is more consistent with the other Arm and AArch64 code.


https://reviews.llvm.org/D52784



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


[PATCH] D53277: [analyzer][NFC][WIP] Collect all -analyzer-config options in a .def file

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 169688.

https://reviews.llvm.org/D53277

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp

Index: lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -56,17 +56,17 @@
 static std::unique_ptr generateWorkList(AnalyzerOptions &Opts,
   SubEngine &subengine) {
   switch (Opts.getExplorationStrategy()) {
-case AnalyzerOptions::ExplorationStrategyKind::DFS:
+case ExplorationStrategyKind::DFS:
   return WorkList::makeDFS();
-case AnalyzerOptions::ExplorationStrategyKind::BFS:
+case ExplorationStrategyKind::BFS:
   return WorkList::makeBFS();
-case AnalyzerOptions::ExplorationStrategyKind::BFSBlockDFSContents:
+case ExplorationStrategyKind::BFSBlockDFSContents:
   return WorkList::makeBFSBlockDFSContents();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirst:
+case ExplorationStrategyKind::UnexploredFirst:
   return WorkList::makeUnexploredFirst();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstQueue:
+case ExplorationStrategyKind::UnexploredFirstQueue:
   return WorkList::makeUnexploredFirstPriorityQueue();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstLocationQueue:
+case ExplorationStrategyKind::UnexploredFirstLocationQueue:
   return WorkList::makeUnexploredFirstPriorityLocationQueue();
   }
 }
Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -49,7 +49,7 @@
   return Result;
 }
 
-AnalyzerOptions::UserModeKind AnalyzerOptions::getUserMode() {
+UserModeKind AnalyzerOptions::getUserMode() {
   if (!UserMode.hasValue()) {
 StringRef ModeStr = getOptionAsString("mode", "deep");
 UserMode = llvm::StringSwitch>(ModeStr)
@@ -61,7 +61,7 @@
   return UserMode.getValue();
 }
 
-AnalyzerOptions::ExplorationStrategyKind
+ExplorationStrategyKind
 AnalyzerOptions::getExplorationStrategy() {
   if (!ExplorationStrategy.hasValue()) {
 StringRef StratStr = getOptionAsString("exploration_strategy",
@@ -182,137 +182,6 @@
   return V.getValue();
 }
 
-bool AnalyzerOptions::includeTemporaryDtorsInCFG() {
-  return getBooleanOption(IncludeTemporaryDtorsInCFG,
-  "cfg-temporary-dtors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeImplicitDtorsInCFG() {
-  return getBooleanOption(IncludeImplicitDtorsInCFG,
-  "cfg-implicit-dtors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeLifetimeInCFG() {
-  return getBooleanOption(IncludeLifetimeInCFG, "cfg-lifetime",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::includeLoopExitInCFG() {
-  return getBooleanOption(IncludeLoopExitInCFG, "cfg-loopexit",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::includeRichConstructorsInCFG() {
-  return getBooleanOption(IncludeRichConstructorsInCFG,
-  "cfg-rich-constructors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeScopesInCFG() {
-  return getBooleanOption(IncludeScopesInCFG,
-  "cfg-scopes",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::mayInlineCXXStandardLibrary() {
-  return getBooleanOption(InlineCXXStandardLibrary,
-  "c++-stdlib-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineTemplateFunctions() {
-  return getBooleanOption(InlineTemplateFunctions,
-  "c++-template-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineCXXAllocator() {
-  return getBooleanOption(InlineCXXAllocator,
-  "c++-allocator-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineCXXContainerMethods() {
-  return getBooleanOption(InlineCXXContainerMethods,
-  "c++-container-inlining",
-  /*Default=*/false);
-}
-
-bool AnalyzerOptions::mayInlineCXXSharedPtrDtor() {
-  return getBooleanOption(InlineCXXSharedPtrDtor,
-  "c++-shared_ptr-inlining",
-  /*Default=*/false);
-}
-
-bool AnalyzerOptions::mayInlineCXXTemporaryDtors() {
-  return getBooleanOption(InlineCXXTemporaryDtors,
-  "c++-temp-dtor-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayI

[PATCH] D52784: [ARM][AArch64] Pass through endianness flags to the GNU assembler and linker

2018-10-15 Thread Peter Smith via Phabricator via cfe-commits
peter.smith updated this revision to Diff 169689.
peter.smith marked 3 inline comments as done.
peter.smith added a comment.

Updated diff to reflect review comments. Main changes are:

- isArmBigEndian always returns false if the target architecture isn't Arm.
- Added tests to make sure "--be8" doesn't get added by mistake (would have 
been in previous patch for aarch64_be arch with -mbig-endian flag.


https://reviews.llvm.org/D52784

Files:
  lib/Driver/ToolChains/Arch/ARM.cpp
  lib/Driver/ToolChains/Arch/ARM.h
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/NetBSD.cpp
  test/Driver/linux-as.c
  test/Driver/linux-ld.c

Index: test/Driver/linux-ld.c
===
--- test/Driver/linux-ld.c
+++ test/Driver/linux-ld.c
@@ -1759,6 +1759,7 @@
 // RUN:   | FileCheck --check-prefix=CHECK-ARMEB %s
 // CHECK-ARMEB: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-ARMEB-NOT: "--be8"
+// CHECK-ARMEB: "-EB"
 // CHECK-ARMEB: "-m" "armelfb_linux_eabi"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
@@ -1768,16 +1769,88 @@
 // RUN:   | FileCheck --check-prefix=CHECK-ARMV7EB %s
 // CHECK-ARMV7EB: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
 // CHECK-ARMV7EB: "--be8"
+// CHECK-ARMV7EB: "-EB"
 // CHECK-ARMV7EB: "-m" "armelfb_linux_eabi"
 
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=armv7-unknown-linux \
+// RUN: -mbig-endian \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7EB %s
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=armebv7-unknown-linux \
+// RUN: -mbig-endian \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7EB %s
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=armv7-unknown-linux \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7EL %s
+// CHECK-ARMV7EL: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-ARMV7EL-NOT: "--be8"
+// CHECK-ARMV7EL: "-EL"
+// CHECK-ARMV7EL: "-m" "armelf_linux_eabi"
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=armebv7-unknown-linux \
+// RUN: -mlittle-endian \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7EL %s
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=armv7-unknown-linux \
+// RUN: -mlittle-endian \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-ARMV7EL %s
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: --target=aarch64_be-unknown-linux \
 // RUN: --gcc-toolchain="" \
 // RUN: --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-AARCH64BE %s
 // CHECK-AARCH64BE: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-AARCH64BE-NOT: "--be8"
+// CHECK-AARCH64BE: "-EB"
 // CHECK-AARCH64BE: "-m" "aarch64linuxb"
 
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=aarch64-unknown-linux \
+// RUN: -mbig-endian \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-AARCH64BE %s
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=aarch64_be-unknown-linux \
+// RUN: -mbig-endian \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-AARCH64BE %s
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=aarch64-unknown-linux \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-AARCH64LE %s
+// CHECK-AARCH64LE: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
+// CHECK-AARCH64LE-NOT: "--be8"
+// CHECK-AARCH64LE: "-EL"
+// CHECK-AARCH64LE: "-m" "aarch64linux"
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=aarch64_be-unknown-linux \
+// RUN: -mlittle-endian \
+// RUN: --gcc-toolchain="" \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-AARCH64LE %s
+
 // Check dynamic-linker for musl-libc
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=i386-pc-linux-musl \
Index: test/Driver/linux-as.c
===
--- test/Driver/linux-as.c
+++ test/Driver/linux-as.c
@@ -3,129 +3,160 @@
 // RUN: %clang -target arm-linux -### \
 // RUN:   -no-integrated-as -c %s 2>&1 \
 // RUN:   | FileCheck -check-pre

[PATCH] D53286: [clangd] Refactor JSON-over-stdin/stdout code into Transport abstraction.

2018-10-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

This patch is big and hard to navigate. I tried to keep it contained, but 
JSONRPCDispatcher is pretty tangled.

The main parts are:

- `Transport.h` is the key new abstraction that should be understood first
- `JSONTransport.cpp` is its standard implementation. The raw IO stuff in there 
is just lifted from the old JSONRPCDispatcher, and isn't very interesting. 
Everything else should be though - it shows how the new interface works.
- The `ClangdLSPServer` and `ClangdMain` changes show how the new interface is 
used
- `JSONRPCDispatcher` has had most of its guts ripped out. There's more that 
can be done there, that file may go away completely.
- The test changes just reflect the shutdown getting a little bit stricter 
(they also pass before this patch)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53286



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


[PATCH] D53277: [analyzer][NFC][WIP] Collect all -analyzer-config options in a .def file

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h:128-135
+/// Describes the kinds for high-level analyzer mode.
+enum UserModeKind {
+  /// Perform shallow but fast analyzes.
+  UMK_Shallow = 1,
+
+  /// Perform deep analyzes.
+  UMK_Deep = 2

Do we actually //ever// use `UMK_SHALLOW`? If not, the whole .def file can be 
simplified, because the use of `getDefaultValForUserMode(/* ShallowVal */, /* 
DeepVal */)` is clunky. If we do, I'd also be fine with rewriting the function 
generating macro from 
```
#define ANALYZER_OPTION_WITH_FN(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL, \
CREATE_FN)
```
to
```

#define ANALYZER_OPTION_WITH_FN(TYPE, NAME, CMDFLAG, DESC, SHALLOW_VAL, \
DEEP_VAL, CREATE_FN)
```
because that'd be nicer than the current solution.


https://reviews.llvm.org/D53277



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


[PATCH] D53280: [analyzer] Emit a warning for unknown -analyzer-config options

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 169693.

https://reviews.llvm.org/D53280

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/Frontend/CompilerInvocation.cpp


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -314,6 +314,8 @@
   Opts.CheckersControlList.emplace_back(checker, enable);
   }
 
+  const std::vector RegisteredOptions = Opts.getConfigOptionList();
+
   // Go through the analyzer configuration options.
   for (const auto *A : Args.filtered(OPT_analyzer_config)) {
 A->claim();
@@ -338,6 +340,14 @@
 Success = false;
 break;
   }
+  // Check whether this really is a valid -analyzer-condfig option.
+  // TODO: We should check whether all options are valid or not, but for
+  // now, skip checker options.
+  if (key.count(':') == 0) {
+if (llvm::find(RegisteredOptions, key) == RegisteredOptions.end())
+  Diags.Report(diag::warn_analyzer_config_unknown_config) << key;
+  }
+
   Opts.Config[key] = val;
 }
   }
Index: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===
--- include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -319,6 +319,15 @@
   template 
   T getDefaultValForUserMode(T ShallowVal, T DeepVal);
 
+  std::vector getConfigOptionList() const {
+return {
+#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC) \
+  CMDFLAG,
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
+#undef ANALYZER_OPTION
+};
+  }
+
 #define ANALYZER_OPTION_WITH_FN(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL, \
 CREATE_FN)  \
   TYPE CREATE_FN();
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -291,6 +291,9 @@
   "analyzer-config option '%0' has a key but no value">;
 def err_analyzer_config_multiple_values : Error<
   "analyzer-config option '%0' should contain only one '='">;
+def warn_analyzer_config_unknown_config : Warning<
+  "unkown -analyzer-config option '%0'">,
+  InGroup;
 
 def err_drv_invalid_hvx_length : Error<
   "-mhvx-length is not supported without a -mhvx/-mhvx= flag">;


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -314,6 +314,8 @@
   Opts.CheckersControlList.emplace_back(checker, enable);
   }
 
+  const std::vector RegisteredOptions = Opts.getConfigOptionList();
+
   // Go through the analyzer configuration options.
   for (const auto *A : Args.filtered(OPT_analyzer_config)) {
 A->claim();
@@ -338,6 +340,14 @@
 Success = false;
 break;
   }
+  // Check whether this really is a valid -analyzer-condfig option.
+  // TODO: We should check whether all options are valid or not, but for
+  // now, skip checker options.
+  if (key.count(':') == 0) {
+if (llvm::find(RegisteredOptions, key) == RegisteredOptions.end())
+  Diags.Report(diag::warn_analyzer_config_unknown_config) << key;
+  }
+
   Opts.Config[key] = val;
 }
   }
Index: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
===
--- include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
+++ include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
@@ -319,6 +319,15 @@
   template 
   T getDefaultValForUserMode(T ShallowVal, T DeepVal);
 
+  std::vector getConfigOptionList() const {
+return {
+#define ANALYZER_OPTION(TYPE, NAME, CMDFLAG, DESC) \
+  CMDFLAG,
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.def"
+#undef ANALYZER_OPTION
+};
+  }
+
 #define ANALYZER_OPTION_WITH_FN(TYPE, NAME, CMDFLAG, DESC, DEFAULT_VAL, \
 CREATE_FN)  \
   TYPE CREATE_FN();
Index: include/clang/Basic/DiagnosticDriverKinds.td
===
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -291,6 +291,9 @@
   "analyzer-config option '%0' has a key but no value">;
 def err_analyzer_config_multiple_values : Error<
   "analyzer-config option '%0' should contain only one '='">;
+def warn_analyzer_config_unknown_config : Warning<
+  "unkown -analyzer-config option '%0'">,
+  InGroup;
 
 def err_drv_invalid_hvx_length : Error<
   "-mhvx-length is not supported without a -mhvx/-mhvx= flag">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.o

[PATCH] D53032: [clangd] Minimal implementation of automatic static index, behind a flag.

2018-10-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 169694.
sammccall marked an inline comment as done.
sammccall added a comment.

Address comments, strip out of clangdlspserver for now.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53032

Files:
  clangd/CMakeLists.txt
  clangd/ClangdServer.cpp
  clangd/Compiler.cpp
  clangd/Compiler.h
  clangd/index/Background.cpp
  clangd/index/Background.h
  unittests/clangd/BackgroundIndexTests.cpp
  unittests/clangd/CMakeLists.txt
  unittests/clangd/SyncAPI.cpp
  unittests/clangd/SyncAPI.h

Index: unittests/clangd/SyncAPI.h
===
--- unittests/clangd/SyncAPI.h
+++ unittests/clangd/SyncAPI.h
@@ -17,7 +17,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H
 
 #include "ClangdServer.h"
-#include 
+#include "index/Index.h"
 
 namespace clang {
 namespace clangd {
@@ -50,6 +50,9 @@
 llvm::Expected>
 runDocumentSymbols(ClangdServer &Server, PathRef File);
 
+SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query);
+SymbolSlab runFuzzyFind(const SymbolIndex &Index, const FuzzyFindRequest &Req);
+
 } // namespace clangd
 } // namespace clang
 
Index: unittests/clangd/SyncAPI.cpp
===
--- unittests/clangd/SyncAPI.cpp
+++ unittests/clangd/SyncAPI.cpp
@@ -125,5 +125,17 @@
   return std::move(*Result);
 }
 
+SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query) {
+  FuzzyFindRequest Req;
+  Req.Query = Query;
+  return runFuzzyFind(Index, Req);
+}
+
+SymbolSlab runFuzzyFind(const SymbolIndex &Index, const FuzzyFindRequest &Req) {
+  SymbolSlab::Builder Builder;
+  Index.fuzzyFind(Req, [&](const Symbol &Sym) { Builder.insert(Sym); });
+  return std::move(Builder).build();
+}
+
 } // namespace clangd
 } // namespace clang
Index: unittests/clangd/CMakeLists.txt
===
--- unittests/clangd/CMakeLists.txt
+++ unittests/clangd/CMakeLists.txt
@@ -10,6 +10,7 @@
 
 add_extra_unittest(ClangdTests
   Annotations.cpp
+  BackgroundIndexTests.cpp
   CancellationTests.cpp
   ClangdTests.cpp
   ClangdUnitTests.cpp
Index: unittests/clangd/BackgroundIndexTests.cpp
===
--- /dev/null
+++ unittests/clangd/BackgroundIndexTests.cpp
@@ -0,0 +1,37 @@
+#include "SyncAPI.h"
+#include "TestFS.h"
+#include "index/Background.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using testing::UnorderedElementsAre;
+
+namespace clang {
+namespace clangd {
+
+MATCHER_P(Named, N, "") { return arg.Name == N; }
+
+TEST(BackgroundIndexTest, IndexTwoFiles) {
+  MockFSProvider FS;
+  // a.h yields different symbols when included by A.cc vs B.cc.
+  // Currently we store symbols for each TU, so we get both.
+  FS.Files[testPath("root/A.h")] = "void a_h(); void NAME(){}";
+  FS.Files[testPath("root/A.cc")] = "#include \"A.h\"";
+  FS.Files[testPath("root/B.cc")] = "#define NAME bar\n#include \"A.h\"";
+  BackgroundIndex Idx(Context::empty(), "", FS);
+
+  tooling::CompileCommand Cmd;
+  Cmd.Filename = testPath("root/A.cc");
+  Cmd.Directory = testPath("root");
+  Cmd.CommandLine = {"clang++", "-DNAME=foo", testPath("root/A.cc")};
+  Idx.enqueue(testPath("root"), Cmd);
+  Cmd.CommandLine.back() = Cmd.Filename = testPath("root/B.cc");
+  Idx.enqueue(testPath("root"), Cmd);
+
+  Idx.blockUntilIdleForTest();
+  EXPECT_THAT(runFuzzyFind(Idx, ""),
+  UnorderedElementsAre(Named("a_h"), Named("foo"), Named("bar")));
+}
+
+} // namespace clangd
+} // namespace clang
Index: clangd/index/Background.h
===
--- /dev/null
+++ clangd/index/Background.h
@@ -0,0 +1,79 @@
+//===--- Background.h - Build an index in a background thread *- 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_CLANGD_INDEX_BACKGROUND_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_BACKGROUND_H
+
+#include "Context.h"
+#include "FSProvider.h"
+#include "index/FileIndex.h"
+#include "index/Index.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/Support/SHA1.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+// Builds an in-memory index by by running the static indexer action over
+// all commands in a compilation database. Indexing happens in the background.
+// FIXME: it should also persist its state on disk for fast start.
+// FIXME: it should watch for changes to files on disk.
+class BackgroundIndex : public SwapIndex {
+public:
+  // FIXME: resource-dir injection should be hoisted somewhere common.
+  BackgroundIndex(Context BackgroundContext, StringRef ResourceDir,
+ 

[PATCH] D53032: [clangd] Minimal implementation of automatic static index, behind a flag.

2018-10-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: unittests/clangd/BackgroundIndexTests.cpp:14
+
+TEST(BackgroundIndexTest, IndexesOneFile) {
+  MockFSProvider FS;

sammccall wrote:
> ioeric wrote:
> > sammccall wrote:
> > > ioeric wrote:
> > > > sammccall wrote:
> > > > > ioeric wrote:
> > > > > > Also add a test for `enqueueAll` with multiple TUs ?
> > > > > Is it important to call `enqueueAll` specifically vs `enqueue` 
> > > > > multiple times?
> > > > > 
> > > > > We don't have a good test fixture for a compilation database, and 
> > > > > `enqueueAll` is trivial...
> > > > I think the randomization code worths a test. 
> > > > 
> > > > How about adding a test in ClangdServer with the auto index enabled? I 
> > > > think we'd also want coverage in ClangdServer anyway.
> > > How would you suggest testing the randomization :-)
> > > 
> > > The problem with a ClangdServer test is that it doesn't know anything 
> > > about autoindex.
> > > AutoIndex lives in ClangdLSPServer, because that's where the compilation 
> > > database lives (because people keep cramming LSP extensions in to 
> > > manipulate it, and I haven't been able to remove them).
> > > Nobody has worked out how to test ClangdLSPServer yet. It's a worthy 
> > > project, but...
> > > How would you suggest testing the randomization :-)
> > Not suggesting testing the behavior; just test that it works really. I 
> > guess a single file would also do it.
> > 
> > > The problem with a ClangdServer test is that it doesn't know anything 
> > > about autoindex.
> > Ah, I see. That's a bit unfortunate. ClangdServer seems to be a better 
> > place for the auto index. I wonder if we could move AutoIndex into 
> > ClangdServer? I'm not very familiar with CDB APIs, but intuitively this 
> > seems doable if we tweak the interface of CDB a bit e.g. inject the 
> > callback into `GlobalCompilationDatabase` without going through 
> > `CompilationDB`? Not sure if how well this would play with the CDB design 
> > though.
> > ClangdServer seems to be a better place for the auto index
> I fully agree.
> 
> >  I wonder if we could move AutoIndex into ClangdServer? I'm not very 
> > familiar with CDB APIs...
> Currently the global CDB is trying to be all things to all people:
>  - by default, it follows Tooling conventions and looks for compile_commands 
> above the source files
>  - google's hosted option wants it to be completely opaque, no indexing
>  - apple wants it to be an in-memory store mutated over LSP
>  - ericsson wants it to be a fixed directory set by the user
> 
> And we've implemented these in ad-hoc ways, not behind any real abstraction. 
> I don't think adding more functionality to the interface without addressing 
> this is a great idea, and I don't really know how to untangle all this 
> without asking people to rethink their use cases. But I'll think about this 
> some more.
After thinking about this, decided to just check in the library with unit tests 
for now while we sort out the layering.
I've ripped out all the ClangdMain and ClangdLSPServer changes.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53032



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


[PATCH] D53032: [clangd] Minimal implementation of automatic static index, behind a flag.

2018-10-15 Thread Eric Liu via Phabricator via cfe-commits
ioeric accepted this revision.
ioeric added a comment.

still lgtm




Comment at: clangd/Compiler.cpp:83
 
+std::string getStandardResourceDir() {
+  static int Dummy; // Just an address in this process.

Maybe also revert this change?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53032



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


[clang-tools-extra] r344513 - [clangd] Minimal implementation of automatic static index (not enabled).

2018-10-15 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Mon Oct 15 06:34:10 2018
New Revision: 344513

URL: http://llvm.org/viewvc/llvm-project?rev=344513&view=rev
Log:
[clangd] Minimal implementation of automatic static index (not enabled).

Summary:
See tinyurl.com/clangd-automatic-index for design and goals.

Lots of limitations to keep this patch smallish, TODOs everywhere:
 - no serialization to disk
 - no changes to dynamic index, which now has a much simpler job
 - no partitioning of symbols by file to avoid duplication of header symbols
 - no reindexing of edited files
 - only a single worker thread
 - compilation database is slurped synchronously (doesn't scale)
 - uses memindex, rebuilds after every file (should be dex, periodically)

It's not hooked up to ClangdServer/ClangdLSPServer yet: the layering
isn't clear (it should really be in ClangdServer, but ClangdLSPServer
has all the CDB interactions).

Reviewers: ioeric

Subscribers: mgorny, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, jfb, 
cfe-commits

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

Added:
clang-tools-extra/trunk/clangd/index/Background.cpp
clang-tools-extra/trunk/clangd/index/Background.h
clang-tools-extra/trunk/unittests/clangd/BackgroundIndexTests.cpp
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
clang-tools-extra/trunk/unittests/clangd/SyncAPI.cpp
clang-tools-extra/trunk/unittests/clangd/SyncAPI.h

Modified: clang-tools-extra/trunk/clangd/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CMakeLists.txt?rev=344513&r1=344512&r2=344513&view=diff
==
--- clang-tools-extra/trunk/clangd/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/CMakeLists.txt Mon Oct 15 06:34:10 2018
@@ -38,6 +38,7 @@ add_clang_library(clangDaemon
   URI.cpp
   XRefs.cpp
 
+  index/Background.cpp
   index/CanonicalIncludes.cpp
   index/FileIndex.cpp
   index/Index.cpp

Added: clang-tools-extra/trunk/clangd/index/Background.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/Background.cpp?rev=344513&view=auto
==
--- clang-tools-extra/trunk/clangd/index/Background.cpp (added)
+++ clang-tools-extra/trunk/clangd/index/Background.cpp Mon Oct 15 06:34:10 2018
@@ -0,0 +1,191 @@
+//===-- Background.cpp - Build an index in a background thread 
===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "index/Background.h"
+#include "ClangdUnit.h"
+#include "Compiler.h"
+#include "Logger.h"
+#include "Trace.h"
+#include "index/IndexAction.h"
+#include "index/MemIndex.h"
+#include "index/Serialization.h"
+#include "llvm/Support/SHA1.h"
+#include 
+
+using namespace llvm;
+namespace clang {
+namespace clangd {
+
+BackgroundIndex::BackgroundIndex(Context BackgroundContext,
+ StringRef ResourceDir,
+ const FileSystemProvider &FSProvider)
+: SwapIndex(llvm::make_unique()), ResourceDir(ResourceDir),
+  FSProvider(FSProvider), BackgroundContext(std::move(BackgroundContext)),
+  Thread([this] { run(); }) {}
+
+BackgroundIndex::~BackgroundIndex() {
+  stop();
+  Thread.join();
+}
+
+void BackgroundIndex::stop() {
+  {
+std::lock_guard Lock(QueueMu);
+ShouldStop = true;
+  }
+  QueueCV.notify_all();
+}
+
+void BackgroundIndex::run() {
+  WithContext Background(std::move(BackgroundContext));
+  while (true) {
+llvm::Optional Task;
+{
+  std::unique_lock Lock(QueueMu);
+  QueueCV.wait(Lock, [&] { return ShouldStop || !Queue.empty(); });
+  if (ShouldStop) {
+Queue.clear();
+QueueCV.notify_all();
+return;
+  }
+  ++NumActiveTasks;
+  Task = std::move(Queue.front());
+  Queue.pop_front();
+}
+(*Task)();
+{
+  std::unique_lock Lock(QueueMu);
+  assert(NumActiveTasks > 0 && "before decrementing");
+  --NumActiveTasks;
+}
+QueueCV.notify_all();
+  }
+}
+
+void BackgroundIndex::blockUntilIdleForTest() {
+  std::unique_lock Lock(QueueMu);
+  QueueCV.wait(Lock, [&] { return Queue.empty() && NumActiveTasks == 0; });
+}
+
+void BackgroundIndex::enqueue(StringRef Directory,
+  tooling::CompileCommand Cmd) {
+  std::lock_guard Lock(QueueMu);
+  enqueueLocked(std::move(Cmd));
+}
+
+void BackgroundIndex::enqueueAll(StringRef Directory,
+ const tooling::CompilationDatabase &CDB) {
+  trace::Span Tracer("BackgroundIndexEnqueueCDB");
+  // FIXME: this function may be slow. Perhaps enqueue a task to re-read the 
CDB
+  // fro

[PATCH] D53032: [clangd] Minimal implementation of automatic static index, behind a flag.

2018-10-15 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE344513: [clangd] Minimal implementation of automatic 
static index (not enabled). (authored by sammccall, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53032?vs=169694&id=169695#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53032

Files:
  clangd/CMakeLists.txt
  clangd/index/Background.cpp
  clangd/index/Background.h
  unittests/clangd/BackgroundIndexTests.cpp
  unittests/clangd/CMakeLists.txt
  unittests/clangd/SyncAPI.cpp
  unittests/clangd/SyncAPI.h

Index: unittests/clangd/SyncAPI.h
===
--- unittests/clangd/SyncAPI.h
+++ unittests/clangd/SyncAPI.h
@@ -17,7 +17,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_SYNCAPI_H
 
 #include "ClangdServer.h"
-#include 
+#include "index/Index.h"
 
 namespace clang {
 namespace clangd {
@@ -50,6 +50,9 @@
 llvm::Expected>
 runDocumentSymbols(ClangdServer &Server, PathRef File);
 
+SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query);
+SymbolSlab runFuzzyFind(const SymbolIndex &Index, const FuzzyFindRequest &Req);
+
 } // namespace clangd
 } // namespace clang
 
Index: unittests/clangd/CMakeLists.txt
===
--- unittests/clangd/CMakeLists.txt
+++ unittests/clangd/CMakeLists.txt
@@ -10,6 +10,7 @@
 
 add_extra_unittest(ClangdTests
   Annotations.cpp
+  BackgroundIndexTests.cpp
   CancellationTests.cpp
   ClangdTests.cpp
   ClangdUnitTests.cpp
Index: unittests/clangd/BackgroundIndexTests.cpp
===
--- unittests/clangd/BackgroundIndexTests.cpp
+++ unittests/clangd/BackgroundIndexTests.cpp
@@ -0,0 +1,37 @@
+#include "SyncAPI.h"
+#include "TestFS.h"
+#include "index/Background.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using testing::UnorderedElementsAre;
+
+namespace clang {
+namespace clangd {
+
+MATCHER_P(Named, N, "") { return arg.Name == N; }
+
+TEST(BackgroundIndexTest, IndexTwoFiles) {
+  MockFSProvider FS;
+  // a.h yields different symbols when included by A.cc vs B.cc.
+  // Currently we store symbols for each TU, so we get both.
+  FS.Files[testPath("root/A.h")] = "void a_h(); void NAME(){}";
+  FS.Files[testPath("root/A.cc")] = "#include \"A.h\"";
+  FS.Files[testPath("root/B.cc")] = "#define NAME bar\n#include \"A.h\"";
+  BackgroundIndex Idx(Context::empty(), "", FS);
+
+  tooling::CompileCommand Cmd;
+  Cmd.Filename = testPath("root/A.cc");
+  Cmd.Directory = testPath("root");
+  Cmd.CommandLine = {"clang++", "-DNAME=foo", testPath("root/A.cc")};
+  Idx.enqueue(testPath("root"), Cmd);
+  Cmd.CommandLine.back() = Cmd.Filename = testPath("root/B.cc");
+  Idx.enqueue(testPath("root"), Cmd);
+
+  Idx.blockUntilIdleForTest();
+  EXPECT_THAT(runFuzzyFind(Idx, ""),
+  UnorderedElementsAre(Named("a_h"), Named("foo"), Named("bar")));
+}
+
+} // namespace clangd
+} // namespace clang
Index: unittests/clangd/SyncAPI.cpp
===
--- unittests/clangd/SyncAPI.cpp
+++ unittests/clangd/SyncAPI.cpp
@@ -125,5 +125,17 @@
   return std::move(*Result);
 }
 
+SymbolSlab runFuzzyFind(const SymbolIndex &Index, StringRef Query) {
+  FuzzyFindRequest Req;
+  Req.Query = Query;
+  return runFuzzyFind(Index, Req);
+}
+
+SymbolSlab runFuzzyFind(const SymbolIndex &Index, const FuzzyFindRequest &Req) {
+  SymbolSlab::Builder Builder;
+  Index.fuzzyFind(Req, [&](const Symbol &Sym) { Builder.insert(Sym); });
+  return std::move(Builder).build();
+}
+
 } // namespace clangd
 } // namespace clang
Index: clangd/index/Background.h
===
--- clangd/index/Background.h
+++ clangd/index/Background.h
@@ -0,0 +1,79 @@
+//===--- Background.h - Build an index in a background thread *- 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_CLANGD_INDEX_BACKGROUND_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_BACKGROUND_H
+
+#include "Context.h"
+#include "FSProvider.h"
+#include "index/FileIndex.h"
+#include "index/Index.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/Support/SHA1.h"
+#include 
+#include 
+#include 
+
+namespace clang {
+namespace clangd {
+
+// Builds an in-memory index by by running the static indexer action over
+// all commands in a compilation database. Indexing happens in the background.
+// FIXME: it should also persist its state on disk for fast start.
+// FIXME: it should watch for changes to files on disk.
+class BackgroundIndex : public SwapIndex {
+public:
+  // FIXME: resource-dir injection should be hoisted s

[PATCH] D53277: [analyzer][NFC][WIP] Collect all -analyzer-config options in a .def file

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 169696.

https://reviews.llvm.org/D53277

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp

Index: lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -56,17 +56,17 @@
 static std::unique_ptr generateWorkList(AnalyzerOptions &Opts,
   SubEngine &subengine) {
   switch (Opts.getExplorationStrategy()) {
-case AnalyzerOptions::ExplorationStrategyKind::DFS:
+case ExplorationStrategyKind::DFS:
   return WorkList::makeDFS();
-case AnalyzerOptions::ExplorationStrategyKind::BFS:
+case ExplorationStrategyKind::BFS:
   return WorkList::makeBFS();
-case AnalyzerOptions::ExplorationStrategyKind::BFSBlockDFSContents:
+case ExplorationStrategyKind::BFSBlockDFSContents:
   return WorkList::makeBFSBlockDFSContents();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirst:
+case ExplorationStrategyKind::UnexploredFirst:
   return WorkList::makeUnexploredFirst();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstQueue:
+case ExplorationStrategyKind::UnexploredFirstQueue:
   return WorkList::makeUnexploredFirstPriorityQueue();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstLocationQueue:
+case ExplorationStrategyKind::UnexploredFirstLocationQueue:
   return WorkList::makeUnexploredFirstPriorityLocationQueue();
   }
 }
Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -49,7 +49,7 @@
   return Result;
 }
 
-AnalyzerOptions::UserModeKind AnalyzerOptions::getUserMode() {
+UserModeKind AnalyzerOptions::getUserMode() {
   if (!UserMode.hasValue()) {
 StringRef ModeStr = getOptionAsString("mode", "deep");
 UserMode = llvm::StringSwitch>(ModeStr)
@@ -61,7 +61,7 @@
   return UserMode.getValue();
 }
 
-AnalyzerOptions::ExplorationStrategyKind
+ExplorationStrategyKind
 AnalyzerOptions::getExplorationStrategy() {
   if (!ExplorationStrategy.hasValue()) {
 StringRef StratStr = getOptionAsString("exploration_strategy",
@@ -182,137 +182,6 @@
   return V.getValue();
 }
 
-bool AnalyzerOptions::includeTemporaryDtorsInCFG() {
-  return getBooleanOption(IncludeTemporaryDtorsInCFG,
-  "cfg-temporary-dtors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeImplicitDtorsInCFG() {
-  return getBooleanOption(IncludeImplicitDtorsInCFG,
-  "cfg-implicit-dtors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeLifetimeInCFG() {
-  return getBooleanOption(IncludeLifetimeInCFG, "cfg-lifetime",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::includeLoopExitInCFG() {
-  return getBooleanOption(IncludeLoopExitInCFG, "cfg-loopexit",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::includeRichConstructorsInCFG() {
-  return getBooleanOption(IncludeRichConstructorsInCFG,
-  "cfg-rich-constructors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeScopesInCFG() {
-  return getBooleanOption(IncludeScopesInCFG,
-  "cfg-scopes",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::mayInlineCXXStandardLibrary() {
-  return getBooleanOption(InlineCXXStandardLibrary,
-  "c++-stdlib-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineTemplateFunctions() {
-  return getBooleanOption(InlineTemplateFunctions,
-  "c++-template-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineCXXAllocator() {
-  return getBooleanOption(InlineCXXAllocator,
-  "c++-allocator-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineCXXContainerMethods() {
-  return getBooleanOption(InlineCXXContainerMethods,
-  "c++-container-inlining",
-  /*Default=*/false);
-}
-
-bool AnalyzerOptions::mayInlineCXXSharedPtrDtor() {
-  return getBooleanOption(InlineCXXSharedPtrDtor,
-  "c++-shared_ptr-inlining",
-  /*Default=*/false);
-}
-
-bool AnalyzerOptions::mayInlineCXXTemporaryDtors() {
-  return getBooleanOption(InlineCXXTemporaryDtors,
-  "c++-temp-dtor-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayI

[PATCH] D53277: [analyzer][NFC][WIP] Collect all -analyzer-config options in a .def file

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 169697.

https://reviews.llvm.org/D53277

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp

Index: lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -56,17 +56,17 @@
 static std::unique_ptr generateWorkList(AnalyzerOptions &Opts,
   SubEngine &subengine) {
   switch (Opts.getExplorationStrategy()) {
-case AnalyzerOptions::ExplorationStrategyKind::DFS:
+case ExplorationStrategyKind::DFS:
   return WorkList::makeDFS();
-case AnalyzerOptions::ExplorationStrategyKind::BFS:
+case ExplorationStrategyKind::BFS:
   return WorkList::makeBFS();
-case AnalyzerOptions::ExplorationStrategyKind::BFSBlockDFSContents:
+case ExplorationStrategyKind::BFSBlockDFSContents:
   return WorkList::makeBFSBlockDFSContents();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirst:
+case ExplorationStrategyKind::UnexploredFirst:
   return WorkList::makeUnexploredFirst();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstQueue:
+case ExplorationStrategyKind::UnexploredFirstQueue:
   return WorkList::makeUnexploredFirstPriorityQueue();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstLocationQueue:
+case ExplorationStrategyKind::UnexploredFirstLocationQueue:
   return WorkList::makeUnexploredFirstPriorityLocationQueue();
   }
 }
Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -49,7 +49,7 @@
   return Result;
 }
 
-AnalyzerOptions::UserModeKind AnalyzerOptions::getUserMode() {
+UserModeKind AnalyzerOptions::getUserMode() {
   if (!UserMode.hasValue()) {
 StringRef ModeStr = getOptionAsString("mode", "deep");
 UserMode = llvm::StringSwitch>(ModeStr)
@@ -61,7 +61,7 @@
   return UserMode.getValue();
 }
 
-AnalyzerOptions::ExplorationStrategyKind
+ExplorationStrategyKind
 AnalyzerOptions::getExplorationStrategy() {
   if (!ExplorationStrategy.hasValue()) {
 StringRef StratStr = getOptionAsString("exploration_strategy",
@@ -182,137 +182,6 @@
   return V.getValue();
 }
 
-bool AnalyzerOptions::includeTemporaryDtorsInCFG() {
-  return getBooleanOption(IncludeTemporaryDtorsInCFG,
-  "cfg-temporary-dtors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeImplicitDtorsInCFG() {
-  return getBooleanOption(IncludeImplicitDtorsInCFG,
-  "cfg-implicit-dtors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeLifetimeInCFG() {
-  return getBooleanOption(IncludeLifetimeInCFG, "cfg-lifetime",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::includeLoopExitInCFG() {
-  return getBooleanOption(IncludeLoopExitInCFG, "cfg-loopexit",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::includeRichConstructorsInCFG() {
-  return getBooleanOption(IncludeRichConstructorsInCFG,
-  "cfg-rich-constructors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeScopesInCFG() {
-  return getBooleanOption(IncludeScopesInCFG,
-  "cfg-scopes",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::mayInlineCXXStandardLibrary() {
-  return getBooleanOption(InlineCXXStandardLibrary,
-  "c++-stdlib-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineTemplateFunctions() {
-  return getBooleanOption(InlineTemplateFunctions,
-  "c++-template-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineCXXAllocator() {
-  return getBooleanOption(InlineCXXAllocator,
-  "c++-allocator-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineCXXContainerMethods() {
-  return getBooleanOption(InlineCXXContainerMethods,
-  "c++-container-inlining",
-  /*Default=*/false);
-}
-
-bool AnalyzerOptions::mayInlineCXXSharedPtrDtor() {
-  return getBooleanOption(InlineCXXSharedPtrDtor,
-  "c++-shared_ptr-inlining",
-  /*Default=*/false);
-}
-
-bool AnalyzerOptions::mayInlineCXXTemporaryDtors() {
-  return getBooleanOption(InlineCXXTemporaryDtors,
-  "c++-temp-dtor-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayI

[PATCH] D53288: [clangd] Optionally use dex for the preamble parts of the dynamic index.

2018-10-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, 
ioeric, ilya-biryukov.

Reuse the old -use-dex-index experiment flag for this.

To avoid breaking the tests, make Dex deduplicate symbols, addressing an old 
FIXME.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53288

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/index/Background.cpp
  clangd/index/FileIndex.cpp
  clangd/index/FileIndex.h
  clangd/index/dex/Dex.h
  clangd/tool/ClangdMain.cpp
  unittests/clangd/DexTests.cpp
  unittests/clangd/FileIndexTests.cpp
  unittests/clangd/TestTU.cpp

Index: unittests/clangd/TestTU.cpp
===
--- unittests/clangd/TestTU.cpp
+++ unittests/clangd/TestTU.cpp
@@ -50,7 +50,8 @@
 
 std::unique_ptr TestTU::index() const {
   auto AST = build();
-  auto Idx = llvm::make_unique();
+  auto Idx = llvm::make_unique(
+  /*URISchemes=*/std::vector{}, /*UseDex=*/true);
   Idx->updatePreamble(Filename, AST.getASTContext(), AST.getPreprocessorPtr());
   Idx->updateMain(Filename, AST);
   return std::move(Idx);
Index: unittests/clangd/FileIndexTests.cpp
===
--- unittests/clangd/FileIndexTests.cpp
+++ unittests/clangd/FileIndexTests.cpp
@@ -86,35 +86,37 @@
 
 TEST(FileSymbolsTest, UpdateAndGet) {
   FileSymbols FS;
-  EXPECT_THAT(getSymbolNames(*FS.buildMemIndex()), UnorderedElementsAre());
+  EXPECT_THAT(getSymbolNames(*FS.buildIndex(IndexType::Light)),
+  UnorderedElementsAre());
 
   FS.update("f1", numSlab(1, 3), refSlab(SymbolID("1"), "f1.cc"));
-  EXPECT_THAT(getSymbolNames(*FS.buildMemIndex()),
+  EXPECT_THAT(getSymbolNames(*FS.buildIndex(IndexType::Light)),
   UnorderedElementsAre("1", "2", "3"));
-  EXPECT_THAT(getRefs(*FS.buildMemIndex(), SymbolID("1")),
+  EXPECT_THAT(getRefs(*FS.buildIndex(IndexType::Light), SymbolID("1")),
   RefsAre({FileURI("f1.cc")}));
 }
 
 TEST(FileSymbolsTest, Overlap) {
   FileSymbols FS;
   FS.update("f1", numSlab(1, 3), nullptr);
   FS.update("f2", numSlab(3, 5), nullptr);
-  EXPECT_THAT(getSymbolNames(*FS.buildMemIndex()),
-  UnorderedElementsAre("1", "2", "3", "4", "5"));
+  for (auto Type : {IndexType::Light, IndexType::Heavy})
+EXPECT_THAT(getSymbolNames(*FS.buildIndex(Type)),
+UnorderedElementsAre("1", "2", "3", "4", "5"));
 }
 
 TEST(FileSymbolsTest, SnapshotAliveAfterRemove) {
   FileSymbols FS;
 
   SymbolID ID("1");
   FS.update("f1", numSlab(1, 3), refSlab(ID, "f1.cc"));
 
-  auto Symbols = FS.buildMemIndex();
+  auto Symbols = FS.buildIndex(IndexType::Light);
   EXPECT_THAT(getSymbolNames(*Symbols), UnorderedElementsAre("1", "2", "3"));
   EXPECT_THAT(getRefs(*Symbols, ID), RefsAre({FileURI("f1.cc")}));
 
   FS.update("f1", nullptr, nullptr);
-  auto Empty = FS.buildMemIndex();
+  auto Empty = FS.buildIndex(IndexType::Light);
   EXPECT_THAT(getSymbolNames(*Empty), UnorderedElementsAre());
   EXPECT_THAT(getRefs(*Empty, ID), ElementsAre());
 
Index: unittests/clangd/DexTests.cpp
===
--- unittests/clangd/DexTests.cpp
+++ unittests/clangd/DexTests.cpp
@@ -492,19 +492,13 @@
"other::A"));
 }
 
-// FIXME(kbobyrev): This test is different for Dex and MemIndex: while
-// MemIndex manages response deduplication, Dex simply returns all matched
-// symbols which means there might be equivalent symbols in the response.
-// Before drop-in replacement of MemIndex with Dex happens, FileIndex
-// should handle deduplication instead.
 TEST(DexTest, DexDeduplicate) {
   std::vector Symbols = {symbol("1"), symbol("2"), symbol("3"),
  symbol("2") /* duplicate */};
   FuzzyFindRequest Req;
   Req.Query = "2";
   Dex I(Symbols, RefSlab(), URISchemes);
-  EXPECT_FALSE(Req.Limit);
-  EXPECT_THAT(match(I, Req), ElementsAre("2", "2"));
+  EXPECT_THAT(match(I, Req), ElementsAre("2"));
 }
 
 TEST(DexTest, DexLimitedNumMatches) {
Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -29,11 +29,11 @@
 using namespace clang;
 using namespace clang::clangd;
 
-// FIXME: remove this option when Dex is stable enough.
+// FIXME: remove this option when Dex is cheap enough.
 static llvm::cl::opt
 UseDex("use-dex-index",
-   llvm::cl::desc("Use experimental Dex static index."),
-   llvm::cl::init(true), llvm::cl::Hidden);
+   llvm::cl::desc("Use experimental Dex dynamic index."),
+   llvm::cl::init(false), llvm::cl::Hidden);
 
 static llvm::cl::opt CompileCommandsDir(
 "compile-commands-dir",
@@ -286,14 +286,15 @@
   if (!ResourceDir.empty())
 Opts.ResourceDir = ResourceDir;
   Opts.BuildDynamicSymbolIndex = Enab

[PATCH] D53274: [analyzer][NFC] Fix inconsistencies in AnalyzerOptions

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 169703.

https://reviews.llvm.org/D53274

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp

Index: lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -68,8 +68,6 @@
   return WorkList::makeUnexploredFirstPriorityQueue();
 case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstLocationQueue:
   return WorkList::makeUnexploredFirstPriorityLocationQueue();
-default:
-  llvm_unreachable("Unexpected case");
   }
 }
 
Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -50,27 +50,24 @@
 }
 
 AnalyzerOptions::UserModeKind AnalyzerOptions::getUserMode() {
-  if (UserMode == UMK_NotSet) {
-StringRef ModeStr =
-Config.insert(std::make_pair("mode", "deep")).first->second;
-UserMode = llvm::StringSwitch(ModeStr)
+  if (!UserMode.hasValue()) {
+StringRef ModeStr = getOptionAsString("mode", "deep");
+UserMode = llvm::StringSwitch>(ModeStr)
   .Case("shallow", UMK_Shallow)
   .Case("deep", UMK_Deep)
-  .Default(UMK_NotSet);
-assert(UserMode != UMK_NotSet && "User mode is invalid.");
+  .Default(None);
+assert(UserMode.getValue() && "User mode is invalid.");
   }
-  return UserMode;
+  return UserMode.getValue();
 }
 
 AnalyzerOptions::ExplorationStrategyKind
 AnalyzerOptions::getExplorationStrategy() {
-  if (ExplorationStrategy == ExplorationStrategyKind::NotSet) {
-StringRef StratStr =
-Config
-.insert(std::make_pair("exploration_strategy", "unexplored_first_queue"))
-.first->second;
+  if (!ExplorationStrategy.hasValue()) {
+StringRef StratStr = getOptionAsString("exploration_strategy",
+   "unexplored_first_queue");
 ExplorationStrategy =
-llvm::StringSwitch(StratStr)
+llvm::StringSwitch>(StratStr)
 .Case("dfs", ExplorationStrategyKind::DFS)
 .Case("bfs", ExplorationStrategyKind::BFS)
 .Case("unexplored_first",
@@ -81,15 +78,15 @@
   ExplorationStrategyKind::UnexploredFirstLocationQueue)
 .Case("bfs_block_dfs_contents",
   ExplorationStrategyKind::BFSBlockDFSContents)
-.Default(ExplorationStrategyKind::NotSet);
-assert(ExplorationStrategy != ExplorationStrategyKind::NotSet &&
+.Default(None);
+assert(ExplorationStrategy.hasValue() &&
"User mode is invalid.");
   }
-  return ExplorationStrategy;
+  return ExplorationStrategy.getValue();
 }
 
 IPAKind AnalyzerOptions::getIPAMode() {
-  if (IPAMode == IPAK_NotSet) {
+  if (!IPAMode.hasValue()) {
 // Use the User Mode to set the default IPA value.
 // Note, we have to add the string to the Config map for the ConfigDumper
 // checker to function properly.
@@ -102,53 +99,41 @@
 assert(DefaultIPA);
 
 // Lookup the ipa configuration option, use the default from User Mode.
-StringRef ModeStr =
-Config.insert(std::make_pair("ipa", DefaultIPA)).first->second;
-IPAKind IPAConfig = llvm::StringSwitch(ModeStr)
+StringRef ModeStr = getOptionAsString("ipa", DefaultIPA);
+IPAMode = llvm::StringSwitch>(ModeStr)
 .Case("none", IPAK_None)
 .Case("basic-inlining", IPAK_BasicInlining)
 .Case("inlining", IPAK_Inlining)
 .Case("dynamic", IPAK_DynamicDispatch)
 .Case("dynamic-bifurcate", IPAK_DynamicDispatchBifurcate)
-.Default(IPAK_NotSet);
-assert(IPAConfig != IPAK_NotSet && "IPA Mode is invalid.");
-
-// Set the member variable.
-IPAMode = IPAConfig;
+.Default(None);
+assert(IPAMode.hasValue() && "IPA Mode is invalid.");
   }
 
-  return IPAMode;
+  return IPAMode.getValue();
 }
 
 bool
 AnalyzerOptions::mayInlineCXXMemberFunction(CXXInlineableMemberKind K) {
   if (getIPAMode() < IPAK_Inlining)
 return false;
 
   if (!CXXMemberInliningMode) {
-static const char *ModeKey = "c++-inlining";
-
-StringRef ModeStr =
-Config.insert(std::make_pair(ModeKey, "destructors")).first->second;
+StringRef ModeStr = getOptionAsString("c++-inlining", "destructors");
 
-CXXInlineableMemberKind &MutableMode =
-  const_cast(CXXMemberInliningMode);
-
-MutableMode = llvm::StringSwitch(ModeStr)
+CXXMemberInliningMode =
+  llvm::StringSwitch>(ModeStr)
   .Case("constructors", CIMK_Constructors)
   .Case("destructors", CIMK_Destructors)
-  .Case("none", CIMK_None)
   .Case("methods", CIMK_MemberFunctions)
-  .Default(CXXInlineableMemberKind());
+  .Case("none", CIMK_No

[PATCH] D53290: [WIP] clangd Transport layer

2018-10-15 Thread Jan Korous via Phabricator via cfe-commits
jkorous created this revision.
jkorous added a reviewer: sammccall.
Herald added subscribers: cfe-commits, kadircet, jfb, arphaman, dexonsmith, 
MaskRay, ioeric, ilya-biryukov, mgorny.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53290

Files:
  clangd/CMakeLists.txt
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/JSONRPCDispatcher.cpp
  clangd/JSONRPCDispatcher.h
  clangd/Protocol.cpp
  clangd/Protocol.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h
  clangd/Transport.cpp
  clangd/Transport.h
  clangd/tool/ClangdMain.cpp

Index: clangd/tool/ClangdMain.cpp
===
--- clangd/tool/ClangdMain.cpp
+++ clangd/tool/ClangdMain.cpp
@@ -315,13 +315,20 @@
   CCOpts.EnableFunctionArgSnippets = EnableFunctionArgSnippets;
   CCOpts.AllScopes = AllScopesCompletion;
 
+  // TODO
+  std::unique_ptr TransportLayer = newJSONTransport(stdin, llvm::outs(), InputStyle);
+  if (!TransportLayer.get()) {
+  // TODO
+  return 42;
+  }
+
   // Initialize and run ClangdLSPServer.
   ClangdLSPServer LSPServer(
-  Out, CCOpts, CompileCommandsDirPath,
+  *TransportLayer.get(), CCOpts, CompileCommandsDirPath,
   /*ShouldUseInMemoryCDB=*/CompileArgsFrom == LSPCompileArgs, Opts);
   constexpr int NoShutdownRequestErrorCode = 1;
   llvm::set_thread_name("clangd.main");
   // Change stdin to binary to not lose \r\n on windows.
   llvm::sys::ChangeStdinToBinary();
-  return LSPServer.run(stdin, InputStyle) ? 0 : NoShutdownRequestErrorCode;
+  return LSPServer.run() ? 0 : NoShutdownRequestErrorCode;
 }
Index: clangd/Transport.h
===
--- /dev/null
+++ clangd/Transport.h
@@ -0,0 +1,94 @@
+//===--- Transport.h - sending and receiving LSP messages ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// The language server protocol is usually implemented by writing messages as
+// JSON-RPC over the stdin/stdout of a subprocess. However other communications
+// mechanisms are possible, such as XPC on mac (see xpc/ directory).
+//
+// The Transport interface allows the mechanism to be replaced, and the JSONRPC
+// Transport is the standard implementation.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H_
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H_
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace clang {
+namespace clangd {
+
+// A transport is responsible for maintaining the connection to a client
+// application, and reading/writing structured messages to it.
+//
+// Transports have limited thread safety requirements:
+//  - messages will not be sent concurrently
+//  - messages MAY be sent while loop() is reading, or its callback is active
+class Transport {
+public:
+  Transport() : shouldTerminateLoop(false) { }
+  virtual ~Transport() = default;
+
+  // Called by Clangd to send messages to the client.
+  // (Because JSON and XPC are so similar, these are concrete and delegate to
+  // sendMessage. We could change this to support more diverse transports).
+  void notifyClient(llvm::StringRef Method, llvm::json::Value Params);
+  void callClient(llvm::StringRef Method, llvm::json::Value Params,
+llvm::json::Value ID);
+  void replyToClient(llvm::json::Value ID, llvm::Expected Result);
+
+  // Implemented by Clangd to handle incoming messages. (See loop() below).
+  class MessageHandler {
+  public:
+// TODO was originally abstract
+virtual ~MessageHandler() {}
+virtual bool notifyServer(llvm::StringRef Method, llvm::json::Value ) = 0;
+virtual bool callServer(llvm::StringRef Method, llvm::json::Value Params,
+  llvm::json::Value ID) = 0;
+virtual bool replyToServer(llvm::json::Value ID,
+   llvm::Expected Result) = 0;
+  };
+  // Called by Clangd to receive messages from the client.
+  // The transport should in turn invoke the handler to process messages.
+  // If handler returns true, the transport should immedately return success.
+  // Otherwise, it returns an error when the transport becomes unusable.
+  // (Because JSON and XPC are so similar, they share handleMessage()).
+  virtual bool loop(MessageHandler &) = 0;
+
+  std::atomic shouldTerminateLoop;
+
+protected:
+  // Common implementation for notify(), call(), and reply().
+  virtual void sendMessage(llvm::json::Value) = 0;
+  // Delegates to notify(), call(), and reply().
+  bool handleMessage(llvm::json::Value, MessageHandler&);
+};
+
+// Controls the way JSON-RPC messages are encoded (both input and output).
+enum JSONSt

[PATCH] D53288: [clangd] Optionally use dex for the preamble parts of the dynamic index.

2018-10-15 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.




Comment at: clangd/ClangdServer.h:79
+/// Use a heavier and faster in-memory index implementation.
+/// FIXME: we should make this true if it isn't too slow!.
+bool HeavyweightDynamicSymbolIndex = false;

"too slow" seems confusing, dex is faster, I think here it means too slow to 
build?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53288



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


[PATCH] D53292: [clangd] Add createIndex in dexp

2018-10-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ioeric, 
ilya-biryukov.

This would allow easily injecting our internal customization.

Also updates the stale "symbol-collection-file" flag.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53292

Files:
  clangd/index/dex/dexp/Dexp.cpp


Index: clangd/index/dex/dexp/Dexp.cpp
===
--- clangd/index/dex/dexp/Dexp.cpp
+++ clangd/index/dex/dexp/Dexp.cpp
@@ -31,9 +31,9 @@
 namespace {
 
 llvm::cl::opt
-SymbolCollection("symbol-collection-file",
- llvm::cl::desc("Path to the file with symbol collection"),
- llvm::cl::Positional, llvm::cl::Required);
+IndexPath("index-path",
+  llvm::cl::desc("Path to the index"),
+  llvm::cl::Positional, llvm::cl::Required);
 
 static const std::string Overview = R"(
 This is an **experimental** interactive tool to process user-provided search
@@ -253,6 +253,10 @@
  llvm::make_unique},
 };
 
+std::unique_ptr createIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*URISchemes=*/{}, /*UseDex=*/true);
+}
+
 } // namespace
 
 int main(int argc, const char *argv[]) {
@@ -262,13 +266,11 @@
 
   std::unique_ptr Index;
   reportTime("Dex build", [&]() {
-Index = loadIndex(SymbolCollection, /*URISchemes=*/{},
-  /*UseDex=*/true);
+Index = createIndex(IndexPath);
   });
 
   if (!Index) {
-llvm::outs()
-<< "ERROR: Please provide a valid path to symbol collection file.\n";
+llvm::outs() << "Failed to create an index.\n";
 return -1;
   }
 


Index: clangd/index/dex/dexp/Dexp.cpp
===
--- clangd/index/dex/dexp/Dexp.cpp
+++ clangd/index/dex/dexp/Dexp.cpp
@@ -31,9 +31,9 @@
 namespace {
 
 llvm::cl::opt
-SymbolCollection("symbol-collection-file",
- llvm::cl::desc("Path to the file with symbol collection"),
- llvm::cl::Positional, llvm::cl::Required);
+IndexPath("index-path",
+  llvm::cl::desc("Path to the index"),
+  llvm::cl::Positional, llvm::cl::Required);
 
 static const std::string Overview = R"(
 This is an **experimental** interactive tool to process user-provided search
@@ -253,6 +253,10 @@
  llvm::make_unique},
 };
 
+std::unique_ptr createIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*URISchemes=*/{}, /*UseDex=*/true);
+}
+
 } // namespace
 
 int main(int argc, const char *argv[]) {
@@ -262,13 +266,11 @@
 
   std::unique_ptr Index;
   reportTime("Dex build", [&]() {
-Index = loadIndex(SymbolCollection, /*URISchemes=*/{},
-  /*UseDex=*/true);
+Index = createIndex(IndexPath);
   });
 
   if (!Index) {
-llvm::outs()
-<< "ERROR: Please provide a valid path to symbol collection file.\n";
+llvm::outs() << "Failed to create an index.\n";
 return -1;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r344520 - [clangd] Use SyncAPI in more places in tests. NFC

2018-10-15 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Mon Oct 15 08:04:03 2018
New Revision: 344520

URL: http://llvm.org/viewvc/llvm-project?rev=344520&view=rev
Log:
[clangd] Use SyncAPI in more places in tests. NFC

Modified:
clang-tools-extra/trunk/clangd/index/Index.h
clang-tools-extra/trunk/unittests/clangd/FileIndexTests.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=344520&r1=344519&r2=344520&view=diff
==
--- clang-tools-extra/trunk/clangd/index/Index.h (original)
+++ clang-tools-extra/trunk/clangd/index/Index.h Mon Oct 15 08:04:03 2018
@@ -286,6 +286,7 @@ class SymbolSlab {
 public:
   using const_iterator = std::vector::const_iterator;
   using iterator = const_iterator;
+  using value_type = Symbol;
 
   SymbolSlab() = default;
 
@@ -294,6 +295,7 @@ public:
   const_iterator find(const SymbolID &SymID) const;
 
   size_t size() const { return Symbols.size(); }
+  bool empty() const { return Symbols.empty(); }
   // Estimates the total memory usage.
   size_t bytes() const {
 return sizeof(*this) + Arena.getTotalMemory() +
@@ -389,6 +391,7 @@ public:
   const_iterator begin() const { return Refs.begin(); }
   const_iterator end() const { return Refs.end(); }
   size_t size() const { return Refs.size(); }
+  bool empty() const { return Refs.empty(); }
 
   size_t bytes() const {
 return sizeof(*this) + Arena.getTotalMemory() +

Modified: clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp?rev=344520&r1=344519&r2=344520&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/FileIndexTests.cpp Mon Oct 15 
08:04:03 2018
@@ -7,12 +7,12 @@
 //
 
//===--===//
 
-#include "Annotations.h"
 #include "AST.h"
+#include "Annotations.h"
 #include "ClangdUnit.h"
+#include "SyncAPI.h"
 #include "TestFS.h"
 #include "TestTU.h"
-#include "gmock/gmock.h"
 #include "index/FileIndex.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/PCHContainerOperations.h"
@@ -20,11 +20,14 @@
 #include "clang/Index/IndexSymbol.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
 using testing::_;
 using testing::AllOf;
+using testing::Contains;
 using testing::ElementsAre;
+using testing::IsEmpty;
 using testing::Pair;
 using testing::UnorderedElementsAre;
 
@@ -35,6 +38,8 @@ MATCHER_P(RefRange, Range, "") {
   Range.end.character);
 }
 MATCHER_P(FileURI, F, "") { return arg.Location.FileURI == F; }
+MATCHER_P(DeclURI, U, "") { return arg.CanonicalDeclaration.FileURI == U; }
+MATCHER_P(QName, N, "") { return (arg.Scope + arg.Name).str() == N; }
 
 namespace clang {
 namespace clangd {
@@ -67,15 +72,6 @@ std::unique_ptr refSlab(const S
   return llvm::make_unique(std::move(Slab).build());
 }
 
-std::vector getSymbolNames(const SymbolIndex &I,
-std::string Query = "") {
-  FuzzyFindRequest Req;
-  Req.Query = Query;
-  std::vector Names;
-  I.fuzzyFind(Req, [&](const Symbol &S) { Names.push_back(S.Name); });
-  return Names;
-}
-
 RefSlab getRefs(const SymbolIndex &I, SymbolID ID) {
   RefsRequest Req;
   Req.IDs = {ID};
@@ -86,11 +82,11 @@ RefSlab getRefs(const SymbolIndex &I, Sy
 
 TEST(FileSymbolsTest, UpdateAndGet) {
   FileSymbols FS;
-  EXPECT_THAT(getSymbolNames(*FS.buildMemIndex()), UnorderedElementsAre());
+  EXPECT_THAT(runFuzzyFind(*FS.buildMemIndex(), ""), IsEmpty());
 
   FS.update("f1", numSlab(1, 3), refSlab(SymbolID("1"), "f1.cc"));
-  EXPECT_THAT(getSymbolNames(*FS.buildMemIndex()),
-  UnorderedElementsAre("1", "2", "3"));
+  EXPECT_THAT(runFuzzyFind(*FS.buildMemIndex(), ""),
+  UnorderedElementsAre(QName("1"), QName("2"), QName("3")));
   EXPECT_THAT(getRefs(*FS.buildMemIndex(), SymbolID("1")),
   RefsAre({FileURI("f1.cc")}));
 }
@@ -99,8 +95,9 @@ TEST(FileSymbolsTest, Overlap) {
   FileSymbols FS;
   FS.update("f1", numSlab(1, 3), nullptr);
   FS.update("f2", numSlab(3, 5), nullptr);
-  EXPECT_THAT(getSymbolNames(*FS.buildMemIndex()),
-  UnorderedElementsAre("1", "2", "3", "4", "5"));
+  EXPECT_THAT(runFuzzyFind(*FS.buildMemIndex(), ""),
+  UnorderedElementsAre(QName("1"), QName("2"), QName("3"),
+   QName("4"), QName("5")));
 }
 
 TEST(FileSymbolsTest, SnapshotAliveAfterRemove) {
@@ -110,27 +107,20 @@ TEST(FileSymbolsTest, SnapshotAliveAfter
   FS.update("f1", numSlab(1, 3), refSlab(ID, "f1.cc"));
 
   auto Symbols = FS.buildMemIndex();
-  EXPECT_THAT(getSymbolNames(*

[PATCH] D53292: [clangd] Add createIndex in dexp

2018-10-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clangd/index/dex/dexp/Dexp.cpp:256
 
+std::unique_ptr createIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*URISchemes=*/{}, /*UseDex=*/true);

createIndex seems a slightly odd name for this (as if writing new files or 
adding new data somehow): openIndex or so?



Comment at: clangd/index/dex/dexp/Dexp.cpp:273
   if (!Index) {
-llvm::outs()
-<< "ERROR: Please provide a valid path to symbol collection file.\n";
+llvm::outs() << "Failed to create an index.\n";
 return -1;

"to open the index"?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53292



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


[PATCH] D53292: [clangd] Add createIndex in dexp

2018-10-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 169712.
hokein marked 2 inline comments as done.
hokein added a comment.

createIndex => openIndex


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53292

Files:
  clangd/index/dex/dexp/Dexp.cpp


Index: clangd/index/dex/dexp/Dexp.cpp
===
--- clangd/index/dex/dexp/Dexp.cpp
+++ clangd/index/dex/dexp/Dexp.cpp
@@ -31,9 +31,9 @@
 namespace {
 
 llvm::cl::opt
-SymbolCollection("symbol-collection-file",
- llvm::cl::desc("Path to the file with symbol collection"),
- llvm::cl::Positional, llvm::cl::Required);
+IndexPath("index-path",
+  llvm::cl::desc("Path to the index"),
+  llvm::cl::Positional, llvm::cl::Required);
 
 static const std::string Overview = R"(
 This is an **experimental** interactive tool to process user-provided search
@@ -253,6 +253,10 @@
  llvm::make_unique},
 };
 
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*URISchemes=*/{}, /*UseDex=*/true);
+}
+
 } // namespace
 
 int main(int argc, const char *argv[]) {
@@ -262,13 +266,11 @@
 
   std::unique_ptr Index;
   reportTime("Dex build", [&]() {
-Index = loadIndex(SymbolCollection, /*URISchemes=*/{},
-  /*UseDex=*/true);
+Index = openIndex(IndexPath);
   });
 
   if (!Index) {
-llvm::outs()
-<< "ERROR: Please provide a valid path to symbol collection file.\n";
+llvm::outs() << "Failed to open the index.\n";
 return -1;
   }
 


Index: clangd/index/dex/dexp/Dexp.cpp
===
--- clangd/index/dex/dexp/Dexp.cpp
+++ clangd/index/dex/dexp/Dexp.cpp
@@ -31,9 +31,9 @@
 namespace {
 
 llvm::cl::opt
-SymbolCollection("symbol-collection-file",
- llvm::cl::desc("Path to the file with symbol collection"),
- llvm::cl::Positional, llvm::cl::Required);
+IndexPath("index-path",
+  llvm::cl::desc("Path to the index"),
+  llvm::cl::Positional, llvm::cl::Required);
 
 static const std::string Overview = R"(
 This is an **experimental** interactive tool to process user-provided search
@@ -253,6 +253,10 @@
  llvm::make_unique},
 };
 
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*URISchemes=*/{}, /*UseDex=*/true);
+}
+
 } // namespace
 
 int main(int argc, const char *argv[]) {
@@ -262,13 +266,11 @@
 
   std::unique_ptr Index;
   reportTime("Dex build", [&]() {
-Index = loadIndex(SymbolCollection, /*URISchemes=*/{},
-  /*UseDex=*/true);
+Index = openIndex(IndexPath);
   });
 
   if (!Index) {
-llvm::outs()
-<< "ERROR: Please provide a valid path to symbol collection file.\n";
+llvm::outs() << "Failed to open the index.\n";
 return -1;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r344521 - [clangd] Add createIndex in dexp

2018-10-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon Oct 15 08:12:40 2018
New Revision: 344521

URL: http://llvm.org/viewvc/llvm-project?rev=344521&view=rev
Log:
[clangd] Add createIndex in dexp

Summary:
This would allow easily injecting our internal customization.

Also updates the stale "symbol-collection-file" flag.

Reviewers: sammccall

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

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

Modified:
clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp

Modified: clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp?rev=344521&r1=344520&r2=344521&view=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp Mon Oct 15 08:12:40 
2018
@@ -31,9 +31,9 @@ using namespace llvm;
 namespace {
 
 llvm::cl::opt
-SymbolCollection("symbol-collection-file",
- llvm::cl::desc("Path to the file with symbol collection"),
- llvm::cl::Positional, llvm::cl::Required);
+IndexPath("index-path",
+  llvm::cl::desc("Path to the index"),
+  llvm::cl::Positional, llvm::cl::Required);
 
 static const std::string Overview = R"(
 This is an **experimental** interactive tool to process user-provided search
@@ -253,6 +253,10 @@ struct {
  llvm::make_unique},
 };
 
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*URISchemes=*/{}, /*UseDex=*/true);
+}
+
 } // namespace
 
 int main(int argc, const char *argv[]) {
@@ -262,13 +266,11 @@ int main(int argc, const char *argv[]) {
 
   std::unique_ptr Index;
   reportTime("Dex build", [&]() {
-Index = loadIndex(SymbolCollection, /*URISchemes=*/{},
-  /*UseDex=*/true);
+Index = openIndex(IndexPath);
   });
 
   if (!Index) {
-llvm::outs()
-<< "ERROR: Please provide a valid path to symbol collection file.\n";
+llvm::outs() << "Failed to open the index.\n";
 return -1;
   }
 


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


[PATCH] D53292: [clangd] Add createIndex in dexp

2018-10-15 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE344521: [clangd] Add createIndex in dexp (authored by 
hokein, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53292?vs=169712&id=169713#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53292

Files:
  clangd/index/dex/dexp/Dexp.cpp


Index: clangd/index/dex/dexp/Dexp.cpp
===
--- clangd/index/dex/dexp/Dexp.cpp
+++ clangd/index/dex/dexp/Dexp.cpp
@@ -31,9 +31,9 @@
 namespace {
 
 llvm::cl::opt
-SymbolCollection("symbol-collection-file",
- llvm::cl::desc("Path to the file with symbol collection"),
- llvm::cl::Positional, llvm::cl::Required);
+IndexPath("index-path",
+  llvm::cl::desc("Path to the index"),
+  llvm::cl::Positional, llvm::cl::Required);
 
 static const std::string Overview = R"(
 This is an **experimental** interactive tool to process user-provided search
@@ -253,6 +253,10 @@
  llvm::make_unique},
 };
 
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*URISchemes=*/{}, /*UseDex=*/true);
+}
+
 } // namespace
 
 int main(int argc, const char *argv[]) {
@@ -262,13 +266,11 @@
 
   std::unique_ptr Index;
   reportTime("Dex build", [&]() {
-Index = loadIndex(SymbolCollection, /*URISchemes=*/{},
-  /*UseDex=*/true);
+Index = openIndex(IndexPath);
   });
 
   if (!Index) {
-llvm::outs()
-<< "ERROR: Please provide a valid path to symbol collection file.\n";
+llvm::outs() << "Failed to open the index.\n";
 return -1;
   }
 


Index: clangd/index/dex/dexp/Dexp.cpp
===
--- clangd/index/dex/dexp/Dexp.cpp
+++ clangd/index/dex/dexp/Dexp.cpp
@@ -31,9 +31,9 @@
 namespace {
 
 llvm::cl::opt
-SymbolCollection("symbol-collection-file",
- llvm::cl::desc("Path to the file with symbol collection"),
- llvm::cl::Positional, llvm::cl::Required);
+IndexPath("index-path",
+  llvm::cl::desc("Path to the index"),
+  llvm::cl::Positional, llvm::cl::Required);
 
 static const std::string Overview = R"(
 This is an **experimental** interactive tool to process user-provided search
@@ -253,6 +253,10 @@
  llvm::make_unique},
 };
 
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*URISchemes=*/{}, /*UseDex=*/true);
+}
+
 } // namespace
 
 int main(int argc, const char *argv[]) {
@@ -262,13 +266,11 @@
 
   std::unique_ptr Index;
   reportTime("Dex build", [&]() {
-Index = loadIndex(SymbolCollection, /*URISchemes=*/{},
-  /*UseDex=*/true);
+Index = openIndex(IndexPath);
   });
 
   if (!Index) {
-llvm::outs()
-<< "ERROR: Please provide a valid path to symbol collection file.\n";
+llvm::outs() << "Failed to open the index.\n";
 return -1;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53084: [clang-doc] Add unit tests for YAML

2018-10-15 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp:45
+  assert(!Err);
+  std::string Expected =
+  "---\n"

Nit: use raw strings here as well, the same here below.


https://reviews.llvm.org/D53084



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


[PATCH] D53293: add riscv32e to the clang

2018-10-15 Thread Daliang Xu via Phabricator via cfe-commits
xudaliang.pku created this revision.
xudaliang.pku added a reviewer: asb.
Herald added subscribers: cfe-commits, jocewei, PkmX, the_o, brucehoult, 
MartinMosbeck, rogfer01, mgrang, edward-jones, zzheng, jrtc27, shiva0217, 
kito-cheng, niosHD, sabuasal, apazos, simoncook, johnrusso, rbar.

1. add optioins -march=rv32e
2. add ilp32e


Repository:
  rC Clang

https://reviews.llvm.org/D53293

Files:
  lib/Basic/Targets.cpp
  lib/Basic/Targets/RISCV.cpp
  lib/Basic/Targets/RISCV.h
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/ToolChains/Arch/RISCV.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Linux.cpp

Index: lib/Driver/ToolChains/Linux.cpp
===
--- lib/Driver/ToolChains/Linux.cpp
+++ lib/Driver/ToolChains/Linux.cpp
@@ -191,7 +191,8 @@
   Triple.getEnvironment() == llvm::Triple::GNUX32)
 return "libx32";
 
-  if (Triple.getArch() == llvm::Triple::riscv32)
+  if (Triple.getArch() == llvm::Triple::riscv32 ||
+  Triple.getArch() == llvm::Triple::riscv32e)
 return "lib32";
 
   return Triple.isArch32Bit() ? "lib" : "lib64";
@@ -254,8 +255,9 @@
   const bool IsAndroid = Triple.isAndroid();
   const bool IsMips = Triple.isMIPS();
   const bool IsHexagon = Arch == llvm::Triple::hexagon;
-  const bool IsRISCV =
-  Arch == llvm::Triple::riscv32 || Arch == llvm::Triple::riscv64;
+  const bool IsRISCV = Arch == llvm::Triple::riscv32 ||
+   Arch == llvm::Triple::riscv64 ||
+   Triple.getArch() == llvm::Triple::riscv32e;
 
   if (IsMips && !SysRoot.empty())
 ExtraOpts.push_back("--sysroot=" + SysRoot);
@@ -574,6 +576,8 @@
 Loader =
 (tools::ppc::hasPPCAbiArg(Args, "elfv1")) ? "ld64.so.1" : "ld64.so.2";
 break;
+  // not sure whether riscv32e use riscv32-ld,
+  case llvm::Triple::riscv32e:
   case llvm::Triple::riscv32: {
 StringRef ABIName = tools::riscv::getRISCVABI(Args, Triple);
 LibDir = "lib";
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -252,6 +252,8 @@
 return "elf64lppc";
   case llvm::Triple::riscv32:
 return "elf32lriscv";
+  case llvm::Triple::riscv32e:
+return "elf32lriscv";
   case llvm::Triple::riscv64:
 return "elf64lriscv";
   case llvm::Triple::sparc:
@@ -607,6 +609,7 @@
 break;
   }
   case llvm::Triple::riscv32:
+  case llvm::Triple::riscv32e:
   case llvm::Triple::riscv64: {
 StringRef ABIName = riscv::getRISCVABI(Args, getToolChain().getTriple());
 CmdArgs.push_back("-mabi");
@@ -842,7 +845,8 @@
 }
 
 static bool isRISCV(llvm::Triple::ArchType Arch) {
-  return Arch == llvm::Triple::riscv32 || Arch == llvm::Triple::riscv64;
+  return Arch == llvm::Triple::riscv32 || Arch == llvm::Triple::riscv64 ||
+ Arch == llvm::Triple::riscv32e;
 }
 
 static Multilib makeMultilib(StringRef commonSuffix) {
@@ -1396,6 +1400,8 @@
 
   FilterNonExistent NonExistent(Path, "/crtbegin.o", D.getVFS());
   Multilib Ilp32 = makeMultilib("lib32/ilp32").flag("+m32").flag("+mabi=ilp32");
+  Multilib Ilp32e =
+  makeMultilib("lib32/ilp32e").flag("+m32").flag("+mabi=ilp32e");
   Multilib Ilp32f =
   makeMultilib("lib32/ilp32f").flag("+m32").flag("+mabi=ilp32f");
   Multilib Ilp32d =
@@ -1405,16 +1411,19 @@
   Multilib Lp64d = makeMultilib("lib64/lp64d").flag("+m64").flag("+mabi=lp64d");
   MultilibSet RISCVMultilibs =
   MultilibSet()
-  .Either({Ilp32, Ilp32f, Ilp32d, Lp64, Lp64f, Lp64d})
+  .Either({Ilp32, Ilp32e, Ilp32f, Ilp32d, Lp64, Lp64f, Lp64d})
   .FilterOut(NonExistent);
 
   Multilib::flags_list Flags;
   bool IsRV64 = TargetTriple.getArch() == llvm::Triple::riscv64;
+  bool IsRV32E = TargetTriple.getArch() == llvm::Triple::riscv32e;
   StringRef ABIName = tools::riscv::getRISCVABI(Args, TargetTriple);
 
   addMultilibFlag(!IsRV64, "m32", Flags);
+  addMultilibFlag(IsRV32E, "m32", Flags);
   addMultilibFlag(IsRV64, "m64", Flags);
   addMultilibFlag(ABIName == "ilp32", "mabi=ilp32", Flags);
+  addMultilibFlag(ABIName == "ilp32e", "mabi=ilp32e", Flags);
   addMultilibFlag(ABIName == "ilp32f", "mabi=ilp32f", Flags);
   addMultilibFlag(ABIName == "ilp32d", "mabi=ilp32d", Flags);
   addMultilibFlag(ABIName == "lp64", "mabi=lp64", Flags);
@@ -2401,6 +2410,7 @@
   case llvm::Triple::ppc64:
   case llvm::Triple::ppc64le:
   case llvm::Triple::riscv32:
+  case llvm::Triple::riscv32e:
   case llvm::Triple::riscv64:
   case llvm::Triple::systemz:
   case llvm::Triple::mips:
@@ -2549,7 +2559,8 @@
!getTriple().hasEnvironment()) ||
   getTriple().getOS() == llvm::Triple::Solaris ||
   getTriple().getArch() == llvm::Triple::riscv32 ||
-  getTriple().getArch() == llvm::Triple::riscv64;
+  getTriple().getArch() == llvm::Triple::riscv64 ||
+  getTriple().getArch() == llvm::Triple::riscv32e;
 
   if (DriverArgs.hasFlag(op

[PATCH] D53286: [clangd] Refactor JSON-over-stdin/stdout code into Transport abstraction.

2018-10-15 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

For reference, @jkorous has a WIP in https://reviews.llvm.org/D53290.
It's scope is a superset, and I think everything in common is basically the 
same (they were both based on a common prototype).
Jan is out at the moment, so I think it makes sense to move ahead with this 
piece - it's progress, and the smaller scope makes landing the change easier.

I just realized though there are no JSONTransport unit tests in this patch, 
I'll add those.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53286



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


[PATCH] D53220: Remove possibility to change compile database path at runtime

2018-10-15 Thread Simon Marchi via Phabricator via cfe-commits
simark marked an inline comment as done.
simark added inline comments.



Comment at: clangd/ClangdLSPServer.h:90
   void reparseOpenedFiles();
+  void applyConfiguration(const ClangdInitializationOptions &Settings);
   void applyConfiguration(const ClangdConfigurationParamsChange &Settings);

sammccall wrote:
> Prefer a different name for this function - an overload set should have 
> similar semantics and these are quite different (pseudo-constructor vs 
> mutation allowed at any time).
Ok, I'll think about a better name.



Comment at: clangd/Protocol.h:422
+struct ClangdInitializationOptions : public ClangdConfigurationParamsChange {
+  llvm::Optional compilationDatabasePath;
+};

sammccall wrote:
> Can we just move this to InitializeParams as a clangd extension?
> Doing tricks with inheritance here makes the protocol harder to understand.
> Can we just move this to InitializeParams as a clangd extension?

Do you mean move it in the JSON, so it looks like this on the wire?

```
{
  "method": "initialize",
  "params": {
"compilationDatabasePath": "",
...
  }
}
```

instead of 

```
{
  "method": "initialize",
  "params": {
"initializationOptions": {
  "compilationDatabasePath": ""
},
...
  }
}
```

?

I think `initializationOptions` is a good place for this to be, I wouldn't 
change that..  If you don't like the inheritance, we can just get rid of it in 
our code and have two separate versions of the deserializing code.  We designed 
it so `didChangeConfiguration` and the initialization options would share the 
same structure, but it doesn't have to stay that way.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53220



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


[PATCH] D50616: [Fixed Point Arithmetic] FixedPointCast

2018-10-15 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 169714.
leonardchan marked an inline comment as done.

Repository:
  rC Clang

https://reviews.llvm.org/D50616

Files:
  include/clang/AST/OperationKinds.def
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticCommonKinds.td
  lib/AST/Expr.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprConstant.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/Edit/RewriteObjCFoundationAPI.cpp
  lib/Sema/Sema.cpp
  lib/Sema/SemaExpr.cpp
  lib/StaticAnalyzer/Core/ExprEngineC.cpp
  test/Frontend/fixed_point_conversions.c
  test/Frontend/fixed_point_unknown_conversions.c

Index: test/Frontend/fixed_point_unknown_conversions.c
===
--- /dev/null
+++ test/Frontend/fixed_point_unknown_conversions.c
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -verify -ffixed-point %s
+
+void func() {
+  _Bool b;
+  char c;
+  int i;
+  float f;
+  double d;
+  double _Complex dc;
+  int _Complex ic;
+  struct S {
+int i;
+  } s;
+  enum E {
+A
+  } e;
+  int *ptr;
+  typedef int int_t;
+  int_t i2;
+
+  _Accum accum;
+  _Fract fract = accum; // ok
+  _Accum *accum_ptr;
+
+  accum = b;   // expected-error{{conversion between fixed point and '_Bool' is not yet supported}}
+  accum = i;   // expected-error{{conversion between fixed point and 'int' is not yet supported}}
+  accum = i;   // expected-error{{conversion between fixed point and 'int' is not yet supported}}
+  accum = f;   // expected-error{{conversion between fixed point and 'float' is not yet supported}}
+  accum = d;   // expected-error{{conversion between fixed point and 'double' is not yet supported}}
+  accum = dc;  // expected-error{{conversion between fixed point and '_Complex double' is not yet supported}}
+  accum = ic;  // expected-error{{conversion between fixed point and '_Complex int' is not yet supported}}
+  accum = s;   // expected-error{{assigning to '_Accum' from incompatible type 'struct S'}}
+  accum = e;   // expected-error{{conversion between fixed point and 'enum E' is not yet supported}}
+  accum = ptr; // expected-error{{assigning to '_Accum' from incompatible type 'int *'}}
+  accum_ptr = ptr; // expected-warning{{incompatible pointer types assigning to '_Accum *' from 'int *'}}
+  accum = i2;  // expected-error{{conversion between fixed point and 'int_t' (aka 'int') is not yet supported}}
+
+  b = accum;   // expected-error{{conversion between fixed point and '_Bool' is not yet supported}}
+  c = accum;   // expected-error{{conversion between fixed point and 'char' is not yet supported}}
+  i = accum;   // expected-error{{conversion between fixed point and 'int' is not yet supported}}
+  f = accum;   // expected-error{{conversion between fixed point and 'float' is not yet supported}}
+  d = accum;   // expected-error{{conversion between fixed point and 'double' is not yet supported}}
+  dc = accum;  // expected-error{{conversion between fixed point and '_Complex double' is not yet supported}}
+  ic = accum;  // expected-error{{conversion between fixed point and '_Complex int' is not yet supported}}
+  s = accum;   // expected-error{{assigning to 'struct S' from incompatible type '_Accum'}}
+  e = accum;   // expected-error{{conversion between fixed point and 'enum E' is not yet supported}}
+  ptr = accum; // expected-error{{assigning to 'int *' from incompatible type '_Accum'}}
+  ptr = accum_ptr; // expected-warning{{incompatible pointer types assigning to 'int *' from '_Accum *'}}
+  i2 = accum;  // expected-error{{conversion between fixed point and 'int' is not yet supported}}
+}
Index: test/Frontend/fixed_point_conversions.c
===
--- /dev/null
+++ test/Frontend/fixed_point_conversions.c
@@ -0,0 +1,283 @@
+// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s -check-prefix=DEFAULT
+// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - -fpadding-on-unsigned-fixed-point | FileCheck %s -check-prefix=SAME
+
+void TestFixedPointCastSameType() {
+  _Accum a = 2.5k;
+  _Accum a2 = a;
+  // DEFAULT:  [[ACCUM:%[0-9]+]] = load i32, i32* %a, align 4
+  // DEFAULT-NEXT: store i32 [[ACCUM]], i32* %a2, align 4
+
+  a2 = (_Accum)a;
+  // DEFAULT:  [[ACCUM:%[0-9]+]] = load i32, i32* %a, align 4
+  // DEFAULT-NEXT: store i32 [[ACCUM]], i32* %a2, align 4
+}
+
+void TestFixedPointCastDown() {
+  long _Accum la = 2.5lk;
+  _Accum a = la;
+  // DEFAULT:  [[LACCUM:%[0-9]+]] = load i64, i64* %la, align 8
+  // DEFAULT-NEXT: [[ACCUM_AS_I64:%[0-9]+]] = ashr i64 [[LACCUM]], 16
+  // DEFAULT-NEXT: [[ACCUM:%[0-9]+]] = trunc i64 [[ACCUM_AS_I64]] to i32
+  // DEFAULT-NEXT: store i32 [[ACCUM]], i32* %a, align 4
+
+  a = (_Accum)la;
+  // DEFAULT:  [[LACCUM:%[0-9]+]] = load i64, i64* %la, align 8
+  //

r344530 - [Fixed Point Arithmetic] FixedPointCast

2018-10-15 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Mon Oct 15 09:07:02 2018
New Revision: 344530

URL: http://llvm.org/viewvc/llvm-project?rev=344530&view=rev
Log:
[Fixed Point Arithmetic] FixedPointCast

This patch is a part of https://reviews.llvm.org/D48456 in an attempt to
split them up. This contains the code for casting between fixed point types
and other fixed point types.

The method for converting between fixed point types is based off the convert()
method in APFixedPoint.

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

Added:
cfe/trunk/test/Frontend/fixed_point_conversions.c
cfe/trunk/test/Frontend/fixed_point_unknown_conversions.c
Modified:
cfe/trunk/include/clang/AST/OperationKinds.def
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprComplex.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp

Modified: cfe/trunk/include/clang/AST/OperationKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OperationKinds.def?rev=344530&r1=344529&r2=344530&view=diff
==
--- cfe/trunk/include/clang/AST/OperationKinds.def (original)
+++ cfe/trunk/include/clang/AST/OperationKinds.def Mon Oct 15 09:07:02 2018
@@ -197,6 +197,10 @@ CAST_OPERATION(IntegralToBoolean)
 ///float f = i;
 CAST_OPERATION(IntegralToFloating)
 
+/// CK_FixedPointCast - Fixed point to fixed point.
+///(_Accum) 0.5r
+CAST_OPERATION(FixedPointCast)
+
 /// CK_FloatingToIntegral - Floating point to integral.  Rounds
 /// towards zero, discarding any fractional component.
 ///(int) f

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=344530&r1=344529&r2=344530&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Oct 15 09:07:02 2018
@@ -2066,7 +2066,8 @@ public:
 STK_Integral,
 STK_Floating,
 STK_IntegralComplex,
-STK_FloatingComplex
+STK_FloatingComplex,
+STK_FixedPoint
   };
 
   /// Given that this is a scalar type, classify it.

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=344530&r1=344529&r2=344530&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Mon Oct 15 09:07:02 
2018
@@ -172,6 +172,8 @@ def err_too_large_for_fixed_point : Erro
   "this value is too large for this fixed point type">;
 def err_fixed_point_not_enabled : Error<"compile with "
   "'-ffixed-point' to enable fixed point types">;
+def err_unimplemented_conversion_with_fixed_point_type : Error<
+  "conversion between fixed point and %0 is not yet supported">;
 
 // SEH
 def err_seh_expected_handler : Error<

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=344530&r1=344529&r2=344530&view=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Oct 15 09:07:02 2018
@@ -1644,6 +1644,7 @@ bool CastExpr::CastConsistency() const {
   case CK_ZeroToOCLEvent:
   case CK_ZeroToOCLQueue:
   case CK_IntToOCLSampler:
+  case CK_FixedPointCast:
 assert(!getType()->isBooleanType() && "unheralded conversion to bool");
 goto CheckNoBasePath;
 

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=344530&r1=344529&r2=344530&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Oct 15 09:07:02 2018
@@ -9556,6 +9556,7 @@ bool IntExprEvaluator::VisitCastExpr(con
   case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
+  case CK_FixedPointCast:
 llvm_unreachable("invalid cast kind for integral value");
 
   case CK_BitCast:
@@ -10090,6 +10091,7 @@ bool ComplexExprEvaluator::VisitCastExpr
   case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
+  case CK_FixedPointCast:
 llvm_unreachable("invalid cast kind for complex value");
 
   case CK_LValueToRValue:

Modified: cfe/tr

[PATCH] D51762: First part of the calendar stuff

2018-10-15 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists accepted this revision.
mclow.lists added a comment.

After discussions with @EricWF, I landed a modified version as revision 344529.


https://reviews.llvm.org/D51762



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


[PATCH] D50616: [Fixed Point Arithmetic] FixedPointCast

2018-10-15 Thread Leonard Chan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL344530: [Fixed Point Arithmetic] FixedPointCast (authored by 
leonardchan, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D50616?vs=169714&id=169716#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50616

Files:
  cfe/trunk/include/clang/AST/OperationKinds.def
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
  cfe/trunk/lib/AST/Expr.cpp
  cfe/trunk/lib/AST/ExprConstant.cpp
  cfe/trunk/lib/AST/Type.cpp
  cfe/trunk/lib/CodeGen/CGExpr.cpp
  cfe/trunk/lib/CodeGen/CGExprAgg.cpp
  cfe/trunk/lib/CodeGen/CGExprComplex.cpp
  cfe/trunk/lib/CodeGen/CGExprConstant.cpp
  cfe/trunk/lib/CodeGen/CGExprScalar.cpp
  cfe/trunk/lib/Edit/RewriteObjCFoundationAPI.cpp
  cfe/trunk/lib/Sema/Sema.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  cfe/trunk/test/Frontend/fixed_point_conversions.c
  cfe/trunk/test/Frontend/fixed_point_unknown_conversions.c

Index: cfe/trunk/include/clang/AST/Type.h
===
--- cfe/trunk/include/clang/AST/Type.h
+++ cfe/trunk/include/clang/AST/Type.h
@@ -2066,7 +2066,8 @@
 STK_Integral,
 STK_Floating,
 STK_IntegralComplex,
-STK_FloatingComplex
+STK_FloatingComplex,
+STK_FixedPoint
   };
 
   /// Given that this is a scalar type, classify it.
Index: cfe/trunk/include/clang/AST/OperationKinds.def
===
--- cfe/trunk/include/clang/AST/OperationKinds.def
+++ cfe/trunk/include/clang/AST/OperationKinds.def
@@ -197,6 +197,10 @@
 ///float f = i;
 CAST_OPERATION(IntegralToFloating)
 
+/// CK_FixedPointCast - Fixed point to fixed point.
+///(_Accum) 0.5r
+CAST_OPERATION(FixedPointCast)
+
 /// CK_FloatingToIntegral - Floating point to integral.  Rounds
 /// towards zero, discarding any fractional component.
 ///(int) f
Index: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
@@ -172,6 +172,8 @@
   "this value is too large for this fixed point type">;
 def err_fixed_point_not_enabled : Error<"compile with "
   "'-ffixed-point' to enable fixed point types">;
+def err_unimplemented_conversion_with_fixed_point_type : Error<
+  "conversion between fixed point and %0 is not yet supported">;
 
 // SEH
 def err_seh_expected_handler : Error<
Index: cfe/trunk/test/Frontend/fixed_point_conversions.c
===
--- cfe/trunk/test/Frontend/fixed_point_conversions.c
+++ cfe/trunk/test/Frontend/fixed_point_conversions.c
@@ -0,0 +1,283 @@
+// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s -check-prefix=DEFAULT
+// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - -fpadding-on-unsigned-fixed-point | FileCheck %s -check-prefix=SAME
+
+void TestFixedPointCastSameType() {
+  _Accum a = 2.5k;
+  _Accum a2 = a;
+  // DEFAULT:  [[ACCUM:%[0-9]+]] = load i32, i32* %a, align 4
+  // DEFAULT-NEXT: store i32 [[ACCUM]], i32* %a2, align 4
+
+  a2 = (_Accum)a;
+  // DEFAULT:  [[ACCUM:%[0-9]+]] = load i32, i32* %a, align 4
+  // DEFAULT-NEXT: store i32 [[ACCUM]], i32* %a2, align 4
+}
+
+void TestFixedPointCastDown() {
+  long _Accum la = 2.5lk;
+  _Accum a = la;
+  // DEFAULT:  [[LACCUM:%[0-9]+]] = load i64, i64* %la, align 8
+  // DEFAULT-NEXT: [[ACCUM_AS_I64:%[0-9]+]] = ashr i64 [[LACCUM]], 16
+  // DEFAULT-NEXT: [[ACCUM:%[0-9]+]] = trunc i64 [[ACCUM_AS_I64]] to i32
+  // DEFAULT-NEXT: store i32 [[ACCUM]], i32* %a, align 4
+
+  a = (_Accum)la;
+  // DEFAULT:  [[LACCUM:%[0-9]+]] = load i64, i64* %la, align 8
+  // DEFAULT-NEXT: [[ACCUM_AS_I64:%[0-9]+]] = ashr i64 [[LACCUM]], 16
+  // DEFAULT-NEXT: [[ACCUM:%[0-9]+]] = trunc i64 [[ACCUM_AS_I64]] to i32
+  // DEFAULT-NEXT: store i32 [[ACCUM]], i32* %a, align 4
+
+  short _Accum sa = a;
+  // DEFAULT:  [[ACCUM:%[0-9]+]] = load i32, i32* %a, align 4
+  // DEFAULT-NEXT: [[SACCUM_AS_I32:%[0-9]+]] = ashr i32 [[ACCUM]], 8
+  // DEFAULT-NEXT: [[SACCUM:%[0-9]+]] = trunc i32 [[SACCUM_AS_I32]] to i16
+  // DEFAULT-NEXT: store i16 [[SACCUM]], i16* %sa, align 2
+
+  sa = (short _Accum)a;
+  // DEFAULT:  [[ACCUM:%[0-9]+]] = load i32, i32* %a, align 4
+  // DEFAULT-NEXT: [[SACCUM_AS_I32:%[0-9]+]] = ashr i32 [[ACCUM]], 8
+  // DEFAULT-NEXT: [[SACCUM:%[0-9]+]] = trunc i32 [[SACCUM_AS_I32]] to i16
+  // DEFAULT-NEXT: store i16 [[SACCUM]], i16* %sa, align 2
+}
+
+void TestFixedPointCastUp() {
+  short _Accum sa = 2.5hk;
+  _Accum a = sa;
+  // DEFAULT:  [[SACCUM:%[0-9]+]] = load i16, i16* %sa, align 2
+  // DEFAULT-NEXT: [[SACCUM_BUFF:%[0-9]+]] = sext i16 [[SACCUM]] to i32
+  // DEFAULT-NEXT: [[ACCUM:%[0-9]+]] = shl i32 [[S

[PATCH] D53025: [clang-tidy] implement new check for const return types.

2018-10-15 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added inline comments.



Comment at: clang-tidy/readability/ConstValueReturnCheck.cpp:64
+
+  // Fix the definition.
+  llvm::Optional Loc = findConstToRemove(Def, Result);

JonasToth wrote:
> ymandel wrote:
> > JonasToth wrote:
> > > ymandel wrote:
> > > > JonasToth wrote:
> > > > > I feel that this comment doesn't add value. Could you please either 
> > > > > make it more expressive or remove it?
> > > > Agreed. I merged the comment below into this one, so one comment 
> > > > describes the rest of the control flow in this block.
> > > Did I tell you the "only one diagnostic in-flight" thing? :D
> > > I told you wrong stuff as you already figured out in the code. Please 
> > > adjust this comment and the additional scope is not necessary too.
> > But, I think you are *correct* in this assertion.  When I tried multiple 
> > in-flight diagnostics, it failed with error:
> > 
> > clang-tidy: 
> > /usr/local/google/home/yitzhakm/Projects/llvm/llvm/tools/clang/include/clang/Basic/Diagnostic.h:1297:
> >  clang::DiagnosticBuilder 
> > clang::DiagnosticsEngine::Report(clang::SourceLocation, unsigned int): 
> > Assertion `CurDiagID == std::numeric_limits::max() && "Multiple 
> > diagnostics in flight at once!"' failed.
> > 
> > Am I doing something wrong?
> > 
> > 
> Then let me revert what I said and claim the first thing again :D 
> 
> I think, the issue is, that you have the `auto Diag = diag()` object not 
> destroyed before the next one is created. So temporarily storing the 
> locations for the problematic transformations might be necessary to close the 
> scope of the `Diag` first and then emit the notes.
> 
> It would be a good idea, to make a function that returns you a list of FixIts 
> and the list of problematic transformations.
> Having these 2 lists (best is probably `llvm::SmallVector`, see 
> https://llvm.org/docs/ProgrammersManual.html#dss-smallvector) simplifies 
> creating the diagnostics a lot.
> Then you have 2 scopes for emitting, one scope for the actual warning and 
> replacement and the second scope for emitting the fail-notes.
> 
> These 2 scopes could even be methods (necessary to access `diag()`).
Sounds good. Here's a stab at this restructuring:
https://reviews.llvm.org/differential/diff/169718/

Doesn't seem worth factoring the actual diag() calls into methods, but let me 
know what you think.

I'll go ahead with other changes as well, just wanted to get this out there...


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53025



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


[PATCH] D53220: Remove possibility to change compile database path at runtime

2018-10-15 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.

I think it'd be a good idea to separate out the on-initialization vs 
dynamically-changing parameters more - I think they should probably be disjoint 
in fact.

But we can discuss/implement that separately from this patch - the change 
itself is really nice.




Comment at: clangd/ClangdLSPServer.cpp:433
 
 reparseOpenedFiles();
   }

sammccall wrote:
> This isn't needed, the compilation database can only be set during 
> initialization.
It's still here... maybe forgot to upload a new diff?
(Just to be clear: I meant `reparseOpenFiles` doesn't need to be called, as 
there are none.)



Comment at: clangd/ClangdLSPServer.h:90
   void reparseOpenedFiles();
+  void applyConfiguration(const ClangdInitializationOptions &Settings);
   void applyConfiguration(const ClangdConfigurationParamsChange &Settings);

simark wrote:
> sammccall wrote:
> > Prefer a different name for this function - an overload set should have 
> > similar semantics and these are quite different (pseudo-constructor vs 
> > mutation allowed at any time).
> Ok, I'll think about a better name.
(In fact, this could also live directly in `onInitialize`, I think?)



Comment at: clangd/Protocol.h:422
+struct ClangdInitializationOptions : public ClangdConfigurationParamsChange {
+  llvm::Optional compilationDatabasePath;
+};

simark wrote:
> sammccall wrote:
> > Can we just move this to InitializeParams as a clangd extension?
> > Doing tricks with inheritance here makes the protocol harder to understand.
> > Can we just move this to InitializeParams as a clangd extension?
> 
> Do you mean move it in the JSON, so it looks like this on the wire?
> 
> ```
> {
>   "method": "initialize",
>   "params": {
> "compilationDatabasePath": "",
> ...
>   }
> }
> ```
> 
> instead of 
> 
> ```
> {
>   "method": "initialize",
>   "params": {
> "initializationOptions": {
>   "compilationDatabasePath": ""
> },
> ...
>   }
> }
> ```
> 
> ?
> 
> I think `initializationOptions` is a good place for this to be, I wouldn't 
> change that..  If you don't like the inheritance, we can just get rid of it 
> in our code and have two separate versions of the deserializing code.  We 
> designed it so `didChangeConfiguration` and the initialization options would 
> share the same structure, but it doesn't have to stay that way.
> Do you mean move it in the JSON, so it looks like this on the wire?

Well, since you asked... :-) I'm not going to push hard for it (this patch is 
certainly a win already), but I do think that would be much clearer.

The current protocol has `InitializeParams` and `ClangdInitializationOptions`, 
and it's not clear semantically what the distinction between them is.

With hindsight, I think something like this would be easier to follow:
```
// Clangd options that may be set at startup.
struct InitializeParams {
  // Clangd extension: override the path used to load the CDB.
  Optional compilationDatabasePath;
  // Provides initial configuration as if by workspace/updateConfiguration.
  Optional initialConfiguration;
}
// Clangd options that may be set dynamically at runtime.
struct ClangdConfigurationParamsChange { ... }
```
though even here, the benefit from being able to inline the initial 
configuration into the initalize message is unclear to me. The implementation 
has to support dynamic updates in any case, so why not make use of that?

> We designed it so didChangeConfiguration and the initialization options would 
> share the same structure

This makes sense, but if they're diverging, I'm not sure that keeping them 
*mostly* the same brings more benefits than confusion.

--

That said, if you prefer to keep the JSON as it is, that's fine. (If we grow 
more extensions, we may want to reorganize in future though?)
My main concern is the use of inheritance here, and how it provides a default 
(configuration-change options can be provided at startup) that doesn't seem 
obviously correct and is hard to opt out of.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53220



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


[clang-tools-extra] r344533 - [clangd] Revert include path change in Dexp. NFC

2018-10-15 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Mon Oct 15 09:47:45 2018
New Revision: 344533

URL: http://llvm.org/viewvc/llvm-project?rev=344533&view=rev
Log:
[clangd] Revert include path change in Dexp. NFC

Modified:
clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt
clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp

Modified: clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt?rev=344533&r1=344532&r2=344533&view=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clangd/index/dex/dexp/CMakeLists.txt Mon Oct 15 
09:47:45 2018
@@ -1,5 +1,3 @@
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
-include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../..)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../)
 
 set(LLVM_LINK_COMPONENTS

Modified: clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp?rev=344533&r1=344532&r2=344533&view=diff
==
--- clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/dexp/Dexp.cpp Mon Oct 15 09:47:45 
2018
@@ -12,9 +12,9 @@
 //
 
//===--===//
 
-#include "Dex.h"
-#include "Serialization.h"
 #include "SourceCode.h"
+#include "index/Serialization.h"
+#include "index/dex/Dex.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"


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


[PATCH] D52840: Include Python binding tests in CMake rules

2018-10-15 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

This causes check-all to abort for me on SystemZ in Release mode (and never 
actually run the lit tests):

  [40/365] cd /home/uweigand/llvm/llvm-head/tools/clang/bindings/python && 
/usr/bin/cmake -E...BRARY_PATH=/home/uweigand/llvm/build/llvm-head/lib 
/usr/bin/python2.7 -m unittest discover
  FAILED: tools/clang/bindings/python/tests/CMakeFiles/check-clang-python 
  cd /home/uweigand/llvm/llvm-head/tools/clang/bindings/python && 
/usr/bin/cmake -E env 
CLANG_LIBRARY_PATH=/home/uweigand/llvm/build/llvm-head/lib /usr/bin/python2.7 
-m unittest discover
  Invalid CXChildVisitResult!
  UNREACHABLE executed at 
/home/uweigand/llvm/llvm-head/tools/clang/tools/libclang/CIndex.cpp:233!
  Child aborted

When running in Debug mode I see instead:

  [165/536] cd /home/uweigand/llvm/llvm-head/tools/clang/bindings/python && 
/usr/bin/cmake -...PATH=/home/uweigand/llvm/build/llvm-head-debug/lib 
/usr/bin/python2.7 -m unittest discover
  ..LIBCLANG 
TOOLING ERROR: fixed-compilation-database: Error while opening fixed database: 
No such file or directory
  json-compilation-database: Error while opening JSON database: No such file or 
directory
  
  ..
  --
  Ran 120 tests in 8.522s
  
  OK

which apparently doesn't count as failure, but still doesn't look quite right 
to me.

Is this some environment setup problem, or does this expose a real bug?  It's 
certainly not good that running the remaining tests is completely aborted in 
Release mode ...


Repository:
  rC Clang

https://reviews.llvm.org/D52840



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


[PATCH] D53200: [OpenCL] Fix serialization of OpenCLExtensionDecls

2018-10-15 Thread Jonas Devlieghere via Phabricator via cfe-commits
JDevlieghere added a comment.

Can you add a test case please?


Repository:
  rC Clang

https://reviews.llvm.org/D53200



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


[PATCH] D52840: Include Python binding tests in CMake rules

2018-10-15 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

The first one seems to indicate that your `libclang.so` is broken in release 
mode (optimization error?). The second one is correct (some of the tests test 
for errors, and apparently don't silence the messages).


Repository:
  rC Clang

https://reviews.llvm.org/D52840



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


r344536 - Revert 344389 "Revert r344375 "[Driver] check for exit code from SIGPIPE""

2018-10-15 Thread Nick Desaulniers via cfe-commits
Author: nickdesaulniers
Date: Mon Oct 15 10:39:00 2018
New Revision: 344536

URL: http://llvm.org/viewvc/llvm-project?rev=344536&view=rev
Log:
Revert 344389 "Revert r344375 "[Driver] check for exit code from SIGPIPE""

Summary:
Add preprocessor guards for UNIX.

This reverts commit r344389.

Reviewers: rnk, majnemer, jfb

Reviewed By: rnk

Subscribers: cfe-commits, pirama, srhines

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

Modified:
cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=344536&r1=344535&r2=344536&view=diff
==
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Mon Oct 15 10:39:00 2018
@@ -81,6 +81,7 @@
 #include 
 #if LLVM_ON_UNIX
 #include  // getpid
+#include  // EX_IOERR
 #endif
 
 using namespace clang::driver;
@@ -1388,8 +1389,9 @@ int Driver::ExecuteCompilation(
 
   // Otherwise, remove result files and print extra information about abnormal
   // failures.
+  int Res = 0;
   for (const auto &CmdPair : FailingCommands) {
-int Res = CmdPair.first;
+int CommandRes = CmdPair.first;
 const Command *FailingCommand = CmdPair.second;
 
 // Remove result files if we're not saving temps.
@@ -1398,10 +1400,19 @@ int Driver::ExecuteCompilation(
   C.CleanupFileMap(C.getResultFiles(), JA, true);
 
   // Failure result files are valid unless we crashed.
-  if (Res < 0)
+  if (CommandRes < 0)
 C.CleanupFileMap(C.getFailureResultFiles(), JA, true);
 }
 
+#if LLVM_ON_UNIX
+// llvm/lib/Support/Unix/Signals.inc will exit with a special return code
+// for SIGPIPE. Do not print diagnostics for this case.
+if (CommandRes == EX_IOERR) {
+  Res = CommandRes;
+  continue;
+}
+#endif
+
 // Print extra information about abnormal failures, if possible.
 //
 // This is ad-hoc, but we don't want to be excessively noisy. If the result
@@ -1411,17 +1422,17 @@ int Driver::ExecuteCompilation(
 // diagnostics, so always print the diagnostic there.
 const Tool &FailingTool = FailingCommand->getCreator();
 
-if (!FailingCommand->getCreator().hasGoodDiagnostics() || Res != 1) {
+if (!FailingCommand->getCreator().hasGoodDiagnostics() || CommandRes != 1) 
{
   // FIXME: See FIXME above regarding result code interpretation.
-  if (Res < 0)
+  if (CommandRes < 0)
 Diag(clang::diag::err_drv_command_signalled)
 << FailingTool.getShortName();
   else
-Diag(clang::diag::err_drv_command_failed) << FailingTool.getShortName()
-  << Res;
+Diag(clang::diag::err_drv_command_failed)
+<< FailingTool.getShortName() << CommandRes;
 }
   }
-  return 0;
+  return Res;
 }
 
 void Driver::PrintHelp(bool ShowHidden) const {


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


[PATCH] D53210: Revert 344389 "Revert r344375 "[Driver] check for exit code from SIGPIPE""

2018-10-15 Thread Nick Desaulniers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC344536: Revert 344389 "Revert r344375 "[Driver] 
check for exit code from SIGPIPE"" (authored by nickdesaulniers, 
committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53210?vs=169474&id=169723#toc

Repository:
  rC Clang

https://reviews.llvm.org/D53210

Files:
  lib/Driver/Driver.cpp


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -81,6 +81,7 @@
 #include 
 #if LLVM_ON_UNIX
 #include  // getpid
+#include  // EX_IOERR
 #endif
 
 using namespace clang::driver;
@@ -1388,20 +1389,30 @@
 
   // Otherwise, remove result files and print extra information about abnormal
   // failures.
+  int Res = 0;
   for (const auto &CmdPair : FailingCommands) {
-int Res = CmdPair.first;
+int CommandRes = CmdPair.first;
 const Command *FailingCommand = CmdPair.second;
 
 // Remove result files if we're not saving temps.
 if (!isSaveTempsEnabled()) {
   const JobAction *JA = cast(&FailingCommand->getSource());
   C.CleanupFileMap(C.getResultFiles(), JA, true);
 
   // Failure result files are valid unless we crashed.
-  if (Res < 0)
+  if (CommandRes < 0)
 C.CleanupFileMap(C.getFailureResultFiles(), JA, true);
 }
 
+#if LLVM_ON_UNIX
+// llvm/lib/Support/Unix/Signals.inc will exit with a special return code
+// for SIGPIPE. Do not print diagnostics for this case.
+if (CommandRes == EX_IOERR) {
+  Res = CommandRes;
+  continue;
+}
+#endif
+
 // Print extra information about abnormal failures, if possible.
 //
 // This is ad-hoc, but we don't want to be excessively noisy. If the result
@@ -1411,17 +1422,17 @@
 // diagnostics, so always print the diagnostic there.
 const Tool &FailingTool = FailingCommand->getCreator();
 
-if (!FailingCommand->getCreator().hasGoodDiagnostics() || Res != 1) {
+if (!FailingCommand->getCreator().hasGoodDiagnostics() || CommandRes != 1) 
{
   // FIXME: See FIXME above regarding result code interpretation.
-  if (Res < 0)
+  if (CommandRes < 0)
 Diag(clang::diag::err_drv_command_signalled)
 << FailingTool.getShortName();
   else
-Diag(clang::diag::err_drv_command_failed) << FailingTool.getShortName()
-  << Res;
+Diag(clang::diag::err_drv_command_failed)
+<< FailingTool.getShortName() << CommandRes;
 }
   }
-  return 0;
+  return Res;
 }
 
 void Driver::PrintHelp(bool ShowHidden) const {


Index: lib/Driver/Driver.cpp
===
--- lib/Driver/Driver.cpp
+++ lib/Driver/Driver.cpp
@@ -81,6 +81,7 @@
 #include 
 #if LLVM_ON_UNIX
 #include  // getpid
+#include  // EX_IOERR
 #endif
 
 using namespace clang::driver;
@@ -1388,20 +1389,30 @@
 
   // Otherwise, remove result files and print extra information about abnormal
   // failures.
+  int Res = 0;
   for (const auto &CmdPair : FailingCommands) {
-int Res = CmdPair.first;
+int CommandRes = CmdPair.first;
 const Command *FailingCommand = CmdPair.second;
 
 // Remove result files if we're not saving temps.
 if (!isSaveTempsEnabled()) {
   const JobAction *JA = cast(&FailingCommand->getSource());
   C.CleanupFileMap(C.getResultFiles(), JA, true);
 
   // Failure result files are valid unless we crashed.
-  if (Res < 0)
+  if (CommandRes < 0)
 C.CleanupFileMap(C.getFailureResultFiles(), JA, true);
 }
 
+#if LLVM_ON_UNIX
+// llvm/lib/Support/Unix/Signals.inc will exit with a special return code
+// for SIGPIPE. Do not print diagnostics for this case.
+if (CommandRes == EX_IOERR) {
+  Res = CommandRes;
+  continue;
+}
+#endif
+
 // Print extra information about abnormal failures, if possible.
 //
 // This is ad-hoc, but we don't want to be excessively noisy. If the result
@@ -1411,17 +1422,17 @@
 // diagnostics, so always print the diagnostic there.
 const Tool &FailingTool = FailingCommand->getCreator();
 
-if (!FailingCommand->getCreator().hasGoodDiagnostics() || Res != 1) {
+if (!FailingCommand->getCreator().hasGoodDiagnostics() || CommandRes != 1) {
   // FIXME: See FIXME above regarding result code interpretation.
-  if (Res < 0)
+  if (CommandRes < 0)
 Diag(clang::diag::err_drv_command_signalled)
 << FailingTool.getShortName();
   else
-Diag(clang::diag::err_drv_command_failed) << FailingTool.getShortName()
-  << Res;
+Diag(clang::diag::err_drv_command_failed)
+<< FailingTool.getShortName() << CommandRes;
 }
   }
-  return 0;
+  return Res;
 }
 
 void Driver::PrintHelp(bool ShowHidden) const {
___
cfe-commits mai

[PATCH] D53274: [analyzer][NFC] Fix inconsistencies in AnalyzerOptions

2018-10-15 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

> The main motivation behind here is to emit warnings if an invalid

I'm totally with you here, but IIRC (@NoQ might want to correct me here),
the design decision was made specifically to ignore incorrect options, so that 
e.g. old versions of Xcode used with old projects would still work.


https://reviews.llvm.org/D53274



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


r344537 - [python] [tests] Disable python binding tests under LLVM_USE_SANITIZER=Address

2018-10-15 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Oct 15 10:43:23 2018
New Revision: 344537

URL: http://llvm.org/viewvc/llvm-project?rev=344537&view=rev
Log:
[python] [tests] Disable python binding tests under LLVM_USE_SANITIZER=Address

They don't work yet.

Patch by Dan Liew!

rdar://problem/45242886

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

Modified:
cfe/trunk/bindings/python/tests/CMakeLists.txt

Modified: cfe/trunk/bindings/python/tests/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/CMakeLists.txt?rev=344537&r1=344536&r2=344537&view=diff
==
--- cfe/trunk/bindings/python/tests/CMakeLists.txt (original)
+++ cfe/trunk/bindings/python/tests/CMakeLists.txt Mon Oct 15 10:43:23 2018
@@ -7,9 +7,24 @@ add_custom_target(check-clang-python
 DEPENDS libclang
 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
 
+# Check if we are building with ASan
+list(FIND LLVM_USE_SANITIZER "Address" LLVM_USE_ASAN_INDEX)
+if (LLVM_USE_ASAN_INDEX EQUAL -1)
+  set(LLVM_USE_ASAN FALSE)
+else()
+  set(LLVM_USE_ASAN TRUE)
+endif()
+
 # Tests fail on Windows, and need someone knowledgeable to fix.
 # It's not clear whether it's a test or a valid binding problem.
-if(NOT WIN32)
+#
+# Do not try to run if libclang was built with ASan because
+# the sanitizer library will likely be loaded too late to perform
+# interception and will then fail.
+# We could use LD_PRELOAD/DYLD_INSERT_LIBRARIES but this isn't
+# portable so its easier just to not run the tests when building
+# with ASan.
+if((NOT WIN32) AND (NOT LLVM_USE_ASAN))
 set_property(GLOBAL APPEND PROPERTY
  LLVM_ADDITIONAL_TEST_TARGETS check-clang-python)
 endif()


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


[PATCH] D53239: [python] [tests] Disable python binding tests when building with LLVM_USE_SANITIZER=Address

2018-10-15 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL344537: [python] [tests] Disable python binding tests under 
LLVM_USE_SANITIZER=Address (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D53239?vs=169535&id=169724#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D53239

Files:
  cfe/trunk/bindings/python/tests/CMakeLists.txt


Index: cfe/trunk/bindings/python/tests/CMakeLists.txt
===
--- cfe/trunk/bindings/python/tests/CMakeLists.txt
+++ cfe/trunk/bindings/python/tests/CMakeLists.txt
@@ -7,9 +7,24 @@
 DEPENDS libclang
 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
 
+# Check if we are building with ASan
+list(FIND LLVM_USE_SANITIZER "Address" LLVM_USE_ASAN_INDEX)
+if (LLVM_USE_ASAN_INDEX EQUAL -1)
+  set(LLVM_USE_ASAN FALSE)
+else()
+  set(LLVM_USE_ASAN TRUE)
+endif()
+
 # Tests fail on Windows, and need someone knowledgeable to fix.
 # It's not clear whether it's a test or a valid binding problem.
-if(NOT WIN32)
+#
+# Do not try to run if libclang was built with ASan because
+# the sanitizer library will likely be loaded too late to perform
+# interception and will then fail.
+# We could use LD_PRELOAD/DYLD_INSERT_LIBRARIES but this isn't
+# portable so its easier just to not run the tests when building
+# with ASan.
+if((NOT WIN32) AND (NOT LLVM_USE_ASAN))
 set_property(GLOBAL APPEND PROPERTY
  LLVM_ADDITIONAL_TEST_TARGETS check-clang-python)
 endif()


Index: cfe/trunk/bindings/python/tests/CMakeLists.txt
===
--- cfe/trunk/bindings/python/tests/CMakeLists.txt
+++ cfe/trunk/bindings/python/tests/CMakeLists.txt
@@ -7,9 +7,24 @@
 DEPENDS libclang
 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..)
 
+# Check if we are building with ASan
+list(FIND LLVM_USE_SANITIZER "Address" LLVM_USE_ASAN_INDEX)
+if (LLVM_USE_ASAN_INDEX EQUAL -1)
+  set(LLVM_USE_ASAN FALSE)
+else()
+  set(LLVM_USE_ASAN TRUE)
+endif()
+
 # Tests fail on Windows, and need someone knowledgeable to fix.
 # It's not clear whether it's a test or a valid binding problem.
-if(NOT WIN32)
+#
+# Do not try to run if libclang was built with ASan because
+# the sanitizer library will likely be loaded too late to perform
+# interception and will then fail.
+# We could use LD_PRELOAD/DYLD_INSERT_LIBRARIES but this isn't
+# portable so its easier just to not run the tests when building
+# with ASan.
+if((NOT WIN32) AND (NOT LLVM_USE_ASAN))
 set_property(GLOBAL APPEND PROPERTY
  LLVM_ADDITIONAL_TEST_TARGETS check-clang-python)
 endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53274: [analyzer][NFC] Fix inconsistencies in AnalyzerOptions

2018-10-15 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

I'm not sure why you could get away with removing those llvm_unreachable cases?




Comment at: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp:373
-  default:
-llvm_unreachable("Invalid mode.");
   case UMK_Shallow:

Why?



Comment at: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp:418
-  default:
-llvm_unreachable("Invalid mode.");
   case UMK_Shallow:

Why?



Comment at: lib/StaticAnalyzer/Core/CoreEngine.cpp:72
-default:
-  llvm_unreachable("Unexpected case");
   }

Why?


https://reviews.llvm.org/D53274



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


[PATCH] D52804: [analyzer] NFC: RetainCountChecker: Avoid dumping symbols during normal operation.

2018-10-15 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC344538: [analyzer] NFC: RetainCountChecker: Don't 
dump() symbols into program point… (authored by dergachev, committed by ).
Herald added a subscriber: donat.nagy.

Repository:
  rC Clang

https://reviews.llvm.org/D52804

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp


Index: lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
@@ -1314,19 +1314,6 @@
   processLeaks(state, Leaked, Ctx, Pred);
 }
 
-const ProgramPointTag *
-RetainCountChecker::getDeadSymbolTag(SymbolRef sym) const {
-  const CheckerProgramPointTag *&tag = DeadSymbolTags[sym];
-  if (!tag) {
-SmallString<64> buf;
-llvm::raw_svector_ostream out(buf);
-out << "Dead Symbol : ";
-sym->dumpToStream(out);
-tag = new CheckerProgramPointTag(this, out.str());
-  }
-  return tag;
-}
-
 void RetainCountChecker::checkDeadSymbols(SymbolReaper &SymReaper,
   CheckerContext &C) const {
   ExplodedNode *Pred = C.getPredecessor();
@@ -1342,8 +1329,8 @@
 if (const RefVal *T = B.lookup(Sym)){
   // Use the symbol as the tag.
   // FIXME: This might not be as unique as we would like.
-  const ProgramPointTag *Tag = getDeadSymbolTag(Sym);
-  state = handleAutoreleaseCounts(state, Pred, Tag, C, Sym, *T);
+  static CheckerProgramPointTag Tag(this, "DeadSymbolAutorelease");
+  state = handleAutoreleaseCounts(state, Pred, &Tag, C, Sym, *T);
   if (!state)
 return;
 


Index: lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
@@ -1314,19 +1314,6 @@
   processLeaks(state, Leaked, Ctx, Pred);
 }
 
-const ProgramPointTag *
-RetainCountChecker::getDeadSymbolTag(SymbolRef sym) const {
-  const CheckerProgramPointTag *&tag = DeadSymbolTags[sym];
-  if (!tag) {
-SmallString<64> buf;
-llvm::raw_svector_ostream out(buf);
-out << "Dead Symbol : ";
-sym->dumpToStream(out);
-tag = new CheckerProgramPointTag(this, out.str());
-  }
-  return tag;
-}
-
 void RetainCountChecker::checkDeadSymbols(SymbolReaper &SymReaper,
   CheckerContext &C) const {
   ExplodedNode *Pred = C.getPredecessor();
@@ -1342,8 +1329,8 @@
 if (const RefVal *T = B.lookup(Sym)){
   // Use the symbol as the tag.
   // FIXME: This might not be as unique as we would like.
-  const ProgramPointTag *Tag = getDeadSymbolTag(Sym);
-  state = handleAutoreleaseCounts(state, Pred, Tag, C, Sym, *T);
+  static CheckerProgramPointTag Tag(this, "DeadSymbolAutorelease");
+  state = handleAutoreleaseCounts(state, Pred, &Tag, C, Sym, *T);
   if (!state)
 return;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r344538 - [analyzer] NFC: RetainCountChecker: Don't dump() symbols into program point tags.

2018-10-15 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Oct 15 10:47:56 2018
New Revision: 344538

URL: http://llvm.org/viewvc/llvm-project?rev=344538&view=rev
Log:
[analyzer] NFC: RetainCountChecker: Don't dump() symbols into program point 
tags.

We don't need a separate node for every symbol, because whenever the first
symbol leaks, a bug is emitted, the analysis is sinked, and the checker
callback immediately returns due to State variable turning into null,
so we never get to see the second leaking symbol.

Additionally, we are no longer able to break normal analysis while experimenting
with debug dumps.

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

Modified:

cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp

Modified: 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp?rev=344538&r1=344537&r2=344538&view=diff
==
--- 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp 
(original)
+++ 
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp 
Mon Oct 15 10:47:56 2018
@@ -1314,19 +1314,6 @@ void RetainCountChecker::checkEndFunctio
   processLeaks(state, Leaked, Ctx, Pred);
 }
 
-const ProgramPointTag *
-RetainCountChecker::getDeadSymbolTag(SymbolRef sym) const {
-  const CheckerProgramPointTag *&tag = DeadSymbolTags[sym];
-  if (!tag) {
-SmallString<64> buf;
-llvm::raw_svector_ostream out(buf);
-out << "Dead Symbol : ";
-sym->dumpToStream(out);
-tag = new CheckerProgramPointTag(this, out.str());
-  }
-  return tag;
-}
-
 void RetainCountChecker::checkDeadSymbols(SymbolReaper &SymReaper,
   CheckerContext &C) const {
   ExplodedNode *Pred = C.getPredecessor();
@@ -1342,8 +1329,8 @@ void RetainCountChecker::checkDeadSymbol
 if (const RefVal *T = B.lookup(Sym)){
   // Use the symbol as the tag.
   // FIXME: This might not be as unique as we would like.
-  const ProgramPointTag *Tag = getDeadSymbolTag(Sym);
-  state = handleAutoreleaseCounts(state, Pred, Tag, C, Sym, *T);
+  static CheckerProgramPointTag Tag(this, "DeadSymbolAutorelease");
+  state = handleAutoreleaseCounts(state, Pred, &Tag, C, Sym, *T);
   if (!state)
 return;
 


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


[PATCH] D52957: [analyzer] Teach CallEvent about C++17 aligned new.

2018-10-15 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL344539: [analyzer] Teach CallEvent about C++17 aligned 
operator new(). (authored by dergachev, committed by ).
Herald added subscribers: llvm-commits, donat.nagy.

Changed prior to commit:
  https://reviews.llvm.org/D52957?vs=168556&id=169726#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D52957

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
  cfe/trunk/test/Analysis/new-aligned.cpp


Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -921,15 +921,28 @@
 return getOriginExpr()->getOperatorNew();
   }
 
+  // Size and maybe implicit alignment in C++17. Instead of size, the AST
+  // contains the construct-expression. Alignment is always hidden.
+  // We pretend that argument 0 is size and argument 1 is alignment (if passed
+  // implicitly) and the rest are placement args. This makes sure that the
+  // number of arguments is always the same as the number of parameters.
+  unsigned getNumImplicitArgs() const {
+return getOriginExpr()->passAlignment() ? 2 : 1;
+  }
+
   unsigned getNumArgs() const override {
-return getOriginExpr()->getNumPlacementArgs() + 1;
+return getOriginExpr()->getNumPlacementArgs() + getNumImplicitArgs();
   }
 
   const Expr *getArgExpr(unsigned Index) const override {
 // The first argument of an allocator call is the size of the allocation.
-if (Index == 0)
+if (Index < getNumImplicitArgs())
   return nullptr;
-return getOriginExpr()->getPlacementArg(Index - 1);
+return getOriginExpr()->getPlacementArg(Index - getNumImplicitArgs());
+  }
+
+  const Expr *getPlacementArgExpr(unsigned Index) const {
+return getOriginExpr()->getPlacementArg(Index);
   }
 
   Kind getKind() const override { return CE_CXXAllocator; }
Index: cfe/trunk/test/Analysis/new-aligned.cpp
===
--- cfe/trunk/test/Analysis/new-aligned.cpp
+++ cfe/trunk/test/Analysis/new-aligned.cpp
@@ -0,0 +1,14 @@
+//RUN: %clang_analyze_cc1 -std=c++17 -analyze -analyzer-checker=core -verify %s
+
+// expected-no-diagnostics
+
+// Notice the weird alignment.
+struct alignas(1024) S {};
+
+void foo() {
+  // Operator new() here is the C++17 aligned new that takes two arguments:
+  // size and alignment. Size is passed implicitly as usual, and alignment
+  // is passed implicitly in a similar manner.
+  S *s = new S; // no-warning
+  delete s;
+}
Index: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -503,10 +503,14 @@
 const ParmVarDecl *ParamDecl = *I;
 assert(ParamDecl && "Formal parameter has no decl?");
 
+// TODO: Support allocator calls.
 if (Call.getKind() != CE_CXXAllocator)
   if (Call.isArgumentConstructedDirectly(Idx))
 continue;
 
+// TODO: Allocators should receive the correct size and possibly alignment,
+// determined in compile-time but not represented as arg-expressions,
+// which makes getArgSVal() fail and return UnknownVal.
 SVal ArgVal = Call.getArgSVal(Idx);
 if (!ArgVal.isUnknown()) {
   Loc ParamLoc = SVB.makeLoc(MRMgr.getVarRegion(ParamDecl, CalleeCtx));


Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
@@ -921,15 +921,28 @@
 return getOriginExpr()->getOperatorNew();
   }
 
+  // Size and maybe implicit alignment in C++17. Instead of size, the AST
+  // contains the construct-expression. Alignment is always hidden.
+  // We pretend that argument 0 is size and argument 1 is alignment (if passed
+  // implicitly) and the rest are placement args. This makes sure that the
+  // number of arguments is always the same as the number of parameters.
+  unsigned getNumImplicitArgs() const {
+return getOriginExpr()->passAlignment() ? 2 : 1;
+  }
+
   unsigned getNumArgs() const override {
-return getOriginExpr()->getNumPlacementArgs() + 1;
+return getOriginExpr()->getNumPlacementArgs() + getNumImplicitArgs();
   }
 
   const Expr *getArgExpr(unsigned Index) const override {
 // The first argument of an allocator call is the size of the allocation.
-if (Index == 0)
+if (Index < getNumImplicitArgs())
   return nullptr;
-return getOriginExpr()->getPlacementArg(Index - 1);
+return getOriginExpr()

[PATCH] D53125: Detect Clear Linux and apply Clear's default linker options

2018-10-15 Thread Thiago Macieira via Phabricator via cfe-commits
thiagomacieira marked an inline comment as done.
thiagomacieira added inline comments.



Comment at: lib/Driver/Distro.cpp:148
+for (StringRef Line : Lines)
+  if (Version == Distro::UnknownDistro && Line.startswith("ID="))
+Version = llvm::StringSwitch(Line.substr(3))

I'm changing this so we can detect Clear-derived distributions.


https://reviews.llvm.org/D53125



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


r344539 - [analyzer] Teach CallEvent about C++17 aligned operator new().

2018-10-15 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Oct 15 10:53:18 2018
New Revision: 344539

URL: http://llvm.org/viewvc/llvm-project?rev=344539&view=rev
Log:
[analyzer] Teach CallEvent about C++17 aligned operator new().

In C++17, when class C has large alignment value, a special case of
overload resolution rule kicks in for expression new C that causes the aligned
version of operator new() to be called. The aligned new has two arguments:
size and alignment. However, the new-expression has only one "argument":
the construct-expression for C(). This causes a false positive in
core.CallAndMessage's check for matching number of arguments and number
of parameters.

Update CXXAllocatorCall, which is a CallEvent sub-class for operator new calls
within new-expressions, so that the number of arguments always matched
the number of parameters.

rdar://problem/44738501

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

Added:
cfe/trunk/test/Analysis/new-aligned.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h?rev=344539&r1=344538&r2=344539&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h Mon 
Oct 15 10:53:18 2018
@@ -921,15 +921,28 @@ public:
 return getOriginExpr()->getOperatorNew();
   }
 
+  // Size and maybe implicit alignment in C++17. Instead of size, the AST
+  // contains the construct-expression. Alignment is always hidden.
+  // We pretend that argument 0 is size and argument 1 is alignment (if passed
+  // implicitly) and the rest are placement args. This makes sure that the
+  // number of arguments is always the same as the number of parameters.
+  unsigned getNumImplicitArgs() const {
+return getOriginExpr()->passAlignment() ? 2 : 1;
+  }
+
   unsigned getNumArgs() const override {
-return getOriginExpr()->getNumPlacementArgs() + 1;
+return getOriginExpr()->getNumPlacementArgs() + getNumImplicitArgs();
   }
 
   const Expr *getArgExpr(unsigned Index) const override {
 // The first argument of an allocator call is the size of the allocation.
-if (Index == 0)
+if (Index < getNumImplicitArgs())
   return nullptr;
-return getOriginExpr()->getPlacementArg(Index - 1);
+return getOriginExpr()->getPlacementArg(Index - getNumImplicitArgs());
+  }
+
+  const Expr *getPlacementArgExpr(unsigned Index) const {
+return getOriginExpr()->getPlacementArg(Index);
   }
 
   Kind getKind() const override { return CE_CXXAllocator; }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=344539&r1=344538&r2=344539&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Mon Oct 15 10:53:18 2018
@@ -503,10 +503,14 @@ static void addParameterValuesToBindings
 const ParmVarDecl *ParamDecl = *I;
 assert(ParamDecl && "Formal parameter has no decl?");
 
+// TODO: Support allocator calls.
 if (Call.getKind() != CE_CXXAllocator)
   if (Call.isArgumentConstructedDirectly(Idx))
 continue;
 
+// TODO: Allocators should receive the correct size and possibly alignment,
+// determined in compile-time but not represented as arg-expressions,
+// which makes getArgSVal() fail and return UnknownVal.
 SVal ArgVal = Call.getArgSVal(Idx);
 if (!ArgVal.isUnknown()) {
   Loc ParamLoc = SVB.makeLoc(MRMgr.getVarRegion(ParamDecl, CalleeCtx));

Added: cfe/trunk/test/Analysis/new-aligned.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/new-aligned.cpp?rev=344539&view=auto
==
--- cfe/trunk/test/Analysis/new-aligned.cpp (added)
+++ cfe/trunk/test/Analysis/new-aligned.cpp Mon Oct 15 10:53:18 2018
@@ -0,0 +1,14 @@
+//RUN: %clang_analyze_cc1 -std=c++17 -analyze -analyzer-checker=core -verify %s
+
+// expected-no-diagnostics
+
+// Notice the weird alignment.
+struct alignas(1024) S {};
+
+void foo() {
+  // Operator new() here is the C++17 aligned new that takes two arguments:
+  // size and alignment. Size is passed implicitly as usual, and alignment
+  // is passed implicitly in a similar manner.
+  S *s = new S; // no-warning
+  delete s;
+}


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


r344540 - [analyzer] Add doxygen comments for the new CXXAllocatorCall APIs.

2018-10-15 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Mon Oct 15 11:01:34 2018
New Revision: 344540

URL: http://llvm.org/viewvc/llvm-project?rev=344540&view=rev
Log:
[analyzer] Add doxygen comments for the new CXXAllocatorCall APIs.

Forgot to squeeze this into r344539.

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h?rev=344540&r1=344539&r2=344540&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h Mon 
Oct 15 11:01:34 2018
@@ -921,11 +921,9 @@ public:
 return getOriginExpr()->getOperatorNew();
   }
 
-  // Size and maybe implicit alignment in C++17. Instead of size, the AST
-  // contains the construct-expression. Alignment is always hidden.
-  // We pretend that argument 0 is size and argument 1 is alignment (if passed
-  // implicitly) and the rest are placement args. This makes sure that the
-  // number of arguments is always the same as the number of parameters.
+  /// Number of non-placement arguments to the call. It is equal to 2 for
+  /// C++17 aligned operator new() calls that have alignment implicitly
+  /// passed as the second argument, and to 1 for other operator new() calls.
   unsigned getNumImplicitArgs() const {
 return getOriginExpr()->passAlignment() ? 2 : 1;
   }
@@ -941,6 +939,10 @@ public:
 return getOriginExpr()->getPlacementArg(Index - getNumImplicitArgs());
   }
 
+  /// Number of placement arguments to the operator new() call. For example,
+  /// standard std::nothrow operator new and standard placement new both have
+  /// 1 implicit argument (size) and 1 placement argument, while regular
+  /// operator new() has 1 implicit argument and 0 placement arguments.
   const Expr *getPlacementArgExpr(unsigned Index) const {
 return getOriginExpr()->getPlacementArg(Index);
   }


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


[PATCH] D52957: [analyzer] Teach CallEvent about C++17 aligned new.

2018-10-15 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Whoops, almost forgot to doxygen-ize comments. Landed in 
https://reviews.llvm.org/rC344540.


Repository:
  rL LLVM

https://reviews.llvm.org/D52957



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


[PATCH] D53295: [OpenCL] Mark load of block invoke function as invariant

2018-10-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: rjmccall, Anastasia.

  OpenCL v2.0 s6.12.5:
Block variable declarations are implicitly qualified with const.
  Therefore all block variables must be initialized at declaration time and
  may not be reassigned.
  
  As such, load of block invoke function can be marked as invariant. This is
  to facilitate lowering of indirect function calls resulted from it to
  direct function calls since OpenCL does not require supporting of function
  pointer.


https://reviews.llvm.org/D53295

Files:
  lib/CodeGen/CGBlocks.cpp
  test/CodeGenOpenCL/blocks.cl


Index: test/CodeGenOpenCL/blocks.cl
===
--- test/CodeGenOpenCL/blocks.cl
+++ test/CodeGenOpenCL/blocks.cl
@@ -98,6 +98,19 @@
   return blockArgFunc(^{return 42;});
 }
 
+// COMMON-LABEL: define {{.*}} @blockInLoopCondition
+// COMMON: %[[INV:.*]] = getelementptr {{.*}}%block.literal, i32 0, i32 2
+// COMMON: load {{.*}}%[[INV]]{{.*}}, !invariant.load
+void blockInLoopCondition(int* res, int tid, int multiplier) {
+  int (^kernelBlock)(int) = ^(int num) {
+return num * multiplier;
+  };
+  res[tid] = 39;
+  for(int i=0; i(Func)->setMetadata(
+CGM.getModule().getMDKindID("invariant.load"),
+llvm::MDNode::get(getLLVMContext(), None));
+
   const FunctionType *FuncTy = FnType->castAs();
   const CGFunctionInfo &FnInfo =
 CGM.getTypes().arrangeBlockFunctionCall(Args, FuncTy);


Index: test/CodeGenOpenCL/blocks.cl
===
--- test/CodeGenOpenCL/blocks.cl
+++ test/CodeGenOpenCL/blocks.cl
@@ -98,6 +98,19 @@
   return blockArgFunc(^{return 42;});
 }
 
+// COMMON-LABEL: define {{.*}} @blockInLoopCondition
+// COMMON: %[[INV:.*]] = getelementptr {{.*}}%block.literal, i32 0, i32 2
+// COMMON: load {{.*}}%[[INV]]{{.*}}, !invariant.load
+void blockInLoopCondition(int* res, int tid, int multiplier) {
+  int (^kernelBlock)(int) = ^(int num) {
+return num * multiplier;
+  };
+  res[tid] = 39;
+  for(int i=0; i(Func)->setMetadata(
+CGM.getModule().getMDKindID("invariant.load"),
+llvm::MDNode::get(getLLVMContext(), None));
+
   const FunctionType *FuncTy = FnType->castAs();
   const CGFunctionInfo &FnInfo =
 CGM.getTypes().arrangeBlockFunctionCall(Args, FuncTy);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52784: [ARM][AArch64] Pass through endianness flags to the GNU assembler and linker

2018-10-15 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers accepted this revision.
nickdesaulniers added a comment.
This revision is now accepted and ready to land.

Thanks for this patch.  With it I was able to link+boot a BE aarch64 Linux 
kernel (and a LE aarch64 Linux kernel).




Comment at: lib/Driver/ToolChains/Gnu.cpp:268
   case llvm::Triple::thumbeb:
-return "armelfb_linux_eabi";
+return (isArmBigEndian(T, Args)) ? "armelfb_linux_eabi"
+ : "armelf_linux_eabi";

probably don't need the parens around `isArmBigEndian(...)`.


https://reviews.llvm.org/D52784



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


[PATCH] D53277: [analyzer][NFC] Collect all -analyzer-config options in a .def file

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus updated this revision to Diff 169731.
Szelethus retitled this revision from "[analyzer][NFC][WIP] Collect all 
-analyzer-config options in a .def file" to "[analyzer][NFC] Collect all 
-analyzer-config options in a .def file".
Szelethus edited the summary of this revision.
Szelethus added a comment.

Added descriptions.


https://reviews.llvm.org/D53277

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp

Index: lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -56,17 +56,17 @@
 static std::unique_ptr generateWorkList(AnalyzerOptions &Opts,
   SubEngine &subengine) {
   switch (Opts.getExplorationStrategy()) {
-case AnalyzerOptions::ExplorationStrategyKind::DFS:
+case ExplorationStrategyKind::DFS:
   return WorkList::makeDFS();
-case AnalyzerOptions::ExplorationStrategyKind::BFS:
+case ExplorationStrategyKind::BFS:
   return WorkList::makeBFS();
-case AnalyzerOptions::ExplorationStrategyKind::BFSBlockDFSContents:
+case ExplorationStrategyKind::BFSBlockDFSContents:
   return WorkList::makeBFSBlockDFSContents();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirst:
+case ExplorationStrategyKind::UnexploredFirst:
   return WorkList::makeUnexploredFirst();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstQueue:
+case ExplorationStrategyKind::UnexploredFirstQueue:
   return WorkList::makeUnexploredFirstPriorityQueue();
-case AnalyzerOptions::ExplorationStrategyKind::UnexploredFirstLocationQueue:
+case ExplorationStrategyKind::UnexploredFirstLocationQueue:
   return WorkList::makeUnexploredFirstPriorityLocationQueue();
   }
 }
Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
===
--- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -49,7 +49,7 @@
   return Result;
 }
 
-AnalyzerOptions::UserModeKind AnalyzerOptions::getUserMode() {
+UserModeKind AnalyzerOptions::getUserMode() {
   if (!UserMode.hasValue()) {
 StringRef ModeStr = getOptionAsString("mode", "deep");
 UserMode = llvm::StringSwitch>(ModeStr)
@@ -61,7 +61,7 @@
   return UserMode.getValue();
 }
 
-AnalyzerOptions::ExplorationStrategyKind
+ExplorationStrategyKind
 AnalyzerOptions::getExplorationStrategy() {
   if (!ExplorationStrategy.hasValue()) {
 StringRef StratStr = getOptionAsString("exploration_strategy",
@@ -182,137 +182,6 @@
   return V.getValue();
 }
 
-bool AnalyzerOptions::includeTemporaryDtorsInCFG() {
-  return getBooleanOption(IncludeTemporaryDtorsInCFG,
-  "cfg-temporary-dtors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeImplicitDtorsInCFG() {
-  return getBooleanOption(IncludeImplicitDtorsInCFG,
-  "cfg-implicit-dtors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeLifetimeInCFG() {
-  return getBooleanOption(IncludeLifetimeInCFG, "cfg-lifetime",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::includeLoopExitInCFG() {
-  return getBooleanOption(IncludeLoopExitInCFG, "cfg-loopexit",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::includeRichConstructorsInCFG() {
-  return getBooleanOption(IncludeRichConstructorsInCFG,
-  "cfg-rich-constructors",
-  /* Default = */ true);
-}
-
-bool AnalyzerOptions::includeScopesInCFG() {
-  return getBooleanOption(IncludeScopesInCFG,
-  "cfg-scopes",
-  /* Default = */ false);
-}
-
-bool AnalyzerOptions::mayInlineCXXStandardLibrary() {
-  return getBooleanOption(InlineCXXStandardLibrary,
-  "c++-stdlib-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineTemplateFunctions() {
-  return getBooleanOption(InlineTemplateFunctions,
-  "c++-template-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineCXXAllocator() {
-  return getBooleanOption(InlineCXXAllocator,
-  "c++-allocator-inlining",
-  /*Default=*/true);
-}
-
-bool AnalyzerOptions::mayInlineCXXContainerMethods() {
-  return getBooleanOption(InlineCXXContainerMethods,
-  "c++-container-inlining",
-  /*Default=*/false);
-}
-
-bool AnalyzerOptions::mayInlineCXXSharedPtrDtor() {
-  return getBooleanOption(InlineCXXSharedPtrDtor,
-  "c++-shared_ptr-inlining",
-   

[PATCH] D53274: [analyzer][NFC] Fix inconsistencies in AnalyzerOptions

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.

In https://reviews.llvm.org/D53274#1265625, @george.karpenkov wrote:

> I'm not sure why you could get away with removing those llvm_unreachable 
> cases?


Because I got a warning for using `default` when every enum value was handled 
in the switch. Since whether the flag is set or not can be retrieved via 
`llvm::Optional::hasValue()`, I removed the `.*NotSet` flags. The future 
maintainer who adds a new value will get a warning for not handling it anyways.

In https://reviews.llvm.org/D53274#1265618, @george.karpenkov wrote:

> > The main motivation behind here is to emit warnings if an invalid
>
> I'm totally with you here, but IIRC (@NoQ might want to correct me here),
>  the design decision was made specifically to ignore incorrect options, so 
> that e.g. old versions of Xcode used with old projects would still work.


I intend to emit a warning, but go on with the analysis. That's fair I believe?


https://reviews.llvm.org/D53274



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


[PATCH] D53296: [analyzer] New flag to print all -analyzer-config options

2018-10-15 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, george.karpenkov, xazax.hun, MTC, rnkovacs.
Herald added subscribers: cfe-commits, donat.nagy, mikhail.ramalho, dmgreen, 
a.sidorin, mgrang, szepet, whisperity.

Title says it all, here's how it look like locally:

  OVERVIEW: Clang Static Analyzer -analyzer-config Option List
  
  USAGE: clang [CLANG_OPTIONS] -analyzer-config 

  
 clang [CLANG_OPTIONS] -analyzer-config OPTION1=VALUE, -analyzer-config 
OPTION2=VALUE, ...
  
  OPTIONS:
  
aggressive-binary-operation-simplification
  (bool) Whether SValBuilder should 
rearrange
  comparisons and additive operations of
  symbolic expressions which consist of a 
sum
  of a symbol and a concrete integer into 
the
  format where symbols are on the left-hand
  side and the integer is on the right. 
This is
  only done if both symbols and both 
concrete
  integers are signed, greater than or 
equal to
  the quarter of the minimum value of the 
type
  and less than or equal to the quarter of 
the
  maximum value of that type. A + n  B 
+ m
  becomes A - B  m - n, where A and B
  symbolic, n and m are integers.  is 
any
  of '==', '!=', '<', '<=', '>', '>=', '+' 
or
  '-'. The rearrangement also happens with 
'-'
  instead of '+' on either or both side and
  also if any or both integers are missing.
  (default: false)
  
avoid-suppressing-null-argument-paths
  (bool) Whether a bug report should not be
  suppressed if its path includes a call 
with a
  null argument, even if that call has a 
null
  return. This option has no effect when
  #shouldSuppressNullReturnPaths() is false.
  This is a counter-heuristic to avoid false
  negatives. (default: false)
  
c++-allocator-inlining(bool) Whether or not allocator call may 
be
  considered for inlining. (default: true)
  
c++-container-inlining(bool) Whether or not methods of C++
  container objects may be considered for
  inlining. (default: false)
  
c++-inlining  (string) Controls which C++ member 
functions
  will be considered for inlining. Value:
  "constructors", "destructors" (default),
  "methods".
  
c++-shared_ptr-inlining   (bool) Whether or not the destructor of 
C++
  'shared_ptr' may be considered for 
inlining.
  This covers std::shared_ptr,
  std::tr1::shared_ptr, and 
boost::shared_ptr,
  and indeed any destructor named
  '~shared_ptr'. (default: false)
  
c++-stdlib-inlining   (bool) Whether or not C++ standard library
  functions may be considered for inlining.
  (default: true)
  
c++-temp-dtor-inlining(bool) Whether C++ temporary destructors
  should be inlined during analysis. If
  temporary destructors are disabled in the 
CFG
  via the 'cfg-temporary-dtors' option,
  temporary destructors would not be inlined
  anyway. (default: true)
  
c++-template-inlining (bool) Whether or not templated functions 
may
  be considered for inlining.
  
cfg-conditional-static-initializers
  (bool) Whether 'static' initializers 
should
  be in conditional logic in the CFG. 
(default:
  true)
  
cfg-implicit-dtors(bool) Whether or not implicit destructors
  for C++ objects should be included in the
   

[PATCH] D52840: Include Python binding tests in CMake rules

2018-10-15 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

In https://reviews.llvm.org/D52840#1265615, @mgorny wrote:

> The first one seems to indicate that your `libclang.so` is broken in release 
> mode (optimization error?). The second one is correct (some of the tests test 
> for errors, and apparently don't silence the messages).


Ok, thanks for the clarification on the second point.

As to the first issue, it turned out to be more complicated.  The wrong value 
results from this call in CursorVisitor::Visit

  switch (Visitor(Cursor, Parent, ClientData)) {

This is a callback routine passed in from the caller, which in the case of the 
Python bindings means that an FFI closure is being called.

Now, due to a historical quirk in the FFI ABI, return values of integral type 
smaller than the register word size must be passed as the special "ffi_arg" 
type when using FFI (either for calls or for closures).  It seems the Python 
2.7 code that interfaces with FFI does not correctly respect this.  As a 
result, it seems that when the closure returns a 32-bit value, it is not 
properly extended and the high bits of the return register contain garbage.

But that violates our ABI, which requires extension to full register size.   
And it seems the clang code, when built with optimization, does indeed rely on 
that ABI guarantee.

So there's a bug in Python (or depending on how you want to look at it, in 
libffi -- that part of the interface has also long been under-documented 
unfortunately), which hits on our platform.  I'll see if I can do anything 
about that, but for now we'll probably want to disable those tests on SystemZ.


Repository:
  rC Clang

https://reviews.llvm.org/D52840



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


[PATCH] D53295: [OpenCL] Mark load of block invoke function as invariant

2018-10-15 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGBlocks.cpp:1318
+CGM.getModule().getMDKindID("invariant.load"),
+llvm::MDNode::get(getLLVMContext(), None));
+

OpenCL blocks are still potentially function-local, right?  I don't think 
you're allowed to put `invariant.load` on something that's visibly initialized, 
even if it's visibly initialized to the same thing every time.  The problem is 
that `invariant.load` could allow the load to be hoisted above the 
initialization.

If you can solve that problem, you can make this non-OpenCL-specific.


https://reviews.llvm.org/D53295



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


[PATCH] D53299: [Fixed Point Arithmetic]

2018-10-15 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added a reviewer: bjope.
leonardchan added a project: clang-tools-extra.

Fix for warnings generated on unhandled enum value `STK_FixedPoint`.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53299

Files:
  clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp


Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -60,6 +60,47 @@
   case Type::STK_IntegralComplex:
 return getValueOfValueInit(
 InitType->getAs()->getElementType());
+  case Type::STK_FixedPoint:
+switch (InitType->getAs()->getKind()) {
+  case BuiltinType::ShortAccum:
+  case BuiltinType::SatShortAccum:
+return "0.0hk";
+  case BuiltinType::Accum:
+  case BuiltinType::SatAccum:
+return "0.0k";
+  case BuiltinType::LongAccum:
+  case BuiltinType::SatLongAccum:
+return "0.0lk";
+  case BuiltinType::UShortAccum:
+  case BuiltinType::SatUShortAccum:
+return "0.0uhk";
+  case BuiltinType::UAccum:
+  case BuiltinType::SatUAccum:
+return "0.0uk";
+  case BuiltinType::ULongAccum:
+  case BuiltinType::SatULongAccum:
+return "0.0ulk";
+  case BuiltinType::ShortFract:
+  case BuiltinType::SatShortFract:
+return "0.0hr";
+  case BuiltinType::Fract:
+  case BuiltinType::SatFract:
+return "0.0r";
+  case BuiltinType::LongFract:
+  case BuiltinType::SatLongFract:
+return "0.0lr";
+  case BuiltinType::UShortFract:
+  case BuiltinType::SatUShortFract:
+return "0.0uhr";
+  case BuiltinType::UFract:
+  case BuiltinType::SatUFract:
+return "0.0ur";
+  case BuiltinType::ULongFract:
+  case BuiltinType::SatULongFract:
+return "0.0ulr";
+  default:
+llvm_unreachable("Unhandled fixed point BuiltinType");
+}
   }
   llvm_unreachable("Invalid scalar type kind");
 }


Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -60,6 +60,47 @@
   case Type::STK_IntegralComplex:
 return getValueOfValueInit(
 InitType->getAs()->getElementType());
+  case Type::STK_FixedPoint:
+switch (InitType->getAs()->getKind()) {
+  case BuiltinType::ShortAccum:
+  case BuiltinType::SatShortAccum:
+return "0.0hk";
+  case BuiltinType::Accum:
+  case BuiltinType::SatAccum:
+return "0.0k";
+  case BuiltinType::LongAccum:
+  case BuiltinType::SatLongAccum:
+return "0.0lk";
+  case BuiltinType::UShortAccum:
+  case BuiltinType::SatUShortAccum:
+return "0.0uhk";
+  case BuiltinType::UAccum:
+  case BuiltinType::SatUAccum:
+return "0.0uk";
+  case BuiltinType::ULongAccum:
+  case BuiltinType::SatULongAccum:
+return "0.0ulk";
+  case BuiltinType::ShortFract:
+  case BuiltinType::SatShortFract:
+return "0.0hr";
+  case BuiltinType::Fract:
+  case BuiltinType::SatFract:
+return "0.0r";
+  case BuiltinType::LongFract:
+  case BuiltinType::SatLongFract:
+return "0.0lr";
+  case BuiltinType::UShortFract:
+  case BuiltinType::SatUShortFract:
+return "0.0uhr";
+  case BuiltinType::UFract:
+  case BuiltinType::SatUFract:
+return "0.0ur";
+  case BuiltinType::ULongFract:
+  case BuiltinType::SatULongFract:
+return "0.0ulr";
+  default:
+llvm_unreachable("Unhandled fixed point BuiltinType");
+}
   }
   llvm_unreachable("Invalid scalar type kind");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53210: Revert 344389 "Revert r344375 "[Driver] check for exit code from SIGPIPE""

2018-10-15 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

I think this is now breaking:
lld :: ELF/format-binary.test
lld :: ELF/relocatable-versioned.s


Repository:
  rC Clang

https://reviews.llvm.org/D53210



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


[PATCH] D53299: [Fixed Point Arithmetic] Fix for clang-tools-extra warning

2018-10-15 Thread Bjorn Pettersson via Phabricator via cfe-commits
bjope accepted this revision.
bjope added a comment.
This revision is now accepted and ready to land.

Just some inline nit:s about whitespace.

LGTM, apart from that!




Comment at: 
clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp:63
 InitType->getAs()->getElementType());
+  case Type::STK_FixedPoint:
+switch (InitType->getAs()->getKind()) {

nit: I'd add an extra line break before this line (just to follow the earlier 
style where it seems like cases are put in different groups in this switch).



Comment at: 
clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp:65
+switch (InitType->getAs()->getKind()) {
+  case BuiltinType::ShortAccum:
+  case BuiltinType::SatShortAccum:

Indents: I think case should be aligned with the switch.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53299



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


[PATCH] D53299: [Fixed Point Arithmetic] Fix for clang-tools-extra warning

2018-10-15 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 169741.
leonardchan marked 2 inline comments as done.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53299

Files:
  clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp


Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -60,6 +60,48 @@
   case Type::STK_IntegralComplex:
 return getValueOfValueInit(
 InitType->getAs()->getElementType());
+
+  case Type::STK_FixedPoint:
+switch (InitType->getAs()->getKind()) {
+case BuiltinType::ShortAccum:
+case BuiltinType::SatShortAccum:
+  return "0.0hk";
+case BuiltinType::Accum:
+case BuiltinType::SatAccum:
+  return "0.0k";
+case BuiltinType::LongAccum:
+case BuiltinType::SatLongAccum:
+  return "0.0lk";
+case BuiltinType::UShortAccum:
+case BuiltinType::SatUShortAccum:
+  return "0.0uhk";
+case BuiltinType::UAccum:
+case BuiltinType::SatUAccum:
+  return "0.0uk";
+case BuiltinType::ULongAccum:
+case BuiltinType::SatULongAccum:
+  return "0.0ulk";
+case BuiltinType::ShortFract:
+case BuiltinType::SatShortFract:
+  return "0.0hr";
+case BuiltinType::Fract:
+case BuiltinType::SatFract:
+  return "0.0r";
+case BuiltinType::LongFract:
+case BuiltinType::SatLongFract:
+  return "0.0lr";
+case BuiltinType::UShortFract:
+case BuiltinType::SatUShortFract:
+  return "0.0uhr";
+case BuiltinType::UFract:
+case BuiltinType::SatUFract:
+  return "0.0ur";
+case BuiltinType::ULongFract:
+case BuiltinType::SatULongFract:
+  return "0.0ulr";
+default:
+  llvm_unreachable("Unhandled fixed point BuiltinType");
+}
   }
   llvm_unreachable("Invalid scalar type kind");
 }


Index: clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -60,6 +60,48 @@
   case Type::STK_IntegralComplex:
 return getValueOfValueInit(
 InitType->getAs()->getElementType());
+
+  case Type::STK_FixedPoint:
+switch (InitType->getAs()->getKind()) {
+case BuiltinType::ShortAccum:
+case BuiltinType::SatShortAccum:
+  return "0.0hk";
+case BuiltinType::Accum:
+case BuiltinType::SatAccum:
+  return "0.0k";
+case BuiltinType::LongAccum:
+case BuiltinType::SatLongAccum:
+  return "0.0lk";
+case BuiltinType::UShortAccum:
+case BuiltinType::SatUShortAccum:
+  return "0.0uhk";
+case BuiltinType::UAccum:
+case BuiltinType::SatUAccum:
+  return "0.0uk";
+case BuiltinType::ULongAccum:
+case BuiltinType::SatULongAccum:
+  return "0.0ulk";
+case BuiltinType::ShortFract:
+case BuiltinType::SatShortFract:
+  return "0.0hr";
+case BuiltinType::Fract:
+case BuiltinType::SatFract:
+  return "0.0r";
+case BuiltinType::LongFract:
+case BuiltinType::SatLongFract:
+  return "0.0lr";
+case BuiltinType::UShortFract:
+case BuiltinType::SatUShortFract:
+  return "0.0uhr";
+case BuiltinType::UFract:
+case BuiltinType::SatUFract:
+  return "0.0ur";
+case BuiltinType::ULongFract:
+case BuiltinType::SatULongFract:
+  return "0.0ulr";
+default:
+  llvm_unreachable("Unhandled fixed point BuiltinType");
+}
   }
   llvm_unreachable("Invalid scalar type kind");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r344548 - added fix

2018-10-15 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Mon Oct 15 12:59:52 2018
New Revision: 344548

URL: http://llvm.org/viewvc/llvm-project?rev=344548&view=rev
Log:
added fix

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp?rev=344548&r1=344547&r2=344548&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
Mon Oct 15 12:59:52 2018
@@ -60,6 +60,47 @@ static StringRef getValueOfValueInit(con
   case Type::STK_IntegralComplex:
 return getValueOfValueInit(
 InitType->getAs()->getElementType());
+  case Type::STK_FixedPoint:
+switch (InitType->getAs()->getKind()) {
+  case BuiltinType::ShortAccum:
+  case BuiltinType::SatShortAccum:
+return "0.0hk";
+  case BuiltinType::Accum:
+  case BuiltinType::SatAccum:
+return "0.0k";
+  case BuiltinType::LongAccum:
+  case BuiltinType::SatLongAccum:
+return "0.0lk";
+  case BuiltinType::UShortAccum:
+  case BuiltinType::SatUShortAccum:
+return "0.0uhk";
+  case BuiltinType::UAccum:
+  case BuiltinType::SatUAccum:
+return "0.0uk";
+  case BuiltinType::ULongAccum:
+  case BuiltinType::SatULongAccum:
+return "0.0ulk";
+  case BuiltinType::ShortFract:
+  case BuiltinType::SatShortFract:
+return "0.0hr";
+  case BuiltinType::Fract:
+  case BuiltinType::SatFract:
+return "0.0r";
+  case BuiltinType::LongFract:
+  case BuiltinType::SatLongFract:
+return "0.0lr";
+  case BuiltinType::UShortFract:
+  case BuiltinType::SatUShortFract:
+return "0.0uhr";
+  case BuiltinType::UFract:
+  case BuiltinType::SatUFract:
+return "0.0ur";
+  case BuiltinType::ULongFract:
+  case BuiltinType::SatULongFract:
+return "0.0ulr";
+  default:
+llvm_unreachable("Unhandled fixed point BuiltinType");
+}
   }
   llvm_unreachable("Invalid scalar type kind");
 }


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


[PATCH] D53299: [Fixed Point Arithmetic] Fix for clang-tools-extra warning

2018-10-15 Thread Leonard Chan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE344549: [Fixed Point Arithmetic] Fix for clang-tools-extra 
warning (authored by leonardchan, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53299?vs=169741&id=169745#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53299

Files:
  clang-tidy/modernize/UseDefaultMemberInitCheck.cpp


Index: clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===
--- clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -60,46 +60,47 @@
   case Type::STK_IntegralComplex:
 return getValueOfValueInit(
 InitType->getAs()->getElementType());
+
   case Type::STK_FixedPoint:
 switch (InitType->getAs()->getKind()) {
-  case BuiltinType::ShortAccum:
-  case BuiltinType::SatShortAccum:
-return "0.0hk";
-  case BuiltinType::Accum:
-  case BuiltinType::SatAccum:
-return "0.0k";
-  case BuiltinType::LongAccum:
-  case BuiltinType::SatLongAccum:
-return "0.0lk";
-  case BuiltinType::UShortAccum:
-  case BuiltinType::SatUShortAccum:
-return "0.0uhk";
-  case BuiltinType::UAccum:
-  case BuiltinType::SatUAccum:
-return "0.0uk";
-  case BuiltinType::ULongAccum:
-  case BuiltinType::SatULongAccum:
-return "0.0ulk";
-  case BuiltinType::ShortFract:
-  case BuiltinType::SatShortFract:
-return "0.0hr";
-  case BuiltinType::Fract:
-  case BuiltinType::SatFract:
-return "0.0r";
-  case BuiltinType::LongFract:
-  case BuiltinType::SatLongFract:
-return "0.0lr";
-  case BuiltinType::UShortFract:
-  case BuiltinType::SatUShortFract:
-return "0.0uhr";
-  case BuiltinType::UFract:
-  case BuiltinType::SatUFract:
-return "0.0ur";
-  case BuiltinType::ULongFract:
-  case BuiltinType::SatULongFract:
-return "0.0ulr";
-  default:
-llvm_unreachable("Unhandled fixed point BuiltinType");
+case BuiltinType::ShortAccum:
+case BuiltinType::SatShortAccum:
+  return "0.0hk";
+case BuiltinType::Accum:
+case BuiltinType::SatAccum:
+  return "0.0k";
+case BuiltinType::LongAccum:
+case BuiltinType::SatLongAccum:
+  return "0.0lk";
+case BuiltinType::UShortAccum:
+case BuiltinType::SatUShortAccum:
+  return "0.0uhk";
+case BuiltinType::UAccum:
+case BuiltinType::SatUAccum:
+  return "0.0uk";
+case BuiltinType::ULongAccum:
+case BuiltinType::SatULongAccum:
+  return "0.0ulk";
+case BuiltinType::ShortFract:
+case BuiltinType::SatShortFract:
+  return "0.0hr";
+case BuiltinType::Fract:
+case BuiltinType::SatFract:
+  return "0.0r";
+case BuiltinType::LongFract:
+case BuiltinType::SatLongFract:
+  return "0.0lr";
+case BuiltinType::UShortFract:
+case BuiltinType::SatUShortFract:
+  return "0.0uhr";
+case BuiltinType::UFract:
+case BuiltinType::SatUFract:
+  return "0.0ur";
+case BuiltinType::ULongFract:
+case BuiltinType::SatULongFract:
+  return "0.0ulr";
+default:
+  llvm_unreachable("Unhandled fixed point BuiltinType");
 }
   }
   llvm_unreachable("Invalid scalar type kind");


Index: clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
===
--- clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
+++ clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
@@ -60,46 +60,47 @@
   case Type::STK_IntegralComplex:
 return getValueOfValueInit(
 InitType->getAs()->getElementType());
+
   case Type::STK_FixedPoint:
 switch (InitType->getAs()->getKind()) {
-  case BuiltinType::ShortAccum:
-  case BuiltinType::SatShortAccum:
-return "0.0hk";
-  case BuiltinType::Accum:
-  case BuiltinType::SatAccum:
-return "0.0k";
-  case BuiltinType::LongAccum:
-  case BuiltinType::SatLongAccum:
-return "0.0lk";
-  case BuiltinType::UShortAccum:
-  case BuiltinType::SatUShortAccum:
-return "0.0uhk";
-  case BuiltinType::UAccum:
-  case BuiltinType::SatUAccum:
-return "0.0uk";
-  case BuiltinType::ULongAccum:
-  case BuiltinType::SatULongAccum:
-return "0.0ulk";
-  case BuiltinType::ShortFract:
-  case BuiltinType::SatShortFract:
-return "0.0hr";
-  case BuiltinType::Fract:
-  case BuiltinType::SatFract:
-return "0.0r";
-  case BuiltinType::LongFract:
-  case BuiltinType::SatLongFract:
-return "0.0lr";
-  case BuiltinType::UShortFract:
-  case BuiltinType::SatUShortFract:
-return "0.0uhr";
-  case BuiltinType::UFract:
-  case BuiltinType::SatUFract:
-return "0.0ur";
-  case BuiltinType::ULongFract:
-  case BuiltinType::SatU

[clang-tools-extra] r344549 - [Fixed Point Arithmetic] Fix for clang-tools-extra warning

2018-10-15 Thread Leonard Chan via cfe-commits
Author: leonardchan
Date: Mon Oct 15 13:00:03 2018
New Revision: 344549

URL: http://llvm.org/viewvc/llvm-project?rev=344549&view=rev
Log:
[Fixed Point Arithmetic] Fix for clang-tools-extra warning

Fix for warnings generated on unhandled enum value `STK_FixedPoint`.

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp?rev=344549&r1=344548&r2=344549&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseDefaultMemberInitCheck.cpp 
Mon Oct 15 13:00:03 2018
@@ -60,46 +60,47 @@ static StringRef getValueOfValueInit(con
   case Type::STK_IntegralComplex:
 return getValueOfValueInit(
 InitType->getAs()->getElementType());
+
   case Type::STK_FixedPoint:
 switch (InitType->getAs()->getKind()) {
-  case BuiltinType::ShortAccum:
-  case BuiltinType::SatShortAccum:
-return "0.0hk";
-  case BuiltinType::Accum:
-  case BuiltinType::SatAccum:
-return "0.0k";
-  case BuiltinType::LongAccum:
-  case BuiltinType::SatLongAccum:
-return "0.0lk";
-  case BuiltinType::UShortAccum:
-  case BuiltinType::SatUShortAccum:
-return "0.0uhk";
-  case BuiltinType::UAccum:
-  case BuiltinType::SatUAccum:
-return "0.0uk";
-  case BuiltinType::ULongAccum:
-  case BuiltinType::SatULongAccum:
-return "0.0ulk";
-  case BuiltinType::ShortFract:
-  case BuiltinType::SatShortFract:
-return "0.0hr";
-  case BuiltinType::Fract:
-  case BuiltinType::SatFract:
-return "0.0r";
-  case BuiltinType::LongFract:
-  case BuiltinType::SatLongFract:
-return "0.0lr";
-  case BuiltinType::UShortFract:
-  case BuiltinType::SatUShortFract:
-return "0.0uhr";
-  case BuiltinType::UFract:
-  case BuiltinType::SatUFract:
-return "0.0ur";
-  case BuiltinType::ULongFract:
-  case BuiltinType::SatULongFract:
-return "0.0ulr";
-  default:
-llvm_unreachable("Unhandled fixed point BuiltinType");
+case BuiltinType::ShortAccum:
+case BuiltinType::SatShortAccum:
+  return "0.0hk";
+case BuiltinType::Accum:
+case BuiltinType::SatAccum:
+  return "0.0k";
+case BuiltinType::LongAccum:
+case BuiltinType::SatLongAccum:
+  return "0.0lk";
+case BuiltinType::UShortAccum:
+case BuiltinType::SatUShortAccum:
+  return "0.0uhk";
+case BuiltinType::UAccum:
+case BuiltinType::SatUAccum:
+  return "0.0uk";
+case BuiltinType::ULongAccum:
+case BuiltinType::SatULongAccum:
+  return "0.0ulk";
+case BuiltinType::ShortFract:
+case BuiltinType::SatShortFract:
+  return "0.0hr";
+case BuiltinType::Fract:
+case BuiltinType::SatFract:
+  return "0.0r";
+case BuiltinType::LongFract:
+case BuiltinType::SatLongFract:
+  return "0.0lr";
+case BuiltinType::UShortFract:
+case BuiltinType::SatUShortFract:
+  return "0.0uhr";
+case BuiltinType::UFract:
+case BuiltinType::SatUFract:
+  return "0.0ur";
+case BuiltinType::ULongFract:
+case BuiltinType::SatULongFract:
+  return "0.0ulr";
+default:
+  llvm_unreachable("Unhandled fixed point BuiltinType");
 }
   }
   llvm_unreachable("Invalid scalar type kind");


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


[PATCH] D53081: [clang-doc] Add unit tests for serialization

2018-10-15 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 169748.
juliehockett marked 2 inline comments as done.

https://reviews.llvm.org/D53081

Files:
  clang-tools-extra/unittests/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/ClangDocTest.cpp
  clang-tools-extra/unittests/clang-doc/ClangDocTest.h
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp

Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -0,0 +1,349 @@
+//===-- clang-doc/SerializeTest.cpp ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "Serialize.h"
+#include "ClangDocTest.h"
+#include "Representation.h"
+#include "clang/AST/Comment.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+class ClangDocSerializeTestVisitor
+: public RecursiveASTVisitor {
+
+  EmittedInfoList &EmittedInfos;
+  bool Public;
+
+  comments::FullComment *getComment(const NamedDecl *D) const {
+if (RawComment *Comment =
+D->getASTContext().getRawCommentForDeclNoCache(D)) {
+  Comment->setAttached();
+  return Comment->parse(D->getASTContext(), nullptr, D);
+}
+return nullptr;
+  }
+
+public:
+  ClangDocSerializeTestVisitor(EmittedInfoList &EmittedInfos, bool Public)
+  : EmittedInfos(EmittedInfos), Public(Public) {}
+
+  bool VisitNamespaceDecl(const NamespaceDecl *D) {
+auto I = serialize::emitInfo(D, getComment(D), /*Line=*/ 0,
+ /*File=*/"test.cpp", Public);
+if (I)
+  EmittedInfos.emplace_back(std::move(I));
+return true;
+  }
+
+  bool VisitFunctionDecl(const FunctionDecl *D) {
+// Don't visit CXXMethodDecls twice
+if (dyn_cast(D))
+  return true;
+auto I = serialize::emitInfo(D, getComment(D), /*Line=*/ 0,
+ /*File=*/"test.cpp", Public);
+if (I)
+  EmittedInfos.emplace_back(std::move(I));
+return true;
+  }
+
+  bool VisitCXXMethodDecl(const CXXMethodDecl *D) {
+auto I = serialize::emitInfo(D, getComment(D), /*Line=*/ 0,
+ /*File=*/"test.cpp", Public);
+if (I)
+  EmittedInfos.emplace_back(std::move(I));
+return true;
+  }
+
+  bool VisitRecordDecl(const RecordDecl *D) {
+auto I = serialize::emitInfo(D, getComment(D), /*Line=*/ 0,
+ /*File=*/"test.cpp", Public);
+if (I)
+  EmittedInfos.emplace_back(std::move(I));
+return true;
+  }
+
+  bool VisitEnumDecl(const EnumDecl *D) {
+auto I = serialize::emitInfo(D, getComment(D), /*Line=*/ 0,
+ /*File=*/"test.cpp", Public);
+if (I)
+  EmittedInfos.emplace_back(std::move(I));
+return true;
+  }
+};
+
+void ExtractInfosFromCode(StringRef Code, size_t NumExpectedInfos, bool Public,
+  EmittedInfoList &EmittedInfos) {
+  auto ASTUnit = clang::tooling::buildASTFromCode(Code);
+  auto TU = ASTUnit->getASTContext().getTranslationUnitDecl();
+  ClangDocSerializeTestVisitor Visitor(EmittedInfos, Public);
+  Visitor.TraverseTranslationUnitDecl(TU);
+  ASSERT_EQ(NumExpectedInfos, EmittedInfos.size());
+}
+
+void ExtractInfosFromCodeWithArgs(StringRef Code, size_t NumExpectedInfos,
+  bool Public, EmittedInfoList &EmittedInfos,
+  std::vector &Args) {
+  auto ASTUnit = clang::tooling::buildASTFromCodeWithArgs(Code, Args);
+  auto TU = ASTUnit->getASTContext().getTranslationUnitDecl();
+  ClangDocSerializeTestVisitor Visitor(EmittedInfos, Public);
+  Visitor.TraverseTranslationUnitDecl(TU);
+  ASSERT_EQ(NumExpectedInfos, EmittedInfos.size());
+}
+
+// Test serialization of namespace declarations.
+TEST(SerializeTest, emitNamespaceInfo) {
+  EmittedInfoList Infos;
+  ExtractInfosFromCode("namespace A { namespace B { void f() {} } }", 3,
+   /*Public=*/false, Infos);
+
+  NamespaceInfo *A = InfoAsNamespace(Infos[0].get());
+  NamespaceInfo ExpectedA(EmptySID, "A");
+  CheckNamespaceInfo(&ExpectedA, A);
+
+  NamespaceInfo *B = InfoAsNamespace(Infos[1].get());
+  NamespaceInfo ExpectedB(EmptySID, "B");
+  ExpectedB.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+  CheckNamespaceInfo(&ExpectedB, B);
+
+  NamespaceInfo *BWithFunction = InfoAsNamespace(Infos[2].get());
+  NamespaceInfo ExpectedBWithFunction(EmptySID);
+  FunctionInfo F;
+  F.Name = "f";
+  F.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+  F.DefLoc = Location(0, llvm::SmallString<16>("test.cpp"));
+  F.Namespa

[PATCH] D53210: Revert 344389 "Revert r344375 "[Driver] check for exit code from SIGPIPE""

2018-10-15 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

Nevermind, looks like flaky tests.  Will try to repro and contact msan 
maintainers.


Repository:
  rC Clang

https://reviews.llvm.org/D53210



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


[PATCH] D53082: [clang-doc] Add unit tests for bitcode

2018-10-15 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D53082



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


[PATCH] D53081: [clang-doc] Add unit tests for serialization

2018-10-15 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp:320
+  ExtractInfosFromCodeWithArgs(
+  "export module M;\n"
+  "int moduleFunction(int x);\n"

Can you use raw strings here (and elsewhere in this file) as well?


https://reviews.llvm.org/D53081



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


[PATCH] D53084: [clang-doc] Add unit tests for YAML

2018-10-15 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 169751.
juliehockett marked an inline comment as done.

https://reviews.llvm.org/D53084

Files:
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -0,0 +1,427 @@
+//===-- clang-doc/YAMLGeneratorTest.cpp
+//===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+std::unique_ptr getYAMLGenerator() {
+  auto G = doc::findGeneratorByName("yaml");
+  if (!G)
+return nullptr;
+  return std::move(G.get());
+}
+
+TEST(YAMLGeneratorTest, emitNamespaceYAML) {
+  NamespaceInfo I;
+  I.Name = "Namespace";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
+ InfoType::IT_namespace);
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual);
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'Namespace'
+Namespace:   
+  - Type:Namespace
+Name:'A'
+ChildNamespaces: 
+  - Type:Namespace
+Name:'ChildNamespace'
+ChildRecords:
+  - Type:Record
+Name:'ChildStruct'
+ChildFunctions:  
+  - USR: ''
+Name:'OneFunction'
+ReturnType:  
+ChildEnums:  
+  - USR: ''
+Name:'OneEnum'
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(YAMLGeneratorTest, emitRecordYAML) {
+  RecordInfo I;
+  I.Name = "r";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>("test.cpp"));
+  I.Loc.emplace_back(12, llvm::SmallString<16>("test.cpp"));
+
+  I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
+  I.TagType = TagTypeKind::TTK_Class;
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
+  I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual);
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'r'
+Namespace:   
+  - Type:Namespace
+Name:'A'
+DefLocation: 
+  LineNumber:  10
+  Filename:'test.cpp'
+Location:
+  - LineNumber:  12
+Filename:'test.cpp'
+TagType: Class
+Members: 
+  - Type:
+  Name:'int'
+Name:'X'
+Access:  Private
+Parents: 
+  - Type:Record
+Name:'F'
+VirtualParents:  
+  - Type:Record
+Name:'G'
+ChildRecords:
+  - Type:Record
+Name:'ChildStruct'
+ChildFunctions:  
+  - USR: ''
+Name:'OneFunction'
+ReturnType:  
+ChildEnums:  
+  - USR: ''
+Name:'OneEnum'
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(YAMLGeneratorTest, emitFunctionYAML) {
+  FunctionInfo I;
+  I.Name = "f";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>("test.cpp"));
+  I.Loc.emplace_back(12, llvm::SmallString<16>("test.cpp"));
+
+  I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+  I.Params.emplace_back("int", "P");
+  I.IsMethod = true;
+  I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
+

[PATCH] D53085: [clang-doc] Add unit tests for Markdown

2018-10-15 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 169752.
juliehockett marked an inline comment as done.

https://reviews.llvm.org/D53085

Files:
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
@@ -0,0 +1,361 @@
+//===-- clang-doc/MDGeneratorTest.cpp -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+std::unique_ptr getMDGenerator() {
+  auto G = doc::findGeneratorByName("md");
+  if (!G)
+return nullptr;
+  return std::move(G.get());
+}
+
+TEST(MDGeneratorTest, emitNamespaceMD) {
+  NamespaceInfo I;
+  I.Name = "Namespace";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
+ InfoType::IT_namespace);
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getMDGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual);
+  assert(!Err);
+  std::string Expected = R"raw(# namespace Namespace
+
+
+
+## Namespaces
+
+ChildNamespace
+
+
+
+## Records
+
+ChildStruct
+
+
+
+## Functions
+
+### OneFunction
+
+* OneFunction()*
+
+
+
+## Enums
+
+| enum OneEnum |
+
+--
+
+
+
+
+
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(MDGeneratorTest, emitRecordMD) {
+  RecordInfo I;
+  I.Name = "r";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>("test.cpp"));
+  I.Loc.emplace_back(12, llvm::SmallString<16>("test.cpp"));
+
+  I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
+  I.TagType = TagTypeKind::TTK_Class;
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
+  I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getMDGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual);
+  assert(!Err);
+  std::string Expected = R"raw(# class r
+
+*Defined at line 10 of test.cpp*
+
+Inherits from F, G
+
+
+
+## Members
+
+private int X
+
+
+
+## Records
+
+ChildStruct
+
+
+
+## Functions
+
+### OneFunction
+
+* OneFunction()*
+
+
+
+## Enums
+
+| enum OneEnum |
+
+--
+
+
+
+
+
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(MDGeneratorTest, emitFunctionMD) {
+  FunctionInfo I;
+  I.Name = "f";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>("test.cpp"));
+  I.Loc.emplace_back(12, llvm::SmallString<16>("test.cpp"));
+
+  I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+  I.Params.emplace_back("int", "P");
+  I.IsMethod = true;
+  I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
+
+  auto G = getMDGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual);
+  assert(!Err);
+  std::string Expected = R"raw(### f
+
+*void f(int P)*
+
+*Defined at line 10 of test.cpp*
+
+)raw";
+
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(MDGeneratorTest, emitEnumMD) {
+  EnumInfo I;
+  I.Name = "e";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>("test.cpp"));
+  I.Loc.emplace_back(12, llvm::SmallString<16>("test.cpp"));
+
+  I.Members.emplace_back("X");
+  I.Scoped = true;
+
+  auto G = getMDGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual);
+  assert(!Err);
+  std::string Expected = R"raw(| enum class e |
+
+--
+
+| X |
+
+
+*Defined at line 10 of test.cpp*
+
+)raw";
+
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(MDGeneratorTest, emitCommentMD) {
+  FunctionInfo I;
+  I.Name = "f";
+  I.DefLoc = Location(10, llvm::SmallString<16>("test.cpp"));
+  I.ReturnType = TypeInfo(EmptySID, "void", I

  1   2   >