[clang] b5fef6d - [OpenCL] Allow optional __generic in __remove_address_space utility

2021-12-27 Thread Justas Janickas via cfe-commits

Author: Justas Janickas
Date: 2021-12-27T08:39:21Z
New Revision: b5fef6dbfd6b4c84d61155fd2221064bcc1ecdcf

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

LOG: [OpenCL] Allow optional __generic in __remove_address_space utility

Added: 
clang/test/SemaOpenCLCXX/remove-address-space.clcpp

Modified: 
clang/lib/Headers/opencl-c-base.h

Removed: 
clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp



diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 9c81ddb5e2a73..7485386c82346 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -600,9 +600,11 @@ typedef struct {
 // C++ for OpenCL - __remove_address_space
 #if defined(__OPENCL_CPP_VERSION__)
 template  struct __remove_address_space { using type = _Tp; };
+#if defined(__opencl_c_generic_address_space)
 template  struct __remove_address_space<__generic _Tp> {
   using type = _Tp;
 };
+#endif
 template  struct __remove_address_space<__global _Tp> {
   using type = _Tp;
 };

diff  --git a/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp 
b/clang/test/SemaOpenCLCXX/remove-address-space.clcpp
similarity index 75%
rename from clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
rename to clang/test/SemaOpenCLCXX/remove-address-space.clcpp
index f6f0c3290aa66..e6b2924eab5f8 100644
--- a/clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
+++ b/clang/test/SemaOpenCLCXX/remove-address-space.clcpp
@@ -1,4 +1,8 @@
-// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins 
-finclude-default-header
+// RUN: %clang_cc1 %s -cl-std=clc++1.0 -triple spir-unknown-unknown 
-fdeclare-opencl-builtins -finclude-default-header -verify
+// RUN: %clang_cc1 %s -cl-std=clc++2021 -triple spir-unknown-unknown 
-fdeclare-opencl-builtins -finclude-default-header -verify
+// RUN: %clang_cc1 %s -cl-std=clc++2021 
-cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -triple 
spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header -verify
+
+// expected-no-diagnostics
 
 template
 struct is_same {
@@ -19,8 +23,10 @@ void test_is_same() {
 void test_remove_address_space() {
   static_assert(is_same<__remove_address_space::type, int>::value,
 "type without an address space unexpectedly modified by 
__remove_address_space");
+#if defined(__opencl_c_generic_address_space)
   static_assert(is_same<__remove_address_space<__generic int>::type, 
int>::value,
 "__generic address space not removed by 
__remove_address_space");
+#endif
   static_assert(is_same<__remove_address_space<__global char>::type, 
char>::value,
 "__global address space not removed by 
__remove_address_space");
   static_assert(is_same<__remove_address_space<__private ulong>::type, 
ulong>::value,



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


[PATCH] D110155: [OpenCL] Allow optional __generic in __remove_address_space utility

2021-12-27 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna closed this revision.
Topotuna added a comment.

Closed by commit: rGb5fef6dbfd6b4c84d61155fd2221064bcc1ecdcf 



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

https://reviews.llvm.org/D110155

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


[PATCH] D116271: [Docs] Document C++ for OpenCL 2021 support in clang

2021-12-27 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna added a comment.

Overall, I think that adjustments are accurate. Suggested a couple of small 
edits




Comment at: clang/docs/OpenCLSupport.rst:28-29
 
-For general issues and bugs with OpenCL in clang refer to `Bugzilla
-`__.
+For general issues and bugs with OpenCL in clang refer to `the following 
Github issue
+list
+`__.





Comment at: clang/docs/OpenCLSupport.rst:323
 
-Clang implements language version 1.0 published in `the official
+Clang implements language version 1.0 and 2021 published in `the official
 release of C++ for OpenCL Documentation




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

https://reviews.llvm.org/D116271

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


[clang] 1f07a4a - [CodeGen] Avoid more pointer element type accesses

2021-12-27 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2021-12-27T12:00:22+01:00
New Revision: 1f07a4a5699b73582461880e716e6692cbe3d6a6

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

LOG: [CodeGen] Avoid more pointer element type accesses

Added: 


Modified: 
clang/lib/CodeGen/CGClass.cpp
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/CodeGen/ItaniumCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp
index 8f99ff0d50ff4..d84956c2653e1 100644
--- a/clang/lib/CodeGen/CGClass.cpp
+++ b/clang/lib/CodeGen/CGClass.cpp
@@ -390,7 +390,7 @@ Address CodeGenFunction::GetAddressOfBaseClass(
 llvm::PHINode *PHI = Builder.CreatePHI(BasePtrTy, 2, "cast.result");
 PHI->addIncoming(Value.getPointer(), notNullBB);
 PHI->addIncoming(llvm::Constant::getNullValue(BasePtrTy), origBB);
-Value = Address(PHI, Value.getAlignment());
+Value = Value.withPointer(PHI);
   }
 
   return Value;
@@ -1983,7 +1983,7 @@ void CodeGenFunction::EmitCXXAggrConstructorCall(const 
CXXConstructorDecl *ctor,
   CharUnits eltAlignment =
 arrayBase.getAlignment()
  .alignmentOfArrayElement(getContext().getTypeSizeInChars(type));
-  Address curAddr = Address(cur, eltAlignment);
+  Address curAddr = Address(cur, elementType, eltAlignment);
 
   // Zero initialize the storage, if requested.
   if (zeroInitialize)

diff  --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 3b996b89a1d7d..0968afd820643 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -614,8 +614,8 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   //   every temporary created in a default argument is sequenced before
   //   the construction of the next array element, if any
   CodeGenFunction::RunCleanupsScope CleanupsScope(CGF);
-  LValue elementLV =
-CGF.MakeAddrLValue(Address(currentElement, elementAlign), elementType);
+  LValue elementLV = CGF.MakeAddrLValue(
+  Address(currentElement, llvmElementType, elementAlign), elementType);
   if (filler)
 EmitInitializationToLValue(filler, elementLV);
   else
@@ -1801,6 +1801,7 @@ void AggExprEmitter::VisitArrayInitLoopExpr(const 
ArrayInitLoopExpr *E,
   CharUnits elementSize = CGF.getContext().getTypeSizeInChars(elementType);
   CharUnits elementAlign =
   destPtr.getAlignment().alignmentOfArrayElement(elementSize);
+  llvm::Type *llvmElementType = CGF.ConvertTypeForMem(elementType);
 
   llvm::BasicBlock *entryBB = Builder.GetInsertBlock();
   llvm::BasicBlock *bodyBB = CGF.createBasicBlock("arrayinit.body");
@@ -1810,8 +1811,8 @@ void AggExprEmitter::VisitArrayInitLoopExpr(const 
ArrayInitLoopExpr *E,
   llvm::PHINode *index =
   Builder.CreatePHI(zero->getType(), 2, "arrayinit.index");
   index->addIncoming(zero, entryBB);
-  llvm::Value *element = Builder.CreateInBoundsGEP(
-  begin->getType()->getPointerElementType(), begin, index);
+  llvm::Value *element =
+  Builder.CreateInBoundsGEP(llvmElementType, begin, index);
 
   // Prepare for a cleanup.
   QualType::DestructionKind dtorKind = elementType.isDestructedType();

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index f76ce8a6400d1..ece863ad10777 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -182,6 +182,7 @@ template <> struct DominatingValue {
 
   struct saved_type {
 DominatingLLVMValue::saved_type SavedValue;
+llvm::Type *ElementType;
 CharUnits Alignment;
   };
 
@@ -190,11 +191,11 @@ template <> struct DominatingValue {
   }
   static saved_type save(CodeGenFunction &CGF, type value) {
 return { DominatingLLVMValue::save(CGF, value.getPointer()),
- value.getAlignment() };
+ value.getElementType(), value.getAlignment() };
   }
   static type restore(CodeGenFunction &CGF, saved_type value) {
 return Address(DominatingLLVMValue::restore(CGF, value.SavedValue),
-   value.Alignment);
+   value.ElementType, value.Alignment);
   }
 };
 

diff  --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp 
b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 1a15b09c7b2b9..ce84430dd743e 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -697,8 +697,8 @@ CGCallee ItaniumCXXABI::EmitLoadOfMemberFunctionPointer(
   CharUnits VTablePtrAlign =
 CGF.CGM.getDynamicOffsetAlignment(ThisAddr.getAlignment(), RD,
   CGF.getPointerAlign());
-  llvm::Value *VTable =
-CGF.GetVTablePtr(Address(This, VTablePtrAlign), VTableTy, RD);
+  llvm::Value *VTable = CGF.GetVTablePtr(
+  Addre

[PATCH] D116283: Added an option to add a space between operator overloading and opening parentheses in clang-format

2021-12-27 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/include/clang/Format/Format.h:3383
+///true:  false:
+///void operator++ (int a); vs.void operator++(int
+///a);

Please put the `vs.` on the same column as the others.



Comment at: clang/include/clang/Format/Format.h:3386
+/// \endcode
+bool AfterOperatorOverloading;
 

Please sort alphabetical.



Comment at: clang/lib/Format/Format.cpp:860
Spacing.BeforeNonEmptyParentheses);
+IO.mapOptional("AfterOperatorOverloading",
+   Spacing.AfterOperatorOverloading);

Sort


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116283

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


[PATCH] D116290: [clang-format] Add enforcement of consistent `class`/typename` keyword for template arguments

2021-12-27 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Nice change, some small notes from me.




Comment at: clang/docs/ClangFormatStyleOptions.rst:4003
 
+**TemplateArgumentKeyword** (``TemplateArgumentStyle``) 
:versionbadge:`clang-format 14`
+  Keyword to use for template arguments (``class`` or ``typename``)

Have you edited this by hand? It is on a different (the right) position than in 
`Format.h`.



Comment at: clang/include/clang/Format/Format.h:1963
+  /// \version 14
+  TemplateArgumentStyle TemplateArgumentKeyword;
+

Please sort (as good as possible, I know some things are out of order).



Comment at: clang/lib/Format/Format.cpp:144-145
+IO.enumCase(Value, "Leave", FormatStyle::TAS_Leave);
+IO.enumCase(Value, "typename", FormatStyle::TAS_Typename);
+IO.enumCase(Value, "class", FormatStyle::TAS_Class);
+  }

This is what is printed in the documentation, if generated automatically.



Comment at: clang/lib/Format/Format.cpp:1237
   LLVMStyle.SpacesInConditionalStatement = false;
 
+  LLVMStyle.TemplateArgumentKeyword = FormatStyle::TAS_Leave;

Drop this blank line.



Comment at: clang/lib/Format/TemplateArgumentKeywordFixer.cpp:45
+  StringRef ReplacementStr;
+  tok::TokenKind BadToken;
+  bool KeepTemplateTemplateKW = false;

I think you should rename it to TokenKindToReplace or something like that.
A `is(BadToken)` can be misleading.



Comment at: clang/lib/Format/TemplateArgumentKeywordFixer.cpp:49
+  case FormatStyle::TAS_Leave:
+return {Fixes, 0};
+  case FormatStyle::TAS_Typename:

Should never happen, right? Assert on that.



Comment at: clang/lib/Format/TemplateArgumentKeywordFixer.cpp:51
+  case FormatStyle::TAS_Typename:
+assert(Style.Standard != FormatStyle::LS_Auto);
+KeepTemplateTemplateKW = Style.Standard < FormatStyle::LS_Cpp17;

Why is that? It is certainly possible to have that configuration and we should 
not assert on possible user input. Either error out or handle it. I think we 
should be on the safe side an pretend auto is before 17. Add a note to the 
documentation about that.



Comment at: clang/lib/Format/TemplateArgumentKeywordFixer.cpp:80
+}
+FormatToken *EndTok = Tok->MatchingParen;
+

assert on non nullness



Comment at: clang/lib/Format/TemplateArgumentKeywordFixer.cpp:93
+  bool StartedDefaultArg = Tok->is(tok::equal);
+  auto advanceTok = [&]() {
+Tok = Tok->Next;

Could be located outside of the loop.



Comment at: clang/unittests/Format/TemplateArgumentKeywordFixerTest.cpp:167
+}
+
+} // namespace

Just to be sure add some tests with incomplete code? E.g.
```
templatehttps://reviews.llvm.org/D116290/new/

https://reviews.llvm.org/D116290

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


[clang] 3e65861 - [CodeGen] Avoid one more pointer element type access

2021-12-27 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2021-12-27T12:58:22+01:00
New Revision: 3e6586113157c164d39120139c14295058e88ccb

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

LOG: [CodeGen] Avoid one more pointer element type access

The number of elements is always a SizeTy here.

Added: 


Modified: 
clang/lib/CodeGen/CGDecl.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index e09279c1d455..36185faf942f 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1392,9 +1392,11 @@ void 
CodeGenFunction::EmitAndRegisterVariableArrayDimensions(
 else {
   // Create an artificial VarDecl to generate debug info for.
   IdentifierInfo *NameIdent = VLAExprNames[NameIdx++];
-  auto VlaExprTy = VlaSize.NumElts->getType()->getPointerElementType();
+  assert(cast(VlaSize.NumElts->getType())
+ ->isOpaqueOrPointeeTypeMatches(SizeTy) &&
+ "Number of VLA elements must be SizeTy");
   auto QT = getContext().getIntTypeForBitwidth(
-  VlaExprTy->getScalarSizeInBits(), false);
+  SizeTy->getScalarSizeInBits(), false);
   auto *ArtificialDecl = VarDecl::Create(
   getContext(), const_cast(D.getDeclContext()),
   D.getLocation(), D.getLocation(), NameIdent, QT,



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


[PATCH] D93844: [clang-format] Add possibility to be based on parent directory

2021-12-27 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks marked an inline comment as done.
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/Format.cpp:3067
+  if (!ChildFormatTextToApply.empty()) {
+assert(ChildFormatTextToApply.size() == 1);
+

zwliew wrote:
> Is there a reason behind limiting the number of children configs to 1 in this 
> case? When the fallback is not used, more than 1 children configs are allowed 
> (line 3036).
> 
> Sorry for digging this up, I came across this seemingly arbitrary decision 
> when working on some changes to https://reviews.llvm.org/D72326
Yeah but it doesn't happen, there is at most only one `.clang-format` in the 
parent directory path which is found. So we assert on that and then don't need 
to loop over what is exactly one element big.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93844

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


[PATCH] D72326: [clang-format] Rebased on master: Add option to specify explicit config file

2021-12-27 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added inline comments.



Comment at: clang/lib/Format/Format.cpp:3393
   if (!ChildFormatTextToApply.empty()) {
 assert(ChildFormatTextToApply.size() == 1);
 

zwliew wrote:
> Is there a reason for this to be limited to 1? I came across this case during 
> testing, but I can't think of why this should be so.
See comment on D93844.



Comment at: clang/lib/Format/Format.cpp:3276
+  // Check for explicit config filename
+  if (StyleName.startswith_insensitive("file:")) {
+auto StyleNameFile = StyleName.substr(5);

zwliew wrote:
> Following my code suggestion above, I think this code block could be 
> refactored to this: 
> ```
> // Check for explicit config filename
> if (StyleName.startswith_insensitive("file:")) {
> auto StyleFileName = StyleName.substr(5);
> if (auto ec = loadConfigFile(StyleFileName, FS, &Style)) {
> return make_string_error(ec.message());
> }
> LLVM_DEBUG(llvm::dbgs() << "Using configuration file " << StyleFileName 
> << '\n');
> return Style;
> }
> ```
> 
> What do you think?
> 
> Also, on another note, I feel like the `-style` option is too overloaded. 
> Would it be better to use a separate option like `-style-file` instead?
You can certainly refactor code.

What happens with `-style="Google" -style-file="Foo/Bar"` is it different from 
`-style-file="Foo/Bar" -style="Google"`?
I do not perse disagree, but I think it makes stuff clearer if there is only 
one option.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72326

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


[PATCH] D93844: [clang-format] Add possibility to be based on parent directory

2021-12-27 Thread Zhao Wei Liew via Phabricator via cfe-commits
zwliew added inline comments.



Comment at: clang/lib/Format/Format.cpp:3067
+  if (!ChildFormatTextToApply.empty()) {
+assert(ChildFormatTextToApply.size() == 1);
+

HazardyKnusperkeks wrote:
> zwliew wrote:
> > Is there a reason behind limiting the number of children configs to 1 in 
> > this case? When the fallback is not used, more than 1 children configs are 
> > allowed (line 3036).
> > 
> > Sorry for digging this up, I came across this seemingly arbitrary decision 
> > when working on some changes to https://reviews.llvm.org/D72326
> Yeah but it doesn't happen, there is at most only one `.clang-format` in the 
> parent directory path which is found. So we assert on that and then don't 
> need to loop over what is exactly one element big.
Thanks for the reply. However, I don't think that's true. Yes, it's only 
possible to find one `.clang-format` file in the first parent directory. But if 
it has `BasedOnStyle: InheritParentConfig` set, then we could find another 
`.clang-format` file in the "grandparent" directory. In this case, we'll have 2 
elements in `ChildFormatTextToApply`, but only the very first one will actually 
be applied.

To illustrate, suppose we have the following file structure:
```
- .clang-format
- foo
  |- .clang-format
  |- input.cpp
```

Both `.clang-format` files have `BasedOnStyle: InheritParentConfig` set. When 
running `clang-format --style=file foo/input.cpp`, only the inner config is 
applied on the fallback style, while the outer config is ignored. When testing 
on a debug build, I encountered a crash due to the failed assert. When removing 
the assert, and using a loop to apply the configs, both the inner and outer 
configs are applied, which I believe is the expected behaviour.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93844

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


[PATCH] D116283: Added an option to add a space between operator overloading and opening parentheses in clang-format

2021-12-27 Thread Rajat Bajpai via Phabricator via cfe-commits
rajatbajpai updated this revision to Diff 396302.
rajatbajpai added a comment.

Incorporated review comments.

Changelog:

1. Using unit test case instead of lit test case.
2. Placed the option according to alphabetical order.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116283

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -14542,6 +14542,22 @@
   // verifyFormat("X A::operator++ (T);", SomeSpace2);
   verifyFormat("int x = int (y);", SomeSpace2);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
+
+  FormatStyle SpaceAfterOperatorOverloading = getLLVMStyle();
+  SpaceAfterOperatorOverloading.SpaceBeforeParens = FormatStyle::SBPO_Custom;
+  SpaceAfterOperatorOverloading.SpaceBeforeParensOptions
+  .AfterOperatorOverloading = true;
+
+  verifyFormat("auto operator++ () -> int;", SpaceAfterOperatorOverloading);
+  verifyFormat("X A::operator++ ();", SpaceAfterOperatorOverloading);
+  verifyFormat("auto func() -> int;", SpaceAfterOperatorOverloading);
+
+  SpaceAfterOperatorOverloading.SpaceBeforeParensOptions
+  .AfterOperatorOverloading = false;
+
+  verifyFormat("auto operator++() -> int;", SpaceAfterOperatorOverloading);
+  verifyFormat("X A::operator++();", SpaceAfterOperatorOverloading);
+  verifyFormat("auto func() -> int;", SpaceAfterOperatorOverloading);
 }
 
 TEST_F(FormatTest, SpaceAfterLogicalNot) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2921,9 +2921,15 @@
 }
 
 bool TokenAnnotator::spaceRequiredBeforeParens(const FormatToken &Right) const {
-  return Style.SpaceBeforeParens == FormatStyle::SBPO_Always ||
- (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
-  Right.ParameterCount > 0);
+  if (Style.SpaceBeforeParens == FormatStyle::SBPO_Always)
+return true;
+  if (Right.is(TT_OverloadedOperatorLParen) &&
+  Style.SpaceBeforeParensOptions.AfterOperatorOverloading)
+return true;
+  if (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
+  Right.ParameterCount > 0)
+return true;
+  return false;
 }
 
 bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -855,10 +855,10 @@
 IO.mapOptional("AfterFunctionDeclarationName",
Spacing.AfterFunctionDeclarationName);
 IO.mapOptional("AfterIfMacros", Spacing.AfterIfMacros);
-IO.mapOptional("BeforeNonEmptyParentheses",
-   Spacing.BeforeNonEmptyParentheses);
 IO.mapOptional("AfterOperatorOverloading",
Spacing.AfterOperatorOverloading);
+IO.mapOptional("BeforeNonEmptyParentheses",
+   Spacing.BeforeNonEmptyParentheses);
   }
 };
 
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3368,6 +3368,13 @@
 ///   
 /// \endcode
 bool AfterIfMacros;
+/// If ``true``, put a space between operator overloading and opening
+/// parentheses.
+/// \code
+///true:  false:
+///void operator++ (int a);vs.void operator++(int a);
+/// \endcode
+bool AfterOperatorOverloading;
 /// If ``true``, put a space before opening parentheses only if the
 /// parentheses are not empty.
 /// \code
@@ -3376,20 +3383,12 @@
 ///f (a); f();
 /// \endcode
 bool BeforeNonEmptyParentheses;
-/// If ``true``, put a space between operator overloading and opening
-/// parentheses.
-/// \code
-///true:  false:
-///void operator++ (int a); vs.void operator++(int
-///a);
-/// \endcode
-bool AfterOperatorOverloading;
 
 SpaceBeforeParensCustom()
 : AfterControlStatements(false), AfterForeachMacros(false),
   AfterFunctionDeclarationName(false),
   AfterFunctionDefinitionName(false), AfterIfMacros(false),
-  BeforeNonEmptyParentheses(false), AfterOperatorOverloading(false) {}
+  AfterOperatorOverloading(false), BeforeNonEmptyParentheses(false) {}
 
 bool operator==(const SpaceBeforeParensCustom &Other) const {
   re

[PATCH] D72326: [clang-format] Rebased on master: Add option to specify explicit config file

2021-12-27 Thread Zhao Wei Liew via Phabricator via cfe-commits
zwliew added inline comments.



Comment at: clang/lib/Format/Format.cpp:3276
+  // Check for explicit config filename
+  if (StyleName.startswith_insensitive("file:")) {
+auto StyleNameFile = StyleName.substr(5);

HazardyKnusperkeks wrote:
> zwliew wrote:
> > Following my code suggestion above, I think this code block could be 
> > refactored to this: 
> > ```
> > // Check for explicit config filename
> > if (StyleName.startswith_insensitive("file:")) {
> > auto StyleFileName = StyleName.substr(5);
> > if (auto ec = loadConfigFile(StyleFileName, FS, &Style)) {
> > return make_string_error(ec.message());
> > }
> > LLVM_DEBUG(llvm::dbgs() << "Using configuration file " << StyleFileName 
> > << '\n');
> > return Style;
> > }
> > ```
> > 
> > What do you think?
> > 
> > Also, on another note, I feel like the `-style` option is too overloaded. 
> > Would it be better to use a separate option like `-style-file` instead?
> You can certainly refactor code.
> 
> What happens with `-style="Google" -style-file="Foo/Bar"` is it different 
> from `-style-file="Foo/Bar" -style="Google"`?
> I do not perse disagree, but I think it makes stuff clearer if there is only 
> one option.
Fair enough. Some ideas off the top of my head that resolve the ambiguity sound 
needlessly complicated. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72326

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


[PATCH] D116313: [MSVC] Silence -Wnon-virtual-dtor on DIA APIs

2021-12-27 Thread Alexandre Ganea via Phabricator via cfe-commits
aganea created this revision.
aganea added reviewers: mstorsjo, amccarth, hans.
aganea requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

When building LLVM with Clang 13.0 on Windows, I see a bunch of 
`-Wnon-virtual-dtor` errors on DIA (Debug Interface Access) COM APIs.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116313

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  llvm/include/llvm/DebugInfo/PDB/DIA/DIASupport.h


Index: llvm/include/llvm/DebugInfo/PDB/DIA/DIASupport.h
===
--- llvm/include/llvm/DebugInfo/PDB/DIA/DIASupport.h
+++ llvm/include/llvm/DebugInfo/PDB/DIA/DIASupport.h
@@ -27,7 +27,14 @@
 
 // DIA headers must come after windows headers.
 #include 
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+#endif
 #include 
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
 #include 
 
 #endif // LLVM_DEBUGINFO_PDB_DIA_DIASUPPORT_H
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -47,7 +47,14 @@
 // Make sure this comes before MSVCSetupApi.h
 #include 
 
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+#endif
 #include "MSVCSetupApi.h"
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
 #include "llvm/Support/COM.h"
 _COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
 _COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));


Index: llvm/include/llvm/DebugInfo/PDB/DIA/DIASupport.h
===
--- llvm/include/llvm/DebugInfo/PDB/DIA/DIASupport.h
+++ llvm/include/llvm/DebugInfo/PDB/DIA/DIASupport.h
@@ -27,7 +27,14 @@
 
 // DIA headers must come after windows headers.
 #include 
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+#endif
 #include 
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
 #include 
 
 #endif // LLVM_DEBUGINFO_PDB_DIA_DIASUPPORT_H
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -47,7 +47,14 @@
 // Make sure this comes before MSVCSetupApi.h
 #include 
 
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+#endif
 #include "MSVCSetupApi.h"
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
 #include "llvm/Support/COM.h"
 _COM_SMARTPTR_TYPEDEF(ISetupConfiguration, __uuidof(ISetupConfiguration));
 _COM_SMARTPTR_TYPEDEF(ISetupConfiguration2, __uuidof(ISetupConfiguration2));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116283: Added an option to add a space between operator overloading and opening parentheses in clang-format

2021-12-27 Thread Rajat Bajpai via Phabricator via cfe-commits
rajatbajpai updated this revision to Diff 396314.
rajatbajpai added a comment.

Fixed the patch file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116283

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -14542,6 +14542,22 @@
   // verifyFormat("X A::operator++ (T);", SomeSpace2);
   verifyFormat("int x = int (y);", SomeSpace2);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
+
+  FormatStyle SpaceAfterOperatorOverloading = getLLVMStyle();
+  SpaceAfterOperatorOverloading.SpaceBeforeParens = FormatStyle::SBPO_Custom;
+  SpaceAfterOperatorOverloading.SpaceBeforeParensOptions
+  .AfterOperatorOverloading = true;
+
+  verifyFormat("auto operator++ () -> int;", SpaceAfterOperatorOverloading);
+  verifyFormat("X A::operator++ ();", SpaceAfterOperatorOverloading);
+  verifyFormat("auto func() -> int;", SpaceAfterOperatorOverloading);
+
+  SpaceAfterOperatorOverloading.SpaceBeforeParensOptions
+  .AfterOperatorOverloading = false;
+
+  verifyFormat("auto operator++() -> int;", SpaceAfterOperatorOverloading);
+  verifyFormat("X A::operator++();", SpaceAfterOperatorOverloading);
+  verifyFormat("auto func() -> int;", SpaceAfterOperatorOverloading);
 }
 
 TEST_F(FormatTest, SpaceAfterLogicalNot) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2921,9 +2921,15 @@
 }
 
 bool TokenAnnotator::spaceRequiredBeforeParens(const FormatToken &Right) const {
-  return Style.SpaceBeforeParens == FormatStyle::SBPO_Always ||
- (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
-  Right.ParameterCount > 0);
+  if (Style.SpaceBeforeParens == FormatStyle::SBPO_Always)
+return true;
+  if (Right.is(TT_OverloadedOperatorLParen) &&
+  Style.SpaceBeforeParensOptions.AfterOperatorOverloading)
+return true;
+  if (Style.SpaceBeforeParensOptions.BeforeNonEmptyParentheses &&
+  Right.ParameterCount > 0)
+return true;
+  return false;
 }
 
 bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -855,6 +855,8 @@
 IO.mapOptional("AfterFunctionDeclarationName",
Spacing.AfterFunctionDeclarationName);
 IO.mapOptional("AfterIfMacros", Spacing.AfterIfMacros);
+IO.mapOptional("AfterOperatorOverloading",
+   Spacing.AfterOperatorOverloading);
 IO.mapOptional("BeforeNonEmptyParentheses",
Spacing.BeforeNonEmptyParentheses);
   }
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3368,6 +3368,13 @@
 ///   
 /// \endcode
 bool AfterIfMacros;
+/// If ``true``, put a space between operator overloading and opening
+/// parentheses.
+/// \code
+///true:  false:
+///void operator++ (int a);vs.void operator++(int a);
+/// \endcode
+bool AfterOperatorOverloading;
 /// If ``true``, put a space before opening parentheses only if the
 /// parentheses are not empty.
 /// \code
@@ -3381,7 +3388,7 @@
 : AfterControlStatements(false), AfterForeachMacros(false),
   AfterFunctionDeclarationName(false),
   AfterFunctionDefinitionName(false), AfterIfMacros(false),
-  BeforeNonEmptyParentheses(false) {}
+  AfterOperatorOverloading(false), BeforeNonEmptyParentheses(false) {}
 
 bool operator==(const SpaceBeforeParensCustom &Other) const {
   return AfterControlStatements == Other.AfterControlStatements &&
@@ -3390,6 +3397,7 @@
  Other.AfterFunctionDeclarationName &&
  AfterFunctionDefinitionName == Other.AfterFunctionDefinitionName &&
  AfterIfMacros == Other.AfterIfMacros &&
+ AfterOperatorOverloading == Other.AfterOperatorOverloading &&
  BeforeNonEmptyParentheses == Other.BeforeNonEmptyParentheses;
 }
   };
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -3752,6 +3752,13 @@
IF (...)vs.IF(...)
 

[PATCH] D115921: [RISCV] Refactor the RISCV ISA extension info and target features to support multiple extension version

2021-12-27 Thread Zixuan Wu via Phabricator via cfe-commits
zixuan-wu added inline comments.



Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:33
+  bool operator!=(const RISCVExtensionVersion &Version) const {
+return !operator==(Version);
+  }

craig.topper wrote:
> Use `!(*this == Version)`
Good taste.



Comment at: llvm/lib/Target/RISCV/RISCVSubtarget.cpp:91
 StringRef ABIName) {
+  initializeEnvironment();
   // Determine default and user-specified characteristics

craig.topper wrote:
> Why do we need to initialize things now but didn't before?
After the constructor is workable to initialize, no need for 
initializeEnvironment. So remove it.


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

https://reviews.llvm.org/D115921

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


[PATCH] D115921: [RISCV] Refactor the RISCV ISA extension info and target features to support multiple extension version

2021-12-27 Thread Zixuan Wu via Phabricator via cfe-commits
zixuan-wu updated this revision to Diff 396147.
zixuan-wu edited the summary of this revision.
zixuan-wu added a comment.

Address all comments.


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

https://reviews.llvm.org/D115921

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-arch-version.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Object/ELFObjectFile.cpp
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes-version.ll
  llvm/test/tools/llvm-objdump/ELF/RISCV/unknown-arch-attr.test

Index: llvm/test/tools/llvm-objdump/ELF/RISCV/unknown-arch-attr.test
===
--- llvm/test/tools/llvm-objdump/ELF/RISCV/unknown-arch-attr.test
+++ llvm/test/tools/llvm-objdump/ELF/RISCV/unknown-arch-attr.test
@@ -3,7 +3,7 @@
 ## The expected behavior is to ignore the unrecognized arch feature and
 ## continue to process the following arch features.
 ##
-## The object file has the "rv32i2p0_x1p0_m2p0" arch feature. "x1p0" is an
+## The object file has the "rv32i2p0_y1p0_m2p0" arch feature. "y1p0" is an
 ## unrecognized architecture extension. llvm-objdump will ignore it and decode
 ## "mul" instruction correctly according to "m2p0" in the arch feature.
 ##
@@ -34,5 +34,5 @@
 Content: 3385C502
   - Name:.riscv.attributes
 Type:SHT_RISCV_ATTRIBUTES
-## The content is the encoding of the arch feature "rv32i2p0_x1p0_m2p0"
-Content: 4123007269736376000119000572763332693270305F783170305F6D32703000
+## The content is the encoding of the arch feature "rv32i2p0_y1p0_m2p0"
+Content: 4123007269736376000119000572763332693270305F793170305F6D32703000
Index: llvm/test/CodeGen/RISCV/attributes-version.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/attributes-version.ll
@@ -0,0 +1,81 @@
+; Generate ELF attributes from llc.
+
+; RUN: llc -mtriple=riscv32 -mattr=+m %s -o - | FileCheck --check-prefix=RV32M %s
+; RUN: llc -mtriple=riscv32 -mattr=+a %s -o - | FileCheck --check-prefix=RV32A %s
+; RUN: llc -mtriple=riscv32 -mattr=+f %s -o - | FileCheck --check-prefix=RV32F %s
+; RUN: llc -mtriple=riscv32 -mattr=+d %s -o - | FileCheck --check-prefix=RV32D %s
+; RUN: llc -mtriple=riscv32 -mattr=+c %s -o - | FileCheck --check-prefix=RV32C %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfhmin %s -o - | FileCheck --check-prefix=RV32ZFHMIN %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfh %s -o - | FileCheck --check-prefix=RV32ZFH %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zba %s -o - | FileCheck --check-prefix=RV32ZBA %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb %s -o - | FileCheck --check-prefix=RV32ZBB %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbc %s -o - | FileCheck --check-prefix=RV32ZBC %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbe %s -o - | FileCheck --check-prefix=RV32ZBE %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbf %s -o - | FileCheck --check-prefix=RV32ZBF %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbm %s -o - | FileCheck --check-prefix=RV32ZBM %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbp %s -o - | FileCheck --check-prefix=RV32ZBP %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV32ZBR %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s
+
+
+; RV32M: .attribute 5, "rv32i2p0_m2p0"
+; RV32A: .attribute 5, "rv32i2p0_a2p0"
+; RV32F: .attribute 5, "rv32i2p0_f2p0"
+; RV32D: .attribute 5, "rv32i2p0_f2p0_d2p0"
+; RV32C: .attribute 5, "rv32i2p0_c2p0"
+; RV32V: .attribute 5, "rv32i2p0_v0p10_zvlsseg0p10"
+; RV32ZFHMIN: .attribute 5, "rv32i2p0_f2p0_zfhmin0p1"
+; RV32ZFH: .attribute 5, "rv32i2p0_f2p0_zfh0p1_zfhmin0p1"
+; RV32ZBA: .attribute 5, "rv32i2p0_zba1p0"
+; RV32ZBB: .attribute 5, "rv32i2p0_zbb1p0"
+; RV32ZBC: .attribute 5, "rv32i2p0_zbc1p0"
+; RV32ZBE: .attribute 5, "rv32i2p0_zbe0p93"
+; RV32ZBF: .attribute 5, "rv32i2p0_zbf0p93"
+; RV32ZBM: .attribute 5, "rv32i2p0_zbm0p93"
+; RV32ZBP: .attribute 5, "rv32i2p0_zbp0p93"
+; RV32ZBR: .attribute 5, "rv32i2p0_zbr0p93"
+; RV32ZBS: .attribute 5, "rv32i2p0_zbs1p0"
+; RV32ZBT: .attribute 5, "rv32i2p0_zbt0p93"
+
+
+; RUN: llc -mtriple=riscv32 -mattr=+m0p7 < %s 2>&1 | FileCheck --check-prefix=RV32M0P7 %s
+; RUN: llc -mtriple=riscv32 -mattr=+a0p7 < %s 2>&1 | FileCheck --check-prefix=RV32A0P7 %s
+; RUN: llc -mtriple=riscv32 -mattr=+f0p7 < %s 2>&1 | FileCheck --check-prefix=RV32F0P7 %s
+; RUN: llc -mtriple=riscv32 -mattr=+d0p7 < %s 2>&1 | FileCheck --check-prefix=RV32D0P7 %s
+; RUN: llc -mtriple

[PATCH] D115921: [RISCV] Refactor the RISCV ISA extension info and target features to support multiple extension version

2021-12-27 Thread Zixuan Wu via Phabricator via cfe-commits
zixuan-wu updated this revision to Diff 396148.

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

https://reviews.llvm.org/D115921

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-arch-version.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Object/ELFObjectFile.cpp
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes-version.ll
  llvm/test/tools/llvm-objdump/ELF/RISCV/unknown-arch-attr.test

Index: llvm/test/tools/llvm-objdump/ELF/RISCV/unknown-arch-attr.test
===
--- llvm/test/tools/llvm-objdump/ELF/RISCV/unknown-arch-attr.test
+++ llvm/test/tools/llvm-objdump/ELF/RISCV/unknown-arch-attr.test
@@ -3,7 +3,7 @@
 ## The expected behavior is to ignore the unrecognized arch feature and
 ## continue to process the following arch features.
 ##
-## The object file has the "rv32i2p0_x1p0_m2p0" arch feature. "x1p0" is an
+## The object file has the "rv32i2p0_y1p0_m2p0" arch feature. "y1p0" is an
 ## unrecognized architecture extension. llvm-objdump will ignore it and decode
 ## "mul" instruction correctly according to "m2p0" in the arch feature.
 ##
@@ -34,5 +34,5 @@
 Content: 3385C502
   - Name:.riscv.attributes
 Type:SHT_RISCV_ATTRIBUTES
-## The content is the encoding of the arch feature "rv32i2p0_x1p0_m2p0"
-Content: 4123007269736376000119000572763332693270305F783170305F6D32703000
+## The content is the encoding of the arch feature "rv32i2p0_y1p0_m2p0"
+Content: 4123007269736376000119000572763332693270305F793170305F6D32703000
Index: llvm/test/CodeGen/RISCV/attributes-version.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/attributes-version.ll
@@ -0,0 +1,81 @@
+; Generate ELF attributes from llc.
+
+; RUN: llc -mtriple=riscv32 -mattr=+m %s -o - | FileCheck --check-prefix=RV32M %s
+; RUN: llc -mtriple=riscv32 -mattr=+a %s -o - | FileCheck --check-prefix=RV32A %s
+; RUN: llc -mtriple=riscv32 -mattr=+f %s -o - | FileCheck --check-prefix=RV32F %s
+; RUN: llc -mtriple=riscv32 -mattr=+d %s -o - | FileCheck --check-prefix=RV32D %s
+; RUN: llc -mtriple=riscv32 -mattr=+c %s -o - | FileCheck --check-prefix=RV32C %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfhmin %s -o - | FileCheck --check-prefix=RV32ZFHMIN %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfh %s -o - | FileCheck --check-prefix=RV32ZFH %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zba %s -o - | FileCheck --check-prefix=RV32ZBA %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbb %s -o - | FileCheck --check-prefix=RV32ZBB %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbc %s -o - | FileCheck --check-prefix=RV32ZBC %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbe %s -o - | FileCheck --check-prefix=RV32ZBE %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbf %s -o - | FileCheck --check-prefix=RV32ZBF %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbm %s -o - | FileCheck --check-prefix=RV32ZBM %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbp %s -o - | FileCheck --check-prefix=RV32ZBP %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbr %s -o - | FileCheck --check-prefix=RV32ZBR %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbs %s -o - | FileCheck --check-prefix=RV32ZBS %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbt %s -o - | FileCheck --check-prefix=RV32ZBT %s
+
+
+; RV32M: .attribute 5, "rv32i2p0_m2p0"
+; RV32A: .attribute 5, "rv32i2p0_a2p0"
+; RV32F: .attribute 5, "rv32i2p0_f2p0"
+; RV32D: .attribute 5, "rv32i2p0_f2p0_d2p0"
+; RV32C: .attribute 5, "rv32i2p0_c2p0"
+; RV32V: .attribute 5, "rv32i2p0_v0p10_zvlsseg0p10"
+; RV32ZFHMIN: .attribute 5, "rv32i2p0_f2p0_zfhmin0p1"
+; RV32ZFH: .attribute 5, "rv32i2p0_f2p0_zfh0p1_zfhmin0p1"
+; RV32ZBA: .attribute 5, "rv32i2p0_zba1p0"
+; RV32ZBB: .attribute 5, "rv32i2p0_zbb1p0"
+; RV32ZBC: .attribute 5, "rv32i2p0_zbc1p0"
+; RV32ZBE: .attribute 5, "rv32i2p0_zbe0p93"
+; RV32ZBF: .attribute 5, "rv32i2p0_zbf0p93"
+; RV32ZBM: .attribute 5, "rv32i2p0_zbm0p93"
+; RV32ZBP: .attribute 5, "rv32i2p0_zbp0p93"
+; RV32ZBR: .attribute 5, "rv32i2p0_zbr0p93"
+; RV32ZBS: .attribute 5, "rv32i2p0_zbs1p0"
+; RV32ZBT: .attribute 5, "rv32i2p0_zbt0p93"
+
+
+; RUN: llc -mtriple=riscv32 -mattr=+m0p7 < %s 2>&1 | FileCheck --check-prefix=RV32M0P7 %s
+; RUN: llc -mtriple=riscv32 -mattr=+a0p7 < %s 2>&1 | FileCheck --check-prefix=RV32A0P7 %s
+; RUN: llc -mtriple=riscv32 -mattr=+f0p7 < %s 2>&1 | FileCheck --check-prefix=RV32F0P7 %s
+; RUN: llc -mtriple=riscv32 -mattr=+d0p7 < %s 2>&1 | FileCheck --check-prefix=RV32D0P7 %s
+; RUN: llc -mtriple=riscv32 -mattr=+c0p7 < %s 2>&1 | FileCheck --check-prefix=RV32C0P7 %s
+; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfhmin0p7 < %s 2>&1 

[PATCH] D115790: [Coroutines] Set presplit attribute in Clang and mlir

2021-12-27 Thread Eugene Zhulenev via Phabricator via cfe-commits
ezhulenev accepted this revision.
ezhulenev added inline comments.



Comment at: mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp:201
+ StringAttr::get(ctx, "0")})}));
+
   CoroMachinery machinery;

nit: builder has an API to simplify attributes construction: 
https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/IR/Builders.h#L92-L100


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

https://reviews.llvm.org/D115790

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


[PATCH] D115790: [Coroutines] Set presplit attribute in Clang and mlir

2021-12-27 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 396254.
ChuanqiXu added a comment.

Address comments.


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

https://reviews.llvm.org/D115790

Files:
  clang/lib/CodeGen/CGCoroutine.cpp
  clang/test/CodeGenCoroutines/coro-always-inline.cpp
  clang/test/CodeGenCoroutines/coro-attributes.cpp
  llvm/docs/Coroutines.rst
  llvm/lib/Transforms/Coroutines/CoroEarly.cpp
  llvm/lib/Transforms/Coroutines/CoroInternal.h
  llvm/test/Transforms/Coroutines/coro-debug-O2.ll
  llvm/test/Transforms/Coroutines/coro-debug-coro-frame.ll
  llvm/test/Transforms/Coroutines/coro-debug-dbg.values-not_used_in_frame.ll
  llvm/test/Transforms/Coroutines/coro-debug-dbg.values.ll
  llvm/test/Transforms/Coroutines/coro-debug-frame-variable.ll
  llvm/test/Transforms/Coroutines/coro-noalias-param.ll
  llvm/test/Transforms/Coroutines/coro-split-01.ll
  llvm/test/Transforms/Coroutines/coro-split-recursive.ll
  llvm/test/Transforms/Coroutines/ex0.ll
  llvm/test/Transforms/Coroutines/ex1.ll
  llvm/test/Transforms/Coroutines/ex2.ll
  llvm/test/Transforms/Coroutines/ex3.ll
  llvm/test/Transforms/Coroutines/ex4.ll
  llvm/test/Transforms/Coroutines/ex5.ll
  llvm/test/Transforms/Coroutines/phi-coro-end.ll
  llvm/test/Transforms/Coroutines/restart-trigger.ll
  mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp
  mlir/test/mlir-opt/async.mlir

Index: mlir/test/mlir-opt/async.mlir
===
--- /dev/null
+++ mlir/test/mlir-opt/async.mlir
@@ -0,0 +1,80 @@
+// Check if mlir marks the corresponding function with required coroutine attribute.
+//
+// RUN:   mlir-opt %s -async-to-async-runtime  \
+// RUN:   -async-runtime-ref-counting  \
+// RUN:   -async-runtime-ref-counting-opt  \
+// RUN:   -convert-async-to-llvm   \
+// RUN:   -convert-linalg-to-loops \
+// RUN:   -convert-scf-to-std  \
+// RUN:   -convert-linalg-to-llvm  \
+// RUN:   -convert-memref-to-llvm  \
+// RUN:   -convert-arith-to-llvm   \
+// RUN:   -convert-std-to-llvm \
+// RUN:   -reconcile-unrealized-casts  \
+// RUN: | FileCheck %s
+
+// CHECK: llvm.func @async_execute_fn{{.*}}attributes{{.*}}"coroutine.presplit", "0"
+// CHECK: llvm.func @async_execute_fn_0{{.*}}attributes{{.*}}"coroutine.presplit", "0"
+// CHECK: llvm.func @async_execute_fn_1{{.*}}attributes{{.*}}"coroutine.presplit", "0"
+
+func @main() {
+  %i0 = arith.constant 0 : index
+  %i1 = arith.constant 1 : index
+  %i2 = arith.constant 2 : index
+  %i3 = arith.constant 3 : index
+
+  %c0 = arith.constant 0.0 : f32
+  %c1 = arith.constant 1.0 : f32
+  %c2 = arith.constant 2.0 : f32
+  %c3 = arith.constant 3.0 : f32
+  %c4 = arith.constant 4.0 : f32
+
+  %A = memref.alloc() : memref<4xf32>
+  linalg.fill(%c0, %A) : f32, memref<4xf32>
+
+  %U = memref.cast %A :  memref<4xf32> to memref<*xf32>
+  call @print_memref_f32(%U): (memref<*xf32>) -> ()
+
+  memref.store %c1, %A[%i0]: memref<4xf32>
+  call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
+  call @print_memref_f32(%U): (memref<*xf32>) -> ()
+
+  %outer = async.execute {
+memref.store %c2, %A[%i1]: memref<4xf32>
+call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
+call @print_memref_f32(%U): (memref<*xf32>) -> ()
+
+// No op async region to create a token for testing async dependency.
+%noop = async.execute {
+  call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
+  async.yield
+}
+
+%inner = async.execute [%noop] {
+  memref.store %c3, %A[%i2]: memref<4xf32>
+  call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
+  call @print_memref_f32(%U): (memref<*xf32>) -> ()
+
+  async.yield
+}
+async.await %inner : !async.token
+
+memref.store %c4, %A[%i3]: memref<4xf32>
+call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
+call @print_memref_f32(%U): (memref<*xf32>) -> ()
+
+async.yield
+  }
+  async.await %outer : !async.token
+
+  call @mlirAsyncRuntimePrintCurrentThreadId(): () -> ()
+  call @print_memref_f32(%U): (memref<*xf32>) -> ()
+
+  memref.dealloc %A : memref<4xf32>
+
+  return
+}
+
+func private @mlirAsyncRuntimePrintCurrentThreadId() -> ()
+
+func private @print_memref_f32(memref<*xf32>) attributes { llvm.emit_c_interface }
Index: mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp
===
--- mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp
+++ mlir/lib/Dialect/Async/Transforms/AsyncToAsyncRuntime.cpp
@@ -190,6 +190,14 @@
 }
  

[PATCH] D116170: [clang-format] Add penalty for breaking after '('

2021-12-27 Thread G Pery via Phabricator via cfe-commits
GPery updated this revision to Diff 396317.
GPery edited the summary of this revision.
GPery added a comment.

Add a unit test and initialisation in LLVMStyle


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116170

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18512,6 +18512,17 @@
 format("int a = /* long block comment */ 42;", Style));
 }
 
+TEST_F(FormatTest, BreakPenaltyAfterLParen) {
+	FormatStyle Style = getLLVMStyle();
+	Style.PenaltyBreakOpenParenthesis = 100;
+	Style.ColumnLimit = 14;
+	Style.PenaltyExcessCharacter = 1;
+EXPECT_EQ("int foo(int );",
+  format("int foo("
+ "int );",
+ Style));
+}
+
 #define EXPECT_ALL_STYLES_EQUAL(Styles)\
   for (size_t i = 1; i < Styles.size(); ++i)   \
   EXPECT_EQ(Styles[0], Styles[i])  \
@@ -18717,6 +18728,8 @@
   PenaltyBreakBeforeFirstCallParameter, 1234u);
   CHECK_PARSE("PenaltyBreakTemplateDeclaration: 1234",
   PenaltyBreakTemplateDeclaration, 1234u);
+  CHECK_PARSE("PenaltyBreakOpenParenthesis: 1234", PenaltyBreakOpenParenthesis,
+  1234u);
   CHECK_PARSE("PenaltyExcessCharacter: 1234", PenaltyExcessCharacter, 1234u);
   CHECK_PARSE("PenaltyReturnTypeOnItsOwnLine: 1234",
   PenaltyReturnTypeOnItsOwnLine, 1234u);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2907,6 +2907,8 @@
   }
   if (Left.ClosesTemplateDeclaration)
 return Style.PenaltyBreakTemplateDeclaration;
+  if (Left.is(tok::l_paren))
+return Style.PenaltyBreakOpenParenthesis;
   if (Left.is(TT_ConditionalExpr))
 return prec::Conditional;
   prec::Level Level = Left.getPrecedence();
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -759,6 +759,8 @@
 IO.mapOptional("PenaltyBreakString", Style.PenaltyBreakString);
 IO.mapOptional("PenaltyBreakTemplateDeclaration",
Style.PenaltyBreakTemplateDeclaration);
+IO.mapOptional("PenaltyBreakOpenParenthesis",
+   Style.PenaltyBreakOpenParenthesis);
 IO.mapOptional("PenaltyExcessCharacter", Style.PenaltyExcessCharacter);
 IO.mapOptional("PenaltyReturnTypeOnItsOwnLine",
Style.PenaltyReturnTypeOnItsOwnLine);
@@ -1233,6 +1235,7 @@
   LLVMStyle.PenaltyReturnTypeOnItsOwnLine = 60;
   LLVMStyle.PenaltyBreakBeforeFirstCallParameter = 19;
   LLVMStyle.PenaltyBreakTemplateDeclaration = prec::Relational;
+  LLVMStyle.PenaltyBreakOpenParenthesis = 0;
   LLVMStyle.PenaltyIndentedWhitespace = 0;
 
   LLVMStyle.DisableFormat = false;
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -2895,6 +2895,10 @@
   /// \version 7
   unsigned PenaltyBreakTemplateDeclaration;
 
+  /// The penalty for breaking after ``(``.
+  /// \version 14
+  unsigned PenaltyBreakOpenParenthesis;
+
   /// The penalty for each character outside of the column limit.
   /// \version 3.7
   unsigned PenaltyExcessCharacter;
@@ -3781,6 +3785,7 @@
R.PenaltyBreakBeforeFirstCallParameter &&
PenaltyBreakComment == R.PenaltyBreakComment &&
PenaltyBreakFirstLessLess == R.PenaltyBreakFirstLessLess &&
+   PenaltyBreakOpenParenthesis == R.PenaltyBreakOpenParenthesis &&
PenaltyBreakString == R.PenaltyBreakString &&
PenaltyExcessCharacter == R.PenaltyExcessCharacter &&
PenaltyReturnTypeOnItsOwnLine == R.PenaltyReturnTypeOnItsOwnLine &&
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -3194,6 +3194,9 @@
 **PenaltyBreakTemplateDeclaration** (``Unsigned``) :versionbadge:`clang-format 7`
   The penalty for breaking after template declaration.
 
+**PenaltyBreakOpenParenthesis** (``Unsigned``) :versionbadge:`clang-format 14`
+  The penalty for breaking after ``(``.
+
 **PenaltyExcessCharacter** (``Unsigned``) :versionbadge:`clang-format 3.7`
   The penalty for each character outsi

[PATCH] D116314: [Clangfmt] Add style to separate definition blocks

2021-12-27 Thread ksyx via Phabricator via cfe-commits
ksyx created this revision.
ksyx added a reviewer: MyDeveloperDay.
ksyx added projects: clang-format, clang.
ksyx requested review of this revision.
Herald added a subscriber: cfe-commits.

This commit resolves GitHub issue #45895 
 (Bugzilla #46550 
), to add empty line between definition blocks 
including namespace, class, and struct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116314

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp

Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -770,6 +770,7 @@
 IO.mapOptional("ReferenceAlignment", Style.ReferenceAlignment);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
@@ -1193,6 +1194,7 @@
   LLVMStyle.ObjCSpaceBeforeProtocolList = true;
   LLVMStyle.PointerAlignment = FormatStyle::PAS_Right;
   LLVMStyle.ReferenceAlignment = FormatStyle::RAS_Pointer;
+  LLVMStyle.SeparateDefinitionBlocks = true;
   LLVMStyle.ShortNamespaceLines = 1;
   LLVMStyle.SpacesBeforeTrailingComments = 1;
   LLVMStyle.Standard = FormatStyle::LS_Latest;
@@ -1333,6 +1335,7 @@
   /*BasedOnStyle=*/"google",
   },
   };
+  GoogleStyle.SeparateDefinitionBlocks = false;
   GoogleStyle.SpacesBeforeTrailingComments = 2;
   GoogleStyle.Standard = FormatStyle::LS_Auto;
 
@@ -1863,13 +1866,13 @@
 return std::make_pair(Result, Penalty);
   }
 
-private:
   static bool inputUsesCRLF(StringRef Text, bool DefaultToCRLF) {
 size_t LF = Text.count('\n');
 size_t CR = Text.count('\r') * 2;
 return LF == CR ? DefaultToCRLF : CR > LF;
   }
 
+private:
   bool
   hasCpp03IncompatibleFormat(const SmallVectorImpl &Lines) {
 for (const AnnotatedLine *Line : Lines) {
@@ -2012,6 +2015,98 @@
   }
 };
 
+// This class separates definition blocks like classes, functions, and
+// namespaces by inserting a line break between them.
+class DefinitionBlockSeparator : public TokenAnalyzer {
+public:
+  DefinitionBlockSeparator(const Environment &Env, const FormatStyle &Style)
+  : TokenAnalyzer(Env, Style) {}
+
+  std::pair
+  analyze(TokenAnnotator &Annotator,
+  SmallVectorImpl &AnnotatedLines,
+  FormatTokenLexer &Tokens) override {
+AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
+tooling::Replacements Result;
+separateBlocks(AnnotatedLines, Result);
+return {Result, 0};
+  }
+
+private:
+  void separateBlocks(SmallVectorImpl &Lines,
+  tooling::Replacements &Result) {
+auto likelyDefinition = [](AnnotatedLine *Line) {
+  return (Line->MightBeFunctionDecl && Line->mightBeFunctionDefinition()) ||
+ Line->First->isOneOf(tok::kw_class, tok::kw_struct,
+  tok::kw_namespace);
+};
+WhitespaceManager Whitespaces(
+Env.getSourceManager(), Style,
+Style.DeriveLineEnding
+? Formatter::inputUsesCRLF(
+  Env.getSourceManager().getBufferData(Env.getFileID()),
+  Style.UseCRLF)
+: Style.UseCRLF);
+for (unsigned I = 0; I < Lines.size(); I++) {
+  auto Line = Lines[I];
+  if (Line->First->closesScope()) {
+auto OpeningLineIndex = Line->MatchingOpeningBlockLineIndex;
+// Case: Opening bracket has its own line
+if (OpeningLineIndex > 0 &&
+Lines[OpeningLineIndex]->First->TokenText == "{") {
+  OpeningLineIndex--;
+}
+AnnotatedLine *OpeningLine = Lines[OpeningLineIndex];
+// Closing a function definition
+if (likelyDefinition(OpeningLine)) {
+  FormatToken *TargetToken = nullptr;
+  AnnotatedLine *TargetLine;
+  auto insertReplacement = [&]() {
+assert(TargetToken);
+Whitespaces.replaceWhitespace(*TargetToken, 2,
+  TargetToken->SpacesRequiredBefore,
+  TargetToken->StartsColumn);
+  };
+
+  // Not the first token
+  if (OpeningLineIndex > 0) {
+TargetLine = Lines[OpeningLineIndex - 1];
+// Not immediately following other scopes' opening
+if (TargetLine->Affected && !TargetLine->Last->opensScope()) {
+  // Change target, since we need to put line break *before*
+  // a token
+  TargetLine = OpeningLine;
+  TargetToken = TargetLine->First;
+
+  

[PATCH] D116314: [Clangfmt] Add style to separate definition blocks

2021-12-27 Thread ksyx via Phabricator via cfe-commits
ksyx added a comment.

Test code:

  // test.cpp
  #include 
  #include 
  #include 
  struct Foo {
int a,b,c;
  };
  namespace Ns {
  class Bar {
  public:
struct Foobar {
  int a;
  int b;
};
  private:
int t;
int method1()
{
  // Intentional test for different
  // line breaking mode of brackets
}
template
int method2(T x) {
  // ...
}
int method3(int par) {}
  };
  class C {
  }
  }
  namespace Ns2 {
  
  }

Tests ran:

  # pwd = build directory
  bin/clang-format test.cpp # LLVM Style
  bin/clang-format -style='{SeparateDefinitionBlocks: false}' test.cpp # 
Disable functionality
  bin/clang-format -style='{BasedOnStyle: Google}' test.cpp # Disable by default
  bin/clang-format -style='{BasedOnStyle: Google, SeparateDefinitionBlocks: 
true}' test.cpp # Override default
  bin/clang-format -style='{BasedOnStyle: WebKit}' test.cpp # Opening bracket 
in new line (WebKit style has this functionality enabled)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116314

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


[PATCH] D116314: [Clangfmt] Add style to separate definition blocks

2021-12-27 Thread ksyx via Phabricator via cfe-commits
ksyx updated this revision to Diff 396321.
ksyx added a comment.

Apply clang-format suggestions


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

https://reviews.llvm.org/D116314

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp

Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -770,6 +770,7 @@
 IO.mapOptional("ReferenceAlignment", Style.ReferenceAlignment);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
@@ -1193,6 +1194,7 @@
   LLVMStyle.ObjCSpaceBeforeProtocolList = true;
   LLVMStyle.PointerAlignment = FormatStyle::PAS_Right;
   LLVMStyle.ReferenceAlignment = FormatStyle::RAS_Pointer;
+  LLVMStyle.SeparateDefinitionBlocks = true;
   LLVMStyle.ShortNamespaceLines = 1;
   LLVMStyle.SpacesBeforeTrailingComments = 1;
   LLVMStyle.Standard = FormatStyle::LS_Latest;
@@ -1333,6 +1335,7 @@
   /*BasedOnStyle=*/"google",
   },
   };
+  GoogleStyle.SeparateDefinitionBlocks = false;
   GoogleStyle.SpacesBeforeTrailingComments = 2;
   GoogleStyle.Standard = FormatStyle::LS_Auto;
 
@@ -1863,13 +1866,13 @@
 return std::make_pair(Result, Penalty);
   }
 
-private:
   static bool inputUsesCRLF(StringRef Text, bool DefaultToCRLF) {
 size_t LF = Text.count('\n');
 size_t CR = Text.count('\r') * 2;
 return LF == CR ? DefaultToCRLF : CR > LF;
   }
 
+private:
   bool
   hasCpp03IncompatibleFormat(const SmallVectorImpl &Lines) {
 for (const AnnotatedLine *Line : Lines) {
@@ -2012,6 +2015,98 @@
   }
 };
 
+// This class separates definition blocks like classes, functions, and
+// namespaces by inserting a line break between them.
+class DefinitionBlockSeparator : public TokenAnalyzer {
+public:
+  DefinitionBlockSeparator(const Environment &Env, const FormatStyle &Style)
+  : TokenAnalyzer(Env, Style) {}
+
+  std::pair
+  analyze(TokenAnnotator &Annotator,
+  SmallVectorImpl &AnnotatedLines,
+  FormatTokenLexer &Tokens) override {
+AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
+tooling::Replacements Result;
+separateBlocks(AnnotatedLines, Result);
+return {Result, 0};
+  }
+
+private:
+  void separateBlocks(SmallVectorImpl &Lines,
+  tooling::Replacements &Result) {
+auto likelyDefinition = [](AnnotatedLine *Line) {
+  return (Line->MightBeFunctionDecl && Line->mightBeFunctionDefinition()) ||
+ Line->First->isOneOf(tok::kw_class, tok::kw_struct,
+  tok::kw_namespace);
+};
+WhitespaceManager Whitespaces(
+Env.getSourceManager(), Style,
+Style.DeriveLineEnding
+? Formatter::inputUsesCRLF(
+  Env.getSourceManager().getBufferData(Env.getFileID()),
+  Style.UseCRLF)
+: Style.UseCRLF);
+for (unsigned I = 0; I < Lines.size(); I++) {
+  auto Line = Lines[I];
+  if (Line->First->closesScope()) {
+auto OpeningLineIndex = Line->MatchingOpeningBlockLineIndex;
+// Case: Opening bracket has its own line
+if (OpeningLineIndex > 0 &&
+Lines[OpeningLineIndex]->First->TokenText == "{") {
+  OpeningLineIndex--;
+}
+AnnotatedLine *OpeningLine = Lines[OpeningLineIndex];
+// Closing a function definition
+if (likelyDefinition(OpeningLine)) {
+  FormatToken *TargetToken = nullptr;
+  AnnotatedLine *TargetLine;
+  auto insertReplacement = [&]() {
+assert(TargetToken);
+Whitespaces.replaceWhitespace(*TargetToken, 2,
+  TargetToken->SpacesRequiredBefore,
+  TargetToken->StartsColumn);
+  };
+
+  // Not the first token
+  if (OpeningLineIndex > 0) {
+TargetLine = Lines[OpeningLineIndex - 1];
+// Not immediately following other scopes' opening
+if (TargetLine->Affected && !TargetLine->Last->opensScope()) {
+  // Change target, since we need to put line break *before*
+  // a token
+  TargetLine = OpeningLine;
+  TargetToken = TargetLine->First;
+
+  // Avoid duplicated replacement
+  if (TargetToken && !TargetToken->opensScope()) {
+insertReplacement();
+  }
+}
+  }
+
+  // Not the last token
+  if (I + 1 < Lines.size()) {
+TargetLine = Line

[PATCH] D116316: [clang-format] Add an experimental option to remove optional control statement braces in LLVM C++ code

2021-12-27 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, curdeius, 
sammccall, aaron.ballman, krasimir.
owenpan added a project: clang-format.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

See the LLVM style examples 
.
 This option can be expanded/configured to support other styles.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116316

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18682,6 +18682,7 @@
   CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
   CHECK_PARSE_BOOL(Cpp11BracedListStyle);
   CHECK_PARSE_BOOL(ReflowComments);
+  CHECK_PARSE_BOOL(RemoveBracesLLVM);
   CHECK_PARSE_BOOL(SortUsingDeclarations);
   CHECK_PARSE_BOOL(SpacesInParentheses);
   CHECK_PARSE_BOOL(SpacesInSquareBrackets);
@@ -23020,6 +23021,297 @@
Style);
 }
 
+TEST_F(FormatTest, RemoveBraces) {
+  FormatStyle Style = getLLVMStyle();
+  Style.RemoveBracesLLVM = true;
+
+  // The following eight test cases are fully-braced versions of the examples at
+  // "llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-
+  // statement-bodies-of-if-else-loop-statements".
+
+  // 1. Omit the braces, since the body is simple and clearly associated with
+  // the if.
+  EXPECT_EQ("if (isa(D))\n"
+"  handleFunctionDecl(D);\n"
+"else if (isa(D))\n"
+"  handleVarDecl(D);",
+format("if (isa(D)) {\n"
+   "  handleFunctionDecl(D);\n"
+   "} else if (isa(D)) {\n"
+   "  handleVarDecl(D);\n"
+   "}",
+   Style));
+
+  // 2. Here we document the condition itself and not the body.
+  verifyFormat("if (isa(D)) {\n"
+   "  // It is necessary that we explain the situation with this\n"
+   "  // surprisingly long comment, so it would be unclear\n"
+   "  // without the braces whether the following statement is in\n"
+   "  // the scope of the `if`.\n"
+   "  // Because the condition is documented, we can't really\n"
+   "  // hoist this comment that applies to the body above the\n"
+   "  // if.\n"
+   "  handleOtherDecl(D);\n"
+   "}",
+   Style);
+
+  // 3. Use braces on the outer `if` to avoid a potential dangling else
+  // situation.
+  EXPECT_EQ("if (isa(D)) {\n"
+"  for (auto *A : D.attrs())\n"
+"if (shouldProcessAttr(A))\n"
+"  handleAttr(A);\n"
+"}",
+format("if (isa(D)) {\n"
+   "  for (auto *A : D.attrs()) {\n"
+   "if (shouldProcessAttr(A)) {\n"
+   "  handleAttr(A);\n"
+   "}\n"
+   "  }\n"
+   "}",
+   Style));
+
+  // 4. Use braces for the `if` block to keep it uniform with the else block.
+  verifyFormat("if (isa(D)) {\n"
+   "  handleFunctionDecl(D);\n"
+   "} else {\n"
+   "  // In this else case, it is necessary that we explain the\n"
+   "  // situation with this surprisingly long comment, so it\n"
+   "  // would be unclear without the braces whether the\n"
+   "  // following statement is in the scope of the `if`.\n"
+   "  handleOtherDecl(D);\n"
+   "}",
+   Style);
+
+  // 5. This should also omit braces.  The `for` loop contains only a single
+  // statement, so it shouldn't have braces.  The `if` also only contains a
+  // single simple statement (the for loop), so it also should omit braces.
+  EXPECT_EQ("if (isa(D))\n"
+"  for (auto *A : D.attrs())\n"
+"handleAttr(A);",
+format("if (isa(D)) {\n"
+   "  for (auto *A : D.attrs()) {\n"
+   "handleAttr(A);\n"
+   "  }\n"
+   "}",
+   Style));
+
+  // 6. Use braces for the outer `if` since the nested `for` is braced.
+  verifyFormat("if (isa(D)) {\n"
+   "  for (auto *A : D.attrs()) {\n"
+   "// In this for loop body, it is necessary that we explain\n"
+   "// the situation with this surprisingly long comment,\n"
+   "// forcing braces on

[PATCH] D116314: [Clangfmt] Add style to separate definition blocks

2021-12-27 Thread ksyx via Phabricator via cfe-commits
ksyx added inline comments.



Comment at: clang/lib/Format/Format.cpp:1197
   LLVMStyle.ReferenceAlignment = FormatStyle::RAS_Pointer;
+  LLVMStyle.SeparateDefinitionBlocks = true;
   LLVMStyle.ShortNamespaceLines = 1;

Not so sure about this as it would break some tests.


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

https://reviews.llvm.org/D116314

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


[PATCH] D116314: [Clangfmt] Add style to separate definition blocks

2021-12-27 Thread ksyx via Phabricator via cfe-commits
ksyx added inline comments.



Comment at: clang/lib/Format/Format.cpp:1197
   LLVMStyle.ReferenceAlignment = FormatStyle::RAS_Pointer;
+  LLVMStyle.SeparateDefinitionBlocks = true;
   LLVMStyle.ShortNamespaceLines = 1;

ksyx wrote:
> Not so sure about this as it would break some tests.
As CI shows some original tests does not expect this empty line, but it looks 
like LLVM is generally adding empty lines between blocks.
```cpp
 template  class B;
+
 class A {
 public:
   int f();
-};
+};\n
```


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

https://reviews.llvm.org/D116314

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


[PATCH] D115971: [OpenMP][FIX] Change globalization alignment to 16

2021-12-27 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert accepted this revision.
jdoerfert added a comment.
This revision is now accepted and ready to land.

LG, partial fix for the problem and fixmes describing what needs to be done 
next.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115971

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


[PATCH] D115888: [Attributor][Fix] Add alignment return attribute to HeapToStack

2021-12-27 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Still LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115888

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


[PATCH] D116317: [CodeCompletion] Signature help for braced constructor calls

2021-12-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

Implementation is based on the "expected type" as used for
designated-initializers in braced init lists. This means it can deduce the type
in some cases where it's not written:

  void foo(Widget);
  foo({ /*help here*/ });

Only basic constructor calls are in scope of this patch, excluded are:

- aggregate initialization (no help is offered for aggregates)
- initializer_list initialization (no help is offered for these constructors)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116317

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseInit.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/ctor-signature.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp

Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -656,14 +656,15 @@
 void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
OverloadCandidate *Candidates,
unsigned NumCandidates,
-   SourceLocation OpenParLoc) override {
+   SourceLocation OpenParLoc,
+   bool Braced) override {
   StoredResults.reserve(StoredResults.size() + NumCandidates);
   for (unsigned I = 0; I != NumCandidates; ++I) {
-CodeCompletionString *StoredCompletion
-  = Candidates[I].CreateSignatureString(CurrentArg, S, getAllocator(),
+CodeCompletionString *StoredCompletion =
+Candidates[I].CreateSignatureString(CurrentArg, S, getAllocator(),
 getCodeCompletionTUInfo(),
-includeBriefComments());
-
+includeBriefComments(), Braced);
+
 CXCompletionResult R;
 R.CursorKind = CXCursor_OverloadCandidate;
 R.CompletionString = StoredCompletion;
Index: clang/test/CodeCompletion/ctor-signature.cpp
===
--- clang/test/CodeCompletion/ctor-signature.cpp
+++ clang/test/CodeCompletion/ctor-signature.cpp
@@ -15,3 +15,40 @@
   // CHECK-CC2: OVERLOAD: Foo(<#const Foo &#>)
   // CHECK-CC2: OVERLOAD: Foo(<#Foo &&#>
 }
+
+namespace std {
+template  struct initializer_list {};
+} // namespace std
+
+struct Bar {
+  // CHECK-BRACED: OVERLOAD: Bar{<#int#>}
+  Bar(int);
+  // CHECK-BRACED: OVERLOAD: Bar{<#double#>, double}
+  Bar(double, double);
+  // FIXME: no support for init-list constructors yet.
+  // CHECK-BRACED-NOT: OVERLOAD: {{.*}}char
+  Bar(std::initializer_list C);
+  // CHECK-BRACED: OVERLOAD: Bar{<#const Bar &#>}
+  // CHECK-BRACED: OVERLOAD: Bar{<#T *Pointer#>}
+  template  Bar(T *Pointer);
+};
+
+auto b1 = Bar{};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:36:15 %s | FileCheck -check-prefix=CHECK-BRACED %s
+Bar b2{};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:38:8 %s | FileCheck -check-prefix=CHECK-BRACED %s
+static int consumeBar(Bar) { return 0; }
+int b3 = consumeBar({});
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:41:22 %s | FileCheck -check-prefix=CHECK-BRACED %s
+
+struct Aggregate {
+  // FIXME: no support for aggregates yet.
+  // CHECK-AGGREGATE-NOT: OVERLOAD: Aggregate{<#const Aggregate &#>}
+  // CHECK-AGGREGATE-NOT: OVERLOAD: {{.*}}first
+  int first;
+  int second;
+};
+
+Aggregate a{};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:52:13 %s | FileCheck -check-prefix=CHECK-AGGREGATE %s
+
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -3761,7 +3761,8 @@
 CodeCompletionString *
 CodeCompleteConsumer::OverloadCandidate::CreateSignatureString(
 unsigned CurrentArg, Sema &S, CodeCompletionAllocator &Allocator,
-CodeCompletionTUInfo &CCTUInfo, bool IncludeBriefComments) const {
+CodeCompletionTUInfo &CCTUInfo, bool IncludeBriefComments,
+bool Braced) const {
   PrintingPolicy Policy = getCompletionPrintingPolicy(S);
   // Show signatures of constructors as they are declared:
  

[PATCH] D116317: [CodeCompletion] Signature help for braced constructor calls

2021-12-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 396324.
sammccall added a comment.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

Fix lldb build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116317

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseInit.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/ctor-signature.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -995,7 +995,8 @@
   void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
  OverloadCandidate *Candidates,
  unsigned NumCandidates,
- SourceLocation OpenParLoc) override {
+ SourceLocation OpenParLoc,
+ bool Braced) override {
 // At the moment we don't filter out any overloaded candidates.
   }
 
Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -656,14 +656,15 @@
 void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
OverloadCandidate *Candidates,
unsigned NumCandidates,
-   SourceLocation OpenParLoc) override {
+   SourceLocation OpenParLoc,
+   bool Braced) override {
   StoredResults.reserve(StoredResults.size() + NumCandidates);
   for (unsigned I = 0; I != NumCandidates; ++I) {
-CodeCompletionString *StoredCompletion
-  = Candidates[I].CreateSignatureString(CurrentArg, S, getAllocator(),
+CodeCompletionString *StoredCompletion =
+Candidates[I].CreateSignatureString(CurrentArg, S, getAllocator(),
 getCodeCompletionTUInfo(),
-includeBriefComments());
-
+includeBriefComments(), Braced);
+
 CXCompletionResult R;
 R.CursorKind = CXCursor_OverloadCandidate;
 R.CompletionString = StoredCompletion;
Index: clang/test/CodeCompletion/ctor-signature.cpp
===
--- clang/test/CodeCompletion/ctor-signature.cpp
+++ clang/test/CodeCompletion/ctor-signature.cpp
@@ -15,3 +15,40 @@
   // CHECK-CC2: OVERLOAD: Foo(<#const Foo &#>)
   // CHECK-CC2: OVERLOAD: Foo(<#Foo &&#>
 }
+
+namespace std {
+template  struct initializer_list {};
+} // namespace std
+
+struct Bar {
+  // CHECK-BRACED: OVERLOAD: Bar{<#int#>}
+  Bar(int);
+  // CHECK-BRACED: OVERLOAD: Bar{<#double#>, double}
+  Bar(double, double);
+  // FIXME: no support for init-list constructors yet.
+  // CHECK-BRACED-NOT: OVERLOAD: {{.*}}char
+  Bar(std::initializer_list C);
+  // CHECK-BRACED: OVERLOAD: Bar{<#const Bar &#>}
+  // CHECK-BRACED: OVERLOAD: Bar{<#T *Pointer#>}
+  template  Bar(T *Pointer);
+};
+
+auto b1 = Bar{};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:36:15 %s | FileCheck -check-prefix=CHECK-BRACED %s
+Bar b2{};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:38:8 %s | FileCheck -check-prefix=CHECK-BRACED %s
+static int consumeBar(Bar) { return 0; }
+int b3 = consumeBar({});
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:41:22 %s | FileCheck -check-prefix=CHECK-BRACED %s
+
+struct Aggregate {
+  // FIXME: no support for aggregates yet.
+  // CHECK-AGGREGATE-NOT: OVERLOAD: Aggregate{<#const Aggregate &#>}
+  // CHECK-AGGREGATE-NOT: OVERLOAD: {{.*}}first
+  int first;
+  int second;
+};
+
+Aggregate a{};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:52:13 %s | FileCheck -check-prefix=CHECK-AGGREGATE %s
+
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -3761,7 +3761,8 @@
 CodeCompletionString *
 CodeCompleteConsu

[PATCH] D116317: [CodeCompletion] Signature help for braced constructor calls

2021-12-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 396325.
sammccall edited the summary of this revision.
sammccall added a comment.
Herald added subscribers: JDevlieghere, ilya-biryukov.

Revert some unintended changes, clean up tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116317

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseInit.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/ctor-signature.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -995,7 +995,8 @@
   void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
  OverloadCandidate *Candidates,
  unsigned NumCandidates,
- SourceLocation OpenParLoc) override {
+ SourceLocation OpenParLoc,
+ bool Braced) override {
 // At the moment we don't filter out any overloaded candidates.
   }
 
Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -656,14 +656,15 @@
 void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
OverloadCandidate *Candidates,
unsigned NumCandidates,
-   SourceLocation OpenParLoc) override {
+   SourceLocation OpenParLoc,
+   bool Braced) override {
   StoredResults.reserve(StoredResults.size() + NumCandidates);
   for (unsigned I = 0; I != NumCandidates; ++I) {
-CodeCompletionString *StoredCompletion
-  = Candidates[I].CreateSignatureString(CurrentArg, S, getAllocator(),
+CodeCompletionString *StoredCompletion =
+Candidates[I].CreateSignatureString(CurrentArg, S, getAllocator(),
 getCodeCompletionTUInfo(),
-includeBriefComments());
-
+includeBriefComments(), Braced);
+
 CXCompletionResult R;
 R.CursorKind = CXCursor_OverloadCandidate;
 R.CompletionString = StoredCompletion;
Index: clang/test/CodeCompletion/ctor-signature.cpp
===
--- clang/test/CodeCompletion/ctor-signature.cpp
+++ clang/test/CodeCompletion/ctor-signature.cpp
@@ -15,3 +15,40 @@
   // CHECK-CC2: OVERLOAD: Foo(<#const Foo &#>)
   // CHECK-CC2: OVERLOAD: Foo(<#Foo &&#>
 }
+
+namespace std {
+template  struct initializer_list {};
+} // namespace std
+
+struct Bar {
+  // CHECK-BRACED: OVERLOAD: Bar{<#int#>}
+  Bar(int);
+  // CHECK-BRACED: OVERLOAD: Bar{<#double#>, double}
+  Bar(double, double);
+  // FIXME: no support for init-list constructors yet.
+  // CHECK-BRACED-NOT: OVERLOAD: {{.*}}char
+  Bar(std::initializer_list C);
+  // CHECK-BRACED: OVERLOAD: Bar{<#const Bar &#>}
+  // CHECK-BRACED: OVERLOAD: Bar{<#T *Pointer#>}
+  template  Bar(T *Pointer);
+};
+
+auto b1 = Bar{};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:36:15 %s | FileCheck -check-prefix=CHECK-BRACED %s
+Bar b2{};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:38:8 %s | FileCheck -check-prefix=CHECK-BRACED %s
+static int consumeBar(Bar) { return 0; }
+int b3 = consumeBar({});
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:41:22 %s | FileCheck -check-prefix=CHECK-BRACED %s
+
+struct Aggregate {
+  // FIXME: no support for aggregates yet.
+  // CHECK-AGGREGATE-NOT: OVERLOAD: Aggregate{<#const Aggregate &#>}
+  // CHECK-AGGREGATE-NOT: OVERLOAD: {{.*}}first
+  int first;
+  int second;
+};
+
+Aggregate a{};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:52:13 %s | FileCheck -check-prefix=CHECK-AGGREGATE %s
+
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp

[PATCH] D116318: [clang-format][NFC] Fix a bug in getPreviousToken() in the parser

2021-12-27 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, curdeius.
owenpan added a project: clang-format.
owenpan 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/D116318

Files:
  clang/lib/Format/UnwrappedLineParser.cpp


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -32,7 +32,7 @@
   // Returns the next token in the token stream.
   virtual FormatToken *getNextToken() = 0;
 
-  // Returns the token precedint the token returned by the last call to
+  // Returns the token preceding the token returned by the last call to
   // getNextToken() in the token stream, or nullptr if no such token exists.
   virtual FormatToken *getPreviousToken() = 0;
 
@@ -246,8 +246,7 @@
   }
 
   FormatToken *getPreviousToken() override {
-assert(Position > 0);
-return Tokens[Position - 1];
+return Position > 0 ? Tokens[Position - 1] : nullptr;
   }
 
   FormatToken *peekNextToken() override {


Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -32,7 +32,7 @@
   // Returns the next token in the token stream.
   virtual FormatToken *getNextToken() = 0;
 
-  // Returns the token precedint the token returned by the last call to
+  // Returns the token preceding the token returned by the last call to
   // getNextToken() in the token stream, or nullptr if no such token exists.
   virtual FormatToken *getPreviousToken() = 0;
 
@@ -246,8 +246,7 @@
   }
 
   FormatToken *getPreviousToken() override {
-assert(Position > 0);
-return Tokens[Position - 1];
+return Position > 0 ? Tokens[Position - 1] : nullptr;
   }
 
   FormatToken *peekNextToken() override {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101070: Make `llvm_install_symlink` robust with respect to absolute dirs.

2021-12-27 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 396339.
Ericson2314 added a comment.
Herald added a project: Flang.



1. Updating D101070 : Make 
`llvm_install_symlink` robust with respect to absolute dirs. #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101070

Files:
  clang/cmake/modules/AddClang.cmake
  flang/cmake/modules/AddFlang.cmake
  lld/cmake/modules/AddLLD.cmake
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/LLVMInstallSymlink.cmake


Index: llvm/cmake/modules/LLVMInstallSymlink.cmake
===
--- llvm/cmake/modules/LLVMInstallSymlink.cmake
+++ llvm/cmake/modules/LLVMInstallSymlink.cmake
@@ -2,9 +2,9 @@
 # DESTDIR environment variable may be unset at configuration time.
 # See PR8397.
 
-function(install_symlink name target outdir)
+function(install_symlink name target absolute_outdir)
   set(DESTDIR $ENV{DESTDIR})
-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
+  set(bindir "${DESTDIR}${absolute_outdir}")
 
   message(STATUS "Creating ${name}")
 
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1905,7 +1905,7 @@
 
 endfunction()
 
-function(llvm_install_symlink name dest)
+function(llvm_install_symlink name dest output_dir)
   cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN})
   foreach(path ${CMAKE_MODULE_PATH})
 if(EXISTS ${path}/LLVMInstallSymlink.cmake)
@@ -1928,7 +1928,7 @@
   set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX})
 
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} 
${LLVM_TOOLS_INSTALL_DIR})"
+  CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
   COMPONENT ${component})
 
   if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)
@@ -2011,7 +2011,8 @@
 endif()
 
 if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND 
LLVM_BUILD_TOOLS)
-  llvm_install_symlink(${link_name} ${target})
+  GNUInstallDirs_get_absolute_install_dir(output_dir 
LLVM_TOOLS_INSTALL_DIR)
+  llvm_install_symlink(${link_name} ${target} ${output_dir})
 endif()
   endif()
 endfunction()
Index: lld/cmake/modules/AddLLD.cmake
===
--- lld/cmake/modules/AddLLD.cmake
+++ lld/cmake/modules/AddLLD.cmake
@@ -62,5 +62,5 @@
 macro(add_lld_symlink name dest)
   add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
   # Always generate install targets
-  llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
+  llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} 
ALWAYS_GENERATE)
 endmacro()
Index: flang/cmake/modules/AddFlang.cmake
===
--- flang/cmake/modules/AddFlang.cmake
+++ flang/cmake/modules/AddFlang.cmake
@@ -124,6 +124,6 @@
 macro(add_flang_symlink name dest)
   add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
   # Always generate install targets
-  llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
+  llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} 
ALWAYS_GENERATE)
 endmacro()
 
Index: clang/cmake/modules/AddClang.cmake
===
--- clang/cmake/modules/AddClang.cmake
+++ clang/cmake/modules/AddClang.cmake
@@ -175,7 +175,7 @@
 macro(add_clang_symlink name dest)
   add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
   # Always generate install targets
-  llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
+  llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} 
ALWAYS_GENERATE)
 endmacro()
 
 function(clang_target_link_libraries target type)


Index: llvm/cmake/modules/LLVMInstallSymlink.cmake
===
--- llvm/cmake/modules/LLVMInstallSymlink.cmake
+++ llvm/cmake/modules/LLVMInstallSymlink.cmake
@@ -2,9 +2,9 @@
 # DESTDIR environment variable may be unset at configuration time.
 # See PR8397.
 
-function(install_symlink name target outdir)
+function(install_symlink name target absolute_outdir)
   set(DESTDIR $ENV{DESTDIR})
-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
+  set(bindir "${DESTDIR}${absolute_outdir}")
 
   message(STATUS "Creating ${name}")
 
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1905,7 +1905,7 @@
 
 endfunction()
 
-function(llvm_install_symlink name dest)
+function(llvm_in

[PATCH] D115888: [Attributor][Fix] Add alignment return attribute to HeapToStack

2021-12-27 Thread Joseph Huber via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG38fc89623b3e: [Attributor][Fix] Add alignment return 
attribute to HeapToStack (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115888

Files:
  llvm/lib/Transforms/IPO/AttributorAttributes.cpp
  llvm/test/Transforms/Attributor/heap_to_stack.ll


Index: llvm/test/Transforms/Attributor/heap_to_stack.ll
===
--- llvm/test/Transforms/Attributor/heap_to_stack.ll
+++ llvm/test/Transforms/Attributor/heap_to_stack.ll
@@ -34,7 +34,7 @@
 ; ISOPM-LABEL: define {{[^@]+}}@h2s_value_simplify_interaction
 ; ISOPM-SAME: (i1 [[C:%.*]], i8* nocapture nofree readnone [[A:%.*]]) {
 ; ISOPM-NEXT:  entry:
-; ISOPM-NEXT:[[M:%.*]] = tail call noalias i8* @malloc(i64 noundef 
4)
+; ISOPM-NEXT:[[M:%.*]] = tail call noalias align 16 i8* 
@malloc(i64 noundef 4)
 ; ISOPM-NEXT:br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
 ; ISOPM:   t:
 ; ISOPM-NEXT:br i1 false, label [[DEAD:%.*]], label [[F2:%.*]]
@@ -43,41 +43,41 @@
 ; ISOPM:   f2:
 ; ISOPM-NEXT:[[C1:%.*]] = bitcast i8* [[M]] to i32*
 ; ISOPM-NEXT:[[C2:%.*]] = bitcast i32* [[C1]] to i8*
-; ISOPM-NEXT:[[L:%.*]] = load i8, i8* [[C2]], align 1
+; ISOPM-NEXT:[[L:%.*]] = load i8, i8* [[C2]], align 16
 ; ISOPM-NEXT:call void @usei8(i8 [[L]])
-; ISOPM-NEXT:call void @no_sync_func(i8* nocapture nofree noundef 
[[C2]]) #[[ATTR5:[0-9]+]]
+; ISOPM-NEXT:call void @no_sync_func(i8* nocapture nofree noundef 
align 16 [[C2]]) #[[ATTR5:[0-9]+]]
 ; ISOPM-NEXT:br label [[J]]
 ; ISOPM:   dead:
 ; ISOPM-NEXT:unreachable
 ; ISOPM:   j:
 ; ISOPM-NEXT:[[PHI:%.*]] = phi i8* [ [[M]], [[F]] ], [ null, 
[[F2]] ]
-; ISOPM-NEXT:tail call void @no_sync_func(i8* nocapture nofree 
noundef [[PHI]]) #[[ATTR5]]
+; ISOPM-NEXT:tail call void @no_sync_func(i8* nocapture nofree 
noundef align 16 [[PHI]]) #[[ATTR5]]
 ; ISOPM-NEXT:ret void
 ;
 ; ISNPM-LABEL: define {{[^@]+}}@h2s_value_simplify_interaction
 ; ISNPM-SAME: (i1 [[C:%.*]], i8* nocapture nofree readnone [[A:%.*]]) {
 ; ISNPM-NEXT:  entry:
-; ISNPM-NEXT:[[TMP0:%.*]] = alloca i8, i64 4, align 1
+; ISNPM-NEXT:[[TMP0:%.*]] = alloca i8, i64 4, align 16
 ; ISNPM-NEXT:br i1 [[C]], label [[T:%.*]], label [[F:%.*]]
 ; ISNPM:   t:
 ; ISNPM-NEXT:br i1 false, label [[DEAD:%.*]], label [[F2:%.*]]
 ; ISNPM:   f:
 ; ISNPM-NEXT:br label [[J:%.*]]
 ; ISNPM:   f2:
-; ISNPM-NEXT:[[L:%.*]] = load i8, i8* [[TMP0]], align 1
+; ISNPM-NEXT:[[L:%.*]] = load i8, i8* [[TMP0]], align 16
 ; ISNPM-NEXT:call void @usei8(i8 [[L]])
-; ISNPM-NEXT:call void @no_sync_func(i8* nocapture nofree noundef 
[[TMP0]]) #[[ATTR6:[0-9]+]]
+; ISNPM-NEXT:call void @no_sync_func(i8* nocapture nofree noundef 
align 16 [[TMP0]]) #[[ATTR6:[0-9]+]]
 ; ISNPM-NEXT:br label [[J]]
 ; ISNPM:   dead:
 ; ISNPM-NEXT:unreachable
 ; ISNPM:   j:
 ; ISNPM-NEXT:[[PHI:%.*]] = phi i8* [ [[TMP0]], [[F]] ], [ null, 
[[F2]] ]
-; ISNPM-NEXT:tail call void @no_sync_func(i8* nocapture nofree 
noundef [[PHI]]) #[[ATTR6]]
+; ISNPM-NEXT:tail call void @no_sync_func(i8* nocapture nofree 
noundef align 16 [[PHI]]) #[[ATTR6]]
 ; ISNPM-NEXT:ret void
 ;
 entry:
   %add = add i64 2, 2
-  %m = tail call noalias i8* @malloc(i64 %add)
+  %m = tail call align 16 noalias i8* @malloc(i64 %add)
   br i1 %c, label %t, label %f
 t:
   br i1 false, label %dead, label %f2
Index: llvm/lib/Transforms/IPO/AttributorAttributes.cpp
===
--- llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -5929,6 +5929,8 @@
   }
 
   Align Alignment(1);
+  if (MaybeAlign RetAlign = AI.CB->getRetAlign())
+Alignment = max(Alignment, RetAlign);
   if (AI.Kind == AllocationInfo::AllocationKind::ALIGNED_ALLOC) {
 Optional AlignmentAPI =
 getAPInt(A, *this, *AI.CB->getArgOperand(0));


Index: llvm/test/Transforms/Attributor/heap_to_stack.ll
===
--- llvm/test/Transforms/Attributor/heap_to_stack.ll
+++ llvm/test/Transforms/Attributor/heap_to_stack.ll
@@ -34,7 +34,7 @@
 ; ISOPM-LABEL: define {{[^@]+}}@h2s_value_simpli

[PATCH] D116314: [Clangfmt] Add style to separate definition blocks

2021-12-27 Thread ksyx via Phabricator via cfe-commits
ksyx updated this revision to Diff 396344.
ksyx added a comment.

Fix missing colon in sample/test code


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

https://reviews.llvm.org/D116314

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp

Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -770,6 +770,7 @@
 IO.mapOptional("ReferenceAlignment", Style.ReferenceAlignment);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
@@ -1193,6 +1194,7 @@
   LLVMStyle.ObjCSpaceBeforeProtocolList = true;
   LLVMStyle.PointerAlignment = FormatStyle::PAS_Right;
   LLVMStyle.ReferenceAlignment = FormatStyle::RAS_Pointer;
+  LLVMStyle.SeparateDefinitionBlocks = true;
   LLVMStyle.ShortNamespaceLines = 1;
   LLVMStyle.SpacesBeforeTrailingComments = 1;
   LLVMStyle.Standard = FormatStyle::LS_Latest;
@@ -1333,6 +1335,7 @@
   /*BasedOnStyle=*/"google",
   },
   };
+  GoogleStyle.SeparateDefinitionBlocks = false;
   GoogleStyle.SpacesBeforeTrailingComments = 2;
   GoogleStyle.Standard = FormatStyle::LS_Auto;
 
@@ -1863,13 +1866,13 @@
 return std::make_pair(Result, Penalty);
   }
 
-private:
   static bool inputUsesCRLF(StringRef Text, bool DefaultToCRLF) {
 size_t LF = Text.count('\n');
 size_t CR = Text.count('\r') * 2;
 return LF == CR ? DefaultToCRLF : CR > LF;
   }
 
+private:
   bool
   hasCpp03IncompatibleFormat(const SmallVectorImpl &Lines) {
 for (const AnnotatedLine *Line : Lines) {
@@ -2012,6 +2015,98 @@
   }
 };
 
+// This class separates definition blocks like classes, functions, and
+// namespaces by inserting a line break between them.
+class DefinitionBlockSeparator : public TokenAnalyzer {
+public:
+  DefinitionBlockSeparator(const Environment &Env, const FormatStyle &Style)
+  : TokenAnalyzer(Env, Style) {}
+
+  std::pair
+  analyze(TokenAnnotator &Annotator,
+  SmallVectorImpl &AnnotatedLines,
+  FormatTokenLexer &Tokens) override {
+AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
+tooling::Replacements Result;
+separateBlocks(AnnotatedLines, Result);
+return {Result, 0};
+  }
+
+private:
+  void separateBlocks(SmallVectorImpl &Lines,
+  tooling::Replacements &Result) {
+auto likelyDefinition = [](AnnotatedLine *Line) {
+  return (Line->MightBeFunctionDecl && Line->mightBeFunctionDefinition()) ||
+ Line->First->isOneOf(tok::kw_class, tok::kw_struct,
+  tok::kw_namespace);
+};
+WhitespaceManager Whitespaces(
+Env.getSourceManager(), Style,
+Style.DeriveLineEnding
+? Formatter::inputUsesCRLF(
+  Env.getSourceManager().getBufferData(Env.getFileID()),
+  Style.UseCRLF)
+: Style.UseCRLF);
+for (unsigned I = 0; I < Lines.size(); I++) {
+  auto Line = Lines[I];
+  if (Line->First->closesScope()) {
+auto OpeningLineIndex = Line->MatchingOpeningBlockLineIndex;
+// Case: Opening bracket has its own line
+if (OpeningLineIndex > 0 &&
+Lines[OpeningLineIndex]->First->TokenText == "{") {
+  OpeningLineIndex--;
+}
+AnnotatedLine *OpeningLine = Lines[OpeningLineIndex];
+// Closing a function definition
+if (likelyDefinition(OpeningLine)) {
+  FormatToken *TargetToken = nullptr;
+  AnnotatedLine *TargetLine;
+  auto insertReplacement = [&]() {
+assert(TargetToken);
+Whitespaces.replaceWhitespace(*TargetToken, 2,
+  TargetToken->SpacesRequiredBefore,
+  TargetToken->StartsColumn);
+  };
+
+  // Not the first token
+  if (OpeningLineIndex > 0) {
+TargetLine = Lines[OpeningLineIndex - 1];
+// Not immediately following other scopes' opening
+if (TargetLine->Affected && !TargetLine->Last->opensScope()) {
+  // Change target, since we need to put line break *before*
+  // a token
+  TargetLine = OpeningLine;
+  TargetToken = TargetLine->First;
+
+  // Avoid duplicated replacement
+  if (TargetToken && !TargetToken->opensScope()) {
+insertReplacement();
+  }
+}
+  }
+
+  // Not the last token
+  if (I + 1 < Lines.size()) {
+TargetLine

[clang] 0c9a4da - [ASTMatchers] Simplify string comparisons (NFC)

2021-12-27 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2021-12-27T15:32:51-08:00
New Revision: 0c9a4da497c44d2c88b22ee52868fe37359c7a76

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

LOG: [ASTMatchers] Simplify string comparisons (NFC)

Identified with readability-string-compare.

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchers.h

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 55cce324b4362..599ab407c442b 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3725,10 +3725,9 @@ AST_MATCHER_P(ObjCMessageExpr, hasReceiver, 
internal::Matcher,
 /// \endcode
 AST_MATCHER_P(ObjCMessageExpr, hasSelector, std::string, BaseName) {
   Selector Sel = Node.getSelector();
-  return BaseName.compare(Sel.getAsString()) == 0;
+  return BaseName == Sel.getAsString();
 }
 
-
 /// Matches when at least one of the supplied string equals to the
 /// Selector.getAsString()
 ///



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


[PATCH] D116314: [Clangfmt] Add style to separate definition blocks

2021-12-27 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay requested changes to this revision.
MyDeveloperDay added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/Format/Format.cpp:1197
   LLVMStyle.ReferenceAlignment = FormatStyle::RAS_Pointer;
+  LLVMStyle.SeparateDefinitionBlocks = true;
   LLVMStyle.ShortNamespaceLines = 1;

This needs to be an enumeration where leave is the default


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

https://reviews.llvm.org/D116314

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


[PATCH] D116325: [X86] Add missing CET intrinsics support

2021-12-27 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe created this revision.
Herald added a subscriber: pengfei.
FreddyYe requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

These two intrinsics are documented o SDM and intrinsic guide.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116325

Files:
  clang/lib/Headers/cetintrin.h
  clang/test/CodeGen/X86/cetintrin.c


Index: clang/test/CodeGen/X86/cetintrin.c
===
--- clang/test/CodeGen/X86/cetintrin.c
+++ clang/test/CodeGen/X86/cetintrin.c
@@ -37,6 +37,12 @@
   return _rdsspd(a);
 }
 
+unsigned int test_rdsspd_i32() {
+  // CHECK-LABEL: @test_rdsspd_i32
+  // CHECK:   call i32 @llvm.x86.rdsspd(i32 %{{[a-z0-9.]+}})
+  return _rdsspd_i32();
+}
+
 #ifdef __x86_64__
 unsigned long long test_rdsspq(unsigned long long a) {
   // X86_64-LABEL: @test_rdsspq
@@ -44,6 +50,12 @@
   return _rdsspq(a);
 }
 
+unsigned long long test_rdsspq_i64() {
+  // X86_64-LABEL: @test_rdsspq_i64
+  // X86_64:   call i64 @llvm.x86.rdsspq(i64 %{{[a-z0-9.]+}})
+  return _rdsspq_i64();
+}
+
 unsigned long long test_get_ssp(void) {
   // X86_64-LABEL: @test_get_ssp
   // X86_64:   call i64 @llvm.x86.rdsspq(i64 0)
Index: clang/lib/Headers/cetintrin.h
===
--- clang/lib/Headers/cetintrin.h
+++ clang/lib/Headers/cetintrin.h
@@ -42,10 +42,20 @@
   return __builtin_ia32_rdsspd(__a);
 }
 
+static __inline__ unsigned int __DEFAULT_FN_ATTRS _rdsspd_i32() {
+  unsigned int t;
+  return __builtin_ia32_rdsspd(t);
+}
+
 #ifdef __x86_64__
 static __inline__ unsigned long long __DEFAULT_FN_ATTRS _rdsspq(unsigned long 
long __a) {
   return __builtin_ia32_rdsspq(__a);
 }
+
+static __inline__ unsigned long long __DEFAULT_FN_ATTRS _rdsspq_i64() {
+  unsigned long long t;
+  return __builtin_ia32_rdsspq(t);
+}
 #endif /* __x86_64__ */
 
 #ifdef __x86_64__


Index: clang/test/CodeGen/X86/cetintrin.c
===
--- clang/test/CodeGen/X86/cetintrin.c
+++ clang/test/CodeGen/X86/cetintrin.c
@@ -37,6 +37,12 @@
   return _rdsspd(a);
 }
 
+unsigned int test_rdsspd_i32() {
+  // CHECK-LABEL: @test_rdsspd_i32
+  // CHECK:   call i32 @llvm.x86.rdsspd(i32 %{{[a-z0-9.]+}})
+  return _rdsspd_i32();
+}
+
 #ifdef __x86_64__
 unsigned long long test_rdsspq(unsigned long long a) {
   // X86_64-LABEL: @test_rdsspq
@@ -44,6 +50,12 @@
   return _rdsspq(a);
 }
 
+unsigned long long test_rdsspq_i64() {
+  // X86_64-LABEL: @test_rdsspq_i64
+  // X86_64:   call i64 @llvm.x86.rdsspq(i64 %{{[a-z0-9.]+}})
+  return _rdsspq_i64();
+}
+
 unsigned long long test_get_ssp(void) {
   // X86_64-LABEL: @test_get_ssp
   // X86_64:   call i64 @llvm.x86.rdsspq(i64 0)
Index: clang/lib/Headers/cetintrin.h
===
--- clang/lib/Headers/cetintrin.h
+++ clang/lib/Headers/cetintrin.h
@@ -42,10 +42,20 @@
   return __builtin_ia32_rdsspd(__a);
 }
 
+static __inline__ unsigned int __DEFAULT_FN_ATTRS _rdsspd_i32() {
+  unsigned int t;
+  return __builtin_ia32_rdsspd(t);
+}
+
 #ifdef __x86_64__
 static __inline__ unsigned long long __DEFAULT_FN_ATTRS _rdsspq(unsigned long long __a) {
   return __builtin_ia32_rdsspq(__a);
 }
+
+static __inline__ unsigned long long __DEFAULT_FN_ATTRS _rdsspq_i64() {
+  unsigned long long t;
+  return __builtin_ia32_rdsspq(t);
+}
 #endif /* __x86_64__ */
 
 #ifdef __x86_64__
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D116325: [X86] Add missing CET intrinsics support

2021-12-27 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

Checked we won't raise uninitialized warning, so LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116325

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


[PATCH] D116314: [Clangfmt] Add style to separate definition blocks

2021-12-27 Thread ksyx via Phabricator via cfe-commits
ksyx updated this revision to Diff 396358.
ksyx marked an inline comment as done.
ksyx added a comment.

- Change bool type of the option to enum type
- Generate empty line for enum block

Testfile:

  // test.cpp
  #include 
  #include 
  #include 
  struct Foo {
int a,b,c;
  };
  namespace Ns {
  class Bar {
  public:
struct Foobar {
  int a;
  int b;
};
  private:
int t;
int method1()
{
  // Intentional test for different
  // line breaking mode of brackets
}
template
int method2(T x) {
  // ...
}
enum Foo {
  FOO,
  BAR
};
int method3(int par) {}
  };
  class C {
  };
  }
  namespace Ns2 {
  
  }

Tests:

  bin/clang-format test2.cpp # Test default (leave as it is)
  bin/clang-format -style='{SeparateDefinitionBlocks: Between}' test2.cpp # 
Test normal functionality
  bin/clang-format -style='{SeparateDefinitionBlocks: Leave}' test2.cpp # Test 
turning off
  bin/clang-format -style='{SeparateDefinitionBlocks: Between, BasedOnStyle: 
WebKit}' test2.cpp # Case: opening bracket { has   its own line


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

https://reviews.llvm.org/D116314

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp

Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -450,6 +450,14 @@
   }
 };
 
+template <>
+struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO, FormatStyle::SeparateDefinitionStyle &Value) {
+IO.enumCase(Value, "Leave", FormatStyle::SDS_Leave);
+IO.enumCase(Value, "Between", FormatStyle::SDS_Between);
+  }
+};
+
 template <>
 struct ScalarEnumerationTraits {
   static void enumeration(IO &IO, FormatStyle::SpaceBeforeParensStyle &Value) {
@@ -770,6 +778,7 @@
 IO.mapOptional("ReferenceAlignment", Style.ReferenceAlignment);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
@@ -1193,6 +1202,7 @@
   LLVMStyle.ObjCSpaceBeforeProtocolList = true;
   LLVMStyle.PointerAlignment = FormatStyle::PAS_Right;
   LLVMStyle.ReferenceAlignment = FormatStyle::RAS_Pointer;
+  LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
   LLVMStyle.ShortNamespaceLines = 1;
   LLVMStyle.SpacesBeforeTrailingComments = 1;
   LLVMStyle.Standard = FormatStyle::LS_Latest;
@@ -1863,13 +1873,13 @@
 return std::make_pair(Result, Penalty);
   }
 
-private:
   static bool inputUsesCRLF(StringRef Text, bool DefaultToCRLF) {
 size_t LF = Text.count('\n');
 size_t CR = Text.count('\r') * 2;
 return LF == CR ? DefaultToCRLF : CR > LF;
   }
 
+private:
   bool
   hasCpp03IncompatibleFormat(const SmallVectorImpl &Lines) {
 for (const AnnotatedLine *Line : Lines) {
@@ -2012,6 +2022,99 @@
   }
 };
 
+// This class separates definition blocks like classes, functions, and
+// namespaces by inserting a line break between them.
+class DefinitionBlockSeparator : public TokenAnalyzer {
+public:
+  DefinitionBlockSeparator(const Environment &Env, const FormatStyle &Style)
+  : TokenAnalyzer(Env, Style) {}
+
+  std::pair
+  analyze(TokenAnnotator &Annotator,
+  SmallVectorImpl &AnnotatedLines,
+  FormatTokenLexer &Tokens) override {
+AffectedRangeMgr.computeAffectedLines(AnnotatedLines);
+tooling::Replacements Result;
+separateBlocks(AnnotatedLines, Result);
+return {Result, 0};
+  }
+
+private:
+  void separateBlocks(SmallVectorImpl &Lines,
+  tooling::Replacements &Result) {
+auto likelyDefinition = [](AnnotatedLine *Line) {
+  return (Line->MightBeFunctionDecl && Line->mightBeFunctionDefinition()) ||
+ Line->First->isOneOf(tok::kw_class, tok::kw_struct,
+  tok::kw_namespace, tok::kw_enum);
+};
+WhitespaceManager Whitespaces(
+Env.getSourceManager(), Style,
+Style.DeriveLineEnding
+? Formatter::inputUsesCRLF(
+  Env.getSourceManager().getBufferData(Env.getFileID()),
+  Style.UseCRLF)
+: Style.UseCRLF);
+for (unsigned I = 0; I < Lines.size(); I++) {
+  auto Line = Lines[I];
+  if (Line->First->closesScope()) {
+auto OpeningLineIndex = Line->MatchingOpeningBlockLineIndex;
+// Case: Opening bracket has its own line
+if (OpeningLineIndex > 0 &&
+Lines[OpeningLineIndex]->First->TokenText == "{") {
+  OpeningLineIndex--;
+}
+AnnotatedLine *OpeningLine = Lines[OpeningLineIndex];
+  

[PATCH] D116290: [clang-format] Add enforcement of consistent `class`/typename` keyword for template arguments

2021-12-27 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang updated this revision to Diff 396361.
avogelsgesang marked 4 inline comments as done.
avogelsgesang added a comment.

Thank you for the quick review, @HazardyKnusperkeks!

I addressed most of your comments by fixing my code.
In two cases, I think there was a misunderstanding and I didn't apply your 
proposed changes, yet.
See my inline replies re "assert on non nullness" and "`typename` vs `Typename` 
in configuration".
If you still think, I should apply your proposed changes, please let me know. I 
don't have strong opinions on those points and am happy to do so.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116290

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/TemplateArgumentKeywordFixer.cpp
  clang/lib/Format/TemplateArgumentKeywordFixer.h
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/TemplateArgumentKeywordFixerTest.cpp

Index: clang/unittests/Format/TemplateArgumentKeywordFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/TemplateArgumentKeywordFixerTest.cpp
@@ -0,0 +1,220 @@
+//===- unittest/Format/TemplateArgumentKeywordFixerTest.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "FormatTestUtils.h"
+#include "TestLexer.h"
+#include "gtest/gtest.h"
+
+#include "../../lib/Format/TemplateArgumentKeywordFixer.h"
+
+using testing::ScopedTrace;
+
+namespace clang {
+namespace format {
+namespace {
+
+class TemplateArgumentKeywordFixerTest : public ::testing::Test {
+protected:
+  std::string format(llvm::StringRef Code,
+ const std::vector &Ranges,
+ const FormatStyle &Style) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+FormattingAttemptStatus Status;
+tooling::Replacements Replaces =
+reformat(Style, Code, Ranges, "", &Status);
+EXPECT_TRUE(Status.FormatComplete);
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  std::string format(llvm::StringRef Code, const FormatStyle &Style) {
+return format(Code,
+  /*Ranges=*/{1, tooling::Range(0, Code.size())}, Style);
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
+ llvm::StringRef Code, const FormatStyle &Style) {
+ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Expected.str(), format(Expected, Style))
+<< "Expected code is not stable";
+EXPECT_EQ(Expected.str(), format(Code, Style));
+EXPECT_EQ(Expected.str(), format(test::messUp(Code), Style));
+  }
+};
+
+#define verifyFormat(...) _verifyFormat(__FILE__, __LINE__, __VA_ARGS__)
+
+TEST_F(TemplateArgumentKeywordFixerTest, DisabledByDefault) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(Style.TemplateArgumentKeyword, FormatStyle::TAS_Leave);
+  verifyFormat("template  class A", "template  class A",
+   Style);
+  verifyFormat("template  class A", "template  class A",
+   Style);
+  verifyFormat("template  class A",
+   "template  class A", Style);
+}
+
+TEST_F(TemplateArgumentKeywordFixerTest, FormatsAsClass) {
+  FormatStyle Style = getLLVMStyle();
+  Style.TemplateArgumentKeyword = FormatStyle::TAS_Class;
+  verifyFormat("template  class A", "template  class A",
+   Style);
+  verifyFormat("template  class A", "template  class A",
+   Style);
+  verifyFormat("template  class A;",
+   "template  class A;", Style);
+  verifyFormat("template  class A;",
+   "template  class A;", Style);
+  verifyFormat("template  class Y> class A;",
+   "template  typename Y> class A;", Style);
+}
+
+TEST_F(TemplateArgumentKeywordFixerTest, ClassLeavesOtherTypenames) {
+  FormatStyle Style = getLLVMStyle();
+  Style.TemplateArgumentKeyword = FormatStyle::TAS_Class;
+  // `typename` outside of a template should stay unchanged
+  verifyFormat("typename T::nested", "typename T::nested", Style);
+  // `typename` inside a template should stay unchanged if it refers to a nested
+  // type
+  verifyFormat(
+  "template  class A;",
+  "template  class A;", Style);
+  // A legitimate `typename` might also occur in a nested list, directly after
+  // the `,` token It's not sufficient to just check for a comma in f

[PATCH] D116290: [clang-format] Add enforcement of consistent `class`/typename` keyword for template arguments

2021-12-27 Thread Adrian Vogelsgesang via Phabricator via cfe-commits
avogelsgesang added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:4003
 
+**TemplateArgumentKeyword** (``TemplateArgumentStyle``) 
:versionbadge:`clang-format 14`
+  Keyword to use for template arguments (``class`` or ``typename``)

HazardyKnusperkeks wrote:
> Have you edited this by hand? It is on a different (the right) position than 
> in `Format.h`.
No, this file is auto-generated using the `dump_format_style.py` script. 
Afaict, it sorts the entries alphabetically during generating the docs.



Comment at: clang/include/clang/Format/Format.h:1963
+  /// \version 14
+  TemplateArgumentStyle TemplateArgumentKeyword;
+

HazardyKnusperkeks wrote:
> Please sort (as good as possible, I know some things are out of order).
moved after `TabWidth`



Comment at: clang/lib/Format/Format.cpp:144-145
+IO.enumCase(Value, "Leave", FormatStyle::TAS_Leave);
+IO.enumCase(Value, "typename", FormatStyle::TAS_Typename);
+IO.enumCase(Value, "class", FormatStyle::TAS_Class);
+  }

HazardyKnusperkeks wrote:
> This is what is printed in the documentation, if generated automatically.
The documentation is currently automatically generated. I used the additional 
comments in `Format.h` to overwrite the "in configuration" values:

```
/// ...
TAS_Leave,
/// ...
TAS_Typename, // typename
/// ...
TAS_Class // class
```

Note the additional comments after `TAS_Typename` and `TAS_Class`. They 
overwrite the "in configuration" names used by dump_format_style.py. The same 
trick is used, e.g., for the `LanguageStandard` enum.

Given that using lowercase `typename` and `class` still allow for 
auto-generated documentation, do yous still want me to switch to uppercase 
`Typename`/`Class`?

Personally, I do prefer lowercase here because the language keywords are also 
lowercase. Are there any other reasons except for auto-generated documentation 
why you would prefer uppercase config values?



Comment at: clang/lib/Format/TemplateArgumentKeywordFixer.cpp:45
+  StringRef ReplacementStr;
+  tok::TokenKind BadToken;
+  bool KeepTemplateTemplateKW = false;

HazardyKnusperkeks wrote:
> I think you should rename it to TokenKindToReplace or something like that.
> A `is(BadToken)` can be misleading.
Good point! Done.



Comment at: clang/lib/Format/TemplateArgumentKeywordFixer.cpp:49
+  case FormatStyle::TAS_Leave:
+return {Fixes, 0};
+  case FormatStyle::TAS_Typename:

HazardyKnusperkeks wrote:
> Should never happen, right? Assert on that.
yes, this should be unreachable. I added an assert.

Out of curiosity/slightly off-topic: where does clang-format stand re 
"defensive programming"? "Fail fast, fail often", or rather "don't trust your 
callers and handle as many situations as possible as gracefully as possible"?



Comment at: clang/lib/Format/TemplateArgumentKeywordFixer.cpp:51
+  case FormatStyle::TAS_Typename:
+assert(Style.Standard != FormatStyle::LS_Auto);
+KeepTemplateTemplateKW = Style.Standard < FormatStyle::LS_Cpp17;

HazardyKnusperkeks wrote:
> Why is that? It is certainly possible to have that configuration and we 
> should not assert on possible user input. Either error out or handle it. I 
> think we should be on the safe side an pretend auto is before 17. Add a note 
> to the documentation about that.
I was under the false impression that `deriveLocalStyle` in `Format.cpp` would 
always replace `auto` by one of the actual versions. I was wrong about that.

Thanks for catching this!

I updated the code and added a test case for this particular case



Comment at: clang/lib/Format/TemplateArgumentKeywordFixer.cpp:80
+}
+FormatToken *EndTok = Tok->MatchingParen;
+

HazardyKnusperkeks wrote:
> assert on non nullness
nullness was checked already in line 75:

```
if (Tok->isNot(TT_TemplateOpener) || !Tok->MatchingParen) {
```

Do you still want me to add this `assert`? Should I maybe restructure the code 
somehow to make it easier to understand? Or are you fine with leaving it as is?



Comment at: clang/lib/Format/TemplateArgumentKeywordFixer.cpp:93
+  bool StartedDefaultArg = Tok->is(tok::equal);
+  auto advanceTok = [&]() {
+Tok = Tok->Next;

HazardyKnusperkeks wrote:
> Could be located outside of the loop.
I agree it could be moved outside the loop. Should it, though?

Having it inside the loop makes the code slightly easier to read by keeping the 
definition closer to its usage. And performancewise, I do trust the compiler to 
do a decent job here.

Or am I somehow misguided in my judgement here?



Comment at: clang/unittests/Format/TemplateArgumentKeywordFixerTest.cpp:167
+}
+
+} // namespace

HazardyKnusperkeks wrote:
> Just to be sure add some tests with incomplete code?

[PATCH] D116317: [CodeCompletion] Signature help for braced constructor calls

2021-12-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 396362.
sammccall added a comment.

Fix clangd tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116317

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/test/initialize-params.test
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/ASTUnit.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseInit.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/ctor-signature.cpp
  clang/tools/libclang/CIndexCodeCompletion.cpp
  lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Index: lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===
--- lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -995,7 +995,8 @@
   void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
  OverloadCandidate *Candidates,
  unsigned NumCandidates,
- SourceLocation OpenParLoc) override {
+ SourceLocation OpenParLoc,
+ bool Braced) override {
 // At the moment we don't filter out any overloaded candidates.
   }
 
Index: clang/tools/libclang/CIndexCodeCompletion.cpp
===
--- clang/tools/libclang/CIndexCodeCompletion.cpp
+++ clang/tools/libclang/CIndexCodeCompletion.cpp
@@ -656,14 +656,15 @@
 void ProcessOverloadCandidates(Sema &S, unsigned CurrentArg,
OverloadCandidate *Candidates,
unsigned NumCandidates,
-   SourceLocation OpenParLoc) override {
+   SourceLocation OpenParLoc,
+   bool Braced) override {
   StoredResults.reserve(StoredResults.size() + NumCandidates);
   for (unsigned I = 0; I != NumCandidates; ++I) {
-CodeCompletionString *StoredCompletion
-  = Candidates[I].CreateSignatureString(CurrentArg, S, getAllocator(),
+CodeCompletionString *StoredCompletion =
+Candidates[I].CreateSignatureString(CurrentArg, S, getAllocator(),
 getCodeCompletionTUInfo(),
-includeBriefComments());
-
+includeBriefComments(), Braced);
+
 CXCompletionResult R;
 R.CursorKind = CXCursor_OverloadCandidate;
 R.CompletionString = StoredCompletion;
Index: clang/test/CodeCompletion/ctor-signature.cpp
===
--- clang/test/CodeCompletion/ctor-signature.cpp
+++ clang/test/CodeCompletion/ctor-signature.cpp
@@ -15,3 +15,40 @@
   // CHECK-CC2: OVERLOAD: Foo(<#const Foo &#>)
   // CHECK-CC2: OVERLOAD: Foo(<#Foo &&#>
 }
+
+namespace std {
+template  struct initializer_list {};
+} // namespace std
+
+struct Bar {
+  // CHECK-BRACED: OVERLOAD: Bar{<#int#>}
+  Bar(int);
+  // CHECK-BRACED: OVERLOAD: Bar{<#double#>, double}
+  Bar(double, double);
+  // FIXME: no support for init-list constructors yet.
+  // CHECK-BRACED-NOT: OVERLOAD: {{.*}}char
+  Bar(std::initializer_list C);
+  // CHECK-BRACED: OVERLOAD: Bar{<#const Bar &#>}
+  // CHECK-BRACED: OVERLOAD: Bar{<#T *Pointer#>}
+  template  Bar(T *Pointer);
+};
+
+auto b1 = Bar{};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:36:15 %s | FileCheck -check-prefix=CHECK-BRACED %s
+Bar b2{};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:38:8 %s | FileCheck -check-prefix=CHECK-BRACED %s
+static int consumeBar(Bar) { return 0; }
+int b3 = consumeBar({});
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:41:22 %s | FileCheck -check-prefix=CHECK-BRACED %s
+
+struct Aggregate {
+  // FIXME: no support for aggregates yet.
+  // CHECK-AGGREGATE-NOT: OVERLOAD: Aggregate{<#const Aggregate &#>}
+  // CHECK-AGGREGATE-NOT: OVERLOAD: {{.*}}first
+  int first;
+  int second;
+};
+
+Aggregate a{};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:52:13 %s | FileCheck -check-prefix=CHECK-AGGREGATE %s
+
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -3761,7 +3761,8 @@
 CodeCompletionString *
 CodeCompleteConsumer::Overload

[PATCH] D116326: [CodeCompletion] Signature help for aggregate initialization.

2021-12-27 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added reviewers: kadircet, usaxena95.
Herald added a subscriber: arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added projects: clang, clang-tools-extra.

The "parameter list" is the list of fields which should be initialized.
We introduce a new OverloadCandidate kind for this.
It starts to become harder for CC consumers to handle all the cases for
params, so I added some extra APIs on OverloadCandidate to abstract them.

Includes some basic support for designated initializers.
The same aggregate signature is shown, the current arg jumps after the
one you just initialized. This follows C99 semantics for mixed
designated/positional initializers (which clang supports in C++ as an extension)
and is also a useful prompt for C++ as C++ designated initializers must be
in order.

Related bugs:

- https://github.com/clangd/clangd/issues/965
- https://github.com/clangd/clangd/issues/306


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116326

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/include/clang/Sema/CodeCompleteConsumer.h
  clang/lib/Sema/CodeCompleteConsumer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/ctor-signature.cpp

Index: clang/test/CodeCompletion/ctor-signature.cpp
===
--- clang/test/CodeCompletion/ctor-signature.cpp
+++ clang/test/CodeCompletion/ctor-signature.cpp
@@ -42,13 +42,29 @@
 // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:41:22 %s | FileCheck -check-prefix=CHECK-BRACED %s
 
 struct Aggregate {
-  // FIXME: no support for aggregates yet.
-  // CHECK-AGGREGATE-NOT: OVERLOAD: Aggregate{<#const Aggregate &#>}
-  // CHECK-AGGREGATE-NOT: OVERLOAD: {{.*}}first
   int first;
   int second;
+  int third;
 };
 
-Aggregate a{};
-// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:52:13 %s | FileCheck -check-prefix=CHECK-AGGREGATE %s
+Aggregate a{1, 2, 3};
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:50:13 %s | FileCheck -check-prefix=CHECK-AGGREGATE-1 %s
+// CHECK-AGGREGATE-1: OVERLOAD: Aggregate{<#int first#>, int second, int third}
+// CHECK-AGGREGATE-1: OVERLOAD: Aggregate{<#const Aggregate &#>}
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:50:16 %s | FileCheck -check-prefix=CHECK-AGGREGATE-2 %s
+// CHECK-AGGREGATE-2: OVERLOAD: Aggregate{int first, <#int second#>, int third}
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:50:18 %s | FileCheck -check-prefix=CHECK-AGGREGATE-3 %s
+// CHECK-AGGREGATE-3: OVERLOAD: Aggregate{int first, int second, <#int third#>}
 
+Aggregate d{.second=1, .first=2, 3, 4, };
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:59:13 %s | FileCheck -check-prefix=CHECK-DESIG-1 %s
+// CHECK-DESIG-1: OVERLOAD: Aggregate{<#int first#>, int second, int third}
+// CHECK-DESIG-1: OVERLOAD: Aggregate{<#const Aggregate &#>}
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:59:24 %s | FileCheck -check-prefix=CHECK-DESIG-2 %s
+// CHECK-DESIG-2: OVERLOAD: Aggregate{int first, int second, <#int third#>}
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:59:34 %s | FileCheck -check-prefix=CHECK-DESIG-3 %s
+// CHECK-DESIG-3: OVERLOAD: Aggregate{int first, <#int second#>, int third}
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:59:37 %s | FileCheck -check-prefix=CHECK-DESIG-4 %s
+// CHECK-DESIG-4: OVERLOAD: Aggregate{int first, int second, <#int third#>}
+// RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:59:38 %s | FileCheck -check-prefix=CHECK-DESIG-5 %s --allow-empty
+// CHECK-DESIG-5-NOT: OVERLOAD
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -2817,14 +2817,18 @@
Optional> ObjCSubsts = None);
 
 static std::string
-FormatFunctionParameter(const PrintingPolicy &Policy, const ParmVarDecl *Param,
-bool SuppressName = false, bool SuppressBlock = false,
+FormatFunctionParameter(const PrintingPolicy &Policy,
+const DeclaratorDecl *Param, bool SuppressName = false,
+bool SuppressBlock = false,
 Optional> ObjCSubsts = None) {
   // Params are unavailable in FunctionTypeLoc if the FunctionType is invalid.
   // It would be better to pass in the param Type, which is usually available.
   // But this case is rare, so just pretend we fell back to int as elsewhere.
   if (!Param)
 return "int";
+  Decl::ObjCDeclQualifier ObjCQual = Decl::OBJC_TQ_None;
+  if (const auto *PVD = dyn_cast(Param))
+ObjCQual = PVD->getObjCDeclQualifier();
   bool ObjCMethodParam = isa(Param->getDeclContext());
   if (Param->getType()->isDependentType() ||
   !Param->getType()->isBloc

[clang] 6c335b1 - [clang] Remove unused "using" (NFC)

2021-12-27 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2021-12-27T20:48:21-08:00
New Revision: 6c335b1a452f48c563bc503c81af297803885b59

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

LOG: [clang] Remove unused "using" (NFC)

Identified by misc-unused-using-decls.

Added: 


Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
clang/lib/Tooling/Transformer/Parsing.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index d32b3f217aa02..736e76152fe48 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -55,7 +55,6 @@
 
 using namespace clang;
 using namespace sema;
-using llvm::RoundingMode;
 
 /// Determine whether the use of this declaration is valid, without
 /// emitting diagnostics.

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index f93e0d2ed1c48..732f07c1e0b38 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -142,7 +142,6 @@ using namespace clang;
 using namespace clang::serialization;
 using namespace clang::serialization::reader;
 using llvm::BitstreamCursor;
-using llvm::RoundingMode;
 
 
//===--===//
 // ChainedASTReaderListener implementation

diff  --git a/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
index 517a5d78271b8..aa70db041c762 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
@@ -23,7 +23,6 @@
 
 using namespace clang;
 using namespace ento;
-using llvm::APSInt;
 
 namespace {
 class MmapWriteExecChecker : public Checker {

diff  --git a/clang/lib/Tooling/Transformer/Parsing.cpp 
b/clang/lib/Tooling/Transformer/Parsing.cpp
index 242db2a16b43e..4f41e2e90def1 100644
--- a/clang/lib/Tooling/Transformer/Parsing.cpp
+++ b/clang/lib/Tooling/Transformer/Parsing.cpp
@@ -33,7 +33,6 @@ using namespace transformer;
 // much as possible with the AST Matchers parsing.
 
 namespace {
-using llvm::Error;
 using llvm::Expected;
 
 template  using RangeSelectorOp = RangeSelector (*)(Ts...);



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


[PATCH] D93298: [RISCV] add the MC layer support of Zfinx extension

2021-12-27 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence updated this revision to Diff 396373.
achieveartificialintelligence added a comment.

Update Part of Zfinx Codes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

Files:
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfoD.td
  llvm/lib/Target/RISCV/RISCVInstrInfoF.td
  llvm/lib/Target/RISCV/RISCVInstrInfoZfh.td
  llvm/lib/Target/RISCV/RISCVRegisterInfo.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/rv32i-invalid.s
  llvm/test/MC/RISCV/rv32zdinx-invalid.s
  llvm/test/MC/RISCV/rv32zdinx-valid.s
  llvm/test/MC/RISCV/rv32zfinx-invalid.s
  llvm/test/MC/RISCV/rv32zfinx-valid.s
  llvm/test/MC/RISCV/rv32zhinx-invalid.s
  llvm/test/MC/RISCV/rv32zhinx-valid.s
  llvm/test/MC/RISCV/rv32zhinxmin-invalid.s
  llvm/test/MC/RISCV/rvzdinx-aliases-valid.s
  llvm/test/MC/RISCV/rvzfinx-aliases-valid.s
  llvm/test/MC/RISCV/rvzhinx-aliases-valid.s

Index: llvm/test/MC/RISCV/rvzhinx-aliases-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvzhinx-aliases-valid.s
@@ -0,0 +1,49 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zhinx -riscv-no-aliases \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zhinx \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zhinx -riscv-no-aliases \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zhinx \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-zhinx %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zhinx -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-zhinx %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zhinx - \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zhinx %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zhinx -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zhinx %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zhinx - \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+
+##===--===##
+## Aliases which omit the rounding mode.
+##===--===##
+
+# CHECK-INST: fmadd.h a0, a1, a2, a3, dyn
+# CHECK-ALIAS: fmadd.h a0, a1, a2, a3
+fmadd.h x10, x11, x12, x13
+# CHECK-INST: fmsub.h a4, a5, a6, a7, dyn
+# CHECK-ALIAS: fmsub.h a4, a5, a6, a7
+fmsub.h x14, x15, x16, x17
+# CHECK-INST: fnmsub.h s2, s3, s4, s5, dyn
+# CHECK-ALIAS: fnmsub.h s2, s3, s4, s5
+fnmsub.h x18, x19, x20, x21
+# CHECK-INST: fnmadd.h s6, s7, s8, s9, dyn
+# CHECK-ALIAS: fnmadd.h s6, s7, s8, s9
+fnmadd.h x22, x23, x24, x25
+# CHECK-INST: fadd.h s10, s11, t3, dyn
+# CHECK-ALIAS: fadd.h s10, s11, t3
+fadd.h x26, x27, x28
+# CHECK-INST: fsub.h t4, t5, t6, dyn
+# CHECK-ALIAS: fsub.h t4, t5, t6
+fsub.h x29, x30, x31
+# CHECK-INST: fmul.h s0, s1, s2, dyn
+# CHECK-ALIAS: fmul.h s0, s1, s2
+fmul.h s0, s1, s2
+# CHECK-INST: fdiv.h s3, s4, s5, dyn
+# CHECK-ALIAS: fdiv.h s3, s4, s5
+fdiv.h s3, s4, s5
Index: llvm/test/MC/RISCV/rvzfinx-aliases-valid.s
===
--- /dev/null
+++ llvm/test/MC/RISCV/rvzfinx-aliases-valid.s
@@ -0,0 +1,49 @@
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zfinx -riscv-no-aliases \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+experimental-zfinx \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zfinx -riscv-no-aliases \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+experimental-zfinx \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-zfinx %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zfinx -M no-aliases - \
+# RUN: | FileCheck -check-prefix=CHECK-INST %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+experimental-zfinx %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zfinx - \
+# RUN: | FileCheck -check-prefix=CHECK-ALIAS %s
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+experimental-zfinx %s \
+# RUN: | llvm-objdump -d --mattr=+experimental-zfinx -M no-aliases - \
+# RUN: | FileCheck -check-prefix=C

[PATCH] D93298: [RISCV] add the part of MC layer support of Zfinx extension

2021-12-27 Thread Shao-Ce SUN via Phabricator via cfe-commits
achieveartificialintelligence added a comment.

I'll finish the rest of code, if this patch is acceptable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93298

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


[PATCH] D116328: [ast-matchers] Add hasSubstmt() traversal matcher for caseStmt(), defaultStmt()

2021-12-27 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood created this revision.
LegalizeAdulthood added a reviewer: klimek.
LegalizeAdulthood requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Previously if you wanted to match the statement associated with
a case or default block, you had to use hasDescendant.  Review
comments stated that hasDescendant is heavy-handed and that a
more specific narrowing matcher was preferred.  This is that
narrowing matcher.

- Separate matcher definitions with a blank line.
- Add corresponding unit tests for new narrowing matcher.
- Add the new matcher to the Registry
- Add documentation in the AST matchers reference HTML page.
- Remove trailing semi-colon from REGISTER_MATCHER macro to be consistent with 
the other macro declarations and fix a missing semi-colon in the invocation of 
the macro.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116328

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -311,6 +311,18 @@
   EXPECT_TRUE(notMatches("struct Foo {};", NamedNotRecord));
 }
 
+TEST_P(ASTMatchersTest, HasCaseSubstmt) {
+  EXPECT_TRUE(matches(
+  "void f() { switch (1) { case 1: return; break; default: break; } }",
+  traverse(TK_AsIs, caseStmt(hasSubstmt(returnStmt());
+}
+
+TEST_P(ASTMatchersTest, HasDefaultSubstmt) {
+  EXPECT_TRUE(matches(
+  "void f() { switch (1) { case 1: return; break; default: break; } }",
+  traverse(TK_AsIs, defaultStmt(hasSubstmt(breakStmt());
+}
+
 TEST_P(ASTMatchersTest, HasCastKind) {
   EXPECT_TRUE(
   matches("char *p = 0;",
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -66,7 +66,7 @@
 
 #define REGISTER_MATCHER(name) \
   registerMatcher(#name, internal::makeMatcherAutoMarshall(\
- ::clang::ast_matchers::name, #name));
+ ::clang::ast_matchers::name, #name))
 
 #define REGISTER_MATCHER_OVERLOAD(name)\
   registerMatcher(#name,   \
@@ -143,7 +143,7 @@
   REGISTER_MATCHER(atomicType);
   REGISTER_MATCHER(attr);
   REGISTER_MATCHER(autoType);
-  REGISTER_MATCHER(autoreleasePoolStmt)
+  REGISTER_MATCHER(autoreleasePoolStmt);
   REGISTER_MATCHER(binaryConditionalOperator);
   REGISTER_MATCHER(binaryOperator);
   REGISTER_MATCHER(binaryOperation);
@@ -355,6 +355,7 @@
   REGISTER_MATCHER(hasSpecializedTemplate);
   REGISTER_MATCHER(hasStaticStorageDuration);
   REGISTER_MATCHER(hasStructuredBlock);
+  REGISTER_MATCHER(hasSubstmt);
   REGISTER_MATCHER(hasSyntacticForm);
   REGISTER_MATCHER(hasTargetDecl);
   REGISTER_MATCHER(hasTemplateArgument);
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2429,6 +2429,7 @@
 /// Matches co_await expressions where the type of the promise is dependent
 extern const internal::VariadicDynCastAllOfMatcher
 dependentCoawaitExpr;
+
 /// Matches co_yield expressions.
 ///
 /// Given
@@ -7716,6 +7717,24 @@
   return InnerMatcher.matches(*Node.getLHS(), Finder, Builder);
 }
 
+/// Matches the substatement associated with a case or default statement.
+///
+/// Given
+/// \code
+///   switch (1) { case 1: break; case 2: return; break; default: return; break; }
+/// \endcode
+///
+/// caseStmt(hasSubstmt(returnStmt()))
+///   matches "case 2: return;"
+/// defaultStmt(hasSubstmt(returnStmt()))
+///   matches "default: return;"
+AST_POLYMORPHIC_MATCHER_P(hasSubstmt,
+  AST_POLYMORPHIC_SUPPORTED_TYPES(CaseStmt,
+  DefaultStmt),
+  internal::Matcher, InnerMatcher) {
+  return InnerMatcher.matches(*Node.getSubStmt(), Finder, Builder);
+}
+
 /// Matches declaration that has a given attribute.
 ///
 /// Given
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -7298,6 +7298,16 @@
 
 
 
+MatcherCaseStmt>hasSubstmtMatcherStmt> InnerMatc

[PATCH] D116328: [ast-matchers] Add hasSubstmt() traversal matcher for caseStmt(), defaultStmt()

2021-12-27 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.

I think while implementing this I got a little confused as to whether or not it 
was a narrowing or traversal matcher.  It feels like a traversal matcher to me.

If someone would confirm my reasoning, I'd appreciate it.  That means I should 
probably move the unit tests to the traversal tests file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116328

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


[PATCH] D116329: [clang-check] Adjust argument adjusters for clang-check to strip options blocking the static analyzer

2021-12-27 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie created this revision.
OikawaKirie added reviewers: kbobyrev, sammccall, labath.
OikawaKirie added a project: clang.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
a.sidorin, baloghadamsoftware.
OikawaKirie requested review of this revision.
Herald added a subscriber: cfe-commits.

Output generation options (like `-save-temps`) will make the analyzer not 
executed even `--analyze` option is provided in the driver arguments.
Besides, the original approach of adding `--analyze` option will not work when 
(more than one) `-fsyntax-only` options are provided in the driver arguments.

This patch fixes these two problems by using the syntax-only adjuster to remove 
output generation options and manually filter out redundant `-fsyntax-only` 
options.

In the new implementation, the adjusters added by `ClangTool` will not be 
removed but used as dependencies for clang-check adjusters for analyzer options.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116329

Files:
  clang/test/Tooling/clang-check-analyze-save-temps.cpp
  clang/tools/clang-check/ClangCheck.cpp


Index: clang/tools/clang-check/ClangCheck.cpp
===
--- clang/tools/clang-check/ClangCheck.cpp
+++ clang/tools/clang-check/ClangCheck.cpp
@@ -208,27 +208,39 @@
   ClangTool Tool(OptionsParser.getCompilations(),
  OptionsParser.getSourcePathList());
 
-  // Clear adjusters because -fsyntax-only is inserted by the default chain.
-  Tool.clearArgumentsAdjusters();
-
-  // Reset output path if is provided by user.
-  Tool.appendArgumentsAdjuster(
-  Analyze ? [&](const CommandLineArguments &Args, StringRef File) {
-  auto Ret = getClangStripOutputAdjuster()(Args, File);
-  if (!AnalyzerOutput.empty()) {
-Ret.emplace_back("-o");
-Ret.emplace_back(AnalyzerOutput);
-  }
-  return Ret;
-}
-  : getClangStripOutputAdjuster());
-
-  Tool.appendArgumentsAdjuster(getClangStripDependencyFileAdjuster());
-
-  // Running the analyzer requires --analyze. Other modes can work with the
-  // -fsyntax-only option.
-  Tool.appendArgumentsAdjuster(getInsertArgumentAdjuster(
-  Analyze ? "--analyze" : "-fsyntax-only", ArgumentInsertPosition::BEGIN));
+  if (Analyze) {
+// Set output path if is provided by user.
+//
+// As the original -o options have been removed by strip-output adjuster, 
we
+// only need to add the analyzer -o options here.
+if (!AnalyzerOutput.empty()) {
+  Tool.appendArgumentsAdjuster(getInsertArgumentAdjuster("-o"));
+  Tool.appendArgumentsAdjuster(
+  getInsertArgumentAdjuster(AnalyzerOutput.c_str()));
+}
+
+// Running the analyzer requires --analyze. Other modes can work with the
+// -fsyntax-only option.
+//
+// The syntax-only adjuster can also help us to remove other options that
+// trigger output generation, e.g. -save-temps. Besides, to enable the
+// analyzer, we also need to replace the first -fsyntax-only option with
+// option --analyze, and remove redundant ones.
+Tool.appendArgumentsAdjuster(
+[&](const CommandLineArguments &Args, StringRef /*unused*/) {
+  CommandLineArguments AdjustedArgs;
+  bool HasAnalyze = false;
+  for (const StringRef Arg : Args) {
+if (Arg != "-fsyntax-only") {
+  AdjustedArgs.emplace_back(Arg);
+} else if (!HasAnalyze) {
+  AdjustedArgs.emplace_back("--analyze");
+  HasAnalyze = true;
+}
+  }
+  return AdjustedArgs;
+});
+  }
 
   ClangCheckActionFactory CheckFactory;
   std::unique_ptr FrontendFactory;
Index: clang/test/Tooling/clang-check-analyze-save-temps.cpp
===
--- /dev/null
+++ clang/test/Tooling/clang-check-analyze-save-temps.cpp
@@ -0,0 +1,19 @@
+// Check whether output generation options (like -save-temps) will not affect
+// the execution of the analyzer.
+
+// RUN: clang-check -analyze %s -- -save-temps -c -Xclang -verify
+
+
+// Check whether redundant -fsyntax-only options will affect the execution of
+// the analyzer.
+
+// RUN: clang-check -analyze %s -- \
+// RUN:   -fsyntax-only -c -fsyntax-only -Xclang -verify 2>&1 | \
+// RUN:   FileCheck %s --allow-empty
+
+// CHECK-NOT: argument unused during compilation: '--analyze'
+
+void a(int *x) {
+  if (x) { }
+  *x = 47; // expected-warning {{Dereference of null pointer}}
+}


Index: clang/tools/clang-check/ClangCheck.cpp
===
--- clang/tools/clang-check/ClangCheck.cpp
+++ clang/tools/clang-check/ClangCheck.cpp
@@ -208,27 +208,39 @@
   ClangTool Tool(OptionsParser.getCompilations(),
  OptionsParser.getSourcePathList());
 
-  // Clear adjus

[clang] b5c5d89 - [clang][dataflow] Add support for noreturn destructor calls

2021-12-27 Thread Stanislav Gatev via cfe-commits

Author: Stanislav Gatev
Date: 2021-12-28T07:04:39Z
New Revision: b5c5d8912e07218e3a6a0f8d1d9f7b436046c5bc

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

LOG: [clang][dataflow] Add support for noreturn destructor calls

This is part of the implementation of the dataflow analysis framework.
See "[RFC] A dataflow analysis framework for Clang AST" on cfe-dev.

Reviewed By: xazax.hun, gribozavr2

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

Added: 
clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp

Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
clang/lib/Analysis/FlowSensitive/CMakeLists.txt
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
clang/unittests/Analysis/FlowSensitive/TestingSupport.h
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h 
b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
new file mode 100644
index 0..e6ceb3a89131d
--- /dev/null
+++ b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
@@ -0,0 +1,57 @@
+//===-- ControlFlowContext.h *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines a ControlFlowContext class that is used by dataflow
+//  analyses that run over Control-Flow Graphs (CFGs).
+//
+//===--===//
+
+#ifndef LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CONTROLFLOWCONTEXT_H
+#define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CONTROLFLOWCONTEXT_H
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Stmt.h"
+#include "clang/Analysis/CFG.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/Support/Error.h"
+#include 
+#include 
+
+namespace clang {
+namespace dataflow {
+
+/// Holds CFG and other derived context that is needed to perform dataflow
+/// analysis.
+class ControlFlowContext {
+public:
+  /// Builds a ControlFlowContext from an AST node.
+  static llvm::Expected build(const Decl *D, Stmt *S,
+  ASTContext *C);
+
+  /// Returns the CFG that is stored in this context.
+  const CFG &getCFG() const { return *Cfg; }
+
+  /// Returns a mapping from statements to basic blocks that contain them.
+  const llvm::DenseMap &getStmtToBlock() const 
{
+return StmtToBlock;
+  }
+
+private:
+  ControlFlowContext(std::unique_ptr Cfg,
+ llvm::DenseMap 
StmtToBlock)
+  : Cfg(std::move(Cfg)), StmtToBlock(std::move(StmtToBlock)) {}
+
+  std::unique_ptr Cfg;
+  llvm::DenseMap StmtToBlock;
+};
+
+} // namespace dataflow
+} // namespace clang
+
+#endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_CONTROLFLOWCONTEXT_H

diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
index a5d4a5d6ba407..a96ed0437a439 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -21,6 +21,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Stmt.h"
 #include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowSensitive/ControlFlowContext.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
 #include "llvm/ADT/Any.h"
@@ -101,17 +102,12 @@ template  struct DataflowAnalysisState 
{
 /// Performs dataflow analysis and returns a mapping from basic block IDs to
 /// dataflow analysis states that model the respective basic blocks. Indices
 /// of the returned vector correspond to basic block IDs.
-///
-/// Requirements:
-///
-///  `Cfg` must have been built with `CFG::BuildOptions::setAllAlwaysAdd()` to
-///  ensure that all sub-expressions in a basic block are evaluated.
 template 
 std::vector>>
-runDataflowAnalysis(const CFG &Cfg, AnalysisT &Analysis,
+runDataflowAnalysis(const ControlFlowContext &CFCtx, AnalysisT &Analysis,
 const Environment &InitEnv) {
   auto TypeErasedBlockStates =
-  runTypeErasedDataflowAnalysis(Cfg, Analysis, InitEnv);
+  runTypeErasedDataflowAnalysis(CFCtx, Analysis, InitEnv);
  

[PATCH] D116022: [clang][dataflow] Add support for noreturn destructor calls

2021-12-27 Thread Stanislav Gatev 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 rGb5c5d8912e07: [clang][dataflow] Add support for noreturn 
destructor calls (authored by sgatev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D116022

Files:
  clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h
  clang/lib/Analysis/FlowSensitive/CMakeLists.txt
  clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "TestingSupport.h"
 #include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
@@ -14,15 +15,24 @@
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
 
 using namespace clang;
 using namespace dataflow;
+using ::testing::IsEmpty;
+using ::testing::Pair;
+using ::testing::UnorderedElementsAre;
 
 template 
 class AnalysisCallback : public ast_matchers::MatchFinder::MatchCallback {
@@ -36,21 +46,12 @@
 Stmt *Body = Func->getBody();
 assert(Body != nullptr);
 
-// FIXME: Consider providing a utility that returns a `CFG::BuildOptions`
-// which is a good default for most clients or a utility that directly
-// builds the `CFG` using default `CFG::BuildOptions`.
-CFG::BuildOptions Options;
-Options.AddImplicitDtors = true;
-Options.AddTemporaryDtors = true;
-Options.setAllAlwaysAdd();
-
-std::unique_ptr Cfg =
-CFG::buildCFG(nullptr, Body, Result.Context, Options);
-assert(Cfg != nullptr);
+auto CFCtx = llvm::cantFail(
+ControlFlowContext::build(nullptr, Body, Result.Context));
 
 AnalysisT Analysis(*Result.Context);
 Environment Env;
-BlockStates = runDataflowAnalysis(*Cfg, Analysis, Env);
+BlockStates = runDataflowAnalysis(CFCtx, Analysis, Env);
   }
 
   std::vector<
@@ -141,8 +142,175 @@
 }
   )");
   EXPECT_EQ(BlockStates.size(), 4u);
-  EXPECT_FALSE(BlockStates[0].hasValue());
+  EXPECT_TRUE(BlockStates[0].hasValue());
   EXPECT_TRUE(BlockStates[1].hasValue());
   EXPECT_TRUE(BlockStates[2].hasValue());
   EXPECT_TRUE(BlockStates[3].hasValue());
 }
+
+struct FunctionCallLattice {
+  llvm::SmallSet CalledFunctions;
+
+  bool operator==(const FunctionCallLattice &Other) const {
+return CalledFunctions == Other.CalledFunctions;
+  }
+
+  LatticeJoinEffect join(const FunctionCallLattice &Other) {
+if (Other.CalledFunctions.empty())
+  return LatticeJoinEffect::Unchanged;
+const size_t size_before = CalledFunctions.size();
+CalledFunctions.insert(Other.CalledFunctions.begin(),
+   Other.CalledFunctions.end());
+return CalledFunctions.size() == size_before ? LatticeJoinEffect::Unchanged
+ : LatticeJoinEffect::Changed;
+  }
+};
+
+std::ostream &operator<<(std::ostream &OS, const FunctionCallLattice &L) {
+  std::string S;
+  llvm::raw_string_ostream ROS(S);
+  llvm::interleaveComma(L.CalledFunctions, ROS);
+  return OS << "{" << S << "}";
+}
+
+class FunctionCallAnalysis
+: public DataflowAnalysis {
+public:
+  explicit FunctionCallAnalysis(ASTContext &Context)
+  : DataflowAnalysis(Context) {}
+
+  static FunctionCallLattice initialElement() { return {}; }
+
+  FunctionCallLattice transfer(const Stmt *S, const FunctionCallLattice &E,
+   Environment &Env) {
+FunctionCallLattice R = E;
+if (auto *C = dyn_cast(S)) {
+  if (auto *F = dyn_cast(C->getCalleeDecl())) {
+R.CalledFunctions.insert(F->getNameInfo().getAsString());
+  }
+}
+return R;
+  }
+};
+
+class NoreturnDestructorTest : public ::testing::Test {
+protected:
+  template 
+  void runDataflow(llvm::StringRef Code, Matcher Expectations) {
+too