[PATCH] D93986: [clang-format] Add the possibility to align assignments spanning empty lines or comments

2021-01-17 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Thie LGTM, just to check a few nits

  /usr/bin/sphinx-build -n ./docs ./html
  /clang/llvm-project/clang/docs/ClangFormatStyleOptions.rst:330: WARNING: 
Bullet list ends without a blank line; unexpected unindent.
  /clang/llvm-project/clang/docs/ClangFormatStyleOptions.rst:404: WARNING: 
Bullet list ends without a blank line; unexpected unindent.
  /clang/llvm-project/clang/docs/ClangFormatStyleOptions.rst:479: WARNING: 
Bullet list ends without a blank line; unexpected unindent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93986

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


[PATCH] D93986: [clang-format] Add the possibility to align assignments spanning empty lines or comments

2021-01-17 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Thank you for changing the dump_style to make this clearer

F15070790: image.png 

F15070797: image.png 

F15070803: image.png 

F15070810: image.png 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93986

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


[PATCH] D93986: [clang-format] Add the possibility to align assignments spanning empty lines or comments

2021-01-17 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added inline comments.



Comment at: clang/include/clang/Format/Format.h:103
   ///
-  /// This will align C/C++ preprocessor macros of consecutive lines.
-  /// Will result in formattings like
+  /// ``Consecutive`` will result in formattings like
   /// \code

Nit: maybe a colon on the end what do you think?



Comment at: clang/include/clang/Format/Format.h:159
+  ///Same as ACS_Consecutive, but also spans over lines only containing
+  ///comments and empty lines, e.g.,
+  ///\code

Nit: no need for a comma I think


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93986

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


[clang] 9af0386 - [clang-format] Revert e9e6e3b34a8e

2021-01-17 Thread via cfe-commits

Author: mydeveloperday
Date: 2021-01-17T11:07:31Z
New Revision: 9af03864df746aa9a9cf3573da952ce6c5d902cd

URL: 
https://github.com/llvm/llvm-project/commit/9af03864df746aa9a9cf3573da952ce6c5d902cd
DIFF: 
https://github.com/llvm/llvm-project/commit/9af03864df746aa9a9cf3573da952ce6c5d902cd.diff

LOG: [clang-format] Revert e9e6e3b34a8e

Reverting {D92753} due to issues with #pragma indentation in #ifdef/endif 
structure

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/UnwrappedLineParser.h
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index c58bb1af7ae6..8eee6187d0c6 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2181,30 +2181,6 @@ the configuration (without a prefix: ``Auto``).
 
 
 
-**IndentPragmas** (``bool``)
-  Indent pragmas
-
-  When ``false``, pragmas are flushed left or follow IndentPPDirectives.
-  When ``true``, pragmas are indented to the current scope level.
-
-  .. code-block:: c++
-
-false:  true:
-#pragma once   vs   #pragma once
-void foo() {void foo() {
-#pragma omp simd  #pragma omp simd
-  for (int i=0;i<10;i++) {for (int i=0;i<10;i++) {
-#pragma omp simd#pragma omp simd
-for (int i=0;i<10;i++) {for (int i=0;i<10;i++) {
-}   }
-#if 1   #if 1
-#pragma omp simd#pragma omp simd
-for (int i=0;i<10;i++) {for (int i=0;i<10;i++) {
-}   }
-#endif  #endif
-  }   }
-}   }
-
 **IndentRequires** (``bool``)
   Indent the requires clause in a template
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index c6a9818a8940..6b3fb8164a28 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -1792,29 +1792,6 @@ struct FormatStyle {
   /// \endcode
   bool IndentGotoLabels;
 
-  /// Indent pragmas
-  ///
-  /// When ``false``, pragmas are flushed left or follow IndentPPDirectives.
-  /// When ``true``, pragmas are indented to the current scope level.
-  /// \code
-  ///   false:  true:
-  ///   #pragma once   vs   #pragma once
-  ///   void foo() {void foo() {
-  ///   #pragma omp simd  #pragma omp simd
-  /// for (int i=0;i<10;i++) {for (int i=0;i<10;i++) {
-  ///   #pragma omp simd#pragma omp simd
-  ///   for (int i=0;i<10;i++) {for (int i=0;i<10;i++) {
-  ///   }   }
-  ///   #if 1   #if 1
-  ///   #pragma omp simd#pragma omp simd
-  ///   for (int i=0;i<10;i++) {for (int i=0;i<10;i++) {
-  ///   }   }
-  ///   #endif  #endif
-  /// }   }
-  ///   }   }
-  /// \endcode
-  bool IndentPragmas;
-
   /// Options for indenting preprocessor directives.
   enum PPDirectiveIndentStyle : unsigned char {
 /// Does not indent any directives.
@@ -2790,7 +2767,6 @@ struct FormatStyle {
IndentCaseLabels == R.IndentCaseLabels &&
IndentCaseBlocks == R.IndentCaseBlocks &&
IndentGotoLabels == R.IndentGotoLabels &&
-   IndentPragmas == R.IndentPragmas &&
IndentPPDirectives == R.IndentPPDirectives &&
IndentExternBlock == R.IndentExternBlock &&
IndentRequires == R.IndentRequires && IndentWidth == R.IndentWidth 
&&

diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 9e15c87509ac..9db42b6c4a70 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -589,12 +589,6 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
State.Line->Type == LT_ImportStatement)) {
 Spaces += State.FirstIndent;
 
-bool isPragmaLine =
-State.Line->First->startsSequence(tok::hash, tok::pp_pragma);
-// If indenting pragmas remove

[PATCH] D92753: [clang-format] Add IndentPragma style to eliminate common clang-format off scenario

2021-01-17 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Sorry but due to the following issue raised by @RatTac , I'm reverting this 
prior to the LLVM 12 branch out so I can work on it further.

I also think this would impact #pragma's in any ifdef code which I envisage 
would be significant.

  #if defined(WIN32)
  #pragma warning(disable : 4005) // NOT indented even though 
IndentPPDirectives: BeforeHash
  #endif


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92753

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


[clang] 00dc97f - [clang-format] PR48594 BraceWrapping: SplitEmptyRecord ignored for templates

2021-01-17 Thread via cfe-commits

Author: mydeveloperday
Date: 2021-01-17T11:14:33Z
New Revision: 00dc97f16708aad67834552285c0af01b37303d6

URL: 
https://github.com/llvm/llvm-project/commit/00dc97f16708aad67834552285c0af01b37303d6
DIFF: 
https://github.com/llvm/llvm-project/commit/00dc97f16708aad67834552285c0af01b37303d6.diff

LOG: [clang-format] PR48594 BraceWrapping: SplitEmptyRecord ignored for 
templates

https://bugs.llvm.org/show_bug.cgi?id=48594

Empty or small templates were not being treated the same way as small classes 
especially when SplitEmptyRecord was set to true

This revision aims to help this by identifying a case when we should try not to 
merge the lines together

Reviewed By: curdeius, JohelEGP

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/FormatTestCSharp.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index d8f718306a45..13c5fdc8bd64 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -248,6 +248,11 @@ class LineJoiner {
 return !Style.BraceWrapping.SplitEmptyRecord && EmptyBlock
? tryMergeSimpleBlock(I, E, Limit)
: 0;
+
+  if (Tok && Tok->is(tok::kw_template) &&
+  Style.BraceWrapping.SplitEmptyRecord && EmptyBlock) {
+return 0;
+  }
 }
 
 // FIXME: TheLine->Level != 0 might or might not be the right check to do.
@@ -355,6 +360,30 @@ class LineJoiner {
 if (TheLine->First->is(tok::l_brace) && I != AnnotatedLines.begin() &&
 I[-1]->First->isOneOf(tok::kw_case, tok::kw_default))
   return 0;
+
+// Don't merge an empty template class or struct if SplitEmptyRecords
+// is defined.
+if (Style.BraceWrapping.SplitEmptyRecord &&
+TheLine->Last->is(tok::l_brace) && I != AnnotatedLines.begin() &&
+I[-1]->Last) {
+  const FormatToken *Previous = I[-1]->Last;
+  if (Previous) {
+if (Previous->is(tok::comment))
+  Previous = Previous->getPreviousNonComment();
+if (Previous) {
+  if (Previous->is(tok::greater))
+return 0;
+  if (Previous->is(tok::identifier)) {
+const FormatToken *PreviousPrevious =
+Previous->getPreviousNonComment();
+if (PreviousPrevious &&
+PreviousPrevious->isOneOf(tok::kw_class, tok::kw_struct))
+  return 0;
+  }
+}
+  }
+}
+
 // Try to merge a block with left brace wrapped that wasn't yet covered
 if (TheLine->Last->is(tok::l_brace)) {
   return !Style.BraceWrapping.AfterFunction ||

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index acfd229e200b..9fd41dbe7556 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9891,6 +9891,71 @@ TEST_F(FormatTest, SplitEmptyClass) {
"{\n"
"} Foo_t;",
Style);
+
+  Style.BraceWrapping.SplitEmptyRecord = true;
+  Style.BraceWrapping.AfterStruct = true;
+  verifyFormat("class rep\n"
+   "{\n"
+   "};",
+   Style);
+  verifyFormat("struct rep\n"
+   "{\n"
+   "};",
+   Style);
+  verifyFormat("template  class rep\n"
+   "{\n"
+   "};",
+   Style);
+  verifyFormat("template  struct rep\n"
+   "{\n"
+   "};",
+   Style);
+  verifyFormat("class rep\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+  verifyFormat("struct rep\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+  verifyFormat("template  class rep\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+  verifyFormat("template  struct rep\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+  verifyFormat("template  class rep // Foo\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+  verifyFormat("template  struct rep // Bar\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+
+  verifyFormat("template  class rep\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+
+  verifyFormat("template  class rep>\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+  verifyFormat("template  class rep>\n"
+   "{\n"
+   "};",
+   Style);
 }
 
 TEST_F(FormatTest, SplitEmptyStruct) {


[PATCH] D93839: [clang-format] PR48594 BraceWrapping: SplitEmptyRecord ignored for templates

2021-01-17 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG00dc97f16708: [clang-format] PR48594 BraceWrapping: 
SplitEmptyRecord ignored for templates (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93839

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -835,25 +835,27 @@
 TEST_F(FormatTestCSharp, CSharpGenericTypeConstraints) {
   FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);
 
-  verifyFormat(R"(//
-class ItemFactory
-where T : new() {})",
+  EXPECT_TRUE(Style.BraceWrapping.SplitEmptyRecord);
+
+  verifyFormat("class ItemFactory\n"
+   "where T : new() {\n"
+   "}",
Style);
 
-  verifyFormat(R"(//
-class Dictionary
-where TKey : IComparable
-where TVal : IMyInterface {
-  public void MyMethod(T t)
-  where T : IMyInterface {
-doThing();
-  }
-})",
+  verifyFormat("class Dictionary\n"
+   "where TKey : IComparable\n"
+   "where TVal : IMyInterface {\n"
+   "  public void MyMethod(T t)\n"
+   "  where T : IMyInterface {\n"
+   "doThing();\n"
+   "  }\n"
+   "}",
Style);
 
-  verifyFormat(R"(//
-class ItemFactory
-where T : new(), IAnInterface, IAnotherInterface, IAnotherInterfaceStill {})",
+  verifyFormat("class ItemFactory\n"
+   "where T : new(), IAnInterface, IAnotherInterface, "
+   "IAnotherInterfaceStill {\n"
+   "}",
Style);
 
   Style.ColumnLimit = 50; // Force lines to be wrapped.
@@ -862,7 +864,8 @@
 where T : new(),
   IAnInterface,
   IAnotherInterface,
-  IAnotherInterfaceStill {})",
+  IAnotherInterfaceStill {
+})",
Style);
 
   // In other languages `where` can be used as a normal identifier.
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -9891,6 +9891,71 @@
"{\n"
"} Foo_t;",
Style);
+
+  Style.BraceWrapping.SplitEmptyRecord = true;
+  Style.BraceWrapping.AfterStruct = true;
+  verifyFormat("class rep\n"
+   "{\n"
+   "};",
+   Style);
+  verifyFormat("struct rep\n"
+   "{\n"
+   "};",
+   Style);
+  verifyFormat("template  class rep\n"
+   "{\n"
+   "};",
+   Style);
+  verifyFormat("template  struct rep\n"
+   "{\n"
+   "};",
+   Style);
+  verifyFormat("class rep\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+  verifyFormat("struct rep\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+  verifyFormat("template  class rep\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+  verifyFormat("template  struct rep\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+  verifyFormat("template  class rep // Foo\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+  verifyFormat("template  struct rep // Bar\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+
+  verifyFormat("template  class rep\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+
+  verifyFormat("template  class rep>\n"
+   "{\n"
+   "  int x;\n"
+   "};",
+   Style);
+  verifyFormat("template  class rep>\n"
+   "{\n"
+   "};",
+   Style);
 }
 
 TEST_F(FormatTest, SplitEmptyStruct) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -248,6 +248,11 @@
 return !Style.BraceWrapping.SplitEmptyRecord && EmptyBlock
? tryMergeSimpleBlock(I, E, Limit)
: 0;
+
+  if (Tok && Tok->is(tok::kw_template) &&
+  Style.BraceWrapping.SplitEmptyRecord && EmptyBlock) {
+return 0;
+  }
 }
 
 // FIXME: TheLine->Level != 0 might or might not be the right check to do.
@@ -355,6 +360,30

[PATCH] D93776: [clang-format] Add StatementAttributeLikeMacros option

2021-01-17 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.

Please address the "not done" comment (regarding the sorting), but other than 
that its LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93776

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


[PATCH] D91949: [clang-format] Add BeforeStructInitialization option in BraceWrapping configuration

2021-01-17 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay requested changes to this revision.
MyDeveloperDay added a comment.
This revision now requires changes to proceed.

I think the revision whilst it does what is needed to structs doesn't address 
the many other times this forms appear. I think we need something a little more 
extensive. It can't just be when a line starts with struct


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

https://reviews.llvm.org/D91949

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


[clang-tools-extra] 0f9908a - [clangd] Use empty() instead of size()>0

2021-01-17 Thread Utkarsh Saxena via cfe-commits

Author: Utkarsh Saxena
Date: 2021-01-17T15:13:01+01:00
New Revision: 0f9908a7c9c547f2675e00f88cc11ec02ca28e8d

URL: 
https://github.com/llvm/llvm-project/commit/0f9908a7c9c547f2675e00f88cc11ec02ca28e8d
DIFF: 
https://github.com/llvm/llvm-project/commit/0f9908a7c9c547f2675e00f88cc11ec02ca28e8d.diff

LOG: [clangd] Use empty() instead of size()>0

Added: 


Modified: 
clang-tools-extra/clangd/Quality.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Quality.cpp 
b/clang-tools-extra/clangd/Quality.cpp
index 7b6a76584778..f076b44f5743 100644
--- a/clang-tools-extra/clangd/Quality.cpp
+++ b/clang-tools-extra/clangd/Quality.cpp
@@ -512,7 +512,7 @@ evaluateDecisionForest(const SymbolQualitySignals &Quality,
   E.setIsNameInContext(NumMatch > 0);
   E.setNumNameInContext(NumMatch);
   E.setFractionNameInContext(
-  Relevance.ContextWords && Relevance.ContextWords->size() > 0
+  Relevance.ContextWords && Relevance.ContextWords->empty()
   ? NumMatch * 1.0 / Relevance.ContextWords->size()
   : 0);
   E.setIsInBaseClass(Relevance.InBaseClass);



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


[clang-tools-extra] 9abbc05 - [clangd] Use !empty() instead of size()>0

2021-01-17 Thread Utkarsh Saxena via cfe-commits

Author: Utkarsh Saxena
Date: 2021-01-17T15:26:40+01:00
New Revision: 9abbc050974ff117b79e8e049c52c56db3f49aec

URL: 
https://github.com/llvm/llvm-project/commit/9abbc050974ff117b79e8e049c52c56db3f49aec
DIFF: 
https://github.com/llvm/llvm-project/commit/9abbc050974ff117b79e8e049c52c56db3f49aec.diff

LOG: [clangd] Use !empty() instead of size()>0

Added: 


Modified: 
clang-tools-extra/clangd/Quality.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Quality.cpp 
b/clang-tools-extra/clangd/Quality.cpp
index f076b44f5743..27b959ecacb3 100644
--- a/clang-tools-extra/clangd/Quality.cpp
+++ b/clang-tools-extra/clangd/Quality.cpp
@@ -512,7 +512,7 @@ evaluateDecisionForest(const SymbolQualitySignals &Quality,
   E.setIsNameInContext(NumMatch > 0);
   E.setNumNameInContext(NumMatch);
   E.setFractionNameInContext(
-  Relevance.ContextWords && Relevance.ContextWords->empty()
+  Relevance.ContextWords && !Relevance.ContextWords->empty()
   ? NumMatch * 1.0 / Relevance.ContextWords->size()
   : 0);
   E.setIsInBaseClass(Relevance.InBaseClass);



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


[PATCH] D93829: [clangd] Support outgoing calls in call hierarchy

2021-01-17 Thread Quentin Chateau via Phabricator via cfe-commits
qchateau added a comment.

You're right, I probably got carried away for the sake of completeness. 
Allocating extra memory for a feature nobody is going to use is definitely not 
worth it. Though maybe we can take advantage of what's already been done and if 
we remove the `RevRefs` map, and pay the full price of iterating all refs when 
`refersTo` is called, we still have this feature. Although slower, it shouldn't 
take more than a few 100's of milliseconds even on a big project. Which means 
the feature is usable, at least for most small to medium sized projects, at no 
extra cost for people who do not use it.

Would this be acceptable ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93829

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


[PATCH] D94875: [clangd] ignore parallelism level for quick tasks

2021-01-17 Thread Quentin Chateau via Phabricator via cfe-commits
qchateau created this revision.
qchateau added a reviewer: sammccall.
Herald added subscribers: usaxena95, kadircet, arphaman, javed.absar.
qchateau requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

This allows quick tasks without dependencies that
need to run fast to run ASAP. This is mostly useful
for code formatting.



This fixes something that's been annoying me:

- Open your IDE workspace and its 20 open files
- Clangd spends 5 minutes parsing it all
- In the meantime you start to work
- Save a file, trigger format-on-save, which hangs because clangd is busy
- You're stuck waiting until clangd is done parsing your files before the 
formatting and save takes place


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94875

Files:
  clang-tools-extra/clangd/ClangdServer.cpp
  clang-tools-extra/clangd/TUScheduler.cpp
  clang-tools-extra/clangd/TUScheduler.h


Index: clang-tools-extra/clangd/TUScheduler.h
===
--- clang-tools-extra/clangd/TUScheduler.h
+++ clang-tools-extra/clangd/TUScheduler.h
@@ -244,6 +244,13 @@
   void run(llvm::StringRef Name, llvm::StringRef Path,
llvm::unique_function Action);
 
+  /// Similar to run, except the task is expected to be quick.
+  /// This function will not honor AsyncThreadsCount (except
+  /// if threading is disabled with AsyncThreadsCount=0)
+  /// It is intended to run quick tasks that need to run ASAP
+  void quickRun(llvm::StringRef Name, llvm::StringRef Path,
+llvm::unique_function Action);
+
   /// Defines how a runWithAST action is implicitly cancelled by other actions.
   enum ASTActionInvalidation {
 /// The request will run unless explicitly cancelled.
@@ -316,10 +323,14 @@
   void profile(MemoryTree &MT) const;
 
 private:
+  void runWithSemaphore(llvm::StringRef Name, llvm::StringRef Path,
+llvm::unique_function Action, Semaphore &Sem);
+
   const GlobalCompilationDatabase &CDB;
   Options Opts;
   std::unique_ptr Callbacks; // not nullptr
   Semaphore Barrier;
+  Semaphore QuickRunBarrier;
   llvm::StringMap> Files;
   std::unique_ptr IdleASTs;
   // None when running tasks synchronously and non-None when running tasks
Index: clang-tools-extra/clangd/TUScheduler.cpp
===
--- clang-tools-extra/clangd/TUScheduler.cpp
+++ clang-tools-extra/clangd/TUScheduler.cpp
@@ -1248,7 +1248,7 @@
 : CDB(CDB), Opts(Opts),
   Callbacks(Callbacks ? move(Callbacks)
   : std::make_unique()),
-  Barrier(Opts.AsyncThreadsCount),
+  Barrier(Opts.AsyncThreadsCount), QuickRunBarrier(1),
   IdleASTs(
   std::make_unique(Opts.RetentionPolicy.MaxRetainedASTs)) {
   // Avoid null checks everywhere.
@@ -1322,14 +1322,27 @@
 
 void TUScheduler::run(llvm::StringRef Name, llvm::StringRef Path,
   llvm::unique_function Action) {
+  runWithSemaphore(Name, Path, std::move(Action), Barrier);
+}
+
+void TUScheduler::quickRun(llvm::StringRef Name, llvm::StringRef Path,
+   llvm::unique_function Action) {
+  // Use QuickRunBarrier to serialize quick tasks: we are ignoring
+  // the parallelism level set by the user, don't abuse it
+  runWithSemaphore(Name, Path, std::move(Action), QuickRunBarrier);
+}
+
+void TUScheduler::runWithSemaphore(llvm::StringRef Name, llvm::StringRef Path,
+   llvm::unique_function Action,
+   Semaphore &Sem) {
   if (!PreambleTasks) {
 WithContext WithProvidedContext(Opts.ContextProvider(Path));
 return Action();
   }
-  PreambleTasks->runAsync(Name, [this, Ctx = Context::current().clone(),
+  PreambleTasks->runAsync(Name, [this, &Sem, Ctx = Context::current().clone(),
  Path(Path.str()),
  Action = std::move(Action)]() mutable {
-std::lock_guard BarrierLock(Barrier);
+std::lock_guard BarrierLock(Sem);
 WithContext WC(std::move(Ctx));
 WithContext WithProvidedContext(Opts.ContextProvider(Path));
 Action();
Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -351,7 +351,7 @@
   Result.push_back(replacementToEdit(Code, R));
 return CB(Result);
   };
-  WorkScheduler.run("FormatOnType", File, std::move(Action));
+  WorkScheduler.quickRun("FormatOnType", File, std::move(Action));
 }
 
 void ClangdServer::prepareRename(PathRef File, Position Pos,
@@ -579,7 +579,7 @@
 tooling::calculateRangesAfterReplacements(IncludeReplaces, Ranges),
 File)));
   };
-  WorkScheduler.run("Format", File, std::move(Action));
+  WorkScheduler.quickRun("Format", Fil

[PATCH] D94876: Remove TypedMatcherOps from VariantValue

2021-01-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It provides no features or advantage over ASTNodeKind-based handling.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94876

Files:
  clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
  clang/lib/ASTMatchers/Dynamic/VariantValue.cpp


Index: clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
===
--- clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
+++ clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
@@ -59,6 +59,11 @@
   return Matcher.canConvertTo(NodeKind);
 }
 
+DynTypedMatcher VariantMatcher::MatcherOps::convertMatcher(
+const DynTypedMatcher &Matcher) const {
+  return Matcher.dynCastTo(NodeKind);
+}
+
 llvm::Optional
 VariantMatcher::MatcherOps::constructVariadicOperator(
 DynTypedMatcher::VariadicOperator Op,
Index: clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
===
--- clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
+++ clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
@@ -100,8 +100,7 @@
 
 /// Convert \p Matcher the destination type and return it as a new
 /// DynTypedMatcher.
-virtual DynTypedMatcher
-convertMatcher(const DynTypedMatcher &Matcher) const = 0;
+DynTypedMatcher convertMatcher(const DynTypedMatcher &Matcher) const;
 
 /// Constructs a variadic typed matcher from \p InnerMatchers.
 /// Will try to convert each inner matcher to the destination type and
@@ -110,9 +109,6 @@
 constructVariadicOperator(DynTypedMatcher::VariadicOperator Op,
   ArrayRef InnerMatchers) const;
 
-  protected:
-~MatcherOps() = default;
-
   private:
 ASTNodeKind NodeKind;
   };
@@ -174,8 +170,12 @@
   /// that can, the result would be ambiguous and false is returned.
   template 
   bool hasTypedMatcher() const {
+return hasTypedMatcher(ASTNodeKind::getFromNodeKind());
+  }
+
+  bool hasTypedMatcher(ASTNodeKind NK) const {
 if (!Value) return false;
-return Value->getTypedMatcher(TypedMatcherOps()).hasValue();
+return Value->getTypedMatcher(MatcherOps(NK)).hasValue();
   }
 
   /// Determines if the contained matcher can be converted to \p Kind.
@@ -197,10 +197,15 @@
   template 
   ast_matchers::internal::Matcher getTypedMatcher() const {
 assert(hasTypedMatcher() && "hasTypedMatcher() == false");
-return Value->getTypedMatcher(TypedMatcherOps())
+return 
Value->getTypedMatcher(MatcherOps(ASTNodeKind::getFromNodeKind()))
 ->template convertTo();
   }
 
+  DynTypedMatcher getTypedMatcher(ASTNodeKind NK) const {
+assert(hasTypedMatcher(NK) && "hasTypedMatcher(NK) == false");
+return *Value->getTypedMatcher(MatcherOps(NK));
+  }
+
   /// String representation of the type of the value.
   ///
   /// If the underlying matcher is a polymorphic one, the string will show all
@@ -211,7 +216,6 @@
   explicit VariantMatcher(std::shared_ptr Value)
   : Value(std::move(Value)) {}
 
-  template  struct TypedMatcherOps;
 
   class SinglePayload;
   class PolymorphicPayload;
@@ -220,17 +224,6 @@
   std::shared_ptr Value;
 };
 
-template 
-struct VariantMatcher::TypedMatcherOps final : VariantMatcher::MatcherOps {
-  TypedMatcherOps() : MatcherOps(ASTNodeKind::getFromNodeKind()) {}
-  typedef ast_matchers::internal::Matcher MatcherT;
-
-  DynTypedMatcher
-  convertMatcher(const DynTypedMatcher &Matcher) const override {
-return DynTypedMatcher(Matcher.convertTo());
-  }
-};
-
 /// Variant value class.
 ///
 /// Basically, a tagged union with value type semantics.


Index: clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
===
--- clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
+++ clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
@@ -59,6 +59,11 @@
   return Matcher.canConvertTo(NodeKind);
 }
 
+DynTypedMatcher VariantMatcher::MatcherOps::convertMatcher(
+const DynTypedMatcher &Matcher) const {
+  return Matcher.dynCastTo(NodeKind);
+}
+
 llvm::Optional
 VariantMatcher::MatcherOps::constructVariadicOperator(
 DynTypedMatcher::VariadicOperator Op,
Index: clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
===
--- clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
+++ clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
@@ -100,8 +100,7 @@
 
 /// Convert \p Matcher the destination type and return it as a new
 /// DynTypedMatcher.
-virtual DynTypedMatcher
-convertMatcher(const DynTypedMatcher &Matcher) const = 0;
+DynTypedMatcher convertMatcher(const DynTypedMatcher &Matcher) const;
 
 /// Constructs a variadic typed matcher from \p InnerMatchers.
 /// Will try to convert each inner matcher to 

[PATCH] D94877: Add API to retrieve a clade kind from ASTNodeKind

2021-01-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94877

Files:
  clang/include/clang/AST/ASTTypeTraits.h
  clang/lib/AST/ASTTypeTraits.cpp


Index: clang/lib/AST/ASTTypeTraits.cpp
===
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -63,6 +63,17 @@
   return Derived == Base;
 }
 
+ASTNodeKind ASTNodeKind::getCladeKind() const {
+  auto LastId = KindId;
+  while (LastId) {
+auto ParentId = AllKindInfo[LastId].ParentId;
+if (ParentId == NKI_None)
+  return LastId;
+LastId = ParentId;
+  }
+  return NKI_None;
+}
+
 StringRef ASTNodeKind::asStringRef() const { return AllKindInfo[KindId].Name; }
 
 ASTNodeKind ASTNodeKind::getMostDerivedType(ASTNodeKind Kind1,
Index: clang/include/clang/AST/ASTTypeTraits.h
===
--- clang/include/clang/AST/ASTTypeTraits.h
+++ clang/include/clang/AST/ASTTypeTraits.h
@@ -100,6 +100,8 @@
   static ASTNodeKind getMostDerivedCommonAncestor(ASTNodeKind Kind1,
   ASTNodeKind Kind2);
 
+  ASTNodeKind getCladeKind() const;
+
   /// Hooks for using ASTNodeKind as a key in a DenseMap.
   struct DenseMapInfo {
 // ASTNodeKind() is a good empty key because it is represented as a 0.


Index: clang/lib/AST/ASTTypeTraits.cpp
===
--- clang/lib/AST/ASTTypeTraits.cpp
+++ clang/lib/AST/ASTTypeTraits.cpp
@@ -63,6 +63,17 @@
   return Derived == Base;
 }
 
+ASTNodeKind ASTNodeKind::getCladeKind() const {
+  auto LastId = KindId;
+  while (LastId) {
+auto ParentId = AllKindInfo[LastId].ParentId;
+if (ParentId == NKI_None)
+  return LastId;
+LastId = ParentId;
+  }
+  return NKI_None;
+}
+
 StringRef ASTNodeKind::asStringRef() const { return AllKindInfo[KindId].Name; }
 
 ASTNodeKind ASTNodeKind::getMostDerivedType(ASTNodeKind Kind1,
Index: clang/include/clang/AST/ASTTypeTraits.h
===
--- clang/include/clang/AST/ASTTypeTraits.h
+++ clang/include/clang/AST/ASTTypeTraits.h
@@ -100,6 +100,8 @@
   static ASTNodeKind getMostDerivedCommonAncestor(ASTNodeKind Kind1,
   ASTNodeKind Kind2);
 
+  ASTNodeKind getCladeKind() const;
+
   /// Hooks for using ASTNodeKind as a key in a DenseMap.
   struct DenseMapInfo {
 // ASTNodeKind() is a good empty key because it is represented as a 0.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94878: Make it possible to store a ASTNodeKind in VariantValue

2021-01-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94878

Files:
  clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
  clang/lib/ASTMatchers/Dynamic/VariantValue.cpp

Index: clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
===
--- clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
+++ clang/lib/ASTMatchers/Dynamic/VariantValue.cpp
@@ -268,6 +268,10 @@
   setString(String);
 }
 
+VariantValue::VariantValue(ASTNodeKind NodeKind) : Type(VT_Nothing) {
+  setNodeKind(NodeKind);
+}
+
 VariantValue::VariantValue(const VariantMatcher &Matcher) : Type(VT_Nothing) {
   setMatcher(Matcher);
 }
@@ -290,6 +294,9 @@
   case VT_String:
 setString(Other.getString());
 break;
+  case VT_NodeKind:
+setNodeKind(Other.getNodeKind());
+break;
   case VT_Matcher:
 setMatcher(Other.getMatcher());
 break;
@@ -308,6 +315,9 @@
   case VT_Matcher:
 delete Value.Matcher;
 break;
+  case VT_NodeKind:
+delete Value.NodeKind;
+break;
   // Cases that do nothing.
   case VT_Boolean:
   case VT_Double:
@@ -378,6 +388,19 @@
   Value.String = new std::string(NewValue);
 }
 
+bool VariantValue::isNodeKind() const { return Type == VT_NodeKind; }
+
+const ASTNodeKind &VariantValue::getNodeKind() const {
+  assert(isNodeKind());
+  return *Value.NodeKind;
+}
+
+void VariantValue::setNodeKind(ASTNodeKind NewValue) {
+  reset();
+  Type = VT_NodeKind;
+  Value.NodeKind = new ASTNodeKind(NewValue);
+}
+
 bool VariantValue::isMatcher() const {
   return Type == VT_Matcher;
 }
@@ -449,6 +472,8 @@
   case VT_Boolean: return "Boolean";
   case VT_Double: return "Double";
   case VT_Unsigned: return "Unsigned";
+  case VT_NodeKind:
+return getNodeKind().asStringRef().str();
   case VT_Nothing: return "Nothing";
   }
   llvm_unreachable("Invalid Type");
Index: clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
===
--- clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
+++ clang/include/clang/ASTMatchers/Dynamic/VariantValue.h
@@ -251,6 +251,7 @@
   VariantValue(double Double);
   VariantValue(unsigned Unsigned);
   VariantValue(StringRef String);
+  VariantValue(ASTNodeKind NodeKind);
   VariantValue(const VariantMatcher &Matchers);
 
   /// Constructs an \c unsigned value (disambiguation from bool).
@@ -280,6 +281,10 @@
   const std::string &getString() const;
   void setString(StringRef String);
 
+  bool isNodeKind() const;
+  const ASTNodeKind &getNodeKind() const;
+  void setNodeKind(ASTNodeKind NodeKind);
+
   /// Matcher value functions.
   bool isMatcher() const;
   const VariantMatcher &getMatcher() const;
@@ -316,7 +321,8 @@
 VT_Double,
 VT_Unsigned,
 VT_String,
-VT_Matcher
+VT_Matcher,
+VT_NodeKind
   };
 
   /// All supported value types.
@@ -326,6 +332,7 @@
 bool Boolean;
 std::string *String;
 VariantMatcher *Matcher;
+ASTNodeKind *NodeKind;
   };
 
   ValueType Type;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94879: Implement dynamic mapAnyOf in terms of ASTNodeKinds

2021-01-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This reduces template bloat, but more importantly, makes it possible to
construct one from clang-query without template types.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94879

Files:
  clang/lib/ASTMatchers/Dynamic/Marshallers.h


Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -925,32 +925,50 @@
   const StringRef MatcherName;
 };
 
-template 
 class MapAnyOfMatcherDescriptor : public MatcherDescriptor {
-  std::vector Funcs;
+  ASTNodeKind CladeNodeKind;
+  std::vector NodeKinds;
 
 public:
-  MapAnyOfMatcherDescriptor(StringRef MatcherName)
-  : Funcs{DynCastAllOfMatcherDescriptor(
-ast_matchers::internal::VariadicDynCastAllOfMatcher{},
-MatcherName)...} {}
+  MapAnyOfMatcherDescriptor(ASTNodeKind CladeNodeKind,
+std::vector NodeKinds)
+  : CladeNodeKind(CladeNodeKind), NodeKinds(NodeKinds) {}
 
   VariantMatcher create(SourceRange NameRange, ArrayRef Args,
 Diagnostics *Error) const override {
-std::vector InnerArgs;
 
-for (auto const &F : Funcs) {
-  InnerArgs.push_back(F.create(NameRange, Args, Error));
-  if (!Error->errors().empty())
-return {};
+std::vector NodeArgs;
+
+for (auto NK : NodeKinds) {
+  std::vector InnerArgs;
+
+  for (const auto &Arg : Args) {
+if (!Arg.Value.isMatcher())
+  return {};
+auto VM = Arg.Value.getMatcher();
+if (VM.hasTypedMatcher(NK)) {
+  auto DM = VM.getTypedMatcher(NK);
+  InnerArgs.push_back(DM);
+}
+  }
+
+  if (InnerArgs.empty()) {
+NodeArgs.push_back(
+DynTypedMatcher::trueMatcher(NK).dynCastTo(CladeNodeKind));
+  } else {
+NodeArgs.push_back(
+DynTypedMatcher::constructVariadic(
+ast_matchers::internal::DynTypedMatcher::VO_AllOf, NK,
+InnerArgs)
+.dynCastTo(CladeNodeKind));
+  }
 }
-return VariantMatcher::SingleMatcher(
-ast_matchers::internal::BindableMatcher(
-VariantMatcher::VariadicOperatorMatcher(
-ast_matchers::internal::DynTypedMatcher::VO_AnyOf,
-std::move(InnerArgs))
-.getTypedMatcher()));
+
+auto Result = DynTypedMatcher::constructVariadic(
+ast_matchers::internal::DynTypedMatcher::VO_AnyOf, CladeNodeKind,
+NodeArgs);
+Result.setAllowBind(true);
+return VariantMatcher::SingleMatcher(Result);
   }
 
   bool isVariadic() const override { return true; }
@@ -963,9 +981,11 @@
 
   bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity,
ASTNodeKind *LeastDerivedKind) const override {
-return llvm::all_of(Funcs, [=](const auto &F) {
-  return F.isConvertibleTo(Kind, Specificity, LeastDerivedKind);
-});
+if (Specificity)
+  *Specificity = 1;
+if (LeastDerivedKind)
+  *LeastDerivedKind = CladeNodeKind;
+return true;
   }
 };
 
@@ -1077,8 +1097,9 @@
 std::unique_ptr makeMatcherAutoMarshall(
 ast_matchers::internal::MapAnyOfMatcherImpl,
 StringRef MatcherName) {
-  return std::make_unique>(
-  MatcherName);
+  return std::make_unique(
+  ASTNodeKind::getFromNodeKind(),
+  std::vector{ASTNodeKind::getFromNodeKind()...});
 }
 
 } // namespace internal


Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -925,32 +925,50 @@
   const StringRef MatcherName;
 };
 
-template 
 class MapAnyOfMatcherDescriptor : public MatcherDescriptor {
-  std::vector Funcs;
+  ASTNodeKind CladeNodeKind;
+  std::vector NodeKinds;
 
 public:
-  MapAnyOfMatcherDescriptor(StringRef MatcherName)
-  : Funcs{DynCastAllOfMatcherDescriptor(
-ast_matchers::internal::VariadicDynCastAllOfMatcher{},
-MatcherName)...} {}
+  MapAnyOfMatcherDescriptor(ASTNodeKind CladeNodeKind,
+std::vector NodeKinds)
+  : CladeNodeKind(CladeNodeKind), NodeKinds(NodeKinds) {}
 
   VariantMatcher create(SourceRange NameRange, ArrayRef Args,
 Diagnostics *Error) const override {
-std::vector InnerArgs;
 
-for (auto const &F : Funcs) {
-  InnerArgs.push_back(F.create(NameRange, Args, Error));
-  if (!Error->errors().empty())
-return {};
+std::vector NodeArgs;
+
+for (auto NK : NodeKinds) {
+  std::vector InnerArgs;
+
+  for (const auto &Arg : Args) {
+if (!Arg.Value.isMatcher())
+

[PATCH] D94880: Add clang-query support for mapAnyOf

2021-01-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94880

Files:
  clang/lib/ASTMatchers/Dynamic/Marshallers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp


Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -102,6 +102,9 @@
   // Other:
   // equalsNode
 
+  registerMatcher("mapAnyOf",
+  std::make_unique());
+
   REGISTER_OVERLOADED_2(callee);
   REGISTER_OVERLOADED_2(hasAnyCapture);
   REGISTER_OVERLOADED_2(hasPrefix);
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -1057,6 +1057,55 @@
   ASTNodeKind nodeMatcherType() const override { return ASTNodeKind(); }
 };
 
+class MapAnyOfBuilderDescriptor : public MatcherDescriptor {
+public:
+  VariantMatcher create(SourceRange NameRange, ArrayRef Args,
+Diagnostics *Error) const override {
+return {};
+  }
+
+  bool isBuilderMatcher() const override { return true; }
+
+  std::unique_ptr
+  buildMatcherCtor(SourceRange NameRange, ArrayRef Args,
+   Diagnostics *Error) const override {
+
+std::vector NodeKinds;
+for (auto Arg : Args) {
+  if (!Arg.Value.isNodeKind())
+return {};
+  NodeKinds.push_back(Arg.Value.getNodeKind());
+}
+
+if (NodeKinds.empty()) {
+  // Set error
+  return {};
+}
+
+ASTNodeKind CladeNodeKind = NodeKinds.front().getCladeKind();
+
+return std::make_unique(CladeNodeKind,
+   NodeKinds);
+  }
+
+  bool isVariadic() const override { return false; }
+
+  unsigned getNumArgs() const override { return 0; }
+
+  void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo,
+   std::vector &ArgKinds) const override {
+return;
+  }
+  bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity = nullptr,
+   ASTNodeKind *LeastDerivedKind = nullptr) const override 
{
+return false;
+  }
+
+  bool isPolymorphic() const override { return false; }
+
+  ASTNodeKind nodeMatcherType() const override { return ASTNodeKind(); }
+};
+
 /// Helper functions to select the appropriate marshaller functions.
 /// They detect the number of arguments, arguments types and return type.
 


Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -102,6 +102,9 @@
   // Other:
   // equalsNode
 
+  registerMatcher("mapAnyOf",
+  std::make_unique());
+
   REGISTER_OVERLOADED_2(callee);
   REGISTER_OVERLOADED_2(hasAnyCapture);
   REGISTER_OVERLOADED_2(hasPrefix);
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -1057,6 +1057,55 @@
   ASTNodeKind nodeMatcherType() const override { return ASTNodeKind(); }
 };
 
+class MapAnyOfBuilderDescriptor : public MatcherDescriptor {
+public:
+  VariantMatcher create(SourceRange NameRange, ArrayRef Args,
+Diagnostics *Error) const override {
+return {};
+  }
+
+  bool isBuilderMatcher() const override { return true; }
+
+  std::unique_ptr
+  buildMatcherCtor(SourceRange NameRange, ArrayRef Args,
+   Diagnostics *Error) const override {
+
+std::vector NodeKinds;
+for (auto Arg : Args) {
+  if (!Arg.Value.isNodeKind())
+return {};
+  NodeKinds.push_back(Arg.Value.getNodeKind());
+}
+
+if (NodeKinds.empty()) {
+  // Set error
+  return {};
+}
+
+ASTNodeKind CladeNodeKind = NodeKinds.front().getCladeKind();
+
+return std::make_unique(CladeNodeKind,
+   NodeKinds);
+  }
+
+  bool isVariadic() const override { return false; }
+
+  unsigned getNumArgs() const override { return 0; }
+
+  void getArgKinds(ASTNodeKind ThisKind, unsigned ArgNo,
+   std::vector &ArgKinds) const override {
+return;
+  }
+  bool isConvertibleTo(ASTNodeKind Kind, unsigned *Specificity = nullptr,
+   ASTNodeKind *LeastDerivedKind = nullptr) const override {
+return false;
+  }
+
+  bool isPolymorphic() const override { return false; }
+
+  ASTNodeKind nodeMatcherType() const override { return ASTNodeKind(); }
+};
+
 /// Helper functions to select the appropriate marshaller functions.
 /// They detect the number of 

[PATCH] D94881: WIP: Add a way to define matcher builders in the dynamic registry

2021-01-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire created this revision.
steveire added a reviewer: aaron.ballman.
steveire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94881

Files:
  clang/include/clang/ASTMatchers/Dynamic/Parser.h
  clang/lib/ASTMatchers/Dynamic/Marshallers.h
  clang/lib/ASTMatchers/Dynamic/Parser.cpp

Index: clang/lib/ASTMatchers/Dynamic/Parser.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Parser.cpp
+++ clang/lib/ASTMatchers/Dynamic/Parser.cpp
@@ -20,6 +20,9 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h"
+
+#include "Marshallers.h"
+
 #include 
 #include 
 #include 
@@ -52,6 +55,7 @@
 
   /// Some known identifiers.
   static const char* const ID_Bind;
+  static const char *const ID_With;
 
   TokenInfo() = default;
 
@@ -62,6 +66,7 @@
 };
 
 const char* const Parser::TokenInfo::ID_Bind = "bind";
+const char *const Parser::TokenInfo::ID_With = "with";
 
 /// Simple tokenizer for the parser.
 class Parser::CodeTokenizer {
@@ -366,7 +371,14 @@
   }
 
   std::string BindID;
-  if (!parseBindID(BindID))
+  Tokenizer->consumeNextToken(); // consume the period.
+  const TokenInfo ChainCallToken = Tokenizer->consumeNextToken();
+  if (ChainCallToken.Kind == TokenInfo::TK_CodeCompletion) {
+addCompletion(ChainCallToken, MatcherCompletion("bind(\"", "bind", 1));
+addCompletion(ChainCallToken, MatcherCompletion("with(\"", "with", 1));
+return false;
+  }
+  if (!parseBindID(ChainCallToken, BindID))
 return false;
 
   assert(NamedValue.isMatcher());
@@ -405,31 +417,26 @@
 
   Tokenizer->SkipNewlines();
 
+  assert(NameToken.Kind == TokenInfo::TK_Ident);
+  const TokenInfo OpenToken = Tokenizer->consumeNextToken();
+  if (OpenToken.Kind != TokenInfo::TK_OpenParen) {
+Error->addError(OpenToken.Range, Error->ET_ParserNoOpenParen)
+<< OpenToken.Text;
+return false;
+  }
+
+  llvm::Optional Ctor = S->lookupMatcherCtor(NameToken.Text);
+
   // Parse as a matcher expression.
-  return parseMatcherExpressionImpl(NameToken, Value);
+  return parseMatcherExpressionImpl(NameToken, OpenToken, Ctor, Value);
 }
 
-bool Parser::parseBindID(std::string &BindID) {
+bool Parser::parseBindID(TokenInfo BindToken, std::string &BindID) {
   // Parse .bind("foo")
-  assert(Tokenizer->peekNextToken().Kind == TokenInfo::TK_Period);
-  Tokenizer->consumeNextToken(); // consume the period.
-  const TokenInfo BindToken = Tokenizer->consumeNextToken();
-  if (BindToken.Kind == TokenInfo::TK_CodeCompletion) {
-addCompletion(BindToken, MatcherCompletion("bind(\"", "bind", 1));
-return false;
-  }
-
   const TokenInfo OpenToken = Tokenizer->consumeNextToken();
   const TokenInfo IDToken = Tokenizer->consumeNextTokenIgnoreNewlines();
   const TokenInfo CloseToken = Tokenizer->consumeNextTokenIgnoreNewlines();
 
-  // TODO: We could use different error codes for each/some to be more
-  //   explicit about the syntax error.
-  if (BindToken.Kind != TokenInfo::TK_Ident ||
-  BindToken.Text != TokenInfo::ID_Bind) {
-Error->addError(BindToken.Range, Error->ET_ParserMalformedBindExpr);
-return false;
-  }
   if (OpenToken.Kind != TokenInfo::TK_OpenParen) {
 Error->addError(OpenToken.Range, Error->ET_ParserMalformedBindExpr);
 return false;
@@ -446,28 +453,140 @@
   return true;
 }
 
+bool Parser::parseMatcherBuilder(MatcherCtor Ctor, const TokenInfo &NameToken,
+ const TokenInfo &OpenToken,
+ VariantValue *Value) {
+  std::vector Args;
+  TokenInfo EndToken;
+
+  Tokenizer->SkipNewlines();
+
+  {
+ScopedContextEntry SCE(this, Ctor);
+
+while (Tokenizer->nextTokenKind() != TokenInfo::TK_Eof) {
+  if (Tokenizer->nextTokenKind() == TokenInfo::TK_CloseParen) {
+// End of args.
+EndToken = Tokenizer->consumeNextToken();
+break;
+  }
+  if (!Args.empty()) {
+// We must find a , token to continue.
+const TokenInfo CommaToken = Tokenizer->consumeNextToken();
+if (CommaToken.Kind != TokenInfo::TK_Comma) {
+  Error->addError(CommaToken.Range, Error->ET_ParserNoComma)
+  << CommaToken.Text;
+  return false;
+}
+  }
+
+  Diagnostics::Context Ctx(Diagnostics::Context::MatcherArg, Error,
+   NameToken.Text, NameToken.Range,
+   Args.size() + 1);
+  ParserValue ArgValue;
+  Tokenizer->SkipNewlines();
+  const auto NodeMatcherToken = Tokenizer->consumeNextToken();
+  ArgValue.Text = NodeMatcherToken.Text;
+  ArgValue.Range = NodeMatcherToken.Range;
+
+  auto MappedMatcher = S->lookupMatcherCtor(ArgValue.Text);
+
+  if (!MappedMatcher) {
+// TODO: error
+ 

[PATCH] D94881: WIP: Add a way to define matcher builders in the dynamic registry

2021-01-17 Thread Stephen Kelly via Phabricator via cfe-commits
steveire added a comment.

This is WIP because there is still some error handling and code completion 
handling to do. Pushed the patch though to complete the series : 
https://github.com/steveire/llvm-project/commits/mapAnyOf


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94881

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


[clang] 9a7fb08 - NFC: Minor cleanup of function calls

2021-01-17 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2021-01-17T18:47:17Z
New Revision: 9a7fb0848771e3d38baf10e4d1078b50dd884265

URL: 
https://github.com/llvm/llvm-project/commit/9a7fb0848771e3d38baf10e4d1078b50dd884265
DIFF: 
https://github.com/llvm/llvm-project/commit/9a7fb0848771e3d38baf10e4d1078b50dd884265.diff

LOG: NFC: Minor cleanup of function calls

Added: 


Modified: 
clang/lib/ASTMatchers/ASTMatchFinder.cpp

Removed: 




diff  --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp 
b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index e35600a083d3..8ddd3c87e09d 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -257,10 +257,7 @@ class MatchChildASTVisitor
   return true;
 ScopedIncrement ScopedDepth(&CurrentDepth);
 
-if (!match(*Node->getDecomposedForm().LHS) ||
-!match(*Node->getDecomposedForm().RHS))
-  return false;
-return true;
+return match(*Node->getLHS()) && match(*Node->getRHS());
   }
   bool TraverseLambdaExpr(LambdaExpr *Node) {
 if (!Finder->isTraversalIgnoringImplicitNodes())



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


[PATCH] D94871: [Clang][OpenMP] Fixed an issue that clang crashed when compiling OpenMP program in device only mode without host IR

2021-01-17 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 317235.
tianshilei1992 added a comment.

Also updated for `registerTargetRegionEntryInfo`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94871

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp


Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2941,16 +2941,12 @@
   // If we are emitting code for a target, the entry is already initialized,
   // only has to be registered.
   if (CGM.getLangOpts().OpenMPIsDevice) {
-if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum)) {
-  unsigned DiagID = CGM.getDiags().getCustomDiagID(
-  DiagnosticsEngine::Error,
-  "Unable to find target region on line '%0' in the device code.");
-  CGM.getDiags().Report(DiagID) << LineNum;
-  return;
-}
+// This could happen if the device compilation is invoked standalone.
+if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum))
+  initializeTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum,
+  OffloadingEntriesNum);
 auto &Entry =
 OffloadEntriesTargetRegion[DeviceID][FileID][ParentName][LineNum];
-assert(Entry.isValid() && "Entry not initialized!");
 Entry.setAddress(Addr);
 Entry.setID(ID);
 Entry.setFlags(Flags);
@@ -3017,9 +3013,10 @@
  OMPTargetGlobalVarEntryKind Flags,
  llvm::GlobalValue::LinkageTypes Linkage) {
   if (CGM.getLangOpts().OpenMPIsDevice) {
+// This could happen if the device compilation is invoked standalone.
+if (!hasDeviceGlobalVarEntryInfo(VarName))
+  initializeDeviceGlobalVarEntryInfo(VarName, Flags, OffloadingEntriesNum);
 auto &Entry = OffloadEntriesDeviceGlobalVar[VarName];
-assert(Entry.isValid() && Entry.getFlags() == Flags &&
-   "Entry not initialized!");
 assert((!Entry.getAddress() || Entry.getAddress() == Addr) &&
"Resetting with the new address.");
 if (Entry.getAddress() && hasDeviceGlobalVarEntryInfo(VarName)) {


Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2941,16 +2941,12 @@
   // If we are emitting code for a target, the entry is already initialized,
   // only has to be registered.
   if (CGM.getLangOpts().OpenMPIsDevice) {
-if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum)) {
-  unsigned DiagID = CGM.getDiags().getCustomDiagID(
-  DiagnosticsEngine::Error,
-  "Unable to find target region on line '%0' in the device code.");
-  CGM.getDiags().Report(DiagID) << LineNum;
-  return;
-}
+// This could happen if the device compilation is invoked standalone.
+if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum))
+  initializeTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum,
+  OffloadingEntriesNum);
 auto &Entry =
 OffloadEntriesTargetRegion[DeviceID][FileID][ParentName][LineNum];
-assert(Entry.isValid() && "Entry not initialized!");
 Entry.setAddress(Addr);
 Entry.setID(ID);
 Entry.setFlags(Flags);
@@ -3017,9 +3013,10 @@
  OMPTargetGlobalVarEntryKind Flags,
  llvm::GlobalValue::LinkageTypes Linkage) {
   if (CGM.getLangOpts().OpenMPIsDevice) {
+// This could happen if the device compilation is invoked standalone.
+if (!hasDeviceGlobalVarEntryInfo(VarName))
+  initializeDeviceGlobalVarEntryInfo(VarName, Flags, OffloadingEntriesNum);
 auto &Entry = OffloadEntriesDeviceGlobalVar[VarName];
-assert(Entry.isValid() && Entry.getFlags() == Flags &&
-   "Entry not initialized!");
 assert((!Entry.getAddress() || Entry.getAddress() == Addr) &&
"Resetting with the new address.");
 if (Entry.getAddress() && hasDeviceGlobalVarEntryInfo(VarName)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94884: [Clang][OpenMP] Include header for CUDA builtin vars into OpenMP wrapper header

2021-01-17 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 created this revision.
Herald added subscribers: guansong, yaxunl.
tianshilei1992 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

Current OpenMP wrapper header `__clang_openmp_device_functions.h`
doesn't include the header for CUDA builtin vars, so variable like `threadIdx`
cannot be used in OpenMP code, even within `declare target`.

This patch includes the header. One thing left is, is it fine that we still use
the name `__clang_openmp_device_functions.h`? Those builtin vars seems like not
part of "device functions".


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94884

Files:
  clang/lib/Headers/__clang_cuda_builtin_vars.h
  clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h


Index: clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
===
--- clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
+++ clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
@@ -30,6 +30,9 @@
 /// Provide definitions for these functions.
 #include <__clang_cuda_device_functions.h>
 
+/// Provide definition for CUDA builtin variables
+#include <__clang_cuda_builtin_vars.h>
+
 #undef __OPENMP_NVPTX__
 #undef __CUDA__
 
Index: clang/lib/Headers/__clang_cuda_builtin_vars.h
===
--- clang/lib/Headers/__clang_cuda_builtin_vars.h
+++ clang/lib/Headers/__clang_cuda_builtin_vars.h
@@ -101,8 +101,12 @@
   __CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_gridDim_t);
 };
 
+#ifdef __OPENMP_NVPTX__
+#define __CUDA_BUILTIN_VAR extern const __attribute__((weak))
+#else
 #define __CUDA_BUILTIN_VAR 
\
   extern const __attribute__((device)) __attribute__((weak))
+#endif
 __CUDA_BUILTIN_VAR __cuda_builtin_threadIdx_t threadIdx;
 __CUDA_BUILTIN_VAR __cuda_builtin_blockIdx_t blockIdx;
 __CUDA_BUILTIN_VAR __cuda_builtin_blockDim_t blockDim;


Index: clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
===
--- clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
+++ clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
@@ -30,6 +30,9 @@
 /// Provide definitions for these functions.
 #include <__clang_cuda_device_functions.h>
 
+/// Provide definition for CUDA builtin variables
+#include <__clang_cuda_builtin_vars.h>
+
 #undef __OPENMP_NVPTX__
 #undef __CUDA__
 
Index: clang/lib/Headers/__clang_cuda_builtin_vars.h
===
--- clang/lib/Headers/__clang_cuda_builtin_vars.h
+++ clang/lib/Headers/__clang_cuda_builtin_vars.h
@@ -101,8 +101,12 @@
   __CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_gridDim_t);
 };
 
+#ifdef __OPENMP_NVPTX__
+#define __CUDA_BUILTIN_VAR extern const __attribute__((weak))
+#else
 #define __CUDA_BUILTIN_VAR \
   extern const __attribute__((device)) __attribute__((weak))
+#endif
 __CUDA_BUILTIN_VAR __cuda_builtin_threadIdx_t threadIdx;
 __CUDA_BUILTIN_VAR __cuda_builtin_blockIdx_t blockIdx;
 __CUDA_BUILTIN_VAR __cuda_builtin_blockDim_t blockDim;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94871: [Clang][OpenMP] Fixed an issue that clang crashed when compiling OpenMP program in device only mode without host IR

2021-01-17 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Here is a minimal reproducer for the issue even without standalone device 
compilation (and I can build the situation in various other ways as well): 
https://godbolt.org/z/T1h9b5
Can you add it as a test, I am also curious how the IR looks like with this 
patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94871

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


[PATCH] D94884: [Clang][OpenMP] Include header for CUDA builtin vars into OpenMP wrapper header

2021-01-17 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a reviewer: tra.
jdoerfert added a comment.

I can see that we want this but I guess the errors show the problem, replace 
`__attribute((device))` with `DEVICE` and define it based on CUDA vs OpenMP 
properly.




Comment at: clang/lib/Headers/__clang_cuda_builtin_vars.h:118
 // architectures have a WARP_SZ value of 32'.
 __attribute__((device)) const int warpSize = 32;
 

Do we need to do something wrt to the attribute here and above?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94884

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


[PATCH] D94785: [clangd] Index local classes, virtual and overriding methods.

2021-01-17 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

In D94785#2501806 , @usaxena95 wrote:

> Although now that I enabled this in all SymbolCollectorTests, this causes a 
> regression in RefContainers.
>
>   void f2() {
> (void) $ref1a[[f1]](1);
> auto fptr = &$ref1b[[f1]];
>   }
>
> `&f1` is contained in `fptr` instead of `f2`. No immediate ideas why would 
> this happen.

I have a theory as to why.

If you look at the next test case in `RefContainers`:

  int $toplevel2[[v1]] = $ref2[[f1]](2);

here, `v1` is a global variable, and it is the containing symbol for the 
reference in the initializer.

So, I think libIndex considers references in initializers to be contained in 
the declaration of the variable. The reason this didn't happen for local 
variables until now, is that `IndexFunctionLocals` was false, and libIndex 
probably avoids returning non-indexed symbols in `ASTNode::Parent`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94785

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


[PATCH] D94614: [FPEnv][X86] Platform builtins edition: clang should get from the AST the metadata for constrained FP builtins

2021-01-17 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/test/CodeGen/X86/avx512dq-builtins-constrained.c:3
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512dq -emit-llvm -o - -Wall 
-Werror | FileCheck %s --check-prefix=UNCONSTRAINED --check-prefix=COMMON 
--check-prefix=COMMONIR
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512dq 
-ffp-exception-behavior=maytrap -DSTRICT=1 -emit-llvm -o - -Wall -Werror | tee 
/tmp/X | FileCheck %s --check-prefix=CONSTRAINED --check-prefix=COMMON 
--check-prefix=COMMONIR
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512dq -S -o - -Wall -Werror | 
FileCheck %s --check-prefix=CHECK-ASM --check-prefix=COMMON

Where is the file used? It results in failure on Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94614

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


[PATCH] D94884: [Clang][OpenMP] Include header for CUDA builtin vars into OpenMP wrapper header

2021-01-17 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 317251.
tianshilei1992 added a comment.

Use macro `DEVICE` to control the attribute


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94884

Files:
  clang/lib/Headers/__clang_cuda_builtin_vars.h
  clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
  clang/test/Headers/nvptx_device_cmath_functions.c
  clang/test/Headers/nvptx_device_cmath_functions.cpp
  clang/test/Headers/nvptx_device_cmath_functions_cxx17.cpp
  clang/test/Headers/nvptx_device_math_complex.c
  clang/test/Headers/nvptx_device_math_complex.cpp
  clang/test/Headers/nvptx_device_math_functions.c
  clang/test/Headers/nvptx_device_math_functions.cpp
  clang/test/Headers/nvptx_device_math_functions_cxx17.cpp
  clang/test/Headers/nvptx_device_math_macro.cpp
  clang/test/Headers/nvptx_device_math_modf.cpp
  clang/test/Headers/nvptx_device_math_sin.c
  clang/test/Headers/nvptx_device_math_sin.cpp
  clang/test/Headers/nvptx_device_math_sin_cos.cpp
  clang/test/Headers/nvptx_device_math_sincos.cpp
  clang/test/Headers/openmp_device_math_isnan.cpp
  clang/test/OpenMP/assumes_include_nvptx.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp

Index: clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
===
--- clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
+++ clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
-// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown  -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
-// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
-// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s
-// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -fexceptions -fcxx-exceptions -aux-triple powerpc64le-unknown-unknown -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -fdeclspec -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -fdeclspec -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown  -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -fdeclspec -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
+// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -fdeclspec -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host

[PATCH] D71714: [Sema] Fix -Warray-bounds false negative when casting an out-of-bounds array item

2021-01-17 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 317252.
vabridgers added a comment.

Rebase, commandeer this patch from Ilya.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71714

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Parser/cxx-ambig-decl-expr.cpp
  clang/test/SemaCXX/array-bounds.cpp

Index: clang/test/SemaCXX/array-bounds.cpp
===
--- clang/test/SemaCXX/array-bounds.cpp
+++ clang/test/SemaCXX/array-bounds.cpp
@@ -27,7 +27,7 @@
 };
 
 void f1(int a[1]) {
-  int val = a[3]; // no warning for function argumnet
+  int val = a[3]; // no warning for function argument
 }
 
 void f2(const int (&a)[2]) { // expected-note {{declared here}}
@@ -133,7 +133,7 @@
 
 int test_sizeof_as_condition(int flag) {
   int arr[2] = { 0, 0 }; // expected-note {{array 'arr' declared here}}
-  if (flag) 
+  if (flag)
 return sizeof(char) != sizeof(char) ? arr[2] : arr[1];
   return sizeof(char) == sizeof(char) ? arr[2] : arr[1]; // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
 }
@@ -241,7 +241,7 @@
 }
 
 int test_pr11007_aux(const char * restrict, ...);
-  
+
 // Test checking with varargs.
 void test_pr11007() {
   double a[5]; // expected-note {{array 'a' declared here}}
@@ -320,3 +320,33 @@
   arr[1] = 0; // expected-warning {{array index 1 is past the end of the array (which contains 1 element)}}
 }
 } // namespace var_template_array
+
+namespace PR44343 {
+  const unsigned int array[2] = {0, 1}; // expected-note 5{{array 'array' declared here}}
+
+  const int i1 = (const int)array[2]; // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  const int i2 = static_cast(array[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  const int &i3 = reinterpret_cast(array[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  unsigned int &i4 = const_cast(array[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  int i5 = int(array[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  const unsigned int *i6 = &(1 > 0 ? array[2] : array[1]); // no warning for one-past-end element's address retrieval
+
+  // Test dynamic cast
+  struct Base {
+virtual ~Base();
+  };
+  struct Derived : Base {
+  };
+  Base baseArr[2]; // expected-note {{array 'baseArr' declared here}}
+  Derived *d1 = dynamic_cast(&baseArr[2]); // FIXME: Should actually warn because dynamic_cast accesses the vptr
+  Derived &d2 = dynamic_cast(baseArr[2]); // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+
+  // Test operator `&` in combination with operators `.` and `->`
+  struct A {
+int n;
+  };
+  A a[2]; // expected-note {{array 'a' declared here}}
+  int *n = &a[2].n; // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+  A *aPtr[2]; // expected-note {{array 'aPtr' declared here}}
+  int *n2 = &aPtr[2]->n; // expected-warning {{array index 2 is past the end of the array (which contains 2 elements)}}
+}
Index: clang/test/Parser/cxx-ambig-decl-expr.cpp
===
--- clang/test/Parser/cxx-ambig-decl-expr.cpp
+++ clang/test/Parser/cxx-ambig-decl-expr.cpp
@@ -24,7 +24,7 @@
 
   // This is array indexing not an array declarator because a comma expression
   // is not syntactically a constant-expression.
-  int(x[1,1]); // expected-warning 2{{unused}}
+  int(x[1,0]); // expected-warning 2{{unused}}
 
   // This is array indexing not an array declaration because a braced-init-list
   // is not syntactically a constant-expression.
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14387,62 +14387,63 @@
 PDiag(diag::note_array_declared_here) << ND);
 }
 
-void Sema::CheckArrayAccess(const Expr *expr) {
-  int AllowOnePastEnd = 0;
-  while (expr) {
-expr = expr->IgnoreParenImpCasts();
-switch (expr->getStmtClass()) {
-  case Stmt::ArraySubscriptExprClass: {
-const ArraySubscriptExpr *ASE = cast(expr);
-CheckArrayAccess(ASE->getBase(), ASE->getIdx(), ASE,
- AllowOnePastEnd > 0);
-expr = ASE->getBase();
-break;
-  }
-  case Stmt::MemberExprClass: {
-expr = cast(expr)->getBase();
-break;
-  }
-  case Stmt::OMPArraySectionExprClass: {
-const OMPArraySectionExpr *ASE = cast(expr);
-if (ASE->getLowerBound())
-  CheckArrayAccess(ASE->getBase(), ASE->getLowerBound(),
-   

[PATCH] D94884: [Clang][OpenMP] Include header for CUDA builtin vars into OpenMP wrapper header

2021-01-17 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

C is still broken as the header is written in C++ where a struct can have 
member functions, either static or not. Need to fix it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94884

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


[PATCH] D94403: [RISCV] Implement new architecture extension macros

2021-01-17 Thread Zakk Chen via Phabricator via cfe-commits
khchen accepted this revision.
khchen added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94403

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


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-01-17 Thread Zhiwei Chen via Phabricator via cfe-commits
condy added a comment.

The tests failed though


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90448

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


[PATCH] D94884: [Clang][OpenMP] Include header for CUDA builtin vars into OpenMP wrapper header

2021-01-17 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 317255.
tianshilei1992 added a comment.

Fixed compilation in C mode


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94884

Files:
  clang/lib/Headers/__clang_cuda_builtin_vars.h
  clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h
  clang/test/Headers/nvptx_device_cmath_functions.c
  clang/test/Headers/nvptx_device_cmath_functions.cpp
  clang/test/Headers/nvptx_device_cmath_functions_cxx17.cpp
  clang/test/Headers/nvptx_device_math_complex.c
  clang/test/Headers/nvptx_device_math_complex.cpp
  clang/test/Headers/nvptx_device_math_functions.c
  clang/test/Headers/nvptx_device_math_functions.cpp
  clang/test/Headers/nvptx_device_math_functions_cxx17.cpp
  clang/test/Headers/nvptx_device_math_macro.cpp
  clang/test/Headers/nvptx_device_math_modf.cpp
  clang/test/Headers/nvptx_device_math_sin.c
  clang/test/Headers/nvptx_device_math_sin.cpp
  clang/test/Headers/nvptx_device_math_sin_cos.cpp
  clang/test/Headers/nvptx_device_math_sincos.cpp
  clang/test/Headers/openmp_device_math_isnan.cpp
  clang/test/OpenMP/assumes_include_nvptx.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp

Index: clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
===
--- clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
+++ clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
-// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown  -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
-// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
-// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s
-// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -fexceptions -fcxx-exceptions -aux-triple powerpc64le-unknown-unknown -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -fdeclspec -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -fdeclspec -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown  -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s
+// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -fdeclspec -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
+// RUN: %clang_cc1 -x c++ -O1 -disable-llvm-optzns -verify -fopenmp -internal-isystem %S/../Headers/Inputs/include -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_device_functions.h -fdeclspec -triple nvptx64-unknown-unknown -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t

[PATCH] D94884: [Clang][OpenMP] Include header for CUDA builtin vars into OpenMP wrapper header

2021-01-17 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added inline comments.



Comment at: clang/lib/Headers/__clang_cuda_builtin_vars.h:95
   // uint3).  This function is defined after we pull in vector_types.h.
-  __attribute__((device)) operator dim3() const;
-  __attribute__((device)) operator uint3() const;
+  DEVICE operator dim3() const;
+  DEVICE operator uint3() const;

How can we deal with the conversion in C?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94884

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


[PATCH] D90448: [clang] Add type check for explicit instantiation of static data members

2021-01-17 Thread Chuyang Chen via Phabricator via cfe-commits
nomanous added a comment.

In D90448#2504022 , @condy wrote:

> The tests failed though

Which? Do you mean the unit test? It seems to be irrelevant with this revision. 
This revision doesn't change the code covered by that test. The failure should 
be caused by other commit on the trunk.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D90448

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


[PATCH] D94403: [RISCV] Implement new architecture extension macros

2021-01-17 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

That's my fault, I didn't specify the behavior of sub-extension clearly on the 
spec, but I think it would be great if we also define sub-extension marcos, 
since it would be easier to check when some core only implement sub-extension, 
and the code can just check the sub-extensio rather than check both.




Comment at: clang/lib/Basic/Targets/RISCV.cpp:148
+  if (HasB) {
+Builder.defineMacro("__riscv_b", "92000");
 Builder.defineMacro("__riscv_bitmanip");

Could you add all subset included in `B`, like zba, zbb, zbc, zbp...



Comment at: clang/lib/Basic/Targets/RISCV.cpp:153
+  if (HasV) {
+Builder.defineMacro("__riscv_v", "9000");
 Builder.defineMacro("__riscv_vector");

Could you add all subset included in `V`, `Zvamo` and `Zvlsseg`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94403

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


[PATCH] D94871: [Clang][OpenMP] Fixed an issue that clang crashed when compiling OpenMP program in device only mode without host IR

2021-01-17 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 317258.
tianshilei1992 added a comment.

Added a new test case for device only compilation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94871

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_target_device_only_compilation.cpp


Index: clang/test/OpenMP/declare_target_device_only_compilation.cpp
===
--- /dev/null
+++ clang/test/OpenMP/declare_target_device_only_compilation.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le -S -emit-llvm 
%s -fopenmp-is-device -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64 -S -emit-llvm %s 
-fopenmp-is-device -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple i386 -S -emit-llvm %s 
-fopenmp-is-device -o - | FileCheck %s
+
+#pragma omp declare target
+#pragma omp begin declare variant match(device={kind(nohost)})
+int G1;
+#pragma omp end declare variant
+#pragma omp end declare target
+
+// CHECK: @[[G:.+]] = hidden {{.*}}global i32 0, align 4
+// CHECK: !omp_offload.info = !{!0}
+// CHECK: !0 = !{i32 1, !"[[G]]", i32 0, i32 0}
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2941,16 +2941,12 @@
   // If we are emitting code for a target, the entry is already initialized,
   // only has to be registered.
   if (CGM.getLangOpts().OpenMPIsDevice) {
-if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum)) {
-  unsigned DiagID = CGM.getDiags().getCustomDiagID(
-  DiagnosticsEngine::Error,
-  "Unable to find target region on line '%0' in the device code.");
-  CGM.getDiags().Report(DiagID) << LineNum;
-  return;
-}
+// This could happen if the device compilation is invoked standalone.
+if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum))
+  initializeTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum,
+  OffloadingEntriesNum);
 auto &Entry =
 OffloadEntriesTargetRegion[DeviceID][FileID][ParentName][LineNum];
-assert(Entry.isValid() && "Entry not initialized!");
 Entry.setAddress(Addr);
 Entry.setID(ID);
 Entry.setFlags(Flags);
@@ -3017,9 +3013,10 @@
  OMPTargetGlobalVarEntryKind Flags,
  llvm::GlobalValue::LinkageTypes Linkage) {
   if (CGM.getLangOpts().OpenMPIsDevice) {
+// This could happen if the device compilation is invoked standalone.
+if (!hasDeviceGlobalVarEntryInfo(VarName))
+  initializeDeviceGlobalVarEntryInfo(VarName, Flags, OffloadingEntriesNum);
 auto &Entry = OffloadEntriesDeviceGlobalVar[VarName];
-assert(Entry.isValid() && Entry.getFlags() == Flags &&
-   "Entry not initialized!");
 assert((!Entry.getAddress() || Entry.getAddress() == Addr) &&
"Resetting with the new address.");
 if (Entry.getAddress() && hasDeviceGlobalVarEntryInfo(VarName)) {


Index: clang/test/OpenMP/declare_target_device_only_compilation.cpp
===
--- /dev/null
+++ clang/test/OpenMP/declare_target_device_only_compilation.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le -S -emit-llvm %s -fopenmp-is-device -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64 -S -emit-llvm %s -fopenmp-is-device -o - | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple i386 -S -emit-llvm %s -fopenmp-is-device -o - | FileCheck %s
+
+#pragma omp declare target
+#pragma omp begin declare variant match(device={kind(nohost)})
+int G1;
+#pragma omp end declare variant
+#pragma omp end declare target
+
+// CHECK: @[[G:.+]] = hidden {{.*}}global i32 0, align 4
+// CHECK: !omp_offload.info = !{!0}
+// CHECK: !0 = !{i32 1, !"[[G]]", i32 0, i32 0}
Index: clang/lib/CodeGen/CGOpenMPRuntime.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2941,16 +2941,12 @@
   // If we are emitting code for a target, the entry is already initialized,
   // only has to be registered.
   if (CGM.getLangOpts().OpenMPIsDevice) {
-if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum)) {
-  unsigned DiagID = CGM.getDiags().getCustomDiagID(
-  DiagnosticsEngine::Error,
-  "Unable to find target region on line '%0' in the device code.");
-  CGM.getDiags().Report(DiagID) << LineNum;
-  return;
-}
+// This could happen if the device compilation is invoked standalone.
+if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName

[PATCH] D93776: [clang-format] Add StatementAttributeLikeMacros option

2021-01-17 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks updated this revision to Diff 317268.
HazardyKnusperkeks marked an inline comment as done.
HazardyKnusperkeks added a comment.

Sorting corrected.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93776

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -14731,6 +14731,11 @@
   CHECK_PARSE("AttributeMacros: [attr1, attr2]", AttributeMacros,
   std::vector({"attr1", "attr2"}));
 
+  Style.StatementAttributeLikeMacros.clear();
+  CHECK_PARSE("StatementAttributeLikeMacros: [emit,Q_EMIT]",
+  StatementAttributeLikeMacros,
+  std::vector({"emit", "Q_EMIT"}));
+
   Style.StatementMacros.clear();
   CHECK_PARSE("StatementMacros: [QUNUSED]", StatementMacros,
   std::vector{"QUNUSED"});
@@ -17803,6 +17808,36 @@
"struct constant;",
Style);
 }
+
+TEST_F(FormatTest, StatementAttributeLikeMacros) {
+  FormatStyle Style = getLLVMStyle();
+  StringRef Source = "void Foo::slot() {\n"
+ "  unsigned char MyChar = 'x';\n"
+ "  emit signal(MyChar);\n"
+ "  Q_EMIT signal(MyChar);\n"
+ "}";
+
+  EXPECT_EQ(Source, format(Source, Style));
+
+  Style.AlignConsecutiveDeclarations = true;
+  EXPECT_EQ("void Foo::slot() {\n"
+"  unsigned char MyChar = 'x';\n"
+"  emit  signal(MyChar);\n"
+"  Q_EMIT signal(MyChar);\n"
+"}",
+format(Source, Style));
+
+  Style.StatementAttributeLikeMacros.push_back("emit");
+  EXPECT_EQ(Source, format(Source, Style));
+
+  Style.StatementAttributeLikeMacros = {};
+  EXPECT_EQ("void Foo::slot() {\n"
+"  unsigned char MyChar = 'x';\n"
+"  emit  signal(MyChar);\n"
+"  Q_EMITsignal(MyChar);\n"
+"}",
+format(Source, Style));
+}
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -655,6 +655,9 @@
   return true;
 if (C.Tok->isNot(TT_StartOfName))
   return false;
+if (C.Tok->Previous &&
+C.Tok->Previous->is(TT_StatementAttributeLikeMacro))
+  return false;
 // Check if there is a subsequent name that starts the same declaration.
 for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) {
   if (Next->is(tok::comment))
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1368,7 +1368,8 @@
 TT_ImplicitStringLiteral, TT_InlineASMBrace, TT_JsFatArrow,
 TT_LambdaArrow, TT_NamespaceMacro, TT_OverloadedOperator,
 TT_RegexLiteral, TT_TemplateString, TT_ObjCStringLiteral,
-TT_UntouchableMacroFunc, TT_ConstraintJunctions))
+TT_UntouchableMacroFunc, TT_ConstraintJunctions,
+TT_StatementAttributeLikeMacro))
   CurrentToken->setType(TT_Unknown);
 CurrentToken->Role.reset();
 CurrentToken->MatchingParen = nullptr;
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -52,6 +52,10 @@
 Macros.insert(
 {&IdentTable.get(WhitespaceSensitiveMacro), TT_UntouchableMacroFunc});
   }
+  for (const std::string &StatementAttributeLikeMacro :
+   Style.StatementAttributeLikeMacros)
+Macros.insert({&IdentTable.get(StatementAttributeLikeMacro),
+   TT_StatementAttributeLikeMacro});
 }
 
 ArrayRef FormatTokenLexer::lex() {
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -96,6 +96,7 @@
   TYPE(RegexLiteral)   \
   TYPE(SelectorName)   \
   TYPE(StartOfName)\
+  TYPE(StatementAttributeLikeMacro)\
   TYPE(StatementMacro)  

[clang] bcc1dee - [clang-format] Add StatementAttributeLikeMacros option

2021-01-17 Thread Björn Schäpers via cfe-commits

Author: Björn Schäpers
Date: 2021-01-18T06:54:31+01:00
New Revision: bcc1dee60019f3a488a04dc7f701f7a692040fed

URL: 
https://github.com/llvm/llvm-project/commit/bcc1dee60019f3a488a04dc7f701f7a692040fed
DIFF: 
https://github.com/llvm/llvm-project/commit/bcc1dee60019f3a488a04dc7f701f7a692040fed.diff

LOG: [clang-format] Add StatementAttributeLikeMacros option

This allows to ignore for example Qts emit when
AlignConsecutiveDeclarations is set, otherwise it is parsed as a type
and it results in some misformating:

unsigned char MyChar = 'x';
emit  signal(MyChar);

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 8eee6187d0c6..928d136ef9ff 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3074,6 +3074,20 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+**StatementAttributeLikeMacros** (``std::vector``)
+  Macros which are ignored in front of a statement, as if they were an
+  attribute. So that they are not parsed as identifier, for example for Qts
+  emit. \code
+AlignConsecutiveDeclarations: true
+StatementAttributeLikeMacros: []
+unsigned char data = 'x';
+emit  signal(data); // This is parsed as variable declaration.
+
+AlignConsecutiveDeclarations: true
+StatementAttributeLikeMacros: [emit]
+unsigned char data = 'x';
+emit signal(data); // Now it's fine again.
+
 **StatementMacros** (``std::vector``)
   A vector of macros that should be interpreted as complete
   statements.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 76d4b6bb5acd..7fcae5bce164 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -296,6 +296,10 @@ clang-format
 - Option ``SpaceBeforeCaseColon`` has been added to add a space before the
   colon in a case or default statement.
 
+- Option ``StatementAttributeLikeMacros`` has been added to declare
+  macros which are not parsed as a type in front of a statement. See
+  the documentation for an example.
+
 
 libclang
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 6b3fb8164a28..943a33cee4fd 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2676,6 +2676,21 @@ struct FormatStyle {
   /// \endcode
   LanguageStandard Standard;
 
+  /// Macros which are ignored in front of a statement, as if they were an
+  /// attribute. So that they are not parsed as identifier, for example for Qts
+  /// emit. \code
+  ///   AlignConsecutiveDeclarations: true
+  ///   StatementAttributeLikeMacros: []
+  ///   unsigned char data = 'x';
+  ///   emit  signal(data); // This is parsed as variable declaration.
+  ///
+  ///   AlignConsecutiveDeclarations: true
+  ///   StatementAttributeLikeMacros: [emit]
+  ///   unsigned char data = 'x';
+  ///   emit signal(data); // Now it's fine again.
+  /// \endcode
+  std::vector StatementAttributeLikeMacros;
+
   /// The number of columns used for tab stops.
   unsigned TabWidth;
 
@@ -2825,9 +2840,11 @@ struct FormatStyle {
SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
BitFieldColonSpacing == R.BitFieldColonSpacing &&
-   Standard == R.Standard && TabWidth == R.TabWidth &&
-   StatementMacros == R.StatementMacros && UseTab == R.UseTab &&
-   UseCRLF == R.UseCRLF && TypenameMacros == R.TypenameMacros;
+   Standard == R.Standard &&
+   StatementAttributeLikeMacros == R.StatementAttributeLikeMacros &&
+   StatementMacros == R.StatementMacros && TabWidth == R.TabWidth &&
+   UseTab == R.UseTab && UseCRLF == R.UseCRLF &&
+   TypenameMacros == R.TypenameMacros;
   }
 
   llvm::Optional GetLanguageStyle(LanguageKind Language) const;

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 1207ac2dcc2b..9f007819326c 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -549,6 +549,8 @@ template <> struct MappingTraits {
Style.ExperimentalAutoDetectBinPacking);
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
+IO.mapOptional("StatementAttributeLikeMacros",
+   Style.StatementAttributeLikeMacros);
 IO.m

[PATCH] D93776: [clang-format] Add StatementAttributeLikeMacros option

2021-01-17 Thread Björn Schäpers via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbcc1dee60019: [clang-format] Add 
StatementAttributeLikeMacros option (authored by HazardyKnusperkeks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93776

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -14731,6 +14731,11 @@
   CHECK_PARSE("AttributeMacros: [attr1, attr2]", AttributeMacros,
   std::vector({"attr1", "attr2"}));
 
+  Style.StatementAttributeLikeMacros.clear();
+  CHECK_PARSE("StatementAttributeLikeMacros: [emit,Q_EMIT]",
+  StatementAttributeLikeMacros,
+  std::vector({"emit", "Q_EMIT"}));
+
   Style.StatementMacros.clear();
   CHECK_PARSE("StatementMacros: [QUNUSED]", StatementMacros,
   std::vector{"QUNUSED"});
@@ -17803,6 +17808,36 @@
"struct constant;",
Style);
 }
+
+TEST_F(FormatTest, StatementAttributeLikeMacros) {
+  FormatStyle Style = getLLVMStyle();
+  StringRef Source = "void Foo::slot() {\n"
+ "  unsigned char MyChar = 'x';\n"
+ "  emit signal(MyChar);\n"
+ "  Q_EMIT signal(MyChar);\n"
+ "}";
+
+  EXPECT_EQ(Source, format(Source, Style));
+
+  Style.AlignConsecutiveDeclarations = true;
+  EXPECT_EQ("void Foo::slot() {\n"
+"  unsigned char MyChar = 'x';\n"
+"  emit  signal(MyChar);\n"
+"  Q_EMIT signal(MyChar);\n"
+"}",
+format(Source, Style));
+
+  Style.StatementAttributeLikeMacros.push_back("emit");
+  EXPECT_EQ(Source, format(Source, Style));
+
+  Style.StatementAttributeLikeMacros = {};
+  EXPECT_EQ("void Foo::slot() {\n"
+"  unsigned char MyChar = 'x';\n"
+"  emit  signal(MyChar);\n"
+"  Q_EMITsignal(MyChar);\n"
+"}",
+format(Source, Style));
+}
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -655,6 +655,9 @@
   return true;
 if (C.Tok->isNot(TT_StartOfName))
   return false;
+if (C.Tok->Previous &&
+C.Tok->Previous->is(TT_StatementAttributeLikeMacro))
+  return false;
 // Check if there is a subsequent name that starts the same declaration.
 for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) {
   if (Next->is(tok::comment))
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1368,7 +1368,8 @@
 TT_ImplicitStringLiteral, TT_InlineASMBrace, TT_JsFatArrow,
 TT_LambdaArrow, TT_NamespaceMacro, TT_OverloadedOperator,
 TT_RegexLiteral, TT_TemplateString, TT_ObjCStringLiteral,
-TT_UntouchableMacroFunc, TT_ConstraintJunctions))
+TT_UntouchableMacroFunc, TT_ConstraintJunctions,
+TT_StatementAttributeLikeMacro))
   CurrentToken->setType(TT_Unknown);
 CurrentToken->Role.reset();
 CurrentToken->MatchingParen = nullptr;
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -52,6 +52,10 @@
 Macros.insert(
 {&IdentTable.get(WhitespaceSensitiveMacro), TT_UntouchableMacroFunc});
   }
+  for (const std::string &StatementAttributeLikeMacro :
+   Style.StatementAttributeLikeMacros)
+Macros.insert({&IdentTable.get(StatementAttributeLikeMacro),
+   TT_StatementAttributeLikeMacro});
 }
 
 ArrayRef FormatTokenLexer::lex() {
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -96,6 +96,7 @@
   TYPE(RegexLiteral)   \
   TYPE(SelectorName)   \
   TYPE(StartOfName)\
+  TYPE(StatementAttributeLikeMac