[PATCH] D66404: [CFG] Make destructor calls more accurate

2019-08-29 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

This commit causes some warnings in the Linux kernel that appear to be false 
positives. For example:

CC  drivers/base/cpu.o
  drivers/base/cpu.c:404:1: error: control may reach end of non-void function 
[-Werror,-Wreturn-type]
  }
  ^
  1 error generated.

Corresponds to this function 
:

  struct device *get_cpu_device(unsigned cpu)
  {
if (cpu < nr_cpu_ids && cpu_possible(cpu))
return per_cpu(cpu_sys_devices, cpu);
else
return NULL;
  }

creduce spits out:

  a() {
if (b())
  return ({
while (0)
  ;
0;
  });
else
  return 0;
  }


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66404



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


[PATCH] D66406: [clangd] Update themeRuleMatcher when color theme changes in vscode extension.

2019-08-29 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 217785.
jvikstrom marked an inline comment as done.
jvikstrom added a comment.

Use `conf.affectsConfiguration('workbench.colorTheme')` instead of keeping 
track of the old color theme manually.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66406

Files:
  clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts


Index: 
clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -91,6 +91,13 @@
 // highlighter being created.
 this.highlighter = new Highlighter(this.scopeLookupTable);
 this.subscriptions.push(vscode.Disposable.from(this.highlighter));
+// Adds a listener to reload the theme when it changes.
+this.subscriptions.push(
+vscode.workspace.onDidChangeConfiguration((conf) => {
+  if (!conf.affectsConfiguration('workbench.colorTheme'))
+return;
+  this.loadCurrentTheme();
+}));
 this.loadCurrentTheme();
 // Event handling for handling with TextDocuments/Editors lifetimes.
 this.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(


Index: clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -91,6 +91,13 @@
 // highlighter being created.
 this.highlighter = new Highlighter(this.scopeLookupTable);
 this.subscriptions.push(vscode.Disposable.from(this.highlighter));
+// Adds a listener to reload the theme when it changes.
+this.subscriptions.push(
+vscode.workspace.onDidChangeConfiguration((conf) => {
+  if (!conf.affectsConfiguration('workbench.colorTheme'))
+return;
+  this.loadCurrentTheme();
+}));
 this.loadCurrentTheme();
 // Event handling for handling with TextDocuments/Editors lifetimes.
 this.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66928: [clangd] Collecting main file macro expansion locations in ParsedAST.

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

TokenBuffer does not collect macro expansions inside macro arguments which is 
needed for semantic higlighting. Therefore collects macro expansions in the 
main file in a PPCallback when building the ParsedAST instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66928

Files:
  clang-tools-extra/clangd/ClangdUnit.cpp
  clang-tools-extra/clangd/ClangdUnit.h
  clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp

Index: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
@@ -244,6 +244,28 @@
   EXPECT_EQ(T.expandedTokens().drop_back().back().text(SM), "}");
 }
 
+TEST(ClangdUnitTest, CollectsMainFileMacroExpansions) {
+  Annotations TestCase(R"cpp(
+#define MACRO_ARGS(X, Y) X Y
+^MACRO_EXP(int A);
+^MACRO_ARGS(^MACRO_ARGS(^MACRO_EXP(int), A), ^MACRO_EXP(= 2));
+  )cpp");
+  auto TU = TestTU::withCode(TestCase.code());
+  TU.HeaderCode = R"cpp(
+#define INNER_MACRO_EXP(X) X
+#define MACRO_EXP(X) INNER_MACRO_EXP(X)
+MACRO_EXP(int B);
+  )cpp";
+  ParsedAST AST = TU.build();
+  const std::vector &MacroExpansionLocations =
+  AST.getMainFileMacroExpansionLocations();
+  std::vector MacroExpansionPositions(MacroExpansionLocations.size());
+  for (int I = 0, End = MacroExpansionLocations.size(); I < End; ++I)
+MacroExpansionPositions[I] =
+sourceLocToPosition(AST.getSourceManager(), MacroExpansionLocations[I]);
+  EXPECT_EQ(MacroExpansionPositions, TestCase.points());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ClangdUnit.h
===
--- clang-tools-extra/clangd/ClangdUnit.h
+++ clang-tools-extra/clangd/ClangdUnit.h
@@ -116,6 +116,7 @@
   const IncludeStructure &getIncludeStructure() const;
   const CanonicalIncludes &getCanonicalIncludes() const;
 
+  const std::vector &getMainFileMacroExpansionLocations() const;
   /// Tokens recorded while parsing the main file.
   /// (!) does not have tokens from the preamble.
   const syntax::TokenBuffer &getTokens() const { return Tokens; }
@@ -124,6 +125,7 @@
   ParsedAST(std::shared_ptr Preamble,
 std::unique_ptr Clang,
 std::unique_ptr Action, syntax::TokenBuffer Tokens,
+std::vector MainFileMacroExpLocs,
 std::vector LocalTopLevelDecls, std::vector Diags,
 IncludeStructure Includes, CanonicalIncludes CanonIncludes);
 
@@ -143,6 +145,8 @@
   ///   - Does not have spelled or expanded tokens for files from preamble.
   syntax::TokenBuffer Tokens;
 
+  /// All macro expansion locations in the main file.
+  std::vector MainFileMacroExpLocs;
   // Data, stored after parsing.
   std::vector Diags;
   // Top-level decls inside the current file. Not that this does not include
Index: clang-tools-extra/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/clangd/ClangdUnit.cpp
+++ clang-tools-extra/clangd/ClangdUnit.cpp
@@ -32,6 +32,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Sema/Sema.h"
@@ -103,6 +104,24 @@
   std::vector TopLevelDecls;
 };
 
+class CollectMainFileMacroExpansions : public PPCallbacks {
+  const SourceManager &SM;
+  std::vector &MainFileMacroLocs;
+
+public:
+  CollectMainFileMacroExpansions(const SourceManager &SM,
+ std::vector &MainFileMacroLocs)
+  : SM(SM), MainFileMacroLocs(MainFileMacroLocs) {}
+
+  virtual void MacroExpands(const Token &MacroNameTok,
+const MacroDefinition &MD, SourceRange Range,
+const MacroArgs *Args) {
+SourceLocation L = MacroNameTok.getLocation();
+if (isInsideMainFile(SM.getSpellingLoc(L), SM))
+  MainFileMacroLocs.push_back(L);
+  }
+};
+
 class CollectMainFileMacros : public PPCallbacks {
 public:
   explicit CollectMainFileMacros(const SourceManager &SM,
@@ -414,6 +433,11 @@
   // (We can't *just* use the replayed includes, they don't have Resolved path).
   Clang->getPreprocessor().addPPCallbacks(
   collectIncludeStructureCallback(Clang->getSourceManager(), &Includes));
+  // Collect the macro expansions in the main file.
+  std::vector MainFileMacroExpLocs;
+  Clang->getPreprocessor().addPPCallbacks(
+  std::make_unique(
+  Clang->getSourceManager(), MainFileMacroExpLocs));
 
   // Copy over the includes from the preamble, then combine with the
   /

[clang-tools-extra] r370304 - Reland "[clangd] Migrate last tweak tests to TweakTesting.h and remove old helpers. NFC"

2019-08-29 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Thu Aug 29 01:20:48 2019
New Revision: 370304

URL: http://llvm.org/viewvc/llvm-project?rev=370304&view=rev
Log:
Reland "[clangd] Migrate last tweak tests to TweakTesting.h and remove old 
helpers. NFC"

This reverts commit 3dcf55aa45bad800533b36b70a14ebeb2b84e219, and avoids
use of multiline raw strings in macro calls.

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

Modified: clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp?rev=370304&r1=370303&r2=370304&view=diff
==
--- clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp Thu Aug 29 01:20:48 
2019
@@ -23,8 +23,6 @@
 #include "gtest/gtest.h"
 #include 
 
-using llvm::Failed;
-using llvm::Succeeded;
 using ::testing::AllOf;
 using ::testing::HasSubstr;
 using ::testing::StartsWith;
@@ -33,100 +31,6 @@ namespace clang {
 namespace clangd {
 namespace {
 
-// FIXME(sammccall): migrate the rest of the tests to use TweakTesting.h and
-// remove these helpers.
-std::string markRange(llvm::StringRef Code, Range R) {
-  size_t Begin = llvm::cantFail(positionToOffset(Code, R.start));
-  size_t End = llvm::cantFail(positionToOffset(Code, R.end));
-  assert(Begin <= End);
-  if (Begin == End) // Mark a single point.
-return (Code.substr(0, Begin) + "^" + Code.substr(Begin)).str();
-  // Mark a range.
-  return (Code.substr(0, Begin) + "[[" + Code.substr(Begin, End - Begin) +
-  "]]" + Code.substr(End))
-  .str();
-}
-
-void checkAvailable(StringRef ID, llvm::StringRef Input, bool Available) {
-  Annotations Code(Input);
-  ASSERT_TRUE(0 < Code.points().size() || 0 < Code.ranges().size())
-  << "no points of interest specified";
-  TestTU TU;
-  TU.Filename = "foo.cpp";
-  TU.Code = Code.code();
-
-  ParsedAST AST = TU.build();
-
-  auto CheckOver = [&](Range Selection) {
-unsigned Begin = cantFail(positionToOffset(Code.code(), Selection.start));
-unsigned End = cantFail(positionToOffset(Code.code(), Selection.end));
-auto T = prepareTweak(ID, Tweak::Selection(AST, Begin, End));
-if (Available)
-  EXPECT_THAT_EXPECTED(T, Succeeded())
-  << "code is " << markRange(Code.code(), Selection);
-else
-  EXPECT_THAT_EXPECTED(T, Failed())
-  << "code is " << markRange(Code.code(), Selection);
-  };
-  for (auto P : Code.points())
-CheckOver(Range{P, P});
-  for (auto R : Code.ranges())
-CheckOver(R);
-}
-
-/// Checks action is available at every point and range marked in \p Input.
-void checkAvailable(StringRef ID, llvm::StringRef Input) {
-  return checkAvailable(ID, Input, /*Available=*/true);
-}
-
-/// Same as checkAvailable, but checks the action is not available.
-void checkNotAvailable(StringRef ID, llvm::StringRef Input) {
-  return checkAvailable(ID, Input, /*Available=*/false);
-}
-
-llvm::Expected apply(StringRef ID, llvm::StringRef Input) {
-  Annotations Code(Input);
-  Range SelectionRng;
-  if (Code.points().size() != 0) {
-assert(Code.ranges().size() == 0 &&
-   "both a cursor point and a selection range were specified");
-SelectionRng = Range{Code.point(), Code.point()};
-  } else {
-SelectionRng = Code.range();
-  }
-  TestTU TU;
-  TU.Filename = "foo.cpp";
-  TU.Code = Code.code();
-
-  ParsedAST AST = TU.build();
-  unsigned Begin = cantFail(positionToOffset(Code.code(), SelectionRng.start));
-  unsigned End = cantFail(positionToOffset(Code.code(), SelectionRng.end));
-  Tweak::Selection S(AST, Begin, End);
-
-  auto T = prepareTweak(ID, S);
-  if (!T)
-return T.takeError();
-  return (*T)->apply(S);
-}
-
-llvm::Expected applyEdit(StringRef ID, llvm::StringRef Input) {
-  auto Effect = apply(ID, Input);
-  if (!Effect)
-return Effect.takeError();
-  if (!Effect->ApplyEdit)
-return llvm::createStringError(llvm::inconvertibleErrorCode(),
-   "No replacements");
-  Annotations Code(Input);
-  return applyAllReplacements(Code.code(), *Effect->ApplyEdit);
-}
-
-void checkTransform(llvm::StringRef ID, llvm::StringRef Input,
-std::string Output) {
-  auto Result = applyEdit(ID, Input);
-  ASSERT_TRUE(bool(Result)) << llvm::toString(Result.takeError()) << Input;
-  EXPECT_EQ(Output, std::string(*Result)) << Input;
-}
-
 TWEAK_TEST(SwapIfBranches);
 TEST_F(SwapIfBranchesTest, Test) {
   Context = Function;
@@ -215,9 +119,9 @@ TEST_F(DumpRecordLayoutTest, Test) {
   AllOf(StartsWith("message:"), HasSubstr("0 |   int x")));
 }
 
-TEST(TweaksTest, ExtractVariable) {
-  llvm::StringLiteral ID = "ExtractVariable";
-  checkAvailable(ID, R"cpp(
+TWEAK_TEST(ExtractVariable);
+TEST_F(ExtractVariableTest, Test) {
+  const char *AvailableCases = R"cpp(
 int xyz(int a = 1) {
   struct T {
 int bar(in

[PATCH] D66669: [X86] Remove what little support we had for MPX

2019-08-29 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.

LGTM - please reword the X86InstrMPX.td comment like @xbolva00 suggested


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D9



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


[PATCH] D66928: [clangd] Collecting main file macro expansion locations in ParsedAST.

2019-08-29 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Looks great, just requests for comments and more test-cases from my side




Comment at: clang-tools-extra/clangd/ClangdUnit.h:148
 
+  /// All macro expansion locations in the main file.
+  std::vector MainFileMacroExpLocs;

NIT: clarify that this is the start location of the identifier that was 
macro-expanded.
"expansion location" is an overloaded term



Comment at: clang-tools-extra/clangd/ClangdUnit.h:149
+  /// All macro expansion locations in the main file.
+  std::vector MainFileMacroExpLocs;
   // Data, stored after parsing.

Could you please document whether these include:
1. locations outside the main file
2. locations from inside other macro expansions, i.e. those that have 
`isMacroID() == true`.



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:248
+TEST(ClangdUnitTest, CollectsMainFileMacroExpansions) {
+  Annotations TestCase(R"cpp(
+#define MACRO_ARGS(X, Y) X Y

Could you add a few more interesting cases?

1. Macros outside the main file **and** the preamble:
```
// foo.inc
int a = ID(1);

// foo.cpp
#define ID(X) X

int b;
#include "foo.inc"
```

2. macro expansions from token concatenations
```
#define FOO(X) X##1()
#define MACRO1() 123

int a = FOO(MACRO);
```
3. Macro names inside other macros:
```
#define FOO BAR
#define BAR 1


int a = FOO; // should BAR at line 1 be highlighted?

```

4. #include not part of the preamble:
```
#define FOO 1

// Preamble ends here.
int a = 10;
#include "some_file_with_macros.h" // <-- should not get any macros from here
```



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:264
+  for (int I = 0, End = MacroExpansionLocations.size(); I < End; ++I)
+MacroExpansionPositions[I] =
+sourceLocToPosition(AST.getSourceManager(), 
MacroExpansionLocations[I]);

NIT: maybe use `push_back` and for-each loop, the resulting code should be 
simpler and readability is more important for the test code than performance:
```
std::vector Positions;
for (SourceLocation Loc : AST.getMainFileMacros())
  Positions.push_back(sourceLocToPosition(Loc));
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66928



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


[clang-tools-extra] r370305 - [clangd] Update themeRuleMatcher when color theme changes in vscode extension.

2019-08-29 Thread Johan Vikstrom via cfe-commits
Author: jvikstrom
Date: Thu Aug 29 01:40:17 2019
New Revision: 370305

URL: http://llvm.org/viewvc/llvm-project?rev=370305&view=rev
Log:
[clangd] Update themeRuleMatcher when color theme changes in vscode extension.

Summary:
Add event listener that listens to configuration changes and reloads the 
ThemeRuleMatcher when the theme changes.

Right now it will not recolor the files, depends on the colorizer CL for that.

Reviewers: hokein, ilya-biryukov

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

Tags: #clang

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

Modified:

clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts

Modified: 
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts?rev=370305&r1=370304&r2=370305&view=diff
==
--- 
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
 (original)
+++ 
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
 Thu Aug 29 01:40:17 2019
@@ -91,6 +91,13 @@ export class SemanticHighlightingFeature
 // highlighter being created.
 this.highlighter = new Highlighter(this.scopeLookupTable);
 this.subscriptions.push(vscode.Disposable.from(this.highlighter));
+// Adds a listener to reload the theme when it changes.
+this.subscriptions.push(
+vscode.workspace.onDidChangeConfiguration((conf) => {
+  if (!conf.affectsConfiguration('workbench.colorTheme'))
+return;
+  this.loadCurrentTheme();
+}));
 this.loadCurrentTheme();
 // Event handling for handling with TextDocuments/Editors lifetimes.
 this.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(


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


[PATCH] D66406: [clangd] Update theme when color theme changes in vscode extension.

2019-08-29 Thread Johan Vikström via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL370305: [clangd] Update themeRuleMatcher when color theme 
changes in vscode extension. (authored by jvikstrom, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66406?vs=217785&id=217794#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66406

Files:
  
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts


Index: 
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- 
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ 
clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -91,6 +91,13 @@
 // highlighter being created.
 this.highlighter = new Highlighter(this.scopeLookupTable);
 this.subscriptions.push(vscode.Disposable.from(this.highlighter));
+// Adds a listener to reload the theme when it changes.
+this.subscriptions.push(
+vscode.workspace.onDidChangeConfiguration((conf) => {
+  if (!conf.affectsConfiguration('workbench.colorTheme'))
+return;
+  this.loadCurrentTheme();
+}));
 this.loadCurrentTheme();
 // Event handling for handling with TextDocuments/Editors lifetimes.
 this.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(


Index: clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
===
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/src/semantic-highlighting.ts
@@ -91,6 +91,13 @@
 // highlighter being created.
 this.highlighter = new Highlighter(this.scopeLookupTable);
 this.subscriptions.push(vscode.Disposable.from(this.highlighter));
+// Adds a listener to reload the theme when it changes.
+this.subscriptions.push(
+vscode.workspace.onDidChangeConfiguration((conf) => {
+  if (!conf.affectsConfiguration('workbench.colorTheme'))
+return;
+  this.loadCurrentTheme();
+}));
 this.loadCurrentTheme();
 // Event handling for handling with TextDocuments/Editors lifetimes.
 this.subscriptions.push(vscode.window.onDidChangeVisibleTextEditors(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66637: [clangd] Support multifile edits as output of Tweaks

2019-08-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 14 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/SourceCode.cpp:601
+  llvm::inconvertibleErrorCode(),
+  "File contents differ on disk for %s, please save", FilePath.data());
+}

sammccall wrote:
> you seem to be checking this both here and in clangdlspserver. Why?
the contents in here are coming from disk, whereas the one in clangdlspserver 
is coming from drafts. I suppose it would make more sense to merge the two in 
clangdlspserver, use draft manager as content source backed by disk in case 
user hasn't opened that file.



Comment at: clang-tools-extra/clangd/SourceCode.h:215
 
+/// Formats the edits in \p ApplyEdits and generates TextEdits from those.
+/// Ensures the files in FS are consistent with the files used while generating

sammccall wrote:
> not sure what "generates TextEdits from those" refers to.
> 
> Could this function be called "reformatEdits" or "formatAroundEdits"?
> not sure what "generates TextEdits from those" refers to.

Leftover from an old-version.



Comment at: clang-tools-extra/clangd/SourceCode.h:220
+llvm::Error formatAndGenerateEdits(llvm::vfs::FileSystem *FS,
+   llvm::StringMap &ApplyEdits,
+   llvm::StringRef MainFilePath,

sammccall wrote:
> This signature is confusing: we pass code in *three* different ways (FS, 
> Edits, and MainFileCode). Much of this is because we put the loop (and 
> therefore all special cases) inside this function.
> The logic around the way the VFS is mapped for the main file vs others 
> doesn't really belong in this layer. Neither does "please save"...
> 
> It seems this wants to be something simpler/smaller like `reformatEdit(const 
> Edit&, const Style&)` that could be called from ClangdServer. There's 
> probably another helper like `checkApplies(const Edit&, VFS*)` that would go 
> in ClangdLSPServer.
> 
as discussed offline for `reformatEdit` to work, made `InitialCode` in `Edit` 
public. As both formatting and style deduction requires access to file contents.

for `checkApplies`, it requires access to both `VFS` and `DraftMgr`and pretty 
special use-case for clangdlspserver, so don't think the function would carry 
its weight. Therefore left the check inlined.



Comment at: clang-tools-extra/clangd/refactor/Tweak.h:74
+/// A mapping from absolute file path to edits.
+llvm::Optional> ApplyEdits;
 

sammccall wrote:
> what's the difference between `None` and an empty map?
`None` :P


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66637



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


[PATCH] D66637: [clangd] Support multifile edits as output of Tweaks

2019-08-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 217803.
kadircet marked 4 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66637

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/refactor/Tweak.cpp
  clang-tools-extra/clangd/refactor/Tweak.h
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
  clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
  clang-tools-extra/clangd/unittests/TweakTesting.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -113,11 +113,15 @@
   auto Effect = apply(ID, Input);
   if (!Effect)
 return Effect.takeError();
-  if (!Effect->ApplyEdit)
+  if (Effect->ApplyEdits.empty())
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"No replacements");
+  auto Edits = Effect->ApplyEdits;
+  if (Edits.size() > 1)
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "Multi-file edits");
   Annotations Code(Input);
-  return applyAllReplacements(Code.code(), *Effect->ApplyEdit);
+  return applyAllReplacements(Code.code(), Edits.begin()->second.Replacements);
 }
 
 void checkTransform(llvm::StringRef ID, llvm::StringRef Input,
Index: clang-tools-extra/clangd/unittests/TweakTesting.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTesting.cpp
+++ clang-tools-extra/clangd/unittests/TweakTesting.cpp
@@ -9,8 +9,8 @@
 #include "TweakTesting.h"
 
 #include "Annotations.h"
-#include "refactor/Tweak.h"
 #include "SourceCode.h"
+#include "refactor/Tweak.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/Support/Error.h"
 
@@ -98,14 +98,16 @@
 return "fail: " + llvm::toString(Result.takeError());
   if (Result->ShowMessage)
 return "message:\n" + *Result->ShowMessage;
-  if (Result->ApplyEdit) {
-if (auto NewText =
-tooling::applyAllReplacements(Input.code(), *Result->ApplyEdit))
-  return unwrap(Context, *NewText);
-else
-  return "bad edits: " + llvm::toString(NewText.takeError());
-  }
-  return "no effect";
+  if (Result->ApplyEdits.empty())
+return "no effect";
+  if (Result->ApplyEdits.size() > 1)
+return "received multi-file edits";
+
+  auto ApplyEdit = Result->ApplyEdits.begin()->second;
+  if (auto NewText = ApplyEdit.apply())
+return unwrap(Context, *NewText);
+  else
+return "bad edits: " + llvm::toString(NewText.takeError());
 }
 
 ::testing::Matcher TweakTest::isAvailable() const {
Index: clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
@@ -90,7 +90,7 @@
  ElseRng->getBegin(),
  ElseCode.size(), ThenCode)))
 return std::move(Err);
-  return Effect::applyEdit(Result);
+  return mainFileEdit(SrcMgr, std::move(Result));
 }
 
 } // namespace
Index: clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
@@ -88,10 +88,12 @@
 }
 
 Expected RawStringLiteral::apply(const Selection &Inputs) {
-  return Effect::applyEdit(tooling::Replacements(
+  auto &SM = Inputs.AST.getSourceManager();
+  auto Reps = tooling::Replacements(
   tooling::Replacement(Inputs.AST.getSourceManager(), Str,
("R\"(" + Str->getBytes() + ")\"").str(),
-   Inputs.AST.getASTContext().getLangOpts(;
+   Inputs.AST.getASTContext().getLangOpts()));
+  return mainFileEdit(SM, std::move(Reps));
 }
 
 } // namespace
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -468,7 +468,7 @@
   // replace

r370314 - [Analyzer] Iterator Checkers - Make range errors and invalidated access fatal

2019-08-29 Thread Adam Balogh via cfe-commits
Author: baloghadamsoftware
Date: Thu Aug 29 02:35:47 2019
New Revision: 370314

URL: http://llvm.org/viewvc/llvm-project?rev=370314&view=rev
Log:
[Analyzer] Iterator Checkers - Make range errors and invalidated access fatal

Range errors (dereferencing or incrementing the past-the-end iterator or
decrementing the iterator of the first element of the range) and access of
invalidated iterators lead to undefined behavior. There is no point to
continue the analysis after such an error on the same execution path, but
terminate it by a sink node (fatal error). This also improves the
performance and helps avoiding double reports (e.g. in case of nested
iterators).

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


Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h
cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp
cfe/trunk/test/Analysis/invalidated-iterator.cpp
cfe/trunk/test/Analysis/iterator-range.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp?rev=370314&r1=370313&r2=370314&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp Thu Aug 29 
02:35:47 2019
@@ -356,14 +356,12 @@ bool isZero(ProgramStateRef State, const
 
 IteratorChecker::IteratorChecker() {
   OutOfRangeBugType.reset(
-  new BugType(this, "Iterator out of range", "Misuse of STL APIs",
-  /*SuppressOnSink=*/true));
+  new BugType(this, "Iterator out of range", "Misuse of STL APIs"));
   MismatchedBugType.reset(
   new BugType(this, "Iterator(s) mismatched", "Misuse of STL APIs",
   /*SuppressOnSink=*/true));
   InvalidatedBugType.reset(
-  new BugType(this, "Iterator invalidated", "Misuse of STL APIs",
-  /*SuppressOnSink=*/true));
+  new BugType(this, "Iterator invalidated", "Misuse of STL APIs"));
 }
 
 void IteratorChecker::checkPreCall(const CallEvent &Call,
@@ -928,7 +926,7 @@ void IteratorChecker::verifyDereference(
   auto State = C.getState();
   const auto *Pos = getIteratorPosition(State, Val);
   if (Pos && isPastTheEnd(State, *Pos)) {
-auto *N = C.generateNonFatalErrorNode(State);
+auto *N = C.generateErrorNode(State);
 if (!N)
   return;
 reportOutOfRangeBug("Past-the-end iterator dereferenced.", Val, C, N);
@@ -940,7 +938,7 @@ void IteratorChecker::verifyAccess(Check
   auto State = C.getState();
   const auto *Pos = getIteratorPosition(State, Val);
   if (Pos && !Pos->isValid()) {
-auto *N = C.generateNonFatalErrorNode(State);
+auto *N = C.generateErrorNode(State);
 if (!N) {
   return;
 }
@@ -1048,14 +1046,14 @@ void IteratorChecker::verifyRandomIncrOr
   // The result may be the past-end iterator of the container, but any other
   // out of range position is undefined behaviour
   if (isAheadOfRange(State, advancePosition(C, Op, *Pos, Value))) {
-auto *N = C.generateNonFatalErrorNode(State);
+auto *N = C.generateErrorNode(State);
 if (!N)
   return;
 reportOutOfRangeBug("Iterator decremented ahead of its valid range.", LHS,
 C, N);
   }
   if (isBehindPastTheEnd(State, advancePosition(C, Op, *Pos, Value))) {
-auto *N = C.generateNonFatalErrorNode(State);
+auto *N = C.generateErrorNode(State);
 if (!N)
   return;
 reportOutOfRangeBug("Iterator incremented behind the past-the-end "

Modified: cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h?rev=370314&r1=370313&r2=370314&view=diff
==
--- cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h (original)
+++ cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h Thu Aug 29 
02:35:47 2019
@@ -150,7 +150,7 @@ template  operator++() { item = item->next; return *this; 
}
   __list_iterator operator++(int) {
 auto tmp = *this;
@@ -175,6 +175,9 @@ template 
+  friend struct __list_iterator;
+
 private:
   T* item;
 };
@@ -190,7 +193,7 @@ template  operator++() { item = item->next; return *this; 
}
   __fwdl_iterator operator++(int) {
 auto tmp = *this;
@@ -208,6 +211,9 @@ template 
+  friend struct __fwdl_iterator;
+
 private:
   T* item;
 };

Modified: cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp?rev=370314&r1=370313&r2=370314&view=diff
==
--- cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp (original)
+++ cf

[PATCH] D62893: [Analyzer] Iterator Checkers - Make range errors and invalidated access fatal

2019-08-29 Thread Balogh, Ádám via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL370314: [Analyzer] Iterator Checkers - Make range errors and 
invalidated access fatal (authored by baloghadamsoftware, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62893?vs=203105&id=217804#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D62893

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h
  cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp
  cfe/trunk/test/Analysis/invalidated-iterator.cpp
  cfe/trunk/test/Analysis/iterator-range.cpp

Index: cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
@@ -356,14 +356,12 @@
 
 IteratorChecker::IteratorChecker() {
   OutOfRangeBugType.reset(
-  new BugType(this, "Iterator out of range", "Misuse of STL APIs",
-  /*SuppressOnSink=*/true));
+  new BugType(this, "Iterator out of range", "Misuse of STL APIs"));
   MismatchedBugType.reset(
   new BugType(this, "Iterator(s) mismatched", "Misuse of STL APIs",
   /*SuppressOnSink=*/true));
   InvalidatedBugType.reset(
-  new BugType(this, "Iterator invalidated", "Misuse of STL APIs",
-  /*SuppressOnSink=*/true));
+  new BugType(this, "Iterator invalidated", "Misuse of STL APIs"));
 }
 
 void IteratorChecker::checkPreCall(const CallEvent &Call,
@@ -928,7 +926,7 @@
   auto State = C.getState();
   const auto *Pos = getIteratorPosition(State, Val);
   if (Pos && isPastTheEnd(State, *Pos)) {
-auto *N = C.generateNonFatalErrorNode(State);
+auto *N = C.generateErrorNode(State);
 if (!N)
   return;
 reportOutOfRangeBug("Past-the-end iterator dereferenced.", Val, C, N);
@@ -940,7 +938,7 @@
   auto State = C.getState();
   const auto *Pos = getIteratorPosition(State, Val);
   if (Pos && !Pos->isValid()) {
-auto *N = C.generateNonFatalErrorNode(State);
+auto *N = C.generateErrorNode(State);
 if (!N) {
   return;
 }
@@ -1048,14 +1046,14 @@
   // The result may be the past-end iterator of the container, but any other
   // out of range position is undefined behaviour
   if (isAheadOfRange(State, advancePosition(C, Op, *Pos, Value))) {
-auto *N = C.generateNonFatalErrorNode(State);
+auto *N = C.generateErrorNode(State);
 if (!N)
   return;
 reportOutOfRangeBug("Iterator decremented ahead of its valid range.", LHS,
 C, N);
   }
   if (isBehindPastTheEnd(State, advancePosition(C, Op, *Pos, Value))) {
-auto *N = C.generateNonFatalErrorNode(State);
+auto *N = C.generateErrorNode(State);
 if (!N)
   return;
 reportOutOfRangeBug("Iterator incremented behind the past-the-end "
Index: cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp
===
--- cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp
+++ cfe/trunk/test/Analysis/diagnostics/explicit-suppression.cpp
@@ -19,6 +19,6 @@
 void testCopyNull(C *I, C *E) {
   std::copy(I, E, (C *)0);
 #ifndef SUPPRESSED
-  // expected-warning@../Inputs/system-header-simulator-cxx.h:680 {{Called C++ object pointer is null}}
+  // expected-warning@../Inputs/system-header-simulator-cxx.h:686 {{Called C++ object pointer is null}}
 #endif
 }
Index: cfe/trunk/test/Analysis/invalidated-iterator.cpp
===
--- cfe/trunk/test/Analysis/invalidated-iterator.cpp
+++ cfe/trunk/test/Analysis/invalidated-iterator.cpp
@@ -3,397 +3,762 @@
 
 #include "Inputs/system-header-simulator-cxx.h"
 
-void bad_copy_assign_operator_list1(std::list &L1,
+void clang_analyzer_warnIfReached();
+
+void bad_copy_assign_operator1_list(std::list &L1,
 const std::list &L2) {
   auto i0 = L1.cbegin();
   L1 = L2;
   *i0; // expected-warning{{Invalidated iterator accessed}}
+  clang_analyzer_warnIfReached();
 }
 
-void bad_copy_assign_operator_vector1(std::vector &V1,
+void bad_copy_assign_operator1_vector(std::vector &V1,
   const std::vector &V2) {
   auto i0 = V1.cbegin();
   V1 = V2;
   *i0; // expected-warning{{Invalidated iterator accessed}}
 }
 
-void bad_copy_assign_operator_deque1(std::deque &D1,
+void bad_copy_assign_operator1_deque(std::deque &D1,
  const std::deque &D2) {
   auto i0 = D1.cbegin();
   D1 = D2;
   *i0; // expected-warning{{Invalidated iterator accessed}}
 }
 
-void bad_copy_assign_operator_forward_list1(std::forward_list &FL1,
+void bad_copy_assign_operator1_forw

[PATCH] D66751: [clangd] Add targetDecl(), which determines what declaration an AST node refers to.

2019-08-29 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.

In D66751#1646991 , @sammccall wrote:

> Yes. I actually ripped this out of the patch, because it wasn't related 
> enough and the patch is large.


Makes sense and thanks for summing it up. Just wanted to make sure we are 
thinking about this use-case.

My comment was specifically referring to the lack of a "flat" model in our 
codebase.
I believe hierarchical model is very well handled by the selection tree (there 
might be bugs, obviously, but conceptually it's doing the right thing).

>> E.g. finding a source location of field for DeclRefExpr produced for 
>> MyBase::field seems to be the same amount of work (in general case) as 
>> finding the Decl* of field.
> 
> For the hierarchical model it's easy, this is one of the few methods 
> DynTypeNode actually has :-)
>  For the flat model: it's not trivial, but is less work because while you do 
> have to dispatch over all node types, you don't have general multi-hop/graph 
> cases (I think).
>  Usually the "handle" tokens are well-supported by the AST because they're 
> precisely the ones that diagnostics want to report. So in the DeclRefExpr 
> case, DeclRefExpr::getLoc() returns the right thing.

To be clear, the concern is **not** that it's hard to find the corresponding 
locations for each particular AST node.
The concern is that it's hard to cover **all** possible nodes and we should do 
it once rather than repeat this multiple times.

`DeclRefExpr` was a bad example for that purpose. E.g. one could make the same 
claim about `targetDecl` function we are introducing: it's very easy to get a 
target decl of `DeclRefExpr`,
but it's hard to enumerate all nodes that can have target decls and ensure they 
are handled properly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66751



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


[PATCH] D66637: [clangd] Support multifile edits as output of Tweaks

2019-08-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 217806.
kadircet added a comment.

- Handle formatting error in ClangdServer rather than just printing it


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66637

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/refactor/Tweak.cpp
  clang-tools-extra/clangd/refactor/Tweak.h
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
  clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
  clang-tools-extra/clangd/unittests/TweakTesting.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -113,11 +113,15 @@
   auto Effect = apply(ID, Input);
   if (!Effect)
 return Effect.takeError();
-  if (!Effect->ApplyEdit)
+  if (Effect->ApplyEdits.empty())
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"No replacements");
+  auto Edits = Effect->ApplyEdits;
+  if (Edits.size() > 1)
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "Multi-file edits");
   Annotations Code(Input);
-  return applyAllReplacements(Code.code(), *Effect->ApplyEdit);
+  return applyAllReplacements(Code.code(), Edits.begin()->second.Replacements);
 }
 
 void checkTransform(llvm::StringRef ID, llvm::StringRef Input,
Index: clang-tools-extra/clangd/unittests/TweakTesting.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTesting.cpp
+++ clang-tools-extra/clangd/unittests/TweakTesting.cpp
@@ -9,8 +9,8 @@
 #include "TweakTesting.h"
 
 #include "Annotations.h"
-#include "refactor/Tweak.h"
 #include "SourceCode.h"
+#include "refactor/Tweak.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/Support/Error.h"
 
@@ -98,14 +98,16 @@
 return "fail: " + llvm::toString(Result.takeError());
   if (Result->ShowMessage)
 return "message:\n" + *Result->ShowMessage;
-  if (Result->ApplyEdit) {
-if (auto NewText =
-tooling::applyAllReplacements(Input.code(), *Result->ApplyEdit))
-  return unwrap(Context, *NewText);
-else
-  return "bad edits: " + llvm::toString(NewText.takeError());
-  }
-  return "no effect";
+  if (Result->ApplyEdits.empty())
+return "no effect";
+  if (Result->ApplyEdits.size() > 1)
+return "received multi-file edits";
+
+  auto ApplyEdit = Result->ApplyEdits.begin()->second;
+  if (auto NewText = ApplyEdit.apply())
+return unwrap(Context, *NewText);
+  else
+return "bad edits: " + llvm::toString(NewText.takeError());
 }
 
 ::testing::Matcher TweakTest::isAvailable() const {
Index: clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
@@ -90,7 +90,7 @@
  ElseRng->getBegin(),
  ElseCode.size(), ThenCode)))
 return std::move(Err);
-  return Effect::applyEdit(Result);
+  return mainFileEdit(SrcMgr, std::move(Result));
 }
 
 } // namespace
Index: clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
@@ -88,10 +88,12 @@
 }
 
 Expected RawStringLiteral::apply(const Selection &Inputs) {
-  return Effect::applyEdit(tooling::Replacements(
+  auto &SM = Inputs.AST.getSourceManager();
+  auto Reps = tooling::Replacements(
   tooling::Replacement(Inputs.AST.getSourceManager(), Str,
("R\"(" + Str->getBytes() + ")\"").str(),
-   Inputs.AST.getASTContext().getLangOpts(;
+   Inputs.AST.getASTContext().getLangOpts()));
+  return mainFileEdit(SM, std::move(Reps));
 }
 
 } // namespace
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -468,7 +468,7 @@
   /

[PATCH] D62893: [Analyzer] Iterator Checkers - Make range errors and invalidated access fatal

2019-08-29 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

In D62893#1608000 , @Szelethus wrote:

> Makes sense! But, does any of the test cases actually test *this* particular 
> change?


I added some reachability checks before committing.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D62893



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


[PATCH] D66933: [ASTImporter] Propagate errors during import of overridden methods.

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

If importing overridden methods fails for a method it can be seen
incorrectly as non-virtual. To avoid this inconsistency the method
is marked with import error to avoid later use of it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66933

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5183,6 +5183,46 @@
   }
 }
 
+TEST_P(ErrorHandlingTest, ImportOfOverriddenMethods) {
+  auto MatchFooA =
+  functionDecl(hasName("foo"), hasAncestor(cxxRecordDecl(hasName("A";
+  auto MatchFooB =
+  functionDecl(hasName("foo"), hasAncestor(cxxRecordDecl(hasName("B";
+  auto MatchFooC =
+  functionDecl(hasName("foo"), hasAncestor(cxxRecordDecl(hasName("C";
+
+  // Provoke import of a method that has overridden methods with import error.
+  TranslationUnitDecl *FromTU = getTuDecl(std::string(R"(
+struct C;
+struct A {
+  virtual void foo();
+  void f1(C *);
+};
+void A::foo() {
+  )") + ErroneousStmt + R"(
+}
+struct B : public A {
+  void foo() override;
+};
+struct C : public B {
+  void foo() override;
+};
+)",
+  Lang_CXX11);
+  auto *FromFooA = FirstDeclMatcher().match(FromTU, MatchFooA);
+  auto *FromFooB = FirstDeclMatcher().match(FromTU, MatchFooB);
+  auto *FromFooC = FirstDeclMatcher().match(FromTU, MatchFooC);
+
+  FunctionDecl *ImportedFooA = Import(FromFooA, Lang_CXX11);
+  EXPECT_FALSE(ImportedFooA);
+  ASTImporter *Importer = findFromTU(FromFooA)->Importer.get();
+  Optional OptErr = Importer->getImportDeclErrorIfAny(FromFooA);
+  ASSERT_TRUE(OptErr);
+  EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
+  EXPECT_FALSE(Import(FromFooB, Lang_CXX11));
+  EXPECT_FALSE(Import(FromFooC, Lang_CXX11));
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, LambdaInFunctionBody) {
   Decl *FromTU = getTuDecl(
   R"(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -639,7 +639,7 @@
   return ImportArrayChecked(InContainer.begin(), InContainer.end(), 
Obegin);
 }
 
-void ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod);
+Error ImportOverrides(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod);
 
 Expected FindFunctionTemplateSpecialization(
 FunctionDecl *FromFD);
@@ -3370,7 +3370,9 @@
   }
 
   if (auto *FromCXXMethod = dyn_cast(D))
-ImportOverrides(cast(ToFunction), FromCXXMethod);
+if (Error Err =
+ImportOverrides(cast(ToFunction), FromCXXMethod))
+  return std::move(Err);
 
   // Import the rest of the chain. I.e. import all subsequent declarations.
   for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
@@ -7804,15 +7806,18 @@
   *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
 }
 
-void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
-  CXXMethodDecl *FromMethod) {
+Error ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
+   CXXMethodDecl *FromMethod) {
+  Error ImportErrors = Error::success();
   for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
 if (auto ImportedOrErr = import(FromOverriddenMethod))
   ToMethod->getCanonicalDecl()->addOverriddenMethod(cast(
   (*ImportedOrErr)->getCanonicalDecl()));
 else
-  consumeError(ImportedOrErr.takeError());
+  ImportErrors =
+  joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
   }
+  return ImportErrors;
 }
 
 ASTImporter::ASTImporter(ASTContext &ToContext, FileManager &ToFileManager,


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5183,6 +5183,46 @@
   }
 }
 
+TEST_P(ErrorHandlingTest, ImportOfOverriddenMethods) {
+  auto MatchFooA =
+  functionDecl(hasName("foo"), hasAncestor(cxxRecordDecl(hasName("A";
+  auto MatchFooB =
+  functionDecl(hasName("foo"), hasAncestor(cxxRecordDecl(hasName("B";
+  auto MatchFooC =
+  functionDecl(hasName("foo"), hasAncestor(cxxRecordDecl(hasName("C";
+
+  // Provoke import of a method that has overridden methods with import error.
+  TranslationUnitDecl *FromTU = getTuDecl(std::string(R"(
+struct C;
+ 

[PATCH] D66928: [clangd] Collecting main file macro expansion locations in ParsedAST.

2019-08-29 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 217811.
jvikstrom marked 5 inline comments as done.
jvikstrom added a comment.

Clarified comments. Added tests. Not getting expansions inside other macro 
expansions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66928

Files:
  clang-tools-extra/clangd/ClangdUnit.cpp
  clang-tools-extra/clangd/ClangdUnit.h
  clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp

Index: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
@@ -244,6 +244,47 @@
   EXPECT_EQ(T.expandedTokens().drop_back().back().text(SM), "}");
 }
 
+TEST(ClangdUnitTest, CollectsMainFileMacroExpansions) {
+  Annotations TestCase(R"cpp(
+#define MACRO_ARGS(X, Y) X Y
+^ID(int A);
+// Macro arguments included.
+^MACRO_ARGS(^MACRO_ARGS(^MACRO_EXP(int), A), ^ID(= 2));
+
+// Macro names inside other macros not included.
+#define FOO BAR
+#define BAR 1
+int A = ^FOO;
+
+// Macros from token concatenations included.
+#define CONCAT(X) X##1()
+#define MACRO1() 123
+int B = ^CONCAT(^MACRO);
+
+// Macros included not from preamble not included.
+#include "foo.inc"
+  )cpp");
+  auto TU = TestTU::withCode(TestCase.code());
+  TU.HeaderCode = R"cpp(
+#define ID(X) X
+#define MACRO_EXP(X) ID(X)
+MACRO_EXP(int B);
+  )cpp";
+  TU.AdditionalFiles["foo.inc"] = R"cpp(
+int C = ID(1);
+#define DEF 1
+int D = DEF;
+  )cpp";
+  ParsedAST AST = TU.build();
+  const std::vector &MacroExpansionLocations =
+  AST.getMainFileMacroExpansionLocations();
+  std::vector MacroExpansionPositions;
+  for (const auto &L : MacroExpansionLocations)
+MacroExpansionPositions.push_back(
+sourceLocToPosition(AST.getSourceManager(), L));
+  EXPECT_EQ(MacroExpansionPositions, TestCase.points());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ClangdUnit.h
===
--- clang-tools-extra/clangd/ClangdUnit.h
+++ clang-tools-extra/clangd/ClangdUnit.h
@@ -116,6 +116,7 @@
   const IncludeStructure &getIncludeStructure() const;
   const CanonicalIncludes &getCanonicalIncludes() const;
 
+  const std::vector &getMainFileMacroExpansionLocations() const;
   /// Tokens recorded while parsing the main file.
   /// (!) does not have tokens from the preamble.
   const syntax::TokenBuffer &getTokens() const { return Tokens; }
@@ -124,6 +125,7 @@
   ParsedAST(std::shared_ptr Preamble,
 std::unique_ptr Clang,
 std::unique_ptr Action, syntax::TokenBuffer Tokens,
+std::vector MainFileMacroExpLocs,
 std::vector LocalTopLevelDecls, std::vector Diags,
 IncludeStructure Includes, CanonicalIncludes CanonIncludes);
 
@@ -143,6 +145,9 @@
   ///   - Does not have spelled or expanded tokens for files from preamble.
   syntax::TokenBuffer Tokens;
 
+  /// The start locations of all macro expansions spelled inside the main file.
+  /// Does not include expansions from inside other macro expansions.
+  std::vector MainFileMacroExpLocs;
   // Data, stored after parsing.
   std::vector Diags;
   // Top-level decls inside the current file. Not that this does not include
Index: clang-tools-extra/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/clangd/ClangdUnit.cpp
+++ clang-tools-extra/clangd/ClangdUnit.cpp
@@ -32,6 +32,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Sema/Sema.h"
@@ -103,6 +104,24 @@
   std::vector TopLevelDecls;
 };
 
+class CollectMainFileMacroExpansions : public PPCallbacks {
+  const SourceManager &SM;
+  std::vector &MainFileMacroLocs;
+
+public:
+  CollectMainFileMacroExpansions(const SourceManager &SM,
+ std::vector &MainFileMacroLocs)
+  : SM(SM), MainFileMacroLocs(MainFileMacroLocs) {}
+
+  virtual void MacroExpands(const Token &MacroNameTok,
+const MacroDefinition &MD, SourceRange Range,
+const MacroArgs *Args) {
+SourceLocation L = MacroNameTok.getLocation();
+if (isInsideMainFile(SM.getSpellingLoc(L), SM) && !L.isMacroID())
+  MainFileMacroLocs.push_back(L);
+  }
+};
+
 class CollectMainFileMacros : public PPCallbacks {
 public:
   explicit CollectMainFileMacros(const SourceManager &SM,
@@ -414,6 +433,11 @@
   // (We can't *just* use the replayed includes, they don't have Resolved path).
   Clang->getPreprocessor().addPPCallbacks(
   collectIncludeStructureC

[PATCH] D66928: [clangd] Collecting main file macro expansion locations in ParsedAST.

2019-08-29 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom added inline comments.



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:248
+TEST(ClangdUnitTest, CollectsMainFileMacroExpansions) {
+  Annotations TestCase(R"cpp(
+#define MACRO_ARGS(X, Y) X Y

ilya-biryukov wrote:
> Could you add a few more interesting cases?
> 
> 1. Macros outside the main file **and** the preamble:
> ```
> // foo.inc
> int a = ID(1);
> 
> // foo.cpp
> #define ID(X) X
> 
> int b;
> #include "foo.inc"
> ```
> 
> 2. macro expansions from token concatenations
> ```
> #define FOO(X) X##1()
> #define MACRO1() 123
> 
> int a = FOO(MACRO);
> ```
> 3. Macro names inside other macros:
> ```
> #define FOO BAR
> #define BAR 1
> 
> 
> int a = FOO; // should BAR at line 1 be highlighted?
> 
> ```
> 
> 4. #include not part of the preamble:
> ```
> #define FOO 1
> 
> // Preamble ends here.
> int a = 10;
> #include "some_file_with_macros.h" // <-- should not get any macros from here
> ```
Does clangd handle `.inc` files differently from `.h`? Because if it doesn't 
shouldn't ` case 1 cover case 4 as well ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66928



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


r370321 - [Index] Marked a bunch of classes 'final'

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 03:16:41 2019
New Revision: 370321

URL: http://llvm.org/viewvc/llvm-project?rev=370321&view=rev
Log:
[Index] Marked a bunch of classes 'final'

This file defines multiple inheritance hierarchies and 'final' helps
with readability.

Modified:
cfe/trunk/lib/Index/IndexingAction.cpp

Modified: cfe/trunk/lib/Index/IndexingAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=370321&r1=370320&r2=370321&view=diff
==
--- cfe/trunk/lib/Index/IndexingAction.cpp (original)
+++ cfe/trunk/lib/Index/IndexingAction.cpp Thu Aug 29 03:16:41 2019
@@ -23,7 +23,7 @@ using namespace clang::index;
 
 namespace {
 
-class IndexASTConsumer : public ASTConsumer {
+class IndexASTConsumer final : public ASTConsumer {
   std::shared_ptr PP;
   std::shared_ptr IndexCtx;
 
@@ -55,7 +55,7 @@ protected:
   }
 };
 
-class IndexPPCallbacks : public PPCallbacks {
+class IndexPPCallbacks final : public PPCallbacks {
   std::shared_ptr IndexCtx;
 
 public:
@@ -110,7 +110,7 @@ protected:
   }
 };
 
-class IndexAction : public ASTFrontendAction, IndexActionBase {
+class IndexAction final : public ASTFrontendAction, IndexActionBase {
 public:
   IndexAction(std::shared_ptr DataConsumer,
   IndexingOptions Opts)
@@ -133,7 +133,7 @@ protected:
   }
 };
 
-class WrappingIndexAction : public WrapperFrontendAction, IndexActionBase {
+class WrappingIndexAction final : public WrapperFrontendAction, 
IndexActionBase {
   bool IndexActionFailed = false;
 
 public:


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


r370322 - [OpenCL] Fix diagnosing enqueue_kernel call with too few args

2019-08-29 Thread Sven van Haastregt via cfe-commits
Author: svenvh
Date: Thu Aug 29 03:21:06 2019
New Revision: 370322

URL: http://llvm.org/viewvc/llvm-project?rev=370322&view=rev
Log:
[OpenCL] Fix diagnosing enqueue_kernel call with too few args

The err_typecheck_call_too_few_args diagnostic takes arguments, but
none were provided causing clang to crash when attempting to diagnose
an enqueue_kernel call with too few arguments.

Fixes llvm.org/PR42045

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

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=370322&r1=370321&r2=370322&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Aug 29 03:21:06 2019
@@ -629,7 +629,9 @@ static bool SemaOpenCLBuiltinEnqueueKern
   unsigned NumArgs = TheCall->getNumArgs();
 
   if (NumArgs < 4) {
-S.Diag(TheCall->getBeginLoc(), diag::err_typecheck_call_too_few_args);
+S.Diag(TheCall->getBeginLoc(),
+   diag::err_typecheck_call_too_few_args_at_least)
+<< 0 << 4 << NumArgs;
 return true;
   }
 

Modified: cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl?rev=370322&r1=370321&r2=370322&view=diff
==
--- cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl (original)
+++ cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl Thu Aug 29 03:21:06 
2019
@@ -158,6 +158,8 @@ kernel void enqueue_kernel_tests() {
   enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt); // 
expected-error{{illegal call to enqueue_kernel, incorrect argument types}}
 
   enqueue_kernel(default_queue, flags, ndrange, 1, 1); // 
expected-error{{illegal call to enqueue_kernel, incorrect argument types}}
+
+  enqueue_kernel(default_queue, ndrange, ^{}); // expected-error{{too few 
arguments to function call, expected at least 4, have 3}}
 }
 
 // Diagnostic tests for get_kernel_work_group_size and allowed block parameter 
types in dynamic parallelism.


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


[PATCH] D66637: [clangd] Support multifile edits as output of Tweaks

2019-08-29 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/SourceCode.cpp:601
+  llvm::inconvertibleErrorCode(),
+  "File contents differ on disk for %s, please save", FilePath.data());
+}

kadircet wrote:
> sammccall wrote:
> > you seem to be checking this both here and in clangdlspserver. Why?
> the contents in here are coming from disk, whereas the one in clangdlspserver 
> is coming from drafts. I suppose it would make more sense to merge the two in 
> clangdlspserver, use draft manager as content source backed by disk in case 
> user hasn't opened that file.
OK, so you're checking here whether the contents-on-disk have changed between 
clang reading the file as part of parse, and the tweak completing?

I don't think this is worth doing. Sure, there's potentially a race condition, 
but it's relatively small (bounded on the order of a few seconds, vs unbounded 
for unsaved drafts) and we can't eliminate it entirely (file on disk can change 
between when we create edits and when they're applied).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66637



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


[PATCH] D66883: PR42045: Fix diagnosing enqueue_kernel call with too few args

2019-08-29 Thread Sven van Haastregt via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL370322: [OpenCL] Fix diagnosing enqueue_kernel call with too 
few args (authored by svenvh, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66883?vs=217642&id=217814#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66883

Files:
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl


Index: cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -158,6 +158,8 @@
   enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt); // 
expected-error{{illegal call to enqueue_kernel, incorrect argument types}}
 
   enqueue_kernel(default_queue, flags, ndrange, 1, 1); // 
expected-error{{illegal call to enqueue_kernel, incorrect argument types}}
+
+  enqueue_kernel(default_queue, ndrange, ^{}); // expected-error{{too few 
arguments to function call, expected at least 4, have 3}}
 }
 
 // Diagnostic tests for get_kernel_work_group_size and allowed block parameter 
types in dynamic parallelism.
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -629,7 +629,9 @@
   unsigned NumArgs = TheCall->getNumArgs();
 
   if (NumArgs < 4) {
-S.Diag(TheCall->getBeginLoc(), diag::err_typecheck_call_too_few_args);
+S.Diag(TheCall->getBeginLoc(),
+   diag::err_typecheck_call_too_few_args_at_least)
+<< 0 << 4 << NumArgs;
 return true;
   }
 


Index: cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl
===
--- cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl
+++ cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl
@@ -158,6 +158,8 @@
   enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, &evt); // expected-error{{illegal call to enqueue_kernel, incorrect argument types}}
 
   enqueue_kernel(default_queue, flags, ndrange, 1, 1); // expected-error{{illegal call to enqueue_kernel, incorrect argument types}}
+
+  enqueue_kernel(default_queue, ndrange, ^{}); // expected-error{{too few arguments to function call, expected at least 4, have 3}}
 }
 
 // Diagnostic tests for get_kernel_work_group_size and allowed block parameter types in dynamic parallelism.
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -629,7 +629,9 @@
   unsigned NumArgs = TheCall->getNumArgs();
 
   if (NumArgs < 4) {
-S.Diag(TheCall->getBeginLoc(), diag::err_typecheck_call_too_few_args);
+S.Diag(TheCall->getBeginLoc(),
+   diag::err_typecheck_call_too_few_args_at_least)
+<< 0 << 4 << NumArgs;
 return true;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r370323 - [Index] Create PP callbacks in the ASTConsumer

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 03:23:29 2019
New Revision: 370323

URL: http://llvm.org/viewvc/llvm-project?rev=370323&view=rev
Log:
[Index] Create PP callbacks in the ASTConsumer

Doing so removes one reason to create a custom FrontendAction.
FrontendActions are not desirable because they are difficult to compose.
ASTConsumers are much easier to compose.

Modified:
cfe/trunk/lib/Index/IndexingAction.cpp

Modified: cfe/trunk/lib/Index/IndexingAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=370323&r1=370322&r2=370323&view=diff
==
--- cfe/trunk/lib/Index/IndexingAction.cpp (original)
+++ cfe/trunk/lib/Index/IndexingAction.cpp Thu Aug 29 03:23:29 2019
@@ -23,6 +23,36 @@ using namespace clang::index;
 
 namespace {
 
+class IndexPPCallbacks final : public PPCallbacks {
+  std::shared_ptr IndexCtx;
+
+public:
+  IndexPPCallbacks(std::shared_ptr IndexCtx)
+  : IndexCtx(std::move(IndexCtx)) {}
+
+  void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
+SourceRange Range, const MacroArgs *Args) override {
+IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(),
+   Range.getBegin(), *MD.getMacroInfo());
+  }
+
+  void MacroDefined(const Token &MacroNameTok,
+const MacroDirective *MD) override {
+IndexCtx->handleMacroDefined(*MacroNameTok.getIdentifierInfo(),
+ MacroNameTok.getLocation(),
+ *MD->getMacroInfo());
+  }
+
+  void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD,
+  const MacroDirective *Undef) override {
+if (!MD.getMacroInfo())  // Ignore noop #undef.
+  return;
+IndexCtx->handleMacroUndefined(*MacroNameTok.getIdentifierInfo(),
+   MacroNameTok.getLocation(),
+   *MD.getMacroInfo());
+  }
+};
+
 class IndexASTConsumer final : public ASTConsumer {
   std::shared_ptr PP;
   std::shared_ptr IndexCtx;
@@ -37,6 +67,7 @@ protected:
 IndexCtx->setASTContext(Context);
 IndexCtx->getDataConsumer().initialize(Context);
 IndexCtx->getDataConsumer().setPreprocessor(PP);
+PP->addPPCallbacks(std::make_unique(IndexCtx));
   }
 
   bool HandleTopLevelDecl(DeclGroupRef DG) override {
@@ -55,36 +86,6 @@ protected:
   }
 };
 
-class IndexPPCallbacks final : public PPCallbacks {
-  std::shared_ptr IndexCtx;
-
-public:
-  IndexPPCallbacks(std::shared_ptr IndexCtx)
-  : IndexCtx(std::move(IndexCtx)) {}
-
-  void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
-SourceRange Range, const MacroArgs *Args) override {
-IndexCtx->handleMacroReference(*MacroNameTok.getIdentifierInfo(),
-   Range.getBegin(), *MD.getMacroInfo());
-  }
-
-  void MacroDefined(const Token &MacroNameTok,
-const MacroDirective *MD) override {
-IndexCtx->handleMacroDefined(*MacroNameTok.getIdentifierInfo(),
- MacroNameTok.getLocation(),
- *MD->getMacroInfo());
-  }
-
-  void MacroUndefined(const Token &MacroNameTok, const MacroDefinition &MD,
-  const MacroDirective *Undef) override {
-if (!MD.getMacroInfo())  // Ignore noop #undef.
-  return;
-IndexCtx->handleMacroUndefined(*MacroNameTok.getIdentifierInfo(),
-   MacroNameTok.getLocation(),
-   *MD.getMacroInfo());
-  }
-};
-
 class IndexActionBase {
 protected:
   std::shared_ptr DataConsumer;
@@ -101,10 +102,6 @@ protected:
IndexCtx);
   }
 
-  std::unique_ptr createIndexPPCallbacks() {
-return std::make_unique(IndexCtx);
-  }
-
   void finish() {
 DataConsumer->finish();
   }
@@ -122,11 +119,6 @@ protected:
 return createIndexASTConsumer(CI);
   }
 
-  bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
-CI.getPreprocessor().addPPCallbacks(createIndexPPCallbacks());
-return true;
-  }
-
   void EndSourceFileAction() override {
 FrontendAction::EndSourceFileAction();
 finish();
@@ -158,12 +150,6 @@ protected:
 return std::make_unique(std::move(Consumers));
   }
 
-  bool BeginSourceFileAction(clang::CompilerInstance &CI) override {
-WrapperFrontendAction::BeginSourceFileAction(CI);
-CI.getPreprocessor().addPPCallbacks(createIndexPPCallbacks());
-return true;
-  }
-
   void EndSourceFileAction() override {
 // Invoke wrapped action's method.
 WrapperFrontendAction::EndSourceFileAction();


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


[PATCH] D66866: [ASTImporter] At import of records re-order indirect fields too.

2019-08-29 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 217816.
balazske added a comment.

- Simplified field matcher in tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66866

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1421,12 +1421,15 @@
 
 AST_MATCHER_P(RecordDecl, hasFieldOrder, std::vector, Order) {
   size_t Index = 0;
-  for (FieldDecl *Field : Node.fields()) {
-if (Index == Order.size())
-  return false;
-if (Field->getName() != Order[Index])
-  return false;
-++Index;
+  for (Decl *D : Node.decls()) {
+if (isa(D) || isa(D)) {
+  auto *ND = cast(D);
+  if (Index == Order.size())
+return false;
+  if (ND->getName() != Order[Index])
+return false;
+  ++Index;
+}
   }
   return Index == Order.size();
 }
@@ -1493,6 +1496,31 @@
   Verifier.match(To, cxxRecordDecl(hasFieldOrder({"a", "b", "c"};
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   CXXRecordDeclFieldAndIndirectFieldOrder) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  // First field is "a", then the field for unnamed union, then "b" and "c"
+  // from it (indirect fields), then "d".
+  R"s(
+  struct declToImport {
+int a = d;
+union { 
+  int b;
+  int c;
+};
+int d;
+  };
+  )s",
+  Lang_CXX11, "", Lang_CXX11);
+
+  MatchVerifier Verifier;
+  ASSERT_TRUE(Verifier.match(
+  From, cxxRecordDecl(hasFieldOrder({"a", "", "b", "c", "d"};
+  EXPECT_TRUE(Verifier.match(
+  To, cxxRecordDecl(hasFieldOrder({"a", "", "b", "c", "d"};
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ShouldImportImplicitCXXRecordDecl) {
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1701,7 +1701,7 @@
   // Remove all declarations, which may be in wrong order in the
   // lexical DeclContext and then add them in the proper order.
   for (auto *D : FromRD->decls()) {
-if (isa(D) || isa(D)) {
+if (isa(D) || isa(D) || isa(D)) {
   assert(D && "DC contains a null decl");
   Decl *ToD = Importer.GetAlreadyImportedOrNull(D);
   // Remove only the decls which we successfully imported.


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1421,12 +1421,15 @@
 
 AST_MATCHER_P(RecordDecl, hasFieldOrder, std::vector, Order) {
   size_t Index = 0;
-  for (FieldDecl *Field : Node.fields()) {
-if (Index == Order.size())
-  return false;
-if (Field->getName() != Order[Index])
-  return false;
-++Index;
+  for (Decl *D : Node.decls()) {
+if (isa(D) || isa(D)) {
+  auto *ND = cast(D);
+  if (Index == Order.size())
+return false;
+  if (ND->getName() != Order[Index])
+return false;
+  ++Index;
+}
   }
   return Index == Order.size();
 }
@@ -1493,6 +1496,31 @@
   Verifier.match(To, cxxRecordDecl(hasFieldOrder({"a", "b", "c"};
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   CXXRecordDeclFieldAndIndirectFieldOrder) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  // First field is "a", then the field for unnamed union, then "b" and "c"
+  // from it (indirect fields), then "d".
+  R"s(
+  struct declToImport {
+int a = d;
+union { 
+  int b;
+  int c;
+};
+int d;
+  };
+  )s",
+  Lang_CXX11, "", Lang_CXX11);
+
+  MatchVerifier Verifier;
+  ASSERT_TRUE(Verifier.match(
+  From, cxxRecordDecl(hasFieldOrder({"a", "", "b", "c", "d"};
+  EXPECT_TRUE(Verifier.match(
+  To, cxxRecordDecl(hasFieldOrder({"a", "", "b", "c", "d"};
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, ShouldImportImplicitCXXRecordDecl) {
   Decl *From, *To;
   std::tie(From, To) = getImportedDecl(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1701,7 +1701,7 @@
   // Remove all declarations, which may be in wrong order in the
   // lexical DeclContext and then add them in the proper order.
   for (auto *D : FromRD->decls()) {
-if (isa(D) || isa(D)) {
+if (isa(D) || isa(D) || isa(D)) {
   assert(D && "DC contains a null decl");
   Decl *ToD = Importer.GetAlreadyImportedOrNull(D);
   // Remove only the decls which we successfully imported.
___

[PATCH] D66875: [Index] Marked a bunch of classes 'final'

2019-08-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added a comment.

Committed as r370321.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66875



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


[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-08-29 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb updated this revision to Diff 217819.
krisb added a comment.

Applied the comment & rebased.
Also changed the patch to take into account only the latest 'crypto' in the 
Features vector, to avoid enabling 'sha2' and 'aes' when 'crypto' was finally 
disabled.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66018

Files:
  lib/Driver/ToolChains/Arch/ARM.cpp
  test/Driver/arm-features.c


Index: test/Driver/arm-features.c
===
--- test/Driver/arm-features.c
+++ test/Driver/arm-features.c
@@ -37,7 +37,8 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.2a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.3a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
-// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" 
"+crypto" "-target-feature" "+sha2" "-target-feature" "+aes"
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.5a+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2 %s
+// CHECK-CRYPTO2: "-cc1"{{.*}} "-target-cpu" "generic"{{.*}} "-target-feature" 
"+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto:
 //
@@ -45,14 +46,27 @@
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.2a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.3a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.4a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
+// RUN: %clang -target arm-arm-none-eabi -march=armv8.5a+nocrypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2 %s
 // CHECK-NOCRYPTO2-NOT: "-target-feature" "+crypto" "-target-feature" "+sha2" 
"-target-feature" "+aes"
 //
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-CRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CRYPTO2-CPU %s
+// CHECK-CRYPTO2-CPU: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} 
"-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" 
"+aes"
+//
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+norypto -### -c %s 
2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57 -mfpu=neon-fp-armv8 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-NOCRYPTO2-CPU %s
+// CHECK-NOCRYPTO2-CPU-NOT: "-cc1"{{.*}} "-target-cpu" "cortex-a57"{{.*}} 
"-target-feature" "+crypto"{{.*}} "-target-feature" "+sha2" "-target-feature" 
"+aes"
+//
 // Check +crypto -sha2 -aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+crypto+nosha2+noaes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+crypto+nosha2+noaes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO3 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nosha2+noaes 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CRYPTO3 %s
 // CHECK-CRYPTO3-NOT: "-target-feature" "+sha2" "-target-feature" "+aes"
 //
 // Check -crypto +sha2 +aes:
 //
 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1a+nocrypto+sha2+aes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+nocrypto+sha2+aes 
-### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
+// RUN: %clang -target arm-arm-none-eabi -mcpu=cortex-a57+sha2+aes 
-mfpu=neon-fp-armv8 -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CRYPTO4 %s
 // CHECK-CRYPTO4: "-target-feature" "+sha2" "-target-feature" "+aes"
Index: lib/Driver/ToolChains/Arch/ARM.cpp
===
--- lib/Driver/ToolChains/Arch/ARM.cpp
+++ lib/Driver/ToolChains/Arch/ARM.cpp
@@ -479,21 +479,20 @@
 
   // For Arch >= ARMv8.0:  crypto = sha2 + aes
   // FIXME: this needs reimplementation after the TargetParser rewrite
-  if (ArchName.find_lower("armv8a") != StringRef::npos ||
-  ArchName.find_lower("armv8.1a") != StringRef::npos ||
-  ArchName.find_lower("armv8.2a") != StringRef::npos ||
-  ArchName.find_lower("armv8.3a") != StringRef::npos ||
-  ArchName.find_lower("armv8.4a") != StringRef::npos) {
-if (ArchName.find_lower("+crypto") != StringRef::npos) {
-  if (ArchName.find_lower("+nosha2") == StringRef::npos)
+  StringRef ArchSuffix = arm::getLLVMArchSuffixForARM(
+  arm::getARMTargetCPU(CPUName, ArchName, Triple), ArchName, Triple);
+
+  if (llvm::ARM::parseArchVersion(Arch

[PATCH] D66637: [clangd] Support multifile edits as output of Tweaks

2019-08-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 217820.
kadircet marked an inline comment as done.
kadircet added a comment.

- Get rid off compatibility check for files that are not open in the editor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66637

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/SourceCode.cpp
  clang-tools-extra/clangd/SourceCode.h
  clang-tools-extra/clangd/refactor/Tweak.cpp
  clang-tools-extra/clangd/refactor/Tweak.h
  clang-tools-extra/clangd/refactor/tweaks/AnnotateHighlightings.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandAutoType.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExpandMacro.cpp
  clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
  clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
  clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
  clang-tools-extra/clangd/unittests/TweakTesting.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -113,11 +113,15 @@
   auto Effect = apply(ID, Input);
   if (!Effect)
 return Effect.takeError();
-  if (!Effect->ApplyEdit)
+  if (Effect->ApplyEdits.empty())
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"No replacements");
+  auto Edits = Effect->ApplyEdits;
+  if (Edits.size() > 1)
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "Multi-file edits");
   Annotations Code(Input);
-  return applyAllReplacements(Code.code(), *Effect->ApplyEdit);
+  return applyAllReplacements(Code.code(), Edits.begin()->second.Replacements);
 }
 
 void checkTransform(llvm::StringRef ID, llvm::StringRef Input,
Index: clang-tools-extra/clangd/unittests/TweakTesting.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTesting.cpp
+++ clang-tools-extra/clangd/unittests/TweakTesting.cpp
@@ -9,8 +9,8 @@
 #include "TweakTesting.h"
 
 #include "Annotations.h"
-#include "refactor/Tweak.h"
 #include "SourceCode.h"
+#include "refactor/Tweak.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/Support/Error.h"
 
@@ -98,14 +98,16 @@
 return "fail: " + llvm::toString(Result.takeError());
   if (Result->ShowMessage)
 return "message:\n" + *Result->ShowMessage;
-  if (Result->ApplyEdit) {
-if (auto NewText =
-tooling::applyAllReplacements(Input.code(), *Result->ApplyEdit))
-  return unwrap(Context, *NewText);
-else
-  return "bad edits: " + llvm::toString(NewText.takeError());
-  }
-  return "no effect";
+  if (Result->ApplyEdits.empty())
+return "no effect";
+  if (Result->ApplyEdits.size() > 1)
+return "received multi-file edits";
+
+  auto ApplyEdit = Result->ApplyEdits.begin()->second;
+  if (auto NewText = ApplyEdit.apply())
+return unwrap(Context, *NewText);
+  else
+return "bad edits: " + llvm::toString(NewText.takeError());
 }
 
 ::testing::Matcher TweakTest::isAvailable() const {
Index: clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/SwapIfBranches.cpp
@@ -90,7 +90,7 @@
  ElseRng->getBegin(),
  ElseCode.size(), ThenCode)))
 return std::move(Err);
-  return Effect::applyEdit(Result);
+  return mainFileEdit(SrcMgr, std::move(Result));
 }
 
 } // namespace
Index: clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/RawStringLiteral.cpp
@@ -88,10 +88,12 @@
 }
 
 Expected RawStringLiteral::apply(const Selection &Inputs) {
-  return Effect::applyEdit(tooling::Replacements(
+  auto &SM = Inputs.AST.getSourceManager();
+  auto Reps = tooling::Replacements(
   tooling::Replacement(Inputs.AST.getSourceManager(), Str,
("R\"(" + Str->getBytes() + ")\"").str(),
-   Inputs.AST.getASTContext().getLangOpts(;
+   Inputs.AST.getASTContext().getLangOpts()));
+  return mainFileEdit(SM, std::move(Reps));
 }
 
 } // namespace
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/clangd/refactor/tw

[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-08-29 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb marked 2 inline comments as done.
krisb added a comment.

@dnsampaio, thanks! This is definitely better. I also added ARMV8_5A as a test 
case.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66018



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


[PATCH] D65234: [CodeGen]: don't treat structures returned in registers as memory inputs

2019-08-29 Thread Alexander Potapenko via Phabricator via cfe-commits
glider updated this revision to Diff 217831.
glider added a comment.

Rebased the patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65234

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/asm-attrs.c
  clang/test/CodeGen/x86_64-PR42672.c

Index: clang/test/CodeGen/x86_64-PR42672.c
===
--- /dev/null
+++ clang/test/CodeGen/x86_64-PR42672.c
@@ -0,0 +1,102 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -DSTRUCT -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-STRUCT
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -USTRUCT -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-NOSTRUCT
+// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_ODD -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_ODD
+// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_BIG -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_BIG
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -DPOSSIBLE_X -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-X
+// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_X -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_X
+
+// Make sure Clang doesn't treat |lockval| as asm input.
+void _raw_spin_lock(void) {
+#ifdef STRUCT
+  struct {
+unsigned short owner, next;
+  } lockval;
+  lockval.owner = 1;
+  lockval.next = 2;
+#else
+  int lockval;
+  lockval = 3;
+#endif
+  asm("nop"
+  : "=r"(lockval));
+}
+// CHECK-LABEL: _raw_spin_lock
+// CHECK-LABEL: entry:
+
+// CHECK-STRUCT:  %lockval = alloca %struct.anon, align 2
+// CHECK-STRUCT:  store i16 1
+// CHECK-STRUCT:  store i16 2
+// CHECK-STRUCT: [[RES:%[0-9]+]] = call i32 asm "nop", "=r,~{dirflag},~{fpsr},~{flags}"()
+// CHECK-STRUCT: [[CAST:%[0-9]+]] = bitcast %struct.anon* %lockval to i32*
+// CHECK-STRUCT: store i32 [[RES]], i32* [[CAST]], align 2
+
+// CHECK-NOSTRUCT: %lockval = alloca i32, align 4
+// CHECK-NOSTRUCT: store i32 3
+// CHECK-NOSTRUCT:  [[RES:%[0-9]+]] = call i32 asm "nop", "=r,~{dirflag},~{fpsr},~{flags}"()
+// CHECK-NOSTRUCT: store i32 [[RES]], i32* %lockval, align 4
+
+// Check Clang correctly handles a structure with padding.
+void unusual_struct(void) {
+  struct {
+unsigned short first;
+unsigned char second;
+  } str;
+  asm("nop"
+  : "=r"(str));
+}
+
+// Check Clang reports an error if attempting to return a structure for which
+// no direct conversion to a register is possible.
+void odd_struct(void) {
+#ifdef IMPOSSIBLE_ODD
+  struct __attribute__((__packed__)) {
+unsigned short first;
+unsigned char second;
+  } str;
+  asm("nop"
+  : "=r"(str));
+#endif
+}
+// CHECK-IMPOSSIBLE_ODD: impossible constraint in asm
+
+// Check Clang reports an error if attempting to return a big structure via a register.
+void big_struct(void) {
+#ifdef IMPOSSIBLE_BIG
+  struct {
+long long int v1, v2, v3, v4;
+  } str;
+  asm("nop"
+  : "=r"(str));
+#endif
+}
+// CHECK-IMPOSSIBLE_BIG: impossible constraint in asm
+
+// Clang is able to emit LLVM IR for an 16-byte structure.
+void x_constraint_fit() {
+#ifdef POSSIBLE_X
+  struct S {
+unsigned x[4];
+  } z;
+  asm volatile("nop"
+   : "=x"(z));
+#endif
+}
+// CHECK-LABEL: x_constraint_fit
+// CHECK-X: %z = alloca %struct.S, align 4
+// CHECK-X: [[RES:%[0-9]+]] = call i128 asm sideeffect "nop", "=x,~{dirflag},~{fpsr},~{flags}"()
+// CHECK-X: [[CAST:%[0-9]+]] = bitcast %struct.S* %z to i128*
+// CHECK-X: store i128 [[RES]], i128* [[CAST]], align 4
+// CHECK-X: ret
+
+// Clang is unable to emit LLVM IR for a 32-byte structure.
+void x_constraint_nofit() {
+#ifdef IMPOSSIBLE_X
+  struct S {
+unsigned x[8];
+  } z;
+  asm volatile("nop"
+   : "=x"(z));
+#endif
+}
+
+// CHECK-IMPOSSIBLE_X: invalid output size for constraint
Index: clang/test/CodeGen/asm-attrs.c
===
--- clang/test/CodeGen/asm-attrs.c
+++ clang/test/CodeGen/asm-attrs.c
@@ -8,7 +8,7 @@
 // CHECK: call i32 asm "foo5", {{.*}} [[READONLY]]
 // CHECK: call i32 asm "foo6", {{.*}} [[NOATTRS]]
 // CHECK: call void asm sideeffect "foo7", {{.*}} [[NOATTRS]]
-// CHECK: call void asm "foo8", {{.*}} [[NOATTRS]]
+// CHECK: call i32 asm "foo8", {{.*}} [[READNONE]]
 
 // CHECK: attributes [[READNONE]] = { nounwind readnone }
 // CHECK: attributes [[NOATTRS]] = { nounwind }
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -1984,6 +1984,7 @@
   std::vector ResultTruncRegTypes;
   std::vector ArgTypes;
   std::vector Args;
+  llvm::BitVector ResultTypeRequiresCast;
 
   // Keep track of inout constraints.
   std::string InOutConstraints;
@@ -2022,13 +2023,23 @@
 
 // If this is a register o

r370335 - [CodeGen]: don't treat structures returned in registers as memory inputs

2019-08-29 Thread Alexander Potapenko via cfe-commits
Author: glider
Date: Thu Aug 29 04:21:41 2019
New Revision: 370335

URL: http://llvm.org/viewvc/llvm-project?rev=370335&view=rev
Log:
[CodeGen]: don't treat structures returned in registers as memory inputs

Summary:
The "=r" output constraint for a structure variable passed to inline asm
shouldn't be converted to "=*r", as this changes the asm directive
semantics and prevents DSE optimizations.
Instead, preserve the constraints and return such structures as integers
of corresponding size, which are converted back to structures when
storing the result.

Fixes PR42672.

Subscribers: cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/CodeGen/x86_64-PR42672.c
Modified:
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/test/CodeGen/asm-attrs.c

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=370335&r1=370334&r2=370335&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Thu Aug 29 04:21:41 2019
@@ -1984,6 +1984,7 @@ void CodeGenFunction::EmitAsmStmt(const
   std::vector ResultTruncRegTypes;
   std::vector ArgTypes;
   std::vector Args;
+  llvm::BitVector ResultTypeRequiresCast;
 
   // Keep track of inout constraints.
   std::string InOutConstraints;
@@ -2022,13 +2023,23 @@ void CodeGenFunction::EmitAsmStmt(const
 
 // If this is a register output, then make the inline asm return it
 // by-value.  If this is a memory result, return the value by-reference.
-if (!Info.allowsMemory() && hasScalarEvaluationKind(OutExpr->getType())) {
+bool isScalarizableAggregate =
+hasAggregateEvaluationKind(OutExpr->getType());
+if (!Info.allowsMemory() && (hasScalarEvaluationKind(OutExpr->getType()) ||
+ isScalarizableAggregate)) {
   Constraints += "=" + OutputConstraint;
   ResultRegQualTys.push_back(OutExpr->getType());
   ResultRegDests.push_back(Dest);
-  ResultRegTypes.push_back(ConvertTypeForMem(OutExpr->getType()));
-  ResultTruncRegTypes.push_back(ResultRegTypes.back());
-
+  ResultTruncRegTypes.push_back(ConvertTypeForMem(OutExpr->getType()));
+  if (Info.allowsRegister() && isScalarizableAggregate) {
+ResultTypeRequiresCast.push_back(true);
+unsigned Size = getContext().getTypeSize(OutExpr->getType());
+llvm::Type *ConvTy = llvm::IntegerType::get(getLLVMContext(), Size);
+ResultRegTypes.push_back(ConvTy);
+  } else {
+ResultTypeRequiresCast.push_back(false);
+ResultRegTypes.push_back(ResultTruncRegTypes.back());
+  }
   // If this output is tied to an input, and if the input is larger, then
   // we need to set the actual result type of the inline asm node to be the
   // same as the input type.
@@ -2271,6 +2282,9 @@ void CodeGenFunction::EmitAsmStmt(const
   assert(RegResults.size() == ResultRegTypes.size());
   assert(RegResults.size() == ResultTruncRegTypes.size());
   assert(RegResults.size() == ResultRegDests.size());
+  // ResultRegDests can be also populated by addReturnRegisterOutputs() above,
+  // in which case its size may grow.
+  assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
   for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
 llvm::Value *Tmp = RegResults[i];
 
@@ -2300,7 +2314,24 @@ void CodeGenFunction::EmitAsmStmt(const
   }
 }
 
-EmitStoreThroughLValue(RValue::get(Tmp), ResultRegDests[i]);
+LValue Dest = ResultRegDests[i];
+// ResultTypeRequiresCast elements correspond to the first
+// ResultTypeRequiresCast.size() elements of RegResults.
+if ((i < ResultTypeRequiresCast.size()) && ResultTypeRequiresCast[i]) {
+  unsigned Size = getContext().getTypeSize(ResultRegQualTys[i]);
+  Address A = Builder.CreateBitCast(Dest.getAddress(),
+ResultRegTypes[i]->getPointerTo());
+  QualType Ty = getContext().getIntTypeForBitwidth(Size, /*Signed*/ false);
+  if (Ty.isNull()) {
+const Expr *OutExpr = S.getOutputExpr(i);
+CGM.Error(
+OutExpr->getExprLoc(),
+"impossible constraint in asm: can't store struct into a 
register");
+return;
+  }
+  Dest = MakeAddrLValue(A, Ty);
+}
+EmitStoreThroughLValue(RValue::get(Tmp), Dest);
   }
 }
 

Modified: cfe/trunk/test/CodeGen/asm-attrs.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asm-attrs.c?rev=370335&r1=370334&r2=370335&view=diff
==
--- cfe/trunk/test/CodeGen/asm-attrs.c (original)
+++ cfe/trunk/test/CodeGen/asm-attrs.c Thu Aug 29 04:21:41 2019
@@ -8,7 +8,7 @@
 // CHECK: call i32 asm "foo5", {{.*}} [[READONLY]]
 // CHECK: call i32 asm "foo6", {{.*}} [[NOATTRS]]
 // CHECK: call void asm sideeffect "

[PATCH] D65234: [CodeGen]: don't treat structures returned in registers as memory inputs

2019-08-29 Thread Alexander Potapenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL370335: [CodeGen]: don't treat structures returned in 
registers as memory inputs (authored by glider, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65234?vs=217831&id=217833#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D65234

Files:
  cfe/trunk/lib/CodeGen/CGStmt.cpp
  cfe/trunk/test/CodeGen/asm-attrs.c
  cfe/trunk/test/CodeGen/x86_64-PR42672.c

Index: cfe/trunk/lib/CodeGen/CGStmt.cpp
===
--- cfe/trunk/lib/CodeGen/CGStmt.cpp
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp
@@ -1984,6 +1984,7 @@
   std::vector ResultTruncRegTypes;
   std::vector ArgTypes;
   std::vector Args;
+  llvm::BitVector ResultTypeRequiresCast;
 
   // Keep track of inout constraints.
   std::string InOutConstraints;
@@ -2022,13 +2023,23 @@
 
 // If this is a register output, then make the inline asm return it
 // by-value.  If this is a memory result, return the value by-reference.
-if (!Info.allowsMemory() && hasScalarEvaluationKind(OutExpr->getType())) {
+bool isScalarizableAggregate =
+hasAggregateEvaluationKind(OutExpr->getType());
+if (!Info.allowsMemory() && (hasScalarEvaluationKind(OutExpr->getType()) ||
+ isScalarizableAggregate)) {
   Constraints += "=" + OutputConstraint;
   ResultRegQualTys.push_back(OutExpr->getType());
   ResultRegDests.push_back(Dest);
-  ResultRegTypes.push_back(ConvertTypeForMem(OutExpr->getType()));
-  ResultTruncRegTypes.push_back(ResultRegTypes.back());
-
+  ResultTruncRegTypes.push_back(ConvertTypeForMem(OutExpr->getType()));
+  if (Info.allowsRegister() && isScalarizableAggregate) {
+ResultTypeRequiresCast.push_back(true);
+unsigned Size = getContext().getTypeSize(OutExpr->getType());
+llvm::Type *ConvTy = llvm::IntegerType::get(getLLVMContext(), Size);
+ResultRegTypes.push_back(ConvTy);
+  } else {
+ResultTypeRequiresCast.push_back(false);
+ResultRegTypes.push_back(ResultTruncRegTypes.back());
+  }
   // If this output is tied to an input, and if the input is larger, then
   // we need to set the actual result type of the inline asm node to be the
   // same as the input type.
@@ -2271,6 +2282,9 @@
   assert(RegResults.size() == ResultRegTypes.size());
   assert(RegResults.size() == ResultTruncRegTypes.size());
   assert(RegResults.size() == ResultRegDests.size());
+  // ResultRegDests can be also populated by addReturnRegisterOutputs() above,
+  // in which case its size may grow.
+  assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
   for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
 llvm::Value *Tmp = RegResults[i];
 
@@ -2300,7 +2314,24 @@
   }
 }
 
-EmitStoreThroughLValue(RValue::get(Tmp), ResultRegDests[i]);
+LValue Dest = ResultRegDests[i];
+// ResultTypeRequiresCast elements correspond to the first
+// ResultTypeRequiresCast.size() elements of RegResults.
+if ((i < ResultTypeRequiresCast.size()) && ResultTypeRequiresCast[i]) {
+  unsigned Size = getContext().getTypeSize(ResultRegQualTys[i]);
+  Address A = Builder.CreateBitCast(Dest.getAddress(),
+ResultRegTypes[i]->getPointerTo());
+  QualType Ty = getContext().getIntTypeForBitwidth(Size, /*Signed*/ false);
+  if (Ty.isNull()) {
+const Expr *OutExpr = S.getOutputExpr(i);
+CGM.Error(
+OutExpr->getExprLoc(),
+"impossible constraint in asm: can't store struct into a register");
+return;
+  }
+  Dest = MakeAddrLValue(A, Ty);
+}
+EmitStoreThroughLValue(RValue::get(Tmp), Dest);
   }
 }
 
Index: cfe/trunk/test/CodeGen/asm-attrs.c
===
--- cfe/trunk/test/CodeGen/asm-attrs.c
+++ cfe/trunk/test/CodeGen/asm-attrs.c
@@ -8,7 +8,7 @@
 // CHECK: call i32 asm "foo5", {{.*}} [[READONLY]]
 // CHECK: call i32 asm "foo6", {{.*}} [[NOATTRS]]
 // CHECK: call void asm sideeffect "foo7", {{.*}} [[NOATTRS]]
-// CHECK: call void asm "foo8", {{.*}} [[NOATTRS]]
+// CHECK: call i32 asm "foo8", {{.*}} [[READNONE]]
 
 // CHECK: attributes [[READNONE]] = { nounwind readnone }
 // CHECK: attributes [[NOATTRS]] = { nounwind }
Index: cfe/trunk/test/CodeGen/x86_64-PR42672.c
===
--- cfe/trunk/test/CodeGen/x86_64-PR42672.c
+++ cfe/trunk/test/CodeGen/x86_64-PR42672.c
@@ -0,0 +1,102 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -DSTRUCT -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-STRUCT
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -USTRUCT -emit-llvm %s -o - 2>&1 | FileCheck %s --c

[PATCH] D65234: [CodeGen]: don't treat structures returned in registers as memory inputs

2019-08-29 Thread Alexander Potapenko via Phabricator via cfe-commits
glider added a comment.

Landed r370335, thank you!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D65234



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


[PATCH] D66937: [clangd] Fix the stale documentation about background indexing.

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66937

Files:
  clang-tools-extra/docs/clangd/Installation.rst


Index: clang-tools-extra/docs/clangd/Installation.rst
===
--- clang-tools-extra/docs/clangd/Installation.rst
+++ clang-tools-extra/docs/clangd/Installation.rst
@@ -352,20 +352,26 @@
 Creating this file by hand is a reasonable place to start if your project is
 quite simple.
 
-Project-wide Index
-==
+Background Indexing
+===
 
-By default clangd only has a view on symbols coming from files you are
-currently editing. You can extend this view to whole project by providing a
-project-wide index to clangd.  There are two ways to do this.
+clangd (v9) turns on the background indexing by default, which will 
incrementally
+build an index of your project (all files listed in the compilation database).
+The index enables code navigation features (go-to-definition, find-references)
+and global code completion.
 
-- Pass an experimental `-background-index` command line argument.  With
-  this feature enabled, clangd incrementally builds an index of projects
-  that you work on and uses the just-built index automatically.
+- the index is saved to the ``.clangd/index`` in the project root;
+- background indexing canb be disable by the ``--background-index=false`` flag;
+  if it is disabled, clangd doesn't have a global view of the whole project, it
+  only has a view on symbols coming from files you are currently editing;
 
-- Generate an index file using `clangd-indexer
+
+Build Index Manually
+
+
+You probably don't need this. There is a `clangd-indexer
   
`__
-  Then you can pass generated index file to clangd using
-  `-index-file=/path/to/index_file`.  *Note that clangd-indexer isn't
+which generates an index file for your project. To use the index, pass the flag
+`-index=file=/path/to/index_file` to clangd. *Note that clangd-indexer isn't
   included alongside clangd in the Debian clang-tools package. You will
   likely have to build it from source to use this option.*


Index: clang-tools-extra/docs/clangd/Installation.rst
===
--- clang-tools-extra/docs/clangd/Installation.rst
+++ clang-tools-extra/docs/clangd/Installation.rst
@@ -352,20 +352,26 @@
 Creating this file by hand is a reasonable place to start if your project is
 quite simple.
 
-Project-wide Index
-==
+Background Indexing
+===
 
-By default clangd only has a view on symbols coming from files you are
-currently editing. You can extend this view to whole project by providing a
-project-wide index to clangd.  There are two ways to do this.
+clangd (v9) turns on the background indexing by default, which will incrementally
+build an index of your project (all files listed in the compilation database).
+The index enables code navigation features (go-to-definition, find-references)
+and global code completion.
 
-- Pass an experimental `-background-index` command line argument.  With
-  this feature enabled, clangd incrementally builds an index of projects
-  that you work on and uses the just-built index automatically.
+- the index is saved to the ``.clangd/index`` in the project root;
+- background indexing canb be disable by the ``--background-index=false`` flag;
+  if it is disabled, clangd doesn't have a global view of the whole project, it
+  only has a view on symbols coming from files you are currently editing;
 
-- Generate an index file using `clangd-indexer
+
+Build Index Manually
+
+
+You probably don't need this. There is a `clangd-indexer
   `__
-  Then you can pass generated index file to clangd using
-  `-index-file=/path/to/index_file`.  *Note that clangd-indexer isn't
+which generates an index file for your project. To use the index, pass the flag
+`-index=file=/path/to/index_file` to clangd. *Note that clangd-indexer isn't
   included alongside clangd in the Debian clang-tools package. You will
   likely have to build it from source to use this option.*
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66876: Indexing: create PP callbacks in the ASTConsumer

2019-08-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added a comment.

Committed as r370323.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66876



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


r370336 - [Index] Moved the IndexDataConsumer::finish call into the IndexASTConsumer from IndexAction

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 04:38:43 2019
New Revision: 370336

URL: http://llvm.org/viewvc/llvm-project?rev=370336&view=rev
Log:
[Index] Moved the IndexDataConsumer::finish call into the IndexASTConsumer from 
IndexAction

Doing so removes the last reason to expose a FrontendAction from
libIndex.

Modified:
cfe/trunk/lib/Index/IndexingAction.cpp

Modified: cfe/trunk/lib/Index/IndexingAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=370336&r1=370335&r2=370336&view=diff
==
--- cfe/trunk/lib/Index/IndexingAction.cpp (original)
+++ cfe/trunk/lib/Index/IndexingAction.cpp Thu Aug 29 04:38:43 2019
@@ -54,13 +54,20 @@ public:
 };
 
 class IndexASTConsumer final : public ASTConsumer {
-  std::shared_ptr PP;
+  std::shared_ptr DataConsumer;
   std::shared_ptr IndexCtx;
+  std::shared_ptr PP;
 
 public:
-  IndexASTConsumer(std::shared_ptr PP,
-   std::shared_ptr IndexCtx)
-  : PP(std::move(PP)), IndexCtx(std::move(IndexCtx)) {}
+  IndexASTConsumer(std::shared_ptr DataConsumer,
+   const IndexingOptions &Opts,
+   std::shared_ptr PP)
+  : DataConsumer(std::move(DataConsumer)),
+IndexCtx(new IndexingContext(Opts, *this->DataConsumer)),
+PP(std::move(PP)) {
+assert(this->DataConsumer != nullptr);
+assert(this->PP != nullptr);
+  }
 
 protected:
   void Initialize(ASTContext &Context) override {
@@ -83,27 +90,25 @@ protected:
   }
 
   void HandleTranslationUnit(ASTContext &Ctx) override {
+DataConsumer->finish();
   }
 };
 
 class IndexActionBase {
 protected:
   std::shared_ptr DataConsumer;
-  std::shared_ptr IndexCtx;
+  IndexingOptions Opts;
 
-  IndexActionBase(std::shared_ptr dataConsumer,
+  IndexActionBase(std::shared_ptr DataConsumer,
   IndexingOptions Opts)
-  : DataConsumer(std::move(dataConsumer)),
-IndexCtx(new IndexingContext(Opts, *DataConsumer)) {}
+  : DataConsumer(std::move(DataConsumer)), Opts(Opts) {
+assert(this->DataConsumer != nullptr);
+  }
 
   std::unique_ptr
   createIndexASTConsumer(CompilerInstance &CI) {
-return std::make_unique(CI.getPreprocessorPtr(),
-   IndexCtx);
-  }
-
-  void finish() {
-DataConsumer->finish();
+return std::make_unique(DataConsumer, Opts,
+  CI.getPreprocessorPtr());
   }
 };
 
@@ -118,16 +123,10 @@ protected:
  StringRef InFile) override {
 return createIndexASTConsumer(CI);
   }
-
-  void EndSourceFileAction() override {
-FrontendAction::EndSourceFileAction();
-finish();
-  }
 };
 
-class WrappingIndexAction final : public WrapperFrontendAction, 
IndexActionBase {
-  bool IndexActionFailed = false;
-
+class WrappingIndexAction final : public WrapperFrontendAction,
+  IndexActionBase {
 public:
   WrappingIndexAction(std::unique_ptr WrappedAction,
   std::shared_ptr DataConsumer,
@@ -140,7 +139,6 @@ protected:
  StringRef InFile) override {
 auto OtherConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile);
 if (!OtherConsumer) {
-  IndexActionFailed = true;
   return nullptr;
 }
 
@@ -149,13 +147,6 @@ protected:
 Consumers.push_back(createIndexASTConsumer(CI));
 return std::make_unique(std::move(Consumers));
   }
-
-  void EndSourceFileAction() override {
-// Invoke wrapped action's method.
-WrapperFrontendAction::EndSourceFileAction();
-if (!IndexActionFailed)
-  finish();
-  }
 };
 
 } // anonymous namespace
@@ -164,10 +155,11 @@ std::unique_ptr
 index::createIndexingAction(std::shared_ptr DataConsumer,
 IndexingOptions Opts,
 std::unique_ptr WrappedAction) {
+  assert(DataConsumer != nullptr);
+
   if (WrappedAction)
 return std::make_unique(std::move(WrappedAction),
-  std::move(DataConsumer),
-  Opts);
+ std::move(DataConsumer), 
Opts);
   return std::make_unique(std::move(DataConsumer), Opts);
 }
 


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


[PATCH] D66877: Moved the IndexDataConsumer::finish call into the IndexASTConsumer from IndexAction

2019-08-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr closed this revision.
gribozavr marked an inline comment as done.
gribozavr added a comment.

Committed as r370336.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66877



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


r370337 - [Index] Stopped wrapping FrontendActions in libIndex and its users

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 04:43:05 2019
New Revision: 370337

URL: http://llvm.org/viewvc/llvm-project?rev=370337&view=rev
Log:
[Index] Stopped wrapping FrontendActions in libIndex and its users

Exposed a new function, createIndexingASTConsumer, that creates an
ASTConsumer. ASTConsumers compose well.

Removed wrapping functionality from createIndexingAction.

Modified:
cfe/trunk/include/clang/Index/IndexingAction.h
cfe/trunk/lib/Index/IndexingAction.cpp
cfe/trunk/tools/c-index-test/core_main.cpp
cfe/trunk/tools/libclang/Indexing.cpp

Modified: cfe/trunk/include/clang/Index/IndexingAction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexingAction.h?rev=370337&r1=370336&r2=370337&view=diff
==
--- cfe/trunk/include/clang/Index/IndexingAction.h (original)
+++ cfe/trunk/include/clang/Index/IndexingAction.h Thu Aug 29 04:43:05 2019
@@ -17,6 +17,7 @@
 
 namespace clang {
   class ASTContext;
+  class ASTConsumer;
   class ASTReader;
   class ASTUnit;
   class Decl;
@@ -49,12 +50,16 @@ struct IndexingOptions {
   bool IndexTemplateParameters = false;
 };
 
+/// Creates an ASTConsumer that indexes all symbols (macros and AST decls).
+std::unique_ptr
+createIndexingASTConsumer(std::shared_ptr DataConsumer,
+  const IndexingOptions &Opts,
+  std::shared_ptr PP);
+
 /// Creates a frontend action that indexes all symbols (macros and AST decls).
-/// \param WrappedAction another frontend action to wrap over or null.
 std::unique_ptr
 createIndexingAction(std::shared_ptr DataConsumer,
- IndexingOptions Opts,
- std::unique_ptr WrappedAction);
+ const IndexingOptions &Opts);
 
 /// Recursively indexes all decls in the AST.
 void indexASTUnit(ASTUnit &Unit, IndexDataConsumer &DataConsumer,

Modified: cfe/trunk/lib/Index/IndexingAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=370337&r1=370336&r2=370337&view=diff
==
--- cfe/trunk/lib/Index/IndexingAction.cpp (original)
+++ cfe/trunk/lib/Index/IndexingAction.cpp Thu Aug 29 04:43:05 2019
@@ -94,72 +94,38 @@ protected:
   }
 };
 
-class IndexActionBase {
-protected:
+class IndexAction final : public ASTFrontendAction {
   std::shared_ptr DataConsumer;
   IndexingOptions Opts;
 
-  IndexActionBase(std::shared_ptr DataConsumer,
-  IndexingOptions Opts)
-  : DataConsumer(std::move(DataConsumer)), Opts(Opts) {
-assert(this->DataConsumer != nullptr);
-  }
-
-  std::unique_ptr
-  createIndexASTConsumer(CompilerInstance &CI) {
-return std::make_unique(DataConsumer, Opts,
-  CI.getPreprocessorPtr());
-  }
-};
-
-class IndexAction final : public ASTFrontendAction, IndexActionBase {
 public:
   IndexAction(std::shared_ptr DataConsumer,
-  IndexingOptions Opts)
-: IndexActionBase(std::move(DataConsumer), Opts) {}
-
-protected:
-  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
- StringRef InFile) override {
-return createIndexASTConsumer(CI);
+  const IndexingOptions &Opts)
+  : DataConsumer(std::move(DataConsumer)), Opts(Opts) {
+assert(this->DataConsumer != nullptr);
   }
-};
-
-class WrappingIndexAction final : public WrapperFrontendAction,
-  IndexActionBase {
-public:
-  WrappingIndexAction(std::unique_ptr WrappedAction,
-  std::shared_ptr DataConsumer,
-  IndexingOptions Opts)
-: WrapperFrontendAction(std::move(WrappedAction)),
-  IndexActionBase(std::move(DataConsumer), Opts) {}
 
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
  StringRef InFile) override {
-auto OtherConsumer = WrapperFrontendAction::CreateASTConsumer(CI, InFile);
-if (!OtherConsumer) {
-  return nullptr;
-}
-
-std::vector> Consumers;
-Consumers.push_back(std::move(OtherConsumer));
-Consumers.push_back(createIndexASTConsumer(CI));
-return std::make_unique(std::move(Consumers));
+return std::make_unique(DataConsumer, Opts,
+  CI.getPreprocessorPtr());
   }
 };
 
 } // anonymous namespace
 
+std::unique_ptr
+index::createIndexingASTConsumer(std::shared_ptr 
DataConsumer,
+  const IndexingOptions &Opts,
+  std::shared_ptr PP) {
+  return std::make_unique(DataConsumer, Opts, PP);
+}
+
 std::unique_ptr
 index::createIndexingAction(std::shared_ptr DataConsumer,
-IndexingOptions Opts,
-std::unique_ptr WrappedAction) {
+const IndexingOptions &O

[clang-tools-extra] r370337 - [Index] Stopped wrapping FrontendActions in libIndex and its users

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 04:43:05 2019
New Revision: 370337

URL: http://llvm.org/viewvc/llvm-project?rev=370337&view=rev
Log:
[Index] Stopped wrapping FrontendActions in libIndex and its users

Exposed a new function, createIndexingASTConsumer, that creates an
ASTConsumer. ASTConsumers compose well.

Removed wrapping functionality from createIndexingAction.

Modified:
clang-tools-extra/trunk/clangd/index/IndexAction.cpp
clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp

Modified: clang-tools-extra/trunk/clangd/index/IndexAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/IndexAction.cpp?rev=370337&r1=370336&r2=370337&view=diff
==
--- clang-tools-extra/trunk/clangd/index/IndexAction.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp Thu Aug 29 04:43:05 
2019
@@ -121,42 +121,32 @@ private:
   IncludeGraph &IG;
 };
 
-/// Returns an ASTConsumer that wraps \p Inner and additionally instructs the
-/// parser to skip bodies of functions in the files that should not be
-/// processed.
-static std::unique_ptr
-skipProcessedFunctions(std::unique_ptr Inner,
-   std::function ShouldIndexFile) {
-  class SkipProcessedFunctions : public ASTConsumer {
-  public:
-SkipProcessedFunctions(std::function FileFilter)
-: ShouldIndexFile(std::move(FileFilter)), Context(nullptr) {
-  assert(this->ShouldIndexFile);
-}
+/// An ASTConsumer that instructs the parser to skip bodies of functions in the
+/// files that should not be processed.
+class SkipProcessedFunctions : public ASTConsumer {
+public:
+  SkipProcessedFunctions(std::function FileFilter)
+  : ShouldIndexFile(std::move(FileFilter)), Context(nullptr) {
+assert(this->ShouldIndexFile);
+  }
 
-void Initialize(ASTContext &Context) override { this->Context = &Context; }
-bool shouldSkipFunctionBody(Decl *D) override {
-  assert(Context && "Initialize() was never called.");
-  auto &SM = Context->getSourceManager();
-  auto FID = SM.getFileID(SM.getExpansionLoc(D->getLocation()));
-  if (!FID.isValid())
-return false;
-  return !ShouldIndexFile(FID);
-}
+  void Initialize(ASTContext &Context) override { this->Context = &Context; }
+  bool shouldSkipFunctionBody(Decl *D) override {
+assert(Context && "Initialize() was never called.");
+auto &SM = Context->getSourceManager();
+auto FID = SM.getFileID(SM.getExpansionLoc(D->getLocation()));
+if (!FID.isValid())
+  return false;
+return !ShouldIndexFile(FID);
+  }
 
-  private:
-std::function ShouldIndexFile;
-const ASTContext *Context;
-  };
-  std::vector> Consumers;
-  Consumers.push_back(
-  std::make_unique(ShouldIndexFile));
-  Consumers.push_back(std::move(Inner));
-  return std::make_unique(std::move(Consumers));
-}
+private:
+  std::function ShouldIndexFile;
+  const ASTContext *Context;
+};
 
 // Wraps the index action and reports index data after each translation unit.
-class IndexAction : public WrapperFrontendAction {
+class IndexAction : public ASTFrontendAction {
 public:
   IndexAction(std::shared_ptr C,
   std::unique_ptr Includes,
@@ -165,11 +155,10 @@ public:
   std::function RefsCallback,
   std::function RelationsCallback,
   std::function IncludeGraphCallback)
-  : WrapperFrontendAction(index::createIndexingAction(C, Opts, nullptr)),
-SymbolsCallback(SymbolsCallback), RefsCallback(RefsCallback),
-RelationsCallback(RelationsCallback),
+  : SymbolsCallback(SymbolsCallback),
+RefsCallback(RefsCallback), RelationsCallback(RelationsCallback),
 IncludeGraphCallback(IncludeGraphCallback), Collector(C),
-Includes(std::move(Includes)),
+Includes(std::move(Includes)), Opts(Opts),
 PragmaHandler(collectIWYUHeaderMaps(this->Includes.get())) {}
 
   std::unique_ptr
@@ -179,9 +168,13 @@ public:
 if (IncludeGraphCallback != nullptr)
   CI.getPreprocessor().addPPCallbacks(
   std::make_unique(CI.getSourceManager(), IG));
-return skipProcessedFunctions(
-WrapperFrontendAction::CreateASTConsumer(CI, InFile),
-[this](FileID FID) { return Collector->shouldIndexFile(FID); });
+
+std::vector> Consumers;
+Consumers.push_back(std::make_unique(
+[this](FileID FID) { return Collector->shouldIndexFile(FID); }));
+Consumers.push_back(index::createIndexingASTConsumer(
+Collector, Opts, CI.getPreprocessorPtr()));
+return std::make_unique(std::move(Consumers));
   }
 
   bool BeginInvocation(CompilerInstance &CI) override {
@@ -195,13 +188,10 @@ public:
 // bodies. The ASTConsumer will take care of skipping only functions inside
 // the files that we have already processed.
 CI.getFrontendOpts().SkipFunctionBodies = true;
-
-return WrapperFrontendAction::Be

r370338 - [Index] Added a ShouldSkipFunctionBody callback to libIndex, and refactored clients to use it instead of inventing their own solution

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 04:47:34 2019
New Revision: 370338

URL: http://llvm.org/viewvc/llvm-project?rev=370338&view=rev
Log:
[Index] Added a ShouldSkipFunctionBody callback to libIndex, and refactored 
clients to use it instead of inventing their own solution

Subscribers: jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Index/IndexingAction.h
cfe/trunk/lib/Index/IndexingAction.cpp
cfe/trunk/tools/libclang/Indexing.cpp

Modified: cfe/trunk/include/clang/Index/IndexingAction.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexingAction.h?rev=370338&r1=370337&r2=370338&view=diff
==
--- cfe/trunk/include/clang/Index/IndexingAction.h (original)
+++ cfe/trunk/include/clang/Index/IndexingAction.h Thu Aug 29 04:47:34 2019
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_INDEX_INDEXINGACTION_H
 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
 
+#include "clang/AST/ASTConsumer.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
@@ -51,10 +52,18 @@ struct IndexingOptions {
 };
 
 /// Creates an ASTConsumer that indexes all symbols (macros and AST decls).
-std::unique_ptr
-createIndexingASTConsumer(std::shared_ptr DataConsumer,
-  const IndexingOptions &Opts,
-  std::shared_ptr PP);
+std::unique_ptr createIndexingASTConsumer(
+std::shared_ptr DataConsumer,
+const IndexingOptions &Opts, std::shared_ptr PP,
+std::function ShouldSkipFunctionBody);
+
+inline std::unique_ptr createIndexingASTConsumer(
+std::shared_ptr DataConsumer,
+const IndexingOptions &Opts, std::shared_ptr PP) {
+  return createIndexingASTConsumer(
+  std::move(DataConsumer), Opts, std::move(PP),
+  /*ShouldSkipFunctionBody=*/[](const Decl *) { return false; });
+}
 
 /// Creates a frontend action that indexes all symbols (macros and AST decls).
 std::unique_ptr

Modified: cfe/trunk/lib/Index/IndexingAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=370338&r1=370337&r2=370338&view=diff
==
--- cfe/trunk/lib/Index/IndexingAction.cpp (original)
+++ cfe/trunk/lib/Index/IndexingAction.cpp Thu Aug 29 04:47:34 2019
@@ -57,14 +57,17 @@ class IndexASTConsumer final : public AS
   std::shared_ptr DataConsumer;
   std::shared_ptr IndexCtx;
   std::shared_ptr PP;
+  std::function ShouldSkipFunctionBody;
 
 public:
   IndexASTConsumer(std::shared_ptr DataConsumer,
const IndexingOptions &Opts,
-   std::shared_ptr PP)
+   std::shared_ptr PP,
+   std::function ShouldSkipFunctionBody)
   : DataConsumer(std::move(DataConsumer)),
 IndexCtx(new IndexingContext(Opts, *this->DataConsumer)),
-PP(std::move(PP)) {
+PP(std::move(PP)),
+ShouldSkipFunctionBody(std::move(ShouldSkipFunctionBody)) {
 assert(this->DataConsumer != nullptr);
 assert(this->PP != nullptr);
   }
@@ -92,6 +95,10 @@ protected:
   void HandleTranslationUnit(ASTContext &Ctx) override {
 DataConsumer->finish();
   }
+
+  bool shouldSkipFunctionBody(Decl *D) override {
+return ShouldSkipFunctionBody(D);
+  }
 };
 
 class IndexAction final : public ASTFrontendAction {
@@ -108,18 +115,20 @@ public:
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
  StringRef InFile) override {
-return std::make_unique(DataConsumer, Opts,
-  CI.getPreprocessorPtr());
+return std::make_unique(
+DataConsumer, Opts, CI.getPreprocessorPtr(),
+/*ShouldSkipFunctionBody=*/[](const Decl *) { return false; });
   }
 };
 
 } // anonymous namespace
 
-std::unique_ptr
-index::createIndexingASTConsumer(std::shared_ptr 
DataConsumer,
-  const IndexingOptions &Opts,
-  std::shared_ptr PP) {
-  return std::make_unique(DataConsumer, Opts, PP);
+std::unique_ptr index::createIndexingASTConsumer(
+std::shared_ptr DataConsumer,
+const IndexingOptions &Opts, std::shared_ptr PP,
+std::function ShouldSkipFunctionBody) {
+  return std::make_unique(DataConsumer, Opts, PP,
+ShouldSkipFunctionBody);
 }
 
 std::unique_ptr

Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=370338&r1=370337&r2=370338&view=diff
==
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Thu Aug 29 04:47:34 2019
@@ -297,54 +297,20 @@ public:
 
 class IndexingConsumer : public ASTCon

[clang-tools-extra] r370338 - [Index] Added a ShouldSkipFunctionBody callback to libIndex, and refactored clients to use it instead of inventing their own solution

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 04:47:34 2019
New Revision: 370338

URL: http://llvm.org/viewvc/llvm-project?rev=370338&view=rev
Log:
[Index] Added a ShouldSkipFunctionBody callback to libIndex, and refactored 
clients to use it instead of inventing their own solution

Subscribers: jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

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

Modified: clang-tools-extra/trunk/clangd/index/IndexAction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/IndexAction.cpp?rev=370338&r1=370337&r2=370338&view=diff
==
--- clang-tools-extra/trunk/clangd/index/IndexAction.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp Thu Aug 29 04:47:34 
2019
@@ -121,30 +121,6 @@ private:
   IncludeGraph &IG;
 };
 
-/// An ASTConsumer that instructs the parser to skip bodies of functions in the
-/// files that should not be processed.
-class SkipProcessedFunctions : public ASTConsumer {
-public:
-  SkipProcessedFunctions(std::function FileFilter)
-  : ShouldIndexFile(std::move(FileFilter)), Context(nullptr) {
-assert(this->ShouldIndexFile);
-  }
-
-  void Initialize(ASTContext &Context) override { this->Context = &Context; }
-  bool shouldSkipFunctionBody(Decl *D) override {
-assert(Context && "Initialize() was never called.");
-auto &SM = Context->getSourceManager();
-auto FID = SM.getFileID(SM.getExpansionLoc(D->getLocation()));
-if (!FID.isValid())
-  return false;
-return !ShouldIndexFile(FID);
-  }
-
-private:
-  std::function ShouldIndexFile;
-  const ASTContext *Context;
-};
-
 // Wraps the index action and reports index data after each translation unit.
 class IndexAction : public ASTFrontendAction {
 public:
@@ -169,12 +145,15 @@ public:
   CI.getPreprocessor().addPPCallbacks(
   std::make_unique(CI.getSourceManager(), IG));
 
-std::vector> Consumers;
-Consumers.push_back(std::make_unique(
-[this](FileID FID) { return Collector->shouldIndexFile(FID); }));
-Consumers.push_back(index::createIndexingASTConsumer(
-Collector, Opts, CI.getPreprocessorPtr()));
-return std::make_unique(std::move(Consumers));
+return index::createIndexingASTConsumer(
+Collector, Opts, CI.getPreprocessorPtr(),
+/*ShouldSkipFunctionBody=*/[this](const Decl *D) {
+  auto &SM = D->getASTContext().getSourceManager();
+  auto FID = SM.getFileID(SM.getExpansionLoc(D->getLocation()));
+  if (!FID.isValid())
+return false;
+  return !Collector->shouldIndexFile(FID);
+});
   }
 
   bool BeginInvocation(CompilerInstance &CI) override {


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


[PATCH] D66878: [Index] Stopped wrapping FrontendActions in libIndex and its users

2019-08-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr marked 2 inline comments as done.
gribozavr added a comment.

Committed as r370337.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66878



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


[PATCH] D66879: [Index] Added a ShouldSkipFunctionBody callback to libIndex, and refactored clients to use it instead of inventing their own solution

2019-08-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL370338: [Index] Added a ShouldSkipFunctionBody callback to 
libIndex, and refactored… (authored by gribozavr, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66879?vs=217627&id=217836#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66879

Files:
  cfe/trunk/include/clang/Index/IndexingAction.h
  cfe/trunk/lib/Index/IndexingAction.cpp
  cfe/trunk/tools/libclang/Indexing.cpp
  clang-tools-extra/trunk/clangd/index/IndexAction.cpp

Index: cfe/trunk/include/clang/Index/IndexingAction.h
===
--- cfe/trunk/include/clang/Index/IndexingAction.h
+++ cfe/trunk/include/clang/Index/IndexingAction.h
@@ -9,6 +9,7 @@
 #ifndef LLVM_CLANG_INDEX_INDEXINGACTION_H
 #define LLVM_CLANG_INDEX_INDEXINGACTION_H
 
+#include "clang/AST/ASTConsumer.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
@@ -51,10 +52,18 @@
 };
 
 /// Creates an ASTConsumer that indexes all symbols (macros and AST decls).
-std::unique_ptr
-createIndexingASTConsumer(std::shared_ptr DataConsumer,
-  const IndexingOptions &Opts,
-  std::shared_ptr PP);
+std::unique_ptr createIndexingASTConsumer(
+std::shared_ptr DataConsumer,
+const IndexingOptions &Opts, std::shared_ptr PP,
+std::function ShouldSkipFunctionBody);
+
+inline std::unique_ptr createIndexingASTConsumer(
+std::shared_ptr DataConsumer,
+const IndexingOptions &Opts, std::shared_ptr PP) {
+  return createIndexingASTConsumer(
+  std::move(DataConsumer), Opts, std::move(PP),
+  /*ShouldSkipFunctionBody=*/[](const Decl *) { return false; });
+}
 
 /// Creates a frontend action that indexes all symbols (macros and AST decls).
 std::unique_ptr
Index: cfe/trunk/lib/Index/IndexingAction.cpp
===
--- cfe/trunk/lib/Index/IndexingAction.cpp
+++ cfe/trunk/lib/Index/IndexingAction.cpp
@@ -57,14 +57,17 @@
   std::shared_ptr DataConsumer;
   std::shared_ptr IndexCtx;
   std::shared_ptr PP;
+  std::function ShouldSkipFunctionBody;
 
 public:
   IndexASTConsumer(std::shared_ptr DataConsumer,
const IndexingOptions &Opts,
-   std::shared_ptr PP)
+   std::shared_ptr PP,
+   std::function ShouldSkipFunctionBody)
   : DataConsumer(std::move(DataConsumer)),
 IndexCtx(new IndexingContext(Opts, *this->DataConsumer)),
-PP(std::move(PP)) {
+PP(std::move(PP)),
+ShouldSkipFunctionBody(std::move(ShouldSkipFunctionBody)) {
 assert(this->DataConsumer != nullptr);
 assert(this->PP != nullptr);
   }
@@ -92,6 +95,10 @@
   void HandleTranslationUnit(ASTContext &Ctx) override {
 DataConsumer->finish();
   }
+
+  bool shouldSkipFunctionBody(Decl *D) override {
+return ShouldSkipFunctionBody(D);
+  }
 };
 
 class IndexAction final : public ASTFrontendAction {
@@ -108,18 +115,20 @@
 protected:
   std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
  StringRef InFile) override {
-return std::make_unique(DataConsumer, Opts,
-  CI.getPreprocessorPtr());
+return std::make_unique(
+DataConsumer, Opts, CI.getPreprocessorPtr(),
+/*ShouldSkipFunctionBody=*/[](const Decl *) { return false; });
   }
 };
 
 } // anonymous namespace
 
-std::unique_ptr
-index::createIndexingASTConsumer(std::shared_ptr DataConsumer,
-  const IndexingOptions &Opts,
-  std::shared_ptr PP) {
-  return std::make_unique(DataConsumer, Opts, PP);
+std::unique_ptr index::createIndexingASTConsumer(
+std::shared_ptr DataConsumer,
+const IndexingOptions &Opts, std::shared_ptr PP,
+std::function ShouldSkipFunctionBody) {
+  return std::make_unique(DataConsumer, Opts, PP,
+ShouldSkipFunctionBody);
 }
 
 std::unique_ptr
Index: cfe/trunk/tools/libclang/Indexing.cpp
===
--- cfe/trunk/tools/libclang/Indexing.cpp
+++ cfe/trunk/tools/libclang/Indexing.cpp
@@ -297,54 +297,20 @@
 
 class IndexingConsumer : public ASTConsumer {
   CXIndexDataConsumer &DataConsumer;
-  ParsedSrcLocationsTracker *ParsedLocsTracker;
 
 public:
   IndexingConsumer(CXIndexDataConsumer &dataConsumer,
ParsedSrcLocationsTracker *parsedLocsTracker)
-  : DataConsumer(dataConsumer), ParsedLocsTracker(parsedLocsTracker) {}
-
-  // ASTConsumer Implementation
+  : DataConsumer(dataConsumer) {}
 
   void Initialize(ASTContext &Context) override {
 DataConsumer.setASTContext(Context);
 

[PATCH] D66937: [clangd] Fix the stale documentation about background indexing.

2019-08-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a subscriber: sammccall.
kadircet added a comment.

Thanks for updating this! Pinging @sammccall since he is also working on 
writing some release docs, might be helpful to bring this to your attention.




Comment at: clang-tools-extra/docs/clangd/Installation.rst:358
 
-By default clangd only has a view on symbols coming from files you are
-currently editing. You can extend this view to whole project by providing a
-project-wide index to clangd.  There are two ways to do this.
+clangd (v9) turns on the background indexing by default, which will 
incrementally
+build an index of your project (all files listed in the compilation database).

I don't think it is necessary to mention the version. It could be better to 
directly start with
```
Clangd builds an incremental index over files listed in the compilation 
database.
```



Comment at: clang-tools-extra/docs/clangd/Installation.rst:360
+build an index of your project (all files listed in the compilation database).
+The index enables code navigation features (go-to-definition, find-references)
+and global code completion.

instead of `enables` let's say `improves` ?



Comment at: clang-tools-extra/docs/clangd/Installation.rst:361
+The index enables code navigation features (go-to-definition, find-references)
+and global code completion.
 

drop the global



Comment at: clang-tools-extra/docs/clangd/Installation.rst:362
+and global code completion.
 
+- the index is saved to the ``.clangd/index`` in the project root;

let's mention it will only use your idle cores to build an index and total 
amount of cores it will use can be limited to `X` by passing `-j=X` to clangd



Comment at: clang-tools-extra/docs/clangd/Installation.rst:363
 
-- Pass an experimental `-background-index` command line argument.  With
-  this feature enabled, clangd incrementally builds an index of projects
-  that you work on and uses the just-built index automatically.
+- the index is saved to the ``.clangd/index`` in the project root;
+- background indexing canb be disable by the ``--background-index=false`` flag;

that's not necessarily true, we also save at home directory, and I don't think 
it is relevant for installation. maybe rather drop it?



Comment at: clang-tools-extra/docs/clangd/Installation.rst:364
+- the index is saved to the ``.clangd/index`` in the project root;
+- background indexing canb be disable by the ``--background-index=false`` flag;
+  if it is disabled, clangd doesn't have a global view of the whole project, it

s/canb/can
s/disable/disabled



Comment at: clang-tools-extra/docs/clangd/Installation.rst:365
+- background indexing canb be disable by the ``--background-index=false`` flag;
+  if it is disabled, clangd doesn't have a global view of the whole project, it
+  only has a view on symbols coming from files you are currently editing;

instead of `if it's disabled...`

```
Note that, disabling background-index will limit clangd's knowledge about your 
codebase to
files you are currently editing.
```



Comment at: clang-tools-extra/docs/clangd/Installation.rst:369
+
+Build Index Manually
+

I don't think it is relevant for installation section again. But let's make the 
`you probably don't need this` a seperate line and make it bold or red ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66937



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


r370340 - Removed two function declarations that don't have definitions

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 05:10:15 2019
New Revision: 370340

URL: http://llvm.org/viewvc/llvm-project?rev=370340&view=rev
Log:
Removed two function declarations that don't have definitions

Modified:
cfe/trunk/include/clang/AST/DeclCXX.h

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=370340&r1=370339&r2=370340&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Aug 29 05:10:15 2019
@@ -3469,12 +3469,6 @@ public:
 return IsVirtual;
   }
 
-  /// Get the constructor or constructor template in the derived class
-  /// correspnding to this using shadow declaration, if it has been implicitly
-  /// declared already.
-  CXXConstructorDecl *getConstructor() const;
-  void setConstructor(NamedDecl *Ctor);
-
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K == ConstructorUsingShadow; }
 };


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


r370341 - Removed `AnyFunctionDecl`, it is unused.

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 05:17:21 2019
New Revision: 370341

URL: http://llvm.org/viewvc/llvm-project?rev=370341&view=rev
Log:
Removed `AnyFunctionDecl`, it is unused.

Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/DeclTemplate.h

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=370341&r1=370340&r2=370341&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Thu Aug 29 05:17:21 2019
@@ -73,52 +73,6 @@ class TemplateDecl;
 class TemplateParameterList;
 class UsingDecl;
 
-/// Represents any kind of function declaration, whether it is a
-/// concrete function or a function template.
-class AnyFunctionDecl {
-  NamedDecl *Function;
-
-  AnyFunctionDecl(NamedDecl *ND) : Function(ND) {}
-
-public:
-  AnyFunctionDecl(FunctionDecl *FD) : Function(FD) {}
-  AnyFunctionDecl(FunctionTemplateDecl *FTD);
-
-  /// Implicily converts any function or function template into a
-  /// named declaration.
-  operator NamedDecl *() const { return Function; }
-
-  /// Retrieve the underlying function or function template.
-  NamedDecl *get() const { return Function; }
-
-  static AnyFunctionDecl getFromNamedDecl(NamedDecl *ND) {
-return AnyFunctionDecl(ND);
-  }
-};
-
-} // namespace clang
-
-namespace llvm {
-
-  // Provide PointerLikeTypeTraits for non-cvr pointers.
-  template<>
-  struct PointerLikeTypeTraits< ::clang::AnyFunctionDecl> {
-static void *getAsVoidPointer(::clang::AnyFunctionDecl F) {
-  return F.get();
-}
-
-static ::clang::AnyFunctionDecl getFromVoidPointer(void *P) {
-  return ::clang::AnyFunctionDecl::getFromNamedDecl(
-  static_cast< ::clang::NamedDecl*>(P));
-}
-
-enum { NumLowBitsAvailable = 2 };
-  };
-
-} // namespace llvm
-
-namespace clang {
-
 /// Represents an access specifier followed by colon ':'.
 ///
 /// An objects of this class represents sugar for the syntactic occurrence

Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=370341&r1=370340&r2=370341&view=diff
==
--- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
+++ cfe/trunk/include/clang/AST/DeclTemplate.h Thu Aug 29 05:17:21 2019
@@ -2527,10 +2527,6 @@ public:
   }
 };
 
-/// Implementation of inline functions that require the template declarations
-inline AnyFunctionDecl::AnyFunctionDecl(FunctionTemplateDecl *FTD)
-: Function(FTD) {}
-
 /// Represents a variable template specialization, which refers to
 /// a variable template with a given set of template arguments.
 ///


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


[PATCH] D66866: [ASTImporter] At import of records re-order indirect fields too.

2019-08-29 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66866



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


[PATCH] D66933: [ASTImporter] Propagate errors during import of overridden methods.

2019-08-29 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a reviewer: a_sidorin.
martong added a comment.
This revision is now accepted and ready to land.

LGTM, other than a few comments.




Comment at: clang/lib/AST/ASTImporter.cpp:7809
 
-void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
-  CXXMethodDecl *FromMethod) {
+Error ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
+   CXXMethodDecl *FromMethod) {

I think this is the time to change the name of this function. In fact, we 
import the overridden methods and not the ones which override this function.
So, I suggest this rename: `ImportOverrides` -> `ImportOverriddenMethods`



Comment at: clang/unittests/AST/ASTImporterTest.cpp:5222
+  EXPECT_EQ(OptErr->Error, ImportError::UnsupportedConstruct);
+  EXPECT_FALSE(Import(FromFooB, Lang_CXX11));
+  EXPECT_FALSE(Import(FromFooC, Lang_CXX11));

Perhaps we should check the error here is UnsupportedConstruct too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66933



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


[PATCH] D66928: [clangd] Collecting main file macro expansion locations in ParsedAST.

2019-08-29 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov marked an inline comment as done.
ilya-biryukov added inline comments.



Comment at: clang-tools-extra/clangd/ClangdUnit.cpp:107
 
+class CollectMainFileMacroExpansions : public PPCallbacks {
+  const SourceManager &SM;

Maybe make this part of `CollectMainFileMacros`? It looks like a natural fit 
there and we won't need another instance of `PPCallbacks`.



Comment at: clang-tools-extra/clangd/ClangdUnit.cpp:120
+SourceLocation L = MacroNameTok.getLocation();
+if (isInsideMainFile(SM.getSpellingLoc(L), SM) && !L.isMacroID())
+  MainFileMacroLocs.push_back(L);

I believe `getSpellingLoc` is a no-op if `isMacroID()` is false. Maybe simplify 
to:
```
if (!L.isMacroID() && isInsideMainFile(L, SM))
  ...
```



Comment at: clang-tools-extra/clangd/ClangdUnit.h:119
 
+  const std::vector &getMainFileMacroExpansionLocations() 
const;
   /// Tokens recorded while parsing the main file.

NIT: return `llvm::ArrayRef` instead of `const vector`



Comment at: clang-tools-extra/clangd/ClangdUnit.h:119
 
+  const std::vector &getMainFileMacroExpansionLocations() 
const;
   /// Tokens recorded while parsing the main file.

ilya-biryukov wrote:
> NIT: return `llvm::ArrayRef` instead of `const vector`
NIT: maybe shorten the name to `getMainFileExpansions`?



Comment at: clang-tools-extra/clangd/ClangdUnit.h:150
+  /// Does not include expansions from inside other macro expansions.
+  std::vector MainFileMacroExpLocs;
   // Data, stored after parsing.

NIT: a comment like this or a similar one is probably also useful in the public 
accessor.



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:248
+TEST(ClangdUnitTest, CollectsMainFileMacroExpansions) {
+  Annotations TestCase(R"cpp(
+#define MACRO_ARGS(X, Y) X Y

jvikstrom wrote:
> ilya-biryukov wrote:
> > Could you add a few more interesting cases?
> > 
> > 1. Macros outside the main file **and** the preamble:
> > ```
> > // foo.inc
> > int a = ID(1);
> > 
> > // foo.cpp
> > #define ID(X) X
> > 
> > int b;
> > #include "foo.inc"
> > ```
> > 
> > 2. macro expansions from token concatenations
> > ```
> > #define FOO(X) X##1()
> > #define MACRO1() 123
> > 
> > int a = FOO(MACRO);
> > ```
> > 3. Macro names inside other macros:
> > ```
> > #define FOO BAR
> > #define BAR 1
> > 
> > 
> > int a = FOO; // should BAR at line 1 be highlighted?
> > 
> > ```
> > 
> > 4. #include not part of the preamble:
> > ```
> > #define FOO 1
> > 
> > // Preamble ends here.
> > int a = 10;
> > #include "some_file_with_macros.h" // <-- should not get any macros from 
> > here
> > ```
> Does clangd handle `.inc` files differently from `.h`? Because if it doesn't 
> shouldn't ` case 1 cover case 4 as well ?
Right, sorry, was rushing to finish a comment. `.inc` and `.h` are handled 
exactly the same.
There is only a difference if they are in the preamble or not.



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:260
+// Macros from token concatenations included.
+#define CONCAT(X) X##1()
+#define MACRO1() 123

Could we also test?
```
#define PREPEND(X) Foo##X
```

It'll probably be the same, but still interesting to see whether it's any 
differnet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66928



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


[clang-tools-extra] r370343 - Fix MSVC "not all control paths return a value" warning. NFCI.

2019-08-29 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Thu Aug 29 05:37:02 2019
New Revision: 370343

URL: http://llvm.org/viewvc/llvm-project?rev=370343&view=rev
Log:
Fix MSVC "not all control paths return a value" warning. NFCI.

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

Modified: clang-tools-extra/trunk/clangd/refactor/tweaks/ExtractFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/tweaks/ExtractFunction.cpp?rev=370343&r1=370342&r2=370343&view=diff
==
--- clang-tools-extra/trunk/clangd/refactor/tweaks/ExtractFunction.cpp 
(original)
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/ExtractFunction.cpp Thu Aug 
29 05:37:02 2019
@@ -132,6 +132,7 @@ const Node *getParentOfRootStmts(const N
 // always unselected.
 return Parent->ASTNode.get() ? Parent->Parent : Parent;
   }
+  llvm_unreachable("Unhandled SelectionTree::Selection enum");
 }
 
 // The ExtractionZone class forms a view of the code wrt Zone.


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


[PATCH] D66919: Warn about zero-parameter K&R definitions in -Wstrict-prototypes

2019-08-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D66919#1650174 , @dexonsmith wrote:

> This could cause a lot of churn in existing projects (especially with `static 
> void foo()`), without giving Clang any new information.  I'm wary of this.


Those projects likely aren't aware they're using prototypeless functions, which 
are trivial to call incorrectly. I suspect this diagnostic will find real bugs 
in code.

>> Zero-parameter K&R definitions specify that the function has no
>>  parameters, but they are still not prototypes, so calling the function
>>  with the wrong number of parameters is just a warning, not an error.
> 
> Why not just directly give an error for the problematic case?  We could carve 
> out a `-W` flag (if it doesn't already exist) that warns if you incorrectly 
> pass parameters to a function whose definition has no prototype, and then 
> make it `-Werror`-by-default.

It's not incorrect to pass arguments to a function without a prototype, so that 
should not be an error. It is incorrect to pass the wrong number or types of 
arguments to a function without a prototype. It's not a bad idea to error in 
that circumstances, but there's no solution for `extern void foo()` where we 
don't see the actual definition.

If this turns out to be chatty in practice, we could put it under its own 
diagnostic flag (-Wstrict-prototype-no-params or something).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66919



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


[PATCH] D66856: [Sema] Suppress -Wformat diagnostics for bool types when printed using %hhd

2019-08-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D66856#1649721 , @erik.pilkington 
wrote:

> In D66856#1648809 , @aaron.ballman 
> wrote:
>
> > I'm wondering whether this should even warn pedantically. There are no 
> > format specifiers that apply directly to a `_Bool` datatype, so the user is 
> > left making a choice as to what specifier fits best. I think `hhd` and 
> > `hhu` are both equally reasonable types, as are the `d` and `u` groups 
> > directly -- I don't think we should warn on either of those specifiers with 
> > a `_Bool` argument. I could maybe see a case for pedantically diagnosing 
> > `h`, `l`, and `ll` prefixes with `_Bool` because that seems a bit 
> > type-confused to me. `c` as a specifier seems weird (given that false 
> > values will potentially terminate the string suddenly depending on terminal 
> > behavior, IIRC), but `lc` seems like type confusion again.
>
>
> Hmm... on second though I think the `l` and `ll` prefixes are worth -Wformat 
> proper, since that can result in printing a half-initialized integer when the 
> argument ends up on the stack (we generate `movl $0,(%rsp)` for the first 
> stack argument).


Agreed.

> I think `%c` is probably also worth a -Wformat, it seems like it would almost 
> certainly be a mistake.

That's my feeling as well. At the very least, -Wformat-pedantic.

> I suppose we could pedantically warn on `%hd`, but I'm not sure.

I think it makes sense to dos o.

> Who is the audience for -Wformat-pedantic?

To me, the audience are people who want to catch 
semantically-benign-but-logically-inconsistent format strings. e.g., it's not 
wrong to pass 'c' to something formatted as `%hd`, but it smells fishy to do so.

> Users that expect it to diagnose any pedantically-UB printf calls will 
> already be disappointed, since the C standard seems to be quite a lot more 
> restrictive then us (7.21.6.9p9 says: "If any argument is not the correct 
> type for the corresponding conversion specification, the behavior is 
> undefined." (I'm assuming "correct type" means "same type")). So I think we 
> should just concern ourselves with calls that would lead to actual problems 
> at runtime, or are likely programmer errors, and `printf("%hd", (_Bool)0)` 
> doesn't seem to meet either of those bars.

To me, actual problems at runtime belong in -Wformat and logical 
inconsistencies that don't cause runtime problems belong in -Wformat-pedantic. 
However, I think it's a defect that the C standard has no clearly UB-free way 
to print a _Bool value. I will bring this up on the reflectors to ask if we can 
clarify the standard here.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66856



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


[PATCH] D66879: [Index] Added a ShouldSkipFunctionBody callback to libIndex, and refactored clients to use it instead of inventing their own solution

2019-08-29 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: cfe/trunk/include/clang/Index/IndexingAction.h:58
+const IndexingOptions &Opts, std::shared_ptr PP,
+std::function ShouldSkipFunctionBody);
+

I know ShouldSkipFunctionBody is important for multi-threaded indexing, but why 
is it a mandatory argument?

There are lots of other overloads, are they good candidates for being mandatory 
arguments?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D66879



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


[PATCH] D66018: [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature

2019-08-29 Thread Diogo N. Sampaio via Phabricator via cfe-commits
dnsampaio accepted this revision.
dnsampaio added a comment.
This revision is now accepted and ready to land.

LGTM. One optional nit as it is not related with this patch anymore.




Comment at: lib/Driver/ToolChains/Arch/ARM.cpp:659
   llvm::ARM::ArchKind ArchKind;
-  if (CPU == "generic") {
+  if (CPU == "generic" || CPU.empty()) {
 std::string ARMArch = tools::arm::getARMArch(Arch, Triple);

dnsampaio wrote:
> Good catch.
For safety perhaps we can keep the CPU.empty() test.


Repository:
  rC Clang

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

https://reviews.llvm.org/D66018



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


[PATCH] D66732: [Clangd] ExtractFunction Added checks for broken control flow

2019-08-29 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah updated this revision to Diff 217865.
SureYeaah added a comment.

Removed selectionTree Visitor


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66732

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -520,14 +520,22 @@
   // FIXME: ExtractFunction should be unavailable inside loop construct
   // initalizer/condition.
   EXPECT_THAT(apply(" for([[int i = 0;]];);"), HasSubstr("extracted"));
+  // We should be able to extract break/continue with a parent loop/switch.
+  EXPECT_THAT(apply(" [[for(;;) if(1) break;]] "), HasSubstr("extracted"));
+  EXPECT_THAT(apply(" for(;;) [[while(1) break;]] "), HasSubstr("extracted"));
+  EXPECT_THAT(apply(" [[switch(1) { break; }]]"), HasSubstr("extracted"));
+  EXPECT_THAT(apply(" [[while(1) switch(1) { continue; }]]"),
+  HasSubstr("extracted"));
   // Don't extract because needs hoisting.
   EXPECT_THAT(apply(" [[int a = 5;]] a++; "), StartsWith("fail"));
   // Don't extract return
   EXPECT_THAT(apply(" if(true) [[return;]] "), StartsWith("fail"));
-  // Don't extract break and continue.
-  // FIXME: We should be able to extract this since it's non broken.
-  EXPECT_THAT(apply(" [[for(;;) break;]] "), StartsWith("fail"));
-  EXPECT_THAT(apply(" for(;;) [[continue;]] "), StartsWith("fail"));
+  // Don't extract break and continue without a loop/switch parent.
+  EXPECT_THAT(apply(" for(;;) [[if(1) continue;]] "), StartsWith("fail"));
+  EXPECT_THAT(apply(" while(1) [[if(1) break;]] "), StartsWith("fail"));
+  EXPECT_THAT(apply(" switch(1) { [[break;]] }"), StartsWith("fail"));
+  EXPECT_THAT(apply(" for(;;) { [[while(1) break; break;]] }"),
+  StartsWith("fail"));
 }
 
 TEST_F(ExtractFunctionTest, FileTest) {
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -29,7 +29,7 @@
 // - Void return type
 // - Cannot extract declarations that will be needed in the original function
 //   after extraction.
-// - Doesn't check for broken control flow (break/continue without loop/switch)
+// - Checks for broken control flow (break/continue without loop/switch)
 //
 // 1. ExtractFunction is the tweak subclass
 //- Prepare does basic analysis of the selection and is therefore fast.
@@ -152,6 +152,7 @@
   // semicolon after the extraction.
   const Node *getLastRootStmt() const { return Parent->Children.back(); }
   void generateRootStmts();
+
 private:
   llvm::DenseSet RootStmts;
 };
@@ -162,7 +163,7 @@
 
 // Generate RootStmts set
 void ExtractionZone::generateRootStmts() {
-  for(const Node *Child : Parent->Children)
+  for (const Node *Child : Parent->Children)
 RootStmts.insert(Child->ASTNode.get());
 }
 
@@ -178,7 +179,7 @@
   if (isa(Func))
 return nullptr;
   // FIXME: Support extraction from templated functions.
-  if(Func->isTemplated())
+  if (Func->isTemplated())
 return nullptr;
   return Func;
 }
@@ -350,8 +351,9 @@
   llvm::DenseMap DeclInfoMap;
   // True if there is a return statement in zone.
   bool HasReturnStmt = false;
-  // For now we just care whether there exists a break/continue in zone.
-  bool HasBreakOrContinue = false;
+  // Control flow is broken if we are extracting a break/continue without a
+  // corresponding parent loop/switch
+  bool BrokenControlFlow = false;
   // FIXME: capture TypeAliasDecl and UsingDirectiveDecl
   // FIXME: Capture type information as well.
   DeclInformation *createDeclInfo(const Decl *D, ZoneRelative RelativeLoc);
@@ -390,6 +392,11 @@
   }
 }
 
+bool isLoop(const Stmt *S) {
+  return isa(S) || isa(S) || isa(S) ||
+ isa(S);
+}
+
 // Captures information from Extraction Zone
 CapturedZoneInfo captureZoneInfo(const ExtractionZone &ExtZone) {
   // We use the ASTVisitor instead of using the selection tree since we need to
@@ -401,24 +408,35 @@
 ExtractionZoneVisitor(const ExtractionZone &ExtZone) : ExtZone(ExtZone) {
   TraverseDecl(const_cast(ExtZone.EnclosingFunction));
 }
+
 bool TraverseStmt(Stmt *S) {
   bool IsRootStmt = ExtZone.isRootStmt(const_cast(S));
   // If we are starting traversal of a RootStmt, we are somewhere inside
   // ExtractionZone
   if (IsRootStmt)
 CurrentLocation = ZoneRelative::Inside;
+  if (CurrentLocation == ZoneRelative::Inside) {
+CurNumberOfLoops += isLoop(S);
+CurNumberOfSwitch += isa(S);
+  }
   // Traverse using base class's Travers

[PATCH] D66943: [clangd][NFC] Update background-index command line description

2019-08-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added reviewers: hokein, sammccall.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, 
ilya-biryukov.
Herald added a project: clang.

We didn't change this in D64019  just in case 
we revert it back.
Deleting it now.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66943

Files:
  clang-tools-extra/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -122,8 +122,7 @@
 opt EnableBackgroundIndex{
 "background-index",
 cat(Features),
-desc("Index project code in the background and persist index on disk. "
- "Experimental"),
+desc("Index project code in the background and persist index on disk."),
 init(true),
 };
 


Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -122,8 +122,7 @@
 opt EnableBackgroundIndex{
 "background-index",
 cat(Features),
-desc("Index project code in the background and persist index on disk. "
- "Experimental"),
+desc("Index project code in the background and persist index on disk."),
 init(true),
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r370361 - Removed a function declaration that doesn't have a definition

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 07:21:05 2019
New Revision: 370361

URL: http://llvm.org/viewvc/llvm-project?rev=370361&view=rev
Log:
Removed a function declaration that doesn't have a definition

Modified:
cfe/trunk/include/clang/AST/ExprCXX.h

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=370361&r1=370360&r2=370361&view=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Thu Aug 29 07:21:05 2019
@@ -4340,9 +4340,6 @@ private:
   };
   llvm::PointerUnion State;
 
-  void initializeExtraState(const ValueDecl *ExtendedBy,
-unsigned ManglingNumber);
-
 public:
   MaterializeTemporaryExpr(QualType T, Expr *Temporary,
bool BoundToLvalueReference)


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


Re: r370321 - [Index] Marked a bunch of classes 'final'

2019-08-29 Thread Nico Weber via cfe-commits
Nitpick (sorry): I think common style for commit message is to describe
what the change does in present tense, i.e. ""Mark a bunch of classes
'final'".

On Thu, Aug 29, 2019 at 6:15 AM Dmitri Gribenko via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: gribozavr
> Date: Thu Aug 29 03:16:41 2019
> New Revision: 370321
>
> URL: http://llvm.org/viewvc/llvm-project?rev=370321&view=rev
> Log:
> [Index] Marked a bunch of classes 'final'
>
> This file defines multiple inheritance hierarchies and 'final' helps
> with readability.
>
> Modified:
> cfe/trunk/lib/Index/IndexingAction.cpp
>
> Modified: cfe/trunk/lib/Index/IndexingAction.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingAction.cpp?rev=370321&r1=370320&r2=370321&view=diff
>
> ==
> --- cfe/trunk/lib/Index/IndexingAction.cpp (original)
> +++ cfe/trunk/lib/Index/IndexingAction.cpp Thu Aug 29 03:16:41 2019
> @@ -23,7 +23,7 @@ using namespace clang::index;
>
>  namespace {
>
> -class IndexASTConsumer : public ASTConsumer {
> +class IndexASTConsumer final : public ASTConsumer {
>std::shared_ptr PP;
>std::shared_ptr IndexCtx;
>
> @@ -55,7 +55,7 @@ protected:
>}
>  };
>
> -class IndexPPCallbacks : public PPCallbacks {
> +class IndexPPCallbacks final : public PPCallbacks {
>std::shared_ptr IndexCtx;
>
>  public:
> @@ -110,7 +110,7 @@ protected:
>}
>  };
>
> -class IndexAction : public ASTFrontendAction, IndexActionBase {
> +class IndexAction final : public ASTFrontendAction, IndexActionBase {
>  public:
>IndexAction(std::shared_ptr DataConsumer,
>IndexingOptions Opts)
> @@ -133,7 +133,7 @@ protected:
>}
>  };
>
> -class WrappingIndexAction : public WrapperFrontendAction, IndexActionBase
> {
> +class WrappingIndexAction final : public WrapperFrontendAction,
> IndexActionBase {
>bool IndexActionFailed = false;
>
>  public:
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66928: [clangd] Collecting main file macro expansion locations in ParsedAST.

2019-08-29 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom marked an inline comment as done.
jvikstrom added inline comments.



Comment at: clang-tools-extra/clangd/ClangdUnit.cpp:107
 
+class CollectMainFileMacroExpansions : public PPCallbacks {
+  const SourceManager &SM;

ilya-biryukov wrote:
> Maybe make this part of `CollectMainFileMacros`? It looks like a natural fit 
> there and we won't need another instance of `PPCallbacks`.
But `CollectMainFileMacros` is only used for `buildPreamble`. 
I think this one needs to run in `ParsedAST::build`?

Is it safe to add a `CollectMainFileMacros in `ParsedAST::build`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66928



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


[clang-tools-extra] r370367 - [clangd][NFC] Update background-index command line description

2019-08-29 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Thu Aug 29 07:38:02 2019
New Revision: 370367

URL: http://llvm.org/viewvc/llvm-project?rev=370367&view=rev
Log:
[clangd][NFC] Update background-index command line description

Summary:
We didn't change this in D64019 just in case we revert it back.
Deleting it now.

Reviewers: hokein, sammccall

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

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp

Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=370367&r1=370366&r2=370367&view=diff
==
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Thu Aug 29 07:38:02 2019
@@ -122,8 +122,7 @@ opt ShowOrigins{
 opt EnableBackgroundIndex{
 "background-index",
 cat(Features),
-desc("Index project code in the background and persist index on disk. "
- "Experimental"),
+desc("Index project code in the background and persist index on disk."),
 init(true),
 };
 


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


[PATCH] D66943: [clangd][NFC] Update background-index command line description

2019-08-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL370367: [clangd][NFC] Update background-index command line 
description (authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66943?vs=217866&id=217876#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66943

Files:
  clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp


Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -122,8 +122,7 @@
 opt EnableBackgroundIndex{
 "background-index",
 cat(Features),
-desc("Index project code in the background and persist index on disk. "
- "Experimental"),
+desc("Index project code in the background and persist index on disk."),
 init(true),
 };
 


Index: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
@@ -122,8 +122,7 @@
 opt EnableBackgroundIndex{
 "background-index",
 cat(Features),
-desc("Index project code in the background and persist index on disk. "
- "Experimental"),
+desc("Index project code in the background and persist index on disk."),
 init(true),
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66945: [clang-tidy] Fix a false positive in unused-using-decl check.

2019-08-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: gribozavr.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.

The previous matcher "hasAnyTemplateArgument(templateArgument())" only
matches the first template argument, but the check wants to iterate all
template arguments. This patch fixes this.

Also some refactorings in this patch (to make the code reusable).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66945

Files:
  clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
  clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp

Index: clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp
===
--- clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp
+++ clang-tools-extra/test/clang-tidy/misc-unused-using-decls.cpp
@@ -29,6 +29,10 @@
 class N {};
 
 template  class P {};
+
+template 
+class Q {};
+
 const int Constant = 0;
 
 class Base {
@@ -169,6 +173,8 @@
 using n::Constant;
 // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: using decl 'Constant' is unused
 
+using n::Q;
+
 // - Usages -
 void f(B b);
 void g() {
@@ -202,3 +208,7 @@
 template 
 void i(n::P* t) {}
 template void i(n::P* t);
+
+template  class U>
+class Bar {};
+Bar *bar;
Index: clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
===
--- clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -37,13 +37,11 @@
   Finder->addMatcher(callExpr(callee(unresolvedLookupExpr().bind("used"))),
  this);
   Finder->addMatcher(
-  callExpr(hasDeclaration(functionDecl(hasAnyTemplateArgument(
-  anyOf(refersToTemplate(templateName().bind("used")),
-refersToDeclaration(functionDecl().bind("used"))),
+  callExpr(hasDeclaration(functionDecl(hasAnyTemplateArgument(anything()))
+  .bind("used_template_args"))),
   this);
-  Finder->addMatcher(loc(templateSpecializationType(hasAnyTemplateArgument(
- templateArgument().bind("used",
- this);
+  Finder->addMatcher(
+  loc(templateSpecializationType().bind("used_template_args")), this);
 }
 
 void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
@@ -85,47 +83,57 @@
   // corresponding using declaration has been found.
   // FIXME: This currently doesn't look at whether the type reference is
   // actually found with the help of the using declaration.
-  if (const auto *Used = Result.Nodes.getNodeAs("used")) {
+  auto RemoveNamedDecl = [&](const NamedDecl *Used) {
+removeFromFoundDecls(Used);
 if (const auto *FD = dyn_cast(Used)) {
   removeFromFoundDecls(FD->getPrimaryTemplate());
 } else if (const auto *Specialization =
dyn_cast(Used)) {
-  Used = Specialization->getSpecializedTemplate();
+  removeFromFoundDecls(Specialization->getSpecializedTemplate());
+} else if (const auto *FD = dyn_cast(Used)) {
+  if (const auto *FDT = FD->getPrimaryTemplate())
+removeFromFoundDecls(FDT);
+} else if (const auto *ECD = dyn_cast(Used)) {
+  if (const auto *ET = ECD->getType()->getAs())
+removeFromFoundDecls(ET->getDecl());
 }
-removeFromFoundDecls(Used);
+  };
+
+  if (const auto *Used = Result.Nodes.getNodeAs("used")) {
+RemoveNamedDecl(Used);
 return;
   }
 
-  if (const auto *Used = Result.Nodes.getNodeAs("used")) {
-// FIXME: Support non-type template parameters.
-if (Used->getKind() == TemplateArgument::Template) {
-  if (const auto *TD = Used->getAsTemplate().getAsTemplateDecl())
-removeFromFoundDecls(TD);
-} else if (Used->getKind() == TemplateArgument::Type) {
-  if (auto *RD = Used->getAsType()->getAsCXXRecordDecl())
-removeFromFoundDecls(RD);
-}
+  if (const auto *DRE = Result.Nodes.getNodeAs("used")) {
+RemoveNamedDecl(DRE->getDecl());
 return;
   }
-
-  if (const auto *Used = Result.Nodes.getNodeAs("used")) {
-removeFromFoundDecls(Used->getAsTemplateDecl());
+  
+  auto RemoveIfUsedInTemplateArguments =
+  [&](llvm::ArrayRef TemplateArgs) {
+for (const auto &Arg : TemplateArgs) {
+  if (Arg.getKind() == TemplateArgument::Template) {
+if (const auto *TD = Arg.getAsTemplate().getAsTemplateDecl())
+  RemoveNamedDecl(TD);
+  } else if (Arg.getKind() == TemplateArgument::Type) {
+if (auto *RD = Arg.getAsType()->getAsCXXRecordDecl())
+  RemoveNamedDecl(RD);
+  } else if (Arg.getKind() == TemplateArgument::Declaration) {
+RemoveNamedDecl(Arg.getAsDecl());
+  }
+}
+  };
+  if (const auto *TFD =
+  Result.Nodes.getNodeAs("used_template_args")) {
+if (const auto *TemplateArgs = TFD->getTemplateSpecializationArg

Re: [clang-tools-extra] r370367 - [clangd][NFC] Update background-index command line description

2019-08-29 Thread Hans Wennborg via cfe-commits
Merged to release_90 in r370370.

On Thu, Aug 29, 2019 at 4:36 PM Kadir Cetinkaya via cfe-commits
 wrote:
>
> Author: kadircet
> Date: Thu Aug 29 07:38:02 2019
> New Revision: 370367
>
> URL: http://llvm.org/viewvc/llvm-project?rev=370367&view=rev
> Log:
> [clangd][NFC] Update background-index command line description
>
> Summary:
> We didn't change this in D64019 just in case we revert it back.
> Deleting it now.
>
> Reviewers: hokein, sammccall
>
> Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
>
> Tags: #clang
>
> Differential Revision: https://reviews.llvm.org/D66943
>
> Modified:
> clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
>
> Modified: clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp?rev=370367&r1=370366&r2=370367&view=diff
> ==
> --- clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp (original)
> +++ clang-tools-extra/trunk/clangd/tool/ClangdMain.cpp Thu Aug 29 07:38:02 
> 2019
> @@ -122,8 +122,7 @@ opt ShowOrigins{
>  opt EnableBackgroundIndex{
>  "background-index",
>  cat(Features),
> -desc("Index project code in the background and persist index on disk. "
> - "Experimental"),
> +desc("Index project code in the background and persist index on disk."),
>  init(true),
>  };
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66732: [Clangd] ExtractFunction Added checks for broken control flow

2019-08-29 Thread Shaurya Gupta via Phabricator via cfe-commits
SureYeaah updated this revision to Diff 217881.
SureYeaah added a comment.

Added null statement check in TraverseStmt


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66732

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -520,14 +520,22 @@
   // FIXME: ExtractFunction should be unavailable inside loop construct
   // initalizer/condition.
   EXPECT_THAT(apply(" for([[int i = 0;]];);"), HasSubstr("extracted"));
+  // We should be able to extract break/continue with a parent loop/switch.
+  EXPECT_THAT(apply(" [[for(;;) if(1) break;]] "), HasSubstr("extracted"));
+  EXPECT_THAT(apply(" for(;;) [[while(1) break;]] "), HasSubstr("extracted"));
+  EXPECT_THAT(apply(" [[switch(1) { break; }]]"), HasSubstr("extracted"));
+  EXPECT_THAT(apply(" [[while(1) switch(1) { continue; }]]"),
+  HasSubstr("extracted"));
   // Don't extract because needs hoisting.
   EXPECT_THAT(apply(" [[int a = 5;]] a++; "), StartsWith("fail"));
   // Don't extract return
   EXPECT_THAT(apply(" if(true) [[return;]] "), StartsWith("fail"));
-  // Don't extract break and continue.
-  // FIXME: We should be able to extract this since it's non broken.
-  EXPECT_THAT(apply(" [[for(;;) break;]] "), StartsWith("fail"));
-  EXPECT_THAT(apply(" for(;;) [[continue;]] "), StartsWith("fail"));
+  // Don't extract break and continue without a loop/switch parent.
+  EXPECT_THAT(apply(" for(;;) [[if(1) continue;]] "), StartsWith("fail"));
+  EXPECT_THAT(apply(" while(1) [[if(1) break;]] "), StartsWith("fail"));
+  EXPECT_THAT(apply(" switch(1) { [[break;]] }"), StartsWith("fail"));
+  EXPECT_THAT(apply(" for(;;) { [[while(1) break; break;]] }"),
+  StartsWith("fail"));
 }
 
 TEST_F(ExtractFunctionTest, FileTest) {
Index: clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
===
--- clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
+++ clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
@@ -29,7 +29,7 @@
 // - Void return type
 // - Cannot extract declarations that will be needed in the original function
 //   after extraction.
-// - Doesn't check for broken control flow (break/continue without loop/switch)
+// - Checks for broken control flow (break/continue without loop/switch)
 //
 // 1. ExtractFunction is the tweak subclass
 //- Prepare does basic analysis of the selection and is therefore fast.
@@ -152,6 +152,7 @@
   // semicolon after the extraction.
   const Node *getLastRootStmt() const { return Parent->Children.back(); }
   void generateRootStmts();
+
 private:
   llvm::DenseSet RootStmts;
 };
@@ -162,7 +163,7 @@
 
 // Generate RootStmts set
 void ExtractionZone::generateRootStmts() {
-  for(const Node *Child : Parent->Children)
+  for (const Node *Child : Parent->Children)
 RootStmts.insert(Child->ASTNode.get());
 }
 
@@ -178,7 +179,7 @@
   if (isa(Func))
 return nullptr;
   // FIXME: Support extraction from templated functions.
-  if(Func->isTemplated())
+  if (Func->isTemplated())
 return nullptr;
   return Func;
 }
@@ -350,8 +351,9 @@
   llvm::DenseMap DeclInfoMap;
   // True if there is a return statement in zone.
   bool HasReturnStmt = false;
-  // For now we just care whether there exists a break/continue in zone.
-  bool HasBreakOrContinue = false;
+  // Control flow is broken if we are extracting a break/continue without a
+  // corresponding parent loop/switch
+  bool BrokenControlFlow = false;
   // FIXME: capture TypeAliasDecl and UsingDirectiveDecl
   // FIXME: Capture type information as well.
   DeclInformation *createDeclInfo(const Decl *D, ZoneRelative RelativeLoc);
@@ -390,6 +392,11 @@
   }
 }
 
+bool isLoop(const Stmt *S) {
+  return isa(S) || isa(S) || isa(S) ||
+ isa(S);
+}
+
 // Captures information from Extraction Zone
 CapturedZoneInfo captureZoneInfo(const ExtractionZone &ExtZone) {
   // We use the ASTVisitor instead of using the selection tree since we need to
@@ -401,24 +408,53 @@
 ExtractionZoneVisitor(const ExtractionZone &ExtZone) : ExtZone(ExtZone) {
   TraverseDecl(const_cast(ExtZone.EnclosingFunction));
 }
+
 bool TraverseStmt(Stmt *S) {
+  if (!S)
+return true;
   bool IsRootStmt = ExtZone.isRootStmt(const_cast(S));
   // If we are starting traversal of a RootStmt, we are somewhere inside
   // ExtractionZone
   if (IsRootStmt)
 CurrentLocation = ZoneRelative::Inside;
+  incrementLoopSwitchCounters(S);
   // Traverse using base class's TraverseStmt
   RecursiveASTVisitor::TraverseStmt(S);
+

[clang-tools-extra] r370371 - [clangd] Update out-of-date links in readme, NFC.

2019-08-29 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Thu Aug 29 07:57:32 2019
New Revision: 370371

URL: http://llvm.org/viewvc/llvm-project?rev=370371&view=rev
Log:
[clangd] Update out-of-date links in readme, NFC.

Modified:
clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md

Modified: clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md?rev=370371&r1=370370&r2=370371&view=diff
==
--- clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md (original)
+++ clang-tools-extra/trunk/clangd/clients/clangd-vscode/README.md Thu Aug 29 
07:57:32 2019
@@ -9,7 +9,7 @@ Protocol](https://github.com/Microsoft/l
 code completion, code formatting and goto definition.
 
 **Note**: `clangd` is under heavy development, not all LSP features are
-implemented. See [Current 
Status](https://clang.llvm.org/extra/clangd.html#current-status)
+implemented. See [Current 
Status](https://clang.llvm.org/extra/clangd/Features.html#complete-list-of-features)
 for details.
 
 To use `vscode-clangd` extension in VS Code, you need to install 
`vscode-clangd`
@@ -25,7 +25,7 @@ Alternatively, the `clangd` executable c
 }
 ```
 
-To obtain `clangd` binary, please see the [installing 
Clangd](https://clang.llvm.org/extra/clangd.html#installing-clangd).
+To obtain `clangd` binary, please see the [installing 
Clangd](https://clang.llvm.org/extra/clangd/Installation.html#installing-clangd).
 
 ## Development
 
@@ -68,7 +68,7 @@ to the marketplace.
 
 The extension is published under `llvm-vs-code-extensions` account, which is
 currently maintained by clangd developers. If you want to make a new release,
-please contact cfe-...@lists.llvm.org.
+please contact clangd-...@lists.llvm.org.
 
 ### Steps
 


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


[PATCH] D66928: [clangd] Collecting main file macro expansion locations in ParsedAST.

2019-08-29 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang-tools-extra/clangd/ClangdUnit.cpp:107
 
+class CollectMainFileMacroExpansions : public PPCallbacks {
+  const SourceManager &SM;

jvikstrom wrote:
> ilya-biryukov wrote:
> > Maybe make this part of `CollectMainFileMacros`? It looks like a natural 
> > fit there and we won't need another instance of `PPCallbacks`.
> But `CollectMainFileMacros` is only used for `buildPreamble`. 
> I think this one needs to run in `ParsedAST::build`?
> 
> Is it safe to add a `CollectMainFileMacros in `ParsedAST::build`?
Ah, good point, LG then.
Could you put a small comment beside the class that explicitly mentions this?
It's obvious when reading through the whole code, but not obvious when peeking 
at different parts of it from a distance.

Something like
```
// CollectMainFileMacros and CollectMainFileMacroExpansions are two different 
classes because
// the latter is only used when building preamble and the former only when 
building the AST for the main file.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66928



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


[PATCH] D66947: Changed FrontendActionFactory::create to return a std::unique_ptr

2019-08-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66947

Files:
  clang-tools-extra/clang-doc/ClangDoc.cpp
  clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbolsAction.h
  clang-tools-extra/clang-move/Move.h
  clang-tools-extra/clang-tidy/ClangTidy.cpp
  clang-tools-extra/clangd/indexer/IndexerMain.cpp
  clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/modularize/CoverageChecker.cpp
  clang-tools-extra/modularize/Modularize.cpp
  clang-tools-extra/pp-trace/PPTrace.cpp
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/Tooling.cpp
  clang/tools/clang-refactor/ClangRefactor.cpp
  clang/unittests/Tooling/ExecutionTest.cpp

Index: clang/unittests/Tooling/ExecutionTest.cpp
===
--- clang/unittests/Tooling/ExecutionTest.cpp
+++ clang/unittests/Tooling/ExecutionTest.cpp
@@ -78,7 +78,9 @@
 class ReportResultActionFactory : public FrontendActionFactory {
 public:
   ReportResultActionFactory(ExecutionContext *Context) : Context(Context) {}
-  FrontendAction *create() override { return new ReportResultAction(Context); }
+  std::unique_ptr create() override {
+return std::make_unique(Context);
+  }
 
 private:
   ExecutionContext *const Context;
Index: clang/tools/clang-refactor/ClangRefactor.cpp
===
--- clang/tools/clang-refactor/ClangRefactor.cpp
+++ clang/tools/clang-refactor/ClangRefactor.cpp
@@ -461,7 +461,9 @@
   ToolActionFactory(TUCallbackType Callback)
   : Callback(std::move(Callback)) {}
 
-  FrontendAction *create() override { return new ToolASTAction(Callback); }
+  std::unique_ptr create() override {
+return std::make_unique(Callback);
+  }
 
 private:
   TUCallbackType Callback;
Index: clang/lib/Tooling/Tooling.cpp
===
--- clang/lib/Tooling/Tooling.cpp
+++ clang/lib/Tooling/Tooling.cpp
@@ -247,12 +247,15 @@
 namespace {
 
 class SingleFrontendActionFactory : public FrontendActionFactory {
-  FrontendAction *Action;
+  std::unique_ptr Action;
 
 public:
-  SingleFrontendActionFactory(FrontendAction *Action) : Action(Action) {}
+  SingleFrontendActionFactory(std::unique_ptr Action)
+  : Action(std::move(Action)) {}
 
-  FrontendAction *create() override { return Action; }
+  std::unique_ptr create() override {
+return std::move(Action);
+  }
 };
 
 } // namespace
@@ -267,8 +270,10 @@
 std::vector CommandLine, FrontendAction *FAction,
 FileManager *Files, std::shared_ptr PCHContainerOps)
 : CommandLine(std::move(CommandLine)),
-  Action(new SingleFrontendActionFactory(FAction)), OwnsAction(true),
-  Files(Files), PCHContainerOps(std::move(PCHContainerOps)) {}
+  Action(new SingleFrontendActionFactory(
+  std::unique_ptr(FAction))),
+  OwnsAction(true), Files(Files),
+  PCHContainerOps(std::move(PCHContainerOps)) {}
 
 ToolInvocation::~ToolInvocation() {
   if (OwnsAction)
Index: clang/include/clang/Tooling/Tooling.h
===
--- clang/include/clang/Tooling/Tooling.h
+++ clang/include/clang/Tooling/Tooling.h
@@ -99,9 +99,7 @@
  DiagnosticConsumer *DiagConsumer) override;
 
   /// Returns a new clang::FrontendAction.
-  ///
-  /// The caller takes ownership of the returned action.
-  virtual FrontendAction *create() = 0;
+  virtual std::unique_ptr create() = 0;
 };
 
 /// Returns a new FrontendActionFactory for a given type.
@@ -161,6 +159,14 @@
std::shared_ptr PCHContainerOps =
std::make_shared());
 
+inline bool
+runToolOnCode(std::unique_ptr ToolAction, const Twine &Code,
+  const Twine &FileName = "input.cc",
+  std::shared_ptr PCHContainerOps =
+  std::make_shared()) {
+  return runToolOnCode(ToolAction.release(), Code, FileName, PCHContainerOps);
+}
+
 /// The first part of the pair is the filename, the second part the
 /// file-content.
 using FileContentMappings = std::vector>;
@@ -186,6 +192,17 @@
 std::make_shared(),
 const FileContentMappings &VirtualMappedFiles = FileContentMappings());
 
+inline bool runToolOnCodeWithArgs(
+std::unique_ptr ToolAction, const Twine &Code,
+const std::vector &Args, const Twine &FileName = "input.cc",
+const Twine &ToolName = "clang-tool",
+std::shared_ptr PCHContainerOps =
+std::make_shared(),
+const FileContentMappings &VirtualMappedFiles = FileContentMappings()) {
+  return runToolOnCodeWithArgs(ToolAction.release(), Code, Args, FileName,
+   ToolName, PCHContainerOps, VirtualMappedFiles);
+}
+
 // Similar to the overload except this takes a VFS.
 bool runT

[PATCH] D66948: [CodeGen]: fix error message for "=r" asm constraint

2019-08-29 Thread Alexander Potapenko via Phabricator via cfe-commits
glider created this revision.
glider added reviewers: eli.friedman, thakis.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Nico Weber reported that the following code:

  char buf[9];
  asm("" : "=r" (buf));

yields the "impossible constraint in asm: can't store struct into a register"
error message, although |buf| is not a struct (see
http://crbug.com/999160).

Make the error message more generic and add a test for it.
Also make sure other tests in x86_64-PR42672.c check for the full error
message.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66948

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/x86_64-PR42672.c


Index: clang/test/CodeGen/x86_64-PR42672.c
===
--- clang/test/CodeGen/x86_64-PR42672.c
+++ clang/test/CodeGen/x86_64-PR42672.c
@@ -4,6 +4,7 @@
 // RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_BIG 
-emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_BIG
 // RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -DPOSSIBLE_X -emit-llvm %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-X
 // RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_X 
-emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_X
+// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_9BYTES 
-emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_9BYTES
 
 // Make sure Clang doesn't treat |lockval| as asm input.
 void _raw_spin_lock(void) {
@@ -57,7 +58,7 @@
   : "=r"(str));
 #endif
 }
-// CHECK-IMPOSSIBLE_ODD: impossible constraint in asm
+// CHECK-IMPOSSIBLE_ODD: impossible constraint in asm: can't store value into 
a register
 
 // Check Clang reports an error if attempting to return a big structure via a 
register.
 void big_struct(void) {
@@ -69,7 +70,7 @@
   : "=r"(str));
 #endif
 }
-// CHECK-IMPOSSIBLE_BIG: impossible constraint in asm
+// CHECK-IMPOSSIBLE_BIG: impossible constraint in asm: can't store value into 
a register
 
 // Clang is able to emit LLVM IR for an 16-byte structure.
 void x_constraint_fit() {
@@ -100,3 +101,17 @@
 }
 
 // CHECK-IMPOSSIBLE_X: invalid output size for constraint
+
+
+// http://crbug.com/999160
+// Clang used to report the following message
+//   impossible constraint in asm: can't store struct into a register
+// for the assembly directive below, although there's no struct.
+void crbug_999160_regtest() {
+#ifdef IMPOSSIBLE_9BYTES
+  char buf[9];
+  asm("" : "=r" (buf));
+#endif
+}
+
+// CHECK-IMPOSSIBLE_9BYTES: impossible constraint in asm: can't store value 
into a register
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2326,7 +2326,7 @@
 const Expr *OutExpr = S.getOutputExpr(i);
 CGM.Error(
 OutExpr->getExprLoc(),
-"impossible constraint in asm: can't store struct into a 
register");
+"impossible constraint in asm: can't store value into a register");
 return;
   }
   Dest = MakeAddrLValue(A, Ty);


Index: clang/test/CodeGen/x86_64-PR42672.c
===
--- clang/test/CodeGen/x86_64-PR42672.c
+++ clang/test/CodeGen/x86_64-PR42672.c
@@ -4,6 +4,7 @@
 // RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_BIG -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_BIG
 // RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -DPOSSIBLE_X -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-X
 // RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_X -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_X
+// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_9BYTES -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_9BYTES
 
 // Make sure Clang doesn't treat |lockval| as asm input.
 void _raw_spin_lock(void) {
@@ -57,7 +58,7 @@
   : "=r"(str));
 #endif
 }
-// CHECK-IMPOSSIBLE_ODD: impossible constraint in asm
+// CHECK-IMPOSSIBLE_ODD: impossible constraint in asm: can't store value into a register
 
 // Check Clang reports an error if attempting to return a big structure via a register.
 void big_struct(void) {
@@ -69,7 +70,7 @@
   : "=r"(str));
 #endif
 }
-// CHECK-IMPOSSIBLE_BIG: impossible constraint in asm
+// CHECK-IMPOSSIBLE_BIG: impossible constraint in asm: can't store value into a register
 
 // Clang is able to emit LLVM IR for an 16-byte structure.
 void x_constraint_fit() {
@@ -100,3 +101,17 @@
 }
 
 // CHECK-IMPOSSIBLE_X: invalid output size for constraint
+
+
+// http://crbug.com/999160
+// Clang used to report the following message
+//   impossible constraint in asm: can't store struct into a register
+// for the assembly directive below, although there's no struct.
+void crbug_999160_regtest() {
+#ifdef 

[PATCH] D66949: [clangd] Add .vscode-test to .gitignore.

2019-08-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: jvikstrom.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66949

Files:
  clang-tools-extra/clangd/clients/clangd-vscode/.gitignore


Index: clang-tools-extra/clangd/clients/clangd-vscode/.gitignore
===
--- clang-tools-extra/clangd/clients/clangd-vscode/.gitignore
+++ clang-tools-extra/clangd/clients/clangd-vscode/.gitignore
@@ -1,2 +1,3 @@
 out
 node_modules
+.vscode-test


Index: clang-tools-extra/clangd/clients/clangd-vscode/.gitignore
===
--- clang-tools-extra/clangd/clients/clangd-vscode/.gitignore
+++ clang-tools-extra/clangd/clients/clangd-vscode/.gitignore
@@ -1,2 +1,3 @@
 out
 node_modules
+.vscode-test
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66948: [CodeGen]: fix error message for "=r" asm constraint

2019-08-29 Thread Alexander Potapenko via Phabricator via cfe-commits
glider updated this revision to Diff 217887.
glider added a comment.

clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66948

Files:
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/x86_64-PR42672.c


Index: clang/test/CodeGen/x86_64-PR42672.c
===
--- clang/test/CodeGen/x86_64-PR42672.c
+++ clang/test/CodeGen/x86_64-PR42672.c
@@ -4,6 +4,7 @@
 // RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_BIG 
-emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_BIG
 // RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -DPOSSIBLE_X -emit-llvm %s 
-o - 2>&1 | FileCheck %s --check-prefix=CHECK-X
 // RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_X 
-emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_X
+// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_9BYTES 
-emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_9BYTES
 
 // Make sure Clang doesn't treat |lockval| as asm input.
 void _raw_spin_lock(void) {
@@ -57,7 +58,7 @@
   : "=r"(str));
 #endif
 }
-// CHECK-IMPOSSIBLE_ODD: impossible constraint in asm
+// CHECK-IMPOSSIBLE_ODD: impossible constraint in asm: can't store value into 
a register
 
 // Check Clang reports an error if attempting to return a big structure via a 
register.
 void big_struct(void) {
@@ -69,7 +70,7 @@
   : "=r"(str));
 #endif
 }
-// CHECK-IMPOSSIBLE_BIG: impossible constraint in asm
+// CHECK-IMPOSSIBLE_BIG: impossible constraint in asm: can't store value into 
a register
 
 // Clang is able to emit LLVM IR for an 16-byte structure.
 void x_constraint_fit() {
@@ -100,3 +101,17 @@
 }
 
 // CHECK-IMPOSSIBLE_X: invalid output size for constraint
+
+// http://crbug.com/999160
+// Clang used to report the following message
+//   impossible constraint in asm: can't store struct into a register
+// for the assembly directive below, although there's no struct.
+void crbug_999160_regtest() {
+#ifdef IMPOSSIBLE_9BYTES
+  char buf[9];
+  asm(""
+  : "=r"(buf));
+#endif
+}
+
+// CHECK-IMPOSSIBLE_9BYTES: impossible constraint in asm: can't store value 
into a register
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2326,7 +2326,7 @@
 const Expr *OutExpr = S.getOutputExpr(i);
 CGM.Error(
 OutExpr->getExprLoc(),
-"impossible constraint in asm: can't store struct into a 
register");
+"impossible constraint in asm: can't store value into a register");
 return;
   }
   Dest = MakeAddrLValue(A, Ty);


Index: clang/test/CodeGen/x86_64-PR42672.c
===
--- clang/test/CodeGen/x86_64-PR42672.c
+++ clang/test/CodeGen/x86_64-PR42672.c
@@ -4,6 +4,7 @@
 // RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_BIG -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_BIG
 // RUN: %clang_cc1 -triple=x86_64-unknown-linux-gnu -DPOSSIBLE_X -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-X
 // RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_X -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_X
+// RUN: not %clang_cc1 -triple=x86_64-unknown-linux-gnu -DIMPOSSIBLE_9BYTES -emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IMPOSSIBLE_9BYTES
 
 // Make sure Clang doesn't treat |lockval| as asm input.
 void _raw_spin_lock(void) {
@@ -57,7 +58,7 @@
   : "=r"(str));
 #endif
 }
-// CHECK-IMPOSSIBLE_ODD: impossible constraint in asm
+// CHECK-IMPOSSIBLE_ODD: impossible constraint in asm: can't store value into a register
 
 // Check Clang reports an error if attempting to return a big structure via a register.
 void big_struct(void) {
@@ -69,7 +70,7 @@
   : "=r"(str));
 #endif
 }
-// CHECK-IMPOSSIBLE_BIG: impossible constraint in asm
+// CHECK-IMPOSSIBLE_BIG: impossible constraint in asm: can't store value into a register
 
 // Clang is able to emit LLVM IR for an 16-byte structure.
 void x_constraint_fit() {
@@ -100,3 +101,17 @@
 }
 
 // CHECK-IMPOSSIBLE_X: invalid output size for constraint
+
+// http://crbug.com/999160
+// Clang used to report the following message
+//   impossible constraint in asm: can't store struct into a register
+// for the assembly directive below, although there's no struct.
+void crbug_999160_regtest() {
+#ifdef IMPOSSIBLE_9BYTES
+  char buf[9];
+  asm(""
+  : "=r"(buf));
+#endif
+}
+
+// CHECK-IMPOSSIBLE_9BYTES: impossible constraint in asm: can't store value into a register
Index: clang/lib/CodeGen/CGStmt.cpp
===
--- clang/lib/CodeGen/CGStmt.cpp
+++ clang/lib/CodeGen/CGStmt.cpp
@@ -2326,7 +2326,7 @@
 const E

[clang-tools-extra] r370372 - [Clangd] NFC: Added fixme for checking for local/anonymous types for extracted parameters

2019-08-29 Thread Shaurya Gupta via cfe-commits
Author: sureyeaah
Date: Thu Aug 29 08:11:59 2019
New Revision: 370372

URL: http://llvm.org/viewvc/llvm-project?rev=370372&view=rev
Log:
[Clangd] NFC: Added fixme for checking for local/anonymous types for extracted 
parameters

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

Modified: clang-tools-extra/trunk/clangd/refactor/tweaks/ExtractFunction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/refactor/tweaks/ExtractFunction.cpp?rev=370372&r1=370371&r2=370372&view=diff
==
--- clang-tools-extra/trunk/clangd/refactor/tweaks/ExtractFunction.cpp 
(original)
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/ExtractFunction.cpp Thu Aug 
29 08:11:59 2019
@@ -459,6 +459,7 @@ CapturedZoneInfo captureZoneInfo(const E
 // Adds parameters to ExtractedFunc.
 // Returns true if able to find the parameters successfully and no hoisting
 // needed.
+// FIXME: Check if the declaration has a local/anonymous type
 bool createParameters(NewFunction &ExtractedFunc,
   const CapturedZoneInfo &CapturedInfo) {
   for (const auto &KeyVal : CapturedInfo.DeclInfoMap) {


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


[PATCH] D65761: Add Windows Control Flow Guard checks (/guard:cf).

2019-08-29 Thread Andrew Paverd via Phabricator via cfe-commits
ajpaverd added a comment.

In D65761#1646059 , @rnk wrote:

> I plan to take a look at this tomorrow, sorry for putting this off for a 
> while. :(


Thanks @rnk! If there's anything I can clarify/fix, please let me know.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65761



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


[PATCH] D66951: [ASTImporter] Add comprehensive tests for ODR violation handling strategies

2019-08-29 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: shafik, a_sidorin, balazske.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp, rnkovacs, 
mgorny.
Herald added a reviewer: a.sidorin.
Herald added a project: clang.
martong updated this revision to Diff 217899.
martong added a comment.

- Fix copy error


In this patch we provide additional and comprehensive tests for the ODR
handling strategies. This is the continuation of
https://reviews.llvm.org/D59692.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66951

Files:
  clang/unittests/AST/ASTImporterODRStrategiesTest.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/CMakeLists.txt

Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -11,6 +11,7 @@
   ASTImporterFixtures.cpp
   ASTImporterTest.cpp
   ASTImporterGenericRedeclTest.cpp
+  ASTImporterODRStrategiesTest.cpp
   ASTImporterVisibilityTest.cpp
   ASTTraverserTest.cpp
   ASTTypeTraitsTest.cpp
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5409,187 +5409,6 @@
   EXPECT_EQ(ImportedX->isAggregate(), FromX->isAggregate());
 }
 
-struct ConflictingDeclsWithLiberalStrategy : ASTImporterOptionSpecificTestBase {
-  ConflictingDeclsWithLiberalStrategy() {
-this->ODRHandling = ASTImporter::ODRHandlingType::Liberal;
-  }
-};
-
-// Check that a Decl has been successfully imported into a standalone redecl
-// chain.
-template 
-static void CheckImportedAsNew(llvm::Expected &Result, Decl *ToTU,
-   PatternTy Pattern) {
-  ASSERT_TRUE(isSuccess(Result));
-  Decl *ImportedD = *Result;
-  ASSERT_TRUE(ImportedD);
-  auto *ToD = FirstDeclMatcher().match(ToTU, Pattern);
-  EXPECT_NE(ImportedD, ToD);
-  EXPECT_FALSE(ImportedD->getPreviousDecl());
-  EXPECT_EQ(DeclCounter().match(ToTU, Pattern), 2u);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, Typedef) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  typedef int X;
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  typedef double X;
-  )",
-  Lang_CXX11);
-  auto Pattern = typedefNameDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, TypeAlias) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  using X = int;
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  using X = double;
-  )",
-  Lang_CXX11);
-  auto Pattern = typedefNameDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, EnumDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  enum X { a, b };
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  enum X { a, b, c };
-  )",
-  Lang_CXX11);
-  auto Pattern = enumDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, EnumConstantDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  enum E { X = 0 };
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  enum E { X = 1 };
-  )",
-  Lang_CXX11);
-  auto Pattern = enumConstantDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, RecordDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  class X { int a; };
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  class X { int b; };
-  )",
-  Lang_CXX11);
-  auto Pattern = cxxRecordDecl(hasName("X"), unless(isImplicit()));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, VarDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  int X;
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  double X;
-  )",
-  Lang_CXX11);
-  auto Pattern = varDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, FunctionDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  

[PATCH] D66951: [ASTImporter] Add comprehensive tests for ODR violation handling strategies

2019-08-29 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 217899.
martong added a comment.

- Fix copy error


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66951

Files:
  clang/unittests/AST/ASTImporterODRStrategiesTest.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/CMakeLists.txt

Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -11,6 +11,7 @@
   ASTImporterFixtures.cpp
   ASTImporterTest.cpp
   ASTImporterGenericRedeclTest.cpp
+  ASTImporterODRStrategiesTest.cpp
   ASTImporterVisibilityTest.cpp
   ASTTraverserTest.cpp
   ASTTypeTraitsTest.cpp
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5409,187 +5409,6 @@
   EXPECT_EQ(ImportedX->isAggregate(), FromX->isAggregate());
 }
 
-struct ConflictingDeclsWithLiberalStrategy : ASTImporterOptionSpecificTestBase {
-  ConflictingDeclsWithLiberalStrategy() {
-this->ODRHandling = ASTImporter::ODRHandlingType::Liberal;
-  }
-};
-
-// Check that a Decl has been successfully imported into a standalone redecl
-// chain.
-template 
-static void CheckImportedAsNew(llvm::Expected &Result, Decl *ToTU,
-   PatternTy Pattern) {
-  ASSERT_TRUE(isSuccess(Result));
-  Decl *ImportedD = *Result;
-  ASSERT_TRUE(ImportedD);
-  auto *ToD = FirstDeclMatcher().match(ToTU, Pattern);
-  EXPECT_NE(ImportedD, ToD);
-  EXPECT_FALSE(ImportedD->getPreviousDecl());
-  EXPECT_EQ(DeclCounter().match(ToTU, Pattern), 2u);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, Typedef) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  typedef int X;
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  typedef double X;
-  )",
-  Lang_CXX11);
-  auto Pattern = typedefNameDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, TypeAlias) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  using X = int;
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  using X = double;
-  )",
-  Lang_CXX11);
-  auto Pattern = typedefNameDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, EnumDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  enum X { a, b };
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  enum X { a, b, c };
-  )",
-  Lang_CXX11);
-  auto Pattern = enumDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, EnumConstantDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  enum E { X = 0 };
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  enum E { X = 1 };
-  )",
-  Lang_CXX11);
-  auto Pattern = enumConstantDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, RecordDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  class X { int a; };
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  class X { int b; };
-  )",
-  Lang_CXX11);
-  auto Pattern = cxxRecordDecl(hasName("X"), unless(isImplicit()));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, VarDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  int X;
-  )",
-  Lang_CXX11);
-  Decl *FromTU = getTuDecl(
-  R"(
-  double X;
-  )",
-  Lang_CXX11);
-  auto Pattern = varDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedAsNew(Result, ToTU, Pattern);
-}
-
-TEST_P(ConflictingDeclsWithLiberalStrategy, FunctionDecl) {
-  Decl *ToTU = getToTuDecl(
-  R"(
-  void X(int);
-  )",
-  Lang_C); // C, no overloading!
-  Decl *FromTU = getTuDecl(
-  R"(
-  void X(double);
-  )",
-  Lang_C);
-  auto Pattern = functionDecl(hasName("X"));
-  auto *FromX = FirstDeclMatcher().match(FromTU, Pattern);
-  Expected Result = importOrError(FromX, Lang_CXX11);
-  CheckImportedA

[PATCH] D66950: [SimplifyCFG] Skip sinking common lifetime markers of `alloca`.

2019-08-29 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 217901.
hliao added a comment.
Herald added subscribers: cfe-commits, erik.pilkington, mgorny.
Herald added a project: clang.

Revise `isLifeTimeMarker` following review comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66950

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/Mangle.h
  clang/include/clang/AST/MangleNumberingContext.h
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/CGCUDANV.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/test/CodeGenCUDA/unnamed-types.cu
  llvm/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/HandleLLVMOptions.cmake
  llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/sink-common-code.ll

Index: llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
===
--- llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
+++ llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
@@ -886,6 +886,33 @@
 ; CHECK: ret
 }
 
+; CHECK-LABEL: @test_not_sink_lifetime_marker
+; CHECK-NOT: select
+; CHECK: call void @llvm.lifetime.end
+; CHECK: call void @llvm.lifetime.end
+define i32 @test_not_sink_lifetime_marker(i1 zeroext %flag, i32 %x) {
+entry:
+  %y = alloca i32
+  %z = alloca i32
+  br i1 %flag, label %if.then, label %if.else
+
+if.then:
+  %y.cast = bitcast i32* %y to i8*
+  call void @llvm.lifetime.end.p0i8(i64 4, i8* %y.cast)
+  br label %if.end
+
+if.else:
+  %z.cast = bitcast i32* %z to i8*
+  call void @llvm.lifetime.end.p0i8(i64 4, i8* %z.cast)
+  br label %if.end
+
+if.end:
+  ret i32 1
+}
+
+declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
+declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
+
 
 ; CHECK: ![[$TBAA]] = !{![[TYPE:[0-9]]], ![[TYPE]], i64 0}
 ; CHECK: ![[TYPE]] = !{!"float", ![[TEXT:[0-9]]]}
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1421,6 +1421,20 @@
   return true;
 }
 
+// Check lifetime markers.
+static bool isLifeTimeMarker(const Instruction *I) {
+  if (auto II = dyn_cast(I)) {
+switch (II->getIntrinsicID()) {
+default:
+  break;
+case Intrinsic::lifetime_start:
+case Intrinsic::lifetime_end:
+  return true;
+}
+  }
+  return false;
+}
+
 // All instructions in Insts belong to different blocks that all unconditionally
 // branch to a common successor. Analyze each instruction and return true if it
 // would be possible to sink them into their successor, creating one common
@@ -1475,20 +1489,25 @@
   return false;
   }
 
-  // Because SROA can't handle speculating stores of selects, try not
-  // to sink loads or stores of allocas when we'd have to create a PHI for
-  // the address operand. Also, because it is likely that loads or stores
-  // of allocas will disappear when Mem2Reg/SROA is run, don't sink them.
+  // Because SROA can't handle speculating stores of selects, try not to sink
+  // loads, stores or lifetime markers of allocas when we'd have to create a
+  // PHI for the address operand. Also, because it is likely that loads or
+  // stores of allocas will disappear when Mem2Reg/SROA is run, don't sink
+  // them.
   // This can cause code churn which can have unintended consequences down
   // the line - see https://llvm.org/bugs/show_bug.cgi?id=30244.
   // FIXME: This is a workaround for a deficiency in SROA - see
   // https://llvm.org/bugs/show_bug.cgi?id=30188
   if (isa(I0) && any_of(Insts, [](const Instruction *I) {
-return isa(I->getOperand(1));
+return isa(I->getOperand(1)->stripPointerCasts());
   }))
 return false;
   if (isa(I0) && any_of(Insts, [](const Instruction *I) {
-return isa(I->getOperand(0));
+return isa(I->getOperand(0)->stripPointerCasts());
+  }))
+return false;
+  if (isLifeTimeMarker(I0) && any_of(Insts, [](const Instruction *I) {
+return isa(I->getOperand(1)->stripPointerCasts());
   }))
 return false;
 
Index: llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
===
--- llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
+++ llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
@@ -384,6 +384,8 @@
   Op.getNode()->isDivergent() ||
   (IIRC && TRI->isDivergentRegClass(IIRC)))
 : nullptr;
+assert(!II || IIOpNum < II->getNumOperands() || !IIRC);
+IIRC = TRI->getAllocatableClass(IIRC);
 
 i

[PATCH] D66950: [SimplifyCFG] Skip sinking common lifetime markers of `alloca`.

2019-08-29 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 217903.
hliao added a comment.

Typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66950

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/sink-common-code.ll


Index: llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
===
--- llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
+++ llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
@@ -886,6 +886,33 @@
 ; CHECK: ret
 }
 
+; CHECK-LABEL: @test_not_sink_lifetime_marker
+; CHECK-NOT: select
+; CHECK: call void @llvm.lifetime.end
+; CHECK: call void @llvm.lifetime.end
+define i32 @test_not_sink_lifetime_marker(i1 zeroext %flag, i32 %x) {
+entry:
+  %y = alloca i32
+  %z = alloca i32
+  br i1 %flag, label %if.then, label %if.else
+
+if.then:
+  %y.cast = bitcast i32* %y to i8*
+  call void @llvm.lifetime.end.p0i8(i64 4, i8* %y.cast)
+  br label %if.end
+
+if.else:
+  %z.cast = bitcast i32* %z to i8*
+  call void @llvm.lifetime.end.p0i8(i64 4, i8* %z.cast)
+  br label %if.end
+
+if.end:
+  ret i32 1
+}
+
+declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
+declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
+
 
 ; CHECK: ![[$TBAA]] = !{![[TYPE:[0-9]]], ![[TYPE]], i64 0}
 ; CHECK: ![[TYPE]] = !{!"float", ![[TEXT:[0-9]]]}
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1421,6 +1421,20 @@
   return true;
 }
 
+// Check lifetime markers.
+static bool isLifeTimeMarker(const Instruction *I) {
+  if (auto II = dyn_cast(I)) {
+switch (II->getIntrinsicID()) {
+default:
+  break;
+case Intrinsic::lifetime_start:
+case Intrinsic::lifetime_end:
+  return true;
+}
+  }
+  return false;
+}
+
 // All instructions in Insts belong to different blocks that all 
unconditionally
 // branch to a common successor. Analyze each instruction and return true if it
 // would be possible to sink them into their successor, creating one common
@@ -1475,20 +1489,25 @@
   return false;
   }
 
-  // Because SROA can't handle speculating stores of selects, try not
-  // to sink loads or stores of allocas when we'd have to create a PHI for
-  // the address operand. Also, because it is likely that loads or stores
-  // of allocas will disappear when Mem2Reg/SROA is run, don't sink them.
+  // Because SROA can't handle speculating stores of selects, try not to sink
+  // loads, stores or lifetime markers of allocas when we'd have to create a
+  // PHI for the address operand. Also, because it is likely that loads or
+  // stores of allocas will disappear when Mem2Reg/SROA is run, don't sink
+  // them.
   // This can cause code churn which can have unintended consequences down
   // the line - see https://llvm.org/bugs/show_bug.cgi?id=30244.
   // FIXME: This is a workaround for a deficiency in SROA - see
   // https://llvm.org/bugs/show_bug.cgi?id=30188
   if (isa(I0) && any_of(Insts, [](const Instruction *I) {
-return isa(I->getOperand(1));
+return isa(I->getOperand(1)->stripPointerCasts());
   }))
 return false;
   if (isa(I0) && any_of(Insts, [](const Instruction *I) {
-return isa(I->getOperand(0));
+return isa(I->getOperand(0)->stripPointerCasts());
+  }))
+return false;
+  if (isLifeTimeMarker(I0) && any_of(Insts, [](const Instruction *I) {
+return isa(I->getOperand(1)->stripPointerCasts());
   }))
 return false;
 


Index: llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
===
--- llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
+++ llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
@@ -886,6 +886,33 @@
 ; CHECK: ret
 }
 
+; CHECK-LABEL: @test_not_sink_lifetime_marker
+; CHECK-NOT: select
+; CHECK: call void @llvm.lifetime.end
+; CHECK: call void @llvm.lifetime.end
+define i32 @test_not_sink_lifetime_marker(i1 zeroext %flag, i32 %x) {
+entry:
+  %y = alloca i32
+  %z = alloca i32
+  br i1 %flag, label %if.then, label %if.else
+
+if.then:
+  %y.cast = bitcast i32* %y to i8*
+  call void @llvm.lifetime.end.p0i8(i64 4, i8* %y.cast)
+  br label %if.end
+
+if.else:
+  %z.cast = bitcast i32* %z to i8*
+  call void @llvm.lifetime.end.p0i8(i64 4, i8* %z.cast)
+  br label %if.end
+
+if.end:
+  ret i32 1
+}
+
+declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
+declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
+
 
 ; CHECK: ![[$TBAA]] = !{![[TYPE:[0-9]]], ![[TYPE]], i64 0}
 ; CHECK: ![[TYPE]] = !{!"float", ![[TEXT:[0-9]]]}
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyC

[PATCH] D66919: Warn about zero-parameter K&R definitions in -Wstrict-prototypes

2019-08-29 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

In D66919#1650775 , @aaron.ballman 
wrote:

> In D66919#1650174 , @dexonsmith 
> wrote:
>
> > This could cause a lot of churn in existing projects (especially with 
> > `static void foo()`), without giving Clang any new information.  I'm wary 
> > of this.
>
>
> Those projects likely aren't aware they're using prototypeless functions, 
> which are trivial to call incorrectly. I suspect this diagnostic will find 
> real bugs in code.


To be clear, my understanding is that `-Wstrict-prototypes` already warns on 
non-prototype declarations like this:

  void foo();

we just don't warn on non-prototype defining declarations, where the meaning is 
unambiguous:

  void foo() {}



> It's not incorrect to pass arguments to a function without a prototype, so 
> that should not be an error. It is incorrect to pass the wrong number or 
> types of arguments to a function without a prototype. It's not a bad idea to 
> error in that circumstances, but there's no solution for `extern void foo()` 
> where we don't see the actual definition.

Given my understanding, then the only corner case that's left is when we *do* 
see the definition.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66919



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


[PATCH] D66947: Changed FrontendActionFactory::create to return a std::unique_ptr

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

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66947



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


[PATCH] D66950: [SimplifyCFG] Skip sinking common lifetime markers of `alloca`.

2019-08-29 Thread Michael Liao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG001871dee8b1: [SimplifyCFG] Skip sinking common lifetime 
markers of `alloca`. (authored by hliao).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66950

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/Transforms/SimplifyCFG/sink-common-code.ll


Index: llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
===
--- llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
+++ llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
@@ -886,6 +886,33 @@
 ; CHECK: ret
 }
 
+; CHECK-LABEL: @test_not_sink_lifetime_marker
+; CHECK-NOT: select
+; CHECK: call void @llvm.lifetime.end
+; CHECK: call void @llvm.lifetime.end
+define i32 @test_not_sink_lifetime_marker(i1 zeroext %flag, i32 %x) {
+entry:
+  %y = alloca i32
+  %z = alloca i32
+  br i1 %flag, label %if.then, label %if.else
+
+if.then:
+  %y.cast = bitcast i32* %y to i8*
+  call void @llvm.lifetime.end.p0i8(i64 4, i8* %y.cast)
+  br label %if.end
+
+if.else:
+  %z.cast = bitcast i32* %z to i8*
+  call void @llvm.lifetime.end.p0i8(i64 4, i8* %z.cast)
+  br label %if.end
+
+if.end:
+  ret i32 1
+}
+
+declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
+declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
+
 
 ; CHECK: ![[$TBAA]] = !{![[TYPE:[0-9]]], ![[TYPE]], i64 0}
 ; CHECK: ![[TYPE]] = !{!"float", ![[TEXT:[0-9]]]}
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -1421,6 +1421,20 @@
   return true;
 }
 
+// Check lifetime markers.
+static bool isLifeTimeMarker(const Instruction *I) {
+  if (auto II = dyn_cast(I)) {
+switch (II->getIntrinsicID()) {
+default:
+  break;
+case Intrinsic::lifetime_start:
+case Intrinsic::lifetime_end:
+  return true;
+}
+  }
+  return false;
+}
+
 // All instructions in Insts belong to different blocks that all 
unconditionally
 // branch to a common successor. Analyze each instruction and return true if it
 // would be possible to sink them into their successor, creating one common
@@ -1475,20 +1489,25 @@
   return false;
   }
 
-  // Because SROA can't handle speculating stores of selects, try not
-  // to sink loads or stores of allocas when we'd have to create a PHI for
-  // the address operand. Also, because it is likely that loads or stores
-  // of allocas will disappear when Mem2Reg/SROA is run, don't sink them.
+  // Because SROA can't handle speculating stores of selects, try not to sink
+  // loads, stores or lifetime markers of allocas when we'd have to create a
+  // PHI for the address operand. Also, because it is likely that loads or
+  // stores of allocas will disappear when Mem2Reg/SROA is run, don't sink
+  // them.
   // This can cause code churn which can have unintended consequences down
   // the line - see https://llvm.org/bugs/show_bug.cgi?id=30244.
   // FIXME: This is a workaround for a deficiency in SROA - see
   // https://llvm.org/bugs/show_bug.cgi?id=30188
   if (isa(I0) && any_of(Insts, [](const Instruction *I) {
-return isa(I->getOperand(1));
+return isa(I->getOperand(1)->stripPointerCasts());
   }))
 return false;
   if (isa(I0) && any_of(Insts, [](const Instruction *I) {
-return isa(I->getOperand(0));
+return isa(I->getOperand(0)->stripPointerCasts());
+  }))
+return false;
+  if (isLifeTimeMarker(I0) && any_of(Insts, [](const Instruction *I) {
+return isa(I->getOperand(1)->stripPointerCasts());
   }))
 return false;
 


Index: llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
===
--- llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
+++ llvm/test/Transforms/SimplifyCFG/sink-common-code.ll
@@ -886,6 +886,33 @@
 ; CHECK: ret
 }
 
+; CHECK-LABEL: @test_not_sink_lifetime_marker
+; CHECK-NOT: select
+; CHECK: call void @llvm.lifetime.end
+; CHECK: call void @llvm.lifetime.end
+define i32 @test_not_sink_lifetime_marker(i1 zeroext %flag, i32 %x) {
+entry:
+  %y = alloca i32
+  %z = alloca i32
+  br i1 %flag, label %if.then, label %if.else
+
+if.then:
+  %y.cast = bitcast i32* %y to i8*
+  call void @llvm.lifetime.end.p0i8(i64 4, i8* %y.cast)
+  br label %if.end
+
+if.else:
+  %z.cast = bitcast i32* %z to i8*
+  call void @llvm.lifetime.end.p0i8(i64 4, i8* %z.cast)
+  br label %if.end
+
+if.end:
+  ret i32 1
+}
+
+declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
+declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
+
 
 ; CHECK: ![[$TBAA]] = !{![[TYPE:[0-9]]], ![[TYPE]], i64 0}
 ; CHECK: ![[TYPE]] = !{!"float", ![[TEXT:[0-9]]]}
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
==

[PATCH] D66621: [clang] Devirtualization for classes with destructors marked as 'final'

2019-08-29 Thread Logan Smith via Phabricator via cfe-commits
logan-5 added a comment.

//ping//


Repository:
  rC Clang

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

https://reviews.llvm.org/D66621



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


r370379 - Changed FrontendActionFactory::create to return a std::unique_ptr

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 09:38:36 2019
New Revision: 370379

URL: http://llvm.org/viewvc/llvm-project?rev=370379&view=rev
Log:
Changed FrontendActionFactory::create to return a std::unique_ptr

Subscribers: jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Tooling/Tooling.h
cfe/trunk/lib/Tooling/Tooling.cpp
cfe/trunk/tools/clang-refactor/ClangRefactor.cpp
cfe/trunk/unittests/Tooling/ExecutionTest.cpp

Modified: cfe/trunk/include/clang/Tooling/Tooling.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Tooling.h?rev=370379&r1=370378&r2=370379&view=diff
==
--- cfe/trunk/include/clang/Tooling/Tooling.h (original)
+++ cfe/trunk/include/clang/Tooling/Tooling.h Thu Aug 29 09:38:36 2019
@@ -99,9 +99,7 @@ public:
  DiagnosticConsumer *DiagConsumer) override;
 
   /// Returns a new clang::FrontendAction.
-  ///
-  /// The caller takes ownership of the returned action.
-  virtual FrontendAction *create() = 0;
+  virtual std::unique_ptr create() = 0;
 };
 
 /// Returns a new FrontendActionFactory for a given type.
@@ -161,6 +159,14 @@ bool runToolOnCode(FrontendAction *ToolA
std::shared_ptr PCHContainerOps =
std::make_shared());
 
+inline bool
+runToolOnCode(std::unique_ptr ToolAction, const Twine &Code,
+  const Twine &FileName = "input.cc",
+  std::shared_ptr PCHContainerOps =
+  std::make_shared()) {
+  return runToolOnCode(ToolAction.release(), Code, FileName, PCHContainerOps);
+}
+
 /// The first part of the pair is the filename, the second part the
 /// file-content.
 using FileContentMappings = std::vector>;
@@ -186,6 +192,17 @@ bool runToolOnCodeWithArgs(
 std::make_shared(),
 const FileContentMappings &VirtualMappedFiles = FileContentMappings());
 
+inline bool runToolOnCodeWithArgs(
+std::unique_ptr ToolAction, const Twine &Code,
+const std::vector &Args, const Twine &FileName = "input.cc",
+const Twine &ToolName = "clang-tool",
+std::shared_ptr PCHContainerOps =
+std::make_shared(),
+const FileContentMappings &VirtualMappedFiles = FileContentMappings()) {
+  return runToolOnCodeWithArgs(ToolAction.release(), Code, Args, FileName,
+   ToolName, PCHContainerOps, VirtualMappedFiles);
+}
+
 // Similar to the overload except this takes a VFS.
 bool runToolOnCodeWithArgs(
 FrontendAction *ToolAction, const Twine &Code,
@@ -195,6 +212,17 @@ bool runToolOnCodeWithArgs(
 std::shared_ptr PCHContainerOps =
 std::make_shared());
 
+inline bool runToolOnCodeWithArgs(
+std::unique_ptr ToolAction, const Twine &Code,
+llvm::IntrusiveRefCntPtr VFS,
+const std::vector &Args, const Twine &FileName = "input.cc",
+const Twine &ToolName = "clang-tool",
+std::shared_ptr PCHContainerOps =
+std::make_shared()) {
+  return runToolOnCodeWithArgs(ToolAction.release(), Code, VFS, Args, FileName,
+   ToolName, PCHContainerOps);
+}
+
 /// Builds an AST for 'Code'.
 ///
 /// \param Code C++ code.
@@ -247,6 +275,13 @@ public:
  std::shared_ptr PCHContainerOps =
  std::make_shared());
 
+  ToolInvocation(std::vector CommandLine,
+ std::unique_ptr FAction, FileManager *Files,
+ std::shared_ptr PCHContainerOps =
+ std::make_shared())
+  : ToolInvocation(std::move(CommandLine), FAction.release(), Files,
+   PCHContainerOps) {}
+
   /// Create a tool invocation.
   ///
   /// \param CommandLine The command line arguments to clang.
@@ -397,7 +432,9 @@ template 
 std::unique_ptr newFrontendActionFactory() {
   class SimpleFrontendActionFactory : public FrontendActionFactory {
   public:
-FrontendAction *create() override { return new T; }
+std::unique_ptr create() override {
+  return std::make_unique();
+}
   };
 
   return std::unique_ptr(
@@ -413,8 +450,9 @@ inline std::unique_ptr create() override {
+  return std::make_unique(ConsumerFactory,
+  Callbacks);
 }
 
   private:

Modified: cfe/trunk/lib/Tooling/Tooling.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=370379&r1=370378&r2=370379&view=diff
==
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)
+++ cfe/trunk/lib/Tooling/Tooling.cpp Thu Aug 29 09:38:36 2019
@@ -247,12 +247,15 @@ void addTargetAndModeForProgramName(std:
 namespace {
 
 class SingleFrontendActionFactory : public FrontendActionFactory {
-  FrontendAction *Action;
+  std::unique_ptr Action;
 
 public:
-  SingleFrontendActionFactory(FrontendAction *Action) : Action(Action) {}

[clang-tools-extra] r370379 - Changed FrontendActionFactory::create to return a std::unique_ptr

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 09:38:36 2019
New Revision: 370379

URL: http://llvm.org/viewvc/llvm-project?rev=370379&view=rev
Log:
Changed FrontendActionFactory::create to return a std::unique_ptr

Subscribers: jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clang-doc/ClangDoc.cpp

clang-tools-extra/trunk/clang-include-fixer/find-all-symbols/FindAllSymbolsAction.h
clang-tools-extra/trunk/clang-move/Move.h
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp
clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp
clang-tools-extra/trunk/modularize/CoverageChecker.cpp
clang-tools-extra/trunk/modularize/Modularize.cpp
clang-tools-extra/trunk/pp-trace/PPTrace.cpp

Modified: clang-tools-extra/trunk/clang-doc/ClangDoc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-doc/ClangDoc.cpp?rev=370379&r1=370378&r2=370379&view=diff
==
--- clang-tools-extra/trunk/clang-doc/ClangDoc.cpp (original)
+++ clang-tools-extra/trunk/clang-doc/ClangDoc.cpp Thu Aug 29 09:38:36 2019
@@ -29,13 +29,13 @@ namespace doc {
 class MapperActionFactory : public tooling::FrontendActionFactory {
 public:
   MapperActionFactory(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
-  clang::FrontendAction *create() override;
+  std::unique_ptr create() override;
 
 private:
   ClangDocContext CDCtx;
 };
 
-clang::FrontendAction *MapperActionFactory::create() {
+std::unique_ptr MapperActionFactory::create() {
   class ClangDocAction : public clang::ASTFrontendAction {
   public:
 ClangDocAction(ClangDocContext CDCtx) : CDCtx(CDCtx) {}
@@ -49,7 +49,7 @@ clang::FrontendAction *MapperActionFacto
   private:
 ClangDocContext CDCtx;
   };
-  return new ClangDocAction(CDCtx);
+  return std::make_unique(CDCtx);
 }
 
 std::unique_ptr

Modified: 
clang-tools-extra/trunk/clang-include-fixer/find-all-symbols/FindAllSymbolsAction.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-include-fixer/find-all-symbols/FindAllSymbolsAction.h?rev=370379&r1=370378&r2=370379&view=diff
==
--- 
clang-tools-extra/trunk/clang-include-fixer/find-all-symbols/FindAllSymbolsAction.h
 (original)
+++ 
clang-tools-extra/trunk/clang-include-fixer/find-all-symbols/FindAllSymbolsAction.h
 Thu Aug 29 09:38:36 2019
@@ -47,8 +47,8 @@ public:
   const HeaderMapCollector::RegexHeaderMap *RegexHeaderMap = nullptr)
   : Reporter(Reporter), RegexHeaderMap(RegexHeaderMap) {}
 
-  clang::FrontendAction *create() override {
-return new FindAllSymbolsAction(Reporter, RegexHeaderMap);
+  std::unique_ptr create() override {
+return std::make_unique(Reporter, RegexHeaderMap);
   }
 
 private:

Modified: clang-tools-extra/trunk/clang-move/Move.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/Move.h?rev=370379&r1=370378&r2=370379&view=diff
==
--- clang-tools-extra/trunk/clang-move/Move.h (original)
+++ clang-tools-extra/trunk/clang-move/Move.h Thu Aug 29 09:38:36 2019
@@ -224,8 +224,8 @@ public:
  DeclarationReporter *const Reporter = nullptr)
   : Context(Context), Reporter(Reporter) {}
 
-  clang::FrontendAction *create() override {
-return new ClangMoveAction(Context, Reporter);
+  std::unique_ptr create() override {
+return std::make_unique(Context, Reporter);
   }
 
 private:

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=370379&r1=370378&r2=370379&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Thu Aug 29 09:38:36 2019
@@ -530,7 +530,9 @@ runClangTidy(clang::tidy::ClangTidyConte
 ActionFactory(ClangTidyContext &Context,
   IntrusiveRefCntPtr BaseFS)
 : ConsumerFactory(Context, BaseFS) {}
-FrontendAction *create() override { return new Action(&ConsumerFactory); }
+std::unique_ptr create() override {
+  return std::make_unique(&ConsumerFactory);
+}
 
 bool runInvocation(std::shared_ptr Invocation,
FileManager *Files,

Modified: clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp?rev=370379&r1=370378&r2=370379&view=diff
==
--- clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp (original)
+++ clang-tools-extra/trunk/clangd/indexer/IndexerMain.c

[PATCH] D66947: Changed FrontendActionFactory::create to return a std::unique_ptr

2019-08-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL370379: Changed FrontendActionFactory::create to return a 
std::unique_ptr (authored by gribozavr, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66947?vs=217883&id=217914#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D66947

Files:
  cfe/trunk/include/clang/Tooling/Tooling.h
  cfe/trunk/lib/Tooling/Tooling.cpp
  cfe/trunk/tools/clang-refactor/ClangRefactor.cpp
  cfe/trunk/unittests/Tooling/ExecutionTest.cpp
  clang-tools-extra/trunk/clang-doc/ClangDoc.cpp
  
clang-tools-extra/trunk/clang-include-fixer/find-all-symbols/FindAllSymbolsAction.h
  clang-tools-extra/trunk/clang-move/Move.h
  clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
  clang-tools-extra/trunk/clangd/indexer/IndexerMain.cpp
  clang-tools-extra/trunk/clangd/unittests/SymbolCollectorTests.cpp
  clang-tools-extra/trunk/modularize/CoverageChecker.cpp
  clang-tools-extra/trunk/modularize/Modularize.cpp
  clang-tools-extra/trunk/pp-trace/PPTrace.cpp

Index: cfe/trunk/lib/Tooling/Tooling.cpp
===
--- cfe/trunk/lib/Tooling/Tooling.cpp
+++ cfe/trunk/lib/Tooling/Tooling.cpp
@@ -247,12 +247,15 @@
 namespace {
 
 class SingleFrontendActionFactory : public FrontendActionFactory {
-  FrontendAction *Action;
+  std::unique_ptr Action;
 
 public:
-  SingleFrontendActionFactory(FrontendAction *Action) : Action(Action) {}
+  SingleFrontendActionFactory(std::unique_ptr Action)
+  : Action(std::move(Action)) {}
 
-  FrontendAction *create() override { return Action; }
+  std::unique_ptr create() override {
+return std::move(Action);
+  }
 };
 
 } // namespace
@@ -267,8 +270,10 @@
 std::vector CommandLine, FrontendAction *FAction,
 FileManager *Files, std::shared_ptr PCHContainerOps)
 : CommandLine(std::move(CommandLine)),
-  Action(new SingleFrontendActionFactory(FAction)), OwnsAction(true),
-  Files(Files), PCHContainerOps(std::move(PCHContainerOps)) {}
+  Action(new SingleFrontendActionFactory(
+  std::unique_ptr(FAction))),
+  OwnsAction(true), Files(Files),
+  PCHContainerOps(std::move(PCHContainerOps)) {}
 
 ToolInvocation::~ToolInvocation() {
   if (OwnsAction)
Index: cfe/trunk/unittests/Tooling/ExecutionTest.cpp
===
--- cfe/trunk/unittests/Tooling/ExecutionTest.cpp
+++ cfe/trunk/unittests/Tooling/ExecutionTest.cpp
@@ -78,7 +78,9 @@
 class ReportResultActionFactory : public FrontendActionFactory {
 public:
   ReportResultActionFactory(ExecutionContext *Context) : Context(Context) {}
-  FrontendAction *create() override { return new ReportResultAction(Context); }
+  std::unique_ptr create() override {
+return std::make_unique(Context);
+  }
 
 private:
   ExecutionContext *const Context;
Index: cfe/trunk/tools/clang-refactor/ClangRefactor.cpp
===
--- cfe/trunk/tools/clang-refactor/ClangRefactor.cpp
+++ cfe/trunk/tools/clang-refactor/ClangRefactor.cpp
@@ -461,7 +461,9 @@
   ToolActionFactory(TUCallbackType Callback)
   : Callback(std::move(Callback)) {}
 
-  FrontendAction *create() override { return new ToolASTAction(Callback); }
+  std::unique_ptr create() override {
+return std::make_unique(Callback);
+  }
 
 private:
   TUCallbackType Callback;
Index: cfe/trunk/include/clang/Tooling/Tooling.h
===
--- cfe/trunk/include/clang/Tooling/Tooling.h
+++ cfe/trunk/include/clang/Tooling/Tooling.h
@@ -99,9 +99,7 @@
  DiagnosticConsumer *DiagConsumer) override;
 
   /// Returns a new clang::FrontendAction.
-  ///
-  /// The caller takes ownership of the returned action.
-  virtual FrontendAction *create() = 0;
+  virtual std::unique_ptr create() = 0;
 };
 
 /// Returns a new FrontendActionFactory for a given type.
@@ -161,6 +159,14 @@
std::shared_ptr PCHContainerOps =
std::make_shared());
 
+inline bool
+runToolOnCode(std::unique_ptr ToolAction, const Twine &Code,
+  const Twine &FileName = "input.cc",
+  std::shared_ptr PCHContainerOps =
+  std::make_shared()) {
+  return runToolOnCode(ToolAction.release(), Code, FileName, PCHContainerOps);
+}
+
 /// The first part of the pair is the filename, the second part the
 /// file-content.
 using FileContentMappings = std::vector>;
@@ -186,6 +192,17 @@
 std::make_shared(),
 const FileContentMappings &VirtualMappedFiles = FileContentMappings());
 
+inline bool runToolOnCodeWithArgs(
+std::unique_ptr ToolAction, const Twine &Code,
+const std::vector &Args, const Twine &FileName = "input.cc",
+const Tw

[PATCH] D66960: [Tooling] Migrated APIs that take ownership of objects to unique_ptr

2019-08-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66960

Files:
  clang-tools-extra/clangd/unittests/IndexActionTests.cpp
  clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
  clang/include/clang/Tooling/Tooling.h
  clang/lib/Tooling/Tooling.cpp
  clang/unittests/AST/EvaluateAsRValueTest.cpp
  clang/unittests/AST/RecursiveASTVisitorTest.cpp
  clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
  clang/unittests/Index/IndexTests.cpp
  clang/unittests/Sema/CodeCompleteTest.cpp
  clang/unittests/Sema/ExternalSemaSourceTest.cpp
  clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp
  clang/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp
  clang/unittests/StaticAnalyzer/StoreTest.cpp
  clang/unittests/StaticAnalyzer/SymbolReaperTest.cpp
  clang/unittests/Tooling/CommentHandlerTest.cpp
  clang/unittests/Tooling/RefactoringTest.cpp
  clang/unittests/Tooling/TestVisitor.h
  clang/unittests/Tooling/ToolingTest.cpp

Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -62,10 +62,10 @@
 
 TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) {
   bool FoundTopLevelDecl = false;
-  EXPECT_TRUE(
-  runToolOnCode(new TestAction(std::make_unique(
-&FoundTopLevelDecl)),
-""));
+  EXPECT_TRUE(runToolOnCode(
+  std::make_unique(
+  std::make_unique(&FoundTopLevelDecl)),
+  ""));
   EXPECT_FALSE(FoundTopLevelDecl);
 }
 
@@ -102,17 +102,17 @@
 
 TEST(runToolOnCode, FindsClassDecl) {
   bool FoundClassDeclX = false;
-  EXPECT_TRUE(
-  runToolOnCode(new TestAction(std::make_unique(
-&FoundClassDeclX)),
-"class X;"));
+  EXPECT_TRUE(runToolOnCode(
+  std::make_unique(
+  std::make_unique(&FoundClassDeclX)),
+  "class X;"));
   EXPECT_TRUE(FoundClassDeclX);
 
   FoundClassDeclX = false;
-  EXPECT_TRUE(
-  runToolOnCode(new TestAction(std::make_unique(
-&FoundClassDeclX)),
-"class Y;"));
+  EXPECT_TRUE(runToolOnCode(
+  std::make_unique(
+  std::make_unique(&FoundClassDeclX)),
+  "class Y;"));
   EXPECT_FALSE(FoundClassDeclX);
 }
 
@@ -160,8 +160,8 @@
   Args.push_back("-Idef");
   Args.push_back("-fsyntax-only");
   Args.push_back("test.cpp");
-  clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction,
-Files.get());
+  clang::tooling::ToolInvocation Invocation(
+  Args, std::make_unique(), Files.get());
   InMemoryFileSystem->addFile(
   "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include \n"));
   InMemoryFileSystem->addFile("def/abc", 0,
@@ -186,8 +186,8 @@
   Args.push_back("-Idef");
   Args.push_back("-fsyntax-only");
   Args.push_back("test.cpp");
-  clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction,
-Files.get());
+  clang::tooling::ToolInvocation Invocation(
+  Args, std::make_unique(), Files.get());
   InMemoryFileSystem->addFile(
   "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include \n"));
   InMemoryFileSystem->addFile("def/abc", 0,
@@ -257,61 +257,61 @@
   std::vector Args = {"-std=c++11"};
   std::vector Args2 = {"-fno-delayed-template-parsing"};
 
-  EXPECT_TRUE(runToolOnCode(new SkipBodyAction,
+  EXPECT_TRUE(runToolOnCode(std::make_unique(),
 "int skipMe() { an_error_here }"));
-  EXPECT_FALSE(runToolOnCode(new SkipBodyAction,
+  EXPECT_FALSE(runToolOnCode(std::make_unique(),
  "int skipMeNot() { an_error_here }"));
 
   // Test constructors with initializers
   EXPECT_TRUE(runToolOnCodeWithArgs(
-  new SkipBodyAction,
+  std::make_unique(),
   "struct skipMe { skipMe() : an_error() { more error } };", Args));
   EXPECT_TRUE(runToolOnCodeWithArgs(
-  new SkipBodyAction, "struct skipMe { skipMe(); };"
+  std::make_unique(), "struct skipMe { skipMe(); };"
   "skipMe::skipMe() : an_error([](){;}) { more error }",
   Args));
   EXPECT_TRUE(runToolOnCodeWithArgs(
-  new SkipBodyAction, "struct skipMe { skipMe(); };"
+  std::make_unique(), "struct skipMe { skipMe(); };"
   "skipMe::skipMe() : an_error{[](){;}} { more error }",
   Args));
   EXPECT_TRUE(runToolOnCodeWithArgs(
-  new SkipBodyAction,
+  std::make_unique(),
   "struct skipMe { skipMe(); };"
   "skipMe::skipMe() : a(e)>>(), f{}, g() { error }",
   Args));
   EXPECT_TRUE(runToolOnCodeWithArgs(
-  new SkipBodyAction, "struct skipMe { skipMe() : bases()... { error } };",
+  std::make_unique(), "struct skipMe { skipMe() : bases()... { error } };",
  

[PATCH] D43779: [Tooling] [0/1] Refactor FrontendActionFactory::create() to return std::unique_ptr<>

2019-08-29 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri abandoned this revision.
lebedev.ri added a comment.
Herald added a project: LLVM.

Superseded by D66960 


Repository:
  rL LLVM

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

https://reviews.llvm.org/D43779



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


[PATCH] D66960: [Tooling] Migrated APIs that take ownership of objects to unique_ptr

2019-08-29 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

This is missing documentation changes.
And this likely would be good to mention in releasenotes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66960



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


[PATCH] D43780: [Tooling] [1/1] Refactor FrontendActionFactory::create() to return std::unique_ptr<>

2019-08-29 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri abandoned this revision.
lebedev.ri added a comment.
Herald added subscribers: kadircet, arphaman, jkorous.
Herald added a project: LLVM.

Superseded by D66960 


Repository:
  rL LLVM

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

https://reviews.llvm.org/D43780



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


r370383 - Added 'inline' to functions defined in headers to avoid ODR violations

2019-08-29 Thread Dmitri Gribenko via cfe-commits
Author: gribozavr
Date: Thu Aug 29 09:58:13 2019
New Revision: 370383

URL: http://llvm.org/viewvc/llvm-project?rev=370383&view=rev
Log:
Added 'inline' to functions defined in headers to avoid ODR violations

Modified:
cfe/trunk/unittests/CodeGen/IRMatchers.h

Modified: cfe/trunk/unittests/CodeGen/IRMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/CodeGen/IRMatchers.h?rev=370383&r1=370382&r2=370383&view=diff
==
--- cfe/trunk/unittests/CodeGen/IRMatchers.h (original)
+++ cfe/trunk/unittests/CodeGen/IRMatchers.h Thu Aug 29 09:58:13 2019
@@ -356,7 +356,7 @@ public:
 
 // Helper function used to construct matchers.
 
-std::shared_ptr MSameAs(unsigned N) {
+inline std::shared_ptr MSameAs(unsigned N) {
   return std::shared_ptr(new SameAsMatcher(N));
 }
 
@@ -367,36 +367,35 @@ std::shared_ptr MIns
   return std::shared_ptr(Result);
 }
 
-std::shared_ptr MConstInt(uint64_t V, unsigned W = 0) {
+inline std::shared_ptr MConstInt(uint64_t V, unsigned W = 0) {
   return std::shared_ptr(new ConstantIntMatcher(V, W));
 }
 
-std::shared_ptr>
- MValType(std::shared_ptr> T) {
+inline std::shared_ptr>
+MValType(std::shared_ptr> T) {
   return std::shared_ptr>(new ValueTypeMatcher(T));
 }
 
-std::shared_ptr> MValType(const Type *T) {
+inline std::shared_ptr> MValType(const Type *T) {
   return std::shared_ptr>(new ValueTypeMatcher(T));
 }
 
-std::shared_ptr>
+inline std::shared_ptr>
 MType(std::function C) {
   return std::shared_ptr>(new CondMatcher(C));
 }
 
-std::shared_ptr> MMAny() {
+inline std::shared_ptr> MMAny() {
   return std::shared_ptr>(new AnyMatcher);
 }
 
-std::shared_ptr>
+inline std::shared_ptr>
 MMSave(const Metadata *&V, std::shared_ptr> M) {
   return std::shared_ptr>(
   new SavingMatcher(V, M));
 }
 
-std::shared_ptr>
-MMString(const char *Name) {
+inline std::shared_ptr> MMString(const char *Name) {
   return std::shared_ptr>(new NameMetaMatcher(Name));
 }
 
@@ -413,7 +412,8 @@ std::shared_ptr>
 /// \returns Pointer to the found instruction or nullptr if such instruction
 ///  was not found.
 ///
-const Instruction *match(const BasicBlock *BB, std::shared_ptr M) {
+inline const Instruction *match(const BasicBlock *BB,
+std::shared_ptr M) {
   MatcherContext MC;
   for (const auto &I : *BB) {
 MC.push(&I);
@@ -425,13 +425,12 @@ const Instruction *match(const BasicBloc
   return nullptr;
 }
 
-
 /// Looks for the instruction that satisfies condition of the specified
 /// matcher starting from the specified instruction inside the same basic 
block.
 ///
 /// The given instruction is not checked.
 ///
-const Instruction *matchNext(const Instruction *I, std::shared_ptr M) 
{
+inline const Instruction *matchNext(const Instruction *I, 
std::shared_ptr M) {
   if (!I)
 return nullptr;
   MatcherContext MC;


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


[PATCH] D66947: Changed FrontendActionFactory::create to return a std::unique_ptr

2019-08-29 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Commented on wrong patch.

In D66960#1651198 , @lebedev.ri wrote:

> This is missing documentation changes.
>  And this likely would be good to mention in releasenotes.





Repository:
  rL LLVM

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

https://reviews.llvm.org/D66947



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


[PATCH] D66928: [clangd] Collecting main file macro expansion locations in ParsedAST.

2019-08-29 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom updated this revision to Diff 217920.
jvikstrom marked 4 inline comments as done.
jvikstrom added a comment.

Added test for prepending concatenations. Also added made tests pass.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66928

Files:
  clang-tools-extra/clangd/ClangdUnit.cpp
  clang-tools-extra/clangd/ClangdUnit.h
  clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp

Index: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
===
--- clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
+++ clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp
@@ -244,6 +244,49 @@
   EXPECT_EQ(T.expandedTokens().drop_back().back().text(SM), "}");
 }
 
+TEST(ClangdUnitTest, CollectsMainFileMacroExpansions) {
+  Annotations TestCase(R"cpp(
+#define MACRO_ARGS(X, Y) X Y
+^ID(int A);
+// Macro arguments included.
+^MACRO_ARGS(^MACRO_ARGS(^MACRO_EXP(int), A), ^ID(= 2));
+
+// Macro names inside other macros not included.
+#define FOO BAR
+#define BAR 1
+int A = ^FOO;
+
+// Macros from token concatenations not included.
+#define CONCAT(X) X##A()
+#define PREPEND(X) MACRO##X()
+#define MACROA() 123
+int B = ^CONCAT(MACRO);
+int D = ^PREPEND(A)
+
+// Macros included not from preamble not included.
+#include "foo.inc"
+  )cpp");
+  auto TU = TestTU::withCode(TestCase.code());
+  TU.HeaderCode = R"cpp(
+#define ID(X) X
+#define MACRO_EXP(X) ID(X)
+MACRO_EXP(int B);
+  )cpp";
+  TU.AdditionalFiles["foo.inc"] = R"cpp(
+int C = ID(1);
+#define DEF 1
+int D = DEF;
+  )cpp";
+  ParsedAST AST = TU.build();
+  const std::vector &MacroExpansionLocations =
+  AST.getMainFileExpansions();
+  std::vector MacroExpansionPositions;
+  for (const auto &L : MacroExpansionLocations)
+MacroExpansionPositions.push_back(
+sourceLocToPosition(AST.getSourceManager(), L));
+  EXPECT_EQ(MacroExpansionPositions, TestCase.points());
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/ClangdUnit.h
===
--- clang-tools-extra/clangd/ClangdUnit.h
+++ clang-tools-extra/clangd/ClangdUnit.h
@@ -116,6 +116,9 @@
   const IncludeStructure &getIncludeStructure() const;
   const CanonicalIncludes &getCanonicalIncludes() const;
 
+  /// The start locations of all macro expansions spelled inside the main file.
+  /// Does not include expansions from inside other macro expansions.
+  llvm::ArrayRef getMainFileExpansions() const;
   /// Tokens recorded while parsing the main file.
   /// (!) does not have tokens from the preamble.
   const syntax::TokenBuffer &getTokens() const { return Tokens; }
@@ -124,6 +127,7 @@
   ParsedAST(std::shared_ptr Preamble,
 std::unique_ptr Clang,
 std::unique_ptr Action, syntax::TokenBuffer Tokens,
+std::vector MainFileMacroExpLocs,
 std::vector LocalTopLevelDecls, std::vector Diags,
 IncludeStructure Includes, CanonicalIncludes CanonIncludes);
 
@@ -143,6 +147,9 @@
   ///   - Does not have spelled or expanded tokens for files from preamble.
   syntax::TokenBuffer Tokens;
 
+  /// The start locations of all macro expansions spelled inside the main file.
+  /// Does not include expansions from inside other macro expansions.
+  std::vector MainFileMacroExpLocs;
   // Data, stored after parsing.
   std::vector Diags;
   // Top-level decls inside the current file. Not that this does not include
Index: clang-tools-extra/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/clangd/ClangdUnit.cpp
+++ clang-tools-extra/clangd/ClangdUnit.cpp
@@ -22,6 +22,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Frontend/CompilerInstance.h"
@@ -32,6 +33,7 @@
 #include "clang/Index/IndexingAction.h"
 #include "clang/Lex/Lexer.h"
 #include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Sema/Sema.h"
@@ -103,6 +105,28 @@
   std::vector TopLevelDecls;
 };
 
+// CollectMainFileMacroExpansions and CollectMainFileMacros are two different
+// classes as CollectMainFileMacroExpansions is only used when building the AST
+// for the main file. CollectMainFileMacros is only used when building the
+// preamble.
+class CollectMainFileMacroExpansions : public PPCallbacks {
+  const SourceManager &SM;
+  std::vector &MainFileMacroLocs;
+
+public:
+  CollectMainFileMacroExpansions(const SourceManager &SM,
+ std::vector &MainFileMacroLocs)
+  : SM(SM

[PATCH] D66928: [clangd] Collecting main file macro expansion locations in ParsedAST.

2019-08-29 Thread Johan Vikström via Phabricator via cfe-commits
jvikstrom marked an inline comment as done.
jvikstrom added inline comments.



Comment at: clang-tools-extra/clangd/unittests/ClangdUnitTests.cpp:260
+// Macros from token concatenations included.
+#define CONCAT(X) X##1()
+#define MACRO1() 123

ilya-biryukov wrote:
> Could we also test?
> ```
> #define PREPEND(X) Foo##X
> ```
> 
> It'll probably be the same, but still interesting to see whether it's any 
> differnet.
So it turns out that the tests weren't actually passing before, must have 
accidentally forgot to save the file or something before compiling. Anyways 
tokens from concatenations are not included right now (which for highlighting 
is probably what we want, we don't highlight types/names that are from macro 
concatenations either)

But the reason they are not are because:
* They do not pass the `isInsideMainFile` check. Their file id is set to 
something that prints `` when dumped
* Even if they did pass the check the SourceLocation does not seem to be 
correct. They return the same SourceLocation as the parent `CONCAT` or `PREPEND`

Don't know how to fix any of this, and don't know if we actually want to 
collect these expansions either.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66928



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


[PATCH] D66862: Make lround builtin constexpr (and others)

2019-08-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

Small nit, just default construct the APFloats.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66862



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


[PATCH] D66960: [Tooling] Migrated APIs that take ownership of objects to unique_ptr

2019-08-29 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr added a comment.

In D66960#1651198 , @lebedev.ri wrote:

> This is missing documentation changes.


Could you point out such places? I tried to remove "takes ownership" comments 
which became redundant.

> And this likely would be good to mention in releasenotes.

Will add.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66960



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


[PATCH] D66919: Warn about zero-parameter K&R definitions in -Wstrict-prototypes

2019-08-29 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D66919#1651108 , @dexonsmith wrote:

> In D66919#1650775 , @aaron.ballman 
> wrote:
>
> > In D66919#1650174 , @dexonsmith 
> > wrote:
> >
> > > This could cause a lot of churn in existing projects (especially with 
> > > `static void foo()`), without giving Clang any new information.  I'm wary 
> > > of this.
> >
> >
> > Those projects likely aren't aware they're using prototypeless functions, 
> > which are trivial to call incorrectly. I suspect this diagnostic will find 
> > real bugs in code.
>
>
> To be clear, my understanding is that `-Wstrict-prototypes` already warns on 
> non-prototype declarations like this:
>
>   void foo();
>
>
> we just don't warn on non-prototype defining declarations, where the meaning 
> is unambiguous:
>
>   void foo() {}
>


There are two different warnings, and perhaps we're speaking about different 
ones. We have a warning about not having a prototype (warning: this function 
declaration is not a prototype) and we have a warning about not seeing a 
preceding prototype (warning: this old-style function definition is not 
preceded by a prototype). I think this patch deals with the latter.

>> It's not incorrect to pass arguments to a function without a prototype, so 
>> that should not be an error. It is incorrect to pass the wrong number or 
>> types of arguments to a function without a prototype. It's not a bad idea to 
>> error in that circumstances, but there's no solution for `extern void foo()` 
>> where we don't see the actual definition.
> 
> Given my understanding, then the only corner case that's left is when we *do* 
> see the definition.

Yeah, and we already handle that situation with an un-ignorable warning: 
https://godbolt.org/z/TPklNE

However, I think the inconsistency this patch is addressing is that we warn 
inconsistently here: https://godbolt.org/z/wvipEs I would expect the definition 
of `bar()` to warn similar to the definition of `foo()` for the same reasons 
that `foo()` is diagnosed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66919



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


[PATCH] D66960: [Tooling] Migrated APIs that take ownership of objects to unique_ptr

2019-08-29 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D66960#1651243 , @gribozavr wrote:

> In D66960#1651198 , @lebedev.ri 
> wrote:
>
> > This is missing documentation changes.
>
>
> Could you point out such places? I tried to remove "takes ownership" comments 
> which became redundant.


See my two original patches.

>> And this likely would be good to mention in releasenotes.
> 
> Will add.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66960



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


[PATCH] D66862: Make lround builtin constexpr (and others)

2019-08-29 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: clang/test/SemaCXX/math-builtins.cpp:5
+{
+  constexpr float f = 12345.6789;
+

Needs more tests
This looks like you always round up


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66862



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


[PATCH] D66862: Make lround builtin constexpr (and others)

2019-08-29 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

What if the input is nan or infinity or out of range. The spec says an 
implementation defined value is returned. But we've deferred to whatever 
library we're compiled with. Which makes our implementation defined behavior 
outside of clang's control and it now depends on how clang is built.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66862



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


[PATCH] D66862: Make lround builtin constexpr (and others)

2019-08-29 Thread Erich Keane via Phabricator via cfe-commits
erichkeane requested changes to this revision.
erichkeane added a comment.
This revision now requires changes to proceed.

Craig topper pointed out to me that constexpr cannot throw exceptions, and at 
least the rints can raise some exceptions, which aren't allowed in Constexpr.  
The round functions similarly hit unspecified behavior, so we need to match 
that behavior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66862



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


[PATCH] D66862: Make lround builtin constexpr (and others)

2019-08-29 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver added a comment.

(from IRC) Add tests for:

- out of range
- nan
- rounding up _and_ down

Also, use the builtin APFloat methods.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66862



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


[PATCH] D66964: Sort Java imports without newline

2019-08-29 Thread Yannic Bonenberger via Phabricator via cfe-commits
yannic created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D66964

Files:
  clang/unittests/Format/SortImportsTestJava.cpp


Index: clang/unittests/Format/SortImportsTestJava.cpp
===
--- clang/unittests/Format/SortImportsTestJava.cpp
+++ clang/unittests/Format/SortImportsTestJava.cpp
@@ -285,6 +285,25 @@
   sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.java").empty());
 }
 
+TEST_F(SortImportsTestJava, NoNewlineBetweenImports) {
+  EXPECT_EQ("import org.a;\n"
+"import org.b;",
+sort("import org.a;import org.b;"));
+  EXPECT_EQ("import org.a;\n"
+"import org.b;",
+sort("import org.b;import org.a;"));
+  EXPECT_EQ("import org.a;\n"
+"import org.b;\n"
+"import org.c",
+sort("import org.b;import org.a;\n"
+ "import org.c;"));
+  EXPECT_EQ("import org.a;\n"
+"import org.b;\n"
+"import org.c",
+sort("import org.c;\n"
+ "import org.b;import org.a;"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


Index: clang/unittests/Format/SortImportsTestJava.cpp
===
--- clang/unittests/Format/SortImportsTestJava.cpp
+++ clang/unittests/Format/SortImportsTestJava.cpp
@@ -285,6 +285,25 @@
   sortIncludes(FmtStyle, Code, GetCodeRange(Code), "input.java").empty());
 }
 
+TEST_F(SortImportsTestJava, NoNewlineBetweenImports) {
+  EXPECT_EQ("import org.a;\n"
+"import org.b;",
+sort("import org.a;import org.b;"));
+  EXPECT_EQ("import org.a;\n"
+"import org.b;",
+sort("import org.b;import org.a;"));
+  EXPECT_EQ("import org.a;\n"
+"import org.b;\n"
+"import org.c",
+sort("import org.b;import org.a;\n"
+ "import org.c;"));
+  EXPECT_EQ("import org.a;\n"
+"import org.b;\n"
+"import org.c",
+sort("import org.c;\n"
+ "import org.b;import org.a;"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66827: Add support for MS qualifiers __ptr32, __ptr64, __sptr, __uptr.

2019-08-29 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 217940.
akhuang marked 4 inline comments as done.
akhuang added a comment.

- Test that codegen adds the correct address spaces
- Modify microsoft mangling to match microsoft mangling.
- add comment for overloading


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66827

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/AddressSpaces.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/ms-mixed-ptr-sizes.c
  llvm/lib/Target/X86/X86.h
  llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/mixed-ptr-sizes.ll

Index: llvm/test/CodeGen/X86/mixed-ptr-sizes.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/mixed-ptr-sizes.ll
@@ -0,0 +1,110 @@
+; RUN: llc < %s | FileCheck --check-prefixes=CHECK %s
+
+; Source to regenerate:
+; struct Foo {
+;   int * __ptr32 p32;
+;   int * __ptr64 p64;
+; }
+; void test_sign_ext(struct Foo *f, int * __ptr32 i) {
+;   f->p64 = i;
+; }
+; void test_sign_ext2(struct Foo *f, int * __ptr32 __sptr i) {
+;   f->p64 = i;
+; }
+; void test_zero_ext(struct Foo *f, int * __ptr32 __uptr i) {
+;   f->p64 = i;
+; }
+; void test_trunc(struct Foo *f, int * __ptr64 i) {
+;   f->p32 = i;
+; }
+; void test_noop1(struct Foo *f, int * __ptr32 i) {
+;   f->p32 = i;
+; }
+; void test_noop2(struct Foo *f, int * __ptr64 i) {
+;   f->p64 = i;
+; }
+;
+; $ clang -cc1 -triple x86_64-windows-msvc -fms-extensions -O2 -emit-llvm -x c t.cpp
+
+; ModuleID = 't.cpp'
+source_filename = "t.cpp"
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-windows-msvc"
+
+%struct.Foo = type { i32 addrspace(270)*, i32* }
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_sign_ext(%struct.Foo* nocapture %f, i32 addrspace(270)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_sign_ext:
+; CHECK:   movslq %edx, %rax
+entry:
+  %0 = addrspacecast i32 addrspace(270)* %i to i32*
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %0, i32** %p64, align 8, !tbaa !2
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_sign_ext2(%struct.Foo* nocapture %f, i32 addrspace(270)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_sign_ext2:
+; CHECK:   movslq %edx, %rax
+entry:
+  %0 = addrspacecast i32 addrspace(270)* %i to i32*
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %0, i32** %p64, align 8, !tbaa !2
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_zero_ext(%struct.Foo* nocapture %f, i32 addrspace(271)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_zero_ext:
+; CHECK:   movl %edx, %eax
+entry:
+  %0 = addrspacecast i32 addrspace(271)* %i to i32*
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %0, i32** %p64, align 8, !tbaa !2
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_trunc(%struct.Foo* nocapture %f, i32* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_trunc:
+; CHECK:   movl %edx, (%rcx)
+entry:
+  %0 = addrspacecast i32* %i to i32 addrspace(270)*
+  %p32 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 0
+  store i32 addrspace(270)* %0, i32 addrspace(270)** %p32, align 8, !tbaa !7
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_noop1(%struct.Foo* nocapture %f, i32 addrspace(270)* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_noop1:
+; CHECK:   movl %edx, (%rcx)
+entry:
+  %p32 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 0
+  store i32 addrspace(270)* %i, i32 addrspace(270)** %p32, align 8, !tbaa !7
+  ret void
+}
+
+; Function Attrs: nofree norecurse nounwind writeonly
+define dso_local void @test_noop2(%struct.Foo* nocapture %f, i32* %i) local_unnamed_addr #0 {
+; CHECK-LABEL: test_noop2:
+; CHECK:   movq %rdx, 8(%rcx)
+entry:
+  %p64 = getelementptr inbounds %struct.Foo, %struct.Foo* %f, i64 0, i32 1
+  store i32* %i, i32** %p64, align 8, !tbaa !2
+  ret void
+}
+
+!llvm.module.flags = !{!0}
+!llvm.ident = !{!1}
+
+!0 = !{i32 1, !"wchar_size", i32 2}
+!1 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git b4887f121b485fb2b6d4c1fa8296724fb78a244d)"}
+!2 = !{!3, !4, i64 8}
+!3 = !{!"Foo", !4, i64 0, !4, i64 8}
+!4 = !{!"any pointer",

  1   2   >