[PATCH] D94500: [clang-format] Rework Whitesmiths mode to use line-level values in UnwrappedLineParser

2021-06-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

This has been landed in the 12.0.1 RC 
https://github.com/llvm/llvm-project/commit/c7d7ace46258b04aa4b5df08952bfebc6fc4ce94


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94500

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

Part of the problem here is we are not really parsing the Lambda but trying to 
break based on token annotation only. This can tend to be a bit fragile 
(normally around corner cases)

The previous approach I think was not constrained enough to just lambdas which 
is why we had the bleed into other things, also when we added this we didn't 
really test that it didn't have any impact on anything else.

Actually this has been a problem when adding new options. I keep meaning to 
extend the `LLVMDefaultStyle`  `GNUDefaultStyle`  `MozillaDefaultStyle` tests 
to cover all behaviour (if/else/while/do/for/etc..) but also to find a way that 
when a new option is added we can validate that non of the other aspects of a 
style aren't broken when using that. (not an easy problem to fix)

I'm keen for this NOT to break the AfterClass, AfterNamespace issue, (which is 
a regression)... we can continue to chip away at corner cases or revert the 
original change completely. (which I also don't want to do)

likely trying to add add parseXXX() functions in UnwrappedLineParser would 
likely take much longer. I feel like that might offer the better solution but 
think I would prefer we used that to replace this and gravitate slowly towards 
a more correct case


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

https://reviews.llvm.org/D104222

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.



> And also another different in that case (without lambda):
>
>   ASSERT_NO_THROW(
>   {
>   iterator += 507408;
>   });
>
> is now format like this:
>
>   ASSERT_NO_THROW({ iterator += 507408; });

I think this shows where your change made an assumption that this was a lambda, 
but its not necessarily is as there is no TT_LamdbaLBrace, I would argue your 
change was the regression even if looks nicer (in your view)

AnnotatedTokens(L=0):
 M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=identifier L=15 PPK=2 FakeLParens= 
FakeRParens=0 II=0xad8a50 Text='ASSERT_NO_THROW'
 M=0 C=0 T=Unknown S=0 F=0 B=1 BK=0 P=23 Name=l_paren L=16 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text='('
 M=0 C=1 T=Unknown S=0 F=0 B=0 BK=1 P=140 Name=l_brace L=17 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text='{'
 M=0 C=1 T=Unknown S=1 F=0 B=0 BK=0 P=61 Name=r_brace L=39 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text='}'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=40 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text=')'
 M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=semi L=41 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text=';'


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

https://reviews.llvm.org/D104222

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

For this case:

>   return iter::chain.from_iterable(
> [](auto&& ite) -> auto&
> {
>   return ite.second;
> });

The code has not been classified as a Lambda

  AnnotatedTokens(L=0):
   M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=return L=6 PPK=2 FakeLParens= 
FakeRParens=0 II=0x24bf7e8 Text='return'
   M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=23 Name=identifier L=11 PPK=2 
FakeLParens=0/ FakeRParens=0 II=0x24c35c0 Text='iter'
   M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=coloncolon L=13 PPK=2 
FakeLParens= FakeRParens=0 II=0x0 Text='::'
   M=0 C=1 T=Unknown S=0 F=0 B=0 BK=0 P=520 Name=identifier L=18 PPK=2 
FakeLParens= FakeRParens=0 II=0x24c3738 Text='chain'
   M=0 C=1 T=Unknown S=0 F=0 B=0 BK=0 P=170 Name=period L=19 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text='.'
   M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=identifier L=32 PPK=2 
FakeLParens= FakeRParens=0 II=0x24c3760 Text='from_iterable'
   M=0 C=0 T=Unknown S=0 F=0 B=1 BK=0 P=23 Name=l_paren L=33 PPK=1 FakeLParens= 
FakeRParens=0 II=0x0 Text='('
   M=0 C=1 T=ArrayInitializerLSquare S=0 F=0 B=0 BK=0 P=59 Name=l_square L=34 
PPK=2 FakeLParens=1/ FakeRParens=0 II=0x0 Text='['
   M=0 C=1 T=Unknown S=0 F=0 B=0 BK=0 P=79 Name=r_square L=35 PPK=2 
FakeLParens= FakeRParens=0 II=0x0 Text=']'
   M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=l_paren L=36 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text='('
   M=0 C=1 T=Unknown S=0 F=0 B=0 BK=0 P=79 Name=auto L=40 PPK=2 FakeLParens= 
FakeRParens=0 II=0x24bf510 Text='auto'
   M=0 C=1 T=PointerOrReference S=1 F=0 B=0 BK=0 P=250 Name=ampamp L=43 PPK=2 
FakeLParens= FakeRParens=0 II=0x0 Text='&&'
   M=0 C=1 T=StartOfName S=0 F=0 B=0 BK=0 P=260 Name=identifier L=46 PPK=2 
FakeLParens= FakeRParens=0 II=0x24c3780 Text='ite'
   M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=63 Name=r_paren L=47 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text=')'
   M=0 C=1 T=LambdaArrow S=1 F=0 B=0 BK=0 P=150 Name=arrow L=50 PPK=2 
FakeLParens= FakeRParens=0 II=0x0 Text='->'
   M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=43 Name=auto L=55 PPK=2 FakeLParens= 
FakeRParens=0 II=0x24bf510 Text='auto'
   M=0 C=1 T=PointerOrReference S=1 F=0 B=0 BK=0 P=230 Name=amp L=57 PPK=2 
FakeLParens= FakeRParens=0 II=0x0 Text='&'
   M=0 C=0 T=Unknown S=1 F=0 B=0 BK=1 P=48 Name=l_brace L=59 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text='{'
   M=0 C=1 T=Unknown S=1 F=0 B=0 BK=0 P=61 Name=r_brace L=80 PPK=2 FakeLParens= 
FakeRParens=1 II=0x0 Text='}'
   M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=81 PPK=2 FakeLParens= 
FakeRParens=1 II=0x0 Text=')'
   M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=semi L=82 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text=';'

It doesn't see this

  M=0 C=0 T=Unknown S=1 F=0 B=0 BK=1 P=48 Name=l_brace L=59 PPK=2 FakeLParens= 
FakeRParens=0 II=0x0 Text='{'

As a LamdaLBrace

Again I would say this was actually a failure elsewhere


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

https://reviews.llvm.org/D104222

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


[PATCH] D103750: [analyzer] Handle std::make_unique for SmartPtrModeling

2021-06-16 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

This looks great to me, I think the patch is good to go as long as Valeriy's 
comment is addressed :)

Speaking of specs, hold up, we're forgetting something very important.

`make_unique()` also has to call the //constructor// of the underlying value. 
We're supposed to model that.

The constructor may be inlined or evaluated conservatively.

`~unique_ptr()` is also supposed to call the //destructor// of the underlying 
value. We're supposed to model that.

F17422410: .jpg 

I.e., you could imagine a bunch of tests like this

  struct S {
int *p;
S(int *p): p(p) {}
~S() { *p = 0; }
  };
  
  void foo() {
int x = 1;
{
  auto P = std::make_unique(&x);
  clang_analyzer_eval(*P->p == 1); // TRUE
}
clang_analyzer_eval(x == 0); // TRUE
  }

We could stick to conservative evaluation of such constructors and destructors; 
at the very least, we should actively invalidate Store at the destructor. This 
patch can remain unchanged because the default values inside freshly conjured 
regions are unknown. But that'd still be a regression because the above test 
(presumably) passes with inlining.

Is now a good time to legalize modeling function calls inside checker callbacks?




Comment at: clang/test/Analysis/smart-ptr-text-output.cpp:3
+// RUN:  -analyzer-checker=core,cplusplus.Move,alpha.cplusplus.SmartPtr\
+// RUN:  -analyzer-config 
cplusplus.SmartPtrModeling:ModelSmartPtrDereference=true\
+// RUN:  -analyzer-output=text -std=c++20 %s -verify=expected

Could you double-check that this flag correctly disables all the newly 
introduced modeling so that it wasn't accidentally enabled for all users before 
it's ready?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103750

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D104222#2820001 , 
@HazardyKnusperkeks wrote:

> Just asking: Would it be different if there is `auto`, `decltype(auto)`, 
> `decltype(a+b)`, `typename` or `template` as trailing return type?

It would be good if you could give a small example, just so I can clarify what 
you mean,

but I think these could easily be corner cases which at least for a current non 
parsed based solution would could potentially fill with mustBreak rules..


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

https://reviews.llvm.org/D104222

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


[PATCH] D104300: [analyzer] Handle std::swap for std::unique_ptr

2021-06-16 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I think notes are fairly straightforward: if we're tracking one smart pointer 
below the swap, we should stop tracking it and start tracking the other smart 
pointer above the swap. If both were tracked, keep tracking both (but in 
swapped manners, assuming we're tracking them in different manners). It doesn't 
matter whether any of them is null, it only matters which ones were tracked. 
Though I guess we could mention if any of them are null or do other cosmetic 
improvements depending on how they participated in the bug. Trackedness is 
equivalent to interestingness because we're dealing with regions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104300

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


[PATCH] D104097: [analyzer] Fix calculating offset for fields with an empty type

2021-06-16 Thread Georgy Komarov via Phabricator via cfe-commits
jubnzv updated this revision to Diff 352361.
jubnzv added a comment.

Added two tests that check whether we still calculate padding correctly for 
structs with `[[no_unique_address]]` on two consecutive fields


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

https://reviews.llvm.org/D104097

Files:
  clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
  clang/test/Analysis/padding_no_unique_address.cpp


Index: clang/test/Analysis/padding_no_unique_address.cpp
===
--- /dev/null
+++ clang/test/Analysis/padding_no_unique_address.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-linux-gnu 
-analyzer-checker=optin.performance -analyzer-config 
optin.performance.Padding:AllowedPad=2 -verify %s
+
+class Empty {}; // no-warning
+
+// expected-warning@+1{{Excessive padding in 'struct NoUniqueAddressWarn1' (6 
padding}}
+struct NoUniqueAddressWarn1 {
+  char c1;
+  [[no_unique_address]] Empty empty;
+  int i;
+  char c2;
+};
+
+// expected-warning@+1{{Excessive padding in 'struct NoUniqueAddressWarn2' (6 
padding}}
+struct NoUniqueAddressWarn2 {
+char c1;
+[[no_unique_address]] Empty e1, e2;
+int i;
+char c2;
+};
+
+struct NoUniqueAddressNoWarn1 {
+  char c1;
+  [[no_unique_address]] Empty empty;
+  char c2;
+};
+
+struct NoUniqueAddressNoWarn2 {
+  char c1;
+  [[no_unique_address]] Empty e1, e2;
+};
Index: clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
@@ -193,6 +193,11 @@
 CharUnits PaddingSum;
 CharUnits Offset = ASTContext.toCharUnitsFromBits(RL.getFieldOffset(0));
 for (const FieldDecl *FD : RD->fields()) {
+  // Skip field that is a subobject of zero size, marked with
+  // [[no_unique_address]] or an empty bitfield, because its address can be
+  // set the same as the other fields addresses.
+  if (FD->isZeroSize(ASTContext))
+continue;
   // This checker only cares about the padded size of the
   // field, and not the data size. If the field is a record
   // with tail padding, then we won't put that number in our
@@ -249,7 +254,7 @@
   RetVal.Field = FD;
   auto &Ctx = FD->getASTContext();
   auto Info = Ctx.getTypeInfoInChars(FD->getType());
-  RetVal.Size = Info.Width;
+  RetVal.Size = FD->isZeroSize(Ctx) ? CharUnits::Zero() : Info.Width;
   RetVal.Align = Info.Align;
   assert(llvm::isPowerOf2_64(RetVal.Align.getQuantity()));
   if (auto Max = FD->getMaxAlignment())


Index: clang/test/Analysis/padding_no_unique_address.cpp
===
--- /dev/null
+++ clang/test/Analysis/padding_no_unique_address.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-linux-gnu -analyzer-checker=optin.performance -analyzer-config optin.performance.Padding:AllowedPad=2 -verify %s
+
+class Empty {}; // no-warning
+
+// expected-warning@+1{{Excessive padding in 'struct NoUniqueAddressWarn1' (6 padding}}
+struct NoUniqueAddressWarn1 {
+  char c1;
+  [[no_unique_address]] Empty empty;
+  int i;
+  char c2;
+};
+
+// expected-warning@+1{{Excessive padding in 'struct NoUniqueAddressWarn2' (6 padding}}
+struct NoUniqueAddressWarn2 {
+char c1;
+[[no_unique_address]] Empty e1, e2;
+int i;
+char c2;
+};
+
+struct NoUniqueAddressNoWarn1 {
+  char c1;
+  [[no_unique_address]] Empty empty;
+  char c2;
+};
+
+struct NoUniqueAddressNoWarn2 {
+  char c1;
+  [[no_unique_address]] Empty e1, e2;
+};
Index: clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp
@@ -193,6 +193,11 @@
 CharUnits PaddingSum;
 CharUnits Offset = ASTContext.toCharUnitsFromBits(RL.getFieldOffset(0));
 for (const FieldDecl *FD : RD->fields()) {
+  // Skip field that is a subobject of zero size, marked with
+  // [[no_unique_address]] or an empty bitfield, because its address can be
+  // set the same as the other fields addresses.
+  if (FD->isZeroSize(ASTContext))
+continue;
   // This checker only cares about the padded size of the
   // field, and not the data size. If the field is a record
   // with tail padding, then we won't put that number in our
@@ -249,7 +254,7 @@
   RetVal.Field = FD;
   auto &Ctx = FD->getASTContext();
   auto Info = Ctx.getTypeInfoInChars(FD->getType());
-  RetVal.Size = Info.Width;
+  RetVal.Size = FD->isZeroSize(Ctx) ? CharUnits::Zero() : Info.Width;
   RetVal.Align = Info.Align;
   assert(llvm::isPowerOf2_64(RetVal.Align.getQuantity()));
   if (auto Max = FD->getMaxAlignment())
__

[clang] a6be6e3 - [flang][driver] Add `-fdebug-dump-all`

2021-06-16 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2021-06-16T07:54:27Z
New Revision: a6be6e31f1810012922e50dab0d4c15cdf990d2e

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

LOG: [flang][driver] Add `-fdebug-dump-all`

The new option will run the semantic checks and then dump the parse tree
and all the symbols. This is equivalent to running the driver twice,
once with `-fdebug-dump-parse-tree` and then with
the `-fdebug-dump-symbols` action flag.

Currently we wouldn't be able to achieve the same by simply running:
```
flang-new -fc1 -fdebug-dump-parse-tree -fdebug-dump-symbols 
```
That's because the new driver will only run one frontend action per
invocation (both of the flags used here are action flags). Diverging
from this design would lead to costly compromises and it's best avoided.

We may want to consider re-designing our debugging actions (and action
options) in the future so that there's more code re-use. For now, I'm
focusing on making sure that we support all the major cases requested by
our users.

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

Added: 
flang/test/Driver/dump-all.f90

Modified: 
clang/include/clang/Driver/Options.td
flang/include/flang/Frontend/FrontendActions.h
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7c6b22c029693..151968de1789e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4523,6 +4523,8 @@ def fdebug_dump_parse_tree_no_sema : Flag<["-"], 
"fdebug-dump-parse-tree-no-sema
   HelpText<"Dump the parse tree (skips the semantic checks)">,
   DocBrief<[{Run the Parser and then output the parse tree. Semantic
 checks are disabled.}]>;
+def fdebug_dump_all : Flag<["-"], "fdebug-dump-all">, Group,
+  HelpText<"Dump symbols and the parse tree after the semantic checks">;
 def fdebug_dump_provenance : Flag<["-"], "fdebug-dump-provenance">, 
Group,
   HelpText<"Dump provenance">;
 def fdebug_dump_parsing_log : Flag<["-"], "fdebug-dump-parsing-log">, 
Group,

diff  --git a/flang/include/flang/Frontend/FrontendActions.h 
b/flang/include/flang/Frontend/FrontendActions.h
index 7a88382075741..72eb44223fe49 100644
--- a/flang/include/flang/Frontend/FrontendActions.h
+++ b/flang/include/flang/Frontend/FrontendActions.h
@@ -116,6 +116,10 @@ class DebugDumpParseTreeAction : public 
PrescanAndSemaAction {
   void ExecuteAction() override;
 };
 
+class DebugDumpAllAction : public PrescanAndSemaAction {
+  void ExecuteAction() override;
+};
+
 class DebugPreFIRTreeAction : public PrescanAndSemaAction {
   void ExecuteAction() override;
 };

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index 9c34abb68f2d6..42ce499566e9f 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -51,6 +51,9 @@ enum ActionKind {
   /// Parse, run semantics and then output the parse tree
   DebugDumpParseTree,
 
+  /// Parse, run semantics and then output the parse tree and symbols
+  DebugDumpAll,
+
   /// Parse and then output the parse tree, skip the semantic checks
   DebugDumpParseTreeNoSema,
 

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index 5098da42dfc0f..dc771ecbc9a8f 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -141,6 +141,9 @@ static bool ParseFrontendArgs(FrontendOptions &opts, 
llvm::opt::ArgList &args,
 case clang::driver::options::OPT_fdebug_dump_parse_tree:
   opts.programAction_ = DebugDumpParseTree;
   break;
+case clang::driver::options::OPT_fdebug_dump_all:
+  opts.programAction_ = DebugDumpAll;
+  break;
 case clang::driver::options::OPT_fdebug_dump_parse_tree_no_sema:
   opts.programAction_ = DebugDumpParseTreeNoSema;
   break;

diff  --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index f4ba515440d9b..d3cce62681cc0 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -305,6 +305,42 @@ void DebugDumpSymbolsAction::ExecuteAction() {
   semantics.DumpSymbols(llvm::outs());
 }
 
+void DebugDumpAllAction::ExecuteAction() {
+  CompilerInstance &ci = this->instance();
+
+  // Dump parse tree
+  auto &parseTree{instance().parsing().parseTree()};
+  Fortran::parser::AnalyzedObjectsAsFortran asFortran =
+  Fortran::frontend::getBasicAsFortran();
+  llvm::outs() <

[PATCH] D104305: [flang][driver] Add `-fdebug-dump-all`

2021-06-16 Thread Andrzej Warzynski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa6be6e31f181: [flang][driver] Add `-fdebug-dump-all` 
(authored by awarzynski).

Changed prior to commit:
  https://reviews.llvm.org/D104305?vs=352234&id=352364#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104305

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/FrontendActions.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/dump-all.f90

Index: flang/test/Driver/dump-all.f90
===
--- /dev/null
+++ flang/test/Driver/dump-all.f90
@@ -0,0 +1,17 @@
+!--
+! RUN lines
+!--
+! RUN: %flang_fc1 -fdebug-dump-all %s 2>&1 | FileCheck %s
+
+!
+! EXPECTED OUTPUT
+!
+! CHECK: Flang: parse tree dump
+! CHECK: Flang: symbols dump
+
+!---
+! INPUT
+!---
+parameter(i=1)
+integer :: j
+end program
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -69,6 +69,7 @@
 ! HELP-FC1-NEXT: -falternative-parameter-statement
 ! HELP-FC1-NEXT: Enable the old style PARAMETER statement
 ! HELP-FC1-NEXT: -fbackslashSpecify that backslash in string introduces an escape character
+! HELP-FC1-NEXT: -fdebug-dump-all   Dump symbols and the parse tree after the semantic checks
 ! HELP-FC1-NEXT: -fdebug-dump-parse-tree-no-sema
 ! HELP-FC1-NEXT:Dump the parse tree (skips the semantic checks)
 ! HELP-FC1-NEXT: -fdebug-dump-parse-tree Dump the parse tree
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -55,6 +55,9 @@
   case DebugDumpParseTreeNoSema:
 return std::make_unique();
 break;
+  case DebugDumpAll:
+return std::make_unique();
+break;
   case DebugDumpProvenance:
 return std::make_unique();
 break;
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -305,6 +305,42 @@
   semantics.DumpSymbols(llvm::outs());
 }
 
+void DebugDumpAllAction::ExecuteAction() {
+  CompilerInstance &ci = this->instance();
+
+  // Dump parse tree
+  auto &parseTree{instance().parsing().parseTree()};
+  Fortran::parser::AnalyzedObjectsAsFortran asFortran =
+  Fortran::frontend::getBasicAsFortran();
+  llvm::outs() << "";
+  llvm::outs() << " Flang: parse tree dump ";
+  llvm::outs() << "\n";
+  Fortran::parser::DumpTree(llvm::outs(), parseTree, &asFortran);
+
+  auto &semantics = this->semantics();
+  auto tables{Fortran::semantics::BuildRuntimeDerivedTypeTables(
+  instance().invocation().semanticsContext())};
+  // The runtime derived type information table builder may find and report
+  // semantic errors. So it is important that we report them _after_
+  // BuildRuntimeDerivedTypeTables is run.
+  reportFatalSemanticErrors(
+  semantics, this->instance().diagnostics(), GetCurrentFileOrBufferName());
+
+  if (!tables.schemata) {
+unsigned DiagID =
+ci.diagnostics().getCustomDiagID(clang::DiagnosticsEngine::Error,
+"could not find module file for __fortran_type_info");
+ci.diagnostics().Report(DiagID);
+llvm::errs() << "\n";
+  }
+
+  // Dump symbols
+  llvm::outs() << "=";
+  llvm::outs() << " Flang: symbols dump ";
+  llvm::outs() << "=\n";
+  semantics.DumpSymbols(llvm::outs());
+}
+
 void DebugDumpParseTreeNoSemaAction::ExecuteAction() {
   auto &parseTree{instance().parsing().parseTree()};
   Fortran::parser::AnalyzedObjectsAsFortran asFortran =
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -141,6 +141,9 @@
 case clang::driver::options::OPT_fdebug_dump_parse_tree:
   opts.programAction_ = DebugDumpParseTree;
   break;
+case clang::driver::options::OPT_fdebug_dump_all:
+  opts.programAction_ = DebugDumpAll;
+  break;
 case clang::driver::options::OPT_fdebug_dump_parse_tree_no_sema:
   opts.programAction_ = DebugDumpParseTreeNoSema;
   break;
Index: flang/include/flang/Frontend/FrontendOptions.h
===
--- flang/inclu

[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-16 Thread Christophe Calmejane via Phabricator via cfe-commits
christophe-calmejane added a comment.

In D104222#2819403 , @MyDeveloperDay 
wrote:

> @christophe-calmejane are you able to post your .clang-format styles that you 
> are using, I'm struggling to see where its not matching your style (other 
> than brace styles on the function and argument placing)

Of course, sorry for the delay, here it is: 
https://github.com/christophe-calmejane/Hive/blob/master/.clang-format


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

https://reviews.llvm.org/D104222

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


[PATCH] D104275: [compiler-rt][hwasan] Add GetShadowOffset function

2021-06-16 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr added inline comments.



Comment at: compiler-rt/lib/hwasan/hwasan_mapping.h:54
+inline uptr GetShadowOffset() {
+  return SANITIZER_FUCHSIA ? 0 : __hwasan_shadow_memory_dynamic_address;
+}

vitalybuka wrote:
> mcgrathr wrote:
> > I think you'll eventually need to make this an `#if` or `if constexpr` for 
> > it to be kosher that the symbol isn't defined at all, which is what we'd 
> > ideally like to have on Fuchsia.
> static inline?
Plain inline has correct semantics here, and is consistent with the existing 
functions below.
static inside namespace scope in a header is a strange thing to do.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104275

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.



> @MyDeveloperDay 
> Of course, sorry for the delay, here it is: 
> https://github.com/christophe-calmejane/Hive/blob/master/.clang-format

You don't have `AllowShortLambdasOnASingleLine` set to be `false` or `None`

If you did The only difference (with this current patch) would be the 
positioning of the first arguments on `paramBeforeAndAfterLambda` and 
`doubleLambda` (I'm not sure the reason for why that is)

F17423148: image.png 


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

https://reviews.llvm.org/D104222

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


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-16 Thread Christophe Calmejane via Phabricator via cfe-commits
christophe-calmejane added a comment.

In D104222#2821375 , @MyDeveloperDay 
wrote:

>> @MyDeveloperDay 
>> Of course, sorry for the delay, here it is: 
>> https://github.com/christophe-calmejane/Hive/blob/master/.clang-format
>
> You don't have `AllowShortLambdasOnASingleLine` set to be `false` or `None`

Just a clarification, this file is meant to be used with clang-format v7.0.0 
along with my small patch fixing formatting issues that were not included in 
the original merge (see the other post). This means it's using the defaults 
from back then ;)
I never had a chance to upgrade clang-format because lambda formatting was 
broken (some of my test cases were failing). I will try to build your latest 
patch and see how it goes. I would expect my project re-formatting to not 
change much :D
Thanks for your work btw.


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

https://reviews.llvm.org/D104222

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


[PATCH] D104275: [compiler-rt][hwasan] Add GetShadowOffset function

2021-06-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: compiler-rt/lib/hwasan/hwasan_mapping.h:54
+inline uptr GetShadowOffset() {
+  return SANITIZER_FUCHSIA ? 0 : __hwasan_shadow_memory_dynamic_address;
+}

mcgrathr wrote:
> vitalybuka wrote:
> > mcgrathr wrote:
> > > I think you'll eventually need to make this an `#if` or `if constexpr` 
> > > for it to be kosher that the symbol isn't defined at all, which is what 
> > > we'd ideally like to have on Fuchsia.
> > static inline?
> Plain inline has correct semantics here, and is consistent with the existing 
> functions below.
> static inside namespace scope in a header is a strange thing to do.
that's exactly the point: inline and no exported symbol
you can find many of then in llvm headers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104275

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


[PATCH] D103440: [WIP][analyzer] Introduce range-based reasoning for addition operator

2021-06-16 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1397
+(LHS.To() < 0 && RHS.To() < 0 && Max > 0) ||
+(LHS.To() < 0 && RHS.To() < 0 && Max > 0)) {
+  return {RangeFactory, Tmin, Tmax};

This clause is exactly the same as the previous one, it is a mistake.
And I think we should have a test that could've shown that.
Also, since you are checking for overflows for both the beginning and the end, 
we should have tests where both overflow.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1401-1402
+
+// FIXME: This case in particular is resulting in failed assertion.
+Range First = Range(Tmin, Max);
+Range Second = Range(Min, Tmax);

manas wrote:
> I changed the logic from using getCrucialPoints (which I mentioned in the 
> e-mail thread) to simple checks to determine overflows using signedness. But 
> the failed assertions again popped up. And I was unable to pin-point the 
> issue here. Can someone help me?
> 
> Although, I am thinking of revising the above logic by using bitwise methods 
> to detect overflows.
This is actually one place that I won't expect an assertion failure.
Can we get a bit more detail on it?  Is it again `From > To` (which will indeed 
be weird) or something different?

NOTE: Asking for help (either here or on StackOverflow) is a lot like filing a 
bug report, try to put as much information as possible, try to structure this 
information so it is easy to follow.  It's also good to tell people what you 
tried, instead of saying that you tried something and it didn't work.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1409-1415
+  if ((LHS.From() > 0 && RHS.From() > 0 && Min < 0) ||
+  (LHS.From() < 0 && RHS.From() < 0 && Min > 0) ||
+  (LHS.To() > 0 && RHS.To() > 0 && Max < 0) ||
+  (LHS.To() < 0 && RHS.To() < 0 && Max > 0)) {
+// return [Tmin, Tmax]
+return {RangeFactory, Tmin, Tmax};
+  }

I thought we talked quite a lot that there is nothing bad with overflows and 
here we have that if ANY overflow happened, we bail out and don't give any 
result.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103440

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


[PATCH] D102492: [clang][AST] Add support for BindingDecl to ASTImporter.

2021-06-16 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 352372.
balazske added a comment.

Using `addDeclToContexts`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102492

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

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3665,6 +3665,52 @@
   EXPECT_TRUE(ImportedD->getDefinition());
 }
 
+TEST_P(ImportVariables, ImportBindingDecl) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"(
+  void declToImport() {
+int a[2] = {1,2};
+auto [x1,y1] = a;
+auto& [x2,y2] = a;
+
+struct S {
+  mutable int x1 : 2;
+  volatile double y1;
+};
+S b;
+const auto [x3, y3] = b;
+  };
+  )",
+  Lang_CXX17, "", Lang_CXX17);
+
+  TranslationUnitDecl *FromTU = From->getTranslationUnitDecl();
+  auto *FromF = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("declToImport")));
+  auto *ToF = Import(FromF, Lang_CXX17);
+  EXPECT_TRUE(ToF);
+
+  auto VerifyImport = [&](llvm::StringRef BindName) {
+auto *FromB = FirstDeclMatcher().match(
+FromF, bindingDecl(hasName(BindName)));
+ASSERT_TRUE(FromB);
+auto *ToB = Import(FromB, Lang_CXX17);
+EXPECT_TRUE(ToB);
+EXPECT_EQ(FromB->getBinding() != nullptr, ToB->getBinding() != nullptr);
+EXPECT_EQ(FromB->getDecomposedDecl() != nullptr,
+  ToB->getDecomposedDecl() != nullptr);
+EXPECT_EQ(FromB->getHoldingVar() != nullptr,
+  ToB->getHoldingVar() != nullptr);
+  };
+
+  VerifyImport("x1");
+  VerifyImport("y1");
+  VerifyImport("x2");
+  VerifyImport("y2");
+  VerifyImport("x3");
+  VerifyImport("y3");
+}
+
 struct ImportClasses : ASTImporterOptionSpecificTestBase {};
 
 TEST_P(ImportClasses, ImportDefinitionWhenProtoIsInNestedToContext) {
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -481,6 +481,7 @@
 ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D);
 ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D);
 ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D);
+ExpectedDecl VisitBindingDecl(BindingDecl *D);
 ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D);
 ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
 ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias);
@@ -2274,6 +2275,35 @@
   return ToD;
 }
 
+ExpectedDecl ASTNodeImporter::VisitBindingDecl(BindingDecl *D) {
+  DeclContext *DC, *LexicalDC;
+  DeclarationName Name;
+  SourceLocation Loc;
+  NamedDecl *ToND;
+  if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
+return std::move(Err);
+  if (ToND)
+return ToND;
+
+  Error Err = Error::success();
+  auto ToType = importChecked(Err, D->getType());
+  auto ToBinding = importChecked(Err, D->getBinding());
+  auto ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
+  if (Err)
+return std::move(Err);
+
+  BindingDecl *ToD;
+  if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
+  Name.getAsIdentifierInfo()))
+return ToD;
+
+  ToD->setBinding(ToType, ToBinding);
+  ToD->setDecomposedDecl(ToDecomposedDecl);
+  addDeclToContexts(D, ToD);
+
+  return ToD;
+}
+
 ExpectedDecl ASTNodeImporter::VisitAccessSpecDecl(AccessSpecDecl *D) {
   ExpectedSLoc LocOrErr = import(D->getLocation());
   if (!LocOrErr)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104222: [clang-format] [PR50702] Lamdba processing does not respect AfterClass and AfterNamespace

2021-06-16 Thread Christophe Calmejane via Phabricator via cfe-commits
christophe-calmejane added a comment.

> If you did The only difference (with this current patch) would be the 
> positioning of the first arguments on `paramBeforeAndAfterLambda` and 
> `doubleLambda` (I'm not sure the reason for why that is)

@MyDeveloperDay The reason is the fix I talked about in the other thread 
(https://reviews.llvm.org/D44609) that I proposed for LLVM 7.0.0. But last time 
I checked, my patch couldn't be applied anymore due to massive changes in the 
code. I don't have enough knowledge of clang-format to clearly follow where 
went the code my patch applies to, I originally fixed the issue blindly by 
stepping into the code :)
Nevertheless, I think the issue is still present (since my patch was not 
applied to the base code) and it might still be related to this reason. See my 
comment that fixed the issue back then 
(https://reviews.llvm.org/D44609#1255395).

It would be really awesome if this could finally be fixed so we have a 
consistent formatting for lambdas!


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

https://reviews.llvm.org/D104222

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


[PATCH] D103440: [WIP][analyzer] Introduce range-based reasoning for addition operator

2021-06-16 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1401-1402
+
+// FIXME: This case in particular is resulting in failed assertion.
+Range First = Range(Tmin, Max);
+Range Second = Range(Min, Tmax);

vsavchenko wrote:
> manas wrote:
> > I changed the logic from using getCrucialPoints (which I mentioned in the 
> > e-mail thread) to simple checks to determine overflows using signedness. 
> > But the failed assertions again popped up. And I was unable to pin-point 
> > the issue here. Can someone help me?
> > 
> > Although, I am thinking of revising the above logic by using bitwise 
> > methods to detect overflows.
> This is actually one place that I won't expect an assertion failure.
> Can we get a bit more detail on it?  Is it again `From > To` (which will 
> indeed be weird) or something different?
> 
> NOTE: Asking for help (either here or on StackOverflow) is a lot like filing 
> a bug report, try to put as much information as possible, try to structure 
> this information so it is easy to follow.  It's also good to tell people what 
> you tried, instead of saying that you tried something and it didn't work.
OK, I downloaded your patch and ran the debugger.

It complains about different bit-width for ranges that the analyzer tries to 
intersect.  What I checked next: what are those ranges, so I took `begin()` 
from one of them and checked what are `From` and `To` there.
Here is one of them:
```
(const llvm::APSInt) $8 = {
  llvm::APInt = {
U = {
  VAL = 22
  pVal = 0x0016
}
BitWidth = 4022311424
  }
  IsUnsigned = true
}
```
Woah, this `BitWidth` seems ridiculous!  What does it tell us?  It definitely 
didn't get there as part of any reasonable logic, right?  So, what can it be 
instead?  Only one answer here - garbage.  We have some sort of memory issue 
with integers that we use as part of our ranges!  So, let's see what type of 
information `Range` class actually stores:
```
class Range {
public:
  Range(const llvm::APSInt &From, const llvm::APSInt &To) : Impl(&From, &To) {
assert(From <= To);
  }

...

private:
  std::pair Impl;
};
```

What we have here is a pair of pointers, and you have:
```
  llvm::APSInt Min = LHS.From() + RHS.From();
  llvm::APSInt Max = LHS.To() + RHS.To();
  llvm::APSInt Tmin = ValueFactory.getMinValue(ResultType);
  llvm::APSInt Tmax = ValueFactory.getMaxValue(ResultType);
```
These are ALL stack variables. So, pointer to those point to adequate data ONLY 
while we are inside of our functions.  When we call another function, these 
pointers point into some data from some other function in the call stack, it 
doesn't point to anything even remotely resembling `llvm::APSInt` and we get 
`BitWidth = 4022311424`.

OK, we figured out the problem, what about a solution?  If you look at other 
implementations, you can notice a couple of interesting things.
When you do:
```
llvm::APSInt Tmin = ValueFactory.getMinValue(ResultType);
```
other code does something like:
```
const llvm::APSInt &Tmin = ValueFactory.getMinValue(ResultType);
```
Or when you do:
```
Range Second = Range(Min, Tmax);
```
The sibling code does:
```
return {RangeFactory, ValueFactory.getValue(Min), ValueFactory.getValue(Max)};
```

It looks like `ValueFactory` is the key here!  It actually manages the lifetime 
of those integers for you and, whenever you ask it about values, it gives you 
`llvm::APSInt &` (note the reference part) that will have the correct lifetime.

I hope this gives you some insight into how you can debug things like this on 
your own and how you can reason about what you see.

Another piece of advice is to look around, other `VisitBinaryOperator` methods 
have all the information you actually needed.  If you don't understand why we 
need `ValueFactory`, - experiment, ask us!  It's bad to just ignore it.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1405-1406
+RangeSet ResultRangeSet = RangeFactory.getRangeSet(First);
+RangeSet ResultRangeSet2 = RangeFactory.add(ResultRangeSet, Second);
+return ResultRangeSet2;
+  }

Why not just `return RangeFactory.add(ResultRangeSet, Second)`?

NOTE: variables with integers in their names is a big no-no.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103440

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


[PATCH] D103096: [analyzer] Implement cast for ranges of symbolic integers.

2021-06-16 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

What about this patch?


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

https://reviews.llvm.org/D103096

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


[PATCH] D104291: [Debug-Info] strict dwarf for DW_LANG_C_plus_plus_14

2021-06-16 Thread ChenZheng via Phabricator via cfe-commits
shchenz added a comment.

Thanks for review @stuart

In D104291#2819398 , @stuart wrote:

> This looks good to me.
>
> @jzzheng22 informs me there was a comment in D99250 
>  to the effect that DW_LANG_C_plus_plus_03 
> is not emitted, at all - it too was introduced in DWARF 5.  I wonder if this 
> should be addressed in a separate commit?

Yes, this was noticed when D99250  was posted. 
There is no `CPlusPlus03` in `LangOptions`, so it is better not to merge 
`DW_LANG_C_plus_plus_03` support with D99250 .

> As mentioned in D104118 , there are 
> language codes of DW_LANG_C_plus_plus_17 and DW_LANG_C_plus_plus_20 that will 
> be introduced in DWARF 6, which it would be good to use in non-strict mode.  
> This would allow us to emit the more proper code of DW_LANG_C_plus_plus_17 
> (instead of DW_LANG_C_plus_plus_14) for //C++ for OpenCL//, while we wait for 
> DW_LANG_CPP_for_OpenCL to get added, as requested at 
> http://dwarfstd.org/ShowIssue.php?issue=210514.1.  Should this be addressed 
> in a third commit?

Yes, we don't have `DW_LANG_C_plus_plus_17` and `DW_LANG_C_plus_plus_20` in 
clang for now. I guess this is because clang does not support DWRAF 6. DWARF 6 
is not officially released? Once DWARF 6 is released and clang starts to 
support DWARF 6, I think we should add the support for `DW_LANG_C_plus_plus_17` 
and `DW_LANG_C_plus_plus_20` in the place that this patch changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104291

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


[PATCH] D104291: [Debug-Info] strict dwarf for DW_LANG_C_plus_plus_14

2021-06-16 Thread ChenZheng 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 rG4590b406c02e: [Debug-Info] guard DW_LANG_C_plus_plus_14 
under strict dwarf (authored by shchenz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104291

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/debug-info-programming-language.cpp


Index: clang/test/CodeGenCXX/debug-info-programming-language.cpp
===
--- clang/test/CodeGenCXX/debug-info-programming-language.cpp
+++ clang/test/CodeGenCXX/debug-info-programming-language.cpp
@@ -1,13 +1,18 @@
-// RUN: %clang_cc1 -dwarf-version=5  -emit-llvm -triple %itanium_abi_triple %s 
-o - \
+// RUN: %clang_cc1 -dwarf-version=5 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
 // RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
-// RUN: | FileCheck --check-prefix=CHECK-DWARF5 %s
-// RUN: %clang_cc1 -dwarf-version=3  -emit-llvm -triple %itanium_abi_triple %s 
-o - \
+// RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
+// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s 
-o - \
 // RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
-// RUN: | FileCheck --check-prefix=CHECK-DWARF3 %s
+// RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
+// RUN: %clang_cc1 -dwarf-version=3 -gstrict-dwarf -emit-llvm -triple 
%itanium_abi_triple %s -o - \
+// RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited 
| FileCheck %s
+// RUN: %clang_cc1 -dwarf-version=5 -gstrict-dwarf -emit-llvm -triple 
%itanium_abi_triple %s -o - \
+// RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
 
 int main() {
   return 0;
 }
 
-// CHECK-DWARF5: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14,
-// CHECK-DWARF3: distinct !DICompileUnit(language: DW_LANG_C_plus_plus,
+// CHECK-CPP14: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14,
+// CHECK: distinct !DICompileUnit(language: DW_LANG_C_plus_plus,
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -568,9 +568,11 @@
   if (LO.CPlusPlus) {
 if (LO.ObjC)
   LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
-else if (LO.CPlusPlus14 && CGM.getCodeGenOpts().DwarfVersion >= 5)
+else if (LO.CPlusPlus14 && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
+CGM.getCodeGenOpts().DwarfVersion >= 5))
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
-else if (LO.CPlusPlus11 && CGM.getCodeGenOpts().DwarfVersion >= 5)
+else if (LO.CPlusPlus11 && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
+CGM.getCodeGenOpts().DwarfVersion >= 5))
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
 else
   LangTag = llvm::dwarf::DW_LANG_C_plus_plus;


Index: clang/test/CodeGenCXX/debug-info-programming-language.cpp
===
--- clang/test/CodeGenCXX/debug-info-programming-language.cpp
+++ clang/test/CodeGenCXX/debug-info-programming-language.cpp
@@ -1,13 +1,18 @@
-// RUN: %clang_cc1 -dwarf-version=5  -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN: %clang_cc1 -dwarf-version=5 -emit-llvm -triple %itanium_abi_triple %s -o - \
 // RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
-// RUN: | FileCheck --check-prefix=CHECK-DWARF5 %s
-// RUN: %clang_cc1 -dwarf-version=3  -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
+// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \
 // RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
-// RUN: | FileCheck --check-prefix=CHECK-DWARF3 %s
+// RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
+// RUN: %clang_cc1 -dwarf-version=3 -gstrict-dwarf -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited | FileCheck %s
+// RUN: %clang_cc1 -dwarf-version=5 -gstrict-dwarf -emit-llvm -triple %itanium_abi_triple %s -o - \
+// RUN:   -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
+// RUN:   | FileCheck --check-prefix=CHECK-CPP14 %s
 
 int main() {
   return 0;
 }
 
-// CHECK-DWARF5: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14,
-// CHECK-DWARF3: distinct !DICompileUnit(language: DW_LANG_C_plus_plus,
+// CHECK-CPP14: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14,
+// CHECK: distinct !DICompileUnit(language: DW_LANG_C_plus_plus,
Index: clang/lib/CodeGen/CGDebugInfo.cpp
=

[PATCH] D104291: [Debug-Info] strict dwarf for DW_LANG_C_plus_plus_14

2021-06-16 Thread Stuart Brady via Phabricator via cfe-commits
stuart added a comment.

> There is no `CPlusPlus03` in `LangOptions`, so it is better not to merge 
> `DW_LANG_C_plus_plus_03` support with D99250 
> .

Oh - I see, `c++03` is defined in LangStandards.def an alias for `c++98`, as 
the former essentially consists of bugfixes for the latter. This loosely 
suggests to me that C++03 implementations are (likely to be / mostly?) 
conformant to C++98, but that C++98 implementations may not be fully conformant 
to C++03. Given this alias, it doesn't seem at all clear to me which of 
DW_LANG_C_plus_plus_98 and DW_LANG_C_plus_plus_03 would be the better choice, 
if both C++98 and C++03 must share a language tag... but I presume this has 
been discussed before. (It also doesn't seem clear whether it would be better 
to model "c++98" as an alias for "c++03".)

> Yes, we don't have `DW_LANG_C_plus_plus_17` and `DW_LANG_C_plus_plus_20` in 
> clang for now. I guess this is because clang does not support DWARF 6. DWARF 
> 6 is not officially released? Once DWARF 6 is released and clang starts to 
> support DWARF 6, I think we should add the support for 
> `DW_LANG_C_plus_plus_17` and `DW_LANG_C_plus_plus_20` in the place that this 
> patch changes.

New DWARF language codes  are published 
ahead of the release of the next version of DWARF, so that they may be used by 
implementations without having to wait for new DWARF version.

It would therefore make sense to go ahead and add `DW_LANG_C_plus_plus_17` and 
`DW_LANG_C_plus_plus_20` now, without waiting, but only in the non-strict DWARF 
mode. (There would be the question of whether it would still make sense in the 
code to say "DwarfVersion >= 6" given that DWARF 6 would be otherwise 
unsupported... but I don't have a strong view on that question.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104291

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


[PATCH] D103440: [WIP][analyzer] Introduce range-based reasoning for addition operator

2021-06-16 Thread Manas Gupta via Phabricator via cfe-commits
manas added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1397
+(LHS.To() < 0 && RHS.To() < 0 && Max > 0) ||
+(LHS.To() < 0 && RHS.To() < 0 && Max > 0)) {
+  return {RangeFactory, Tmin, Tmax};

vsavchenko wrote:
> This clause is exactly the same as the previous one, it is a mistake.
> And I think we should have a test that could've shown that.
> Also, since you are checking for overflows for both the beginning and the 
> end, we should have tests where both overflow.
Understood! I will add tests to check each OR part of these conditionals in 
these cases.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1401-1402
+
+// FIXME: This case in particular is resulting in failed assertion.
+Range First = Range(Tmin, Max);
+Range Second = Range(Min, Tmax);

vsavchenko wrote:
> vsavchenko wrote:
> > manas wrote:
> > > I changed the logic from using getCrucialPoints (which I mentioned in the 
> > > e-mail thread) to simple checks to determine overflows using signedness. 
> > > But the failed assertions again popped up. And I was unable to pin-point 
> > > the issue here. Can someone help me?
> > > 
> > > Although, I am thinking of revising the above logic by using bitwise 
> > > methods to detect overflows.
> > This is actually one place that I won't expect an assertion failure.
> > Can we get a bit more detail on it?  Is it again `From > To` (which will 
> > indeed be weird) or something different?
> > 
> > NOTE: Asking for help (either here or on StackOverflow) is a lot like 
> > filing a bug report, try to put as much information as possible, try to 
> > structure this information so it is easy to follow.  It's also good to tell 
> > people what you tried, instead of saying that you tried something and it 
> > didn't work.
> OK, I downloaded your patch and ran the debugger.
> 
> It complains about different bit-width for ranges that the analyzer tries to 
> intersect.  What I checked next: what are those ranges, so I took `begin()` 
> from one of them and checked what are `From` and `To` there.
> Here is one of them:
> ```
> (const llvm::APSInt) $8 = {
>   llvm::APInt = {
> U = {
>   VAL = 22
>   pVal = 0x0016
> }
> BitWidth = 4022311424
>   }
>   IsUnsigned = true
> }
> ```
> Woah, this `BitWidth` seems ridiculous!  What does it tell us?  It definitely 
> didn't get there as part of any reasonable logic, right?  So, what can it be 
> instead?  Only one answer here - garbage.  We have some sort of memory issue 
> with integers that we use as part of our ranges!  So, let's see what type of 
> information `Range` class actually stores:
> ```
> class Range {
> public:
>   Range(const llvm::APSInt &From, const llvm::APSInt &To) : Impl(&From, &To) {
> assert(From <= To);
>   }
> 
> ...
> 
> private:
>   std::pair Impl;
> };
> ```
> 
> What we have here is a pair of pointers, and you have:
> ```
>   llvm::APSInt Min = LHS.From() + RHS.From();
>   llvm::APSInt Max = LHS.To() + RHS.To();
>   llvm::APSInt Tmin = ValueFactory.getMinValue(ResultType);
>   llvm::APSInt Tmax = ValueFactory.getMaxValue(ResultType);
> ```
> These are ALL stack variables. So, pointer to those point to adequate data 
> ONLY while we are inside of our functions.  When we call another function, 
> these pointers point into some data from some other function in the call 
> stack, it doesn't point to anything even remotely resembling `llvm::APSInt` 
> and we get `BitWidth = 4022311424`.
> 
> OK, we figured out the problem, what about a solution?  If you look at other 
> implementations, you can notice a couple of interesting things.
> When you do:
> ```
> llvm::APSInt Tmin = ValueFactory.getMinValue(ResultType);
> ```
> other code does something like:
> ```
> const llvm::APSInt &Tmin = ValueFactory.getMinValue(ResultType);
> ```
> Or when you do:
> ```
> Range Second = Range(Min, Tmax);
> ```
> The sibling code does:
> ```
> return {RangeFactory, ValueFactory.getValue(Min), ValueFactory.getValue(Max)};
> ```
> 
> It looks like `ValueFactory` is the key here!  It actually manages the 
> lifetime of those integers for you and, whenever you ask it about values, it 
> gives you `llvm::APSInt &` (note the reference part) that will have the 
> correct lifetime.
> 
> I hope this gives you some insight into how you can debug things like this on 
> your own and how you can reason about what you see.
> 
> Another piece of advice is to look around, other `VisitBinaryOperator` 
> methods have all the information you actually needed.  If you don't 
> understand why we need `ValueFactory`, - experiment, ask us!  It's bad to 
> just ignore it.
Got it! I am working on fixing this. 



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1405-1406
+RangeSet ResultRangeSet = RangeFactory.getRangeSet(First);
+RangeSet ResultRangeSet2 =

[PATCH] D97085: [OpenMP] libomp: implement OpenMP 5.1 inoutset task dependence type

2021-06-16 Thread Andrey Churbanov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG610fea65e296: [OpenMP] libomp: fixed implementation of OMP 
5.1 inoutset task dependence type (authored by AndreyChurbanov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97085

Files:
  openmp/runtime/src/kmp.h
  openmp/runtime/src/kmp_taskdeps.cpp
  openmp/runtime/src/kmp_taskdeps.h
  openmp/runtime/test/tasking/hidden_helper_task/common.h
  openmp/runtime/test/tasking/hidden_helper_task/depend.cpp
  openmp/runtime/test/tasking/hidden_helper_task/gtid.cpp
  openmp/runtime/test/tasking/omp51_task_dep_inoutset.c

Index: openmp/runtime/test/tasking/omp51_task_dep_inoutset.c
===
--- /dev/null
+++ openmp/runtime/test/tasking/omp51_task_dep_inoutset.c
@@ -0,0 +1,258 @@
+// RUN: %libomp-compile-and-run
+// RUN: %libomp-cxx-compile-and-run
+// UNSUPPORTED: gcc
+
+// Tests OMP 5.0 task dependences "mutexinoutset" and 5.1 "inoutset",
+// emulates compiler codegen for new dep kinds
+// Mutually exclusive tasks get same input dependency info array
+//
+// Task tree created:
+//  task0 - task1 (in)
+// \
+//task2 - task3 (inoutset)
+// /
+//  task3 - task4 (in)
+//   /
+//  task6 <-->task7  (mutexinoutset)
+//   \/
+//   task8 (in)
+//
+#include 
+#include 
+
+#ifdef _WIN32
+#include 
+#define mysleep(n) Sleep(n)
+#else
+#include 
+#define mysleep(n) usleep((n)*1000)
+#endif
+
+// to check the # of concurrent tasks (must be 1 for MTX, <3 for other kinds)
+static int volatile checker = 0;
+static int err = 0;
+#ifndef DELAY
+#define DELAY 100
+#endif
+
+// ---
+// internal data to emulate compiler codegen
+typedef struct DEP {
+  size_t addr;
+  size_t len;
+  unsigned char flags;
+} dep;
+typedef struct task {
+  void** shareds;
+  void* entry;
+  int part_id;
+  void* destr_thunk;
+  int priority;
+  long long device_id;
+  int f_priv;
+} task_t;
+#define TIED 1
+typedef int(*entry_t)(int, task_t*);
+typedef struct ID {
+  int reserved_1;
+  int flags;
+  int reserved_2;
+  int reserved_3;
+  char *psource;
+} id;
+// thunk routine for tasks with MTX dependency
+int thunk_m(int gtid, task_t* ptask) {
+  int th = omp_get_thread_num();
+  #pragma omp atomic
+++checker;
+  printf("task _%d, th %d\n", ptask->f_priv, th);
+  if (checker != 1) { // no more than 1 task at a time
+err++;
+printf("Error1, checker %d != 1\n", checker);
+  }
+  mysleep(DELAY);
+  if (checker != 1) { // no more than 1 task at a time
+err++;
+printf("Error2, checker %d != 1\n", checker);
+  }
+  #pragma omp atomic
+--checker;
+  return 0;
+}
+// thunk routine for tasks with inoutset dependency
+int thunk_s(int gtid, task_t* ptask) {
+  int th = omp_get_thread_num();
+  #pragma omp atomic
+++checker;
+  printf("task _%d, th %d\n", ptask->f_priv, th);
+  if (checker > 2) { // no more than 2 tasks concurrently
+err++;
+printf("Error1, checker %d > 2\n", checker);
+  }
+  mysleep(DELAY);
+  if (checker > 2) { // no more than 2 tasks concurrently
+err++;
+printf("Error2, checker %d > 2\n", checker);
+  }
+  #pragma omp atomic
+--checker;
+  return 0;
+}
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+int __kmpc_global_thread_num(id*);
+extern task_t* __kmpc_omp_task_alloc(id *loc, int gtid, int flags,
+ size_t sz, size_t shar, entry_t rtn);
+int
+__kmpc_omp_task_with_deps(id *loc, int gtid, task_t *task, int nd, dep *dep_lst,
+  int nd_noalias, dep *noalias_dep_lst);
+static id loc = {0, 2, 0, 0, ";file;func;0;0;;"};
+#ifdef __cplusplus
+} // extern "C"
+#endif
+// End of internal data
+// ---
+
+int main()
+{
+  int i1,i2,i3;
+  omp_set_num_threads(4);
+  omp_set_dynamic(0);
+  #pragma omp parallel
+  {
+#pragma omp single nowait
+{
+  dep sdep[2];
+  task_t *ptr;
+  int gtid = __kmpc_global_thread_num(&loc);
+  int t = omp_get_thread_num();
+  #pragma omp task depend(in: i1, i2)
+  { int th = omp_get_thread_num();
+printf("task 0_%d, th %d\n", t, th);
+#pragma omp atomic
+  ++checker;
+if (checker > 2) { // no more than 2 tasks concurrently
+  err++;
+  printf("Error1, checker %d > 2\n", checker);
+}
+mysleep(DELAY);
+if (checker > 2) { // no more than 2 tasks concurrently
+  err++;
+  printf("Error1, checker %d > 2\n", checker);
+}
+#pragma omp atomic
+  --checker;
+  }
+  #pragma omp task depend(in: i1, i2)
+  { int th = omp_get_thread_num();
+printf("task 1_%d, th %d\n", t, th);
+#pragma omp atomic
+  ++checker;
+if (ch

[PATCH] D102186: [clang][c++20] Fix false warning for unused private fields when a class has only defaulted comparison operators.

2021-06-16 Thread Alexandru Octavian Buțiu via Phabricator via cfe-commits
predator5047 updated this revision to Diff 352400.
predator5047 added a comment.

Updated the test case so it is clearer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102186

Files:
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/SemaCXX/warn-unused-private-field.cpp


Index: clang/test/SemaCXX/warn-unused-private-field.cpp
===
--- clang/test/SemaCXX/warn-unused-private-field.cpp
+++ clang/test/SemaCXX/warn-unused-private-field.cpp
@@ -1,5 +1,26 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunused-private-field 
-Wused-but-marked-unused -Wno-uninitialized -verify -std=c++11 %s
 // RUN: %clang_cc1 -fsyntax-only -Wunused-private-field 
-Wused-but-marked-unused -Wno-uninitialized -verify -std=c++17 %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-private-field 
-Wused-but-marked-unused -Wno-uninitialized -verify -std=c++20 %s
+
+#if __cplusplus >= 202002L
+
+class EqDefaultCompare {
+  int used;
+
+public:
+  EqDefaultCompare(int x) : used(x) {}
+  bool operator==(const EqDefaultCompare &) const = default;
+};
+
+class SpaceShipDefaultCompare {
+  int used;
+
+public:
+  SpaceShipDefaultCompare(int x) : used(x) {}
+  int operator<=>(const SpaceShipDefaultCompare &) const = default;
+};
+
+#endif
 
 class NotFullyDefined {
  public:
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -7292,6 +7292,9 @@
 return;
   }
 
+  if (DefKind.isComparison())
+UnusedPrivateFields.clear();
+
   if (DefKind.isSpecialMember()
   ? CheckExplicitlyDefaultedSpecialMember(cast(FD),
   DefKind.asSpecialMember())


Index: clang/test/SemaCXX/warn-unused-private-field.cpp
===
--- clang/test/SemaCXX/warn-unused-private-field.cpp
+++ clang/test/SemaCXX/warn-unused-private-field.cpp
@@ -1,5 +1,26 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++11 %s
 // RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++17 %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused-private-field -Wused-but-marked-unused -Wno-uninitialized -verify -std=c++20 %s
+
+#if __cplusplus >= 202002L
+
+class EqDefaultCompare {
+  int used;
+
+public:
+  EqDefaultCompare(int x) : used(x) {}
+  bool operator==(const EqDefaultCompare &) const = default;
+};
+
+class SpaceShipDefaultCompare {
+  int used;
+
+public:
+  SpaceShipDefaultCompare(int x) : used(x) {}
+  int operator<=>(const SpaceShipDefaultCompare &) const = default;
+};
+
+#endif
 
 class NotFullyDefined {
  public:
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -7292,6 +7292,9 @@
 return;
   }
 
+  if (DefKind.isComparison())
+UnusedPrivateFields.clear();
+
   if (DefKind.isSpecialMember()
   ? CheckExplicitlyDefaultedSpecialMember(cast(FD),
   DefKind.asSpecialMember())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D102186: [clang][c++20] Fix false warning for unused private fields when a class has only defaulted comparison operators.

2021-06-16 Thread Alexandru Octavian Buțiu via Phabricator via cfe-commits
predator5047 marked an inline comment as done.
predator5047 added inline comments.



Comment at: clang/test/SemaCXX/warn-unused-private-field.cpp:7
+
+class EqDefaultCompare {
+  int unused_;

hans wrote:
> The test case feels a little strange to me, I mean the member variable is 
> still pretty unused even though I suppose the comparison function technically 
> uses it.. At least the test case in the bug report had a constructor which 
> set the value. Perhaps with that it makes more sense.
Thanks for your feedback I updated the test case based on your comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102186

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


[PATCH] D103612: [flang][driver] Add `-fno-unparse-typed-exprs`

2021-06-16 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 352403.
awarzynski added a comment.

Rebase on top of main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103612

Files:
  clang/include/clang/Driver/Options.td
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Frontend/FrontendOptions.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/unparse-typed-exprs.f95
  flang/tools/f18/f18.cpp
  flang/tools/f18/flang

Index: flang/tools/f18/flang
===
--- flang/tools/f18/flang
+++ flang/tools/f18/flang
@@ -8,7 +8,7 @@
 #======#
 
 wd=$(cd $(dirname "$0")/.. && pwd)
-opts="-module-suffix .f18.mod "
+opts="-fno-unparse-typed-exprs -module-suffix .f18.mod "
 if ! $wd/bin/f18 $opts "$@"
 then status=$?
  echo flang: in $PWD, f18 failed with exit status $status: $wd/bin/f18 $opts "$@" >&2
Index: flang/tools/f18/f18.cpp
===
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -105,7 +105,7 @@
   bool debugModuleWriter{false};
   bool defaultReal8{false};
   bool measureTree{false};
-  bool unparseTypedExprsToF18_FC{false};
+  bool unparseTypedExprs{true};
   std::vector F18_FCArgs;
   const char *prefix{nullptr};
   bool getDefinition{false};
@@ -322,7 +322,8 @@
 Unparse(llvm::outs(), parseTree, driver.encoding, true /*capitalize*/,
 options.features.IsEnabled(
 Fortran::common::LanguageFeature::BackslashEscapes),
-nullptr /* action before each statement */, &asFortran);
+nullptr /* action before each statement */,
+driver.unparseTypedExprs ? &asFortran : nullptr);
 return {};
   }
   if (driver.dumpPreFirTree) {
@@ -353,7 +354,7 @@
 options.features.IsEnabled(
 Fortran::common::LanguageFeature::BackslashEscapes),
 nullptr /* action before each statement */,
-driver.unparseTypedExprsToF18_FC ? &asFortran : nullptr);
+driver.unparseTypedExprs ? &asFortran : nullptr);
   }
 
   RunOtherCompiler(driver, tmpSourcePath.data(), relo.data());
@@ -578,8 +579,8 @@
 } else if (arg == "-funparse-with-symbols" ||
 arg == "-fdebug-unparse-with-symbols") {
   driver.dumpUnparseWithSymbols = true;
-} else if (arg == "-funparse-typed-exprs-to-f18-fc") {
-  driver.unparseTypedExprsToF18_FC = true;
+} else if (arg == "-fno-unparse-typed-exprs") {
+  driver.unparseTypedExprs = false;
 } else if (arg == "-fparse-only" || arg == "-fsyntax-only") {
   driver.syntaxOnly = true;
 } else if (arg == "-c") {
Index: flang/test/Driver/unparse-typed-exprs.f95
===
--- /dev/null
+++ flang/test/Driver/unparse-typed-exprs.f95
@@ -0,0 +1,34 @@
+! Tests `-fno-unparse-typed-exprs-to-f18-fc` frontend option
+
+!--
+! RUN lines
+!--
+! RUN: %flang_fc1 -fdebug-unparse  %s | FileCheck %s --check-prefix=UNPARSED_TYPED_EXPR
+! RUN: %flang_fc1 -fdebug-unparse -fno-unparse-typed-exprs %s | FileCheck %s --check-prefix=AS_FORTRAN
+
+!--
+! EXPECTED OUTPUT: default
+!--
+! UNPARSED_TYPED_EXPR: PROGRAM test_allocated
+! UNPARSED_TYPED_EXPR-NEXT:  INTEGER :: i = 4_4
+! UNPARSED_TYPED_EXPR-NEXT:  REAL(KIND=4_4), ALLOCATABLE :: x(:)
+! UNPARSED_TYPED_EXPR-NEXT:  IF (.NOT.allocated(x)) ALLOCATE(x(i))
+! UNPARSED_TYPED_EXPR-NEXT: END PROGRAM test_allocated
+
+!-
+! EXPECTED OUTPUT: unparsed as Fortran
+!--
+! AS_FORTRAN: PROGRAM test_allocated
+! AS_FORTRAN-NEXT:  INTEGER :: i = 4
+! AS_FORTRAN-NEXT:  REAL(KIND=4), ALLOCATABLE :: x(:)
+! AS_FORTRAN-NEXT:  IF (.NOT.allocated(x)) ALLOCATE(x(i))
+! AS_FORTRAN-NEXT: END PROGRAM test_allocated
+
+!--
+! INPUT
+!--
+program test_allocated
+  integer :: i = 4
+  real(4), allocatable :: x(:)
+  if (.not. allocated(x)) allocate(x(i))
+end program test_allocated
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -101,6 +101,8 @@
 ! HELP-FC1-NEXT:Specify where to find the compiled intrinsic modules
 ! HELP-FC1-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
+! HELP-FC1-NEXT: -fno-unparse-typed-exprs
+! HELP-FC1-NEXT:Don't unparse typed expressions
 ! HELP-FC1-NEXT: -fopenacc  Enable OpenACC
 ! HELP-FC1-NEXT: -fopenmp  

[PATCH] D103096: [analyzer] Implement cast for ranges of symbolic integers.

2021-06-16 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko requested changes to this revision.
vsavchenko added a comment.
This revision now requires changes to proceed.

Hey, great work!  I think that casts are extremely important, but it looks like 
you mixed so many things into this patch.  Let's make one step at a time a 
split it into (at least) a couple of patches.




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:757-767
   markDisequal(BasicValueFactory &BV, RangeSet::Factory &F,
-   ProgramStateRef State, SymbolRef First, SymbolRef Second);
+   ProgramStateRef State, NominalTypeList &NTL, SymbolRef First,
+   SymbolRef Second);
   LLVM_NODISCARD static inline ProgramStateRef
   markDisequal(BasicValueFactory &BV, RangeSet::Factory &F,
-   ProgramStateRef State, EquivalenceClass First,
-   EquivalenceClass Second);
+   ProgramStateRef State, NominalTypeList &NTL,
+   EquivalenceClass First, EquivalenceClass Second);

That's definitely regresses the interface, so `NominalTypeList` should be 
definitely reworked.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1015-1042
+class NominalTypeList {
+  CanQualType Types[4];
+
+public:
+  using Iterator = CanQualType *;
+
+  NominalTypeList(ASTContext &C)

This looks like a very `static` data structure to me, I don't see any reasons 
why the user should be able to create multiple copies of it.
If it becomes a static data-structure, there will be no need in passing it 
around.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1067-1103
+do {
+  // We only handle integral cast, when all the types are integrals.
+  // Otherwise, pass the expression to VisitSymExpr.
+  QualType T = RootSym->getType();
+  if (!T->isIntegralOrEnumerationType())
+return VisitSymExpr(Sym);
+

I think all this extra logic about how we infer ranges for casts is 
interesting, but should be a separate patch.
For now, you can simply put `return Visit(Sym->getOperand());`.

First, it will unblock you from depending on that `RangeFactory` feature.
And also have quite a few questions about this particular implementation, so it 
will stagger this patch as well.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:2464-2523
+std::tuple
+RangeConstraintManager::handleSymbolCast(ProgramStateRef State, SymbolRef Sym,
+ RangeSet R) {
+  QualType T = Sym->getType();
+  if (!T->isIntegralOrEnumerationType() || R.isEmpty())
+return {State, Sym, R};
+

I need more explanation why we have this function and why we call it where we 
call it.  Additionally, it again looks like it belongs in a separate patch.


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

https://reviews.llvm.org/D103096

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


[libunwind] 5636402 - [libcxx] Fix exception raised during downstream bare-metal libunwind tests

2021-06-16 Thread Amilendra Kodithuwakku via cfe-commits

Author: Amilendra Kodithuwakku
Date: 2021-06-16T13:35:36+01:00
New Revision: 5636402bc0c92eec2faf46edb0fb733d78fa259e

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

LOG: [libcxx] Fix exception raised during downstream bare-metal libunwind tests

Fix for the following exception.

AttributeError: 'TestingConfig' object has no attribute 'target_triple'

Related revision: https://reviews.llvm.org/D102012

'TestingConfig' object has no attribute 'target_triple'

Reviewed By: #libunwind, miyuki, danielkiss, mstorsjo

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

Added: 


Modified: 
libunwind/test/libunwind/test/config.py

Removed: 




diff  --git a/libunwind/test/libunwind/test/config.py 
b/libunwind/test/libunwind/test/config.py
index e3e1dfcaed88a..b3f12bfe403c4 100644
--- a/libunwind/test/libunwind/test/config.py
+++ b/libunwind/test/libunwind/test/config.py
@@ -44,7 +44,8 @@ def configure_compile_flags(self):
 # generated by default on all Targets.
 self.cxx.compile_flags += ['-funwind-tables']
 # Make symbols available in the tests.
-if 'linux' in self.config.target_triple:
+triple = self.get_lit_conf('target_triple', None)
+if 'linux' in triple:
 self.cxx.link_flags += ['-Wl,--export-dynamic']
 if not self.get_lit_bool('enable_threads', True):
 self.cxx.compile_flags += ['-D_LIBUNWIND_HAS_NO_THREADS']



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


[PATCH] D103440: [WIP][analyzer] Introduce range-based reasoning for addition operator

2021-06-16 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1409-1415
+  if ((LHS.From() > 0 && RHS.From() > 0 && Min < 0) ||
+  (LHS.From() < 0 && RHS.From() < 0 && Min > 0) ||
+  (LHS.To() > 0 && RHS.To() > 0 && Max < 0) ||
+  (LHS.To() < 0 && RHS.To() < 0 && Max > 0)) {
+// return [Tmin, Tmax]
+return {RangeFactory, Tmin, Tmax};
+  }

manas wrote:
> vsavchenko wrote:
> > I thought we talked quite a lot that there is nothing bad with overflows 
> > and here we have that if ANY overflow happened, we bail out and don't give 
> > any result.
> Understood! Should I replace it with code returning EmptySet()?
Why `EmptySet()`?  `EmptySet()` means that this can never happen, this path is 
infeasible.  Is that the case?
Let's say we have: `[INT_MAX - 20, INT_MAX - 10] + [30, 40]` what happens in 
this case?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103440

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


[PATCH] D93525: [clang-offload-bundler] Add unbundling of archives containing bundled object files into device specific archives

2021-06-16 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93525

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


[PATCH] D103440: [WIP][analyzer] Introduce range-based reasoning for addition operator

2021-06-16 Thread Manas Gupta via Phabricator via cfe-commits
manas added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1409-1415
+  if ((LHS.From() > 0 && RHS.From() > 0 && Min < 0) ||
+  (LHS.From() < 0 && RHS.From() < 0 && Min > 0) ||
+  (LHS.To() > 0 && RHS.To() > 0 && Max < 0) ||
+  (LHS.To() < 0 && RHS.To() < 0 && Max > 0)) {
+// return [Tmin, Tmax]
+return {RangeFactory, Tmin, Tmax};
+  }

vsavchenko wrote:
> manas wrote:
> > vsavchenko wrote:
> > > I thought we talked quite a lot that there is nothing bad with overflows 
> > > and here we have that if ANY overflow happened, we bail out and don't 
> > > give any result.
> > Understood! Should I replace it with code returning EmptySet()?
> Why `EmptySet()`?  `EmptySet()` means that this can never happen, this path 
> is infeasible.  Is that the case?
> Let's say we have: `[INT_MAX - 20, INT_MAX - 10] + [30, 40]` what happens in 
> this case?
Right! That will not be the case.

In this particular case, the range will be `[INT_MIN + 9, INT_MIN + 29]` which 
is far smaller than `[Tmin, Tmax]`.

Also, I think I misunderstood the part of //bailing out and not giving any 
result// as returning empty.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103440

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


[PATCH] D103440: [WIP][analyzer] Introduce range-based reasoning for addition operator

2021-06-16 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1409-1415
+  if ((LHS.From() > 0 && RHS.From() > 0 && Min < 0) ||
+  (LHS.From() < 0 && RHS.From() < 0 && Min > 0) ||
+  (LHS.To() > 0 && RHS.To() > 0 && Max < 0) ||
+  (LHS.To() < 0 && RHS.To() < 0 && Max > 0)) {
+// return [Tmin, Tmax]
+return {RangeFactory, Tmin, Tmax};
+  }

manas wrote:
> vsavchenko wrote:
> > manas wrote:
> > > vsavchenko wrote:
> > > > I thought we talked quite a lot that there is nothing bad with 
> > > > overflows and here we have that if ANY overflow happened, we bail out 
> > > > and don't give any result.
> > > Understood! Should I replace it with code returning EmptySet()?
> > Why `EmptySet()`?  `EmptySet()` means that this can never happen, this path 
> > is infeasible.  Is that the case?
> > Let's say we have: `[INT_MAX - 20, INT_MAX - 10] + [30, 40]` what happens 
> > in this case?
> Right! That will not be the case.
> 
> In this particular case, the range will be `[INT_MIN + 9, INT_MIN + 29]` 
> which is far smaller than `[Tmin, Tmax]`.
> 
> Also, I think I misunderstood the part of //bailing out and not giving any 
> result// as returning empty.
Gotcha!

Because of cases like this, you need to re-think that part about `Min > Max` 
and maybe count the number of overflows on each side?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103440

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


[PATCH] D104376: [clangd] Correct SelectionTree behavior around anonymous field access.

2021-06-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: usaxena95, kadircet, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

struct A { struct { int b; }; };
A().^b;

This should be considered a reference to b, but currently it's
considered a reference to the anonymous struct field.

Fixes https://github.com/clangd/clangd/issues/798


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104376

Files:
  clang-tools-extra/clangd/Selection.cpp
  clang-tools-extra/clangd/unittests/XRefsTests.cpp


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -420,6 +420,18 @@
   //   $def is the definition location (if absent, symbol has no definition)
   //   unnamed range becomes both $decl and $def.
   const char *Tests[] = {
+  R"cpp(
+struct X {
+  union {
+int [[a]];
+float b;
+  };
+};
+int test(X &x) {
+  return x.^a;
+}
+  )cpp",
+
   R"cpp(// Local variable
 int main() {
   int [[bonjour]];
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -57,6 +57,27 @@
 SelectionUsedRecovery.record(0, LanguageLabel); // unused.
 }
 
+SourceRange getSourceRange(const DynTypedNode &N) {
+  // MemberExprs to implicitly access anonymous fields should not claim any
+  // tokens for themselves. Given:
+  //   struct A { struct { int b; }; };
+  // The clang AST reports the following nodes for an access to b:
+  //   A().b;
+  //   [] MemberExpr, base = A()., member = b
+  //   [] MemberExpr: base = A(), member = 
+  //   [-]CXXConstructExpr
+  // For our purposes, we don't want the second MemberExpr to own any tokens,
+  // so we reduce its range to match the CXXConstructExpr.
+  // (It's not clear that changing the clang AST would be correct in general).
+  if (const auto *ME = N.get()) {
+if (!ME->getMemberDecl()->getDeclName())
+  return ME->getBase()
+ ? getSourceRange(DynTypedNode::create(*ME->getBase()))
+ : SourceRange();
+  }
+  return N.getSourceRange();
+}
+
 // An IntervalSet maintains a set of disjoint subranges of an array.
 //
 // Initially, it contains the entire array.
@@ -608,7 +629,7 @@
   // An optimization for a common case: nodes outside macro expansions that
   // don't intersect the selection may be recursively skipped.
   bool canSafelySkipNode(const DynTypedNode &N) {
-SourceRange S = N.getSourceRange();
+SourceRange S = getSourceRange(N);
 if (auto *TL = N.get()) {
   // FIXME: TypeLoc::getBeginLoc()/getEndLoc() are pretty fragile
   // heuristics. We should consider only pruning critical TypeLoc nodes, to
@@ -665,7 +686,7 @@
   void pop() {
 Node &N = *Stack.top();
 dlog("{1}pop: {0}", printNodeToString(N.ASTNode, PrintPolicy), indent(-1));
-claimRange(N.ASTNode.getSourceRange(), N.Selected);
+claimRange(getSourceRange(N.ASTNode), N.Selected);
 if (N.Selected == NoTokens)
   N.Selected = SelectionTree::Unselected;
 if (N.Selected || !N.Children.empty()) {
@@ -868,13 +889,13 @@
 
 const SelectionTree::Node &SelectionTree::Node::ignoreImplicit() const {
   if (Children.size() == 1 &&
-  Children.front()->ASTNode.getSourceRange() == ASTNode.getSourceRange())
+  getSourceRange(Children.front()->ASTNode) == getSourceRange(ASTNode))
 return Children.front()->ignoreImplicit();
   return *this;
 }
 
 const SelectionTree::Node &SelectionTree::Node::outerImplicit() const {
-  if (Parent && Parent->ASTNode.getSourceRange() == ASTNode.getSourceRange())
+  if (Parent && getSourceRange(Parent->ASTNode) == getSourceRange(ASTNode))
 return Parent->outerImplicit();
   return *this;
 }


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -420,6 +420,18 @@
   //   $def is the definition location (if absent, symbol has no definition)
   //   unnamed range becomes both $decl and $def.
   const char *Tests[] = {
+  R"cpp(
+struct X {
+  union {
+int [[a]];
+float b;
+  };
+};
+int test(X &x) {
+  return x.^a;
+}
+  )cpp",
+
   R"cpp(// Local variable
 int main() {
   int [[bonjour]];
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/cla

[PATCH] D103440: [WIP][analyzer] Introduce range-based reasoning for addition operator

2021-06-16 Thread Manas Gupta via Phabricator via cfe-commits
manas added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1409-1415
+  if ((LHS.From() > 0 && RHS.From() > 0 && Min < 0) ||
+  (LHS.From() < 0 && RHS.From() < 0 && Min > 0) ||
+  (LHS.To() > 0 && RHS.To() > 0 && Max < 0) ||
+  (LHS.To() < 0 && RHS.To() < 0 && Max > 0)) {
+// return [Tmin, Tmax]
+return {RangeFactory, Tmin, Tmax};
+  }

vsavchenko wrote:
> manas wrote:
> > vsavchenko wrote:
> > > manas wrote:
> > > > vsavchenko wrote:
> > > > > I thought we talked quite a lot that there is nothing bad with 
> > > > > overflows and here we have that if ANY overflow happened, we bail out 
> > > > > and don't give any result.
> > > > Understood! Should I replace it with code returning EmptySet()?
> > > Why `EmptySet()`?  `EmptySet()` means that this can never happen, this 
> > > path is infeasible.  Is that the case?
> > > Let's say we have: `[INT_MAX - 20, INT_MAX - 10] + [30, 40]` what happens 
> > > in this case?
> > Right! That will not be the case.
> > 
> > In this particular case, the range will be `[INT_MIN + 9, INT_MIN + 29]` 
> > which is far smaller than `[Tmin, Tmax]`.
> > 
> > Also, I think I misunderstood the part of //bailing out and not giving any 
> > result// as returning empty.
> Gotcha!
> 
> Because of cases like this, you need to re-think that part about `Min > Max` 
> and maybe count the number of overflows on each side?
That's right. If it is able to deduce how many times overflows are occurring 
then it can reason about whether it will be MaxRangeSet or a subset of it. 
Fixing it!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103440

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


[PATCH] D104381: [analyzer] Added a test case for PR46264

2021-06-16 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: NoQ, steakhal.
ASDenysPetrov added a project: clang.
Herald added subscribers: manas, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
ASDenysPetrov requested review of this revision.
Herald added a subscriber: cfe-commits.

It's not able to reproduce the issue 
(https://bugs.llvm.org/show_bug.cgi?id=46264) for the latest sources. Add a 
reported test case to try to catch the problem if occures.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104381

Files:
  clang/test/Analysis/diagnostics/PR46264.cpp


Index: clang/test/Analysis/diagnostics/PR46264.cpp
===
--- /dev/null
+++ clang/test/Analysis/diagnostics/PR46264.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text 
-verify %s
+
+// PR46264
+// This case shall not warn about dereference of void*
+namespace ns1 {
+namespace a {
+class b {
+public:
+  typedef int b::*c;
+  operator c() { return d ? &b::d : 0; }
+  // expected-note@-1{{'?' condition is true}}
+  // expected-note@-2{{Assuming field 'd' is not equal to 0}}
+  // expected-note@-3{{Returning value, which participates in a condition 
later}}
+  int d;
+};
+} // namespace a
+using a::b;
+class e {
+  void f();
+  void g();
+  b h;
+};
+void e::f() {
+  e *i;
+  // expected-note@-1{{'i' declared without an initial value}}
+  if (h)
+// expected-note@-1{{Taking true branch}}
+// expected-note@-2{{'b::operator int ns1::a::b::*'}}
+// expected-note@-3{{Returning from 'b::operator int ns1::a::b::*'}}
+i->g();
+  // expected-note@-1{{Called C++ object pointer is uninitialized}}
+  // expected-warning@-2{{Called C++ object pointer is uninitialized}}
+}
+} // namespace ns1


Index: clang/test/Analysis/diagnostics/PR46264.cpp
===
--- /dev/null
+++ clang/test/Analysis/diagnostics/PR46264.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output=text -verify %s
+
+// PR46264
+// This case shall not warn about dereference of void*
+namespace ns1 {
+namespace a {
+class b {
+public:
+  typedef int b::*c;
+  operator c() { return d ? &b::d : 0; }
+  // expected-note@-1{{'?' condition is true}}
+  // expected-note@-2{{Assuming field 'd' is not equal to 0}}
+  // expected-note@-3{{Returning value, which participates in a condition later}}
+  int d;
+};
+} // namespace a
+using a::b;
+class e {
+  void f();
+  void g();
+  b h;
+};
+void e::f() {
+  e *i;
+  // expected-note@-1{{'i' declared without an initial value}}
+  if (h)
+// expected-note@-1{{Taking true branch}}
+// expected-note@-2{{'b::operator int ns1::a::b::*'}}
+// expected-note@-3{{Returning from 'b::operator int ns1::a::b::*'}}
+i->g();
+  // expected-note@-1{{Called C++ object pointer is uninitialized}}
+  // expected-warning@-2{{Called C++ object pointer is uninitialized}}
+}
+} // namespace ns1
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104299: Handle interactions between reserved identifier and user-defined suffixes

2021-06-16 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 352423.
serge-sans-paille added a comment.

Tried another not-so-intrusive approach. @rsmith?


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

https://reviews.llvm.org/D104299

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Decl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/Sema/reserved-identifier.cpp

Index: clang/test/Sema/reserved-identifier.cpp
===
--- clang/test/Sema/reserved-identifier.cpp
+++ clang/test/Sema/reserved-identifier.cpp
@@ -76,7 +76,12 @@
 int _barbatruc; // no-warning
 }
 
-long double operator"" _BarbeBleue(long double) // expected-warning {{identifier 'operator""_BarbeBleue' is reserved because it starts with '_' followed by a capital letter}}
+long double operator"" _BarbeBleue(long double) // expected-warning {{identifier '_BarbeBleue' is reserved because it starts with '_' followed by a capital letter}}
+{
+  return 0.;
+}
+
+long double operator""_SacreBleue(long double) // no-warning
 {
   return 0.;
 }
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -484,8 +484,19 @@
 }
 
 bool Sema::checkLiteralOperatorId(const CXXScopeSpec &SS,
-  const UnqualifiedId &Name) {
+  const UnqualifiedId &Name, bool isUDSuffix) {
   assert(Name.getKind() == UnqualifiedIdKind::IK_LiteralOperatorId);
+  if (!isUDSuffix) {
+// [over.literal] p8
+IdentifierInfo *II = Name.Identifier;
+auto Status = II->isReserved(PP.getLangOpts());
+auto Loc = Name.getBeginLoc();
+if (Status != ReservedIdentifierStatus::NotReserved &&
+!PP.getSourceManager().isInSystemHeader(Loc)) {
+  Diag(Loc, diag::warn_reserved_extern_symbol)
+  << II << static_cast(Status);
+}
+  }
 
   if (!SS.isValid())
 return false;
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -9,7 +9,6 @@
 // This file implements the Expression parsing implementation for C++.
 //
 //===--===//
-#include "clang/Parse/Parser.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclTemplate.h"
@@ -17,6 +16,7 @@
 #include "clang/Basic/PrettyStackTrace.h"
 #include "clang/Lex/LiteralSupport.h"
 #include "clang/Parse/ParseDiagnostic.h"
+#include "clang/Parse/Parser.h"
 #include "clang/Parse/RAIIObjectsForParser.h"
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/ParsedTemplate.h"
@@ -2636,9 +2636,10 @@
 
 // Grab the literal operator's suffix, which will be either the next token
 // or a ud-suffix from the string literal.
+const bool isUDSuffix = !Literal.getUDSuffix().empty();
 IdentifierInfo *II = nullptr;
 SourceLocation SuffixLoc;
-if (!Literal.getUDSuffix().empty()) {
+if (isUDSuffix) {
   II = &PP.getIdentifierTable().get(Literal.getUDSuffix());
   SuffixLoc =
 Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()],
@@ -2675,7 +2676,7 @@
 
 Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
 
-return Actions.checkLiteralOperatorId(SS, Result);
+return Actions.checkLiteralOperatorId(SS, Result, isUDSuffix);
   }
 
   // Parse a conversion-function-id.
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1088,6 +1088,10 @@
   if (!II)
 return ReservedIdentifierStatus::NotReserved;
 
+  // already checked at lexing time
+  if (getDeclName().getCXXLiteralIdentifier())
+return ReservedIdentifierStatus::NotReserved;
+
   ReservedIdentifierStatus Status = II->isReserved(LangOpts);
   if (Status == ReservedIdentifierStatus::StartsWithUnderscoreAtGlobalScope) {
 // Check if we're at TU level or not.
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -4128,7 +4128,8 @@
 bool RValueThis, unsigned ThisQuals);
   CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
 
-  bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id);
+  bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id,
+  bool isUDSuffix);
   LiteralOperatorLookupResult
   LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef ArgTys,
 bool AllowRaw, bool AllowTemplate,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cg

[PATCH] D102107: [OpenMP] Codegen aggregate for outlined function captures

2021-06-16 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

(answered now, I forgot to submit this yesterday -.- )

In D102107#2819869 , @lebedev.ri 
wrote:

> (This is not offload-specific, right?)

It is not. It applies to all parallel regions. We still use the variadic call 
on the CPU but we can now replace it with a non-variadic interface.

> This does not bring any compatibility issues, right?

We'll keep the old interface (kmpc_fork_call) for the host (libomp) and code 
that uses it will continue to work. New code will use it also in a compatible 
way
because we change caller and callee of kmpc_fork_call to adjust for the 
aggregate. This will also hold as the new non-variadic interface is introduced.

The device side is simpler, we are only compatible with a device runtime that 
machtes (as we link it into the app), so there is no compatibility issue to be 
expected.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102107

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


[PATCH] D102107: [OpenMP] Codegen aggregate for outlined function captures

2021-06-16 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

We used this kind of codegen initially but later found out that it causes a 
large overhead when gathering pointers into a record. What about hybrid scheme 
where the first args are passed as arguments and others (if any) are gathered 
into a record?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102107

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


[PATCH] D103668: [PowerPC] Implement trap and conversion builtins for XL compatibility

2021-06-16 Thread Albion Fung via Phabricator via cfe-commits
Conanap updated this revision to Diff 352431.
Conanap added a comment.

Rebase and added 64 bit sema checking

Rebased to include the updated location for the builtin alias
definition location, as well as added 64 bit checking for 64
bit only builtins in sema checking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103668

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/Sema/SemaChecking.cpp
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCInstr64Bit.td
  llvm/lib/Target/PowerPC/PPCInstrPrefix.td
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-conversionfunc.c
  llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.c

Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.c
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-trap.c
@@ -0,0 +1,226 @@
+// RUN: clang -mcpu=pwr7 -m64 -O2 -c -S %s -o - | FileCheck %s
+
+long long lla, llb;
+double da;
+
+void test_tdlgt(void) {
+// CHECK-LABEL: test_tdlgt
+// CHECK: tdlgt
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 1);
+}
+
+void test_xl_tdlgt(void) {
+// CHECK-LABEL: test_xl_tdlgt
+// CHECK: tdlgt
+// CHECK: blr
+
+  __tdw(lla, llb, 1);
+}
+
+void test_tdllt(void) {
+// CHECK-LABEL: test_tdllt
+// CHECK: tdllt
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 2);
+}
+
+void test_xl_tdllt(void) {
+// CHECK-LABEL: test_xl_tdllt
+// CHECK: tdllt
+// CHECK: blr
+
+  __tdw(lla, llb, 2);
+}
+
+void test_tdne3(void) {
+// CHECK-LABEL: test_tdne3
+// CHECK: tdne
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 3);
+}
+
+void test_xl_tdne3(void) {
+// CHECK-LABEL: test_xl_tdne3
+// CHECK: tdne
+// CHECK: blr
+
+  __tdw(lla, llb, 3);
+}
+
+void test_tdeq(void) {
+// CHECK-LABEL: test_tdeq
+// CHECK: tdeq
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 4);
+}
+
+void test_xl_tdeq(void) {
+// CHECK-LABEL: test_xl_tdeq
+// CHECK: tdeq
+// CHECK: blr
+
+  __tdw(lla, llb, 4);
+}
+
+void test_tdlge(void) {
+// CHECK-LABEL: test_tdlge
+// CHECK: tdlge
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 5);
+}
+
+void test_xl_tdlge(void) {
+// CHECK-LABEL: test_xl_tdlge
+// CHECK: tdlge
+// CHECK: blr
+
+  __tdw(lla, llb, 5);
+}
+
+void test_tdlle(void) {
+// CHECK-LABEL: test_tdlle
+// CHECK: tdlle
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 6);
+}
+
+void test_xl_tdlle(void) {
+// CHECK-LABEL: test_xl_tdlle
+// CHECK: tdlle
+// CHECK: blr
+
+  __tdw(lla, llb, 6);
+}
+
+void test_tdgt(void) {
+// CHECK-LABEL: test_tdgt
+// CHECK: tdgt
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 8);
+}
+
+void test_xl_tdgt(void) {
+// CHECK-LABEL: test_xl_tdgt
+// CHECK: tdgt
+// CHECK: blr
+
+  __tdw(lla, llb, 8);
+}
+
+void test_tdge(void) {
+// CHECK-LABEL: test_tdge
+// CHECK: tdge
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 12);
+}
+
+void test_xl_tdge(void) {
+// CHECK-LABEL: test_xl_tdge
+// CHECK: tdge
+// CHECK: blr
+
+  __tdw(lla, llb, 12);
+}
+
+void test_tdlt(void) {
+// CHECK-LABEL: test_tdlt
+// CHECK: tdlt
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 16);
+}
+
+void test_xl_tdlt(void) {
+// CHECK-LABEL: test_xl_tdlt
+// CHECK: tdlt
+// CHECK: blr
+
+  __tdw(lla, llb, 16);
+}
+
+void test_tdle(void) {
+// CHECK-LABEL: test_tdle
+// CHECK: tdle
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 20);
+}
+
+void test_xl_tdle(void) {
+// CHECK-LABEL: test_xl_tdle
+// CHECK: tdle
+// CHECK: blr
+
+  __tdw(lla, llb, 20);
+}
+
+void test_tdne24(void) {
+// CHECK-LABEL: test_tdne24
+// CHECK: tdne
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 24);
+}
+
+void test_xl_tdne24(void) {
+// CHECK-LABEL: test_xl_tdne24
+// CHECK: tdne
+// CHECK: blr
+
+  __tdw(lla, llb, 24);
+}
+
+void test_tdeq31(void) {
+// CHECK-LABEL: test_tdeq31
+// CHECK: tdeq
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 31);
+}
+
+void test_xl_tdeq31(void) {
+// CHECK-LABEL: test_xl_tdeq31
+// CHECK: tdeq
+// CHECK: blr
+
+  __tdw(lla, llb, 31);
+}
+
+void test_td_no_match(void) {
+// CHECK-LABEL: test_td_no_match
+// CHECK: td 13
+// CHECK: blr
+
+  __builtin_ppc_tdw(lla, llb, 13);
+}
+
+void test_xl_td_no_match(void) {
+// CHECK-LABEL: test_xl_td_no_match
+// CHECK: td 13
+// CHECK: blr
+
+  __tdw(lla, llb, 13);
+}
+
+void test_trapd(void) {
+// CHECK-LABEL: test_trapd
+// CHECK: tdnei 3, 0
+// CHECK: blr
+  __builtin_ppc_trapd(da);
+}
+
+void test_xl_trapd(void) {
+// CHECK-LABEL: test_xl_trapd
+// CHECK: tdnei 3, 0
+// CHECK: blr
+  __trapd(da);
+}
Index: llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-conversionfunc.c
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/builtins-ppc-xlcompat-conversionfunc.c
@@ -0,0 +1,115 @@
+// RUN: clang -mcpu=pwr9 -O2 -c -S %s -o - | FileCheck %s
+
+double a;
+
+double test_fcfid(double a) {
+  // CHECK-LABEL: test_fcfid
+  // CHECK: xscvsxddp 1, 1
+  // CHECK: blr

[PATCH] D104386: [PowerPC][Builtins] Added a number of builtins for compatibility with XL.

2021-06-16 Thread Stefan Pintilie via Phabricator via cfe-commits
stefanp created this revision.
stefanp added reviewers: nemanjai, lei.
Herald added subscribers: shchenz, kbarton.
stefanp requested review of this revision.
Herald added a project: clang.

Added a number of different builtins that exist in the XL compiler. Most of
these builtins already exist in clang under a different name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104386

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-abs.c
  clang/test/CodeGen/builtins-ppc-xlcompat-alloca.c
  clang/test/CodeGen/builtins-ppc-xlcompat-bpermd.c
  clang/test/CodeGen/builtins-ppc-xlcompat-cipher.c
  clang/test/CodeGen/builtins-ppc-xlcompat-cmplx.c
  clang/test/CodeGen/builtins-ppc-xlcompat-darn.c
  clang/test/CodeGen/builtins-ppc-xlcompat-div.c
  clang/test/CodeGen/builtins-ppc-xlcompat-expect.c
  clang/test/CodeGen/builtins-ppc-xlcompat-fma.c
  clang/test/CodeGen/builtins-ppc-xlcompat-memory.c
  clang/test/CodeGen/builtins-ppc-xlcompat-mode.c
  clang/test/CodeGen/builtins-ppc-xlcompat-popcnt.c
  clang/test/CodeGen/builtins-ppc-xlcompat-rotate.c

Index: clang/test/CodeGen/builtins-ppc-xlcompat-rotate.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-rotate.c
@@ -0,0 +1,175 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown -D__ppc64__ \
+// RUN:-emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s --check-prefix=BE64
+// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown -D__ppc64__ \
+// RUN:   -emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s --check-prefix=LE64
+// RUN: %clang_cc1 -triple powerpc-unknown-unknown \
+// RUN:-emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s --check-prefix=BE32
+// RUN: %clang_cc1 -triple powerpcle-unknown-unknown \
+// RUN:   -emit-llvm %s -o -  -target-cpu pwr8 | FileCheck %s --check-prefix=LE32
+
+// BE64-LABEL: @testrotatel4(
+// BE64-NEXT:  entry:
+// BE64-NEXT:[[RS_ADDR:%.*]] = alloca i32, align 4
+// BE64-NEXT:[[SHIFT_ADDR:%.*]] = alloca i32, align 4
+// BE64-NEXT:store i32 [[RS:%.*]], i32* [[RS_ADDR]], align 4
+// BE64-NEXT:store i32 [[SHIFT:%.*]], i32* [[SHIFT_ADDR]], align 4
+// BE64-NEXT:[[TMP0:%.*]] = load i32, i32* [[RS_ADDR]], align 4
+// BE64-NEXT:[[TMP1:%.*]] = load i32, i32* [[SHIFT_ADDR]], align 4
+// BE64-NEXT:[[TMP2:%.*]] = call i32 @llvm.fshl.i32(i32 [[TMP0]], i32 [[TMP0]], i32 [[TMP1]])
+// BE64-NEXT:ret i32 [[TMP2]]
+//
+// LE64-LABEL: @testrotatel4(
+// LE64-NEXT:  entry:
+// LE64-NEXT:[[RS_ADDR:%.*]] = alloca i32, align 4
+// LE64-NEXT:[[SHIFT_ADDR:%.*]] = alloca i32, align 4
+// LE64-NEXT:store i32 [[RS:%.*]], i32* [[RS_ADDR]], align 4
+// LE64-NEXT:store i32 [[SHIFT:%.*]], i32* [[SHIFT_ADDR]], align 4
+// LE64-NEXT:[[TMP0:%.*]] = load i32, i32* [[RS_ADDR]], align 4
+// LE64-NEXT:[[TMP1:%.*]] = load i32, i32* [[SHIFT_ADDR]], align 4
+// LE64-NEXT:[[TMP2:%.*]] = call i32 @llvm.fshl.i32(i32 [[TMP0]], i32 [[TMP0]], i32 [[TMP1]])
+// LE64-NEXT:ret i32 [[TMP2]]
+//
+// BE32-LABEL: @testrotatel4(
+// BE32-NEXT:  entry:
+// BE32-NEXT:[[RS_ADDR:%.*]] = alloca i32, align 4
+// BE32-NEXT:[[SHIFT_ADDR:%.*]] = alloca i32, align 4
+// BE32-NEXT:store i32 [[RS:%.*]], i32* [[RS_ADDR]], align 4
+// BE32-NEXT:store i32 [[SHIFT:%.*]], i32* [[SHIFT_ADDR]], align 4
+// BE32-NEXT:[[TMP0:%.*]] = load i32, i32* [[RS_ADDR]], align 4
+// BE32-NEXT:[[TMP1:%.*]] = load i32, i32* [[SHIFT_ADDR]], align 4
+// BE32-NEXT:[[TMP2:%.*]] = call i32 @llvm.fshl.i32(i32 [[TMP0]], i32 [[TMP0]], i32 [[TMP1]])
+// BE32-NEXT:ret i32 [[TMP2]]
+//
+// LE32-LABEL: @testrotatel4(
+// LE32-NEXT:  entry:
+// LE32-NEXT:[[RS_ADDR:%.*]] = alloca i32, align 4
+// LE32-NEXT:[[SHIFT_ADDR:%.*]] = alloca i32, align 4
+// LE32-NEXT:store i32 [[RS:%.*]], i32* [[RS_ADDR]], align 4
+// LE32-NEXT:store i32 [[SHIFT:%.*]], i32* [[SHIFT_ADDR]], align 4
+// LE32-NEXT:[[TMP0:%.*]] = load i32, i32* [[RS_ADDR]], align 4
+// LE32-NEXT:[[TMP1:%.*]] = load i32, i32* [[SHIFT_ADDR]], align 4
+// LE32-NEXT:[[TMP2:%.*]] = call i32 @llvm.fshl.i32(i32 [[TMP0]], i32 [[TMP0]], i32 [[TMP1]])
+// LE32-NEXT:ret i32 [[TMP2]]
+//
+unsigned int testrotatel4(unsigned int rs, unsigned int shift) {
+  return __rotatel4(rs, shift);
+}
+
+// BE64-LABEL: @testrotatel8(
+// BE64-NEXT:  entry:
+// BE64-NEXT:[[RS_ADDR:%.*]] = alloca i64, align 8
+// BE64-NEXT:[[SHIFT_ADDR:%.*]] = alloca i64, align 8
+// BE64-NEXT:store i64 [[RS:%.*]], i64* [[RS_ADDR]], align 8
+// BE64-NEXT:store i64 [[SHIFT:%.*]], i64* [[SHIFT_ADDR]], align 8
+// BE64-NEXT:[[TMP0:%.*]] = load i64, i64* [[RS_ADDR]], align 8
+// BE64-NEXT:[[TMP1:%.*]] = load i64, i64* [[SHIFT_ADDR]], align 8
+// BE64-NEXT:[[TMP2:%.*]] = call i64 @l

[PATCH] D102782: Add support for Warning Flag "-Wstack-usage="

2021-06-16 Thread Ryan Santhirarajan via Phabricator via cfe-commits
rsanthir.quic added a comment.

ping @Quuxplusone this is being used as a diagnostic flag that aliases 
"-Wframe-larger-than", I think if we want to add more user-facing documentation 
to clarify things we should revisit what the "-Wframe-larger-than=" tracks as 
well. Currently there isn't too much info on that flag either.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102782

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


[PATCH] D104387: [clang-cl] Implement /external:I, /external:env, and EXTERNAL_INCLUDE support (PR36003)

2021-06-16 Thread Hans Wennborg via Phabricator via cfe-commits
hans created this revision.
hans added a reviewer: thakis.
Herald added a subscriber: dang.
hans requested review of this revision.
Herald added a project: clang.

This patch does three things:

- Map the /external:I flag to -isystem

- Add support for the /external:env: flag which reads system include paths 
for the  environment variable

- Pick up system include dirs EXTERNAL_INCLUDE in addition to the old INCLUDE 
environment variable.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104387

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/cl-include.c
  clang/test/Driver/cl-options.c

Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -38,6 +38,10 @@
 // EP: "-P"
 // EP: "-o" "-"
 
+// RUN: %clang_cl /external:Ipath  -### -- %s 2>&1 | FileCheck -check-prefix=EXTERNAL_I %s
+// RUN: %clang_cl /external:I path -### -- %s 2>&1 | FileCheck -check-prefix=EXTERNAL_I %s
+// EXTERNAL_I: "-isystem" "path"
+
 // RUN: %clang_cl /fp:fast /fp:except -### -- %s 2>&1 | FileCheck -check-prefix=fpexcept %s
 // fpexcept-NOT: -menable-unsafe-fp-math
 
@@ -434,8 +438,6 @@
 // RUN: /experimental:preprocessor \
 // RUN: /exportHeader /headerName:foo \
 // RUN: /external:anglebrackets \
-// RUN: /external:Ipath \
-// RUN: /external:I path \
 // RUN: /external:env:var \
 // RUN: /external:W0 \
 // RUN: /external:W1 \
Index: clang/test/Driver/cl-include.c
===
--- clang/test/Driver/cl-include.c
+++ clang/test/Driver/cl-include.c
@@ -7,19 +7,27 @@
 // RUN: %clang_cl -nobuiltininc -### -- %s 2>&1 | FileCheck %s --check-prefix=NOBUILTIN
 // NOBUILTIN-NOT: "-internal-isystem" "{{.*lib.*clang.*include}}"
 
-// RUN: env INCLUDE=/my/system/inc %clang_cl -### -- %s 2>&1 | FileCheck %s --check-prefix=STDINC
+// RUN: env INCLUDE=/my/system/inc env EXTERNAL_INCLUDE=/my/system/inc2 %clang_cl -### -- %s 2>&1 | FileCheck %s --check-prefix=STDINC
 // STDINC: "-internal-isystem" "/my/system/inc"
+// STDINC: "-internal-isystem" "/my/system/inc2"
 
 // -nostdinc suppresses all of %INCLUDE%, clang resource dirs, and -imsvc dirs.
-// RUN: env INCLUDE=/my/system/inc %clang_cl -nostdinc -imsvc /my/other/inc -### -- %s 2>&1 | FileCheck %s --check-prefix=NOSTDINC
+// RUN: env INCLUDE=/my/system/inc env EXTERNAL_INCLUDE=/my/system/inc2 %clang_cl -nostdinc -imsvc /my/other/inc -### -- %s 2>&1 | FileCheck %s --check-prefix=NOSTDINC
 // NOSTDINC: argument unused{{.*}}-imsvc
 // NOSTDINC-NOT: "-internal-isystem" "/my/system/inc"
+// NOSTDINC-NOT: "-internal-isystem" "/my/system/inc2"
 // NOSTDINC-NOT: "-internal-isystem" "{{.*lib.*clang.*include}}"
 // NOSTDINC-NOT: "-internal-isystem" "/my/other/inc"
 
 // /X suppresses %INCLUDE% but not clang resource dirs or -imsvc dirs.
-// RUN: env INCLUDE=/my/system/inc %clang_cl /X -imsvc /my/other/inc -### -- %s 2>&1 | FileCheck %s --check-prefix=SLASHX
+// RUN: env INCLUDE=/my/system/inc env EXTERNAL_INCLUDE=/my/system/inc2 %clang_cl /X -imsvc /my/other/inc -### -- %s 2>&1 | FileCheck %s --check-prefix=SLASHX
 // SLASHX-NOT: "argument unused{{.*}}-imsvc"
 // SLASHX-NOT: "-internal-isystem" "/my/system/inc"
+// SLASHX-NOT: "-internal-isystem" "/my/system/inc2"
 // SLASHX: "-internal-isystem" "{{.*lib.*clang.*include}}"
 // SLASHX: "-internal-isystem" "/my/other/inc"
+
+// RUN: env "FOO=/dir1;/dir2" env "BAR=/dir3" %clang_cl /external:env:FOO /external:env:BAR -### -- %s 2>&1 | FileCheck %s --check-prefix=EXTERNAL_ENV
+// EXTERNAL_ENV: "-internal-isystem" "/dir1"
+// EXTERNAL_ENV: "-internal-isystem" "/dir2"
+// EXTERNAL_ENV: "-internal-isystem" "/dir3"
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1243,22 +1243,40 @@
   for (const auto &Path : DriverArgs.getAllArgValues(options::OPT__SLASH_imsvc))
 addSystemInclude(DriverArgs, CC1Args, Path);
 
+  // Add %INCLUDE%-like dirs via the /external:env: flag.
+  for (const auto &Var :
+   DriverArgs.getAllArgValues(options::OPT__SLASH_external_env)) {
+if (auto Val = llvm::sys::Process::GetEnv(Var)) {
+  SmallVector Dirs;
+  StringRef(*Val).split(Dirs, ";", /*MaxSplit=*/-1, /*KeepEmpty=*/false);
+  for (StringRef Dir : Dirs)
+addSystemInclude(DriverArgs, CC1Args, Dir);
+}
+  }
+
   if (DriverArgs.hasArg(options::OPT_nostdlibinc))
 return;
 
-  // Honor %INCLUDE%. It should know essential search paths with vcvarsall.bat.
-  // Skip if the user expressly set a vctoolsdir
+  // Honor %INCLUDE% and %EXTERNAL_INCLUDE%. It should have essential search
+  // paths set by vcvarsall.bat. Skip if the user expressly set a vctoolsdir.
   if (!DriverArgs.getLastArg(options::OPT__SLASH_vctoolsdir,
   

[PATCH] D104388: [clang-format] PR50727 C# Invoke Lamda Expression indentation incorrect

2021-06-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: curdeius, HazardyKnusperkeks, exv, lbk, jbcoe.
MyDeveloperDay added projects: clang, clang-format.
MyDeveloperDay requested review of this revision.

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

When processing C# Lambda expression in the indentation can goes a little 
wrong, 
resulting the the closing } being at the wrong indentation level and meaning 
the remaining part of the file is
incorrectly indented.

This revision tries to address that for C#

This can be a fairly common pattern for when C# wants to peform a UI action 
from a thread, 
and it wants to invoke that action on the main thread

  class A
  {
  
  void foo()
  {
  Dispatcher.Invoke(DispatcherPriority.Render, (Action)(() => {
lock (A)
{
if (true)
{
A.Remove(item);
  }
  }
  }));
  }
  
  void bar()
  {
  ...
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104388

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -640,6 +640,34 @@
 };
 })",
MicrosoftStyle);
+
+  verifyFormat("void bar()\n"
+   "{\n"
+   "Function(Val, (Action)(() => {\n"
+   " lock (mylock)\n"
+   " {\n"
+   " if (true)\n"
+   " {\n"
+   " A.Remove(item);\n"
+   " }\n"
+   " }\n"
+   " }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+   "{\n"
+   "Function(Val, (Action)(() => {\n"
+   " using (var a = new Lock())\n"
+   " {\n"
+   " if (true)\n"
+   " {\n"
+   " A.Remove(item);\n"
+   " }\n"
+   " }\n"
+   " }));\n"
+   "}",
+   MicrosoftStyle);
 }
 
 TEST_F(FormatTestCSharp, CSharpObjectInitializers) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1927,6 +1927,12 @@
 parseBracedList();
   }
   break;
+case tok::equal:
+  if (Style.isCSharp() && FormatTok->is(TT_FatArrow))
+parseBracedList();
+  else
+nextToken();
+  break;
 case tok::kw_class:
   if (Style.Language == FormatStyle::LK_JavaScript)
 parseRecord(/*ParseAsExpr=*/true);


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -640,6 +640,34 @@
 };
 })",
MicrosoftStyle);
+
+  verifyFormat("void bar()\n"
+   "{\n"
+   "Function(Val, (Action)(() => {\n"
+   " lock (mylock)\n"
+   " {\n"
+   " if (true)\n"
+   " {\n"
+   " A.Remove(item);\n"
+   " }\n"
+   " }\n"
+   " }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+   "{\n"
+   "Function(Val, (Action)(() => {\n"
+   " using (var a = new Lock())\n"
+   " {\n"
+   " if (true)\n"
+   " {\n"
+   " A.Remove(item);\n"
+   " }\n"
+   " }\n"
+   " }));\n"
+   "}",
+   MicrosoftStyle);
 }
 
 TEST_F(FormatTestCSharp, CSharpObjectInitializers) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1927,6 +1927,12 @@
 parseBracedList();
   }
   break;
+ 

[clang] f387c85 - [libTooling][NFC] Refactor implemenation of Transformer Stencils to use standard OOP

2021-06-16 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2021-06-16T15:18:40Z
New Revision: f387c8545d3a729eaf0e76c22f445a2209705814

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

LOG: [libTooling][NFC] Refactor implemenation of Transformer Stencils to use 
standard OOP

Currently, the implementation combines OOP and overloads, using a template to
tie the two together. In practice, this has proven confusing with no
benefits. This patch simplifies the code to use standard OOP design (a
collection of classes deriving from an interface).

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

Added: 


Modified: 
clang/lib/Tooling/Transformer/Stencil.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Transformer/Stencil.cpp 
b/clang/lib/Tooling/Transformer/Stencil.cpp
index 235473b691878..9223b4a290a08 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -43,141 +43,6 @@ getNode(const ast_matchers::BoundNodes &Nodes, StringRef 
Id) {
   return It->second;
 }
 
-namespace {
-// An arbitrary fragment of code within a stencil.
-struct RawTextData {
-  explicit RawTextData(std::string T) : Text(std::move(T)) {}
-  std::string Text;
-};
-
-// A debugging operation to dump the AST for a particular (bound) AST node.
-struct DebugPrintNodeData {
-  explicit DebugPrintNodeData(std::string S) : Id(std::move(S)) {}
-  std::string Id;
-};
-
-// Operators that take a single node Id as an argument.
-enum class UnaryNodeOperator {
-  Parens,
-  Deref,
-  MaybeDeref,
-  AddressOf,
-  MaybeAddressOf,
-  Describe,
-};
-
-// Generic container for stencil operations with a (single) node-id argument.
-struct UnaryOperationData {
-  UnaryOperationData(UnaryNodeOperator Op, std::string Id)
-  : Op(Op), Id(std::move(Id)) {}
-  UnaryNodeOperator Op;
-  std::string Id;
-};
-
-// The fragment of code corresponding to the selected range.
-struct SelectorData {
-  explicit SelectorData(RangeSelector S) : Selector(std::move(S)) {}
-  RangeSelector Selector;
-};
-
-// A stencil operation to build a member access `e.m` or `e->m`, as 
appropriate.
-struct AccessData {
-  AccessData(StringRef BaseId, Stencil Member)
-  : BaseId(std::string(BaseId)), Member(std::move(Member)) {}
-  std::string BaseId;
-  Stencil Member;
-};
-
-struct IfBoundData {
-  IfBoundData(StringRef Id, Stencil TrueStencil, Stencil FalseStencil)
-  : Id(std::string(Id)), TrueStencil(std::move(TrueStencil)),
-FalseStencil(std::move(FalseStencil)) {}
-  std::string Id;
-  Stencil TrueStencil;
-  Stencil FalseStencil;
-};
-
-struct SequenceData {
-  SequenceData(std::vector Stencils) : Stencils(std::move(Stencils)) 
{}
-  std::vector Stencils;
-};
-
-std::string toStringData(const RawTextData &Data) {
-  std::string Result;
-  llvm::raw_string_ostream OS(Result);
-  OS << "\"";
-  OS.write_escaped(Data.Text);
-  OS << "\"";
-  OS.flush();
-  return Result;
-}
-
-std::string toStringData(const DebugPrintNodeData &Data) {
-  return (llvm::Twine("dPrint(\"") + Data.Id + "\")").str();
-}
-
-std::string toStringData(const UnaryOperationData &Data) {
-  StringRef OpName;
-  switch (Data.Op) {
-  case UnaryNodeOperator::Parens:
-OpName = "expression";
-break;
-  case UnaryNodeOperator::Deref:
-OpName = "deref";
-break;
-  case UnaryNodeOperator::MaybeDeref:
-OpName = "maybeDeref";
-break;
-  case UnaryNodeOperator::AddressOf:
-OpName = "addressOf";
-break;
-  case UnaryNodeOperator::MaybeAddressOf:
-OpName = "maybeAddressOf";
-break;
-  case UnaryNodeOperator::Describe:
-OpName = "describe";
-break;
-  }
-  return (OpName + "(\"" + Data.Id + "\")").str();
-}
-
-std::string toStringData(const SelectorData &) { return "selection(...)"; }
-
-std::string toStringData(const AccessData &Data) {
-  return (llvm::Twine("access(\"") + Data.BaseId + "\", " +
-  Data.Member->toString() + ")")
-  .str();
-}
-
-std::string toStringData(const IfBoundData &Data) {
-  return (llvm::Twine("ifBound(\"") + Data.Id + "\", " +
-  Data.TrueStencil->toString() + ", " + Data.FalseStencil->toString() +
-  ")")
-  .str();
-}
-
-std::string toStringData(const MatchConsumer &) {
-  return "run(...)";
-}
-
-std::string toStringData(const SequenceData &Data) {
-  llvm::SmallVector Parts;
-  Parts.reserve(Data.Stencils.size());
-  for (const auto &S : Data.Stencils)
-Parts.push_back(S->toString());
-  return (llvm::Twine("seq(") + llvm::join(Parts, ", ") + ")").str();
-}
-
-// The `evalData()` overloads evaluate the given stencil data to a string, 
given
-// the match result, and append it to `Result`. We define an overload for each
-// type of stencil data.
-
-Error evalData(const RawTextData &Data, const MatchFinder::MatchResult &,
-

[PATCH] D104317: [libTooling][NFC] Refactor implemenation of Transformer Stencils to use standard OOP

2021-06-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf387c8545d3a: [libTooling][NFC] Refactor implemenation of 
Transformer Stencils to use… (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104317

Files:
  clang/lib/Tooling/Transformer/Stencil.cpp

Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -43,141 +43,6 @@
   return It->second;
 }
 
-namespace {
-// An arbitrary fragment of code within a stencil.
-struct RawTextData {
-  explicit RawTextData(std::string T) : Text(std::move(T)) {}
-  std::string Text;
-};
-
-// A debugging operation to dump the AST for a particular (bound) AST node.
-struct DebugPrintNodeData {
-  explicit DebugPrintNodeData(std::string S) : Id(std::move(S)) {}
-  std::string Id;
-};
-
-// Operators that take a single node Id as an argument.
-enum class UnaryNodeOperator {
-  Parens,
-  Deref,
-  MaybeDeref,
-  AddressOf,
-  MaybeAddressOf,
-  Describe,
-};
-
-// Generic container for stencil operations with a (single) node-id argument.
-struct UnaryOperationData {
-  UnaryOperationData(UnaryNodeOperator Op, std::string Id)
-  : Op(Op), Id(std::move(Id)) {}
-  UnaryNodeOperator Op;
-  std::string Id;
-};
-
-// The fragment of code corresponding to the selected range.
-struct SelectorData {
-  explicit SelectorData(RangeSelector S) : Selector(std::move(S)) {}
-  RangeSelector Selector;
-};
-
-// A stencil operation to build a member access `e.m` or `e->m`, as appropriate.
-struct AccessData {
-  AccessData(StringRef BaseId, Stencil Member)
-  : BaseId(std::string(BaseId)), Member(std::move(Member)) {}
-  std::string BaseId;
-  Stencil Member;
-};
-
-struct IfBoundData {
-  IfBoundData(StringRef Id, Stencil TrueStencil, Stencil FalseStencil)
-  : Id(std::string(Id)), TrueStencil(std::move(TrueStencil)),
-FalseStencil(std::move(FalseStencil)) {}
-  std::string Id;
-  Stencil TrueStencil;
-  Stencil FalseStencil;
-};
-
-struct SequenceData {
-  SequenceData(std::vector Stencils) : Stencils(std::move(Stencils)) {}
-  std::vector Stencils;
-};
-
-std::string toStringData(const RawTextData &Data) {
-  std::string Result;
-  llvm::raw_string_ostream OS(Result);
-  OS << "\"";
-  OS.write_escaped(Data.Text);
-  OS << "\"";
-  OS.flush();
-  return Result;
-}
-
-std::string toStringData(const DebugPrintNodeData &Data) {
-  return (llvm::Twine("dPrint(\"") + Data.Id + "\")").str();
-}
-
-std::string toStringData(const UnaryOperationData &Data) {
-  StringRef OpName;
-  switch (Data.Op) {
-  case UnaryNodeOperator::Parens:
-OpName = "expression";
-break;
-  case UnaryNodeOperator::Deref:
-OpName = "deref";
-break;
-  case UnaryNodeOperator::MaybeDeref:
-OpName = "maybeDeref";
-break;
-  case UnaryNodeOperator::AddressOf:
-OpName = "addressOf";
-break;
-  case UnaryNodeOperator::MaybeAddressOf:
-OpName = "maybeAddressOf";
-break;
-  case UnaryNodeOperator::Describe:
-OpName = "describe";
-break;
-  }
-  return (OpName + "(\"" + Data.Id + "\")").str();
-}
-
-std::string toStringData(const SelectorData &) { return "selection(...)"; }
-
-std::string toStringData(const AccessData &Data) {
-  return (llvm::Twine("access(\"") + Data.BaseId + "\", " +
-  Data.Member->toString() + ")")
-  .str();
-}
-
-std::string toStringData(const IfBoundData &Data) {
-  return (llvm::Twine("ifBound(\"") + Data.Id + "\", " +
-  Data.TrueStencil->toString() + ", " + Data.FalseStencil->toString() +
-  ")")
-  .str();
-}
-
-std::string toStringData(const MatchConsumer &) {
-  return "run(...)";
-}
-
-std::string toStringData(const SequenceData &Data) {
-  llvm::SmallVector Parts;
-  Parts.reserve(Data.Stencils.size());
-  for (const auto &S : Data.Stencils)
-Parts.push_back(S->toString());
-  return (llvm::Twine("seq(") + llvm::join(Parts, ", ") + ")").str();
-}
-
-// The `evalData()` overloads evaluate the given stencil data to a string, given
-// the match result, and append it to `Result`. We define an overload for each
-// type of stencil data.
-
-Error evalData(const RawTextData &Data, const MatchFinder::MatchResult &,
-   std::string *Result) {
-  Result->append(Data.Text);
-  return Error::success();
-}
-
 static Error printNode(StringRef Id, const MatchFinder::MatchResult &Match,
std::string *Result) {
   std::string Output;
@@ -190,11 +55,6 @@
   return Error::success();
 }
 
-Error evalData(const DebugPrintNodeData &Data,
-   const MatchFinder::MatchResult &Match, std::string *Result) {
-  return printNode(Data.Id, Match, Result);
-}
-
 // FIXME: Consider memoizing this function using the `ASTContext`.
 static bool isSmartPointerType(QualType Ty, ASTContext 

[PATCH] D104388: [clang-format] PR50727 C# Invoke Lamda Expression indentation incorrect

2021-06-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 352444.
MyDeveloperDay added a comment.

I wanted to add some more tests and this really only manifested itself using 
`lock` and `using`  although the use of them is not generally broken when not 
using them in a Lambda expression


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

https://reviews.llvm.org/D104388

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -640,6 +640,76 @@
 };
 })",
MicrosoftStyle);
+
+  verifyFormat("void bar()\n"
+   "{\n"
+   "Function(Val, (Action)(() => {\n"
+   " lock (mylock)\n"
+   " {\n"
+   " if (true)\n"
+   " {\n"
+   " A.Remove(item);\n"
+   " }\n"
+   " }\n"
+   " }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+   "{\n"
+   "Function(Val, (Action)(() => {\n"
+   " using (var a = new Lock())\n"
+   " {\n"
+   " if (true)\n"
+   " {\n"
+   " A.Remove(item);\n"
+   " }\n"
+   " }\n"
+   " }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+   "{\n"
+   "Function(Val, (Action)(() => {\n"
+   " if (true)\n"
+   " {\n"
+   " A.Remove(item);\n"
+   " }\n"
+   " }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+   "{\n"
+   "Function(Val, (Action)(() => {\n"
+   " do\n"
+   " {\n"
+   " A.Remove(item);\n"
+   " } while (true)\n"
+   " }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+   "{\n"
+   "Function(Val, (Action)(() => { A.Remove(item); }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void bar()\n"
+   "{\n"
+   "Function(Val, (() => {\n"
+   " lock (mylock)\n"
+   " {\n"
+   " if (true)\n"
+   " {\n"
+   " A.Remove(item);\n"
+   " }\n"
+   " }\n"
+   " }));\n"
+   "}",
+   MicrosoftStyle);
 }
 
 TEST_F(FormatTestCSharp, CSharpObjectInitializers) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1927,6 +1927,12 @@
 parseBracedList();
   }
   break;
+case tok::equal:
+  if (Style.isCSharp() && FormatTok->is(TT_FatArrow))
+parseBracedList();
+  else
+nextToken();
+  break;
 case tok::kw_class:
   if (Style.Language == FormatStyle::LK_JavaScript)
 parseRecord(/*ParseAsExpr=*/true);


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -640,6 +640,76 @@
 };
 })",
MicrosoftStyle);
+
+  verifyFormat("void bar()\n"
+   "{\n"
+   "Function(Val, (Action)(() => {\n"
+   " lock (mylock)\n"
+   " {\n"
+   " if (true)\n"
+   " {\n"
+   " A.Remove(item);\n"
+   " }\n"
+   " }\n"
+   " }));\n"
+   "}",
+   MicrosoftStyle);
+
+  verifyFormat("void baz()\n"
+   "{\n"
+   "Function(Val, (Action)(() => {\n"
+   " using (var a = new Lock())\n"
+   " {\n"
+   " 

[PATCH] D104389: [ASTMatchers] Fix bug in `hasUnaryOperand`

2021-06-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: gribozavr2.
ymandel requested review of this revision.
Herald added a project: clang.

Currently, `hasUnaryOperand` fails for the overloaded `operator*`. This patch 
fixes the bug and
adds tests for this case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104389

Files:
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1893,6 +1893,23 @@
  cxxOperatorCallExpr(
  forFunction(functionDecl(hasName("plusIntOperator"))),
  hasOperatorName("+"), hasUnaryOperand(expr());
+
+  Code = R"cpp(
+struct HasOpArrow
+{
+int& operator*();
+};
+void foo()
+{
+HasOpArrow s1;
+*s1;
+}
+)cpp";
+
+  EXPECT_TRUE(
+  matches(Code, traverse(TK_IgnoreUnlessSpelledInSource,
+ cxxOperatorCallExpr(hasOperatorName("*"),
+ hasUnaryOperand(expr());
 }
 
 TEST(Matcher, UnaryOperatorTypes) {
Index: clang/include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -2102,6 +2102,8 @@
 return UO_Minus;
   case OO_Amp:
 return UO_AddrOf;
+  case OO_Star:
+return UO_Deref;
   case OO_Tilde:
 return UO_Not;
   case OO_Exclaim:


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1893,6 +1893,23 @@
  cxxOperatorCallExpr(
  forFunction(functionDecl(hasName("plusIntOperator"))),
  hasOperatorName("+"), hasUnaryOperand(expr());
+
+  Code = R"cpp(
+struct HasOpArrow
+{
+int& operator*();
+};
+void foo()
+{
+HasOpArrow s1;
+*s1;
+}
+)cpp";
+
+  EXPECT_TRUE(
+  matches(Code, traverse(TK_IgnoreUnlessSpelledInSource,
+ cxxOperatorCallExpr(hasOperatorName("*"),
+ hasUnaryOperand(expr());
 }
 
 TEST(Matcher, UnaryOperatorTypes) {
Index: clang/include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -2102,6 +2102,8 @@
 return UO_Minus;
   case OO_Amp:
 return UO_AddrOf;
+  case OO_Star:
+return UO_Deref;
   case OO_Tilde:
 return UO_Not;
   case OO_Exclaim:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93525: [clang-offload-bundler] Add unbundling of archives containing bundled object files into device specific archives

2021-06-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

Does this pass internal CI (ePSDB) ? I am concerned about the enforcement of 
the canonical format of target triple since this may break backward 
compatibility.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93525

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


[PATCH] D104390: [libTooling] Change `access` stencil to recognize use of `operator*`.

2021-06-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel created this revision.
ymandel added a reviewer: gribozavr2.
ymandel requested review of this revision.
Herald added a project: clang.

Currently, `access` doesn't recognize a dereferenced smart pointer. So,
`access(e, "field")` where `e = *x`, yields:

- `x->field`, for normal-pointer x,
- `(*x).field`, for smart-pointer x.

This patch normalizes handling of smart pointer to match normal pointer, when
the smart pointer type supports `->`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104390

Files:
  clang/lib/Tooling/Transformer/Stencil.cpp
  clang/unittests/Tooling/StencilTest.cpp


Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -407,7 +407,7 @@
 *x;
   )cc";
   StringRef Id = "id";
-  testExpr(Id, Snippet, access(Id, "field"), "(*x).field");
+  testExpr(Id, Snippet, access(Id, "field"), "x->field");
 }
 
 TEST_F(StencilTest, AccessOpSmartPointerMemberCall) {
Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -73,6 +73,25 @@
   return match(SmartPointer, Ty, Context).size() > 0;
 }
 
+static const Expr *isDereference(const Expr &E, ASTContext &Context) {
+  using namespace ::clang::ast_matchers;
+
+  const auto HasOverloadedArrow = cxxRecordDecl(hasMethod(cxxMethodDecl(
+  hasOverloadedOperatorName("->"), returns(qualType(pointsTo(type()));
+  auto Deref = expr(anyOf(
+  cxxOperatorCallExpr(hasOverloadedOperatorName("*"),
+  // FIXME: Use `hasUnaryOperand` once bug in
+  // `equivalentUnaryOperand` is fixed.
+  // hasArgument(0, expr().bind("arg"))
+  hasUnaryOperand(expr().bind("arg")),
+  callee(cxxMethodDecl(ofClass(HasOverloadedArrow,
+  unaryOperator(hasOperatorName("*"),
+hasUnaryOperand(expr().bind("arg");
+  auto matches = match(Deref, E, Context);
+  llvm::errs() << "num matches = " << matches.size() << "\n";
+  return selectFirst("arg", matches);
+}
+
 namespace {
 // An arbitrary fragment of code within a stencil.
 class RawTextStencil : public StencilInterface {
@@ -309,6 +328,8 @@
   }
 }
 S = tooling::buildArrow(*E, *Match.Context);
+  } else if (const auto *Operand = isDereference(*E, *Match.Context)) {
+S = tooling::buildArrow(*Operand, *Match.Context);
   } else {
 S = tooling::buildDot(*E, *Match.Context);
   }


Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -407,7 +407,7 @@
 *x;
   )cc";
   StringRef Id = "id";
-  testExpr(Id, Snippet, access(Id, "field"), "(*x).field");
+  testExpr(Id, Snippet, access(Id, "field"), "x->field");
 }
 
 TEST_F(StencilTest, AccessOpSmartPointerMemberCall) {
Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -73,6 +73,25 @@
   return match(SmartPointer, Ty, Context).size() > 0;
 }
 
+static const Expr *isDereference(const Expr &E, ASTContext &Context) {
+  using namespace ::clang::ast_matchers;
+
+  const auto HasOverloadedArrow = cxxRecordDecl(hasMethod(cxxMethodDecl(
+  hasOverloadedOperatorName("->"), returns(qualType(pointsTo(type()));
+  auto Deref = expr(anyOf(
+  cxxOperatorCallExpr(hasOverloadedOperatorName("*"),
+  // FIXME: Use `hasUnaryOperand` once bug in
+  // `equivalentUnaryOperand` is fixed.
+  // hasArgument(0, expr().bind("arg"))
+  hasUnaryOperand(expr().bind("arg")),
+  callee(cxxMethodDecl(ofClass(HasOverloadedArrow,
+  unaryOperator(hasOperatorName("*"),
+hasUnaryOperand(expr().bind("arg");
+  auto matches = match(Deref, E, Context);
+  llvm::errs() << "num matches = " << matches.size() << "\n";
+  return selectFirst("arg", matches);
+}
+
 namespace {
 // An arbitrary fragment of code within a stencil.
 class RawTextStencil : public StencilInterface {
@@ -309,6 +328,8 @@
   }
 }
 S = tooling::buildArrow(*E, *Match.Context);
+  } else if (const auto *Operand = isDereference(*E, *Match.Context)) {
+S = tooling::buildArrow(*Operand, *Match.Context);
   } else {
 S = tooling::buildDot(*E, *Match.Context);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/li

[PATCH] D104390: [libTooling] Change `access` stencil to recognize use of `operator*`.

2021-06-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 352450.
ymandel added a comment.

cleanup tweaks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104390

Files:
  clang/lib/Tooling/Transformer/Stencil.cpp
  clang/unittests/Tooling/StencilTest.cpp


Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -407,7 +407,7 @@
 *x;
   )cc";
   StringRef Id = "id";
-  testExpr(Id, Snippet, access(Id, "field"), "(*x).field");
+  testExpr(Id, Snippet, access(Id, "field"), "x->field");
 }
 
 TEST_F(StencilTest, AccessOpSmartPointerMemberCall) {
Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -73,6 +73,21 @@
   return match(SmartPointer, Ty, Context).size() > 0;
 }
 
+static const Expr *isDereference(const Expr &E, ASTContext &Context) {
+  using namespace ::clang::ast_matchers;
+
+  const auto HasOverloadedArrow = cxxRecordDecl(hasMethod(cxxMethodDecl(
+  hasOverloadedOperatorName("->"), returns(qualType(pointsTo(type()));
+  auto Deref = expr(anyOf(
+  cxxOperatorCallExpr(hasOverloadedOperatorName("*"),
+  hasUnaryOperand(expr().bind("arg")),
+  callee(cxxMethodDecl(ofClass(HasOverloadedArrow,
+  unaryOperator(hasOperatorName("*"),
+hasUnaryOperand(expr().bind("arg");
+  auto matches = match(Deref, E, Context);
+  return selectFirst("arg", matches);
+}
+
 namespace {
 // An arbitrary fragment of code within a stencil.
 class RawTextStencil : public StencilInterface {
@@ -309,6 +324,8 @@
   }
 }
 S = tooling::buildArrow(*E, *Match.Context);
+  } else if (const auto *Operand = isDereference(*E, *Match.Context)) {
+S = tooling::buildArrow(*Operand, *Match.Context);
   } else {
 S = tooling::buildDot(*E, *Match.Context);
   }


Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -407,7 +407,7 @@
 *x;
   )cc";
   StringRef Id = "id";
-  testExpr(Id, Snippet, access(Id, "field"), "(*x).field");
+  testExpr(Id, Snippet, access(Id, "field"), "x->field");
 }
 
 TEST_F(StencilTest, AccessOpSmartPointerMemberCall) {
Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -73,6 +73,21 @@
   return match(SmartPointer, Ty, Context).size() > 0;
 }
 
+static const Expr *isDereference(const Expr &E, ASTContext &Context) {
+  using namespace ::clang::ast_matchers;
+
+  const auto HasOverloadedArrow = cxxRecordDecl(hasMethod(cxxMethodDecl(
+  hasOverloadedOperatorName("->"), returns(qualType(pointsTo(type()));
+  auto Deref = expr(anyOf(
+  cxxOperatorCallExpr(hasOverloadedOperatorName("*"),
+  hasUnaryOperand(expr().bind("arg")),
+  callee(cxxMethodDecl(ofClass(HasOverloadedArrow,
+  unaryOperator(hasOperatorName("*"),
+hasUnaryOperand(expr().bind("arg");
+  auto matches = match(Deref, E, Context);
+  return selectFirst("arg", matches);
+}
+
 namespace {
 // An arbitrary fragment of code within a stencil.
 class RawTextStencil : public StencilInterface {
@@ -309,6 +324,8 @@
   }
 }
 S = tooling::buildArrow(*E, *Match.Context);
+  } else if (const auto *Operand = isDereference(*E, *Match.Context)) {
+S = tooling::buildArrow(*Operand, *Match.Context);
   } else {
 S = tooling::buildDot(*E, *Match.Context);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104390: [libTooling] Change `access` stencil to recognize use of `operator*`.

2021-06-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 352453.
ymandel added a comment.

add comments and simplify.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104390

Files:
  clang/lib/Tooling/Transformer/Stencil.cpp
  clang/unittests/Tooling/StencilTest.cpp


Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -407,7 +407,7 @@
 *x;
   )cc";
   StringRef Id = "id";
-  testExpr(Id, Snippet, access(Id, "field"), "(*x).field");
+  testExpr(Id, Snippet, access(Id, "field"), "x->field");
 }
 
 TEST_F(StencilTest, AccessOpSmartPointerMemberCall) {
Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -73,6 +73,21 @@
   return match(SmartPointer, Ty, Context).size() > 0;
 }
 
+// Identifies use of `operator*` on smart pointers, and returns the underlying
+// smart-pointer expression; otherwise, returns null.
+static const Expr *isSmartDereference(const Expr &E, ASTContext &Context) {
+  using namespace ::clang::ast_matchers;
+
+  const auto HasOverloadedArrow = cxxRecordDecl(hasMethod(cxxMethodDecl(
+  hasOverloadedOperatorName("->"), returns(qualType(pointsTo(type()));
+  // Verify it is a smart pointer by finding `operator->` in the class
+  // declaration.
+  auto Deref = cxxOperatorCallExpr(
+  hasOverloadedOperatorName("*"), hasUnaryOperand(expr().bind("arg")),
+  callee(cxxMethodDecl(ofClass(HasOverloadedArrow;
+  return selectFirst("arg", match(Deref, E, Context));
+}
+
 namespace {
 // An arbitrary fragment of code within a stencil.
 class RawTextStencil : public StencilInterface {
@@ -309,6 +324,10 @@
   }
 }
 S = tooling::buildArrow(*E, *Match.Context);
+  } else if (const auto *Operand = isSmartDereference(*E, *Match.Context)) 
{
+// `buildDot` already handles the built-in dereference operator, so we
+// only need to catch overloaded `operator*`.
+S = tooling::buildArrow(*Operand, *Match.Context);
   } else {
 S = tooling::buildDot(*E, *Match.Context);
   }


Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -407,7 +407,7 @@
 *x;
   )cc";
   StringRef Id = "id";
-  testExpr(Id, Snippet, access(Id, "field"), "(*x).field");
+  testExpr(Id, Snippet, access(Id, "field"), "x->field");
 }
 
 TEST_F(StencilTest, AccessOpSmartPointerMemberCall) {
Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -73,6 +73,21 @@
   return match(SmartPointer, Ty, Context).size() > 0;
 }
 
+// Identifies use of `operator*` on smart pointers, and returns the underlying
+// smart-pointer expression; otherwise, returns null.
+static const Expr *isSmartDereference(const Expr &E, ASTContext &Context) {
+  using namespace ::clang::ast_matchers;
+
+  const auto HasOverloadedArrow = cxxRecordDecl(hasMethod(cxxMethodDecl(
+  hasOverloadedOperatorName("->"), returns(qualType(pointsTo(type()));
+  // Verify it is a smart pointer by finding `operator->` in the class
+  // declaration.
+  auto Deref = cxxOperatorCallExpr(
+  hasOverloadedOperatorName("*"), hasUnaryOperand(expr().bind("arg")),
+  callee(cxxMethodDecl(ofClass(HasOverloadedArrow;
+  return selectFirst("arg", match(Deref, E, Context));
+}
+
 namespace {
 // An arbitrary fragment of code within a stencil.
 class RawTextStencil : public StencilInterface {
@@ -309,6 +324,10 @@
   }
 }
 S = tooling::buildArrow(*E, *Match.Context);
+  } else if (const auto *Operand = isSmartDereference(*E, *Match.Context)) {
+// `buildDot` already handles the built-in dereference operator, so we
+// only need to catch overloaded `operator*`.
+S = tooling::buildArrow(*Operand, *Match.Context);
   } else {
 S = tooling::buildDot(*E, *Match.Context);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98895: [X86][Draft] Disable long double type for -mno-x87 option

2021-06-16 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic added a comment.

@erichkeane, can you please check if this patch is OK for Clang?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98895

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


[PATCH] D104392: [HIP] Add support functions for C++ polymorphic types

2021-06-16 Thread Siu Chi Chan via Phabricator via cfe-commits
scchan created this revision.
scchan added a reviewer: yaxunl.
scchan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Add runtime functions to detect invalid calls to pure or deleted virtual
functions


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104392

Files:
  clang/lib/Headers/__clang_hip_runtime_wrapper.h


Index: clang/lib/Headers/__clang_hip_runtime_wrapper.h
===
--- clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -51,6 +51,23 @@
   #define nullptr NULL;
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_pure_virtual(void) {
+__builtin_trap();
+  }
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_deleted_virtual(void) {
+__builtin_trap();
+  } 
+}
+#endif //__cplusplus
+
 #if __HIP_ENABLE_DEVICE_MALLOC__
 extern "C" __device__ void *__hip_malloc(size_t __size);
 extern "C" __device__ void *__hip_free(void *__ptr);


Index: clang/lib/Headers/__clang_hip_runtime_wrapper.h
===
--- clang/lib/Headers/__clang_hip_runtime_wrapper.h
+++ clang/lib/Headers/__clang_hip_runtime_wrapper.h
@@ -51,6 +51,23 @@
   #define nullptr NULL;
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_pure_virtual(void) {
+__builtin_trap();
+  }
+  __attribute__((__visibility__("default")))
+  __attribute__((weak))
+  __attribute__((noreturn))
+  __device__ void __cxa_deleted_virtual(void) {
+__builtin_trap();
+  } 
+}
+#endif //__cplusplus
+
 #if __HIP_ENABLE_DEVICE_MALLOC__
 extern "C" __device__ void *__hip_malloc(size_t __size);
 extern "C" __device__ void *__hip_free(void *__ptr);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98895: [X86][Draft] Disable long double type for -mno-x87 option

2021-06-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

This seems to do a lot of work that I think already exists, I believe I've seen 
that SPIRV targets already prohibit long-double, so doing another 
implementation specifically for x86 seems like the wrong approach.  I'd suggest 
seeing if the SPIRV version works for these.  If it doesn't, I'd prefer you 
generalize that implementation.




Comment at: clang/include/clang/Basic/TargetInfo.h:599
+  /// Determine whether the long double type is supported on this target.
+  virtual bool hasLongDoubleType() const { return HasLongDouble; }
+

I think SPIR targets already do something like this, can you check and see how 
they do it instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98895

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


[PATCH] D103967: [Analyzer][solver] Add dump methods for (dis)equality classes.

2021-06-16 Thread Gabor Marton via Phabricator via cfe-commits
martong updated this revision to Diff 352464.
martong added a comment.

- Extend printJson to handle equivalency info


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103967

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/expr-inspection-printState-diseq-info.c
  clang/test/Analysis/expr-inspection-printState-eq-classes.c
  clang/test/Analysis/expr-inspection.c

Index: clang/test/Analysis/expr-inspection.c
===
--- clang/test/Analysis/expr-inspection.c
+++ clang/test/Analysis/expr-inspection.c
@@ -38,6 +38,8 @@
 // CHECK-NEXT:   "constraints": [
 // CHECK-NEXT: { "symbol": "reg_$0", "range": "{ [-2147483648, 13] }" }
 // CHECK-NEXT:   ],
+// CHECK-NEXT:   "equivalence_classes": null,
+// CHECK-NEXT:   "disequality_info": null,
 // CHECK-NEXT:   "dynamic_types": null,
 // CHECK-NEXT:   "dynamic_casts": null,
 // CHECK-NEXT:   "constructing_objects": null,
Index: clang/test/Analysis/expr-inspection-printState-eq-classes.c
===
--- /dev/null
+++ clang/test/Analysis/expr-inspection-printState-eq-classes.c
@@ -0,0 +1,21 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=debug.ExprInspection %s 2>&1 | FileCheck %s
+
+void clang_analyzer_printState();
+
+void test_equivalence_classes(int a, int b, int c, int d) {
+  if (a + b != c)
+return;
+  if (a != d)
+return;
+  if (b != 0)
+return;
+  clang_analyzer_printState();
+  (void)(a * b * c * d);
+  return;
+}
+
+// CHECK:   "equivalence_classes": [
+// CHECK-NEXT:[ "reg_$0", "(reg_$0) + (reg_$1)", "reg_$2", "reg_$3" ],
+// CHECK-NEXT:[ "((reg_$0) + (reg_$1)) != (reg_$2)", "(reg_$0) != (reg_$2)" ]
+// CHECK-NEXT:  ],
Index: clang/test/Analysis/expr-inspection-printState-diseq-info.c
===
--- /dev/null
+++ clang/test/Analysis/expr-inspection-printState-diseq-info.c
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 \
+// RUN:  -analyzer-checker=debug.ExprInspection %s 2>&1 | FileCheck %s
+
+void clang_analyzer_printState();
+
+void test_disequality_info(int e0, int b0, int b1, int c0) {
+  int e1 = e0 - b0;
+  if (b0 == 2) {
+int e2 = e1 - b1;
+if (e2 > 0) {
+  if (b1 != c0)
+clang_analyzer_printState();
+}
+  }
+}
+
+// CHECK:   "disequality_info": [
+// CHECK-NEXT:{
+// CHECK-NEXT:  "class": [ "reg_$2" ],
+// CHECK-NEXT:  "disequal_to": [
+// CHECK-NEXT:[ "(reg_$0) - 2" ],
+// CHECK-NEXT:[ "reg_$3" ]]
+// CHECK-NEXT:},
+// CHECK-NEXT:{
+// CHECK-NEXT:  "class": [ "(reg_$0) - 2" ],
+// CHECK-NEXT:  "disequal_to": [
+// CHECK-NEXT:[ "reg_$2" ]]
+// CHECK-NEXT:},
+// CHECK-NEXT:{
+// CHECK-NEXT:  "class": [ "reg_$3" ],
+// CHECK-NEXT:  "disequal_to": [
+// CHECK-NEXT:[ "reg_$2" ]]
+// CHECK-NEXT:}
+// CHECK-NEXT:  ],
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -594,6 +594,11 @@
   RangeSet::Factory &F,
   ProgramStateRef State);
 
+  void dumpToStream(ProgramStateRef State, raw_ostream &os) const;
+  LLVM_DUMP_METHOD void dump(ProgramStateRef State) const {
+dumpToStream(State, llvm::errs());
+  }
+
   /// Check equivalence data for consistency.
   LLVM_NODISCARD LLVM_ATTRIBUTE_UNUSED static bool
   isClassDataConsistent(ProgramStateRef State);
@@ -1420,6 +1425,17 @@
 
   void printJson(raw_ostream &Out, ProgramStateRef State, const char *NL = "\n",
  unsigned int Space = 0, bool IsDot = false) const override;
+  void printConstraints(raw_ostream &Out, ProgramStateRef State,
+const char *NL = "\n", unsigned int Space = 0,
+bool IsDot = false) const;
+  void printEquivalenceClasses(raw_ostream &Out, ProgramStateRef State,
+   const char *NL = "\n", unsigned int Space = 0,
+   bool IsDot = false) const;
+  void printEquivalenceClass(raw_ostream &Out, ProgramStateRef State,
+ EquivalenceClass Class) const;
+  void printDisequalities(raw_ostream &Out, ProgramStateRef State,
+  const char *NL = "\n", unsigned int Space = 0,
+  bool IsDot = false) const;
 
   //===--===//
   // Implementation for interface from RangedConstraintManager.
@@ -1646,6 +1662,15 @@
 // EqualityClass implementation details
 //===-

[PATCH] D103967: [Analyzer][solver] Add dump methods for (dis)equality classes.

2021-06-16 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D103967#2809590 , @NoQ wrote:

> Yes we should definitely have as much as possible in the state dump.

Okay, I've updated likewise and added two test files to check them in 
State->dump.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103967

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


[PATCH] D103967: [Analyzer][solver] Add dump methods for (dis)equality classes.

2021-06-16 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

I suspect that the exploded-graph-rewriter should be updated as well so that 
the HTML dumps also carry this information.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103967

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


[PATCH] D104392: [HIP] Add support functions for C++ polymorphic types

2021-06-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

can you add a test to 
https://github.com/llvm/llvm-project/blob/main/clang/test/Headers/hip-header.hip


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104392

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


[PATCH] D104387: [clang-cl] Implement /external:I, /external:env, and EXTERNAL_INCLUDE support (PR36003)

2021-06-16 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Nice, that's much less convoluted than I had feared :)




Comment at: clang/lib/Driver/ToolChains/MSVC.cpp:1255
+}
+  }
+

`/external:env` should happen after winsysroot I think. sysroots try to make 
builds hermetic and env vars defeat that.

I.e. this flag is more like the env var reads below than imsvc above – it reads 
the env mostly, instead of being a flag mostly.



Comment at: clang/lib/Driver/ToolChains/MSVC.cpp:1266
+llvm::Optional include_var =
+llvm::sys::Process::GetEnv("INCLUDE");
+llvm::Optional ext_include_var =

Maybe this should grow a FIXME to make regular INCLUDE not a system include at 
some point? Kind of sounds like this is the direction msvc is moving in with 
the existence of EXTERNAL_INCLUDE at least.



Comment at: clang/test/Driver/cl-include.c:10
 
-// RUN: env INCLUDE=/my/system/inc %clang_cl -### -- %s 2>&1 | FileCheck %s 
--check-prefix=STDINC
+// RUN: env INCLUDE=/my/system/inc env EXTERNAL_INCLUDE=/my/system/inc2 
%clang_cl -### -- %s 2>&1 | FileCheck %s --check-prefix=STDINC
 // STDINC: "-internal-isystem" "/my/system/inc"

Should there be tests for the interaction with `/X`, `/winsysroot:`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104387

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


[PATCH] D104348: [index] Fix performance regression with indexing macros

2021-06-16 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman accepted this revision.
arphaman added a comment.
This revision is now accepted and ready to land.

Thanks, LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104348

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


[clang] 773ad55 - [index] Fix performance regression with indexing macros

2021-06-16 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2021-06-16T10:16:26-07:00
New Revision: 773ad55a393f368cc92b1611c52e493ed45a353f

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

LOG: [index] Fix performance regression with indexing macros

When using FileIndexRecord with macros, symbol references can be seen
out of source order, which was causing a regression to insert the
symbols into a vector. Instead, we now lazily sort the vector. The
impact is small on most code, but in very large files with many macro
references (M) near the beginning of the file followed by many decl
references (D) it was O(M*D). A particularly bad protobuf-generated
header was observed with a 100% regression in practice.

rdar://78628133

Added: 


Modified: 
clang/lib/Index/FileIndexRecord.cpp
clang/lib/Index/FileIndexRecord.h

Removed: 




diff  --git a/clang/lib/Index/FileIndexRecord.cpp 
b/clang/lib/Index/FileIndexRecord.cpp
index 950a99a2304b..d392a2bedeba 100644
--- a/clang/lib/Index/FileIndexRecord.cpp
+++ b/clang/lib/Index/FileIndexRecord.cpp
@@ -17,23 +17,16 @@
 using namespace clang;
 using namespace clang::index;
 
-static void addOccurrence(std::vector &Decls,
-  DeclOccurrence Info) {
-  auto IsNextOccurence = [&]() -> bool {
-if (Decls.empty())
-  return true;
-auto &Last = Decls.back();
-return Last.Offset < Info.Offset;
-  };
-
-  if (IsNextOccurence()) {
-Decls.push_back(std::move(Info));
-return;
+ArrayRef
+FileIndexRecord::getDeclOccurrencesSortedByOffset() const {
+  if (!IsSorted) {
+llvm::stable_sort(Decls,
+  [](const DeclOccurrence &A, const DeclOccurrence &B) {
+return A.Offset < B.Offset;
+  });
+IsSorted = true;
   }
-
-  // We keep Decls in order as we need to access them in this order in all 
cases.
-  auto It = llvm::upper_bound(Decls, Info);
-  Decls.insert(It, std::move(Info));
+  return Decls;
 }
 
 void FileIndexRecord::addDeclOccurence(SymbolRoleSet Roles, unsigned Offset,
@@ -41,13 +34,15 @@ void FileIndexRecord::addDeclOccurence(SymbolRoleSet Roles, 
unsigned Offset,
ArrayRef Relations) {
   assert(D->isCanonicalDecl() &&
  "Occurrences should be associated with their canonical decl");
-  addOccurrence(Decls, DeclOccurrence(Roles, Offset, D, Relations));
+  IsSorted = false;
+  Decls.emplace_back(Roles, Offset, D, Relations);
 }
 
 void FileIndexRecord::addMacroOccurence(SymbolRoleSet Roles, unsigned Offset,
 const IdentifierInfo *Name,
 const MacroInfo *MI) {
-  addOccurrence(Decls, DeclOccurrence(Roles, Offset, Name, MI));
+  IsSorted = false;
+  Decls.emplace_back(Roles, Offset, Name, MI);
 }
 
 void FileIndexRecord::removeHeaderGuardMacros() {

diff  --git a/clang/lib/Index/FileIndexRecord.h 
b/clang/lib/Index/FileIndexRecord.h
index 037f39f10aef..621d5b78977d 100644
--- a/clang/lib/Index/FileIndexRecord.h
+++ b/clang/lib/Index/FileIndexRecord.h
@@ -27,14 +27,13 @@ class FileIndexRecord {
 private:
   FileID FID;
   bool IsSystem;
-  std::vector Decls;
+  mutable bool IsSorted = false;
+  mutable std::vector Decls;
 
 public:
   FileIndexRecord(FileID FID, bool IsSystem) : FID(FID), IsSystem(IsSystem) {}
 
-  ArrayRef getDeclOccurrencesSortedByOffset() const {
-return Decls;
-  }
+  ArrayRef getDeclOccurrencesSortedByOffset() const;
 
   FileID getFileID() const { return FID; }
   bool isSystem() const { return IsSystem; }



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


[PATCH] D104348: [index] Fix performance regression with indexing macros

2021-06-16 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir closed this revision.
benlangmuir added a comment.

Pushed rG773ad55a393f 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104348

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


[PATCH] D104248: [compiler-rt][hwasan] Refactor Thread::Init

2021-06-16 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 352476.
leonardchan marked an inline comment as done.
leonardchan added a comment.

Rebased and formatted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104248

Files:
  compiler-rt/lib/hwasan/hwasan_linux.cpp
  compiler-rt/lib/hwasan/hwasan_thread.cpp
  compiler-rt/lib/hwasan/hwasan_thread.h


Index: compiler-rt/lib/hwasan/hwasan_thread.h
===
--- compiler-rt/lib/hwasan/hwasan_thread.h
+++ compiler-rt/lib/hwasan/hwasan_thread.h
@@ -23,8 +23,13 @@
 
 class Thread {
  public:
-  void Init(uptr stack_buffer_start, uptr stack_buffer_size);  // Must be 
called from the thread itself.
+  void Init(uptr stack_buffer_start, uptr stack_buffer_size);
   void InitRandomState();
+  void InitStackAndTls();
+
+  // Must be called from the thread itself.
+  void InitStackRingBuffer(uptr stack_buffer_start, uptr stack_buffer_size);
+
   void Destroy();
 
   uptr stack_top() { return stack_top_; }
Index: compiler-rt/lib/hwasan/hwasan_thread.cpp
===
--- compiler-rt/lib/hwasan/hwasan_thread.cpp
+++ compiler-rt/lib/hwasan/hwasan_thread.cpp
@@ -44,6 +44,12 @@
   if (auto sz = flags()->heap_history_size)
 heap_allocations_ = HeapAllocationsRingBuffer::New(sz);
 
+  InitStackAndTls();
+  InitStackRingBuffer(stack_buffer_start, stack_buffer_size);
+}
+
+void Thread::InitStackRingBuffer(uptr stack_buffer_start,
+ uptr stack_buffer_size) {
   HwasanTSDThreadInit();  // Only needed with interceptors.
   uptr *ThreadLong = GetCurrentThreadLongPtr();
   // The following implicitly sets (this) as the current thread.
@@ -55,13 +61,6 @@
   // ScopedTaggingDisable needs GetCurrentThread to be set up.
   ScopedTaggingDisabler disabler;
 
-  uptr tls_size;
-  uptr stack_size;
-  GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, 
&tls_begin_,
-   &tls_size);
-  stack_top_ = stack_bottom_ + stack_size;
-  tls_end_ = tls_begin_ + tls_size;
-
   if (stack_bottom_) {
 int local;
 CHECK(AddrIsInStack((uptr)&local));
Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -427,6 +427,14 @@
   HandleDeadlySignal(info, context, GetTid(), &OnStackUnwind, nullptr);
 }
 
+void Thread::InitStackAndTls() {
+  uptr tls_size;
+  uptr stack_size;
+  GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, 
&tls_begin_,
+   &tls_size);
+  stack_top_ = stack_bottom_ + stack_size;
+  tls_end_ = tls_begin_ + tls_size;
+}
 
 } // namespace __hwasan
 


Index: compiler-rt/lib/hwasan/hwasan_thread.h
===
--- compiler-rt/lib/hwasan/hwasan_thread.h
+++ compiler-rt/lib/hwasan/hwasan_thread.h
@@ -23,8 +23,13 @@
 
 class Thread {
  public:
-  void Init(uptr stack_buffer_start, uptr stack_buffer_size);  // Must be called from the thread itself.
+  void Init(uptr stack_buffer_start, uptr stack_buffer_size);
   void InitRandomState();
+  void InitStackAndTls();
+
+  // Must be called from the thread itself.
+  void InitStackRingBuffer(uptr stack_buffer_start, uptr stack_buffer_size);
+
   void Destroy();
 
   uptr stack_top() { return stack_top_; }
Index: compiler-rt/lib/hwasan/hwasan_thread.cpp
===
--- compiler-rt/lib/hwasan/hwasan_thread.cpp
+++ compiler-rt/lib/hwasan/hwasan_thread.cpp
@@ -44,6 +44,12 @@
   if (auto sz = flags()->heap_history_size)
 heap_allocations_ = HeapAllocationsRingBuffer::New(sz);
 
+  InitStackAndTls();
+  InitStackRingBuffer(stack_buffer_start, stack_buffer_size);
+}
+
+void Thread::InitStackRingBuffer(uptr stack_buffer_start,
+ uptr stack_buffer_size) {
   HwasanTSDThreadInit();  // Only needed with interceptors.
   uptr *ThreadLong = GetCurrentThreadLongPtr();
   // The following implicitly sets (this) as the current thread.
@@ -55,13 +61,6 @@
   // ScopedTaggingDisable needs GetCurrentThread to be set up.
   ScopedTaggingDisabler disabler;
 
-  uptr tls_size;
-  uptr stack_size;
-  GetThreadStackAndTls(IsMainThread(), &stack_bottom_, &stack_size, &tls_begin_,
-   &tls_size);
-  stack_top_ = stack_bottom_ + stack_size;
-  tls_end_ = tls_begin_ + tls_size;
-
   if (stack_bottom_) {
 int local;
 CHECK(AddrIsInStack((uptr)&local));
Index: compiler-rt/lib/hwasan/hwasan_linux.cpp
===
--- compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -427,6 +427,14 @@
   HandleDeadlySignal(info, context, GetTid(), &OnStackUnwind, nullptr);
 }
 
+void Thread::InitStack

[PATCH] D103850: [clang] diagnose instead of assert for defaulted comparison return type deduction.

2021-06-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/test/CXX/class/class.compare/class.spaceship/p2.cpp:200
+  struct b3 {
+auto operator<=>(b3 const &) const = default; // expected-error {{cannot 
be deduced because three-way comparison for member 'f' would compare as builtin 
type 'void (*)()' which is not currently supported}}
+// expected-warning@-1 {{implicitly deleted}}

I think three-way comparison for function pointers is ill-formed, and that the 
problem in this case is that [over.built] lists candidates for which a 
three-way comparison is invalid. So our overload resolution succeeds, but 
results in a meaningless builtin candidate with an undefined return type.

I think the behavior here after this patch is fine -- we should treat the 
comparison as deleted -- but the diagnostic is wrong. This isn't a "not 
currently supported" case, this is a "not a valid expression" case, per 
[class.compare.default]/3.2 (except that the wording currently gets this wrong 
and doesn't actually say what happens here, because we're actually in 
[class.compare.default]/3.1). Though perhaps the better fix would be to not 
even include a builtin candidate for `operator<=>(void (*)(), void (*)())`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103850

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


[PATCH] D103855: [clang] Exclude function pointers on DefaultedComparisonAnalyzer

2021-06-16 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

I think we need to take this to the C++ committee. For example, consider a case 
like:

  struct A {
using T1 = void(*)();
using T2 = int;
operator T1();
operator T2();
  };
  struct B {
A a;
friend auto operator<=>(B, B) = default;
  };

Under the standard rules, the `operator<=>` is deleted due to ambiguity, but 
with this change we'd unambiguously pick the conversion to `T2`. The old 
behavior here better matches the current standard wording -- in particular, the 
special case is in [class.compare.default]/3.2 and only applies when neither 
operand is of overloadable type -- but perhaps the right approach here would be 
to fix the language rules so that `operator<=>` is only provided for object 
pointer types, not for all pointer types, in general.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103855

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


[PATCH] D103850: [clang] diagnose instead of assert for defaulted comparison return type deduction.

2021-06-16 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/test/CXX/class/class.compare/class.spaceship/p2.cpp:200
+  struct b3 {
+auto operator<=>(b3 const &) const = default; // expected-error {{cannot 
be deduced because three-way comparison for member 'f' would compare as builtin 
type 'void (*)()' which is not currently supported}}
+// expected-warning@-1 {{implicitly deleted}}

rsmith wrote:
> I think three-way comparison for function pointers is ill-formed, and that 
> the problem in this case is that [over.built] lists candidates for which a 
> three-way comparison is invalid. So our overload resolution succeeds, but 
> results in a meaningless builtin candidate with an undefined return type.
> 
> I think the behavior here after this patch is fine -- we should treat the 
> comparison as deleted -- but the diagnostic is wrong. This isn't a "not 
> currently supported" case, this is a "not a valid expression" case, per 
> [class.compare.default]/3.2 (except that the wording currently gets this 
> wrong and doesn't actually say what happens here, because we're actually in 
> [class.compare.default]/3.1). Though perhaps the better fix would be to not 
> even include a builtin candidate for `operator<=>(void (*)(), void (*)())`?
Yeah this was part of my plan to give the correct diagnostic for function 
pointers in the next patch in the series:
https://reviews.llvm.org/D103855

The idea on this one is to produce an error, is the TU will not compile, for 
built-in types not supported.

After the next one, we just implicitly delete the comparison for function 
pointers, and leave the error for other unimplemented built-in types.

I think this makes more sense, even if we manage to implement this deduction 
for all built-in types currently available, it would still be too easy for 
another patch to introduce a new built-in types and forget to support it here.

And it does make sense to error on these cases than to simply pick an arbitrary 
answer and churn along, I think 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103850

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


[PATCH] D103136: [AVR] Add support for the tinyAVR 0-series and tinyAVR 1-seriesø

2021-06-16 Thread Justin Latimer via Phabricator via cfe-commits
justinlatimer added a comment.

@dylanmckay is there anything else I need to update on this patch? Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103136

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


[PATCH] D104096: [Clang-Format] Add ReferenceAlignment directive

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

In D104096#2820206 , @skirkovski 
wrote:

> Ping,
>
> I do not have commit access, can someone submit this as time permits ?

Please state the name and email for the commit, I will commit it on the weekend.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104096

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


[PATCH] D103855: [clang] Exclude function pointers on DefaultedComparisonAnalyzer

2021-06-16 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

I see. I can change this patch so it just implicitly deletes the operator in 
case we decide to pick function pointers, without the hard error introduced by 
the previous patch.
And if the comitee decides to stop providing relational operators for function 
pointers, we can revisit this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103855

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


[PATCH] D99439: Update @llvm.powi to handle different int sizes for the exponent

2021-06-16 Thread Bjorn Pettersson via Phabricator via cfe-commits
bjope added a comment.

ping!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99439

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


[PATCH] D104305: [flang][driver] Add `-fdebug-dump-all`

2021-06-16 Thread Peter Klausler via Phabricator via cfe-commits
klausler added a comment.

The non-shared-library build of the current llvm-project/main tree fails on 
this new test; it looks as if gfortran is being invoked and passed an option 
that it does not recognize.  The shared library build passes all tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104305

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


[PATCH] D104305: [flang][driver] Add `-fdebug-dump-all`

2021-06-16 Thread Pete Steinfeld via Phabricator via cfe-commits
PeteSteinfeld added a comment.

In D104305#2822589 , @klausler wrote:

> The non-shared-library build of the current llvm-project/main tree fails on 
> this new test; it looks as if gfortran is being invoked and passed an option 
> that it does not recognize.  The shared library build passes all tests.

Weird.  It worked for me.  Note that, if you're doing an out-of-tree build, you 
need to do a "make install" in your main build.  Then, in your out-of-tree 
build, you need to reference the directories from the "install" rather than the 
"build" directories.  Here's the cmake command I used for my out-of-tree build:

  cmake \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_EXTERNAL_LIT=/local/home/psteinfeld/main/clean/build/bin/llvm-lit \
-DLLVM_LIT_ARGS=-v \
-DFLANG_ENABLE_WERROR=On \
-DCMAKE_C_COMPILER=/home/sw/thirdparty/gcc/gcc-9.3.0/linux86-64/bin/gcc \
-DCMAKE_CXX_COMPILER=/home/sw/thirdparty/gcc/gcc-9.3.0/linux86-64/bin/g++ \
-DCMAKE_CXX_STANDARD=17 \
-DLLVM_TARGETS_TO_BUILD=host \
-DLLVM_ENABLE_ZLIB=OFF \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_CXX_LINK_FLAGS="-Wl,-rpath,$LD_LIBRARY_PATH" \
-DLLVM_MAIN_SRC_DIR=/local/home/psteinfeld/main/clean/llvm \
-DCLANG_DIR=/local/home/psteinfeld/main/clean/install/lib/cmake/clang \
-DLLVM_DIR=/local/home/psteinfeld/main/clean/install/lib/cmake/llvm \
-DMLIR_DIR=/local/home/psteinfeld/main/clean/install/lib/cmake/mlir \
..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104305

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


[PATCH] D104305: [flang][driver] Add `-fdebug-dump-all`

2021-06-16 Thread Peter Klausler via Phabricator via cfe-commits
klausler added a comment.

No; I'm hitting this problem with an in-tree static build of llvm-project/main. 
 Weird.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104305

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


[PATCH] D104248: [compiler-rt][hwasan] Refactor Thread::Init

2021-06-16 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added a reviewer: mcgrathr.
vitalybuka added inline comments.



Comment at: compiler-rt/lib/hwasan/hwasan_linux.cpp:430
 
+void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size) {
+  CHECK_EQ(0, unique_id_);  // try to catch bad stack reuse

mcgrathr wrote:
> vitalybuka wrote:
> > leonardchan wrote:
> > > leonardchan wrote:
> > > > mcgrathr wrote:
> > > > > Most of this code can actually be reused for Fuchsia (just not 
> > > > > necessarily in Thread::Init).
> > > > > It's probably better to split it up for reuse rather than just moving 
> > > > > the whole thing to linux-specific.
> > > > So maybe something like the current patch? Then on Fuchsia we could (1) 
> > > > have a custom implementation of `InitStackAndTls`, (2) wrap the call to 
> > > > `Thread::InitStackRingBuffer` in `Thread::Init` with a `#if 
> > > > SANITIZER_FUCHSIA` so it's not called before thread creation, then (2) 
> > > > call `Thread::InitStackRingBuffer` in the 
> > > > `__sanitizer_thread_start_hook` hook.
> > > Sorry. Meant wrapping with a `#if !SANITIZER_FUCHSIA`.
> > in other sanitizers only GetThreadStackAndTls is platform specific
> > 
> > in other sanitizers only GetThreadStackAndTls is platform specific
> 
> That's not entirely accurate.  AsanThread::SetThreadStackAndTls might be a 
> model here.  But asan on Fuchsia also splits up the initialization into 
> pre-creation and on-created-thread portions (AsanThread::Init is called 
> before thread creation, and AsanThreadRegistry::StartThread is called on the 
> created thread).
> 
Patch itself is LGTM.
But I am not sure if @mcgrathr is asking for particular changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104248

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


[PATCH] D104305: [flang][driver] Add `-fdebug-dump-all`

2021-06-16 Thread Pete Steinfeld via Phabricator via cfe-commits
PeteSteinfeld added a comment.

For what it's worth, here's my cmake command that results in a successful 
static full build:

  cmake -G Ninja ../llvm \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_LIT_ARGS=-v \
-DFLANG_ENABLE_WERROR=On \
-DCMAKE_C_COMPILER=/home/sw/thirdparty/gcc/gcc-9.3.0/linux86-64/bin/gcc \
-DCMAKE_CXX_COMPILER=/home/sw/thirdparty/gcc/gcc-9.3.0/linux86-64/bin/g++ \
-DCMAKE_CXX_STANDARD=17 \
-DLLVM_TARGETS_TO_BUILD=host \
-DLLVM_ENABLE_ZLIB=OFF \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_CXX_LINK_FLAGS="-Wl,-rpath,$LD_LIBRARY_PATH" \
-DLLVM_INSTALL_UTILS=On \
-DLLVM_ENABLE_PROJECTS="clang;mlir;flang" \
-DCMAKE_INSTALL_PREFIX=$INSTALLDIR


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104305

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


[PATCH] D99696: [clang] NRVO: Improvements and handling of more cases.

2021-06-16 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

Some tiny nits. I can't think of any interesting block-related cases (but my 
knowledge of blocks is apparently very rusty at this point).




Comment at: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:1100
+// This is the last chance we have of checking copy elision eligibility
+// for functions in depdendent contexts. The sema actions for building
+// the return statement during template instantiation will have no effect

/depdendent/dependent/



Comment at: clang/test/CodeGen/nrvo-tracking.cpp:206
+void b_attr() {
+  auto t = []() { return ^ X () [[clang::vectorcall]] {
+  T t;

Formatting nit: I'd think
```
auto t = []() {
return ^X() [[clang::vectorcall]] {
T t;
return t;
};
}()();
```
would be less confusing to the eyes.




Comment at: clang/test/SemaObjCXX/block-capture.mm:43
+  ConvertingRVRef(X &&);
+  operator X() const & = delete;;
+  operator X() &&;

Nit: `;;` here


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99696

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


[PATCH] D103096: [analyzer] Implement cast for ranges of symbolic integers.

2021-06-16 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

In D103096#2821750 , @vsavchenko 
wrote:

> Hey, great work!  I think that casts are extremely important, but it looks 
> like you mixed so many things into this patch.  Let's make one step at a time 
> a split it into (at least) a couple of patches.

Thanks for the tips. I'll adress them in the next update. Actually, I thought 
about splitting before the first upload and splitted it into D103094 
 and the current one. This particular patch 
provides full mechanism implementing feasibility of the test cases. Honestly, I 
don't know what part could be cut to keep this mechanism holistic and 
self-sufficient. But I'll see what i can do.


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

https://reviews.llvm.org/D103096

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


[clang] 439c920 - [ASTMatchers] Fix bug in `hasUnaryOperand`

2021-06-16 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2021-06-16T20:17:56Z
New Revision: 439c9206945aba15d74d5bcaef3bf3f4d1e32b5e

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

LOG: [ASTMatchers] Fix bug in `hasUnaryOperand`

Currently, `hasUnaryOperand` fails for the overloaded `operator*`. This patch 
fixes the bug and
adds tests for this case.

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

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchersInternal.h
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h 
b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 64e4dcb06894f..71f4f2d17ae3f 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -2102,6 +2102,8 @@ equivalentUnaryOperator(const 
CXXOperatorCallExpr &Node) {
 return UO_Minus;
   case OO_Amp:
 return UO_AddrOf;
+  case OO_Star:
+return UO_Deref;
   case OO_Tilde:
 return UO_Not;
   case OO_Exclaim:

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index ae496d39e00cf..12012d9c699d4 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1893,6 +1893,23 @@ void plusIntOperator()
  cxxOperatorCallExpr(
  forFunction(functionDecl(hasName("plusIntOperator"))),
  hasOperatorName("+"), hasUnaryOperand(expr());
+
+  Code = R"cpp(
+struct HasOpArrow
+{
+int& operator*();
+};
+void foo()
+{
+HasOpArrow s1;
+*s1;
+}
+)cpp";
+
+  EXPECT_TRUE(
+  matches(Code, traverse(TK_IgnoreUnlessSpelledInSource,
+ cxxOperatorCallExpr(hasOperatorName("*"),
+ hasUnaryOperand(expr());
 }
 
 TEST(Matcher, UnaryOperatorTypes) {



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


[PATCH] D104389: [ASTMatchers] Fix bug in `hasUnaryOperand`

2021-06-16 Thread Yitzhak Mandelbaum 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 rG439c9206945a: [ASTMatchers] Fix bug in `hasUnaryOperand` 
(authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104389

Files:
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1893,6 +1893,23 @@
  cxxOperatorCallExpr(
  forFunction(functionDecl(hasName("plusIntOperator"))),
  hasOperatorName("+"), hasUnaryOperand(expr());
+
+  Code = R"cpp(
+struct HasOpArrow
+{
+int& operator*();
+};
+void foo()
+{
+HasOpArrow s1;
+*s1;
+}
+)cpp";
+
+  EXPECT_TRUE(
+  matches(Code, traverse(TK_IgnoreUnlessSpelledInSource,
+ cxxOperatorCallExpr(hasOperatorName("*"),
+ hasUnaryOperand(expr());
 }
 
 TEST(Matcher, UnaryOperatorTypes) {
Index: clang/include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -2102,6 +2102,8 @@
 return UO_Minus;
   case OO_Amp:
 return UO_AddrOf;
+  case OO_Star:
+return UO_Deref;
   case OO_Tilde:
 return UO_Not;
   case OO_Exclaim:


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1893,6 +1893,23 @@
  cxxOperatorCallExpr(
  forFunction(functionDecl(hasName("plusIntOperator"))),
  hasOperatorName("+"), hasUnaryOperand(expr());
+
+  Code = R"cpp(
+struct HasOpArrow
+{
+int& operator*();
+};
+void foo()
+{
+HasOpArrow s1;
+*s1;
+}
+)cpp";
+
+  EXPECT_TRUE(
+  matches(Code, traverse(TK_IgnoreUnlessSpelledInSource,
+ cxxOperatorCallExpr(hasOperatorName("*"),
+ hasUnaryOperand(expr());
 }
 
 TEST(Matcher, UnaryOperatorTypes) {
Index: clang/include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -2102,6 +2102,8 @@
 return UO_Minus;
   case OO_Amp:
 return UO_AddrOf;
+  case OO_Star:
+return UO_Deref;
   case OO_Tilde:
 return UO_Not;
   case OO_Exclaim:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D103021: [clang-tidy] performance-unnecessary-copy-initialization: Search whole function body for variable initializations.

2021-06-16 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp:62
 
 AST_MATCHER_FUNCTION(StatementMatcher, isInitializedFromReferenceToConst) {
   auto OldVarDeclRef =

This name seems a little off now. maybe rename?



Comment at: 
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp:98-101
   auto Matches =
   match(findAll(declStmt(has(varDecl(equalsNode(&InitializingVar
 .bind("declStmt")),
+Body, Context);

flx wrote:
> ymandel wrote:
> > flx wrote:
> > > ymandel wrote:
> > > > flx wrote:
> > > > > ymandel wrote:
> > > > > > Consider inspecting the `DeclContext`s instead, which should be 
> > > > > > much more efficient than searching the entire block.  Pass the 
> > > > > > `FunctionDecl` as an argument instead of `Body`, since it is a 
> > > > > > `DeclContext`.  e.g. `const DeclContext &Fun`
> > > > > > 
> > > > > > Then, either
> > > > > > 1. Call `Fun.containsDecl(InitializingVar)`, or
> > > > > > 2. Search through the contexts yourself; something like:
> > > > > > ```
> > > > > > DeclContext* DC = InitializingVar->getDeclContext(); 
> > > > > > while (DC != nullptr && DC != &Fun)
> > > > > >   DC = DC->getLexicalParent();
> > > > > > if (DC == nullptr)
> > > > > >   // The reference or pointer is not initialized anywhere witin the 
> > > > > > function. We
> > > > > >   // assume its pointee is not modified then.
> > > > > >   return true;
> > > > > > ```
> > > > > Are #1 and #2 equivalent? From the implementation and comment I 
> > > > > cannot tell whether #1 would cover cases where the variable is not 
> > > > > declared directly in the function, but in child block:
> > > > > 
> > > > > ```
> > > > > void Fun() {
> > > > >  {
> > > > >var i;
> > > > >{
> > > > >  i.usedHere();
> > > > >}  
> > > > >  } 
> > > > > }
> > > > > ```
> > > > > 
> > > > > I'm also reading this as an optimization to more quickly determine 
> > > > > whether we can stop here. We still need to find the matches for the 
> > > > > next steps, but I  think I could then limit matching to the 
> > > > > DeclContext I found here. Is this correct? For this I would actually 
> > > > > need the DeclContext result from #2.
> > > > A. I think you're right that #2 is more suited to what you need. I 
> > > > wasn't sure, so included both. Agreed that the comments are ambiguous.
> > > > B. yes, this is just an optimization. it may be premature for that 
> > > > matter; just that match can be expensive and this seemed a more direct 
> > > > expression of the algorithm.
> > > I was not able to pass the (possibly more narrow) DeclContext to the 
> > > match function as scope since match does not support DeclContexts.
> > > 
> > > I implemented  isDeclaredInFunction() which iterates through the decl 
> > > contexts as you suggested. I'm not sure though whether we should start 
> > > with VarDecl::getDeclContext() or VarDecl::getLexicalDeclContext()?
> > > 
> > > While looking at VarDecl::getLexicalDeclContext() I discovered is VarDecl 
> > > has the following method:
> > > 
> > > ```
> > >   /// Returns true for local variable declarations other than parameters. 
> > >
> > >   /// Note that this includes static variables inside of functions. It 
> > > also  
> > >   /// includes variables inside blocks.   
> > >
> > >   /// 
> > >
> > >   ///   void foo() { int x; static int y; extern int z; } 
> > >
> > >   bool isLocalVarDecl() const;
> > > ```
> > > 
> > > I think this is exactly what we'd want here. What do you think?
> > > 
> > You mean instead of `isDeclaredInFunction`?  If so -- yes, that seems 
> > right.  But, if so, are you still planning to bind "declStmt" with the 
> > `match`, or will you replace that with something more direct?
> I was able to examine the`VarDecl.getInit()` expression directly. This 
> completely avoids a search inside the function and he FunctionDecl is also no 
> longer needed. PTAL.
Nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103021

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


[clang] c7ed4fe - [libTooling] Change `access` stencil to recognize use of `operator*`.

2021-06-16 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2021-06-16T20:34:00Z
New Revision: c7ed4fe56e0a6c664c5fb5dedaedb426abe7224d

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

LOG: [libTooling] Change `access` stencil to recognize use of `operator*`.

Currently, `access` doesn't recognize a dereferenced smart pointer. So,
`access(e, "field")` where `e = *x`, yields:
* `x->field`, for normal-pointer x,
* `(*x).field`, for smart-pointer x.

This patch normalizes handling of smart pointer to match normal pointer, when
the smart pointer type supports `->`.

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

Added: 


Modified: 
clang/lib/Tooling/Transformer/Stencil.cpp
clang/unittests/Tooling/StencilTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Transformer/Stencil.cpp 
b/clang/lib/Tooling/Transformer/Stencil.cpp
index 9223b4a290a08..4dc3544bb06db 100644
--- a/clang/lib/Tooling/Transformer/Stencil.cpp
+++ b/clang/lib/Tooling/Transformer/Stencil.cpp
@@ -73,6 +73,21 @@ static bool isSmartPointerType(QualType Ty, ASTContext 
&Context) {
   return match(SmartPointer, Ty, Context).size() > 0;
 }
 
+// Identifies use of `operator*` on smart pointers, and returns the underlying
+// smart-pointer expression; otherwise, returns null.
+static const Expr *isSmartDereference(const Expr &E, ASTContext &Context) {
+  using namespace ::clang::ast_matchers;
+
+  const auto HasOverloadedArrow = cxxRecordDecl(hasMethod(cxxMethodDecl(
+  hasOverloadedOperatorName("->"), returns(qualType(pointsTo(type()));
+  // Verify it is a smart pointer by finding `operator->` in the class
+  // declaration.
+  auto Deref = cxxOperatorCallExpr(
+  hasOverloadedOperatorName("*"), hasUnaryOperand(expr().bind("arg")),
+  callee(cxxMethodDecl(ofClass(HasOverloadedArrow;
+  return selectFirst("arg", match(Deref, E, Context));
+}
+
 namespace {
 // An arbitrary fragment of code within a stencil.
 class RawTextStencil : public StencilInterface {
@@ -309,6 +324,10 @@ class AccessStencil : public StencilInterface {
   }
 }
 S = tooling::buildArrow(*E, *Match.Context);
+  } else if (const auto *Operand = isSmartDereference(*E, *Match.Context)) 
{
+// `buildDot` already handles the built-in dereference operator, so we
+// only need to catch overloaded `operator*`.
+S = tooling::buildArrow(*Operand, *Match.Context);
   } else {
 S = tooling::buildDot(*E, *Match.Context);
   }

diff  --git a/clang/unittests/Tooling/StencilTest.cpp 
b/clang/unittests/Tooling/StencilTest.cpp
index df05e6deeb577..0b5b9691dadc5 100644
--- a/clang/unittests/Tooling/StencilTest.cpp
+++ b/clang/unittests/Tooling/StencilTest.cpp
@@ -407,7 +407,7 @@ TEST_F(StencilTest, AccessOpSmartPointerDereference) {
 *x;
   )cc";
   StringRef Id = "id";
-  testExpr(Id, Snippet, access(Id, "field"), "(*x).field");
+  testExpr(Id, Snippet, access(Id, "field"), "x->field");
 }
 
 TEST_F(StencilTest, AccessOpSmartPointerMemberCall) {



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


[PATCH] D104390: [libTooling] Change `access` stencil to recognize use of `operator*`.

2021-06-16 Thread Yitzhak Mandelbaum 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 rGc7ed4fe56e0a: [libTooling] Change `access` stencil to 
recognize use of `operator*`. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104390

Files:
  clang/lib/Tooling/Transformer/Stencil.cpp
  clang/unittests/Tooling/StencilTest.cpp


Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -407,7 +407,7 @@
 *x;
   )cc";
   StringRef Id = "id";
-  testExpr(Id, Snippet, access(Id, "field"), "(*x).field");
+  testExpr(Id, Snippet, access(Id, "field"), "x->field");
 }
 
 TEST_F(StencilTest, AccessOpSmartPointerMemberCall) {
Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -73,6 +73,21 @@
   return match(SmartPointer, Ty, Context).size() > 0;
 }
 
+// Identifies use of `operator*` on smart pointers, and returns the underlying
+// smart-pointer expression; otherwise, returns null.
+static const Expr *isSmartDereference(const Expr &E, ASTContext &Context) {
+  using namespace ::clang::ast_matchers;
+
+  const auto HasOverloadedArrow = cxxRecordDecl(hasMethod(cxxMethodDecl(
+  hasOverloadedOperatorName("->"), returns(qualType(pointsTo(type()));
+  // Verify it is a smart pointer by finding `operator->` in the class
+  // declaration.
+  auto Deref = cxxOperatorCallExpr(
+  hasOverloadedOperatorName("*"), hasUnaryOperand(expr().bind("arg")),
+  callee(cxxMethodDecl(ofClass(HasOverloadedArrow;
+  return selectFirst("arg", match(Deref, E, Context));
+}
+
 namespace {
 // An arbitrary fragment of code within a stencil.
 class RawTextStencil : public StencilInterface {
@@ -309,6 +324,10 @@
   }
 }
 S = tooling::buildArrow(*E, *Match.Context);
+  } else if (const auto *Operand = isSmartDereference(*E, *Match.Context)) 
{
+// `buildDot` already handles the built-in dereference operator, so we
+// only need to catch overloaded `operator*`.
+S = tooling::buildArrow(*Operand, *Match.Context);
   } else {
 S = tooling::buildDot(*E, *Match.Context);
   }


Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -407,7 +407,7 @@
 *x;
   )cc";
   StringRef Id = "id";
-  testExpr(Id, Snippet, access(Id, "field"), "(*x).field");
+  testExpr(Id, Snippet, access(Id, "field"), "x->field");
 }
 
 TEST_F(StencilTest, AccessOpSmartPointerMemberCall) {
Index: clang/lib/Tooling/Transformer/Stencil.cpp
===
--- clang/lib/Tooling/Transformer/Stencil.cpp
+++ clang/lib/Tooling/Transformer/Stencil.cpp
@@ -73,6 +73,21 @@
   return match(SmartPointer, Ty, Context).size() > 0;
 }
 
+// Identifies use of `operator*` on smart pointers, and returns the underlying
+// smart-pointer expression; otherwise, returns null.
+static const Expr *isSmartDereference(const Expr &E, ASTContext &Context) {
+  using namespace ::clang::ast_matchers;
+
+  const auto HasOverloadedArrow = cxxRecordDecl(hasMethod(cxxMethodDecl(
+  hasOverloadedOperatorName("->"), returns(qualType(pointsTo(type()));
+  // Verify it is a smart pointer by finding `operator->` in the class
+  // declaration.
+  auto Deref = cxxOperatorCallExpr(
+  hasOverloadedOperatorName("*"), hasUnaryOperand(expr().bind("arg")),
+  callee(cxxMethodDecl(ofClass(HasOverloadedArrow;
+  return selectFirst("arg", match(Deref, E, Context));
+}
+
 namespace {
 // An arbitrary fragment of code within a stencil.
 class RawTextStencil : public StencilInterface {
@@ -309,6 +324,10 @@
   }
 }
 S = tooling::buildArrow(*E, *Match.Context);
+  } else if (const auto *Operand = isSmartDereference(*E, *Match.Context)) {
+// `buildDot` already handles the built-in dereference operator, so we
+// only need to catch overloaded `operator*`.
+S = tooling::buildArrow(*Operand, *Match.Context);
   } else {
 S = tooling::buildDot(*E, *Match.Context);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D98798: Produce warning for performing pointer arithmetic on a null pointer.

2021-06-16 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser added a comment.

ping


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

https://reviews.llvm.org/D98798

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


[PATCH] D102706: [clang-format] Add new LambdaBodyIndentation option

2021-06-16 Thread Vitali Lovich via Phabricator via cfe-commits
vlovich added a comment.

I don't know how to commit. Happy to do it if I have the permissions & 
appropriate instructions.

Name: Vitali Lovich
E-mail: vlov...@gmail.com


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

https://reviews.llvm.org/D102706

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


[PATCH] D102730: [clang-format] Support custom If macros

2021-06-16 Thread Vitali Lovich via Phabricator via cfe-commits
vlovich added a comment.

Just back from vacation so will try to polish this off today.


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

https://reviews.llvm.org/D102730

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


[PATCH] D104305: [flang][driver] Add `-fdebug-dump-all`

2021-06-16 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Apologies, this is my fault. Should be fixed: 
https://github.com/llvm/llvm-project/commit/46446e398b5202303280d9e18676c07529f1d0b0.
 I pushed it without a review as it felt rather straightforward and I wanted to 
make sure that you are unblocked.

If for whatever reason your issue is still not resolved, please revert and I 
will fix it once I'm back online.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104305

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


[PATCH] D104420: thread_local support for AIX

2021-06-16 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser created this revision.
jamieschmeiser added reviewers: hubert.reinterpretcast, sfertile, 
cebowleratibm, DiggerLin, rsmith.
jamieschmeiser requested review of this revision.
Herald added a project: clang.

Changes to support thread_local storage on AIX.

  

The AIX linker will produce errors on unresolved weak symbols.  Change the
generated code to not check for the initialization function but just call
it and ensure that it always exists.  Also, the AIX atexit routine has a
different name (and signature) so call it correctly.  Update the lit tests
to test on AIX appropriately.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104420

Files:
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/cxx11-thread-local-reference.cpp
  clang/test/CodeGenCXX/cxx11-thread-local-visibility.cpp
  clang/test/CodeGenCXX/cxx11-thread-local.cpp

Index: clang/test/CodeGenCXX/cxx11-thread-local.cpp
===
--- clang/test/CodeGenCXX/cxx11-thread-local.cpp
+++ clang/test/CodeGenCXX/cxx11-thread-local.cpp
@@ -9,11 +9,13 @@
 // RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -femulated-tls -emit-llvm %s -o - \
 // RUN: -triple x86_64-linux-gnu 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=LINUX %s
 // RUN: %clang_cc1 -std=c++11 -fno-use-cxa-atexit -emit-llvm %s -o - -triple x86_64-apple-darwin12 | FileCheck --check-prefix=CHECK --check-prefix=DARWIN %s
+// RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o - -triple powerpc64-unknown-aix-xcoff | FileCheck --check-prefix=CHECK --check-prefix=AIX %s
 
 int f();
 int g();
 
 // LINUX-DAG: @a ={{.*}} thread_local global i32 0
+// AIX-DAG: @a ={{.*}} thread_local global i32 0
 // DARWIN-DAG: @a = internal thread_local global i32 0
 thread_local int a = f();
 extern thread_local int b;
@@ -24,6 +26,7 @@
 
 struct U { static thread_local int m; };
 // LINUX-DAG: @_ZN1U1mE ={{.*}} thread_local global i32 0
+// AIX-DAG: @_ZN1U1mE ={{.*}} thread_local global i32 0
 // DARWIN-DAG: @_ZN1U1mE = internal thread_local global i32 0
 thread_local int U::m = f();
 
@@ -90,8 +93,10 @@
 // CHECK-DAG: @llvm.global_ctors = appending global {{.*}} @[[GLOBAL_INIT:[^ ]*]]
 
 // LINUX-DAG: @_ZTH1a ={{.*}} alias void (), void ()* @__tls_init
+// AIX-DAG: @_ZTH1a ={{.*}} alias void (), void ()* @__tls_init
 // DARWIN-DAG: @_ZTH1a = internal alias void (), void ()* @__tls_init
 // LINUX-DAG: @_ZTHN1U1mE ={{.*}} alias void (), void ()* @__tls_init
+// AIX-DAG: @_ZTHN1U1mE ={{.*}} alias void (), void ()* @__tls_init
 // DARWIN-DAG: @_ZTHN1U1mE = internal alias void (), void ()* @__tls_init
 // CHECK-DAG: @_ZTHN1VIiE1mE = linkonce_odr alias void (), void ()* @[[V_M_INIT:[^, ]*]]
 // CHECK-DAG: @_ZTHN1XIiE1mE = linkonce_odr alias void (), void ()* @[[X_M_INIT:[^, ]*]]
@@ -106,16 +111,16 @@
 // Individual variable initialization functions:
 
 // CHECK: define {{.*}} @[[A_INIT:.*]]()
-// CHECK: call i32 @_Z1fv()
+// CHECK: call{{.*}} i32 @_Z1fv()
 // CHECK-NEXT: store i32 {{.*}}, i32* @a, align 4
 
 // CHECK-LABEL: define{{.*}} i32 @_Z1fv()
 int f() {
   // CHECK: %[[GUARD:.*]] = load i8, i8* @_ZGVZ1fvE1n, align 1
   // CHECK: %[[NEED_INIT:.*]] = icmp eq i8 %[[GUARD]], 0
-  // CHECK: br i1 %[[NEED_INIT]]
+  // CHECK: br i1 %[[NEED_INIT]]{{.*}}
 
-  // CHECK: %[[CALL:.*]] = call i32 @_Z1gv()
+  // CHECK: %[[CALL:.*]] = call{{.*}} i32 @_Z1gv()
   // CHECK: store i32 %[[CALL]], i32* @_ZZ1fvE1n, align 4
   // CHECK: store i8 1, i8* @_ZGVZ1fvE1n
   // CHECK: br label
@@ -127,54 +132,67 @@
 
 // CHECK: define {{.*}} @[[C_INIT:.*]]()
 // LINUX: call i32* @_ZTW1b()
+// AIX: call i32* @_ZTW1b()
 // DARWIN: call cxx_fast_tlscc i32* @_ZTW1b()
 // CHECK-NEXT: load i32, i32* %{{.*}}, align 4
 // CHECK-NEXT: store i32 %{{.*}}, i32* @c, align 4
 
 // LINUX-LABEL: define linkonce_odr hidden i32* @_ZTW1b()
+// AIX-LABEL: define linkonce_odr hidden i32* @_ZTW1b()
 // LINUX: br i1 icmp ne (void ()* @_ZTH1b, void ()* null),
 // not null:
 // LINUX: call void @_ZTH1b()
+// AIX-NOT: br i1 icmp ne (void ()* @_ZTH1b, void ()* null),
+// AIX: call void @_ZTH1b()
 // LINUX: br label
 // finally:
 // LINUX: ret i32* @b
+// AIX: ret i32* @b
 // DARWIN-LABEL: declare cxx_fast_tlscc i32* @_ZTW1b()
 // There is no definition of the thread wrapper on Darwin for external TLV.
 
 // CHECK: define {{.*}} @[[D_INIT:.*]]()
-// CHECK: call i32 @_Z1gv()
+// CHECK: call{{.*}} i32 @_Z1gv()
 // CHECK-NEXT: store i32 %{{.*}}, i32* @_ZL1d, align 4
 
 // CHECK: define {{.*}} @[[U_M_INIT:.*]]()
-// CHECK: call i32 @_Z1fv()
+// CHECK: call{{.*}} i32 @_Z1fv()
 // CHECK-NEXT: store i32 %{{.*}}, i32* @_ZN1U1mE, align 4
 
 // CHECK: define {{.*}} @[[E_INIT:.*]]()
 // LINUX: call i32* @_ZTWN1VIiE1mE()
+// AIX: call i32* @_ZTWN1VIiE1mE()
 // DARWIN: call cxx_fast_tlscc i32* @_ZTWN1VIiE1mE()
 // CHECK-NEXT: load i32, i32* %{{.*}}, align 4
 // LINUX: call {{.*}}* @_ZTWN1XIiE1mE()
+// AIX: call {{.*}}* @_ZTWN1XIiE1mE()
 // DARWIN: call cxx_fast_tlscc {{.*}}* @

[PATCH] D99696: [clang] NRVO: Improvements and handling of more cases.

2021-06-16 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 352566.
mizvekov added a comment.

Fix Arthur's nits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99696

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGen/nrvo-tracking.cpp
  clang/test/SemaObjCXX/block-capture.mm

Index: clang/test/SemaObjCXX/block-capture.mm
===
--- /dev/null
+++ clang/test/SemaObjCXX/block-capture.mm
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_20,cxx20%s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_20,cxx98_11 %s
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_20,cxx98_11 %s
+
+#define TEST(T) void test_##T() { \
+  __block T x;\
+  (void)^(void) { (void)x; }; \
+}
+
+struct CopyOnly {
+  CopyOnly();
+  CopyOnly(CopyOnly &);
+};
+TEST(CopyOnly);
+
+struct CopyNoMove {
+  CopyNoMove();
+  CopyNoMove(CopyNoMove &);
+  CopyNoMove(CopyNoMove &&) = delete; // cxx98_20-note {{marked deleted here}}
+};
+TEST(CopyNoMove); // cxx98_20-error {{call to deleted constructor}}
+
+struct MoveOnly {
+  MoveOnly();
+  MoveOnly(MoveOnly &) = delete;
+  MoveOnly(MoveOnly &&);
+};
+TEST(MoveOnly);
+
+struct NoCopyNoMove {
+  NoCopyNoMove();
+  NoCopyNoMove(NoCopyNoMove &) = delete;
+  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx98_20-note {{marked deleted here}}
+};
+TEST(NoCopyNoMove); // cxx98_20-error {{call to deleted constructor}}
+
+struct ConvertingRVRef {
+  ConvertingRVRef();
+  ConvertingRVRef(ConvertingRVRef &) = delete; // cxx98_11-note {{marked deleted here}}
+
+  struct X {};
+  ConvertingRVRef(X &&);
+  operator X() const & = delete;
+  operator X() &&;
+};
+TEST(ConvertingRVRef); // cxx98_11-error {{call to deleted constructor}}
+
+struct ConvertingCLVRef {
+  ConvertingCLVRef();
+  ConvertingCLVRef(ConvertingCLVRef &);
+
+  struct X {};
+  ConvertingCLVRef(X &&); // cxx20-note {{passing argument to parameter here}}
+  operator X() const &;
+  operator X() && = delete; // cxx20-note {{marked deleted here}}
+};
+TEST(ConvertingCLVRef); // cxx20-error {{invokes a deleted function}}
+
+struct SubSubMove {};
+struct SubMove : SubSubMove {
+  SubMove();
+  SubMove(SubMove &) = delete; // cxx98_11-note {{marked deleted here}}
+
+  SubMove(SubSubMove &&);
+};
+TEST(SubMove); // cxx98_11-error {{call to deleted constructor}}
Index: clang/test/CodeGen/nrvo-tracking.cpp
===
--- clang/test/CodeGen/nrvo-tracking.cpp
+++ clang/test/CodeGen/nrvo-tracking.cpp
@@ -29,8 +29,6 @@
 
 // CHECK-LABEL: define{{.*}} void @_Z2l3v
 // CHECK:   call {{.*}} @_ZN1XC1Ev
-// CHECK-NEXT:  call {{.*}} @_ZN1XC1EOS_
-// CHECK-NEXT:  call void @llvm.lifetime.end
 // CHECK-NEXT:  call void @llvm.lifetime.end
 // CHECK-NEXT:  ret void
 L(3, t, T);
@@ -152,7 +150,11 @@
   }; }()();\
 }
 
-//B(1, X); // Uncomment this line at your own peril ;)
+// CHECK-LABEL: define{{.*}} void @_Z2b1v
+// CHECK:   call {{.*}} @_ZN1XC1Ev
+// CHECK-NEXT:  call void @llvm.lifetime.end
+// CHECK-NEXT:  ret void
+B(1, X);
 
 // CHECK-LABEL: define{{.*}} void @_Z2b2v
 // CHECK:   call {{.*}} @_ZN1XC1Ev
@@ -164,8 +166,6 @@
 
 // CHECK-LABEL: define{{.*}} void @_Z2b3v
 // CHECK:   call {{.*}} @_ZN1XC1Ev
-// CHECK-NEXT:  call {{.*}} @_ZN1XC1EOS_
-// CHECK-NEXT:  call void @llvm.lifetime.end
 // CHECK-NEXT:  call void @llvm.lifetime.end
 // CHECK-NEXT:  ret void
 B(3, T);
@@ -187,3 +187,26 @@
 B(5, );
 
 #undef B
+
+// CHECK-LABEL: define{{.*}} void @_Z6f_attrv
+// CHECK:   call {{.*}} @_ZN1XC1Ev
+// CHECK-NEXT:  call void @llvm.lifetime.end
+// CHECK-NEXT:  ret void
+template [[gnu::cdecl]] static inline auto tf_attr() -> X {
+T t;
+return t;
+}
+void f_attr() { auto t = tf_attr(); }
+
+// CHECK-LABEL: define{{.*}} void @_Z6b_attrv
+// CHECK:   call {{.*}} @_ZN1XC1Ev
+// CHECK-NEXT:  call void @llvm.lifetime.end
+// CHECK-NEXT:  ret void
+void b_attr() {
+  auto t = []() {
+return ^ X () [[clang::vectorcall]] {
+  T t;
+  return t;
+};
+  }()();
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Lookup.h"
+#include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/SemaInternal.h"
 #include "clang/Sema/Template.h"
 #include "clang/Sema/TemplateIn

[PATCH] D104424: [Sema] Fix for PR50741

2021-06-16 Thread Chris Hamilton via Phabricator via cfe-commits
chrish_ericsson_atx created this revision.
chrish_ericsson_atx added reviewers: erichkeane, aaron.ballman, abhinavgaba.
chrish_ericsson_atx requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixed crash when doing pointer math on a

  void pointer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104424

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/unbounded-array-bounds.c

Index: clang/test/Sema/unbounded-array-bounds.c
===
--- clang/test/Sema/unbounded-array-bounds.c
+++ clang/test/Sema/unbounded-array-bounds.c
@@ -1,9 +1,6 @@
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-X86-ADDR64 %s  \
-// RUN:  --implicit-check-not 'past the last possible element'
-// RUN: %clang_cc1 -triple i386-pc-linux-gnu   -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-I386-ADDR32 %s \
-// RUN:  --implicit-check-not 'past the last possible element'
-// RUN: %clang_cc1 -triple avr-pc-linux-gnu-fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-AVR-ADDR16 %s  \
-// RUN:  --implicit-check-not 'past the last possible element'
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only  -verify=addr64,expected %s
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu   -fsyntax-only  -verify=addr32,expected %s
+// RUN: %clang_cc1 -triple avr-pc-linux-gnu-fsyntax-only  -verify=addr16,expected %s
 
 struct S {
   long long a;
@@ -12,61 +9,61 @@
   short d;
 };
 
-struct S s[];
+struct S s[]; // expected-warning {{tentative array definition}} expected-note {{declared here}} addr16-note {{declared here}}
 
 void f1() {
   ++s[3].a;
   ++s[7073650413200313099].b;
-  // CHECK-X86-ADDR64:  :[[@LINE-1]]:5: warning: array index 7073650413200313099 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576460752303423488 elements)
-  // CHECK-I386-ADDR32: :[[@LINE-2]]:5: warning: {{.*}} past the last possible element {{.*}} in 32-bit {{.*}} (max possible 178956970 elements)
-  // CHECK-AVR-ADDR16:  :[[@LINE-3]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 3276 elements)
+  // addr16-warning@16 {{array index 7073650413200313099 refers past the last possible element for an array in 16-bit address space containing 160-bit (20-byte) elements (max possible 3276 elements)}}
+  // addr32-warning@16 {{array index 7073650413200313099 refers past the last possible element for an array in 32-bit address space containing 192-bit (24-byte) elements (max possible 178956970 elements)}}
+  // addr64-warning@16 {{array index 7073650413200313099 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576460752303423488 elements)}}
   ++s[7073650].c;
-  // CHECK-AVR-ADDR16:  :[[@LINE-1]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 3276 elements)
+  // addr16-warning@20 {{array index 7073650 refers past the last possible element for an array in 16-bit address space containing 160-bit (20-byte) elements (max possible 3276 elements)}}
 }
 
-long long ll[];
+long long ll[]; // expected-warning {{tentative array definition}} expected-note {{declared here}} addr16-note {{declared here}} addr32-note {{declared here}}
 
 void f2() {
   ++ll[3];
   ++ll[2705843009213693952];
-  // CHECK-X86-ADDR64:  :[[@LINE-1]]:5: warning: {{.*}} past the last possible element {{.*}} in 64-bit {{.*}} (max possible 2305843009213693952 elements)
-  // CHECK-I386-ADDR32: :[[@LINE-2]]:5: warning: {{.*}} past the last possible element {{.*}} in 32-bit {{.*}} (max possible 536870912 elements)
-  // CHECK-AVR-ADDR16:  :[[@LINE-3]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 8192 elements)
+  // addr16-warning@28 {{array index 2705843009213693952 refers past the last possible element for an array in 16-bit address space containing 64-bit (8-byte) elements (max possible 8192 elements)}}
+  // addr32-warning@28 {{array index 2705843009213693952 refers past the last possible element for an array in 32-bit address space containing 64-bit (8-byte) elements (max possible 536870912 elements)}}
+  // addr64-warning@28 {{array index 2705843009213693952 refers past the last possible element for an array in 64-bit address space containing 64-bit (8-byte) elements (max possible 2305843009213693952 elements)}}
   ++ll[847073650];
-  // CHECK-I386-ADDR32: :[[@LINE-1]]:5: warning: {{.*}} past the last possible element {{.*}} in 32-bit {{.*}} (max possible 536870912 elements)
-  // CHECK-AVR-ADDR16:  :[[@LINE-2]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 8192 elements)
+  // addr16-warning@32 {{array index 847073650 refers past the last possibl

[PATCH] D104424: [Sema] Fix for PR50741

2021-06-16 Thread Chris Hamilton via Phabricator via cfe-commits
chrish_ericsson_atx updated this revision to Diff 352569.
chrish_ericsson_atx added a comment.

Updated summary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104424

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/unbounded-array-bounds.c

Index: clang/test/Sema/unbounded-array-bounds.c
===
--- clang/test/Sema/unbounded-array-bounds.c
+++ clang/test/Sema/unbounded-array-bounds.c
@@ -1,9 +1,6 @@
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-X86-ADDR64 %s  \
-// RUN:  --implicit-check-not 'past the last possible element'
-// RUN: %clang_cc1 -triple i386-pc-linux-gnu   -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-I386-ADDR32 %s \
-// RUN:  --implicit-check-not 'past the last possible element'
-// RUN: %clang_cc1 -triple avr-pc-linux-gnu-fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-AVR-ADDR16 %s  \
-// RUN:  --implicit-check-not 'past the last possible element'
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only  -verify=addr64,expected %s
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu   -fsyntax-only  -verify=addr32,expected %s
+// RUN: %clang_cc1 -triple avr-pc-linux-gnu-fsyntax-only  -verify=addr16,expected %s
 
 struct S {
   long long a;
@@ -12,61 +9,61 @@
   short d;
 };
 
-struct S s[];
+struct S s[]; // expected-warning {{tentative array definition}} expected-note {{declared here}} addr16-note {{declared here}}
 
 void f1() {
   ++s[3].a;
   ++s[7073650413200313099].b;
-  // CHECK-X86-ADDR64:  :[[@LINE-1]]:5: warning: array index 7073650413200313099 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576460752303423488 elements)
-  // CHECK-I386-ADDR32: :[[@LINE-2]]:5: warning: {{.*}} past the last possible element {{.*}} in 32-bit {{.*}} (max possible 178956970 elements)
-  // CHECK-AVR-ADDR16:  :[[@LINE-3]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 3276 elements)
+  // addr16-warning@16 {{array index 7073650413200313099 refers past the last possible element for an array in 16-bit address space containing 160-bit (20-byte) elements (max possible 3276 elements)}}
+  // addr32-warning@16 {{array index 7073650413200313099 refers past the last possible element for an array in 32-bit address space containing 192-bit (24-byte) elements (max possible 178956970 elements)}}
+  // addr64-warning@16 {{array index 7073650413200313099 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576460752303423488 elements)}}
   ++s[7073650].c;
-  // CHECK-AVR-ADDR16:  :[[@LINE-1]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 3276 elements)
+  // addr16-warning@20 {{array index 7073650 refers past the last possible element for an array in 16-bit address space containing 160-bit (20-byte) elements (max possible 3276 elements)}}
 }
 
-long long ll[];
+long long ll[]; // expected-warning {{tentative array definition}} expected-note {{declared here}} addr16-note {{declared here}} addr32-note {{declared here}}
 
 void f2() {
   ++ll[3];
   ++ll[2705843009213693952];
-  // CHECK-X86-ADDR64:  :[[@LINE-1]]:5: warning: {{.*}} past the last possible element {{.*}} in 64-bit {{.*}} (max possible 2305843009213693952 elements)
-  // CHECK-I386-ADDR32: :[[@LINE-2]]:5: warning: {{.*}} past the last possible element {{.*}} in 32-bit {{.*}} (max possible 536870912 elements)
-  // CHECK-AVR-ADDR16:  :[[@LINE-3]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 8192 elements)
+  // addr16-warning@28 {{array index 2705843009213693952 refers past the last possible element for an array in 16-bit address space containing 64-bit (8-byte) elements (max possible 8192 elements)}}
+  // addr32-warning@28 {{array index 2705843009213693952 refers past the last possible element for an array in 32-bit address space containing 64-bit (8-byte) elements (max possible 536870912 elements)}}
+  // addr64-warning@28 {{array index 2705843009213693952 refers past the last possible element for an array in 64-bit address space containing 64-bit (8-byte) elements (max possible 2305843009213693952 elements)}}
   ++ll[847073650];
-  // CHECK-I386-ADDR32: :[[@LINE-1]]:5: warning: {{.*}} past the last possible element {{.*}} in 32-bit {{.*}} (max possible 536870912 elements)
-  // CHECK-AVR-ADDR16:  :[[@LINE-2]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 8192 elements)
+  // addr16-warning@32 {{array index 847073650 refers past the last possible element for an array in 16-bit address space containing 64-bit (8-byte) elements (max possible 8192 elements)}}
+  // addr3

[PATCH] D104424: [Sema] Fix for PR50741

2021-06-16 Thread Abhinav Gaba via Phabricator via cfe-commits
abhinavgaba added a comment.

@erichkeane, can you please take a look?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104424

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


[PATCH] D104344: [modules] Track how headers are included by different modules.

2021-06-16 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 352572.
vsapsai added a comment.

Test when a non-modular header *is* visible through a module import (mostly for 
completeness).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104344

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  
clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Headers/Invisible.h
  
clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Headers/Visible.h
  
clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Modules/module.modulemap
  
clang/test/Modules/Inputs/import-nonmodular/Unmodularized.framework/Headers/Unmodularized.h
  clang/test/Modules/import-nonmodular.m

Index: clang/test/Modules/import-nonmodular.m
===
--- /dev/null
+++ clang/test/Modules/import-nonmodular.m
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F %S/Inputs/import-nonmodular %s -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F %S/Inputs/import-nonmodular %s -verify -DTEST_IMPORT_FROM_MODULE
+// expected-no-diagnostics
+
+// Test non-modular headers are not skipped even if they are imported by
+// non-imported submodules of an imported module. Dependency graph is
+//
+//   Unmodularized.h
+//   ^   ^
+//   |   |
+//  Modularized.Visible  |Modularized.Invisible
+//  ^|
+//   \   |
+//import-nonmodular.m
+
+#import 
+#ifdef TEST_IMPORT_FROM_MODULE
+#import 
+#endif
+#import 
+void test(UnmodularizedStruct *s) {}
Index: clang/test/Modules/Inputs/import-nonmodular/Unmodularized.framework/Headers/Unmodularized.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-nonmodular/Unmodularized.framework/Headers/Unmodularized.h
@@ -0,0 +1,2 @@
+typedef struct UnmodularizedStruct {
+} UnmodularizedStruct;
Index: clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Modules/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Modules/module.modulemap
@@ -0,0 +1,11 @@
+framework module Modularized {
+  module Visible {
+header "Visible.h"
+export *
+  }
+
+  module Invisible {
+header "Invisible.h"
+export *
+  }
+}
Index: clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Headers/Visible.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Headers/Visible.h
@@ -0,0 +1 @@
+// Empty.
Index: clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Headers/Invisible.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Headers/Invisible.h
@@ -0,0 +1 @@
+#import 
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -1668,7 +1668,10 @@
 std::pair
 EmitKeyDataLength(raw_ostream& Out, key_type_ref key, data_type_ref Data) {
   unsigned KeyLen = key.Filename.size() + 1 + 8 + 8;
-  unsigned DataLen = 1 + 2 + 4 + 4;
+  unsigned DataLen = 1 + 4 + 4 + 4;
+  for (auto ModuleIncluder : Data.HFI.ModuleIncludersMap)
+if (Writer.getLocalOrImportedSubmoduleID(ModuleIncluder.first))
+  DataLen += 4;
   for (auto ModInfo : Data.KnownHeaders)
 if (Writer.getLocalOrImportedSubmoduleID(ModInfo.getModule()))
   DataLen += 4;
@@ -1695,12 +1698,10 @@
   endian::Writer LE(Out, little);
   uint64_t Start = Out.tell(); (void)Start;
 
-  unsigned char Flags = (Data.HFI.isImport << 5)
-  | (Data.HFI.isPragmaOnce << 4)
-  | (Data.HFI.DirInfo << 1)
-  | Data.HFI.IndexHeaderMapHeader;
+  unsigned char Flags = (Data.HFI.isPragmaOnce << 4) |
+(Data.HFI.DirInfo << 1) |
+Data.HFI.IndexHeaderMapHeader;
   LE.write(Flags);
-  LE.write(Data.HFI.NumIncludes);
 
   if (!Data.HFI.ControllingMacro)
 LE.write(Data.HFI.ControllingMacroID);
@@ -1723,6 +1724,18 @@
   }
   LE.write(Offset);
 
+  for (auto ModuleIncluder : Data.HFI.ModuleIncludersMap) {
+if (uint32_t ModID =
+Writer.getLocal

[PATCH] D102730: [clang-format] Support custom If macros

2021-06-16 Thread Vitali Lovich via Phabricator via cfe-commits
vlovich updated this revision to Diff 352573.
vlovich added a comment.

Review response

I've updated coverage for AllowShortIfStatementsOnASingleLine and
BreakBeforeBraces. SpacesInConditionalStatement is what the existing
tests were covering so I don't think there's anything there to update.
I looked & couldn't find any tests for
BraceWrappingAfterControlStatementStyle so my (admittedly lazy)
preference is to skip that for now if possible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102730

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -525,6 +525,7 @@
"}");
 
   FormatStyle AllowsMergedIf = getLLVMStyle();
+  AllowsMergedIf.IfMacros.push_back("MYIF");
   AllowsMergedIf.AlignEscapedNewlines = FormatStyle::ENAS_Left;
   AllowsMergedIf.AllowShortIfStatementsOnASingleLine =
   FormatStyle::SIS_WithoutElse;
@@ -564,17 +565,62 @@
"  f();\n"
"}",
AllowsMergedIf);
+  verifyFormat("MYIF (a)\n"
+   "  // comment\n"
+   "  f();",
+   AllowsMergedIf);
+  verifyFormat("{\n"
+   "  MYIF (a)\n"
+   "  label:\n"
+   "f();\n"
+   "}",
+   AllowsMergedIf);
+  verifyFormat("#define A  \\\n"
+   "  MYIF (a) \\\n"
+   "  label:   \\\n"
+   "f()",
+   AllowsMergedIf);
+  verifyFormat("MYIF (a)\n"
+   "  ;",
+   AllowsMergedIf);
+  verifyFormat("MYIF (a)\n"
+   "  MYIF (b) return;",
+   AllowsMergedIf);
+
+  verifyFormat("MYIF (a) // Can't merge this\n"
+   "  f();\n",
+   AllowsMergedIf);
+  verifyFormat("MYIF (a) /* still don't merge */\n"
+   "  f();",
+   AllowsMergedIf);
+  verifyFormat("MYIF (a) { // Never merge this\n"
+   "  f();\n"
+   "}",
+   AllowsMergedIf);
+  verifyFormat("MYIF (a) { /* Never merge this */\n"
+   "  f();\n"
+   "}",
+   AllowsMergedIf);
 
   AllowsMergedIf.ColumnLimit = 14;
+  // Where line-lengths matter, a 2-letter synonym that maintains line length.
+  // Not IF to avoid any confusion that IF is somehow special.
+  AllowsMergedIf.IfMacros.push_back("FI");
   verifyFormat("if (a) return;", AllowsMergedIf);
   verifyFormat("if (a)\n"
"  return;",
AllowsMergedIf);
+  verifyFormat("FI (a) return;", AllowsMergedIf);
+  verifyFormat("FI (a)\n"
+   "  return;",
+   AllowsMergedIf);
 
   AllowsMergedIf.ColumnLimit = 13;
   verifyFormat("if (a)\n  return;", AllowsMergedIf);
+  verifyFormat("FI (a)\n  return;", AllowsMergedIf);
 
   FormatStyle AllowsMergedIfElse = getLLVMStyle();
+  AllowsMergedIfElse.IfMacros.push_back("MYIF");
   AllowsMergedIfElse.AllowShortIfStatementsOnASingleLine =
   FormatStyle::SIS_AllIfsAndElse;
   verifyFormat("if (a)\n"
@@ -626,10 +672,60 @@
"  else if constexpr (c) return;\n"
"  else return;",
AllowsMergedIfElse);
+  verifyFormat("MYIF (a)\n"
+   "  // comment\n"
+   "  f();\n"
+   "else\n"
+   "  // comment\n"
+   "  f();",
+   AllowsMergedIfElse);
+  verifyFormat("{\n"
+   "  MYIF (a)\n"
+   "  label:\n"
+   "f();\n"
+   "  else\n"
+   "  label:\n"
+   "f();\n"
+   "}",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a)\n"
+   "  ;\n"
+   "else\n"
+   "  ;",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a) {\n"
+   "} else {\n"
+   "}",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a) return;\n"
+   "else MYIF (b) return;\n"
+   "else return;",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a) {\n"
+   "} else return;",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a) {\n"
+   "} else MYIF (b) return;\n"
+   "else return;",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a) return;\n"
+   "else MYIF (b) {\n"
+   "} else return;",
+   AllowsMergedIfElse);
+  verifyFormat("MYIF (a)\n"
+   "  MYIF (b) return;\n"
+   "  else 

[PATCH] D104285: [analyzer] Retrieve value by direct index from list initialization of constant array declaration.

2021-06-16 Thread Chris Hamilton via Phabricator via cfe-commits
chrish_ericsson_atx added a comment.

I'm not sure about whether or not this patch would only work for constant 
arrays with initializer lists.  If it does only work for such arrays, then I 
wonder whether the fix is broad enough -- I haven't tested (yet), but I think 
the presence of the initializer list in the test case is not necessary to 
trigger the spurious warnings about garbage/undefined values.  I'll try it 
tomorrow morning...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104285

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


[PATCH] D104344: [modules] Track how headers are included by different modules.

2021-06-16 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 352580.
vsapsai added a comment.

Add a test to verify `MarkFileIncludedFromModule` does `|= isImport` instead of 
`= isImport`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104344

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  
clang/test/Modules/Inputs/import-nonmodular/MixedDirectives.framework/Headers/MixedDirectives.h
  
clang/test/Modules/Inputs/import-nonmodular/MixedDirectives.framework/Modules/module.modulemap
  
clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Headers/Invisible.h
  
clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Headers/Visible.h
  
clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Modules/module.modulemap
  
clang/test/Modules/Inputs/import-nonmodular/Unmodularized.framework/Headers/Unmodularized.h
  clang/test/Modules/import-nonmodular-directive-tracking.m
  clang/test/Modules/import-nonmodular.m

Index: clang/test/Modules/import-nonmodular.m
===
--- /dev/null
+++ clang/test/Modules/import-nonmodular.m
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F %S/Inputs/import-nonmodular %s -verify
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F %S/Inputs/import-nonmodular %s -verify -DTEST_IMPORT_FROM_MODULE
+// expected-no-diagnostics
+
+// Test non-modular headers are not skipped even if they are imported by
+// non-imported submodules of an imported module. Dependency graph is
+//
+//   Unmodularized.h
+//   ^   ^
+//   |   |
+//  Modularized.Visible  |Modularized.Invisible
+//  ^|
+//   \   |
+//import-nonmodular.m
+
+#import 
+#ifdef TEST_IMPORT_FROM_MODULE
+#import 
+#endif
+#import 
+void test(UnmodularizedStruct *s) {}
Index: clang/test/Modules/import-nonmodular-directive-tracking.m
===
--- /dev/null
+++ clang/test/Modules/import-nonmodular-directive-tracking.m
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -F %S/Inputs/import-nonmodular %s -verify
+// expected-no-diagnostics
+
+// Test that #import in a module is "sticky" and isn't overwritten by subsequent #include.
+
+#import 
+// #include instead of #import on purpose.
+#include 
+void test(UnmodularizedStruct *s) {}
Index: clang/test/Modules/Inputs/import-nonmodular/Unmodularized.framework/Headers/Unmodularized.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-nonmodular/Unmodularized.framework/Headers/Unmodularized.h
@@ -0,0 +1,4 @@
+// No header guard on purpose.
+
+typedef struct UnmodularizedStruct {
+} UnmodularizedStruct;
Index: clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Modules/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Modules/module.modulemap
@@ -0,0 +1,11 @@
+framework module Modularized {
+  module Visible {
+header "Visible.h"
+export *
+  }
+
+  module Invisible {
+header "Invisible.h"
+export *
+  }
+}
Index: clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Headers/Visible.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Headers/Visible.h
@@ -0,0 +1 @@
+// Empty.
Index: clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Headers/Invisible.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-nonmodular/Modularized.framework/Headers/Invisible.h
@@ -0,0 +1 @@
+#import 
Index: clang/test/Modules/Inputs/import-nonmodular/MixedDirectives.framework/Modules/module.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-nonmodular/MixedDirectives.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+framework module MixedDirectives {
+  header "MixedDirectives.h"
+  export *
+}
Index: clang/test/Modules/Inputs/import-nonmodular/MixedDirectives.framework/Headers/MixedDirectives.h
===
--- /dev/null
+++ clang/test/Modules/Inputs/import-nonmodular/MixedDirectives.framework/Headers/MixedDirectives.h
@@ -0,0 +1,2 @@
+#import 
+#include 
Index: clang/li

[PATCH] D104424: [Sema] Fix for PR50741

2021-06-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

Two small changes to the test that you can do as a part of committing.  Thanks!




Comment at: clang/test/Sema/unbounded-array-bounds.c:17
   ++s[7073650413200313099].b;
-  // CHECK-X86-ADDR64:  :[[@LINE-1]]:5: warning: array index 
7073650413200313099 refers past the last possible element for an array in 
64-bit address space containing 256-bit (32-byte) elements (max possible 
576460752303423488 elements)
-  // CHECK-I386-ADDR32: :[[@LINE-2]]:5: warning: {{.*}} past the last possible 
element {{.*}} in 32-bit {{.*}} (max possible 178956970 elements)
-  // CHECK-AVR-ADDR16:  :[[@LINE-3]]:5: warning: {{.*}} past the last possible 
element {{.*}} in 16-bit {{.*}} (max possible 3276 elements)
+  // addr16-warning@16 {{array index 7073650413200313099 refers past the last 
possible element for an array in 16-bit address space containing 160-bit 
(20-byte) elements (max possible 3276 elements)}}
+  // addr32-warning@16 {{array index 7073650413200313099 refers past the last 
possible element for an array in 32-bit address space containing 192-bit 
(24-byte) elements (max possible 178956970 elements)}}

Rather than actual line numbers, do @-1 here instead (you can do relative 
values).  That way all of these are easy to read when going back through these.



Comment at: clang/test/Sema/unbounded-array-bounds.c:80
+void pr50741() {
+  (void *)0 + 0xdeadUL; // expected-warning {{expression result 
unused}}
+  // no array-bounds warning, and no crash

As this warning is unrelated here, I'd suggest either casting this entire thing 
to (void) to suppress this, or just doing -Wno-unused on the command line flags.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104424

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


[clang] 12c90e2 - [clang] NRVO: Improvements and handling of more cases.

2021-06-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-17T01:56:38+02:00
New Revision: 12c90e2e25dfd1d38250055efc21acb42d158912

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

LOG: [clang] NRVO: Improvements and handling of more cases.

This expands NRVO propagation for more cases:

Parse analysis improvement:
* Lambdas and Blocks with dependent return type can have their variables
  marked as NRVO Candidates.

Variable instantiation improvements:
* Fixes crash when instantiating NRVO variables in Blocks.
* Functions, Lambdas, and Blocks which have auto return type have their
  variables' NRVO status propagated. For Blocks with non-auto return type,
  as a limitation, this propagation does not consider the actual return
  type.

This also implements exclusion of VarDecls which are references to
dependent types.

Signed-off-by: Matheus Izvekov 

Reviewed By: Quuxplusone

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

Added: 
clang/test/SemaObjCXX/block-capture.mm

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/CodeGen/nrvo-tracking.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6ade9d7691266..f7ec89a33e00c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3455,12 +3455,6 @@ class Sema final {
   bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
   bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg);
 
-  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
- const VarDecl *NRVOCandidate,
- QualType ResultType,
- Expr *Value,
- bool AllowNRVO = true);
-
   bool CanPerformAggregateInitializationForOverloadResolution(
   const InitializedEntity &Entity, InitListExpr *From);
 
@@ -4760,28 +4754,30 @@ class Sema final {
SourceLocation Loc,
unsigned NumParams);
 
-  enum CopyElisionSemanticsKind {
-CES_Strict = 0,
-CES_AllowParameters = 1,
-CES_AllowDifferentTypes = 2,
-CES_AllowExceptionVariables = 4,
-CES_AllowRValueReferenceType = 8,
-CES_ImplicitlyMovableCXX11CXX14CXX17 =
-(CES_AllowParameters | CES_AllowDifferentTypes),
-CES_ImplicitlyMovableCXX20 =
-(CES_AllowParameters | CES_AllowDifferentTypes |
- CES_AllowExceptionVariables | CES_AllowRValueReferenceType),
+  struct NamedReturnInfo {
+const VarDecl *Candidate;
+
+enum Status : uint8_t { None, MoveEligible, MoveEligibleAndCopyElidable };
+Status S;
+
+bool isMoveEligible() const { return S != None; };
+bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }
   };
+  NamedReturnInfo getNamedReturnInfo(const Expr *E, bool ForceCXX20 = false);
+  NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
+ bool ForceCXX20 = false);
+  const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info,
+ QualType ReturnType);
 
-  VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
-   CopyElisionSemanticsKind CESK);
-  bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
-  CopyElisionSemanticsKind CESK);
+  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
+ const NamedReturnInfo &NRInfo,
+ Expr *Value);
 
   StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
  Scope *CurScope);
   StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
-  StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr 
*RetValExp);
+  StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
+ NamedReturnInfo &NRInfo);
 
   StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
  bool IsVolatile, unsigned NumOutputs,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 850c189cc51a3..b87e2c2bea80d 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1955,6 +1955,9 @@ void Sema::RecordParsingTemplateParameterDepth(unsigned 
Depth) {
 
 // Check that the type of the VarDecl has an accessible copy constru

[PATCH] D99696: [clang] NRVO: Improvements and handling of more cases.

2021-06-16 Thread Matheus Izvekov 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 rG12c90e2e25df: [clang] NRVO: Improvements and handling of 
more cases. (authored by mizvekov).

Changed prior to commit:
  https://reviews.llvm.org/D99696?vs=352566&id=352586#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99696

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGen/nrvo-tracking.cpp
  clang/test/SemaObjCXX/block-capture.mm

Index: clang/test/SemaObjCXX/block-capture.mm
===
--- /dev/null
+++ clang/test/SemaObjCXX/block-capture.mm
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_20,cxx20%s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fobjc-arc -fblocks   -verify=cxx98_20,cxx98_11 %s
+// RUN: %clang_cc1 -std=c++98 -fsyntax-only -fobjc-arc -fblocks -Wno-c++11-extensions -verify=cxx98_20,cxx98_11 %s
+
+#define TEST(T) void test_##T() { \
+  __block T x;\
+  (void)^(void) { (void)x; }; \
+}
+
+struct CopyOnly {
+  CopyOnly();
+  CopyOnly(CopyOnly &);
+};
+TEST(CopyOnly);
+
+struct CopyNoMove {
+  CopyNoMove();
+  CopyNoMove(CopyNoMove &);
+  CopyNoMove(CopyNoMove &&) = delete; // cxx98_20-note {{marked deleted here}}
+};
+TEST(CopyNoMove); // cxx98_20-error {{call to deleted constructor}}
+
+struct MoveOnly {
+  MoveOnly();
+  MoveOnly(MoveOnly &) = delete;
+  MoveOnly(MoveOnly &&);
+};
+TEST(MoveOnly);
+
+struct NoCopyNoMove {
+  NoCopyNoMove();
+  NoCopyNoMove(NoCopyNoMove &) = delete;
+  NoCopyNoMove(NoCopyNoMove &&) = delete; // cxx98_20-note {{marked deleted here}}
+};
+TEST(NoCopyNoMove); // cxx98_20-error {{call to deleted constructor}}
+
+struct ConvertingRVRef {
+  ConvertingRVRef();
+  ConvertingRVRef(ConvertingRVRef &) = delete; // cxx98_11-note {{marked deleted here}}
+
+  struct X {};
+  ConvertingRVRef(X &&);
+  operator X() const & = delete;
+  operator X() &&;
+};
+TEST(ConvertingRVRef); // cxx98_11-error {{call to deleted constructor}}
+
+struct ConvertingCLVRef {
+  ConvertingCLVRef();
+  ConvertingCLVRef(ConvertingCLVRef &);
+
+  struct X {};
+  ConvertingCLVRef(X &&); // cxx20-note {{passing argument to parameter here}}
+  operator X() const &;
+  operator X() && = delete; // cxx20-note {{marked deleted here}}
+};
+TEST(ConvertingCLVRef); // cxx20-error {{invokes a deleted function}}
+
+struct SubSubMove {};
+struct SubMove : SubSubMove {
+  SubMove();
+  SubMove(SubMove &) = delete; // cxx98_11-note {{marked deleted here}}
+
+  SubMove(SubSubMove &&);
+};
+TEST(SubMove); // cxx98_11-error {{call to deleted constructor}}
Index: clang/test/CodeGen/nrvo-tracking.cpp
===
--- clang/test/CodeGen/nrvo-tracking.cpp
+++ clang/test/CodeGen/nrvo-tracking.cpp
@@ -29,8 +29,6 @@
 
 // CHECK-LABEL: define{{.*}} void @_Z2l3v
 // CHECK:   call {{.*}} @_ZN1XC1Ev
-// CHECK-NEXT:  call {{.*}} @_ZN1XC1EOS_
-// CHECK-NEXT:  call void @llvm.lifetime.end
 // CHECK-NEXT:  call void @llvm.lifetime.end
 // CHECK-NEXT:  ret void
 L(3, t, T);
@@ -152,7 +150,11 @@
   }; }()();\
 }
 
-//B(1, X); // Uncomment this line at your own peril ;)
+// CHECK-LABEL: define{{.*}} void @_Z2b1v
+// CHECK:   call {{.*}} @_ZN1XC1Ev
+// CHECK-NEXT:  call void @llvm.lifetime.end
+// CHECK-NEXT:  ret void
+B(1, X);
 
 // CHECK-LABEL: define{{.*}} void @_Z2b2v
 // CHECK:   call {{.*}} @_ZN1XC1Ev
@@ -164,8 +166,6 @@
 
 // CHECK-LABEL: define{{.*}} void @_Z2b3v
 // CHECK:   call {{.*}} @_ZN1XC1Ev
-// CHECK-NEXT:  call {{.*}} @_ZN1XC1EOS_
-// CHECK-NEXT:  call void @llvm.lifetime.end
 // CHECK-NEXT:  call void @llvm.lifetime.end
 // CHECK-NEXT:  ret void
 B(3, T);
@@ -187,3 +187,26 @@
 B(5, );
 
 #undef B
+
+// CHECK-LABEL: define{{.*}} void @_Z6f_attrv
+// CHECK:   call {{.*}} @_ZN1XC1Ev
+// CHECK-NEXT:  call void @llvm.lifetime.end
+// CHECK-NEXT:  ret void
+template [[gnu::cdecl]] static inline auto tf_attr() -> X {
+  T t;
+  return t;
+}
+void f_attr() { auto t = tf_attr(); }
+
+// CHECK-LABEL: define{{.*}} void @_Z6b_attrv
+// CHECK:   call {{.*}} @_ZN1XC1Ev
+// CHECK-NEXT:  call void @llvm.lifetime.end
+// CHECK-NEXT:  ret void
+void b_attr() {
+  auto t = []() {
+return ^X() [[clang::vectorcall]] {
+  T t;
+  return t;
+};
+  }()();
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -23,6 +23,7 @@
 #include "clang/Basi

  1   2   >