[PATCH] D129973: [clang] Pass FoundDecl to DeclRefExpr creator for operator overloads

2022-07-29 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

In D129973#3688329 , @SimplyDanny 
wrote:

> In D129973#3684940 , @yvvan wrote:
>
>> With this change we don't pass "LocInfo" directly and it seems to break the 
>> locations when calling "getCXXOperatorNameRange" for this DeclRefExpr later 
>> on. Please fix it. You can introduce another "Create" static method for 
>> DeclRefExpr that accepts LocInfo and passes it to the DeclarationNameInfo 
>> constructor.
>
> Thank you for the hint! This indeed "fixes" the test references so that they 
> can be reverted to their original state. This is done in D130799 
> .
>
> Instead of a new `create` method or a new constructor (there are already 
> quite a lot of them with complex signatures), I created a 
> `DeclarationNameInfo` and passed it to one of the existing creators.

Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129973

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


[PATCH] D129973: [clang] Pass FoundDecl to DeclRefExpr creator for operator overloads

2022-07-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

With this change we don't pass "LocInfo" directly and it seems to break the 
locations when calling "getCXXOperatorNameRange" for this DeclRefExpr later on. 
Please fix it. You can introduce another "Create" static method for DeclRefExpr 
that accepts LocInfo and passes it to the DeclarationNameInfo constructor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129973

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


[PATCH] D81263: [Sema][CodeComplete][ObjC] Don't include arrow/dot fixits

2020-06-08 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

I'm not a big objC expert here. The idea looks fine to me and won't affect my 
workflow. So let's take this patch if nobody comments against it here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81263



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


[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2020-06-04 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@DmitryPolukhin Sorry, I didn't have time recently. Thanks a lot for taking 
care!


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63482



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


[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2020-05-06 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@mgehre I think we need to adjust `denormalize(const IO &)` method here to 
convert \n back properly. It seems I missed it in my patch.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63482



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


[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2020-05-04 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@mgehre From your comment it seems that `clang-apply-replacements` handles the 
YAML wrong and does not make the proper conversion back from "\n\n" to "\n"


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63482



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


[PATCH] D74564: libclang: Add static build support for Windows

2020-02-18 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan accepted this revision.
yvvan added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/include/clang-c/Platform.h:31
+#elif defined(CINDEX_EXPORTS)
+  #define CINDEX_LINKAGE __attribute__((visibility("default")))
+#endif

cristian.adam wrote:
> yvvan wrote:
> > Is it different from just leaving CINDEX_LINKAGE empty?
> On Windows the default symbol visibility is hidden and with CINDEX_LINKAGE we 
> make the symbols visible.
> 
> On Linux it's the other way around, everything is visible, but 
> with CMAKE_CXX_VISIBILITY_PRESET=hidden we will have the Windows behavior and 
> then we need to make CINDEX_LINKAGE point to something that will make the 
> symbols visible.
but this one happens only in non-Windows case (#elif) so it should not change 
anything I guess


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74564



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


[PATCH] D74564: libclang: Add static build support for Windows

2020-02-16 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Please, upload patches with context (-U).




Comment at: clang/include/clang-c/Platform.h:31
+#elif defined(CINDEX_EXPORTS)
+  #define CINDEX_LINKAGE __attribute__((visibility("default")))
+#endif

Is it different from just leaving CINDEX_LINKAGE empty?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74564



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


[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2019-07-03 Thread Ivan Donchevskii via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365017: [clang-tidy] Fix the YAML created for checks like 
modernize-pass-by-value (authored by yvvan, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63482?vs=207483=207747#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63482

Files:
  cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
  cfe/trunk/unittests/Tooling/ReplacementsYamlTest.cpp


Index: cfe/trunk/unittests/Tooling/ReplacementsYamlTest.cpp
===
--- cfe/trunk/unittests/Tooling/ReplacementsYamlTest.cpp
+++ cfe/trunk/unittests/Tooling/ReplacementsYamlTest.cpp
@@ -46,6 +46,30 @@
YamlContentStream.str().c_str());
 }
 
+TEST(ReplacementsYamlTest, serializesNewLines) {
+  TranslationUnitReplacements Doc;
+
+  Doc.MainSourceFile = "/path/to/source.cpp";
+  Doc.Replacements.emplace_back("/path/to/file1.h", 0, 0, "#include 
\n");
+
+  std::string YamlContent;
+  llvm::raw_string_ostream YamlContentStream(YamlContent);
+
+  yaml::Output YAML(YamlContentStream);
+  YAML << Doc;
+
+  // NOTE: If this test starts to fail for no obvious reason, check whitespace.
+  ASSERT_STREQ("---\n"
+   "MainSourceFile:  '/path/to/source.cpp'\n"
+   "Replacements:\n" // Extra whitespace here!
+   "  - FilePath:'/path/to/file1.h'\n"
+   "Offset:  0\n"
+   "Length:  0\n"
+   "ReplacementText: '#include \n\n'\n"
+   "...\n",
+   YamlContentStream.str().c_str());
+}
+
 TEST(ReplacementsYamlTest, deserializesReplacements) {
   std::string YamlContent = "---\n"
 "MainSourceFile:  /path/to/source.cpp\n"
Index: cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
===
--- cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
+++ cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
@@ -35,7 +35,13 @@
 
 NormalizedReplacement(const IO &, const clang::tooling::Replacement )
 : FilePath(R.getFilePath()), Offset(R.getOffset()),
-  Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
+  Length(R.getLength()), ReplacementText(R.getReplacementText()) {
+  size_t lineBreakPos = ReplacementText.find('\n');
+  while (lineBreakPos != std::string::npos) {
+ReplacementText.replace(lineBreakPos, 1, "\n\n");
+lineBreakPos = ReplacementText.find('\n', lineBreakPos + 2);
+  }
+}
 
 clang::tooling::Replacement denormalize(const IO &) {
   return clang::tooling::Replacement(FilePath, Offset, Length,


Index: cfe/trunk/unittests/Tooling/ReplacementsYamlTest.cpp
===
--- cfe/trunk/unittests/Tooling/ReplacementsYamlTest.cpp
+++ cfe/trunk/unittests/Tooling/ReplacementsYamlTest.cpp
@@ -46,6 +46,30 @@
YamlContentStream.str().c_str());
 }
 
+TEST(ReplacementsYamlTest, serializesNewLines) {
+  TranslationUnitReplacements Doc;
+
+  Doc.MainSourceFile = "/path/to/source.cpp";
+  Doc.Replacements.emplace_back("/path/to/file1.h", 0, 0, "#include \n");
+
+  std::string YamlContent;
+  llvm::raw_string_ostream YamlContentStream(YamlContent);
+
+  yaml::Output YAML(YamlContentStream);
+  YAML << Doc;
+
+  // NOTE: If this test starts to fail for no obvious reason, check whitespace.
+  ASSERT_STREQ("---\n"
+   "MainSourceFile:  '/path/to/source.cpp'\n"
+   "Replacements:\n" // Extra whitespace here!
+   "  - FilePath:'/path/to/file1.h'\n"
+   "Offset:  0\n"
+   "Length:  0\n"
+   "ReplacementText: '#include \n\n'\n"
+   "...\n",
+   YamlContentStream.str().c_str());
+}
+
 TEST(ReplacementsYamlTest, deserializesReplacements) {
   std::string YamlContent = "---\n"
 "MainSourceFile:  /path/to/source.cpp\n"
Index: cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
===
--- cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
+++ cfe/trunk/include/clang/Tooling/ReplacementsYaml.h
@@ -35,7 +35,13 @@
 
 NormalizedReplacement(const IO &, const clang::tooling::Replacement )
 : FilePath(R.getFilePath()), Offset(R.getOffset()),
-  Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
+  Length(R.getLength()), ReplacementText(R.getReplacementText()) {
+  size_t lineBreakPos = ReplacementText.find('\n');
+  while (lineBreakPos != std::string::npos) {
+ReplacementText.replace(lineBreakPos, 1, "\n\n");
+lineBreakPos = 

[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2019-07-03 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

ok, will do it through svn. i forgot that clang repo is called "cfe" so it's 
there


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

https://reviews.llvm.org/D63482



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


[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2019-07-03 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

This script does not seem to work properly on windows.


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

https://reviews.llvm.org/D63482



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


[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2019-07-03 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

I have a commit access but I don't understand how am I supposed to commit 
(haven't done that for a while). There's no clang svn repo anymore. Do you know 
what's the current state of repositories and where to commit?


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

https://reviews.llvm.org/D63482



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


[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2019-07-02 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 207483.

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

https://reviews.llvm.org/D63482

Files:
  clang/include/clang/Tooling/ReplacementsYaml.h
  clang/unittests/Tooling/ReplacementsYamlTest.cpp


Index: clang/unittests/Tooling/ReplacementsYamlTest.cpp
===
--- clang/unittests/Tooling/ReplacementsYamlTest.cpp
+++ clang/unittests/Tooling/ReplacementsYamlTest.cpp
@@ -46,6 +46,30 @@
YamlContentStream.str().c_str());
 }
 
+TEST(ReplacementsYamlTest, serializesNewLines) {
+  TranslationUnitReplacements Doc;
+
+  Doc.MainSourceFile = "/path/to/source.cpp";
+  Doc.Replacements.emplace_back("/path/to/file1.h", 0, 0, "#include 
\n");
+
+  std::string YamlContent;
+  llvm::raw_string_ostream YamlContentStream(YamlContent);
+
+  yaml::Output YAML(YamlContentStream);
+  YAML << Doc;
+
+  // NOTE: If this test starts to fail for no obvious reason, check whitespace.
+  ASSERT_STREQ("---\n"
+   "MainSourceFile:  '/path/to/source.cpp'\n"
+   "Replacements:\n" // Extra whitespace here!
+   "  - FilePath:'/path/to/file1.h'\n"
+   "Offset:  0\n"
+   "Length:  0\n"
+   "ReplacementText: '#include \n\n'\n"
+   "...\n",
+   YamlContentStream.str().c_str());
+}
+
 TEST(ReplacementsYamlTest, deserializesReplacements) {
   std::string YamlContent = "---\n"
 "MainSourceFile:  /path/to/source.cpp\n"
Index: clang/include/clang/Tooling/ReplacementsYaml.h
===
--- clang/include/clang/Tooling/ReplacementsYaml.h
+++ clang/include/clang/Tooling/ReplacementsYaml.h
@@ -35,7 +35,13 @@
 
 NormalizedReplacement(const IO &, const clang::tooling::Replacement )
 : FilePath(R.getFilePath()), Offset(R.getOffset()),
-  Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
+  Length(R.getLength()), ReplacementText(R.getReplacementText()) {
+  size_t lineBreakPos = ReplacementText.find('\n');
+  while (lineBreakPos != std::string::npos) {
+ReplacementText.replace(lineBreakPos, 1, "\n\n");
+lineBreakPos = ReplacementText.find('\n', lineBreakPos + 2);
+  }
+}
 
 clang::tooling::Replacement denormalize(const IO &) {
   return clang::tooling::Replacement(FilePath, Offset, Length,


Index: clang/unittests/Tooling/ReplacementsYamlTest.cpp
===
--- clang/unittests/Tooling/ReplacementsYamlTest.cpp
+++ clang/unittests/Tooling/ReplacementsYamlTest.cpp
@@ -46,6 +46,30 @@
YamlContentStream.str().c_str());
 }
 
+TEST(ReplacementsYamlTest, serializesNewLines) {
+  TranslationUnitReplacements Doc;
+
+  Doc.MainSourceFile = "/path/to/source.cpp";
+  Doc.Replacements.emplace_back("/path/to/file1.h", 0, 0, "#include \n");
+
+  std::string YamlContent;
+  llvm::raw_string_ostream YamlContentStream(YamlContent);
+
+  yaml::Output YAML(YamlContentStream);
+  YAML << Doc;
+
+  // NOTE: If this test starts to fail for no obvious reason, check whitespace.
+  ASSERT_STREQ("---\n"
+   "MainSourceFile:  '/path/to/source.cpp'\n"
+   "Replacements:\n" // Extra whitespace here!
+   "  - FilePath:'/path/to/file1.h'\n"
+   "Offset:  0\n"
+   "Length:  0\n"
+   "ReplacementText: '#include \n\n'\n"
+   "...\n",
+   YamlContentStream.str().c_str());
+}
+
 TEST(ReplacementsYamlTest, deserializesReplacements) {
   std::string YamlContent = "---\n"
 "MainSourceFile:  /path/to/source.cpp\n"
Index: clang/include/clang/Tooling/ReplacementsYaml.h
===
--- clang/include/clang/Tooling/ReplacementsYaml.h
+++ clang/include/clang/Tooling/ReplacementsYaml.h
@@ -35,7 +35,13 @@
 
 NormalizedReplacement(const IO &, const clang::tooling::Replacement )
 : FilePath(R.getFilePath()), Offset(R.getOffset()),
-  Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
+  Length(R.getLength()), ReplacementText(R.getReplacementText()) {
+  size_t lineBreakPos = ReplacementText.find('\n');
+  while (lineBreakPos != std::string::npos) {
+ReplacementText.replace(lineBreakPos, 1, "\n\n");
+lineBreakPos = ReplacementText.find('\n', lineBreakPos + 2);
+  }
+}
 
 clang::tooling::Replacement denormalize(const IO &) {
   return clang::tooling::Replacement(FilePath, Offset, Length,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2019-07-02 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan marked an inline comment as done.
yvvan added inline comments.



Comment at: clang/include/clang/Tooling/ReplacementsYaml.h:35
+: FilePath(""), Offset(0), Length(0), ReplacementText("") {
+  size_t lineBreakPos = ReplacementText.find('\n');
+  while (lineBreakPos != std::string::npos) {

gribozavr wrote:
> yvvan wrote:
> > gribozavr wrote:
> > > Sorry, I don't understand how this works -- ReplacementText does not 
> > > contain a \n, so lineBreakPos will be npos, and the loop below will not 
> > > execute...
> > Quite opposite. This patch targets the cases where it's not npos (see the 
> > test example). So it has a line break and this line break should be 
> > transformed into two line breaks.
> What I'm saying that in this constructor RelpcamentText is an empty string, 
> always, and therefore it does not contain a \n.
Ah, yes, my fault. I've generated the wrong diff. Thanks, will update it soon.


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

https://reviews.llvm.org/D63482



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


[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2019-07-01 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan marked an inline comment as done.
yvvan added inline comments.



Comment at: clang/include/clang/Tooling/ReplacementsYaml.h:35
+: FilePath(""), Offset(0), Length(0), ReplacementText("") {
+  size_t lineBreakPos = ReplacementText.find('\n');
+  while (lineBreakPos != std::string::npos) {

gribozavr wrote:
> Sorry, I don't understand how this works -- ReplacementText does not contain 
> a \n, so lineBreakPos will be npos, and the loop below will not execute...
Quite opposite. This patch targets the cases where it's not npos (see the test 
example). So it has a line break and this line break should be transformed into 
two line breaks.


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

https://reviews.llvm.org/D63482



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


[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2019-06-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 207062.
yvvan added a comment.

Sorry for delay.
Test added, redundant comments removed.


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

https://reviews.llvm.org/D63482

Files:
  clang/include/clang/Tooling/ReplacementsYaml.h
  clang/unittests/Tooling/ReplacementsYamlTest.cpp


Index: clang/unittests/Tooling/ReplacementsYamlTest.cpp
===
--- clang/unittests/Tooling/ReplacementsYamlTest.cpp
+++ clang/unittests/Tooling/ReplacementsYamlTest.cpp
@@ -46,6 +46,30 @@
YamlContentStream.str().c_str());
 }
 
+TEST(ReplacementsYamlTest, serializesNewLines) {
+  TranslationUnitReplacements Doc;
+
+  Doc.MainSourceFile = "/path/to/source.cpp";
+  Doc.Replacements.emplace_back("/path/to/file1.h", 0, 0, "#include 
\n");
+
+  std::string YamlContent;
+  llvm::raw_string_ostream YamlContentStream(YamlContent);
+
+  yaml::Output YAML(YamlContentStream);
+  YAML << Doc;
+
+  // NOTE: If this test starts to fail for no obvious reason, check whitespace.
+  ASSERT_STREQ("---\n"
+   "MainSourceFile:  '/path/to/source.cpp'\n"
+   "Replacements:\n" // Extra whitespace here!
+   "  - FilePath:'/path/to/file1.h'\n"
+   "Offset:  0\n"
+   "Length:  0\n"
+   "ReplacementText: '#include \n\n'\n"
+   "...\n",
+   YamlContentStream.str().c_str());
+}
+
 TEST(ReplacementsYamlTest, deserializesReplacements) {
   std::string YamlContent = "---\n"
 "MainSourceFile:  /path/to/source.cpp\n"
Index: clang/include/clang/Tooling/ReplacementsYaml.h
===
--- clang/include/clang/Tooling/ReplacementsYaml.h
+++ clang/include/clang/Tooling/ReplacementsYaml.h
@@ -31,7 +31,13 @@
   /// access to its data members.
   struct NormalizedReplacement {
 NormalizedReplacement(const IO &)
-: FilePath(""), Offset(0), Length(0), ReplacementText("") {}
+: FilePath(""), Offset(0), Length(0), ReplacementText("") {
+  size_t lineBreakPos = ReplacementText.find('\n');
+  while (lineBreakPos != std::string::npos) {
+ReplacementText.replace(lineBreakPos, 1, "\n\n");
+lineBreakPos = ReplacementText.find('\n', lineBreakPos + 2);
+  }
+}
 
 NormalizedReplacement(const IO &, const clang::tooling::Replacement )
 : FilePath(R.getFilePath()), Offset(R.getOffset()),


Index: clang/unittests/Tooling/ReplacementsYamlTest.cpp
===
--- clang/unittests/Tooling/ReplacementsYamlTest.cpp
+++ clang/unittests/Tooling/ReplacementsYamlTest.cpp
@@ -46,6 +46,30 @@
YamlContentStream.str().c_str());
 }
 
+TEST(ReplacementsYamlTest, serializesNewLines) {
+  TranslationUnitReplacements Doc;
+
+  Doc.MainSourceFile = "/path/to/source.cpp";
+  Doc.Replacements.emplace_back("/path/to/file1.h", 0, 0, "#include \n");
+
+  std::string YamlContent;
+  llvm::raw_string_ostream YamlContentStream(YamlContent);
+
+  yaml::Output YAML(YamlContentStream);
+  YAML << Doc;
+
+  // NOTE: If this test starts to fail for no obvious reason, check whitespace.
+  ASSERT_STREQ("---\n"
+   "MainSourceFile:  '/path/to/source.cpp'\n"
+   "Replacements:\n" // Extra whitespace here!
+   "  - FilePath:'/path/to/file1.h'\n"
+   "Offset:  0\n"
+   "Length:  0\n"
+   "ReplacementText: '#include \n\n'\n"
+   "...\n",
+   YamlContentStream.str().c_str());
+}
+
 TEST(ReplacementsYamlTest, deserializesReplacements) {
   std::string YamlContent = "---\n"
 "MainSourceFile:  /path/to/source.cpp\n"
Index: clang/include/clang/Tooling/ReplacementsYaml.h
===
--- clang/include/clang/Tooling/ReplacementsYaml.h
+++ clang/include/clang/Tooling/ReplacementsYaml.h
@@ -31,7 +31,13 @@
   /// access to its data members.
   struct NormalizedReplacement {
 NormalizedReplacement(const IO &)
-: FilePath(""), Offset(0), Length(0), ReplacementText("") {}
+: FilePath(""), Offset(0), Length(0), ReplacementText("") {
+  size_t lineBreakPos = ReplacementText.find('\n');
+  while (lineBreakPos != std::string::npos) {
+ReplacementText.replace(lineBreakPos, 1, "\n\n");
+lineBreakPos = ReplacementText.find('\n', lineBreakPos + 2);
+  }
+}
 
 NormalizedReplacement(const IO &, const clang::tooling::Replacement )
 : FilePath(R.getFilePath()), Offset(R.getOffset()),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

2019-06-18 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: gribozavr, nik.
Herald added a subscriber: xazax.hun.

Currently this check generates the replacement with the newline in the end. The 
proper way to export it to YAML is to have two \n\n instead of one.

Without this fix clients should reinterpret the replacement as "#include 
 " instead of "#include \n"


https://reviews.llvm.org/D63482

Files:
  clang/include/clang/Tooling/ReplacementsYaml.h


Index: clang/include/clang/Tooling/ReplacementsYaml.h
===
--- clang/include/clang/Tooling/ReplacementsYaml.h
+++ clang/include/clang/Tooling/ReplacementsYaml.h
@@ -35,7 +35,15 @@
 
 NormalizedReplacement(const IO &, const clang::tooling::Replacement )
 : FilePath(R.getFilePath()), Offset(R.getOffset()),
-  Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
+  Length(R.getLength()), ReplacementText(R.getReplacementText()) {
+  size_t lineBreakPos = ReplacementText.find('\n');
+  while (lineBreakPos != std::string::npos) {
+// Replace this occurrence of Sub String
+ReplacementText.replace(lineBreakPos, 1, "\n\n");
+// Get the next occurrence from the current position
+lineBreakPos = ReplacementText.find('\n', lineBreakPos + 2);
+  }
+}
 
 clang::tooling::Replacement denormalize(const IO &) {
   return clang::tooling::Replacement(FilePath, Offset, Length,


Index: clang/include/clang/Tooling/ReplacementsYaml.h
===
--- clang/include/clang/Tooling/ReplacementsYaml.h
+++ clang/include/clang/Tooling/ReplacementsYaml.h
@@ -35,7 +35,15 @@
 
 NormalizedReplacement(const IO &, const clang::tooling::Replacement )
 : FilePath(R.getFilePath()), Offset(R.getOffset()),
-  Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
+  Length(R.getLength()), ReplacementText(R.getReplacementText()) {
+  size_t lineBreakPos = ReplacementText.find('\n');
+  while (lineBreakPos != std::string::npos) {
+// Replace this occurrence of Sub String
+ReplacementText.replace(lineBreakPos, 1, "\n\n");
+// Get the next occurrence from the current position
+lineBreakPos = ReplacementText.find('\n', lineBreakPos + 2);
+  }
+}
 
 clang::tooling::Replacement denormalize(const IO &) {
   return clang::tooling::Replacement(FilePath, Offset, Length,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D48116: [libclang] Allow skipping warnings from all included files

2019-06-05 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan accepted this revision.
yvvan added a comment.
This revision is now accepted and ready to land.

libclang part is quite small here and looks ok. I would just accept it


Repository:
  rC Clang

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

https://reviews.llvm.org/D48116



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


[PATCH] D53072: [clang-format] Create a new tool for IDEs based on clang-format

2019-05-11 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 199151.
yvvan added a comment.

Some misleading reformatting fixed.


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

https://reviews.llvm.org/D53072

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatInternal.h
  clang/lib/Format/TokenAnalyzer.cpp
  clang/lib/Format/TokenAnalyzer.h
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineFormatter.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -35,15 +35,16 @@
 SC_DoNotCheck
   };
 
-  std::string format(llvm::StringRef Code,
- const FormatStyle  = getLLVMStyle(),
- StatusCheck CheckComplete = SC_ExpectComplete) {
+  std::string
+  format(llvm::StringRef Code, const FormatStyle  = getLLVMStyle(),
+ StatusCheck CheckComplete = SC_ExpectComplete,
+ ExtraFormattingOptions ExtraOptions = ExtraFormattingOptions::None) {
 LLVM_DEBUG(llvm::errs() << "---\n");
 LLVM_DEBUG(llvm::errs() << Code << "\n\n");
 std::vector Ranges(1, tooling::Range(0, Code.size()));
 FormattingAttemptStatus Status;
 tooling::Replacements Replaces =
-reformat(Style, Code, Ranges, "", );
+reformat(Style, ExtraOptions, Code, Ranges, "", );
 if (CheckComplete != SC_DoNotCheck) {
   bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
   EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
@@ -395,6 +396,25 @@
Style));
 }
 
+TEST_F(FormatTest, KeepsLineBreaks) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ("if (a\n"
+"&& b) {\n"
+"}",
+format("if (a\n"
+   "&& b) {\n"
+   "}",
+   Style, SC_ExpectComplete,
+   ExtraFormattingOptions::KeepLineBreaksForNonEmptyLines));
+
+  EXPECT_EQ("[]() {\n"
+"  foo(); }",
+format("[]() {\n"
+   "foo(); }",
+   Style, SC_ExpectComplete,
+   ExtraFormattingOptions::KeepLineBreaksForNonEmptyLines));
+}
+
 TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) {
   verifyFormat("x = (a) and (b);");
   verifyFormat("x = (a) or (b);");
Index: clang/tools/clang-format/ClangFormat.cpp
===
--- clang/tools/clang-format/ClangFormat.cpp
+++ clang/tools/clang-format/ClangFormat.cpp
@@ -51,13 +51,14 @@
  "Can only be used with one input file."),
 cl::cat(ClangFormatCategory));
 static cl::list
-LineRanges("lines", cl::desc(": - format a range of\n"
- "lines (both 1-based).\n"
- "Multiple ranges can be formatted by specifying\n"
- "several -lines arguments.\n"
- "Can't be used with -offset and -length.\n"
- "Can only be used with one input file."),
-   cl::cat(ClangFormatCategory));
+LineRanges("lines",
+   cl::desc(": - format a range of\n"
+"lines (both 1-based).\n"
+"Multiple ranges can be formatted by specifying\n"
+"several -lines arguments.\n"
+"Can't be used with -offset and -length.\n"
+"Can only be used with one input file."),
+   cl::cat(ClangFormatCategory));
 static cl::opt
 Style("style", cl::desc(clang::format::StyleOptionHelpDescription),
   cl::init(clang::format::DefaultFormatStyle),
@@ -72,12 +73,12 @@
   cl::init(clang::format::DefaultFallbackStyle),
   cl::cat(ClangFormatCategory));
 
-static cl::opt
-AssumeFileName("assume-filename",
-   cl::desc("When reading from stdin, clang-format assumes this\n"
-"filename to look for a style config file (with\n"
-"-style=file) and to determine the language."),
-   cl::init(""), cl::cat(ClangFormatCategory));
+static cl::opt AssumeFileName(
+"assume-filename",
+cl::desc("When reading from stdin, clang-format assumes this\n"
+ "filename to look for a style config file (with\n"
+ "-style=file) and to determine the language."),
+cl::init(""), cl::cat(ClangFormatCategory));
 
 static cl::opt Inplace("i",
  cl::desc("Inplace edit s, if specified."),
@@ -107,6 +108,11 @@
 Verbose("verbose", cl::desc("If set, shows the list of processed files"),
  

[PATCH] D53072: [clang-format] Create a new tool for IDEs based on clang-format

2019-05-11 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 199150.
yvvan added a comment.

Sorry for unrelated formatting changes - that's clang-format's work :)

I've removed the extra executable.

I don't know how to force that behavior only for the given line (for that I 
need someone who can help) but in our usecase we should not care if we apply 
the rule to the whole file or only to the current line since we are only 
interested in one single Replacement which we can anyways filter afterwards.


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

https://reviews.llvm.org/D53072

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatInternal.h
  clang/lib/Format/TokenAnalyzer.cpp
  clang/lib/Format/TokenAnalyzer.h
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineFormatter.h
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -29,21 +29,18 @@
 
 class FormatTest : public ::testing::Test {
 protected:
-  enum StatusCheck {
-SC_ExpectComplete,
-SC_ExpectIncomplete,
-SC_DoNotCheck
-  };
+  enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
 
-  std::string format(llvm::StringRef Code,
- const FormatStyle  = getLLVMStyle(),
- StatusCheck CheckComplete = SC_ExpectComplete) {
+  std::string
+  format(llvm::StringRef Code, const FormatStyle  = getLLVMStyle(),
+ StatusCheck CheckComplete = SC_ExpectComplete,
+ ExtraFormattingOptions ExtraOptions = ExtraFormattingOptions::None) {
 LLVM_DEBUG(llvm::errs() << "---\n");
 LLVM_DEBUG(llvm::errs() << Code << "\n\n");
 std::vector Ranges(1, tooling::Range(0, Code.size()));
 FormattingAttemptStatus Status;
 tooling::Replacements Replaces =
-reformat(Style, Code, Ranges, "", );
+reformat(Style, ExtraOptions, Code, Ranges, "", );
 if (CheckComplete != SC_DoNotCheck) {
   bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
   EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
@@ -332,13 +329,15 @@
 format("namespace {\n"
"int i;\n"
"\n"
-   "}", LLVMWithNoNamespaceFix));
+   "}",
+   LLVMWithNoNamespaceFix));
   EXPECT_EQ("namespace {\n"
 "int i;\n"
 "}",
 format("namespace {\n"
"int i;\n"
-   "}", LLVMWithNoNamespaceFix));
+   "}",
+   LLVMWithNoNamespaceFix));
   EXPECT_EQ("namespace {\n"
 "int i;\n"
 "\n"
@@ -346,13 +345,15 @@
 format("namespace {\n"
"int i;\n"
"\n"
-   "};", LLVMWithNoNamespaceFix));
+   "};",
+   LLVMWithNoNamespaceFix));
   EXPECT_EQ("namespace {\n"
 "int i;\n"
 "};",
 format("namespace {\n"
"int i;\n"
-   "};", LLVMWithNoNamespaceFix));
+   "};",
+   LLVMWithNoNamespaceFix));
   EXPECT_EQ("namespace {\n"
 "int i;\n"
 "\n"
@@ -395,6 +396,25 @@
Style));
 }
 
+TEST_F(FormatTest, KeepsLineBreaks) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ("if (a\n"
+"&& b) {\n"
+"}",
+format("if (a\n"
+   "&& b) {\n"
+   "}",
+   Style, SC_ExpectComplete,
+   ExtraFormattingOptions::KeepLineBreaksForNonEmptyLines));
+
+  EXPECT_EQ("[]() {\n"
+"  foo(); }",
+format("[]() {\n"
+   "foo(); }",
+   Style, SC_ExpectComplete,
+   ExtraFormattingOptions::KeepLineBreaksForNonEmptyLines));
+}
+
 TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) {
   verifyFormat("x = (a) and (b);");
   verifyFormat("x = (a) or (b);");
@@ -854,7 +874,8 @@
   verifyFormat("for (Foo *x = 0; x != in; x++) {\n}");
   verifyFormat("Foo *x;\nfor (x = 0; x != in; x++) {\n}");
   verifyFormat("Foo *x;\nfor (x in y) {\n}");
-  verifyFormat("for (const Foo  = in.value(); !baz.at_end(); ++baz) {\n}");
+  verifyFormat(
+  "for (const Foo  = in.value(); !baz.at_end(); ++baz) {\n}");
 
   FormatStyle NoBinPacking = getLLVMStyle();
   NoBinPacking.BinPackParameters = false;
@@ -1246,20 +1267,26 @@
"#endif\n"
"}",
Style));
-  EXPECT_EQ("switch (a) {\n" "case 0:\n"
-"  return; // long long long long long 

[PATCH] D53072: [clang-format] Create a new tool for IDEs based on clang-format

2019-05-11 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@sammccall 
I can't avoid adding extra formatting options because my first attempt to 
introduce an ordinary clang-format option faced resistance because of not 
fitting the clang-format purpose to format files.


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

https://reviews.llvm.org/D53072



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


[PATCH] D53072: [clang-format] Create a new tool for IDEs based on clang-format

2019-05-09 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

In D53072#1496317 , @sammccall wrote:

> My feedback would be:
>
> - I definitely think more control over preserving line breaks would be 
> useful. Actually preserving *blank* lines is an important property. If you 
> see D60605 , there are a lot of cases where 
> clang-format wants to delete the line you just added. Maybe we can make 
> `MaxEmptyLinesToKeep: 999` work in more cases.
> - I'm not convinced you need/want to preserve *all* line breaks, isn't it 
> just one? (where the user pressed enter)
> - It's unclear why "extraformattingoptions" is needed, rather than just the 
> usual formatting options, or some other parameter. It would be nice to avoid 
> a new library entry point (overload) if possible.
> - as far as command-line interface goes, this definitely feels more like a 
> flag than a new tool


Thanks for the feedback!
'to preserve *all* line breaks, isn't it just one' - it's just much easier code 
wise, you don't need to take the current position into account. I can look how 
I can make it for only one line.
'unclear why "extraformattingoptions" is needed' - the idea behind is that we 
can add more ide-specific options later without introducing new reformat 
parameters.
I will definitely remove a separate tool, it seems nobody sees the need of such 
thing.


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

https://reviews.llvm.org/D53072



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


[PATCH] D53072: [clang-format] Create a new tool for IDEs based on clang-format

2019-05-09 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@ilya-biryukov
I don't really care how it's used from the tool side. I'm also fine to have a 
new option in clang-format itself. That's why this review is here - to ask for 
opinions. It's easy to remove that "ide" part from this patch and just add an 
option for clang-format instead.
Do you have any other remarks/concerns apart from that?


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

https://reviews.llvm.org/D53072



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


[PATCH] D60605: [clangd] Revamp textDocument/onTypeFormatting.

2019-05-08 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@ilya-biryukov 
What do you think about D53072 ? It can be 
polished and combined with this change removing some code from here (which I 
assume is a good thing).
The idea there is that clang-format knows that it's not allowed to remove new 
lines and it always marks them with MustBreakBefore.
I'm not sure if anybody needs an executable but I think it's not a big deal to 
have an extra reformat() function.

It is also safe because it was the only way I found which does not break the 
code style like, for instance, adding comment block to the end of the previous 
line.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D60605



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


[PATCH] D60678: [libclang] Forward isInline for NamespaceDecl to libclang

2019-05-03 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Seems so.


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

https://reviews.llvm.org/D60678



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


[PATCH] D61232: [libclang] Restore old clang_Cursor_isAnonymous behaviour

2019-04-29 Thread Ivan Donchevskii via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL359448: [libclang] Restore old clang_Cursor_isAnonymous 
behaviour (authored by yvvan, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61232?vs=197038=197103#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61232

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/test/Index/print-type.c
  cfe/trunk/tools/c-index-test/c-index-test.c
  cfe/trunk/tools/libclang/CXType.cpp

Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 55
+#define CINDEX_VERSION_MINOR 56
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
   ((major) * 1)   \
@@ -3921,10 +3921,16 @@
 CINDEX_LINKAGE long long clang_Cursor_getOffsetOfField(CXCursor C);
 
 /**
+ * Determine whether the given cursor represents an anonymous
+ * tag or namespace
+ */
+CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
+
+/**
  * Determine whether the given cursor represents an anonymous record
  * declaration.
  */
-CINDEX_LINKAGE unsigned clang_Cursor_isAnonymous(CXCursor C);
+CINDEX_LINKAGE unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C);
 
 enum CXRefQualifierKind {
   /** No ref-qualifier was provided. */
Index: cfe/trunk/test/Index/print-type.c
===
--- cfe/trunk/test/Index/print-type.c
+++ cfe/trunk/test/Index/print-type.c
@@ -15,6 +15,20 @@
 enum Enum{i}; enum Enum elaboratedEnumType();
 struct Struct{}; struct Struct elaboratedStructType();
 
+struct {
+  int x;
+  int y;
+} foo;
+
+struct {
+  struct {
+int x;
+int y;
+  };
+} bar;
+
+void fun(struct { int x; int y; } *param);
+
 // RUN: c-index-test -test-print-type %s | FileCheck %s
 // CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, int *, void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] [resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] [Pointer] [FooType] [Typedef] [int [5]] [ConstantArray] [void (*)(int)] [Pointer]] [isPOD=0]
 // CHECK: ParmDecl=p:3:13 (Definition) [type=int *] [typekind=Pointer] [isPOD=1] [pointeetype=int] [pointeekind=Int]
@@ -53,3 +67,7 @@
 // CHECK: StructDecl=Struct:16:8 (Definition) [type=struct Struct] [typekind=Record] [isPOD=1]
 // CHECK: FunctionDecl=elaboratedStructType:16:32 [type=struct Struct ()] [typekind=FunctionNoProto] [canonicaltype=struct Struct ()] [canonicaltypekind=FunctionNoProto] [resulttype=struct Struct] [resulttypekind=Elaborated] [isPOD=0]
 // CHECK: TypeRef=struct Struct:16:8 [type=struct Struct] [typekind=Record] [isPOD=1]
+// CHECK: StructDecl=:18:1 (Definition) [type=struct (anonymous at {{.*}}print-type.c:18:1)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=0]
+// CHECK: StructDecl=:23:1 (Definition) [type=struct (anonymous at {{.*}}print-type.c:23:1)] [typekind=Record] [isPOD=1] [nbFields=1] [isAnon=1] [isAnonRecDecl=0]
+// CHECK: StructDecl=:24:3 (Definition) [type=struct (anonymous at {{.*}}print-type.c:24:3)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=1]
+// CHECK: StructDecl=:30:10 (Definition) [type=struct (anonymous at {{.*}}print-type.c:30:10)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=0]
Index: cfe/trunk/tools/libclang/CXType.cpp
===
--- cfe/trunk/tools/libclang/CXType.cpp
+++ cfe/trunk/tools/libclang/CXType.cpp
@@ -1253,6 +1253,16 @@
 
   return 0;
 }
+
+unsigned clang_Cursor_isAnonymousRecordDecl(CXCursor C){
+  if (!clang_isDeclaration(C.kind))
+return 0;
+  const Decl *D = cxcursor::getCursorDecl(C);
+  if (const RecordDecl *FD = dyn_cast_or_null(D))
+return FD->isAnonymousStructOrUnion();
+  return 0;
+}
+
 CXType clang_Type_getNamedType(CXType CT){
   QualType T = GetQualType(CT);
   const Type *TP = T.getTypePtrOrNull();
Index: cfe/trunk/tools/c-index-test/c-index-test.c
===
--- cfe/trunk/tools/c-index-test/c-index-test.c
+++ cfe/trunk/tools/c-index-test/c-index-test.c
@@ -1665,6 +1665,12 @@
   }
 }
 
+/* Print if it is an anonymous record decl */
+{
+  unsigned isAnonRecDecl = clang_Cursor_isAnonymousRecordDecl(cursor);
+  printf(" [isAnonRecDecl=%d]", isAnonRecDecl);
+}
+
 printf("\n");
   }
   return CXChildVisit_Recurse;
___
cfe-commits mailing list

[PATCH] D61232: [libclang] Restore old clang_Cursor_isAnonymous behaviour

2019-04-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Thank you! Sorry that I forgot about the required minor version increment.
I will run tests tomorrow and then I can commit it for you.




Comment at: include/clang-c/Index.h:35
 #define CINDEX_VERSION_MAJOR 0
 #define CINDEX_VERSION_MINOR 55
 

We also need to increment the minor version because of the new function added.


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

https://reviews.llvm.org/D61232



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


[PATCH] D61232: [libclang] Restore old clang_Cursor_isAnonymous behaviour

2019-04-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Could you please also upload diff with the full context? It's -U for git 
and quite similar for svn.
Otherwise looks ok.




Comment at: test/Index/print-type.c:70
 // CHECK: TypeRef=struct Struct:16:8 [type=struct Struct] [typekind=Record] 
[isPOD=1]
+// CHECK: StructDecl=:18:1 (Definition) [type=struct (anonymous at 
.\test\Index\print-type.c:18:1)] [typekind=Record] [isPOD=1] [nbFields=2] 
[isAnon=1] [isAnonRecDecl=0]
+// CHECK: StructDecl=:23:1 (Definition) [type=struct (anonymous at 
.\test\Index\print-type.c:23:1)] [typekind=Record] [isPOD=1] [nbFields=1] 
[isAnon=1] [isAnonRecDecl=0]

The path will be different depending on the machine and OS. You can 
{{.*}}print-type.cpp instead (like in https://reviews.llvm.org/D54996).


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

https://reviews.llvm.org/D61232



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


[PATCH] D61232: [libclang] Restore old clang_Cursor_isAnonymous behaviour

2019-04-27 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Now we know that somebody else also uses libclang :)
I the mentioned change I only wanted to follow the same logic as in 
TypePrinter::printTag to cover more anonymity cases.

Adding the old one as an extra function seems totally fine to me.  Can you 
please add some tests for it to clarify the purpose for future users?


Repository:
  rC Clang

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

https://reviews.llvm.org/D61232



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


[PATCH] D53072: [clang-format] Create a new tool for IDEs based on clang-format

2019-04-25 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@sammccall

Having a separate tool is nice because it allows the client to make it 
plugable. clang-format sometimes changes options quite significantly and it can 
be nice if you have a choice which version to pick, otherwise it might be 
unable to read the configuration you have.


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

https://reviews.llvm.org/D53072



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


[PATCH] D53072: [clang-format] Create a new tool for IDEs based on clang-format

2019-04-12 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 194844.
yvvan retitled this revision from "[clang-format] Introduce the flag which 
allows not to shrink lines" to "[clang-format] Create a new tool for IDEs based 
on clang-format".
yvvan edited the summary of this revision.
yvvan added a reviewer: arphaman.
yvvan added a comment.
Herald added subscribers: dexonsmith, mgorny.

New approach - title and summary are updated.


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

https://reviews.llvm.org/D53072

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatInternal.h
  lib/Format/TokenAnalyzer.cpp
  lib/Format/TokenAnalyzer.h
  lib/Format/UnwrappedLineFormatter.cpp
  lib/Format/UnwrappedLineFormatter.h
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  tools/CMakeLists.txt
  tools/clang-format-ide/CMakeLists.txt
  tools/clang-format-ide/ClangFormatIDE.cpp
  tools/clang-format/ClangFormat.cpp
  tools/clang-format/ClangFormat.h
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -35,15 +35,16 @@
 SC_DoNotCheck
   };
 
-  std::string format(llvm::StringRef Code,
- const FormatStyle  = getLLVMStyle(),
- StatusCheck CheckComplete = SC_ExpectComplete) {
+  std::string format(
+  llvm::StringRef Code, const FormatStyle  = getLLVMStyle(),
+  StatusCheck CheckComplete = SC_ExpectComplete,
+  ExtraFormattingOptions FormattingOptions = ExtraFormattingOptions::None) {
 LLVM_DEBUG(llvm::errs() << "---\n");
 LLVM_DEBUG(llvm::errs() << Code << "\n\n");
 std::vector Ranges(1, tooling::Range(0, Code.size()));
 FormattingAttemptStatus Status;
 tooling::Replacements Replaces =
-reformat(Style, Code, Ranges, "", );
+reformat(Style, FormattingOptions, Code, Ranges, "", );
 if (CheckComplete != SC_DoNotCheck) {
   bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
   EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
@@ -395,6 +396,25 @@
Style));
 }
 
+TEST_F(FormatTest, KeepsLineBreaks) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ("if (a\n"
+"&& b) {\n"
+"}",
+format("if (a\n"
+   "&& b) {\n"
+   "}",
+   Style, SC_ExpectComplete,
+   ExtraFormattingOptions::KeepLineBreaksForNonEmptyLines));
+
+  EXPECT_EQ("[]() {\n"
+"  foo(); }",
+format("[]() {\n"
+   "foo(); }",
+   Style, SC_ExpectComplete,
+   ExtraFormattingOptions::KeepLineBreaksForNonEmptyLines));
+}
+
 TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) {
   verifyFormat("x = (a) and (b);");
   verifyFormat("x = (a) or (b);");
Index: tools/clang-format-ide/ClangFormatIDE.cpp
===
--- tools/clang-format-ide/ClangFormatIDE.cpp
+++ tools/clang-format-ide/ClangFormatIDE.cpp
@@ -0,0 +1,102 @@
+//===-- clang-format/ClangFormat.cpp - Clang format tool --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file implements a clang-format tool that automatically formats
+/// (fragments of) C++ code.
+///
+//===--===//
+
+#include "../clang-format/ClangFormat.h"
+
+static cl::opt
+KeepLineBreaks("keep-line-breaks",
+   cl::desc("If set, keeps all existing line breaks"),
+   cl::cat(ClangFormatCategory));
+
+static void PrintVersion(raw_ostream ) {
+  OS << clang::getClangToolFullVersion("clang-format-ide") << '\n';
+}
+
+int main(int argc, const char **argv) {
+  llvm::InitLLVM X(argc, argv);
+
+  cl::HideUnrelatedOptions(ClangFormatCategory);
+
+  cl::SetVersionPrinter(PrintVersion);
+  cl::ParseCommandLineOptions(
+  argc, argv,
+  "A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# code.\n\n"
+  "If no arguments are specified, it formats the code from standard input\n"
+  "and writes the result to the standard output.\n"
+  "If s are given, it reformats the files. If -i is specified\n"
+  "together with s, the files are edited in-place. Otherwise, the\n"
+  "result is written to the standard output.\n");
+
+  if (Help) {
+cl::PrintHelpMessage();
+return 0;
+  }
+
+  if (DumpConfig) {
+StringRef FileName;
+std::unique_ptr Code;
+if (FileNames.empty()) {
+  // We can't read the code 

[PATCH] D58501: [libclang] Fix CXTranslationUnit_KeepGoing

2019-03-07 Thread Ivan Donchevskii via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL355586: [libclang] Fix CXTranslationUnit_KeepGoing (authored 
by yvvan, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D58501?vs=187765=189668#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D58501

Files:
  cfe/trunk/include/clang/Basic/Diagnostic.h
  cfe/trunk/lib/Basic/DiagnosticIDs.cpp
  cfe/trunk/test/Index/Inputs/keep-going-template-instantiations.h
  cfe/trunk/test/Index/keep-going-template-instantiations.cpp
  cfe/trunk/test/Index/keep-going.cpp
  cfe/trunk/tools/libclang/CIndex.cpp
  cfe/trunk/unittests/Basic/DiagnosticTest.cpp

Index: cfe/trunk/lib/Basic/DiagnosticIDs.cpp
===
--- cfe/trunk/lib/Basic/DiagnosticIDs.cpp
+++ cfe/trunk/lib/Basic/DiagnosticIDs.cpp
@@ -481,6 +481,11 @@
   Result = diag::Severity::Fatal;
   }
 
+  // If explicitly requested, map fatal errors to errors.
+  if (Result == diag::Severity::Fatal &&
+  Diag.CurDiagID != diag::fatal_too_many_errors && Diag.FatalsAsError)
+Result = diag::Severity::Error;
+
   // Custom diagnostics always are emitted in system headers.
   bool ShowInSystemHeader =
   !GetDiagInfo(DiagID) || GetDiagInfo(DiagID)->WarnShowInSystemHeader;
@@ -660,7 +665,7 @@
 
   // If a fatal error has already been emitted, silence all subsequent
   // diagnostics.
-  if (Diag.FatalErrorOccurred && Diag.SuppressAfterFatalError) {
+  if (Diag.FatalErrorOccurred) {
 if (DiagLevel >= DiagnosticIDs::Error &&
 Diag.Client->IncludeInDiagnosticCounts()) {
   ++Diag.NumErrors;
Index: cfe/trunk/unittests/Basic/DiagnosticTest.cpp
===
--- cfe/trunk/unittests/Basic/DiagnosticTest.cpp
+++ cfe/trunk/unittests/Basic/DiagnosticTest.cpp
@@ -46,13 +46,13 @@
   EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
 }
 
-// Check that SuppressAfterFatalError works as intended
-TEST(DiagnosticTest, suppressAfterFatalError) {
-  for (unsigned Suppress = 0; Suppress != 2; ++Suppress) {
+// Check that FatalsAsError works as intended
+TEST(DiagnosticTest, fatalsAsError) {
+  for (unsigned FatalsAsError = 0; FatalsAsError != 2; ++FatalsAsError) {
 DiagnosticsEngine Diags(new DiagnosticIDs(),
 new DiagnosticOptions,
 new IgnoringDiagConsumer());
-Diags.setSuppressAfterFatalError(Suppress);
+Diags.setFatalsAsError(FatalsAsError);
 
 // Diag that would set UnrecoverableErrorOccurred and ErrorOccurred.
 Diags.Report(diag::err_cannot_open_file) << "file" << "error";
@@ -62,16 +62,15 @@
 Diags.Report(diag::warn_mt_message) << "warning";
 
 EXPECT_TRUE(Diags.hasErrorOccurred());
-EXPECT_TRUE(Diags.hasFatalErrorOccurred());
+EXPECT_EQ(Diags.hasFatalErrorOccurred(), FatalsAsError ? 0u : 1u);
 EXPECT_TRUE(Diags.hasUncompilableErrorOccurred());
 EXPECT_TRUE(Diags.hasUnrecoverableErrorOccurred());
 
 // The warning should be emitted and counted only if we're not suppressing
 // after fatal errors.
-EXPECT_EQ(Diags.getNumWarnings(), Suppress ? 0u : 1u);
+EXPECT_EQ(Diags.getNumWarnings(), FatalsAsError);
   }
 }
-
 TEST(DiagnosticTest, diagnosticError) {
   DiagnosticsEngine Diags(new DiagnosticIDs(), new DiagnosticOptions,
   new IgnoringDiagConsumer());
Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -3408,7 +3408,7 @@
 Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions));
 
   if (options & CXTranslationUnit_KeepGoing)
-Diags->setSuppressAfterFatalError(false);
+Diags->setFatalsAsError(true);
 
   // Recover resources if we crash before exiting this function.
   llvm::CrashRecoveryContextCleanupRegistrarErrorsAsFatal = Val; }
   bool getErrorsAsFatal() const { return GetCurDiagState()->ErrorsAsFatal; }
 
-  /// When set to true (the default), suppress further diagnostics after
-  /// a fatal error.
-  void setSuppressAfterFatalError(bool Val) { SuppressAfterFatalError = Val; }
+  /// \brief When set to true, any fatal error reported is made an error.
+  ///
+  /// This setting takes precedence over the setErrorsAsFatal setting above.
+  void setFatalsAsError(bool Val) { FatalsAsError = Val; }
+  bool getFatalsAsError() const { return FatalsAsError; }
 
   /// When set to true mask warnings that come from system headers.
   void setSuppressSystemWarnings(bool Val) {
Index: cfe/trunk/test/Index/keep-going-template-instantiations.cpp
===
--- cfe/trunk/test/Index/keep-going-template-instantiations.cpp
+++ 

[PATCH] D57951: [Lex] Allow to set missing include error to not fatal

2019-02-11 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan planned changes to this revision.
yvvan added a comment.

It's probably not needed because I don't see a path which checked for the fatal 
errors in 8.0. So i will probably abandon this one or update if it does not 
cover the case I need.


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

https://reviews.llvm.org/D57951



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


[PATCH] D57951: [Lex] Allow to set missing include error to not fatal

2019-02-08 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

I've tested it with libclang. If something else is needed for proper clangd 
args forwarding - let me know.


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

https://reviews.llvm.org/D57951



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


[PATCH] D57951: [Lex] Allow to set missing include error to not fatal

2019-02-08 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: ilya-biryukov, nik.

For IDE it's a nice feature to not get a fatal error and continue preprocessing 
even if the file is missing.
This allows include further files and get more relevant information about the 
current translation unit.


https://reviews.llvm.org/D57951

Files:
  include/clang/Basic/Diagnostic.h
  include/clang/Basic/DiagnosticLexKinds.td
  include/clang/Lex/PreprocessorOptions.h
  lib/Frontend/ASTUnit.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/Pragma.cpp


Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -29,6 +29,7 @@
 #include "clang/Lex/ModuleLoader.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Lex/PreprocessorLexer.h"
 #include "clang/Lex/Token.h"
 #include "clang/Lex/TokenLexer.h"
@@ -508,8 +509,12 @@
   LookupFile(FilenameTok.getLocation(), Filename, isAngled, nullptr,
  nullptr, CurDir, nullptr, nullptr, nullptr, nullptr, nullptr);
   if (!File) {
-if (!SuppressIncludeNotFoundError)
-  Diag(FilenameTok, diag::err_pp_file_not_found) << Filename;
+if (!SuppressIncludeNotFoundError) {
+  Diag(FilenameTok, PPOpts->KeepGoingAfterMissingInclude
+? diag::err_pp_file_not_found_keep_going
+: diag::err_pp_file_not_found)
+  << Filename;
+}
 return;
   }
 
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1866,8 +1866,10 @@
 
   // If the file is still not found, just go with the vanilla diagnostic
   if (!File) {
-Diag(FilenameTok, diag::err_pp_file_not_found) << OriginalFilename
-   << FilenameRange;
+Diag(FilenameTok, PPOpts->KeepGoingAfterMissingInclude
+  ? diag::err_pp_file_not_found_keep_going
+  : diag::err_pp_file_not_found)
+<< OriginalFilename << FilenameRange;
 if (IsFrameworkFound) {
   size_t SlashPos = OriginalFilename.find('/');
   assert(SlashPos != StringRef::npos &&
Index: lib/Frontend/ASTUnit.cpp
===
--- lib/Frontend/ASTUnit.cpp
+++ lib/Frontend/ASTUnit.cpp
@@ -1735,6 +1735,7 @@
   PPOpts.RemappedFilesKeepOriginalName = RemappedFilesKeepOriginalName;
   PPOpts.AllowPCHWithCompilerErrors = AllowPCHWithCompilerErrors;
   PPOpts.SingleFileParseMode = SingleFileParse;
+  PPOpts.KeepGoingAfterMissingInclude = !Diags->getSuppressAfterFatalError();
 
   // Override the resources path.
   CI->getHeaderSearchOpts().ResourceDir = ResourceFilesPath;
Index: include/clang/Lex/PreprocessorOptions.h
===
--- include/clang/Lex/PreprocessorOptions.h
+++ include/clang/Lex/PreprocessorOptions.h
@@ -142,6 +142,12 @@
   /// compiler invocation and its buffers will be reused.
   bool RetainRemappedFileBuffers = false;
 
+  /// Whether to emit normal error instead of fatal in case the include is
+  /// missing. This should help to provide more meaningful information for the
+  /// code that uses data from the following headers which are ignored
+  /// otherwise.
+  bool KeepGoingAfterMissingInclude = false;
+
   /// The Objective-C++ ARC standard library that we should support,
   /// by providing appropriate definitions to retrofit the standard library
   /// with support for lifetime-qualified pointers.
Index: include/clang/Basic/DiagnosticLexKinds.td
===
--- include/clang/Basic/DiagnosticLexKinds.td
+++ include/clang/Basic/DiagnosticLexKinds.td
@@ -399,6 +399,7 @@
 def err_pp_directive_required : Error<
   "%0 must be used within a preprocessing directive">;
 def err_pp_file_not_found : Error<"'%0' file not found">, DefaultFatal;
+def err_pp_file_not_found_keep_going : Error<"'%0' file not found">;
 def err_pp_through_header_not_found : Error<
   "'%0' required for precompiled header not found">, DefaultFatal;
 def err_pp_through_header_not_seen : Error<
Index: include/clang/Basic/Diagnostic.h
===
--- include/clang/Basic/Diagnostic.h
+++ include/clang/Basic/Diagnostic.h
@@ -618,6 +618,8 @@
   /// a fatal error.
   void setSuppressAfterFatalError(bool Val) { SuppressAfterFatalError = Val; }
 
+  bool getSuppressAfterFatalError() { return SuppressAfterFatalError; }
+
   /// When set to true mask warnings that come from system headers.
   void setSuppressSystemWarnings(bool Val) {
 GetCurDiagState()->SuppressSystemWarnings = Val;


Index: lib/Lex/Pragma.cpp
===
--- 

[PATCH] D53072: [clang-format] Introduce the flag which allows not to shrink lines

2019-01-11 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 181274.
yvvan added a comment.

The tests are improved - now they actually act differently with and without the 
introduced flag. Also few more cases are covered (see the second added test).


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

https://reviews.llvm.org/D53072

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/UnwrappedLineFormatter.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -349,6 +349,22 @@
"  void funk() {}\n"
"};",
Style));
+
+  Style.KeepLineBreaksForNonEmptyLines = true;
+  Style.ColumnLimit = 0;
+  EXPECT_EQ("if (a\n"
+"&& b) {\n"
+"}",
+format("if (a\n"
+   "&& b) {\n"
+   "}",
+   Style));
+
+  EXPECT_EQ("[]() {\n"
+"  foo(); }",
+format("[]() {\n"
+   "foo(); }",
+   Style));
 }
 
 TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) {
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -2517,6 +2517,8 @@
   else
 readTokenWithJavaScriptASI();
   FormatTok->Previous = Previous;
+  if (FormatTok->NewlinesBefore && Style.KeepLineBreaksForNonEmptyLines)
+FormatTok->MustBreakBefore = true;
 }
 
 void UnwrappedLineParser::distributeComments(
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -672,7 +672,7 @@
   LineFormatter(ContinuationIndenter *Indenter, WhitespaceManager *Whitespaces,
 const FormatStyle ,
 UnwrappedLineFormatter *BlockFormatter)
-  : Indenter(Indenter), Whitespaces(Whitespaces), Style(Style),
+  : Indenter(Indenter), Style(Style), Whitespaces(Whitespaces),
 BlockFormatter(BlockFormatter) {}
   virtual ~LineFormatter() {}
 
@@ -715,7 +715,8 @@
   // assert so that we can simply call this function for all tokens.
   return true;
 
-if (NewLine) {
+if (NewLine || (Previous.Children[0]->First->MustBreakBefore &&
+Style.KeepLineBreaksForNonEmptyLines)) {
   int AdditionalIndent = State.Stack.back().Indent -
  Previous.Children[0]->Level * Style.IndentWidth;
 
@@ -760,10 +761,10 @@
   }
 
   ContinuationIndenter *Indenter;
+  const FormatStyle 
 
 private:
   WhitespaceManager *Whitespaces;
-  const FormatStyle 
   UnwrappedLineFormatter *BlockFormatter;
 };
 
@@ -786,7 +787,7 @@
 while (State.NextToken) {
   bool Newline =
   Indenter->mustBreak(State) ||
-  (Indenter->canBreak(State) && State.NextToken->NewlinesBefore > 0);
+  (State.NextToken->NewlinesBefore > 0 && Indenter->canBreak(State));
   unsigned Penalty = 0;
   formatChildren(State, Newline, /*DryRun=*/false, Penalty);
   Indenter->addTokenToState(State, Newline, /*DryRun=*/false);
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -416,6 +416,8 @@
Style.IndentWrappedFunctionNames);
 IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
+IO.mapOptional("KeepLineBreaksForNonEmptyLines",
+   Style.KeepLineBreaksForNonEmptyLines);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
@@ -676,6 +678,7 @@
   LLVMStyle.JavaScriptWrapImports = true;
   LLVMStyle.TabWidth = 8;
   LLVMStyle.MaxEmptyLinesToKeep = 1;
+  LLVMStyle.KeepLineBreaksForNonEmptyLines = false;
   LLVMStyle.KeepEmptyLinesAtTheStartOfBlocks = true;
   LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
   LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
@@ -741,6 +744,7 @@
   {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
   GoogleStyle.IndentCaseLabels = true;
+  GoogleStyle.KeepLineBreaksForNonEmptyLines = false;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
   GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
   GoogleStyle.ObjCSpaceAfterProperty = false;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -1160,6 

[PATCH] D54996: [libclang] Fix clang_Cursor_isAnonymous

2019-01-10 Thread Ivan Donchevskii via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350805: [libclang] Fix clang_Cursor_isAnonymous (authored by 
yvvan, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D54996?vs=181005=181008#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D54996

Files:
  cfe/trunk/test/Index/print-type.cpp
  cfe/trunk/tools/c-index-test/c-index-test.c
  cfe/trunk/tools/libclang/CXType.cpp


Index: cfe/trunk/tools/c-index-test/c-index-test.c
===
--- cfe/trunk/tools/c-index-test/c-index-test.c
+++ cfe/trunk/tools/c-index-test/c-index-test.c
@@ -1654,13 +1654,14 @@
 if (numFields != 0) {
   printf(" [nbFields=%d]", numFields);
 }
-/* Print if it is an anonymous record. */
-{
-  unsigned isAnon = clang_Cursor_isAnonymous(cursor);
-  if (isAnon != 0) {
-printf(" [isAnon=%d]", isAnon);
-  }
-}
+  }
+}
+
+/* Print if it is an anonymous record or namespace. */
+{
+  unsigned isAnon = clang_Cursor_isAnonymous(cursor);
+  if (isAnon != 0) {
+printf(" [isAnon=%d]", isAnon);
   }
 }
 
Index: cfe/trunk/tools/libclang/CXType.cpp
===
--- cfe/trunk/tools/libclang/CXType.cpp
+++ cfe/trunk/tools/libclang/CXType.cpp
@@ -1229,11 +1229,15 @@
   if (!clang_isDeclaration(C.kind))
 return 0;
   const Decl *D = cxcursor::getCursorDecl(C);
-  if (const RecordDecl *FD = dyn_cast_or_null(D))
-return FD->isAnonymousStructOrUnion();
+  if (const NamespaceDecl *ND = dyn_cast_or_null(D)) {
+return ND->isAnonymousNamespace();
+  } else if (const TagDecl *TD = dyn_cast_or_null(D)) {
+return TD->getTypedefNameForAnonDecl() == nullptr &&
+   TD->getIdentifier() == nullptr;
+  }
+
   return 0;
 }
-
 CXType clang_Type_getNamedType(CXType CT){
   QualType T = GetQualType(CT);
   const Type *TP = T.getTypePtrOrNull();
Index: cfe/trunk/test/Index/print-type.cpp
===
--- cfe/trunk/test/Index/print-type.cpp
+++ cfe/trunk/test/Index/print-type.cpp
@@ -79,6 +79,17 @@
 
 outer::Foo parameter;
 outer::inner::Bar construct();
+
+class X {
+  struct { int a; };
+  class { public: int b; };
+  union { int c; int d;};
+  enum { Test };
+};
+
+namespace {
+  int a;
+}
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
@@ -188,3 +199,8 @@
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] 
[templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] 
[typekind=Void]] [isPOD=0]
 // CHECK: VarDecl=autoTemplPointer:78:6 (Definition) 
[type=Specialization &> *] [typekind=Auto] 
[canonicaltype=Specialization &> *] 
[canonicaltypekind=Pointer] [isPOD=1] 
[pointeetype=Specialization &>] [pointeekind=Record]
 // CHECK: CallExpr=Bar:17:3 [type=outer::inner::Bar] [typekind=Elaborated] 
[canonicaltype=outer::inner::Bar] [canonicaltypekind=Record] [args= 
[outer::Foo *] [Pointer]] [isPOD=0] [nbFields=3]
+// CHECK: StructDecl=:84:3 (Definition) [type=X::(anonymous struct at 
{{.*}}print-type.cpp:84:3)] [typekind=Record] [isPOD=1] [nbFields=1] [isAnon=1]
+// CHECK: ClassDecl=:85:3 (Definition) [type=X::(anonymous class at 
{{.*}}print-type.cpp:85:3)] [typekind=Record] [isPOD=1] [nbFields=1] [isAnon=1]
+// CHECK: UnionDecl=:86:3 (Definition) [type=X::(anonymous union at 
{{.*}}print-type.cpp:86:3)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1]
+// CHECK: EnumDecl=:87:3 (Definition) [type=X::(anonymous enum at 
{{.*}}print-type.cpp:87:3)] [typekind=Enum] [isPOD=1] [isAnon=1]
+// CHECK: Namespace=:90:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] 
[isAnon=1]


Index: cfe/trunk/tools/c-index-test/c-index-test.c
===
--- cfe/trunk/tools/c-index-test/c-index-test.c
+++ cfe/trunk/tools/c-index-test/c-index-test.c
@@ -1654,13 +1654,14 @@
 if (numFields != 0) {
   printf(" [nbFields=%d]", numFields);
 }
-/* Print if it is an anonymous record. */
-{
-  unsigned isAnon = clang_Cursor_isAnonymous(cursor);
-  if (isAnon != 0) {
-printf(" [isAnon=%d]", isAnon);
-  }
-}
+  }
+}
+
+/* Print if it is an anonymous record or namespace. */
+{
+  unsigned isAnon = clang_Cursor_isAnonymous(cursor);
+  if (isAnon != 0) {
+printf(" [isAnon=%d]", isAnon);
   }
 }
 
Index: cfe/trunk/tools/libclang/CXType.cpp

[PATCH] D54996: [libclang] Fix clang_Cursor_isAnonymous

2019-01-10 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 181005.
yvvan added a comment.

Replace the absolute path with {{.*}} to be independent from the machine.


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

https://reviews.llvm.org/D54996

Files:
  test/Index/print-type.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CXType.cpp


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -1229,11 +1229,15 @@
   if (!clang_isDeclaration(C.kind))
 return 0;
   const Decl *D = cxcursor::getCursorDecl(C);
-  if (const RecordDecl *FD = dyn_cast_or_null(D))
-return FD->isAnonymousStructOrUnion();
+  if (const NamespaceDecl *ND = dyn_cast_or_null(D)) {
+return ND->isAnonymousNamespace();
+  } else if (const TagDecl *TD = dyn_cast_or_null(D)) {
+return TD->getTypedefNameForAnonDecl() == nullptr &&
+   TD->getIdentifier() == nullptr;
+  }
+
   return 0;
 }
-
 CXType clang_Type_getNamedType(CXType CT){
   QualType T = GetQualType(CT);
   const Type *TP = T.getTypePtrOrNull();
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1654,16 +1654,17 @@
 if (numFields != 0) {
   printf(" [nbFields=%d]", numFields);
 }
-/* Print if it is an anonymous record. */
-{
-  unsigned isAnon = clang_Cursor_isAnonymous(cursor);
-  if (isAnon != 0) {
-printf(" [isAnon=%d]", isAnon);
-  }
-}
   }
 }
 
+/* Print if it is an anonymous record or namespace. */
+{
+  unsigned isAnon = clang_Cursor_isAnonymous(cursor);
+  if (isAnon != 0) {
+printf(" [isAnon=%d]", isAnon);
+  }
+}
+
 printf("\n");
   }
   return CXChildVisit_Recurse;
Index: test/Index/print-type.cpp
===
--- test/Index/print-type.cpp
+++ test/Index/print-type.cpp
@@ -79,6 +79,17 @@
 
 outer::Foo parameter;
 outer::inner::Bar construct();
+
+class X {
+  struct { int a; };
+  class { public: int b; };
+  union { int c; int d;};
+  enum { Test };
+};
+
+namespace {
+  int a;
+}
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
@@ -188,3 +199,8 @@
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] 
[templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] 
[typekind=Void]] [isPOD=0]
 // CHECK: VarDecl=autoTemplPointer:78:6 (Definition) 
[type=Specialization &> *] [typekind=Auto] 
[canonicaltype=Specialization &> *] 
[canonicaltypekind=Pointer] [isPOD=1] 
[pointeetype=Specialization &>] [pointeekind=Record]
 // CHECK: CallExpr=Bar:17:3 [type=outer::inner::Bar] [typekind=Elaborated] 
[canonicaltype=outer::inner::Bar] [canonicaltypekind=Record] [args= 
[outer::Foo *] [Pointer]] [isPOD=0] [nbFields=3]
+// CHECK: StructDecl=:84:3 (Definition) [type=X::(anonymous struct at 
{{.*}}print-type.cpp:84:3)] [typekind=Record] [isPOD=1] [nbFields=1] [isAnon=1]
+// CHECK: ClassDecl=:85:3 (Definition) [type=X::(anonymous class at 
{{.*}}print-type.cpp:85:3)] [typekind=Record] [isPOD=1] [nbFields=1] [isAnon=1]
+// CHECK: UnionDecl=:86:3 (Definition) [type=X::(anonymous union at 
{{.*}}print-type.cpp:86:3)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1]
+// CHECK: EnumDecl=:87:3 (Definition) [type=X::(anonymous enum at 
{{.*}}print-type.cpp:87:3)] [typekind=Enum] [isPOD=1] [isAnon=1]
+// CHECK: Namespace=:90:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] 
[isAnon=1]


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -1229,11 +1229,15 @@
   if (!clang_isDeclaration(C.kind))
 return 0;
   const Decl *D = cxcursor::getCursorDecl(C);
-  if (const RecordDecl *FD = dyn_cast_or_null(D))
-return FD->isAnonymousStructOrUnion();
+  if (const NamespaceDecl *ND = dyn_cast_or_null(D)) {
+return ND->isAnonymousNamespace();
+  } else if (const TagDecl *TD = dyn_cast_or_null(D)) {
+return TD->getTypedefNameForAnonDecl() == nullptr &&
+   TD->getIdentifier() == nullptr;
+  }
+
   return 0;
 }
-
 CXType clang_Type_getNamedType(CXType CT){
   QualType T = GetQualType(CT);
   const Type *TP = T.getTypePtrOrNull();
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1654,16 +1654,17 @@
 if (numFields != 0) {
   printf(" [nbFields=%d]", numFields);
 }
-/* Print if 

[PATCH] D54996: [libclang] Fix clang_Cursor_isAnonymous

2019-01-09 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Good point :)


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

https://reviews.llvm.org/D54996



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


[PATCH] D53072: [clang-format] Introduce the flag which allows not to shrink lines

2019-01-07 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@djasper
Ok, if there's a possible way to go forward I will find time to provide a 
better test which behaves differently depending on this check. Also my current 
patch is a bit bigger than this version.


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

https://reviews.llvm.org/D53072



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


[PATCH] D53072: [clang-format] Introduce the flag which allows not to shrink lines

2019-01-07 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

In D53072#1348033 , @djasper wrote:

>   $ cat /tmp/test.cc
>   int foo(int a,
>  int b) {
> f();
> }
>   
>   $ clang-format -style="{ColumnLimit: 0}" /tmp/test.cc
>   int foo(int a,
>   int b) {
> f();
>   }
>   
>
> Is this not what you want? If so, in what way?


Ok, this might mean that my test is bad and does not test what I want (there 
are more cases which are not formatted the way I want with ColumnLimit: 0). But 
since the patch is never to be submitted I don't see a reason to improve it.


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

https://reviews.llvm.org/D53072



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


[PATCH] D53072: [clang-format] Introduce the flag which allows not to shrink lines

2019-01-07 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

In D53072#1342363 , @djasper wrote:

> I don't quite understand. What you are describing should already be the 
> behavior with ColumnLimit=0 and I think your test should pass without the new 
> option. Doesn't it?


As far as I see how it works column limit does not prevent the shrinking 
behavior.

In D53072#1342353 , @krasimir wrote:

> In D53072#1268883 , @yvvan wrote:
>
> > Do you know the better way to accomplish my aim than adding an option to 
> > libFormat? For example making a dependent library which serves a little 
> > different purpose than libFormat itself or something simpler?
>
>
> I don't know about the specific use-case, but in general a fail-safe way to 
> force a line break in C++ code is to add an empty line comment on the 
> preceding line.


This is close but will not work for the case when more than two lines are 
packed together. So it requires to put the empty comment on the each line 
ending which is not too nice (if i'm not missing something)


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

https://reviews.llvm.org/D53072



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


[PATCH] D55595: [clang-tidy] Share the forced linking code between clang-tidy tool and plugin

2018-12-13 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan marked an inline comment as done.
yvvan added inline comments.



Comment at: clang-tidy/plugin/ClangTidyPlugin.cpp:11
 #include "../ClangTidy.h"
+#include "../ClangTidyForceLinker.h"
 #include "../ClangTidyModule.h"

yvvan wrote:
> lebedev.ri wrote:
> > yvvan wrote:
> > > It seems it had to go after #include "clang/Config/config.h" to have MPI 
> > > checks enabled...
> > The includes should be auto-sorted by clang-format, so if that header needs 
> > some headers,
> > then it should include them, not hope they will already be included.
> > 
> True. Will fix tomorrow asap.
Damn, "config.h" is special and can only be included once.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D55595



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


[PATCH] D55595: [clang-tidy] Share the forced linking code between clang-tidy tool and plugin

2018-12-13 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan marked an inline comment as done.
yvvan added inline comments.



Comment at: clang-tidy/ClangTidyForceLinker.h:11
+#include "llvm/Support/Compiler.h"
+
+namespace clang {

dyung wrote:
> dyung wrote:
> > Is there a reason that this header file does not use the standard header 
> > guards?
> Sorry, this should not have been marked as done.
I'm adding them together with the include.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D55595



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


[PATCH] D55595: [clang-tidy] Share the forced linking code between clang-tidy tool and plugin

2018-12-13 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan marked an inline comment as done.
yvvan added inline comments.



Comment at: clang-tidy/plugin/ClangTidyPlugin.cpp:11
 #include "../ClangTidy.h"
+#include "../ClangTidyForceLinker.h"
 #include "../ClangTidyModule.h"

lebedev.ri wrote:
> yvvan wrote:
> > It seems it had to go after #include "clang/Config/config.h" to have MPI 
> > checks enabled...
> The includes should be auto-sorted by clang-format, so if that header needs 
> some headers,
> then it should include them, not hope they will already be included.
> 
True. Will fix tomorrow asap.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D55595



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


[PATCH] D55595: [clang-tidy] Share the forced linking code between clang-tidy tool and plugin

2018-12-13 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan marked an inline comment as done.
yvvan added inline comments.



Comment at: clang-tidy/plugin/ClangTidyPlugin.cpp:11
 #include "../ClangTidy.h"
+#include "../ClangTidyForceLinker.h"
 #include "../ClangTidyModule.h"

It seems it had to go after #include "clang/Config/config.h" to have MPI checks 
enabled...


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D55595



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


[PATCH] D55595: [clang-tidy] Share the forced linking code between clang-tidy tool and plugin

2018-12-13 Thread Ivan Donchevskii via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE349038: [clang-tidy] Share the forced linking code between 
clang-tidy tool and plugin (authored by yvvan, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D55595?vs=177832=178048#toc

Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D55595

Files:
  clang-tidy/ClangTidyForceLinker.h
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/tool/ClangTidyMain.cpp

Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -16,6 +16,7 @@
 //===--===//
 
 #include "../ClangTidy.h"
+#include "../ClangTidyForceLinker.h"
 #include "clang/Config/config.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "llvm/Support/Process.h"
@@ -482,98 +483,6 @@
   return 0;
 }
 
-// This anchor is used to force the linker to link the CERTModule.
-extern volatile int CERTModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
-CERTModuleAnchorSource;
-
-// This anchor is used to force the linker to link the AbseilModule.
-extern volatile int AbseilModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED AbseilModuleAnchorDestination =
-AbseilModuleAnchorSource;
-
-// This anchor is used to force the linker to link the BoostModule.
-extern volatile int BoostModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
-BoostModuleAnchorSource;
-
-// This anchor is used to force the linker to link the BugproneModule.
-extern volatile int BugproneModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination =
-BugproneModuleAnchorSource;
-
-// This anchor is used to force the linker to link the LLVMModule.
-extern volatile int LLVMModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
-LLVMModuleAnchorSource;
-
-// This anchor is used to force the linker to link the CppCoreGuidelinesModule.
-extern volatile int CppCoreGuidelinesModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
-CppCoreGuidelinesModuleAnchorSource;
-
-// This anchor is used to force the linker to link the FuchsiaModule.
-extern volatile int FuchsiaModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED FuchsiaModuleAnchorDestination =
-FuchsiaModuleAnchorSource;
-
-// This anchor is used to force the linker to link the GoogleModule.
-extern volatile int GoogleModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
-GoogleModuleAnchorSource;
-
-// This anchor is used to force the linker to link the AndroidModule.
-extern volatile int AndroidModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED AndroidModuleAnchorDestination =
-AndroidModuleAnchorSource;
-
-// This anchor is used to force the linker to link the MiscModule.
-extern volatile int MiscModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
-MiscModuleAnchorSource;
-
-// This anchor is used to force the linker to link the ModernizeModule.
-extern volatile int ModernizeModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
-ModernizeModuleAnchorSource;
-
-#if CLANG_ENABLE_STATIC_ANALYZER
-// This anchor is used to force the linker to link the MPIModule.
-extern volatile int MPIModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
-MPIModuleAnchorSource;
-#endif
-
-// This anchor is used to force the linker to link the PerformanceModule.
-extern volatile int PerformanceModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
-PerformanceModuleAnchorSource;
-
-// This anchor is used to force the linker to link the PortabilityModule.
-extern volatile int PortabilityModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED PortabilityModuleAnchorDestination =
-PortabilityModuleAnchorSource;
-
-// This anchor is used to force the linker to link the ReadabilityModule.
-extern volatile int ReadabilityModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
-ReadabilityModuleAnchorSource;
-
-// This anchor is used to force the linker to link the ObjCModule.
-extern volatile int ObjCModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED ObjCModuleAnchorDestination =
-ObjCModuleAnchorSource;
-
-// This anchor is used to force the linker to link the HICPPModule.
-extern volatile int HICPPModuleAnchorSource;
-static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination =
-HICPPModuleAnchorSource;
-
-// This anchor is used to force the linker to link the ZirconModule.
-extern volatile int ZirconModuleAnchorSource;
-static int 

[PATCH] D55595: [clang-tidy] Share the forced linking code between clang-tidy tool and plugin

2018-12-13 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

In D55595#1329647 , @JonasToth wrote:

> One thing: Could you please check the utility-scripts in clang-tidy that 
> create new checks, if they need adjustments? Not sure if we have something in 
> there that relies on the old structure.


As far as I see these scripts do not touch 'tool' or 'plugin' folders at all, 
only the specific module, docs and tests.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D55595



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


[PATCH] D55595: Share the forced linking code between clang-tidy tool and plugin

2018-12-12 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 177832.
yvvan marked an inline comment as done.
yvvan added a comment.

Add standard prologue to the new header


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

https://reviews.llvm.org/D55595

Files:
  clang-tidy/ClangTidyForceLinker.h
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/tool/ClangTidyMain.cpp

Index: clang-tidy/ClangTidyForceLinker.h
===
--- clang-tidy/ClangTidyForceLinker.h
+++ clang-tidy/ClangTidyForceLinker.h
@@ -0,0 +1,108 @@
+//===- ClangTidyForceLinker.h - clang-tidy ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "llvm/Support/Compiler.h"
+
+namespace clang {
+namespace tidy {
+
+// This anchor is used to force the linker to link the CERTModule.
+extern volatile int CERTModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
+CERTModuleAnchorSource;
+
+// This anchor is used to force the linker to link the AbseilModule.
+extern volatile int AbseilModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED AbseilModuleAnchorDestination =
+AbseilModuleAnchorSource;
+
+// This anchor is used to force the linker to link the BoostModule.
+extern volatile int BoostModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
+BoostModuleAnchorSource;
+
+// This anchor is used to force the linker to link the BugproneModule.
+extern volatile int BugproneModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination =
+BugproneModuleAnchorSource;
+
+// This anchor is used to force the linker to link the LLVMModule.
+extern volatile int LLVMModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
+LLVMModuleAnchorSource;
+
+// This anchor is used to force the linker to link the CppCoreGuidelinesModule.
+extern volatile int CppCoreGuidelinesModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
+CppCoreGuidelinesModuleAnchorSource;
+
+// This anchor is used to force the linker to link the FuchsiaModule.
+extern volatile int FuchsiaModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED FuchsiaModuleAnchorDestination =
+FuchsiaModuleAnchorSource;
+
+// This anchor is used to force the linker to link the GoogleModule.
+extern volatile int GoogleModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
+GoogleModuleAnchorSource;
+
+// This anchor is used to force the linker to link the AndroidModule.
+extern volatile int AndroidModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED AndroidModuleAnchorDestination =
+AndroidModuleAnchorSource;
+
+// This anchor is used to force the linker to link the MiscModule.
+extern volatile int MiscModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
+MiscModuleAnchorSource;
+
+// This anchor is used to force the linker to link the ModernizeModule.
+extern volatile int ModernizeModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
+ModernizeModuleAnchorSource;
+
+#if CLANG_ENABLE_STATIC_ANALYZER
+// This anchor is used to force the linker to link the MPIModule.
+extern volatile int MPIModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
+MPIModuleAnchorSource;
+#endif
+
+// This anchor is used to force the linker to link the PerformanceModule.
+extern volatile int PerformanceModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
+PerformanceModuleAnchorSource;
+
+// This anchor is used to force the linker to link the PortabilityModule.
+extern volatile int PortabilityModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED PortabilityModuleAnchorDestination =
+PortabilityModuleAnchorSource;
+
+// This anchor is used to force the linker to link the ReadabilityModule.
+extern volatile int ReadabilityModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
+ReadabilityModuleAnchorSource;
+
+// This anchor is used to force the linker to link the ObjCModule.
+extern volatile int ObjCModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ObjCModuleAnchorDestination =
+ObjCModuleAnchorSource;
+
+// This anchor is used to force the linker to link the HICPPModule.
+extern volatile int HICPPModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination =
+HICPPModuleAnchorSource;
+
+// This anchor is used to force the linker to link the ZirconModule.
+extern volatile int ZirconModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ZirconModuleAnchorDestination =
+

[PATCH] D55595: Share the forced linking code between clang-tidy tool and plugin

2018-12-12 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 177829.
yvvan retitled this revision from "Add missing bugprone checks to clang-tidy 
plugin" to "Share the forced linking code between clang-tidy tool and plugin".
yvvan edited the summary of this revision.
Herald added a subscriber: srhines.

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

https://reviews.llvm.org/D55595

Files:
  clang-tidy/ClangTidyForceLinker.h
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/tool/ClangTidyMain.cpp

Index: clang-tidy/ClangTidyForceLinker.h
===
--- clang-tidy/ClangTidyForceLinker.h
+++ clang-tidy/ClangTidyForceLinker.h
@@ -0,0 +1,99 @@
+#include "llvm/Support/Compiler.h"
+
+namespace clang {
+namespace tidy {
+
+// This anchor is used to force the linker to link the CERTModule.
+extern volatile int CERTModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
+CERTModuleAnchorSource;
+
+// This anchor is used to force the linker to link the AbseilModule.
+extern volatile int AbseilModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED AbseilModuleAnchorDestination =
+AbseilModuleAnchorSource;
+
+// This anchor is used to force the linker to link the BoostModule.
+extern volatile int BoostModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
+BoostModuleAnchorSource;
+
+// This anchor is used to force the linker to link the BugproneModule.
+extern volatile int BugproneModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination =
+BugproneModuleAnchorSource;
+
+// This anchor is used to force the linker to link the LLVMModule.
+extern volatile int LLVMModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
+LLVMModuleAnchorSource;
+
+// This anchor is used to force the linker to link the CppCoreGuidelinesModule.
+extern volatile int CppCoreGuidelinesModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
+CppCoreGuidelinesModuleAnchorSource;
+
+// This anchor is used to force the linker to link the FuchsiaModule.
+extern volatile int FuchsiaModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED FuchsiaModuleAnchorDestination =
+FuchsiaModuleAnchorSource;
+
+// This anchor is used to force the linker to link the GoogleModule.
+extern volatile int GoogleModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
+GoogleModuleAnchorSource;
+
+// This anchor is used to force the linker to link the AndroidModule.
+extern volatile int AndroidModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED AndroidModuleAnchorDestination =
+AndroidModuleAnchorSource;
+
+// This anchor is used to force the linker to link the MiscModule.
+extern volatile int MiscModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
+MiscModuleAnchorSource;
+
+// This anchor is used to force the linker to link the ModernizeModule.
+extern volatile int ModernizeModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
+ModernizeModuleAnchorSource;
+
+#if CLANG_ENABLE_STATIC_ANALYZER
+// This anchor is used to force the linker to link the MPIModule.
+extern volatile int MPIModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
+MPIModuleAnchorSource;
+#endif
+
+// This anchor is used to force the linker to link the PerformanceModule.
+extern volatile int PerformanceModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
+PerformanceModuleAnchorSource;
+
+// This anchor is used to force the linker to link the PortabilityModule.
+extern volatile int PortabilityModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED PortabilityModuleAnchorDestination =
+PortabilityModuleAnchorSource;
+
+// This anchor is used to force the linker to link the ReadabilityModule.
+extern volatile int ReadabilityModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
+ReadabilityModuleAnchorSource;
+
+// This anchor is used to force the linker to link the ObjCModule.
+extern volatile int ObjCModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ObjCModuleAnchorDestination =
+ObjCModuleAnchorSource;
+
+// This anchor is used to force the linker to link the HICPPModule.
+extern volatile int HICPPModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination =
+HICPPModuleAnchorSource;
+
+// This anchor is used to force the linker to link the ZirconModule.
+extern volatile int ZirconModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ZirconModuleAnchorDestination =
+ZirconModuleAnchorSource;
+
+} // namespace tidy
+} // namespace clang
Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp
+++ 

[PATCH] D55595: Add missing bugprone checks to clang-tidy plugin

2018-12-12 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan planned changes to this revision.
yvvan added a comment.

In D55595#1328100 , @lebedev.ri wrote:

> 1. Please always upload all patches with full context.
> 2. There are two places where this pattern exists - this file, and 
> `tool/ClangTidyMain.cpp`. It clearly leads to such issues, Can this be 
> reworked to be just one file that is simply included in both places?




1. Usually I do that but this time used tortoisesvn to generate the patch...
2. Makes sense.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D55595



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


[PATCH] D55595: Add missing bugprone checks to clang-tidy plugin

2018-12-12 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: JonasToth, alexfh.

Synchronize it with ClangTidyMain


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D55595

Files:
  clang-tidy/plugin/ClangTidyPlugin.cpp


Index: clang-tidy/plugin/ClangTidyPlugin.cpp
===
--- clang-tidy/plugin/ClangTidyPlugin.cpp
+++ clang-tidy/plugin/ClangTidyPlugin.cpp
@@ -94,6 +94,11 @@
 static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
 BoostModuleAnchorSource;
 
+// This anchor is used to force the linker to link the BugproneModule.
+extern volatile int BugproneModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination =
+BugproneModuleAnchorSource;
+
 // This anchor is used to force the linker to link the CERTModule.
 extern volatile int CERTModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =


Index: clang-tidy/plugin/ClangTidyPlugin.cpp
===
--- clang-tidy/plugin/ClangTidyPlugin.cpp
+++ clang-tidy/plugin/ClangTidyPlugin.cpp
@@ -94,6 +94,11 @@
 static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
 BoostModuleAnchorSource;
 
+// This anchor is used to force the linker to link the BugproneModule.
+extern volatile int BugproneModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination =
+BugproneModuleAnchorSource;
+
 // This anchor is used to force the linker to link the CERTModule.
 extern volatile int CERTModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55415: Revert removal of tidy plugin support from libclang

2018-12-10 Thread Ivan Donchevskii via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL348764: [libclang] Revert removal of tidy plugin support 
from libclang introduced in… (authored by yvvan, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D55415?vs=177134=177515#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D55415

Files:
  cfe/trunk/tools/libclang/CIndex.cpp
  cfe/trunk/tools/libclang/CMakeLists.txt


Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -8938,3 +8938,16 @@
 OS << "--\n";
   }
 }
+
+#ifdef CLANG_TOOL_EXTRA_BUILD
+// This anchor is used to force the linker to link the clang-tidy plugin.
+extern volatile int ClangTidyPluginAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ClangTidyPluginAnchorDestination =
+ClangTidyPluginAnchorSource;
+
+// This anchor is used to force the linker to link the clang-include-fixer
+// plugin.
+extern volatile int ClangIncludeFixerPluginAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ClangIncludeFixerPluginAnchorDestination =
+ClangIncludeFixerPluginAnchorSource;
+#endif
Index: cfe/trunk/tools/libclang/CMakeLists.txt
===
--- cfe/trunk/tools/libclang/CMakeLists.txt
+++ cfe/trunk/tools/libclang/CMakeLists.txt
@@ -47,6 +47,15 @@
   list(APPEND LIBS clangARCMigrate)
 endif ()
 
+if (TARGET clangTidyPlugin)
+  add_definitions(-DCLANG_TOOL_EXTRA_BUILD)
+  list(APPEND LIBS clangTidyPlugin)
+  list(APPEND LIBS clangIncludeFixerPlugin)
+  if(LLVM_ENABLE_MODULES)
+list(APPEND LLVM_COMPILE_FLAGS 
"-fmodules-ignore-macro=CLANG_TOOL_EXTRA_BUILD")
+  endif()
+endif ()
+
 find_library(DL_LIBRARY_PATH dl)
 if (DL_LIBRARY_PATH)
   list(APPEND LIBS dl)


Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -8938,3 +8938,16 @@
 OS << "--\n";
   }
 }
+
+#ifdef CLANG_TOOL_EXTRA_BUILD
+// This anchor is used to force the linker to link the clang-tidy plugin.
+extern volatile int ClangTidyPluginAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ClangTidyPluginAnchorDestination =
+ClangTidyPluginAnchorSource;
+
+// This anchor is used to force the linker to link the clang-include-fixer
+// plugin.
+extern volatile int ClangIncludeFixerPluginAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ClangIncludeFixerPluginAnchorDestination =
+ClangIncludeFixerPluginAnchorSource;
+#endif
Index: cfe/trunk/tools/libclang/CMakeLists.txt
===
--- cfe/trunk/tools/libclang/CMakeLists.txt
+++ cfe/trunk/tools/libclang/CMakeLists.txt
@@ -47,6 +47,15 @@
   list(APPEND LIBS clangARCMigrate)
 endif ()
 
+if (TARGET clangTidyPlugin)
+  add_definitions(-DCLANG_TOOL_EXTRA_BUILD)
+  list(APPEND LIBS clangTidyPlugin)
+  list(APPEND LIBS clangIncludeFixerPlugin)
+  if(LLVM_ENABLE_MODULES)
+list(APPEND LLVM_COMPILE_FLAGS "-fmodules-ignore-macro=CLANG_TOOL_EXTRA_BUILD")
+  endif()
+endif ()
+
 find_library(DL_LIBRARY_PATH dl)
 if (DL_LIBRARY_PATH)
   list(APPEND LIBS dl)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55415: Revert removal of tidy plugin support from libclang

2018-12-07 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

In D55415#1323120 , @bkramer wrote:

> I'd be interested in hearing how this is used. I added this feature as an 
> experiment a while back but it simply didn't work as I envisioned it to. Some 
> checks do work but the overall latency makes it unusable in an IDE setting. 
> People repeatedly asked me to remove it because it slows down builds while 
> not adding value.


We use it with Qt Creator and you can see that we make additions/fixes in 
libclang from time to time.
With tidy checks selected it is slow indeed but there's always a choice whether 
to enable checks or not. And if you have very few checks enabled it performs 
quite fine. And we are still using libclang because we already have 
infrastructure on top of it which can't be just replaced with clangd (at least 
it requires quite some time).


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

https://reviews.llvm.org/D55415



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


[PATCH] D55415: Revert removal of tidy plugin support from libclang

2018-12-07 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

We can also add an extra variable for it if you care about build time


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

https://reviews.llvm.org/D55415



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


[PATCH] D55415: Revert removal of tidy plugin support from libclang

2018-12-07 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 177134.
yvvan added a comment.
Herald added a subscriber: mgorny.

I generated the wrong diff. This is the proper one.


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

https://reviews.llvm.org/D55415

Files:
  tools/libclang/CIndex.cpp
  tools/libclang/CMakeLists.txt


Index: tools/libclang/CMakeLists.txt
===
--- tools/libclang/CMakeLists.txt
+++ tools/libclang/CMakeLists.txt
@@ -47,6 +47,15 @@
   list(APPEND LIBS clangARCMigrate)
 endif ()
 
+if (TARGET clangTidyPlugin)
+  add_definitions(-DCLANG_TOOL_EXTRA_BUILD)
+  list(APPEND LIBS clangTidyPlugin)
+  list(APPEND LIBS clangIncludeFixerPlugin)
+  if(LLVM_ENABLE_MODULES)
+list(APPEND LLVM_COMPILE_FLAGS 
"-fmodules-ignore-macro=CLANG_TOOL_EXTRA_BUILD")
+  endif()
+endif ()
+
 find_library(DL_LIBRARY_PATH dl)
 if (DL_LIBRARY_PATH)
   list(APPEND LIBS dl)
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -8938,3 +8938,16 @@
 OS << "--\n";
   }
 }
+
+#ifdef CLANG_TOOL_EXTRA_BUILD
+// This anchor is used to force the linker to link the clang-tidy plugin.
+extern volatile int ClangTidyPluginAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ClangTidyPluginAnchorDestination =
+ClangTidyPluginAnchorSource;
+
+// This anchor is used to force the linker to link the clang-include-fixer
+// plugin.
+extern volatile int ClangIncludeFixerPluginAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ClangIncludeFixerPluginAnchorDestination =
+ClangIncludeFixerPluginAnchorSource;
+#endif


Index: tools/libclang/CMakeLists.txt
===
--- tools/libclang/CMakeLists.txt
+++ tools/libclang/CMakeLists.txt
@@ -47,6 +47,15 @@
   list(APPEND LIBS clangARCMigrate)
 endif ()
 
+if (TARGET clangTidyPlugin)
+  add_definitions(-DCLANG_TOOL_EXTRA_BUILD)
+  list(APPEND LIBS clangTidyPlugin)
+  list(APPEND LIBS clangIncludeFixerPlugin)
+  if(LLVM_ENABLE_MODULES)
+list(APPEND LLVM_COMPILE_FLAGS "-fmodules-ignore-macro=CLANG_TOOL_EXTRA_BUILD")
+  endif()
+endif ()
+
 find_library(DL_LIBRARY_PATH dl)
 if (DL_LIBRARY_PATH)
   list(APPEND LIBS dl)
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -8938,3 +8938,16 @@
 OS << "--\n";
   }
 }
+
+#ifdef CLANG_TOOL_EXTRA_BUILD
+// This anchor is used to force the linker to link the clang-tidy plugin.
+extern volatile int ClangTidyPluginAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ClangTidyPluginAnchorDestination =
+ClangTidyPluginAnchorSource;
+
+// This anchor is used to force the linker to link the clang-include-fixer
+// plugin.
+extern volatile int ClangIncludeFixerPluginAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ClangIncludeFixerPluginAnchorDestination =
+ClangIncludeFixerPluginAnchorSource;
+#endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D55415: Revert removal of tidy plugin support from libclang

2018-12-07 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: bkramer, arphaman, nik.
Herald added subscribers: kadircet, jkorous, ioeric, javed.absar, ilya-biryukov.

libclang has nothing to do with clangd so I don't see why having the last one 
is the reason to remove features from libclang. Especially without reviews.


https://reviews.llvm.org/D55415

Files:
  unittests/clangd/TUSchedulerTests.cpp


Index: unittests/clangd/TUSchedulerTests.cpp
===
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -709,29 +709,6 @@
   TUState(TUAction::Idle, /*No action*/ "")));
 }
 
-TEST_F(TUSchedulerTests, NoTUStatusEmittedForRemovedFile) {
-  class CaptureTUStatus : public DiagnosticsConsumer {
-  public:
-void onDiagnosticsReady(PathRef File,
-std::vector Diagnostics) override {}
-
-void onFileUpdated(PathRef File, const TUStatus ) override {
-  // Block the worker thread until the document is removed.
-  Removed.wait();
-}
-Notification Removed;
-  } CaptureTUStatus;
-  MockFSProvider FS;
-  MockCompilationDatabase CDB;
-  ClangdServer Server(CDB, FS, CaptureTUStatus, ClangdServer::optsForTest());
-
-  Server.addDocument(testPath("foo.cpp"), "int main() {}",
- WantDiagnostics::Yes);
-  Server.removeDocument(testPath("foo.cpp"));
-  CaptureTUStatus.Removed.notify();
-  ASSERT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for finishing";
-}
-
 } // namespace
 } // namespace clangd
 } // namespace clang


Index: unittests/clangd/TUSchedulerTests.cpp
===
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -709,29 +709,6 @@
   TUState(TUAction::Idle, /*No action*/ "")));
 }
 
-TEST_F(TUSchedulerTests, NoTUStatusEmittedForRemovedFile) {
-  class CaptureTUStatus : public DiagnosticsConsumer {
-  public:
-void onDiagnosticsReady(PathRef File,
-std::vector Diagnostics) override {}
-
-void onFileUpdated(PathRef File, const TUStatus ) override {
-  // Block the worker thread until the document is removed.
-  Removed.wait();
-}
-Notification Removed;
-  } CaptureTUStatus;
-  MockFSProvider FS;
-  MockCompilationDatabase CDB;
-  ClangdServer Server(CDB, FS, CaptureTUStatus, ClangdServer::optsForTest());
-
-  Server.addDocument(testPath("foo.cpp"), "int main() {}",
- WantDiagnostics::Yes);
-  Server.removeDocument(testPath("foo.cpp"));
-  CaptureTUStatus.Removed.notify();
-  ASSERT_TRUE(Server.blockUntilIdleForTest()) << "Waiting for finishing";
-}
-
 } // namespace
 } // namespace clangd
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54995: [MemoryBuffer] Add the setter to be able to force disabled mmap

2018-12-04 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan abandoned this revision.
yvvan added a comment.

@zturner

The fact that so many call-sites decide what to do is pretty error-prone.
There was already at least one issue when this flag was not properly set by 
some of the call-sites.


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] Add the setter to be able to force disabled mmap

2018-12-03 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@ilya-biryukov

Hm. What about another way around? - We have user include paths (-I) and report 
them to the filesystem. This means that we have specific paths under which 
nothing can be mmaped and everything else can be. In particular cases we can 
also report -isystem there. This is quite the same logic as current isVolatile 
parameter but is set only once for each path.


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] Add the setter to be able to force disabled mmap

2018-12-03 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

In D54995#1316457 , @ilya-biryukov 
wrote:

> In D54995#1316437 , @yvvan wrote:
>
> > Ok, no global option.
> >  Why not placing your VolatileFSProvider in clang so that libclang could 
> > you it too?
>
>
> Would be happy to, will need to figure out what to do with PCH and PCM files 
> first. However if we do this on clang level, I believe we should remove the 
> `isVolatile` flag from the VFS interfaces in the first place.
>  It would be nice to not loose out on the opportunity to avoid fully loading 
> the PCH files, but that obviously requires passing some flags into the VFS 
> implementation or various hacks (matching on filenames/extensions?) to find 
> out which files are PCHs. 
>  I actually don't know which approach to choose: on one hand, I'd really want 
> to get rid of the isVolatile flag, on the other hand I'd really want to avoid 
> loading large binary files into memory and that requires passing the flags.


I don't think removing the flag is a good idea since I can easily assume cases 
when user wants mmap and is ready to encounter locks. In our case it can be an 
IDE option which behavior to choose.
The ideal solution in my opinion would be to have isSystem(filename) in 
FileSystem class. And is based on system directories with which ASTUnit feeds 
the FileSystem for example.


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] Add the setter to be able to force disabled mmap

2018-12-03 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan planned changes to this revision.
yvvan added a comment.

Ok, no global option.
Why not placing your VolatileFSProvider in clang so that libclang could you it 
too?


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] Add the setter to be able to force disabled mmap

2018-12-03 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan marked an inline comment as done.
yvvan added inline comments.



Comment at: lib/Support/MemoryBuffer.cpp:42
 
+static bool MemoryMappingEnabled = true;
+

lebedev.ri wrote:
> Such global flags are a bad idea in general, and really not great in LLVM's 
> case.
> The editor would set it for "it's" llvm, but that will also affect the LLVM 
> that is used by e.g. mesa.
> 
Oh no, don't mention mesa. The proper client should never share it's LLVM layer 
with mesa. We already got issues with versions incompatibility and the only 
good solution is to link llvm statically inside client. Otherwise mesa causes 
the mess anyways.

Also I expect this setter to be used only on Windows.

Of course there's another solution is that Ilya proposed but it's only for 
clangd there and is bigger in code size. And it can still allow bugs if 
somebody uses MemoryBuffer not through the FileSystem class.


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] Add the setter to be able to force disabled mmap

2018-12-03 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 176318.
yvvan retitled this revision from "[MemoryBuffer] By default assume that all 
files are volatile to prevent unintended file locks" to "[MemoryBuffer] Add the 
setter to be able to force disabled mmap".
yvvan edited the summary of this revision.
yvvan added a comment.

Instead of forcing some default value let's give the client an ability to force 
disabled mmap if one desires.


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

https://reviews.llvm.org/D54995

Files:
  include/llvm/Support/MemoryBuffer.h
  lib/Support/MemoryBuffer.cpp


Index: lib/Support/MemoryBuffer.cpp
===
--- lib/Support/MemoryBuffer.cpp
+++ lib/Support/MemoryBuffer.cpp
@@ -39,6 +39,12 @@
 // MemoryBuffer implementation itself.
 
//===--===//
 
+static bool MemoryMappingEnabled = true;
+
+void MemoryBuffer::enableMemoryMapping(bool enable) {
+  MemoryMappingEnabled = enable;
+}
+
 MemoryBuffer::~MemoryBuffer() { }
 
 /// init - Initialize this MemoryBuffer as a reference to externally allocated
@@ -312,6 +318,9 @@
   bool RequiresNullTerminator,
   int PageSize,
   bool IsVolatile) {
+  if (!MemoryMappingEnabled)
+return false;
+
   // mmap may leave the buffer without null terminator if the file size changed
   // by the time the last page is mapped in, so avoid it if the file size is
   // likely to change.
Index: include/llvm/Support/MemoryBuffer.h
===
--- include/llvm/Support/MemoryBuffer.h
+++ include/llvm/Support/MemoryBuffer.h
@@ -132,6 +132,8 @@
   getFileSlice(const Twine , uint64_t MapSize, uint64_t Offset,
bool IsVolatile = false);
 
+  static void enableMemoryMapping(bool enable);
+
   
//======//
   // Provided for performance analysis.
   
//======//


Index: lib/Support/MemoryBuffer.cpp
===
--- lib/Support/MemoryBuffer.cpp
+++ lib/Support/MemoryBuffer.cpp
@@ -39,6 +39,12 @@
 // MemoryBuffer implementation itself.
 //===--===//
 
+static bool MemoryMappingEnabled = true;
+
+void MemoryBuffer::enableMemoryMapping(bool enable) {
+  MemoryMappingEnabled = enable;
+}
+
 MemoryBuffer::~MemoryBuffer() { }
 
 /// init - Initialize this MemoryBuffer as a reference to externally allocated
@@ -312,6 +318,9 @@
   bool RequiresNullTerminator,
   int PageSize,
   bool IsVolatile) {
+  if (!MemoryMappingEnabled)
+return false;
+
   // mmap may leave the buffer without null terminator if the file size changed
   // by the time the last page is mapped in, so avoid it if the file size is
   // likely to change.
Index: include/llvm/Support/MemoryBuffer.h
===
--- include/llvm/Support/MemoryBuffer.h
+++ include/llvm/Support/MemoryBuffer.h
@@ -132,6 +132,8 @@
   getFileSlice(const Twine , uint64_t MapSize, uint64_t Offset,
bool IsVolatile = false);
 
+  static void enableMemoryMapping(bool enable);
+
   //======//
   // Provided for performance analysis.
   //======//
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-30 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@ilya-biryukov 
What do you think about the global settable bool in MemoryBuffer in place of 
the ifdef from https://reviews.llvm.org/D35200 ? In this case the client on 
Windows can set it and you're safe that any MemoryBuffer call never mmaps.


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-30 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

No success with unmapping. Buffers are hold by PCMCache in Preprocessor (and 
the same one in ASTReader) and if I clean them then SourceManger crashed sooner 
or later on some call that gets data from external files.
So far I have no steps to reproduce the lock on user file so I don't currently 
know if I try something else.


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-29 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

I'm currently trying out another suggestion - which unmaps memory buffer caches 
after ASTUnit's Parse or Reparse and is limited to Windows only.
And my aim currently is not only clangd but any other client as well.


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-29 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

According to 
https://msdn.microsoft.com/en-us/2e9c3174-af48-4fa3-9f6a-fb62b23ed994 - 
"Unmapping a mapped view of a file invalidates the range occupied by the view 
in the address space of the process and makes the range available for other 
allocations".
Also as far as i understand from 
https://msdn.microsoft.com/en-us/library/ms810613.aspx mapped files can only be 
edited in other apps as mapped files opened with the same name 
(OpenFileMapping).

Simple example, I launch it and until i enter the number the test.h header 
remains locked and therefore i can't edit it in other apps.

  DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
  int accessRights = 0;
  accessRights |= GENERIC_READ;
  SECURITY_ATTRIBUTES securityAtts = { sizeof(SECURITY_ATTRIBUTES), NULL, FALSE 
};
  HANDLE fileHandle =
  CreateFile("D:\\test.h", accessRights, shareMode, ,
 OPEN_EXISTING,
 FILE_FLAG_BACKUP_SEMANTICS,
 NULL);
  
  HANDLE FileMappingHandle =
  CreateFileMappingA(fileHandle, 0, PAGE_READONLY, 0, 0, "D:_code_test.h");
  
  LPVOID Mapping = MapViewOfFile(FileMappingHandle, FILE_MAP_READ, 0, 0, 0);
  assert(Mapping);
  
  CloseHandle(FileMappingHandle);
  
  int i {0};
  std::cin >> i;
  UnmapViewOfFile(Mapping);
  
  CloseHandle(fileHandle);


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@ilya-biryukov

To clarify a little bit - i did not write my own simple app but used libclang 
in qt creator to reproduce the lock and track the issue. This time I hope to go 
further, collect flags used by clang and make a simple example.


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@ilya-biryukov

https://bugreports.qt.io/browse/QTCREATORBUG-15449

I was able to lock files last time with mmap. The Windows API calls are 
CreateFileMappingW (it's in the Path.inc, line 794) and MapViewOfFile (further 
down). As far as I remember the second call actually creates the lock and is 
freed only by UnmapViewOfFile in destructor


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@ilya-biryukov

According to https://stackoverflow.com/a/7414798 (if it's true) we can't 
prevent locks.


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

"could we figure out the exact cause of the issue?"

I'm pretty sure we can. Currently the issue is mentioned in our bugreports 
(https://bugreports.qt.io/secure/attachment/78582/clang-locks.png) and i plan 
to reproduce it and track the exact issue.
And this review was not meant to proceed immediately but rather state the 
intention and get some feedback because I still don't know answers to the 
questions 1 and 2 (did somebody else investigate that?)


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Hm, probably FileManager can be that adapter since it's in clang


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

I've realized that this patch covers too much stuff outside of clang and I have 
no idea how bad is to not memory map it.

"My hope is that we can get rid of this flag some day" - i'm not sure it's 
possible. For that we need some concept of user and system files in llvm 
similar to clang::SrcMgr::CharacteristicKind. But we can probably make an 
adapter for the MemoryBuffer in clang which will do the work at least in clang 
case.


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

https://reviews.llvm.org/D54995



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


[PATCH] D54996: [libclang] Fix clang_Cursor_isAnonymous

2018-11-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: nik, marcobubke.
Herald added a subscriber: arphaman.

Use the same logic as in TypePrinter::printTag to determine that the tag is 
anonymous and the separate check for namespaces.


https://reviews.llvm.org/D54996

Files:
  test/Index/print-type.cpp
  tools/c-index-test/c-index-test.c
  tools/libclang/CXType.cpp


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -1137,8 +1137,13 @@
   if (!clang_isDeclaration(C.kind))
 return 0;
   const Decl *D = cxcursor::getCursorDecl(C);
-  if (const RecordDecl *FD = dyn_cast_or_null(D))
-return FD->isAnonymousStructOrUnion();
+  if (const NamespaceDecl *ND = dyn_cast_or_null(D)) {
+return ND->isAnonymousNamespace();
+  } else if (const TagDecl *TD = dyn_cast_or_null(D)) {
+return TD->getTypedefNameForAnonDecl() == nullptr &&
+   TD->getIdentifier() == nullptr;
+  }
+
   return 0;
 }
 
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1563,13 +1563,14 @@
 if (numFields != 0) {
   printf(" [nbFields=%d]", numFields);
 }
-/* Print if it is an anonymous record. */
-{
-  unsigned isAnon = clang_Cursor_isAnonymous(cursor);
-  if (isAnon != 0) {
-printf(" [isAnon=%d]", isAnon);
-  }
-}
+  }
+}
+
+/* Print if it is an anonymous record or namespace. */
+{
+  unsigned isAnon = clang_Cursor_isAnonymous(cursor);
+  if (isAnon != 0) {
+printf(" [isAnon=%d]", isAnon);
   }
 }
 
Index: test/Index/print-type.cpp
===
--- test/Index/print-type.cpp
+++ test/Index/print-type.cpp
@@ -79,6 +79,17 @@
 
 outer::Foo parameter;
 outer::inner::Bar construct();
+
+class X {
+  struct { int a; };
+  class { public: int b; };
+  union { int c; int d;};
+  enum { Test };
+};
+
+namespace {
+  int a;
+}
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
@@ -188,3 +199,8 @@
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] 
[templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] 
[typekind=Void]] [isPOD=0]
 // CHECK: VarDecl=autoTemplPointer:78:6 (Definition) 
[type=Specialization &> *] [typekind=Auto] 
[canonicaltype=Specialization &> *] 
[canonicaltypekind=Pointer] [isPOD=1] 
[pointeetype=Specialization &>] [pointeekind=Record]
 // CHECK: CallExpr=Bar:17:3 [type=outer::inner::Bar] [typekind=Elaborated] 
[canonicaltype=outer::inner::Bar] [canonicaltypekind=Record] [args= 
[outer::Foo *] [Pointer]] [isPOD=0] [nbFields=3]
+// CHECK: StructDecl=:84:3 (Definition) [type=X::(anonymous struct at 
D:\code\qt_llvm\tools\clang\test\Index\print-type.cpp:84:3)] [typekind=Record] 
[isPOD=1] [nbFields=1] [isAnon=1]
+// CHECK: ClassDecl=:85:3 (Definition) [type=X::(anonymous class at 
D:\code\qt_llvm\tools\clang\test\Index\print-type.cpp:85:3)] [typekind=Record] 
[isPOD=1] [nbFields=1] [isAnon=1]
+// CHECK: UnionDecl=:86:3 (Definition) [type=X::(anonymous union at 
D:\code\qt_llvm\tools\clang\test\Index\print-type.cpp:86:3)] [typekind=Record] 
[isPOD=1] [nbFields=2] [isAnon=1]
+// CHECK: EnumDecl=:87:3 (Definition) [type=X::(anonymous enum at 
D:\code\qt_llvm\tools\clang\test\Index\print-type.cpp:87:3)] [typekind=Enum] 
[isPOD=1] [isAnon=1]
+// CHECK: Namespace=:90:11 (Definition) [type=] [typekind=Invalid] [isPOD=0] 
[isAnon=1]


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -1137,8 +1137,13 @@
   if (!clang_isDeclaration(C.kind))
 return 0;
   const Decl *D = cxcursor::getCursorDecl(C);
-  if (const RecordDecl *FD = dyn_cast_or_null(D))
-return FD->isAnonymousStructOrUnion();
+  if (const NamespaceDecl *ND = dyn_cast_or_null(D)) {
+return ND->isAnonymousNamespace();
+  } else if (const TagDecl *TD = dyn_cast_or_null(D)) {
+return TD->getTypedefNameForAnonDecl() == nullptr &&
+   TD->getIdentifier() == nullptr;
+  }
+
   return 0;
 }
 
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -1563,13 +1563,14 @@
 if (numFields != 0) {
   printf(" [nbFields=%d]", numFields);
 }
-/* Print if it is an anonymous record. */
-{
-  unsigned isAnon = clang_Cursor_isAnonymous(cursor);
-  if (isAnon != 0) {

[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@ilya-biryukov

I have the reported evidence but didn't yet have time to investigate myself.
This is probably caused by our upgrade to Clang-7 which shows that we can't 
rely on the aimed fixes like the one I mention (D47460 
).

Another option that I can suggest here is to remove all default isVolatile 
values at all, track all callers and specify the proper value in each case 
(ideally depending on the current flags). What do you think?


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

https://reviews.llvm.org/D54995



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


[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: ilya-biryukov, Dmitry.Kozhevnikov.

There are reported cases of non-system files being locked by libclang on 
Windows (and likely by other clients as well). I tried to solve that with 
https://reviews.llvm.org/D47460 but it might be not the only issue.
IsVolatile flag is there only for performance reasons so this change should not 
break any code


https://reviews.llvm.org/D54995

Files:
  include/llvm/Support/MemoryBuffer.h
  tools/clang/include/clang/Basic/FileManager.h
  tools/clang/include/clang/Basic/VirtualFileSystem.h
  tools/clang/lib/Basic/VirtualFileSystem.cpp


Index: tools/clang/lib/Basic/VirtualFileSystem.cpp
===
--- tools/clang/lib/Basic/VirtualFileSystem.cpp
+++ tools/clang/lib/Basic/VirtualFileSystem.cpp
@@ -193,7 +193,7 @@
   ErrorOr> getBuffer(const Twine ,
int64_t FileSize,
bool RequiresNullTerminator,
-   bool IsVolatile) override;
+   bool IsVolatile = true) 
override;
   std::error_code close() override;
 };
 
Index: tools/clang/include/clang/Basic/VirtualFileSystem.h
===
--- tools/clang/include/clang/Basic/VirtualFileSystem.h
+++ tools/clang/include/clang/Basic/VirtualFileSystem.h
@@ -120,7 +120,7 @@
   /// Get the contents of the file as a \p MemoryBuffer.
   virtual llvm::ErrorOr>
   getBuffer(const Twine , int64_t FileSize = -1,
-bool RequiresNullTerminator = true, bool IsVolatile = false) = 0;
+bool RequiresNullTerminator = true, bool IsVolatile = true) = 0;
 
   /// Closes the file.
   virtual std::error_code close() = 0;
@@ -234,7 +234,7 @@
   /// closes the file.
   llvm::ErrorOr>
   getBufferForFile(const Twine , int64_t FileSize = -1,
-   bool RequiresNullTerminator = true, bool IsVolatile = 
false);
+   bool RequiresNullTerminator = true, bool IsVolatile = true);
 
   /// Get a directory_iterator for \p Dir.
   /// \note The 'end' iterator is directory_iterator().
Index: tools/clang/include/clang/Basic/FileManager.h
===
--- tools/clang/include/clang/Basic/FileManager.h
+++ tools/clang/include/clang/Basic/FileManager.h
@@ -236,10 +236,10 @@
   /// Open the specified file as a MemoryBuffer, returning a new
   /// MemoryBuffer if successful, otherwise returning null.
   llvm::ErrorOr>
-  getBufferForFile(const FileEntry *Entry, bool isVolatile = false,
+  getBufferForFile(const FileEntry *Entry, bool isVolatile = true,
bool ShouldCloseOpenFile = true);
   llvm::ErrorOr>
-  getBufferForFile(StringRef Filename, bool isVolatile = false);
+  getBufferForFile(StringRef Filename, bool isVolatile = true);
 
   /// Get the 'stat' information for the given \p Path.
   ///
Index: include/llvm/Support/MemoryBuffer.h
===
--- include/llvm/Support/MemoryBuffer.h
+++ include/llvm/Support/MemoryBuffer.h
@@ -79,7 +79,7 @@
   /// while the user is editing/updating the file or if the file is on an NFS.
   static ErrorOr>
   getFile(const Twine , int64_t FileSize = -1,
-  bool RequiresNullTerminator = true, bool IsVolatile = false);
+  bool RequiresNullTerminator = true, bool IsVolatile = true);
 
   /// Read all of the specified file into a MemoryBuffer as a stream
   /// (i.e. until EOF reached). This is useful for special files that
@@ -92,7 +92,7 @@
   /// Since this is in the middle of a file, the buffer is not null terminated.
   static ErrorOr>
   getOpenFileSlice(int FD, const Twine , uint64_t MapSize,
-   int64_t Offset, bool IsVolatile = false);
+   int64_t Offset, bool IsVolatile = true);
 
   /// Given an already-open file descriptor, read the file and return a
   /// MemoryBuffer.
@@ -102,7 +102,7 @@
   /// while the user is editing/updating the file or if the file is on an NFS.
   static ErrorOr>
   getOpenFile(int FD, const Twine , uint64_t FileSize,
-  bool RequiresNullTerminator = true, bool IsVolatile = false);
+  bool RequiresNullTerminator = true, bool IsVolatile = true);
 
   /// Open the specified memory range as a MemoryBuffer. Note that InputData
   /// must be null terminated if RequiresNullTerminator is true.


Index: tools/clang/lib/Basic/VirtualFileSystem.cpp
===
--- tools/clang/lib/Basic/VirtualFileSystem.cpp
+++ tools/clang/lib/Basic/VirtualFileSystem.cpp
@@ -193,7 +193,7 @@
   ErrorOr> getBuffer(const Twine ,
int64_t FileSize,
bool RequiresNullTerminator,
- 

[PATCH] D54995: [MemoryBuffer] By default assume that all files are volatile to prevent unintended file locks

2018-11-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 175635.
yvvan added a comment.

VFS is moved to llvm in 8.0, update the diff


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

https://reviews.llvm.org/D54995

Files:
  include/llvm/Support/MemoryBuffer.h
  include/llvm/Support/VirtualFileSystem.h
  lib/Support/VirtualFileSystem.cpp
  tools/clang/include/clang/Basic/FileManager.h


Index: lib/Support/VirtualFileSystem.cpp
===
--- lib/Support/VirtualFileSystem.cpp
+++ lib/Support/VirtualFileSystem.cpp
@@ -193,7 +193,7 @@
   ErrorOr> getBuffer(const Twine ,
int64_t FileSize,
bool RequiresNullTerminator,
-   bool IsVolatile) override;
+   bool IsVolatile = true) 
override;
   std::error_code close() override;
 };
 
Index: include/llvm/Support/VirtualFileSystem.h
===
--- include/llvm/Support/VirtualFileSystem.h
+++ include/llvm/Support/VirtualFileSystem.h
@@ -120,7 +120,7 @@
   /// Get the contents of the file as a \p MemoryBuffer.
   virtual llvm::ErrorOr>
   getBuffer(const Twine , int64_t FileSize = -1,
-bool RequiresNullTerminator = true, bool IsVolatile = false) = 0;
+bool RequiresNullTerminator = true, bool IsVolatile = true) = 0;
 
   /// Closes the file.
   virtual std::error_code close() = 0;
@@ -234,7 +234,7 @@
   /// closes the file.
   llvm::ErrorOr>
   getBufferForFile(const Twine , int64_t FileSize = -1,
-   bool RequiresNullTerminator = true, bool IsVolatile = 
false);
+   bool RequiresNullTerminator = true, bool IsVolatile = true);
 
   /// Get a directory_iterator for \p Dir.
   /// \note The 'end' iterator is directory_iterator().
Index: tools/clang/include/clang/Basic/FileManager.h
===
--- tools/clang/include/clang/Basic/FileManager.h
+++ tools/clang/include/clang/Basic/FileManager.h
@@ -236,10 +236,10 @@
   /// Open the specified file as a MemoryBuffer, returning a new
   /// MemoryBuffer if successful, otherwise returning null.
   llvm::ErrorOr>
-  getBufferForFile(const FileEntry *Entry, bool isVolatile = false,
+  getBufferForFile(const FileEntry *Entry, bool isVolatile = true,
bool ShouldCloseOpenFile = true);
   llvm::ErrorOr>
-  getBufferForFile(StringRef Filename, bool isVolatile = false);
+  getBufferForFile(StringRef Filename, bool isVolatile = true);
 
   /// Get the 'stat' information for the given \p Path.
   ///
Index: include/llvm/Support/MemoryBuffer.h
===
--- include/llvm/Support/MemoryBuffer.h
+++ include/llvm/Support/MemoryBuffer.h
@@ -79,7 +79,7 @@
   /// while the user is editing/updating the file or if the file is on an NFS.
   static ErrorOr>
   getFile(const Twine , int64_t FileSize = -1,
-  bool RequiresNullTerminator = true, bool IsVolatile = false);
+  bool RequiresNullTerminator = true, bool IsVolatile = true);
 
   /// Read all of the specified file into a MemoryBuffer as a stream
   /// (i.e. until EOF reached). This is useful for special files that
@@ -92,7 +92,7 @@
   /// Since this is in the middle of a file, the buffer is not null terminated.
   static ErrorOr>
   getOpenFileSlice(int FD, const Twine , uint64_t MapSize,
-   int64_t Offset, bool IsVolatile = false);
+   int64_t Offset, bool IsVolatile = true);
 
   /// Given an already-open file descriptor, read the file and return a
   /// MemoryBuffer.
@@ -102,7 +102,7 @@
   /// while the user is editing/updating the file or if the file is on an NFS.
   static ErrorOr>
   getOpenFile(int FD, const Twine , uint64_t FileSize,
-  bool RequiresNullTerminator = true, bool IsVolatile = false);
+  bool RequiresNullTerminator = true, bool IsVolatile = true);
 
   /// Open the specified memory range as a MemoryBuffer. Note that InputData
   /// must be null terminated if RequiresNullTerminator is true.


Index: lib/Support/VirtualFileSystem.cpp
===
--- lib/Support/VirtualFileSystem.cpp
+++ lib/Support/VirtualFileSystem.cpp
@@ -193,7 +193,7 @@
   ErrorOr> getBuffer(const Twine ,
int64_t FileSize,
bool RequiresNullTerminator,
-   bool IsVolatile) override;
+   bool IsVolatile = true) override;
   std::error_code close() override;
 };
 
Index: include/llvm/Support/VirtualFileSystem.h
===
--- 

[PATCH] D54934: [libclang] Fix clang_Cursor_getNumArguments and clang_Cursor_getArgument for CXXConstructExpr

2018-11-27 Thread Ivan Donchevskii via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC347654: [libclang] Fix clang_Cursor_getNumArguments and 
clang_Cursor_getArgument for… (authored by yvvan, committed by ).

Repository:
  rC Clang

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

https://reviews.llvm.org/D54934

Files:
  test/Index/print-type.cpp
  tools/libclang/CXCursor.cpp


Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -1164,6 +1164,9 @@
 if (const CallExpr *CE = dyn_cast(E)) {
   return CE->getNumArgs();
 }
+if (const CXXConstructExpr *CE = dyn_cast(E)) {
+  return CE->getNumArgs();
+}
   }
 
   return -1;
@@ -1192,6 +1195,13 @@
   cxcursor::getCursorTU(C));
   }
 }
+if (const CXXConstructExpr *CE = dyn_cast(E)) {
+  if (i < CE->getNumArgs()) {
+return cxcursor::MakeCXCursor(CE->getArg(i),
+  getCursorDecl(C),
+  cxcursor::getCursorTU(C));
+  }
+}
   }
 
   return clang_getNullCursor();
Index: test/Index/print-type.cpp
===
--- test/Index/print-type.cpp
+++ test/Index/print-type.cpp
@@ -77,6 +77,8 @@
 
 auto autoTemplPointer = 
 
+outer::Foo parameter;
+outer::inner::Bar construct();
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
@@ -185,3 +187,4 @@
 // CHECK: DeclRefExpr=templRefParam:71:40 
[type=Specialization &>] [typekind=Unexposed] 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] 
[templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] 
[typekind=Void]] [isPOD=0]
 // CHECK: VarDecl=autoTemplPointer:78:6 (Definition) 
[type=Specialization &> *] [typekind=Auto] 
[canonicaltype=Specialization &> *] 
[canonicaltypekind=Pointer] [isPOD=1] 
[pointeetype=Specialization &>] [pointeekind=Record]
+// CHECK: CallExpr=Bar:17:3 [type=outer::inner::Bar] [typekind=Elaborated] 
[canonicaltype=outer::inner::Bar] [canonicaltypekind=Record] [args= 
[outer::Foo *] [Pointer]] [isPOD=0] [nbFields=3]


Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -1164,6 +1164,9 @@
 if (const CallExpr *CE = dyn_cast(E)) {
   return CE->getNumArgs();
 }
+if (const CXXConstructExpr *CE = dyn_cast(E)) {
+  return CE->getNumArgs();
+}
   }
 
   return -1;
@@ -1192,6 +1195,13 @@
   cxcursor::getCursorTU(C));
   }
 }
+if (const CXXConstructExpr *CE = dyn_cast(E)) {
+  if (i < CE->getNumArgs()) {
+return cxcursor::MakeCXCursor(CE->getArg(i),
+  getCursorDecl(C),
+  cxcursor::getCursorTU(C));
+  }
+}
   }
 
   return clang_getNullCursor();
Index: test/Index/print-type.cpp
===
--- test/Index/print-type.cpp
+++ test/Index/print-type.cpp
@@ -77,6 +77,8 @@
 
 auto autoTemplPointer = 
 
+outer::Foo parameter;
+outer::inner::Bar construct();
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] [isPOD=0]
@@ -185,3 +187,4 @@
 // CHECK: DeclRefExpr=templRefParam:71:40 [type=Specialization &>] [typekind=Unexposed] [templateargs/1= [type=Specialization &] [typekind=LValueReference]] [canonicaltype=Specialization &>] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization &] [typekind=LValueReference]] [isPOD=1]
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] [templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] [typekind=Void]] [isPOD=0]
 // CHECK: VarDecl=autoTemplPointer:78:6 (Definition) [type=Specialization &> *] [typekind=Auto] [canonicaltype=Specialization &> *] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=Specialization &>] [pointeekind=Record]
+// CHECK: CallExpr=Bar:17:3 [type=outer::inner::Bar] [typekind=Elaborated] [canonicaltype=outer::inner::Bar] [canonicaltypekind=Record] [args= [outer::Foo *] [Pointer]] [isPOD=0] 

[PATCH] D54934: [libclang] Fix clang_Cursor_getNumArguments and clang_Cursor_getArgument for CXXConstructExpr

2018-11-27 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: nik, marcobubke.
Herald added a subscriber: arphaman.

Constructors have the same methods for arguments as call expressions. Let's 
provide a way to get their arguments the same way.


https://reviews.llvm.org/D54934

Files:
  test/Index/print-type.cpp
  tools/libclang/CXCursor.cpp


Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -1146,6 +1146,9 @@
 if (const CallExpr *CE = dyn_cast(E)) {
   return CE->getNumArgs();
 }
+if (const CXXConstructExpr *CE = dyn_cast(E)) {
+  return CE->getNumArgs();
+}
   }
 
   return -1;
@@ -1174,6 +1177,13 @@
   cxcursor::getCursorTU(C));
   }
 }
+if (const CXXConstructExpr *CE = dyn_cast(E)) {
+  if (i < CE->getNumArgs()) {
+return cxcursor::MakeCXCursor(CE->getArg(i),
+  getCursorDecl(C),
+  cxcursor::getCursorTU(C));
+  }
+}
   }
 
   return clang_getNullCursor();
Index: test/Index/print-type.cpp
===
--- test/Index/print-type.cpp
+++ test/Index/print-type.cpp
@@ -77,6 +77,8 @@
 
 auto autoTemplPointer = 
 
+outer::Foo parameter;
+outer::inner::Bar construct();
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
@@ -185,3 +187,4 @@
 // CHECK: DeclRefExpr=templRefParam:71:40 
[type=Specialization &>] [typekind=Unexposed] 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] 
[templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] 
[typekind=Void]] [isPOD=0]
 // CHECK: VarDecl=autoTemplPointer:78:6 (Definition) 
[type=Specialization &> *] [typekind=Auto] 
[canonicaltype=Specialization &> *] 
[canonicaltypekind=Pointer] [isPOD=1] 
[pointeetype=Specialization &>] [pointeekind=Record]
+// CHECK: CallExpr=Bar:17:3 [type=outer::inner::Bar] [typekind=Elaborated] 
[canonicaltype=outer::inner::Bar] [canonicaltypekind=Record] [args= 
[outer::Foo *] [Pointer]] [isPOD=0] [nbFields=3]


Index: tools/libclang/CXCursor.cpp
===
--- tools/libclang/CXCursor.cpp
+++ tools/libclang/CXCursor.cpp
@@ -1146,6 +1146,9 @@
 if (const CallExpr *CE = dyn_cast(E)) {
   return CE->getNumArgs();
 }
+if (const CXXConstructExpr *CE = dyn_cast(E)) {
+  return CE->getNumArgs();
+}
   }
 
   return -1;
@@ -1174,6 +1177,13 @@
   cxcursor::getCursorTU(C));
   }
 }
+if (const CXXConstructExpr *CE = dyn_cast(E)) {
+  if (i < CE->getNumArgs()) {
+return cxcursor::MakeCXCursor(CE->getArg(i),
+  getCursorDecl(C),
+  cxcursor::getCursorTU(C));
+  }
+}
   }
 
   return clang_getNullCursor();
Index: test/Index/print-type.cpp
===
--- test/Index/print-type.cpp
+++ test/Index/print-type.cpp
@@ -77,6 +77,8 @@
 
 auto autoTemplPointer = 
 
+outer::Foo parameter;
+outer::inner::Bar construct();
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] [isPOD=0]
@@ -185,3 +187,4 @@
 // CHECK: DeclRefExpr=templRefParam:71:40 [type=Specialization &>] [typekind=Unexposed] [templateargs/1= [type=Specialization &] [typekind=LValueReference]] [canonicaltype=Specialization &>] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization &] [typekind=LValueReference]] [isPOD=1]
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] [templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] [typekind=Void]] [isPOD=0]
 // CHECK: VarDecl=autoTemplPointer:78:6 (Definition) [type=Specialization &> *] [typekind=Auto] [canonicaltype=Specialization &> *] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=Specialization &>] [pointeekind=Record]
+// CHECK: CallExpr=Bar:17:3 [type=outer::inner::Bar] [typekind=Elaborated] [canonicaltype=outer::inner::Bar] [canonicaltypekind=Record] [args= [outer::Foo *] [Pointer]] [isPOD=0] [nbFields=3]
___
cfe-commits mailing 

[PATCH] D53866: [Preamble] Fix preamble for circular #includes

2018-10-31 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

@ilya-biryukov 
As far as I understand the problem the same thing happens when you are in the 
header a.h which includes b.h and b.h includes a.h at the same time. So you get 
this recursion indirectly and very often because that's why include guards are 
there.


Repository:
  rC Clang

https://reviews.llvm.org/D53866



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


[PATCH] D53072: [clang-format] Introduce the flag which allows not to shrink lines

2018-10-19 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Do you know the better way to accomplish my aim than adding an option to 
libFormat? For example making a dependent library which serves a little 
different purpose than libFormat itself or something simpler?


https://reviews.llvm.org/D53072



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


[PATCH] D53072: [clang-format] Introduce the flag which allows not to shrink lines

2018-10-10 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: klimek, djasper, krasimir.

Currently there's no way to prevent to lines optimization even if you have 
intentionally put  to split the line.

In general case it's fine. So I would prefer to have such option which you can 
enable in special cases (for me it's an IDE related use case).


https://reviews.llvm.org/D53072

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -349,6 +349,14 @@
"  void funk() {}\n"
"};",
Style));
+
+  Style.KeepLineBreaksForNonEmptyLines = true;
+  Style.ColumnLimit = 0;
+  EXPECT_EQ("int foo(int a,\n"
+"int b) {}",
+format("int foo(int a,\n"
+   "int b) {}",
+   Style));
 }
 
 TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) {
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -672,7 +672,7 @@
   LineFormatter(ContinuationIndenter *Indenter, WhitespaceManager *Whitespaces,
 const FormatStyle ,
 UnwrappedLineFormatter *BlockFormatter)
-  : Indenter(Indenter), Whitespaces(Whitespaces), Style(Style),
+  : Indenter(Indenter), Style(Style), Whitespaces(Whitespaces),
 BlockFormatter(BlockFormatter) {}
   virtual ~LineFormatter() {}
 
@@ -760,10 +760,10 @@
   }
 
   ContinuationIndenter *Indenter;
+  const FormatStyle 
 
 private:
   WhitespaceManager *Whitespaces;
-  const FormatStyle 
   UnwrappedLineFormatter *BlockFormatter;
 };
 
@@ -786,7 +786,8 @@
 while (State.NextToken) {
   bool Newline =
   Indenter->mustBreak(State) ||
-  (Indenter->canBreak(State) && State.NextToken->NewlinesBefore > 0);
+  (State.NextToken->NewlinesBefore > 0 &&
+   (Style.KeepLineBreaksForNonEmptyLines || Indenter->canBreak(State)));
   unsigned Penalty = 0;
   formatChildren(State, Newline, /*DryRun=*/false, Penalty);
   Indenter->addTokenToState(State, Newline, /*DryRun=*/false);
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -416,6 +416,8 @@
Style.IndentWrappedFunctionNames);
 IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
+IO.mapOptional("KeepLineBreaksForNonEmptyLines",
+   Style.KeepLineBreaksForNonEmptyLines);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
@@ -676,6 +678,7 @@
   LLVMStyle.JavaScriptWrapImports = true;
   LLVMStyle.TabWidth = 8;
   LLVMStyle.MaxEmptyLinesToKeep = 1;
+  LLVMStyle.KeepLineBreaksForNonEmptyLines = false;
   LLVMStyle.KeepEmptyLinesAtTheStartOfBlocks = true;
   LLVMStyle.NamespaceIndentation = FormatStyle::NI_None;
   LLVMStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Auto;
@@ -741,6 +744,7 @@
   {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
   GoogleStyle.IndentCaseLabels = true;
+  GoogleStyle.KeepLineBreaksForNonEmptyLines = false;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
   GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
   GoogleStyle.ObjCSpaceAfterProperty = false;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -1160,6 +1160,16 @@
   /// \endcode
   bool JavaScriptWrapImports;
 
+  /// If true, no line breaks are optimized out (works only with ColumnLimit = 0)
+  /// \code
+  ///true:  false:
+  ///int foo(int a, vs. int foo(int a, int b) {
+  ///int b) {
+  ///  bar(); bar();
+  ///}  }
+  /// \endcode
+  bool KeepLineBreaksForNonEmptyLines;
+
   /// If true, the empty line at the start of blocks is kept.
   /// \code
   ///true:  false:
@@ -1726,6 +1736,7 @@
IndentWrappedFunctionNames == R.IndentWrappedFunctionNames &&
JavaScriptQuotes == R.JavaScriptQuotes &&
JavaScriptWrapImports == R.JavaScriptWrapImports &&
+   KeepLineBreaksForNonEmptyLines == R.KeepLineBreaksForNonEmptyLines &&
KeepEmptyLinesAtTheStartOfBlocks ==
 

[PATCH] D52261: [Sema] Generate completion fix-its for C code as well

2018-09-21 Thread Ivan Donchevskii via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC342721: [CodeComplete] Generate completion fix-its for C 
code as well (authored by yvvan, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D52261

Files:
  lib/Parse/ParseExpr.cpp
  test/CodeCompletion/member-access.c


Index: test/CodeCompletion/member-access.c
===
--- test/CodeCompletion/member-access.c
+++ test/CodeCompletion/member-access.c
@@ -10,3 +10,22 @@
   // CHECK-CC1: x
   // CHECK-CC1: y
   // CHECK-CC1: z
+}
+
+struct Point2 {
+  float x;
+};
+
+void test2(struct Point2 p) {
+  p->
+}
+
+void test3(struct Point2 *p) {
+  p.
+}
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits 
-code-completion-at=%s:20:6 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: x (requires fix-it: {20:4-20:6} to ".")
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits 
-code-completion-at=%s:24:5 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+// CHECK-CC3: x (requires fix-it: {24:4-24:5} to "->")
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1766,6 +1766,8 @@
 
 Expr *Base = LHS.get();
 Expr *CorrectedBase = CorrectedLHS.get();
+if (!CorrectedBase && !getLangOpts().CPlusPlus)
+  CorrectedBase = Base;
 
 // Code completion for a member access expression.
 Actions.CodeCompleteMemberReferenceExpr(


Index: test/CodeCompletion/member-access.c
===
--- test/CodeCompletion/member-access.c
+++ test/CodeCompletion/member-access.c
@@ -10,3 +10,22 @@
   // CHECK-CC1: x
   // CHECK-CC1: y
   // CHECK-CC1: z
+}
+
+struct Point2 {
+  float x;
+};
+
+void test2(struct Point2 p) {
+  p->
+}
+
+void test3(struct Point2 *p) {
+  p.
+}
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:20:6 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: x (requires fix-it: {20:4-20:6} to ".")
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:24:5 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+// CHECK-CC3: x (requires fix-it: {24:4-24:5} to "->")
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1766,6 +1766,8 @@
 
 Expr *Base = LHS.get();
 Expr *CorrectedBase = CorrectedLHS.get();
+if (!CorrectedBase && !getLangOpts().CPlusPlus)
+  CorrectedBase = Base;
 
 // Code completion for a member access expression.
 Actions.CodeCompleteMemberReferenceExpr(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52261: [Sema] Generate completion fix-its for C code as well

2018-09-21 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 166407.
yvvan added a comment.

Provide CorrectedBase = Base for C code


https://reviews.llvm.org/D52261

Files:
  lib/Parse/ParseExpr.cpp
  test/CodeCompletion/member-access.c


Index: test/CodeCompletion/member-access.c
===
--- test/CodeCompletion/member-access.c
+++ test/CodeCompletion/member-access.c
@@ -10,3 +10,22 @@
   // CHECK-CC1: x
   // CHECK-CC1: y
   // CHECK-CC1: z
+}
+
+struct Point2 {
+  float x;
+};
+
+void test2(struct Point2 p) {
+  p->
+}
+
+void test3(struct Point2 *p) {
+  p.
+}
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits 
-code-completion-at=%s:20:6 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: x (requires fix-it: {20:4-20:6} to ".")
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits 
-code-completion-at=%s:24:5 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+// CHECK-CC3: x (requires fix-it: {24:4-24:5} to "->")
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1738,6 +1738,8 @@
 
 Expr *Base = LHS.get();
 Expr *CorrectedBase = CorrectedLHS.get();
+if (!CorrectedBase && !getLangOpts().CPlusPlus)
+  CorrectedBase = Base;
 
 // Code completion for a member access expression.
 Actions.CodeCompleteMemberReferenceExpr(


Index: test/CodeCompletion/member-access.c
===
--- test/CodeCompletion/member-access.c
+++ test/CodeCompletion/member-access.c
@@ -10,3 +10,22 @@
   // CHECK-CC1: x
   // CHECK-CC1: y
   // CHECK-CC1: z
+}
+
+struct Point2 {
+  float x;
+};
+
+void test2(struct Point2 p) {
+  p->
+}
+
+void test3(struct Point2 *p) {
+  p.
+}
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:20:6 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: x (requires fix-it: {20:4-20:6} to ".")
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:24:5 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+// CHECK-CC3: x (requires fix-it: {24:4-24:5} to "->")
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -1738,6 +1738,8 @@
 
 Expr *Base = LHS.get();
 Expr *CorrectedBase = CorrectedLHS.get();
+if (!CorrectedBase && !getLangOpts().CPlusPlus)
+  CorrectedBase = Base;
 
 // Code completion for a member access expression.
 Actions.CodeCompleteMemberReferenceExpr(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52261: [Sema] Generate completion fix-its for C code as well

2018-09-21 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

You're right actually. The fix is much simpler than I expected :)


https://reviews.llvm.org/D52261



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


[PATCH] D52261: [Sema] Generate completion fix-its for C code as well

2018-09-20 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

I tried that first but did not I find a way just to copy an expression (we 
basically need the same expr for such case). Do you know how to properly 
generate a copy of expression or some other way to get the same expression?


https://reviews.llvm.org/D52261



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


[PATCH] D52261: [Sema] Generate completion fix-its for C code as well

2018-09-19 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 166110.
yvvan added a comment.

Test is added


https://reviews.llvm.org/D52261

Files:
  lib/Sema/SemaCodeComplete.cpp
  test/CodeCompletion/member-access.c

Index: test/CodeCompletion/member-access.c
===
--- test/CodeCompletion/member-access.c
+++ test/CodeCompletion/member-access.c
@@ -10,3 +10,22 @@
   // CHECK-CC1: x
   // CHECK-CC1: y
   // CHECK-CC1: z
+}
+
+struct Point2 {
+  float x;
+};
+
+void test2(struct Point2 p) {
+  p->
+}
+
+void test3(struct Point2 *p) {
+  p.
+}
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:20:6 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: x (requires fix-it: {20:4-20:6} to ".")
+
+// RUN: %clang_cc1 -fsyntax-only -code-completion-with-fixits -code-completion-at=%s:24:5 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+// CHECK-CC3: x (requires fix-it: {24:4-24:5} to "->")
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -4037,39 +4037,33 @@
   QualType ConvertedBaseType = ConvertedBase.get()->getType();
 
   enum CodeCompletionContext::Kind contextKind;
+  QualType TypeWithoutPointer = ConvertedBaseType;
 
   if (IsArrow) {
-if (const PointerType *Ptr = ConvertedBaseType->getAs())
-  ConvertedBaseType = Ptr->getPointeeType();
+if (const PointerType *Ptr = TypeWithoutPointer->getAs())
+  TypeWithoutPointer = Ptr->getPointeeType();
   }
 
   if (IsArrow) {
 contextKind = CodeCompletionContext::CCC_ArrowMemberAccess;
   } else {
-if (ConvertedBaseType->isObjCObjectPointerType() ||
-ConvertedBaseType->isObjCObjectOrInterfaceType()) {
+if (TypeWithoutPointer->isObjCObjectPointerType() ||
+TypeWithoutPointer->isObjCObjectOrInterfaceType()) {
   contextKind = CodeCompletionContext::CCC_ObjCPropertyAccess;
 } else {
   contextKind = CodeCompletionContext::CCC_DotMemberAccess;
 }
   }
 
-  CodeCompletionContext CCContext(contextKind, ConvertedBaseType);
+  CodeCompletionContext CCContext(contextKind, TypeWithoutPointer);
   ResultBuilder Results(*this, CodeCompleter->getAllocator(),
 CodeCompleter->getCodeCompletionTUInfo(), CCContext,
 ::IsMember);
 
-  auto DoCompletion = [&](Expr *Base, bool IsArrow, Optional AccessOpFixIt) -> bool {
-if (!Base)
+  auto DoCompletion = [&](QualType BaseType, bool IsArrow,
+  Optional AccessOpFixIt) -> bool {
+if (BaseType.isNull())
   return false;
-
-ExprResult ConvertedBase = PerformMemberExprBaseConversion(Base, IsArrow);
-if (ConvertedBase.isInvalid())
-  return false;
-Base = ConvertedBase.get();
-
-QualType BaseType = Base->getType();
-
 if (IsArrow) {
   if (const PointerType *Ptr = BaseType->getAs())
 BaseType = Ptr->getPointeeType();
@@ -4140,13 +4134,28 @@
 
   Results.EnterNewScope();
 
-  bool CompletionSucceded = DoCompletion(Base, IsArrow, None);
+  bool CompletionSucceded = DoCompletion(ConvertedBaseType, IsArrow, None);
   if (CodeCompleter->includeFixIts()) {
-const CharSourceRange OpRange =
-CharSourceRange::getTokenRange(OpLoc, OpLoc);
-CompletionSucceded |= DoCompletion(
-OtherOpBase, !IsArrow,
-FixItHint::CreateReplacement(OpRange, IsArrow ? "." : "->"));
+QualType ConvertedOtherBaseType;
+if (!OtherOpBase) {
+  const Type *BaseTypePtr = ConvertedBaseType.getTypePtrOrNull();
+  // Proceed if the initial type is pointer but IsArrow is false or the
+  // other way around.
+  if (BaseTypePtr && IsArrow != BaseTypePtr->isPointerType())
+ConvertedOtherBaseType = ConvertedBaseType;
+} else {
+  ExprResult ConvertedOtherBase =
+  PerformMemberExprBaseConversion(OtherOpBase, !IsArrow);
+  if (!ConvertedOtherBase.isInvalid())
+ConvertedOtherBaseType = ConvertedOtherBase.get()->getType();
+}
+if (!ConvertedOtherBaseType.isNull()) {
+  const CharSourceRange OpRange =
+  CharSourceRange::getTokenRange(OpLoc, OpLoc);
+  CompletionSucceded |= DoCompletion(
+  ConvertedOtherBaseType, !IsArrow,
+  FixItHint::CreateReplacement(OpRange, IsArrow ? "." : "->"));
+}
   }
 
   Results.ExitScope();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52261: [Sema] Generate completion fix-its for C code as well

2018-09-19 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: nik, ilya-biryukov.

Current completion fix-its approach does not provide OtherOpBase for C code. 
But we can easily proceed in this case taking the original Base type.


https://reviews.llvm.org/D52261

Files:
  lib/Sema/SemaCodeComplete.cpp


Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -4037,39 +4037,33 @@
   QualType ConvertedBaseType = ConvertedBase.get()->getType();
 
   enum CodeCompletionContext::Kind contextKind;
+  QualType TypeWithoutPointer = ConvertedBaseType;
 
   if (IsArrow) {
-if (const PointerType *Ptr = ConvertedBaseType->getAs())
-  ConvertedBaseType = Ptr->getPointeeType();
+if (const PointerType *Ptr = TypeWithoutPointer->getAs())
+  TypeWithoutPointer = Ptr->getPointeeType();
   }
 
   if (IsArrow) {
 contextKind = CodeCompletionContext::CCC_ArrowMemberAccess;
   } else {
-if (ConvertedBaseType->isObjCObjectPointerType() ||
-ConvertedBaseType->isObjCObjectOrInterfaceType()) {
+if (TypeWithoutPointer->isObjCObjectPointerType() ||
+TypeWithoutPointer->isObjCObjectOrInterfaceType()) {
   contextKind = CodeCompletionContext::CCC_ObjCPropertyAccess;
 } else {
   contextKind = CodeCompletionContext::CCC_DotMemberAccess;
 }
   }
 
-  CodeCompletionContext CCContext(contextKind, ConvertedBaseType);
+  CodeCompletionContext CCContext(contextKind, TypeWithoutPointer);
   ResultBuilder Results(*this, CodeCompleter->getAllocator(),
 CodeCompleter->getCodeCompletionTUInfo(), CCContext,
 ::IsMember);
 
-  auto DoCompletion = [&](Expr *Base, bool IsArrow, Optional 
AccessOpFixIt) -> bool {
-if (!Base)
+  auto DoCompletion = [&](QualType BaseType, bool IsArrow,
+  Optional AccessOpFixIt) -> bool {
+if (BaseType.isNull())
   return false;
-
-ExprResult ConvertedBase = PerformMemberExprBaseConversion(Base, IsArrow);
-if (ConvertedBase.isInvalid())
-  return false;
-Base = ConvertedBase.get();
-
-QualType BaseType = Base->getType();
-
 if (IsArrow) {
   if (const PointerType *Ptr = BaseType->getAs())
 BaseType = Ptr->getPointeeType();
@@ -4140,13 +4134,28 @@
 
   Results.EnterNewScope();
 
-  bool CompletionSucceded = DoCompletion(Base, IsArrow, None);
+  bool CompletionSucceded = DoCompletion(ConvertedBaseType, IsArrow, None);
   if (CodeCompleter->includeFixIts()) {
-const CharSourceRange OpRange =
-CharSourceRange::getTokenRange(OpLoc, OpLoc);
-CompletionSucceded |= DoCompletion(
-OtherOpBase, !IsArrow,
-FixItHint::CreateReplacement(OpRange, IsArrow ? "." : "->"));
+QualType ConvertedOtherBaseType;
+if (!OtherOpBase) {
+  const Type *BaseTypePtr = ConvertedBaseType.getTypePtrOrNull();
+  // Proceed if the initial type is pointer but IsArrow is false or the
+  // other way around.
+  if (BaseTypePtr && IsArrow != BaseTypePtr->isPointerType())
+ConvertedOtherBaseType = ConvertedBaseType;
+} else {
+  ExprResult ConvertedOtherBase =
+  PerformMemberExprBaseConversion(OtherOpBase, !IsArrow);
+  if (!ConvertedOtherBase.isInvalid())
+ConvertedOtherBaseType = ConvertedOtherBase.get()->getType();
+}
+if (!ConvertedOtherBaseType.isNull()) {
+  const CharSourceRange OpRange =
+  CharSourceRange::getTokenRange(OpLoc, OpLoc);
+  CompletionSucceded |= DoCompletion(
+  ConvertedOtherBaseType, !IsArrow,
+  FixItHint::CreateReplacement(OpRange, IsArrow ? "." : "->"));
+}
   }
 
   Results.ExitScope();


Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -4037,39 +4037,33 @@
   QualType ConvertedBaseType = ConvertedBase.get()->getType();
 
   enum CodeCompletionContext::Kind contextKind;
+  QualType TypeWithoutPointer = ConvertedBaseType;
 
   if (IsArrow) {
-if (const PointerType *Ptr = ConvertedBaseType->getAs())
-  ConvertedBaseType = Ptr->getPointeeType();
+if (const PointerType *Ptr = TypeWithoutPointer->getAs())
+  TypeWithoutPointer = Ptr->getPointeeType();
   }
 
   if (IsArrow) {
 contextKind = CodeCompletionContext::CCC_ArrowMemberAccess;
   } else {
-if (ConvertedBaseType->isObjCObjectPointerType() ||
-ConvertedBaseType->isObjCObjectOrInterfaceType()) {
+if (TypeWithoutPointer->isObjCObjectPointerType() ||
+TypeWithoutPointer->isObjCObjectOrInterfaceType()) {
   contextKind = CodeCompletionContext::CCC_ObjCPropertyAccess;
 } else {
   contextKind = CodeCompletionContext::CCC_DotMemberAccess;
 }
   }
 
-  CodeCompletionContext CCContext(contextKind, ConvertedBaseType);
+  CodeCompletionContext CCContext(contextKind, 

[PATCH] D51281: [libclang] Return the proper pointee type for 'auto' deduced to pointer

2018-09-07 Thread Ivan Donchevskii via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL341656: [libclang] Return the proper pointee type for 
auto deduced to pointer (authored by yvvan, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D51281?vs=164151=164399#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D51281

Files:
  cfe/trunk/test/Index/print-type.cpp
  cfe/trunk/tools/libclang/CXType.cpp


Index: cfe/trunk/tools/libclang/CXType.cpp
===
--- cfe/trunk/tools/libclang/CXType.cpp
+++ cfe/trunk/tools/libclang/CXType.cpp
@@ -442,6 +442,7 @@
   if (!TP)
 return MakeCXType(QualType(), GetTU(CT));
 
+try_again:
   switch (TP->getTypeClass()) {
 case Type::Pointer:
   T = cast(TP)->getPointeeType();
@@ -459,6 +460,12 @@
 case Type::MemberPointer:
   T = cast(TP)->getPointeeType();
   break;
+case Type::Auto:
+case Type::DeducedTemplateSpecialization:
+  TP = cast(TP)->getDeducedType().getTypePtrOrNull();
+  if (TP)
+goto try_again;
+  break;
 default:
   T = QualType();
   break;
Index: cfe/trunk/test/Index/print-type.cpp
===
--- cfe/trunk/test/Index/print-type.cpp
+++ cfe/trunk/test/Index/print-type.cpp
@@ -75,6 +75,8 @@
 template using C = T;
 using baz = C>;
 
+auto autoTemplPointer = 
+
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
@@ -182,3 +184,4 @@
 // CHECK: UnexposedExpr=templRefParam:71:40 [type=const 
Specialization &>] [typekind=Unexposed] const 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=const Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: DeclRefExpr=templRefParam:71:40 
[type=Specialization &>] [typekind=Unexposed] 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] 
[templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] 
[typekind=Void]] [isPOD=0]
+// CHECK: VarDecl=autoTemplPointer:78:6 (Definition) 
[type=Specialization &> *] [typekind=Auto] 
[canonicaltype=Specialization &> *] 
[canonicaltypekind=Pointer] [isPOD=1] 
[pointeetype=Specialization &>] [pointeekind=Record]


Index: cfe/trunk/tools/libclang/CXType.cpp
===
--- cfe/trunk/tools/libclang/CXType.cpp
+++ cfe/trunk/tools/libclang/CXType.cpp
@@ -442,6 +442,7 @@
   if (!TP)
 return MakeCXType(QualType(), GetTU(CT));
 
+try_again:
   switch (TP->getTypeClass()) {
 case Type::Pointer:
   T = cast(TP)->getPointeeType();
@@ -459,6 +460,12 @@
 case Type::MemberPointer:
   T = cast(TP)->getPointeeType();
   break;
+case Type::Auto:
+case Type::DeducedTemplateSpecialization:
+  TP = cast(TP)->getDeducedType().getTypePtrOrNull();
+  if (TP)
+goto try_again;
+  break;
 default:
   T = QualType();
   break;
Index: cfe/trunk/test/Index/print-type.cpp
===
--- cfe/trunk/test/Index/print-type.cpp
+++ cfe/trunk/test/Index/print-type.cpp
@@ -75,6 +75,8 @@
 template using C = T;
 using baz = C>;
 
+auto autoTemplPointer = 
+
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] [isPOD=0]
@@ -182,3 +184,4 @@
 // CHECK: UnexposedExpr=templRefParam:71:40 [type=const Specialization &>] [typekind=Unexposed] const [templateargs/1= [type=Specialization &] [typekind=LValueReference]] [canonicaltype=const Specialization &>] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization &] [typekind=LValueReference]] [isPOD=1]
 // CHECK: DeclRefExpr=templRefParam:71:40 [type=Specialization &>] [typekind=Unexposed] [templateargs/1= [type=Specialization &] [typekind=LValueReference]] [canonicaltype=Specialization &>] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization &] [typekind=LValueReference]] [isPOD=1]
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] [templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] [typekind=Void]] [isPOD=0]
+// CHECK: VarDecl=autoTemplPointer:78:6 

[PATCH] D51281: [libclang] Return the proper pointee type for 'auto' deduced to pointer

2018-09-06 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 164151.
yvvan added a comment.

Comments addressed


https://reviews.llvm.org/D51281

Files:
  test/Index/print-type.cpp
  tools/libclang/CXType.cpp


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -427,6 +427,7 @@
   if (!TP)
 return MakeCXType(QualType(), GetTU(CT));
 
+try_again:
   switch (TP->getTypeClass()) {
 case Type::Pointer:
   T = cast(TP)->getPointeeType();
@@ -444,6 +445,12 @@
 case Type::MemberPointer:
   T = cast(TP)->getPointeeType();
   break;
+case Type::Auto:
+case Type::DeducedTemplateSpecialization:
+  TP = cast(TP)->getDeducedType().getTypePtrOrNull();
+  if (TP)
+goto try_again;
+  break;
 default:
   T = QualType();
   break;
Index: test/Index/print-type.cpp
===
--- test/Index/print-type.cpp
+++ test/Index/print-type.cpp
@@ -75,6 +75,8 @@
 template using C = T;
 using baz = C>;
 
+auto autoTemplPointer = 
+
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] 
[isPOD=0]
@@ -182,3 +184,4 @@
 // CHECK: UnexposedExpr=templRefParam:71:40 [type=const 
Specialization &>] [typekind=Unexposed] const 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=const Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: DeclRefExpr=templRefParam:71:40 
[type=Specialization &>] [typekind=Unexposed] 
[templateargs/1= [type=Specialization &] [typekind=LValueReference]] 
[canonicaltype=Specialization &>] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization 
&] [typekind=LValueReference]] [isPOD=1]
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] 
[templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] 
[canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] 
[typekind=Void]] [isPOD=0]
+// CHECK: VarDecl=autoTemplPointer:78:6 (Definition) 
[type=Specialization &> *] [typekind=Auto] 
[canonicaltype=Specialization &> *] 
[canonicaltypekind=Pointer] [isPOD=1] 
[pointeetype=Specialization &>] [pointeekind=Record]


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -427,6 +427,7 @@
   if (!TP)
 return MakeCXType(QualType(), GetTU(CT));
 
+try_again:
   switch (TP->getTypeClass()) {
 case Type::Pointer:
   T = cast(TP)->getPointeeType();
@@ -444,6 +445,12 @@
 case Type::MemberPointer:
   T = cast(TP)->getPointeeType();
   break;
+case Type::Auto:
+case Type::DeducedTemplateSpecialization:
+  TP = cast(TP)->getDeducedType().getTypePtrOrNull();
+  if (TP)
+goto try_again;
+  break;
 default:
   T = QualType();
   break;
Index: test/Index/print-type.cpp
===
--- test/Index/print-type.cpp
+++ test/Index/print-type.cpp
@@ -75,6 +75,8 @@
 template using C = T;
 using baz = C>;
 
+auto autoTemplPointer = 
+
 // RUN: c-index-test -test-print-type %s -std=c++14 | FileCheck %s
 // CHECK: Namespace=outer:1:11 (Definition) [type=] [typekind=Invalid] [isPOD=0]
 // CHECK: ClassTemplate=Foo:4:8 (Definition) [type=] [typekind=Invalid] [isPOD=0]
@@ -182,3 +184,4 @@
 // CHECK: UnexposedExpr=templRefParam:71:40 [type=const Specialization &>] [typekind=Unexposed] const [templateargs/1= [type=Specialization &] [typekind=LValueReference]] [canonicaltype=const Specialization &>] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization &] [typekind=LValueReference]] [isPOD=1]
 // CHECK: DeclRefExpr=templRefParam:71:40 [type=Specialization &>] [typekind=Unexposed] [templateargs/1= [type=Specialization &] [typekind=LValueReference]] [canonicaltype=Specialization &>] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=Specialization &] [typekind=LValueReference]] [isPOD=1]
 // CHECK: TypeAliasDecl=baz:76:7 (Definition) [type=baz] [typekind=Typedef] [templateargs/1= [type=A] [typekind=Unexposed]] [canonicaltype=A] [canonicaltypekind=Record] [canonicaltemplateargs/1= [type=void] [typekind=Void]] [isPOD=0]
+// CHECK: VarDecl=autoTemplPointer:78:6 (Definition) [type=Specialization &> *] [typekind=Auto] [canonicaltype=Specialization &> *] [canonicaltypekind=Pointer] [isPOD=1] [pointeetype=Specialization &>] [pointeekind=Record]
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51281: [libclang] Return the proper pointee type for 'auto' deduced to pointer

2018-08-29 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

You are completely right! Thanks!
I did not think that -test-print-type also checks for the pointee.


https://reviews.llvm.org/D51281



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


[PATCH] D51281: [libclang] Return the proper pointee type for 'auto' deduced to pointer

2018-08-27 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.
yvvan added reviewers: erikjv, arphaman, michaelwu.

Currently the resulting type is always invalid in such case.


https://reviews.llvm.org/D51281

Files:
  tools/libclang/CXType.cpp


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -427,6 +427,7 @@
   if (!TP)
 return MakeCXType(QualType(), GetTU(CT));
 
+try_again:
   switch (TP->getTypeClass()) {
 case Type::Pointer:
   T = cast(TP)->getPointeeType();
@@ -444,6 +445,11 @@
 case Type::MemberPointer:
   T = cast(TP)->getPointeeType();
   break;
+case Type::Auto:
+  TP = cast(TP)->getDeducedType().getTypePtrOrNull();
+  if (TP)
+goto try_again;
+  break;
 default:
   T = QualType();
   break;


Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -427,6 +427,7 @@
   if (!TP)
 return MakeCXType(QualType(), GetTU(CT));
 
+try_again:
   switch (TP->getTypeClass()) {
 case Type::Pointer:
   T = cast(TP)->getPointeeType();
@@ -444,6 +445,11 @@
 case Type::MemberPointer:
   T = cast(TP)->getPointeeType();
   break;
+case Type::Auto:
+  TP = cast(TP)->getDeducedType().getTypePtrOrNull();
+  if (TP)
+goto try_again;
+  break;
 default:
   T = QualType();
   break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40481: [libclang] Fix cursors for arguments of Subscript and Call operators

2018-08-23 Thread Ivan Donchevskii via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL340521: [libclang] Fix cursors for arguments of Subscript 
and Call operators (authored by yvvan, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D40481?vs=124341=162145#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40481

Files:
  cfe/trunk/test/Index/annotate-operator-call-expr.cpp
  cfe/trunk/tools/libclang/CIndex.cpp

Index: cfe/trunk/test/Index/annotate-operator-call-expr.cpp
===
--- cfe/trunk/test/Index/annotate-operator-call-expr.cpp
+++ cfe/trunk/test/Index/annotate-operator-call-expr.cpp
@@ -0,0 +1,84 @@
+struct Foo {
+  int operator[](int key);
+  int operator()(int key = 2);
+};
+
+void testFoo(Foo foo, int index) {
+  foo();
+  foo(index);
+
+  foo[index];
+  foo[index + index];
+
+  foo[foo[index]];
+  foo[foo() + foo[index]];
+  foo[foo(index) + foo[index]];
+}
+
+// RUN: c-index-test -test-annotate-tokens=%s:7:1:7:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK1
+// CHECK1: Identifier: "foo" [7:3 - 7:6] DeclRefExpr=foo:6:18
+// CHECK1: Punctuation: "(" [7:6 - 7:7] DeclRefExpr=operator():3:7 RefName=[7:6 - 7:7] RefName=[7:7 - 7:8]
+// CHECK1: Punctuation: ")" [7:7 - 7:8] DeclRefExpr=operator():3:7 RefName=[7:6 - 7:7] RefName=[7:7 - 7:8]
+// CHECK1: Punctuation: ";" [7:8 - 7:9] CompoundStmt=
+
+// RUN: c-index-test -test-annotate-tokens=%s:8:1:8:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK2
+// CHECK2: Punctuation: "(" [8:6 - 8:7] DeclRefExpr=operator():3:7 RefName=[8:6 - 8:7] RefName=[8:12 - 8:13]
+// CHECK2: Identifier: "index" [8:7 - 8:12] DeclRefExpr=index:6:27
+// CHECK2: Punctuation: ")" [8:12 - 8:13] DeclRefExpr=operator():3:7 RefName=[8:6 - 8:7] RefName=[8:12 - 8:13]
+// CHECK2: Punctuation: ";" [8:13 - 8:14] CompoundStmt=
+
+// RUN: c-index-test -test-annotate-tokens=%s:10:1:10:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK3
+// CHECK3: Identifier: "foo" [10:3 - 10:6] DeclRefExpr=foo:6:18
+// CHECK3: Punctuation: "[" [10:6 - 10:7] DeclRefExpr=operator[]:2:7 RefName=[10:6 - 10:7] RefName=[10:12 - 10:13]
+// CHECK3: Identifier: "index" [10:7 - 10:12] DeclRefExpr=index:6:27
+// CHECK3: Punctuation: "]" [10:12 - 10:13] DeclRefExpr=operator[]:2:7 RefName=[10:6 - 10:7] RefName=[10:12 - 10:13]
+// CHECK3: Punctuation: ";" [10:13 - 10:14] CompoundStmt=
+
+// RUN: c-index-test -test-annotate-tokens=%s:11:1:11:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK4
+// CHECK4: Identifier: "foo" [11:3 - 11:6] DeclRefExpr=foo:6:18
+// CHECK4: Punctuation: "[" [11:6 - 11:7] DeclRefExpr=operator[]:2:7 RefName=[11:6 - 11:7] RefName=[11:20 - 11:21]
+// CHECK4: Identifier: "index" [11:7 - 11:12] DeclRefExpr=index:6:27
+// CHECK4: Punctuation: "+" [11:13 - 11:14] BinaryOperator=
+// CHECK4: Identifier: "index" [11:15 - 11:20] DeclRefExpr=index:6:27
+// CHECK4: Punctuation: "]" [11:20 - 11:21] DeclRefExpr=operator[]:2:7 RefName=[11:6 - 11:7] RefName=[11:20 - 11:21]
+// CHECK4: Punctuation: ";" [11:21 - 11:22] CompoundStmt=
+
+// RUN: c-index-test -test-annotate-tokens=%s:13:1:13:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK5
+// CHECK5: Identifier: "foo" [13:3 - 13:6] DeclRefExpr=foo:6:18
+// CHECK5: Punctuation: "[" [13:6 - 13:7] DeclRefExpr=operator[]:2:7 RefName=[13:6 - 13:7] RefName=[13:17 - 13:18]
+// CHECK5: Identifier: "foo" [13:7 - 13:10] DeclRefExpr=foo:6:18
+// CHECK5: Punctuation: "[" [13:10 - 13:11] DeclRefExpr=operator[]:2:7 RefName=[13:10 - 13:11] RefName=[13:16 - 13:17]
+// CHECK5: Identifier: "index" [13:11 - 13:16] DeclRefExpr=index:6:27
+// CHECK5: Punctuation: "]" [13:16 - 13:17] DeclRefExpr=operator[]:2:7 RefName=[13:10 - 13:11] RefName=[13:16 - 13:17]
+// CHECK5: Punctuation: "]" [13:17 - 13:18] DeclRefExpr=operator[]:2:7 RefName=[13:6 - 13:7] RefName=[13:17 - 13:18]
+// CHECK5: Punctuation: ";" [13:18 - 13:19] CompoundStmt=
+
+// RUN: c-index-test -test-annotate-tokens=%s:14:1:14:100 %s -std=c++11 -Wno-unused-value | FileCheck %s -check-prefix=CHECK6
+// CHECK6: Identifier: "foo" [14:3 - 14:6] DeclRefExpr=foo:6:18
+// CHECK6: Punctuation: "[" [14:6 - 14:7] DeclRefExpr=operator[]:2:7 RefName=[14:6 - 14:7] RefName=[14:25 - 14:26]
+// CHECK6: Identifier: "foo" [14:7 - 14:10] DeclRefExpr=foo:6:18
+// CHECK6: Punctuation: "(" [14:10 - 14:11] DeclRefExpr=operator():3:7 RefName=[14:10 - 14:11] RefName=[14:11 - 14:12]
+// CHECK6: Punctuation: ")" [14:11 - 14:12] DeclRefExpr=operator():3:7 RefName=[14:10 - 14:11] RefName=[14:11 - 14:12]
+// CHECK6: Punctuation: "+" [14:13 - 14:14] BinaryOperator=
+// CHECK6: Identifier: "foo" [14:15 - 14:18] DeclRefExpr=foo:6:18
+// CHECK6: Punctuation: "[" [14:18 - 14:19] DeclRefExpr=operator[]:2:7 RefName=[14:18 - 14:19] RefName=[14:24 - 14:25]
+// CHECK6: Identifier: "index" [14:19 - 14:24] DeclRefExpr=operator[]:2:7 

[PATCH] D40481: [libclang] Fix cursors for arguments of Subscript and Call operators

2018-08-23 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan accepted this revision.
yvvan added a comment.
This revision is now accepted and ready to land.

Let's proceed with this one. I really see that it's going to be useful.


https://reviews.llvm.org/D40481



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


[PATCH] D49794: [libclang] Allow skipping warnings from all included files

2018-07-31 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

In https://reviews.llvm.org/D49794#1182272, @ilya-biryukov wrote:

> In https://reviews.llvm.org/D49794#1182220, @yvvan wrote:
>
> > And we already saw, that -isystem is not the best choice for that.
>
>
> Are you referring to the file-locking on Windows? 
>  Any other reasons why the -isystem trick might be non-ideal?


File locking is the first one. Another one comes with "plugin mode" of tidy.

>> And by the way - clang-tidy has this filtering in consumer which does not 
>> exist in it's plugin-mode so it spits all system diagnostics all the time...
> 
> I would still argue against adding this option in the current form to the 
> compiler. I don't see how that might be useful to non-clang-tidy, 
> non-editor-integration users.
> 
> What's the 'plugin mode' of clang-tidy? I don't seem to able to Google it :-)

Clang tidy is not only a standalone tool but also a plugin. It's almost never 
used this way (but we do that in Qt Creator to combine it with Clazy) and it 
also seems that some of the recent checks are added only to standalone tool 
(which is easy to fix).
Being loaded into clang as plugin it does not support most of clang-tidy 
command line options and is not able to filter system includes. I'm not sure 
it's possible to fix both of these issues (and probably some other).


https://reviews.llvm.org/D49794



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


[PATCH] D49794: [libclang] Allow skipping warnings from all included files

2018-07-31 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Anyways, if c++ part does not seem relevant I'm fine if we only have libclang 
part from https://reviews.llvm.org/D48116.

BTW I don't remember if you answered something to my suggestion of adding flag 
-ithird-party as an alternative to -isystem which does not lock files and helps 
to filter diagnostics, etc.


https://reviews.llvm.org/D49794



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


[PATCH] D49794: [libclang] Allow skipping warnings from all included files

2018-07-31 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

And we already saw, that -isystem is not the best choice for that. And by the 
way - clang-tidy has this filtering in consumer which does not exist in it's 
plugin-mode so it spits all system diagnostics all the time...


https://reviews.llvm.org/D49794



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


[PATCH] D49794: [libclang] Allow skipping warnings from all included files

2018-07-31 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

I already mentioned in the review inherited by this one that this way covers 
also loaded plugins with different consumers. So let's assume that driver loads 
clang-tidy and some other plugins and runs over each file in the project.
It makes sense not to include clang-tidy diagnostics coming from headers, at 
least for third-party headers (you can still run clang over specific headers 
themselves to get diagnostics for them).


https://reviews.llvm.org/D49794



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


[PATCH] D49794: [libclang] Allow skipping warnings from all included files

2018-07-31 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan updated this revision to Diff 158211.
yvvan added a comment.

Restore missing tests


https://reviews.llvm.org/D49794

Files:
  include/clang-c/Index.h
  include/clang/Basic/Diagnostic.h
  include/clang/Basic/DiagnosticOptions.def
  include/clang/Driver/Options.td
  lib/Basic/DiagnosticIDs.cpp
  lib/Basic/Warnings.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Frontend/Inputs/header-with-warning.h
  test/Frontend/warnings-ignore-from-includes.cpp
  test/Index/ignore-warnings-from-headers.cpp
  test/Index/ignore-warnings-from-headers.h
  tools/c-index-test/c-index-test.c
  tools/libclang/CIndex.cpp

Index: test/Index/ignore-warnings-from-headers.h
===
--- /dev/null
+++ test/Index/ignore-warnings-from-headers.h
@@ -0,0 +1 @@
+void f(int unusedInHeader) {}
Index: test/Index/ignore-warnings-from-headers.cpp
===
--- /dev/null
+++ test/Index/ignore-warnings-from-headers.cpp
@@ -0,0 +1,7 @@
+#include "ignore-warnings-from-headers.h"
+
+void g(int unusedInMainFile) {}
+
+// RUN: env CINDEXTEST_IGNORE_NONERRORS_FROM_INCLUDED_FILES=1 c-index-test -test-load-source function %s -Wunused-parameter 2>&1 | FileCheck %s
+// CHECK-NOT: warning: unused parameter 'unusedInHeader'
+// CHECK: warning: unused parameter 'unusedInMainFile'
Index: test/Frontend/warnings-ignore-from-includes.cpp
===
--- /dev/null
+++ test/Frontend/warnings-ignore-from-includes.cpp
@@ -0,0 +1,7 @@
+#include "header-with-warning.h"
+
+static void f1(void) {}
+
+// RUN: %clang_cc1 -I%S/Inputs/ -Wunused-function -fsuppress-non-errors-from-included-files %s 2>&1 | FileCheck %s
+// CHECK-NOT: warning: unused function 'f0'
+// CHECK: warning: unused function 'f1'
Index: test/Frontend/Inputs/header-with-warning.h
===
--- /dev/null
+++ test/Frontend/Inputs/header-with-warning.h
@@ -0,0 +1 @@
+static void f0(void) {}
Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -3398,6 +3398,9 @@
   if (options & CXTranslationUnit_KeepGoing)
 Diags->setSuppressAfterFatalError(false);
 
+  if (options & CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles)
+  Diags->setSuppressNonErrorsFromIncludedFiles(true);
+
   // Recover resources if we crash before exiting this function.
   llvm::CrashRecoveryContextCleanupRegistrar >
Index: tools/c-index-test/c-index-test.c
===
--- tools/c-index-test/c-index-test.c
+++ tools/c-index-test/c-index-test.c
@@ -84,6 +84,8 @@
 options |= CXTranslationUnit_KeepGoing;
   if (getenv("CINDEXTEST_LIMIT_SKIP_FUNCTION_BODIES_TO_PREAMBLE"))
 options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble;
+  if (getenv("CINDEXTEST_IGNORE_NONERRORS_FROM_INCLUDED_FILES"))
+options |= CXTranslationUnit_IgnoreNonErrorsFromIncludedFiles;
 
   return options;
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1223,6 +1223,8 @@
   Args.getLastArg(OPT_diagnostic_serialized_file, OPT__serialize_diags))
 Opts.DiagnosticSerializationFile = A->getValue();
   Opts.IgnoreWarnings = Args.hasArg(OPT_w);
+  Opts.SuppressNonErrorsFromIncludedFiles =
+  Args.hasArg(OPT_fsuppress_non_errors_from_included_files);
   Opts.NoRewriteMacros = Args.hasArg(OPT_Wno_rewrite_macros);
   Opts.Pedantic = Args.hasArg(OPT_pedantic);
   Opts.PedanticErrors = Args.hasArg(OPT_pedantic_errors);
Index: lib/Basic/Warnings.cpp
===
--- lib/Basic/Warnings.cpp
+++ lib/Basic/Warnings.cpp
@@ -46,6 +46,7 @@
   bool ReportDiags) {
   Diags.setSuppressSystemWarnings(true);  // Default to -Wno-system-headers
   Diags.setIgnoreAllWarnings(Opts.IgnoreWarnings);
+  Diags.setSuppressNonErrorsFromIncludedFiles(Opts.SuppressNonErrorsFromIncludedFiles);
   Diags.setShowOverloads(Opts.getShowOverloads());
 
   Diags.setElideType(Opts.ElideType);
Index: lib/Basic/DiagnosticIDs.cpp
===
--- lib/Basic/DiagnosticIDs.cpp
+++ lib/Basic/DiagnosticIDs.cpp
@@ -477,6 +477,14 @@
   Result = diag::Severity::Fatal;
   }
 
+  // If requested, ignore non-errors from all included files.
+  if (Diag.SuppressNonErrorsFromIncludedFiles &&
+  Result <= diag::Severity::Warning && Loc.isValid() &&
+  !Diag.getSourceManager().isInMainFile(
+  Diag.getSourceManager().getExpansionLoc(Loc))) {
+return diag::Severity::Ignored;
+  }
+
   // Custom diagnostics always are emitted in system headers.
   bool ShowInSystemHeader =
   

[PATCH] D49063: [libclang 1/8] Add support for ObjCObjectType

2018-07-26 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

I'm mostly fine with your set of patches. Let me double check and we can get it 
in.


https://reviews.llvm.org/D49063



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


  1   2   3   >