[PATCH] D84087: [NFC] Clean up doc comment and implementation for Module::isSubModuleOf.

2020-07-17 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84087

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/Basic/Module.cpp


Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -173,14 +173,10 @@
 }
 
 bool Module::isSubModuleOf(const Module *Other) const {
-  const Module *This = this;
-  do {
+  for (const Module *This = this; This != nullptr; This = This->Parent) {
 if (This == Other)
   return true;
-
-This = This->Parent;
-  } while (This);
-
+  }
   return false;
 }
 
Index: clang/include/clang/Basic/Module.h
===
--- clang/include/clang/Basic/Module.h
+++ clang/include/clang/Basic/Module.h
@@ -457,8 +457,12 @@
   /// Determine whether this module is a submodule.
   bool isSubModule() const { return Parent != nullptr; }
 
-  /// Determine whether this module is a submodule of the given other
-  /// module.
+  /// Check if this module is a (possibly transitive) submodule of \p Other.
+  ///
+  /// The 'A is a submodule of B' relation is a partial order based on the
+  /// the parent-child relationship between individual modules.
+  ///
+  /// Returns \c false if \p Other is \c nullptr.
   bool isSubModuleOf(const Module *Other) const;
 
   /// Determine whether this module is a part of a framework,


Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -173,14 +173,10 @@
 }
 
 bool Module::isSubModuleOf(const Module *Other) const {
-  const Module *This = this;
-  do {
+  for (const Module *This = this; This != nullptr; This = This->Parent) {
 if (This == Other)
   return true;
-
-This = This->Parent;
-  } while (This);
-
+  }
   return false;
 }
 
Index: clang/include/clang/Basic/Module.h
===
--- clang/include/clang/Basic/Module.h
+++ clang/include/clang/Basic/Module.h
@@ -457,8 +457,12 @@
   /// Determine whether this module is a submodule.
   bool isSubModule() const { return Parent != nullptr; }
 
-  /// Determine whether this module is a submodule of the given other
-  /// module.
+  /// Check if this module is a (possibly transitive) submodule of \p Other.
+  ///
+  /// The 'A is a submodule of B' relation is a partial order based on the
+  /// the parent-child relationship between individual modules.
+  ///
+  /// Returns \c false if \p Other is \c nullptr.
   bool isSubModuleOf(const Module *Other) const;
 
   /// Determine whether this module is a part of a framework,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84087: [NFC] Clean up doc comment and implementation for Module::isSubModuleOf.

2020-07-17 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 278972.
varungandhi-apple added a comment.

Updated commit message with reviewer information and revision link.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84087

Files:
  clang/include/clang/Basic/Module.h
  clang/lib/Basic/Module.cpp


Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -173,14 +173,10 @@
 }
 
 bool Module::isSubModuleOf(const Module *Other) const {
-  const Module *This = this;
-  do {
+  for (const Module *This = this; This != nullptr; This = This->Parent) {
 if (This == Other)
   return true;
-
-This = This->Parent;
-  } while (This);
-
+  }
   return false;
 }
 
Index: clang/include/clang/Basic/Module.h
===
--- clang/include/clang/Basic/Module.h
+++ clang/include/clang/Basic/Module.h
@@ -457,8 +457,12 @@
   /// Determine whether this module is a submodule.
   bool isSubModule() const { return Parent != nullptr; }
 
-  /// Determine whether this module is a submodule of the given other
-  /// module.
+  /// Check if this module is a (possibly transitive) submodule of \p Other.
+  ///
+  /// The 'A is a submodule of B' relation is a partial order based on the
+  /// the parent-child relationship between individual modules.
+  ///
+  /// Returns \c false if \p Other is \c nullptr.
   bool isSubModuleOf(const Module *Other) const;
 
   /// Determine whether this module is a part of a framework,


Index: clang/lib/Basic/Module.cpp
===
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -173,14 +173,10 @@
 }
 
 bool Module::isSubModuleOf(const Module *Other) const {
-  const Module *This = this;
-  do {
+  for (const Module *This = this; This != nullptr; This = This->Parent) {
 if (This == Other)
   return true;
-
-This = This->Parent;
-  } while (This);
-
+  }
   return false;
 }
 
Index: clang/include/clang/Basic/Module.h
===
--- clang/include/clang/Basic/Module.h
+++ clang/include/clang/Basic/Module.h
@@ -457,8 +457,12 @@
   /// Determine whether this module is a submodule.
   bool isSubModule() const { return Parent != nullptr; }
 
-  /// Determine whether this module is a submodule of the given other
-  /// module.
+  /// Check if this module is a (possibly transitive) submodule of \p Other.
+  ///
+  /// The 'A is a submodule of B' relation is a partial order based on the
+  /// the parent-child relationship between individual modules.
+  ///
+  /// Returns \c false if \p Other is \c nullptr.
   bool isSubModuleOf(const Module *Other) const;
 
   /// Determine whether this module is a part of a framework,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D84087: [NFC] Clean up doc comment and implementation for Module::isSubModuleOf.

2020-07-21 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple marked an inline comment as done.
varungandhi-apple added inline comments.



Comment at: clang/lib/Basic/Module.cpp:176
 bool Module::isSubModuleOf(const Module *Other) const {
-  const Module *This = this;
-  do {
+  for (const Module *This = this; This != nullptr; This = This->Parent) {
 if (This == Other)

aprantl wrote:
> ```
> for (const Module *Parent = this; Parent; Parent = Parent->Parent) {
>   if (Parent == Other)
>return true;
> }
> ```
> ?
That seems confusing... I would like to avoid giving a local variable the same 
name as an instance member. I can rename `This` to `Current` if that makes it 
clearer?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84087



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


[PATCH] D84087: [NFC] Clean up doc comment and implementation for Module::isSubModuleOf.

2020-07-21 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added a comment.

(Could you land the patch if it looks good? I don't have commit access.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84087



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


[PATCH] D84087: [NFC] Clean up doc comment and implementation for Module::isSubModuleOf.

2020-07-21 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added a comment.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D84087



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


[PATCH] D82791: [lit] Improve lit's output with default settings and --verbose.

2020-07-26 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 280786.
varungandhi-apple marked 11 inline comments as done.
varungandhi-apple added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82791

Files:
  llvm/docs/CommandGuide/lit.rst
  llvm/utils/lit/lit/LitConfig.py
  llvm/utils/lit/lit/OutputSettings.py
  llvm/utils/lit/lit/TestRunner.py
  llvm/utils/lit/lit/cl_arguments.py
  llvm/utils/lit/lit/display.py
  llvm/utils/lit/lit/main.py
  llvm/utils/lit/tests/shtest-format.py
  llvm/utils/lit/tests/shtest-run-at-line.py
  llvm/utils/lit/tests/unittest-failing-locator.py

Index: llvm/utils/lit/tests/unittest-failing-locator.py
===
--- /dev/null
+++ llvm/utils/lit/tests/unittest-failing-locator.py
@@ -0,0 +1,122 @@
+# Check that the locate_last_failing_run_line function works as expected.
+
+# RUN: %{python} %s
+# END.
+
+import unittest
+
+from lit.TestRunner import locate_last_run_line
+
+class TestRunLineLocatorHeuristics(unittest.TestCase):
+
+def test_basic(self):
+# from a script like
+# RUN: echo Hello 1>&2
+basic = (
+"+ : 'RUN: at line 1'\n"
+"+ echo Hello 1>&2\n"
+"+ Hello\n"
+)
+line_start, substr = locate_last_run_line(basic)
+self.assertEqual(line_start, 0)
+self.assertEqual(substr, "RUN: at line 1")
+
+def test_multiple(self):
+# from a script like
+# RUN: echo Hello 1>&2
+# RUN: false
+multiple = (
+"+ : 'RUN: at line 1'\n"
+"+ echo Hello 1>&2\n"
+"+ Hello\n"
+"+ : 'RUN: at line 2'\n"
+"+ false\n"
+)
+line_start, substr = locate_last_run_line(multiple)
+self.assertEqual(line_start, multiple.rfind("+ :"))
+self.assertEqual(substr, "RUN: at line 2")
+
+def test_varying_prefix(self):
+# from a script like
+# RUN: echo Hello 1>&2
+# RUN: false
+#
+# in a hypothetical shell which prints line-numbers on 'set +x'
+# (as an example of something that varies)
+varying_prefix = (
+"+ 1 : 'RUN: at line 1'\n"
+"+ 2 echo Hello 1>&2\n"
+"+ Hello\n"
+"+ 3 : 'RUN: at line 2'\n"
+"+ 4 false\n"
+)
+line_start, substr = locate_last_run_line(varying_prefix)
+self.assertEqual(line_start, varying_prefix.rfind("+ 3"))
+self.assertEqual(substr, "RUN: at line 2")
+
+def test_confusing_basic(self):
+# from a script like
+# RUN: echo 'RUN: at line 10' 1>&2
+confusing_basic = (
+"+ : 'RUN: at line 1'\n"
+"+ echo 'RUN: at line 10'\n"
+"RUN: at line 10\n"
+)
+line_start, substr = locate_last_run_line(confusing_basic)
+# FIXME: These should both be equal ideally.
+self.assertNotEqual(line_start, 0)
+self.assertNotEqual(substr, "RUN: at line 1")
+
+def test_confusing_multiple(self):
+# from a script like
+# RUN: echo 'RUN: at line 10' 1>&2
+# RUN: false
+confusing_multiple = (
+"+ : 'RUN: at line 1'\n"
+"+ echo 'RUN: at line 10'\n"
+"RUN: at line 10\n"
+"+ : 'RUN: at line 2'\n"
+"+ false\n"
+)
+line_start, substr = locate_last_run_line(confusing_multiple)
+self.assertEqual(line_start, confusing_multiple.rfind("+ :"))
+self.assertEqual(substr, "RUN: at line 2")
+
+def test_confusing_varying_prefix_1(self):
+# from a script like
+# RUN: echo 'RUN: at line 10' 1>&2
+# RUN: false
+#
+# in a hypothetical shell which prints line-numbers on 'set +x'
+# (as an example of something that varies)
+confusing_varying_prefix = (
+"+ 1 : 'RUN: at line 1'\n"
+"+ 2 echo 'RUN: at line 10'\n"
+"RUN: at line 10\n"
+"+ 3 : 'RUN: at line 2'\n"
+"+ 4 false\n"
+)
+line_start, substr = locate_last_run_line(confusing_varying_prefix)
+self.assertEqual(line_start, confusing_varying_prefix.rfind("+ 3"))
+self.assertEqual(substr, "RUN: at line 2")
+
+def test_confusing_varying_prefix_2(self):
+# from a script like
+# RUN: true
+# RUN: not echo 'RUN: at line 100'
+#
+# in a hypothetical shell which prints line-numbers on 'set +x'
+# (as an example of something that varies)
+confusing_varying_prefix = (
+"+ 1 : 'RUN: at line 1'\n"
+"+ 2 true\n"
+"+ 3 : 'RUN: at line 2'\n"
+"+ 4 not echo 'RUN: at line 100'\n"
+"+ RUN: at line 100\n"
+)
+line_start, substr = locate_last_run_line(confusing_varying_prefix)

[PATCH] D82791: [lit] Improve lit's output with default settings and --verbose.

2020-07-26 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added a comment.

Some of the changes probably don't make perfect sense in this revision because 
I initially started out with the whole change being one revision and then split 
things into commits, while trying to minimize the churn between revisions. 
Please also take a look at the follow-up revision D82811 
 and let me know if that's acceptable (less 
churn, less self-contained, things make sense when you look at the two 
together) or if you'd prefer that I make this revision more self-contained 
(that would create more churn in D82811 ).




Comment at: llvm/utils/lit/lit/OutputSettings.py:34
+ONLY_FAILING_COMMAND = CommandOutputStyle("OnlyFailing")
+UP_TO_AND_INCLUDING_FAILING_COMMAND = CommandOutputStyle("UpToAndIncluding")
+

yln wrote:
> I really like the "communicating intent" part of this infrastructure.  
> However, this is a lot of code and `if`s considering we really only have to 
> distinguish two cases.  From your commit message:
> 
> - default (no flags): no script, show only failing line in command output
> - `-v`: full script, adds 'set +x', shows command output
> 
> Am I missing something or could everything be keyed off a single verbose 
> (reading from the code below `showAllOutput` implies verbose) flag.  Do we 
> anticipate other combinations being useful? (In general I would argue for 
> striving for the simplest implementation that gives us what we currently want 
> and not try to anticipate future extensions.)
> 
> Have you considered (or started out with) just using a single verbose flag to 
> base your decisions in the implementation functions?  
Not sure what you mean by two cases, I think there are three cases:

1. Quiet -> Corresponds on `NO_COMMAND`
2. Default (no quiet, no verbose) -> Corresponds to `ONLY_FAILING`.
3. Verbose -> Corresponds to `UP_TO_AND_INCLUDING_FAILING`.

Since there is a 1-1 correspondence, we _could_ compare quiet vs (!quiet && 
!verbose) vs verbose in `make_command_output`. I chose not to do that because I 
figured this makes the intent clearer by distinguishing between user-specified 
options and derived options.

Does that make sense? Would you still prefer that I get rid of this?



Comment at: llvm/utils/lit/lit/TestRunner.py:1503-1508
+Returns a pair of:
+- The index in ``output_str`` pointing to immediately after the preceding
+  newline, i.e. the start of the RUN line, before any shell-specific
+  prefix.
+- The matched substring itself, including the number at the end,
+  starting with 'RUN', skipping the shell-specific prefix.

yln wrote:
> Why use a complicated parser-like return value? Our only caller below could 
> just receive the potentially found RUN line.
Sorry, it's not super clear because in this revision, there is only one caller, 
which could do with just using the index. However, the highlighting patch 
(which comes right after this logically) ends up making use of the substring. 
The line of reasoning is:

1. A substring by itself is not good enough (and hence `make_command_output` in 
this patch makes use of the first index return value), because we want to 
distinguish the case `line_start == 0` from the case `line_start > 0` by 
printing `Command Output (stderr)` instead of `Command Output (stderr, 
truncated)` when `line_start == 0`.
2. An index by itself could be "good enough", but we try to be smarter in the 
highlighting patch (https://reviews.llvm.org/D82811) by not highlighting the 
shell-specific prefix, and starting highlighting from the "RUN", which 
`make_script_output` makes use of.

Does that make sense? I decided against splitting changes to this function into 
two revisions and have the full functionality in the first iteration because I 
felt like that would create more churn with the tests and the implementation, 
but I see how it can be confusing as to why two 
related-but-slightly-different-values are being returned simultaneously when 
only one is really being used in this patch.



Comment at: llvm/utils/lit/lit/TestRunner.py:1593
+assert(lit_config.script_output_style == OutputSettings.FULL_SCRIPT)
+return default_output()
+

yln wrote:
> Why are we using two local functions here?
> 
> The whole thing could be (already assuming just one verbose flag):
> 
> ```
> def make_script_output(lit_config, script_lines, exit_code):
> if not lit_config.verbose:
> return ""
> return ...
> ```
It mimics the structure of the `make_command_output` function right below. 
Right now, this function is very simple, so it probably seems overkill. 
However, `make_script_output` becomes much more complicated in the highlighting 
patch after this: https://reviews.llvm.org/D82811, so I figured it would be 
helpful to have the two functions `make_script_output` and 
`make_command_output` follow a similar pa

[PATCH] D82791: [lit] Improve lit's output with default settings and --verbose.

2020-07-01 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 274865.
varungandhi-apple added a comment.

Rebase after changes in D82808 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82791

Files:
  llvm/docs/CommandGuide/lit.rst
  llvm/utils/lit/lit/LitConfig.py
  llvm/utils/lit/lit/OutputSettings.py
  llvm/utils/lit/lit/TestRunner.py
  llvm/utils/lit/lit/cl_arguments.py
  llvm/utils/lit/lit/display.py
  llvm/utils/lit/lit/main.py
  llvm/utils/lit/tests/shtest-format.py
  llvm/utils/lit/tests/shtest-run-at-line.py
  llvm/utils/lit/tests/unittest-failing-locator.py

Index: llvm/utils/lit/tests/unittest-failing-locator.py
===
--- /dev/null
+++ llvm/utils/lit/tests/unittest-failing-locator.py
@@ -0,0 +1,122 @@
+# Check that the locate_last_failing_run_line function works as expected.
+
+# RUN: %{python} %s
+# END.
+
+import unittest
+
+from lit.TestRunner import locate_last_run_line
+
+class TestRunLineLocatorHeuristics(unittest.TestCase):
+
+def test_basic(self):
+# from a script like
+# RUN: echo Hello 1>&2
+basic = (
+"+ : 'RUN: at line 1'\n"
+"+ echo Hello 1>&2\n"
+"+ Hello\n"
+)
+line_start, substr = locate_last_run_line(basic)
+self.assertEqual(line_start, 0)
+self.assertEqual(substr, "RUN: at line 1")
+
+def test_multiple(self):
+# from a script like
+# RUN: echo Hello 1>&2
+# RUN: false
+multiple = (
+"+ : 'RUN: at line 1'\n"
+"+ echo Hello 1>&2\n"
+"+ Hello\n"
+"+ : 'RUN: at line 2'\n"
+"+ false\n"
+)
+line_start, substr = locate_last_run_line(multiple)
+self.assertEqual(line_start, multiple.rfind("+ :"))
+self.assertEqual(substr, "RUN: at line 2")
+
+def test_varying_prefix(self):
+# from a script like
+# RUN: echo Hello 1>&2
+# RUN: false
+#
+# in a hypothetical shell which prints line-numbers on 'set +x'
+# (as an example of something that varies)
+varying_prefix = (
+"+ 1 : 'RUN: at line 1'\n"
+"+ 2 echo Hello 1>&2\n"
+"+ Hello\n"
+"+ 3 : 'RUN: at line 2'\n"
+"+ 4 false\n"
+)
+line_start, substr = locate_last_run_line(varying_prefix)
+self.assertEqual(line_start, varying_prefix.rfind("+ 3"))
+self.assertEqual(substr, "RUN: at line 2")
+
+def test_confusing_basic(self):
+# from a script like
+# RUN: echo 'RUN: at line 10' 1>&2
+confusing_basic = (
+"+ : 'RUN: at line 1'\n"
+"+ echo 'RUN: at line 10'\n"
+"RUN: at line 10\n"
+)
+line_start, substr = locate_last_run_line(confusing_basic)
+# FIXME: These should both be equal ideally.
+self.assertNotEqual(line_start, 0)
+self.assertNotEqual(substr, "RUN: at line 1")
+
+def test_confusing_multiple(self):
+# from a script like
+# RUN: echo 'RUN: at line 10' 1>&2
+# RUN: false
+confusing_multiple = (
+"+ : 'RUN: at line 1'\n"
+"+ echo 'RUN: at line 10'\n"
+"RUN: at line 10\n"
+"+ : 'RUN: at line 2'\n"
+"+ false\n"
+)
+line_start, substr = locate_last_run_line(confusing_multiple)
+self.assertEqual(line_start, confusing_multiple.rfind("+ :"))
+self.assertEqual(substr, "RUN: at line 2")
+
+def test_confusing_varying_prefix_1(self):
+# from a script like
+# RUN: echo 'RUN: at line 10' 1>&2
+# RUN: false
+#
+# in a hypothetical shell which prints line-numbers on 'set +x'
+# (as an example of something that varies)
+confusing_varying_prefix = (
+"+ 1 : 'RUN: at line 1'\n"
+"+ 2 echo 'RUN: at line 10'\n"
+"RUN: at line 10\n"
+"+ 3 : 'RUN: at line 2'\n"
+"+ 4 false\n"
+)
+line_start, substr = locate_last_run_line(confusing_varying_prefix)
+self.assertEqual(line_start, confusing_varying_prefix.rfind("+ 3"))
+self.assertEqual(substr, "RUN: at line 2")
+
+def test_confusing_varying_prefix_2(self):
+# from a script like
+# RUN: true
+# RUN: not echo 'RUN: at line 100'
+#
+# in a hypothetical shell which prints line-numbers on 'set +x'
+# (as an example of something that varies)
+confusing_varying_prefix = (
+"+ 1 : 'RUN: at line 1'\n"
+"+ 2 true\n"
+"+ 3 : 'RUN: at line 2'\n"
+"+ 4 not echo 'RUN: at line 100'\n"
+"+ RUN: at line 100\n"
+)
+line_start, substr = locate_last_run_line(confusing_varying_prefix)
+# F

[PATCH] D82791: [lit] Improve lit's output with default settings and --verbose.

2020-07-06 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple marked 2 inline comments as done.
varungandhi-apple added a comment.

Thanks for the review, it's a big patch. 😅 I'm a bit busy at the moment, I will 
respond to the other comments later this week or sometime next week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82791



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


[PATCH] D82791: [lit] Improve lit's output with default settings and --verbose.

2020-06-29 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 274242.
varungandhi-apple added a comment.

- [docs] [lit] Add a more helpful description for lit.py's -s flag.
- [NFC] [lit] Separate verbose and showOutput.
- [lit] Improve lit's output with default settings and --verbose.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82791

Files:
  llvm/docs/CommandGuide/lit.rst
  llvm/utils/lit/lit/LitConfig.py
  llvm/utils/lit/lit/OutputSettings.py
  llvm/utils/lit/lit/TestRunner.py
  llvm/utils/lit/lit/cl_arguments.py
  llvm/utils/lit/lit/display.py
  llvm/utils/lit/lit/main.py
  llvm/utils/lit/tests/shtest-format.py
  llvm/utils/lit/tests/shtest-run-at-line.py
  llvm/utils/lit/tests/unittest-failing-locator.py

Index: llvm/utils/lit/tests/unittest-failing-locator.py
===
--- /dev/null
+++ llvm/utils/lit/tests/unittest-failing-locator.py
@@ -0,0 +1,122 @@
+# Check that the locate_last_failing_run_line function works as expected.
+
+# RUN: %{python} %s
+# END.
+
+import unittest
+
+from lit.TestRunner import locate_last_run_line
+
+class TestRunLineLocatorHeuristics(unittest.TestCase):
+
+def test_basic(self):
+# from a script like
+# RUN: echo Hello 1>&2
+basic = (
+"+ : 'RUN: at line 1'\n"
+"+ echo Hello 1>&2\n"
+"+ Hello\n"
+)
+line_start, substr = locate_last_run_line(basic)
+self.assertEqual(line_start, 0)
+self.assertEqual(substr, "RUN: at line 1")
+
+def test_multiple(self):
+# from a script like
+# RUN: echo Hello 1>&2
+# RUN: false
+multiple = (
+"+ : 'RUN: at line 1'\n"
+"+ echo Hello 1>&2\n"
+"+ Hello\n"
+"+ : 'RUN: at line 2'\n"
+"+ false\n"
+)
+line_start, substr = locate_last_run_line(multiple)
+self.assertEqual(line_start, multiple.rfind("+ :"))
+self.assertEqual(substr, "RUN: at line 2")
+
+def test_varying_prefix(self):
+# from a script like
+# RUN: echo Hello 1>&2
+# RUN: false
+#
+# in a hypothetical shell which prints line-numbers on 'set +x'
+# (as an example of something that varies)
+varying_prefix = (
+"+ 1 : 'RUN: at line 1'\n"
+"+ 2 echo Hello 1>&2\n"
+"+ Hello\n"
+"+ 3 : 'RUN: at line 2'\n"
+"+ 4 false\n"
+)
+line_start, substr = locate_last_run_line(varying_prefix)
+self.assertEqual(line_start, varying_prefix.rfind("+ 3"))
+self.assertEqual(substr, "RUN: at line 2")
+
+def test_confusing_basic(self):
+# from a script like
+# RUN: echo 'RUN: at line 10' 1>&2
+confusing_basic = (
+"+ : 'RUN: at line 1'\n"
+"+ echo 'RUN: at line 10'\n"
+"RUN: at line 10\n"
+)
+line_start, substr = locate_last_run_line(confusing_basic)
+# FIXME: These should both be equal ideally.
+self.assertNotEqual(line_start, 0)
+self.assertNotEqual(substr, "RUN: at line 1")
+
+def test_confusing_multiple(self):
+# from a script like
+# RUN: echo 'RUN: at line 10' 1>&2
+# RUN: false
+confusing_multiple = (
+"+ : 'RUN: at line 1'\n"
+"+ echo 'RUN: at line 10'\n"
+"RUN: at line 10\n"
+"+ : 'RUN: at line 2'\n"
+"+ false\n"
+)
+line_start, substr = locate_last_run_line(confusing_multiple)
+self.assertEqual(line_start, confusing_multiple.rfind("+ :"))
+self.assertEqual(substr, "RUN: at line 2")
+
+def test_confusing_varying_prefix_1(self):
+# from a script like
+# RUN: echo 'RUN: at line 10' 1>&2
+# RUN: false
+#
+# in a hypothetical shell which prints line-numbers on 'set +x'
+# (as an example of something that varies)
+confusing_varying_prefix = (
+"+ 1 : 'RUN: at line 1'\n"
+"+ 2 echo 'RUN: at line 10'\n"
+"RUN: at line 10\n"
+"+ 3 : 'RUN: at line 2'\n"
+"+ 4 false\n"
+)
+line_start, substr = locate_last_run_line(confusing_varying_prefix)
+self.assertEqual(line_start, confusing_varying_prefix.rfind("+ 3"))
+self.assertEqual(substr, "RUN: at line 2")
+
+def test_confusing_varying_prefix_2(self):
+# from a script like
+# RUN: true
+# RUN: not echo 'RUN: at line 100'
+#
+# in a hypothetical shell which prints line-numbers on 'set +x'
+# (as an example of something that varies)
+confusing_varying_prefix = (
+"+ 1 : 'RUN: at line 1'\n"
+"+ 2 true\n"
+"+ 3 : 'RUN: at line 2'\n"
+"+ 4 not echo 'RUN: at line 100'\n"
+"+ RUN: 

[PATCH] D82791: [lit] Improve lit's output with default settings and --verbose.

2020-06-29 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 274240.
varungandhi-apple added a comment.
Herald added subscribers: cfe-commits, martong.
Herald added a project: clang.

Include missing commit separating verbose and showOutput.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D82791

Files:
  clang/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h
  clang/lib/StaticAnalyzer/Core/BugReporter.cpp
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/CodeGen/aarch64-sve.c
  clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp
  clang/test/CodeGenCXX/aarch64-sve-typeinfo.cpp
  clang/test/CodeGenObjC/aarch64-sve-types.m
  clang/test/PCH/aarch64-sve-types.c
  clang/test/Sema/aarch64-sve-types.c
  clang/test/SemaObjC/aarch64-sve-types.m
  clang/unittests/StaticAnalyzer/FalsePositiveRefutationBRVisitorTest.cpp

Index: clang/unittests/StaticAnalyzer/FalsePositiveRefutationBRVisitorTest.cpp
===
--- clang/unittests/StaticAnalyzer/FalsePositiveRefutationBRVisitorTest.cpp
+++ clang/unittests/StaticAnalyzer/FalsePositiveRefutationBRVisitorTest.cpp
@@ -170,6 +170,54 @@
 "test.FalsePositiveGenerator:CAN_BE_TRUE\n");
 }
 
+TEST(FalsePositiveRefutationBRVisitor,
+ UnSatAtErrorNodeDueToRefinedConstraintNoReport) {
+  SKIP_WITHOUT_Z3;
+  constexpr auto Code = R"(
+void reportIfCanBeTrue(bool);
+void reachedWithNoContradiction();
+void test(unsigned x, unsigned n) {
+  if (n >= 1 && n <= 2) {
+if (x >= 3)
+  return;
+// x: [0,2] and n: [1,2]
+int y = x + n; // y: '(x+n)' Which is in approximately between 1 and 4.
+
+// Registers the symbol 'y' with the constraint [1, MAX] in the true
+// branch.
+if (y > 0) {
+  // Since the x: [0,2] and n: [1,2], the 'y' is indeed greater than
+  // zero. If we emit a warning here, the constraints on the BugPath is
+  // SAT. Therefore that report is NOT invalidated.
+  reachedWithNoContradiction(); // 'y' can be greater than zero. OK
+
+  // If we ask the analyzer whether the 'y' can be 5. It won't know,
+  // therefore, the state will be created where the 'y' expression is 5.
+  // Although, this assumption is false!
+  // 'y' can not be 5 if the maximal value of both x and n is 2.
+  // The BugPath which become UnSAT in the ErrorNode with a refined
+  // constraint, should be invalidated.
+  reportIfCanBeTrue(y == 5);
+}
+  }
+})";
+
+  std::string Diags;
+  EXPECT_TRUE(runCheckerOnCodeWithArgs(
+  Code, LazyAssumeAndCrossCheckArgs, Diags));
+  EXPECT_EQ(Diags,
+"test.FalsePositiveGenerator:REACHED_WITH_NO_CONTRADICTION\n");
+  // Single warning. The second report was invalidated by the visitor.
+
+  // Without enabling the crosscheck-with-z3 both reports are displayed.
+  std::string Diags2;
+  EXPECT_TRUE(runCheckerOnCodeWithArgs(
+  Code, LazyAssumeArgs, Diags2));
+  EXPECT_EQ(Diags2,
+"test.FalsePositiveGenerator:REACHED_WITH_NO_CONTRADICTION\n"
+"test.FalsePositiveGenerator:CAN_BE_TRUE\n");
+}
+
 } // namespace
 } // namespace ento
 } // namespace clang
Index: clang/test/SemaObjC/aarch64-sve-types.m
===
--- clang/test/SemaObjC/aarch64-sve-types.m
+++ clang/test/SemaObjC/aarch64-sve-types.m
@@ -18,5 +18,7 @@
 @property(nullable) __SVFloat32_t f32; // expected-error {{cannot be applied to non-pointer type}}
 @property(nullable) __SVFloat64_t f64; // expected-error {{cannot be applied to non-pointer type}}
 
+@property(nullable) __SVBFloat16_t bf16; // expected-error {{cannot be applied to non-pointer type}}
+
 @property(nullable) __SVBool_t b8; // expected-error {{cannot be applied to non-pointer type}}
 @end
Index: clang/test/Sema/aarch64-sve-types.c
===
--- clang/test/Sema/aarch64-sve-types.c
+++ clang/test/Sema/aarch64-sve-types.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -triple aarch64-none-linux-gnu -target-feature +sve -fsyntax-only -verify
+// RUN: %clang_cc1 %s -triple aarch64-none-linux-gnu -target-feature +sve,+bf16 -fsyntax-only -verify
 
 void f() {
   int size_s8[sizeof(__SVInt8_t) == 0 ? 1 : -1];// expected-error {{invalid application of 'sizeof' to sizeless type '__SVInt8_t'}}
@@ -34,6 +34,9 @@
   int size_f64[sizeof(__SVFloat64_t) == 0 ? 1 : -1];// expected-error {{invalid application of 'sizeof' to sizeless type '__SVFloat64_t'}}
   int align_f64[__alignof__(__SVFloat64_t) == 16 ? 1 : -1]; // expected-error {{invalid application of '__alignof' to sizeless type '__SVFloat64_t'}}
 
+  int size_bf16[sizeof(__SVBFloat16_t) == 0 ? 1 : -1];// expected-error {{invalid application of 'sizeof' to sizeless type '__SVBFloat1

[PATCH] D95053: [Demangle] Support demangling Swift calling convention in MS demangler.

2021-01-27 Thread Varun Gandhi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG44f792966e0f: [Demangle] Support demangling Swift calling 
convention in MS demangler. (authored by varungandhi-apple).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95053

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-mangle.test


Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -338,6 +338,9 @@
 ?vector_func@@YQXXZ
 ; CHECK: void __vectorcall vector_func(void)
 
+?swift_func@@YSXXZ
+; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -107,6 +107,9 @@
   case CallingConv::Clrcall:
 OS << "__clrcall";
 break;
+  case CallingConv::Swift:
+OS << "__attribute__((__swiftcall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1711,6 +1711,8 @@
 return CallingConv::Eabi;
   case 'Q':
 return CallingConv::Vectorcall;
+  case 'S':
+return CallingConv::Swift;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,6 +67,7 @@
   Eabi,
   Vectorcall,
   Regcall,
+  Swift, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -2684,6 +2684,7 @@
   //  ::= I # __fastcall
   //  ::= J # __export __fastcall
   //  ::= Q # __vectorcall
+  //  ::= S # __attribute__((__swiftcall__)) // Clang-only
   //  ::= w # __regcall
   // The 'export' calling conventions are from a bygone era
   // (*cough*Win16*cough*) when functions were declared for export with


Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -338,6 +338,9 @@
 ?vector_func@@YQXXZ
 ; CHECK: void __vectorcall vector_func(void)
 
+?swift_func@@YSXXZ
+; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -107,6 +107,9 @@
   case CallingConv::Clrcall:
 OS << "__clrcall";
 break;
+  case CallingConv::Swift:
+OS << "__attribute__((__swiftcall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1711,6 +1711,8 @@
 return CallingConv::Eabi;
   case 'Q':
 return CallingConv::Vectorcall;
+  case 'S':
+return CallingConv::Swift;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,6 +67,7 @@
   Eabi,
   Vectorcall,
   Regcall,
+  Swift, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -2684,6 +2684,7 @@
   //  ::= I # __fastcall
   //  ::= J # __export __fastcall
   //  ::= Q # __vectorcall
+  //  ::= S # __attribute__((__swiftcall__)) // Clang-only
   //   

[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-01-27 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple created this revision.
varungandhi-apple added reviewers: rjmccall, ahatanak.
Herald added subscribers: dexonsmith, arphaman, kbarton, hiraditya, 
jgravelle-google, sbc100, nemanjai, dschuff.
Herald added a reviewer: aaron.ballman.
varungandhi-apple published this revision for review.
Herald added subscribers: llvm-commits, cfe-commits, aheejin.
Herald added projects: clang, LLVM.

This change is intended as initial setup. The plan is to add
more semantic checks later. I plan to update the documentation
as more semantic checks are added (instead of documenting the
details up front). Most of the code closely mirrors that for
the Swift calling convention. Three places are marked as
[FIXME: swiftasynccc]; those will be addressed once the
corresponding convention is introduced in LLVM.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95561

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/CodeGen/SwiftCallingConv.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/Sema/attr-swiftcall.c
  clang/test/Sema/no_callconv.cpp
  clang/test/SemaCXX/attr-swiftcall.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-mangle.test

Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -341,6 +341,9 @@
 ?swift_func@@YSXXZ
 ; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
 
+?swift_async_func@@YTXXZ
+; CHECK: void __attribute__((__swiftasynccall__))swift_async_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -110,6 +110,9 @@
   case CallingConv::Swift:
 OS << "__attribute__((__swiftcall__)) ";
 break;
+  case CallingConv::SwiftAsync:
+OS << "__attribute__((__swiftasynccall__))";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1713,6 +1713,8 @@
 return CallingConv::Vectorcall;
   case 'S':
 return CallingConv::Swift;
+  case 'T':
+return CallingConv::SwiftAsync;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,7 +67,8 @@
   Eabi,
   Vectorcall,
   Regcall,
-  Swift, // Clang-only
+  Swift,  // Clang-only
+  SwiftAsync, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -664,6 +664,7 @@
   TCALLINGCONV(AAPCS_VFP);
   TCALLINGCONV(IntelOclBicc);
   TCALLINGCONV(Swift);
+  TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/attr-swiftcall.cpp
===
--- clang/test/SemaCXX/attr-swiftcall.cpp
+++ clang/test/SemaCXX/attr-swiftcall.cpp
@@ -1,14 +1,20 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
 
 #define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
 #define INDIRECT_RESULT __attribute__((swift_indirect_result))
 #define ERROR_RESULT __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
 
 int notAFunction SWIFTCALL; // expected-warning {{'swiftcall' only applies to function types; type here is 'int

[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-01-27 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:4398
+  let Content = [{
+TODO
+  }];

I have left this as a TODO for now, so that it can be filled in later when the 
exact details of the convention are implemented in LLVM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

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


[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-01-27 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added a comment.

I don't get how you stack your change on top of someone else's change (the diff 
seems to have been created with only one commit), but this depends on 
https://reviews.llvm.org/D95228, which depends on 
https://reviews.llvm.org/D95044.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

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


[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-01-27 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:2688-2689
   //  ::= S # __attribute__((__swiftcall__)) // Clang-only
+  //  ::= T # __attribute__((__swiftasynccall__)) //
+  //  Clang-only
   //  ::= w # __regcall

Whitespace needs fixing after comment was broken up by `arc`'s linter.



Comment at: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp:114
+  case CallingConv::SwiftAsync:
+OS << "__attribute__((__swiftasynccall__))";
+break;

Need to add extra whitespace at end similar to `__swiftcall__`.



Comment at: llvm/test/Demangle/ms-mangle.test:345
+?swift_async_func@@YTXXZ
+; CHECK: void __attribute__((__swiftasynccall__))swift_async_func(void)
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

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


[PATCH] D95704: [CodeGen] Introduce DWARF tag for SwiftTail and emit it in CodeGen.

2021-01-29 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple created this revision.
varungandhi-apple added a reviewer: aprantl.
varungandhi-apple requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

swifttailcc is a new calling convention in LLVM introduced
in https://reviews.llvm.org/D95443. We add a new DWARF tag to capture
this in debuginfo.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95704

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-cc.c
  llvm/include/llvm/BinaryFormat/Dwarf.def


Index: llvm/include/llvm/BinaryFormat/Dwarf.def
===
--- llvm/include/llvm/BinaryFormat/Dwarf.def
+++ llvm/include/llvm/BinaryFormat/Dwarf.def
@@ -788,6 +788,7 @@
 HANDLE_DW_CC(0xc9, LLVM_PreserveMost)
 HANDLE_DW_CC(0xca, LLVM_PreserveAll)
 HANDLE_DW_CC(0xcb, LLVM_X86RegCall)
+HANDLE_DW_CC(0xcc, LLVM_SwiftTail)
 // From GCC source code (include/dwarf2.h): This DW_CC_ value is not currently
 // generated by any toolchain.  It is used internally to GDB to indicate 
OpenCL C
 // functions that have been compiled with the IBM XL C for OpenCL compiler and 
use
Index: clang/test/CodeGen/debug-info-cc.c
===
--- clang/test/CodeGen/debug-info-cc.c
+++ clang/test/CodeGen/debug-info-cc.c
@@ -57,9 +57,8 @@
   return a+b;
 }
 
-// [FIXME: swiftasynccc] Update debuginfo tag to SwiftAsync once LLVM support 
lands.
 // LINUX: !DISubprogram({{.*}}"add_swiftasynccall", {{.*}}type: ![[FTY:[0-9]+]]
-// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_Swift,
+// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_SwiftTail,
 __attribute__((swiftasynccall)) int add_swiftasynccall(int a, int b) {
   return a+b;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1249,8 +1249,7 @@
   case CC_Swift:
 return llvm::dwarf::DW_CC_LLVM_Swift;
   case CC_SwiftAsync:
-// [FIXME: swiftasynccc] Update to SwiftAsync once LLVM support lands.
-return llvm::dwarf::DW_CC_LLVM_Swift;
+return llvm::dwarf::DW_CC_LLVM_SwiftTail;
   case CC_PreserveMost:
 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
   case CC_PreserveAll:


Index: llvm/include/llvm/BinaryFormat/Dwarf.def
===
--- llvm/include/llvm/BinaryFormat/Dwarf.def
+++ llvm/include/llvm/BinaryFormat/Dwarf.def
@@ -788,6 +788,7 @@
 HANDLE_DW_CC(0xc9, LLVM_PreserveMost)
 HANDLE_DW_CC(0xca, LLVM_PreserveAll)
 HANDLE_DW_CC(0xcb, LLVM_X86RegCall)
+HANDLE_DW_CC(0xcc, LLVM_SwiftTail)
 // From GCC source code (include/dwarf2.h): This DW_CC_ value is not currently
 // generated by any toolchain.  It is used internally to GDB to indicate OpenCL C
 // functions that have been compiled with the IBM XL C for OpenCL compiler and use
Index: clang/test/CodeGen/debug-info-cc.c
===
--- clang/test/CodeGen/debug-info-cc.c
+++ clang/test/CodeGen/debug-info-cc.c
@@ -57,9 +57,8 @@
   return a+b;
 }
 
-// [FIXME: swiftasynccc] Update debuginfo tag to SwiftAsync once LLVM support lands.
 // LINUX: !DISubprogram({{.*}}"add_swiftasynccall", {{.*}}type: ![[FTY:[0-9]+]]
-// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_Swift,
+// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_SwiftTail,
 __attribute__((swiftasynccall)) int add_swiftasynccall(int a, int b) {
   return a+b;
 }
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1249,8 +1249,7 @@
   case CC_Swift:
 return llvm::dwarf::DW_CC_LLVM_Swift;
   case CC_SwiftAsync:
-// [FIXME: swiftasynccc] Update to SwiftAsync once LLVM support lands.
-return llvm::dwarf::DW_CC_LLVM_Swift;
+return llvm::dwarf::DW_CC_LLVM_SwiftTail;
   case CC_PreserveMost:
 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
   case CC_PreserveAll:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95814: [NFC] Simplify test to use multiple FileCheck prefixes.

2021-02-01 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple created this revision.
varungandhi-apple added a reviewer: aschwaighofer.
varungandhi-apple requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Minor cleanup where we can avoid calling the compiler
twice with the same arguments.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95814

Files:
  clang/test/CodeGen/64bit-swiftcall.c


Index: clang/test/CodeGen/64bit-swiftcall.c
===
--- clang/test/CodeGen/64bit-swiftcall.c
+++ clang/test/CodeGen/64bit-swiftcall.c
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm 
-o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm 
-o - %s | FileCheck %s --check-prefix=X86-64
-// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o 
- %s | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o 
- %s | FileCheck %s --check-prefix=ARM64
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm 
-o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=X86-64
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o 
- %s | FileCheck %s --check-prefix=CHECK --check-prefix=ARM64
 
 // REQUIRES: aarch64-registered-target,x86-registered-target
 


Index: clang/test/CodeGen/64bit-swiftcall.c
===
--- clang/test/CodeGen/64bit-swiftcall.c
+++ clang/test/CodeGen/64bit-swiftcall.c
@@ -1,7 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s --check-prefix=X86-64
-// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM64
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=X86-64
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=ARM64
 
 // REQUIRES: aarch64-registered-target,x86-registered-target
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-02-02 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added inline comments.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:8106-8115
+  case ParsedAttr::AT_SwiftAsyncCall:
   case ParsedAttr::AT_VectorCall:
   case ParsedAttr::AT_MSABI:
   case ParsedAttr::AT_SysVABI:
   case ParsedAttr::AT_Pcs:
   case ParsedAttr::AT_IntelOclBicc:
   case ParsedAttr::AT_PreserveMost:

There seems to be some weirdness here in `handleCallConvAttr` where the 
codepath to attach the attribute to the decl isn't taken. Instead in my 
examples, it exits out at this line:

```
  if (hasDeclarator(D)) return;
```

with an `isa` check.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

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


[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-02-02 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added inline comments.



Comment at: clang/lib/AST/MicrosoftMangle.cpp:2711
+  Out << 'T';
+  break;
 case CC_PreserveMost: Out << 'U'; break;

rjmccall wrote:
> Please use consistent formatting with the other cases, here and elsewhere.  
> Keeping the switch compact is better for readability than following an 
> abstract style rule.
I'm pretty sure I wrote it the right way originally, but saying yes to the 
clang-tidy prompt by `arc` broke it. :sigh:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

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


[PATCH] D95984: [CodeGen] Fix codegen for __attribute__((swiftasynccall)).

2021-02-03 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple created this revision.
varungandhi-apple added a reviewer: rjmccall.
varungandhi-apple requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

1. It should be mapped to LLVM's swifttailcc, which is now available.
2. We should make sure we generate a tail call instead of an ordinary call.

Fixes rdar://73762895.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95984

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGen/64bit-swiftcall.c
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/swift-async-call-conv.c
  clang/test/CodeGen/swift-call-conv.c

Index: clang/test/CodeGen/swift-call-conv.c
===
--- clang/test/CodeGen/swift-call-conv.c
+++ clang/test/CodeGen/swift-call-conv.c
@@ -7,3 +7,5 @@
 void __attribute__((__swiftcall__)) f(void) {}
 // CHECK-LABEL: define dso_local swiftcc void @f()
 
+void __attribute__((__swiftasynccall__)) f_async(void) {}
+// CHECK-LABEL: define dso_local swifttailcc void @f_async()
Index: clang/test/CodeGen/swift-async-call-conv.c
===
--- /dev/null
+++ clang/test/CodeGen/swift-async-call-conv.c
@@ -0,0 +1,104 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+
+// Test tail call behavior when a swiftasynccall function is called
+// from another swiftasynccall function.
+
+#define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
+
+// CHECK-LABEL: swifttailcc void @async_leaf1(i8* swiftasync
+SWIFTASYNCCALL void async_leaf1(char * ASYNC_CONTEXT ctx) {
+  *ctx += 1;
+}
+
+// CHECK-LABEL: swifttailcc void @async_leaf2(i8* swiftasync
+SWIFTASYNCCALL void async_leaf2(char * ASYNC_CONTEXT ctx) {
+  *ctx += 2;
+}
+
+// CHECK-LABEL: swifttailcc void @async_branch
+// CHECK: tail call swifttailcc void @async_leaf1
+// CHECK: tail call swifttailcc void @async_leaf2
+SWIFTASYNCCALL void async_branch(_Bool b, char * ASYNC_CONTEXT ctx) {
+  if (b) {
+return async_leaf1(ctx);
+  } else {
+return async_leaf2(ctx);
+  }
+}
+
+// CHECK-LABEL: swifttailcc void @async_loop
+// CHECK: tail call swifttailcc void @async_leaf1
+// CHECK: tail call swifttailcc void @async_leaf2
+// CHECK: tail call swifttailcc void @async_loop
+SWIFTASYNCCALL void async_loop(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_loop(u - 2, ctx);
+}
+
+// Forward-declaration + mutual recursion is okay.
+
+SWIFTASYNCCALL void async_mutual_loop2(unsigned u, char * ASYNC_CONTEXT ctx);
+
+// CHECK: swifttailcc void @async_mutual_loop
+// CHECK: tail call swifttailcc void @async_leaf
+// CHECK: tail call swifttailcc void @async_leaf
+// CHECK: tail call swifttailcc void @async_mutual_loop
+SWIFTASYNCCALL void async_mutual_loop1(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_mutual_loop2(u - 2, ctx);
+}
+
+// CHECK: swifttailcc void @async_mutual_loop
+// CHECK: tail call swifttailcc void @async_leaf1
+// CHECK: tail call swifttailcc void @async_leaf2
+// CHECK: tail call swifttailcc void @async_mutual_loop1
+SWIFTASYNCCALL void async_mutual_loop2(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_mutual_loop1(u - 2, ctx);
+}
+
+// When swiftasynccall functions are called by non-swiftasynccall functions,
+// the call isn't marked as a tail call.
+
+// CHECK-LABEL: swiftcc i8 @sync_calling_async
+// CHECK-NOT: tail call
+// CHECK: call swifttailcc void @async_branch
+// CHECK-NOT: tail call
+// CHECK: call swifttailcc void @async_loop
+SWIFTCALL char sync_calling_async(_Bool b, unsigned u) {
+  char x = 'a';
+  async_branch(b, &x);
+  async_loop(u, &x);
+  return x;
+}
+
+// CHECK-LABEL: i8 @c_calling_async
+// CHECK-NOT: tail call
+// CHECK: call swifttailcc void @async_branch
+// CHECK-NOT: tail call
+// CHECK: call swifttailcc void @async_loop
+char c_calling_async(_Bool b, unsigned u) {
+  char x = 'a';
+  async_branch(b, &x);
+  async_loop(u, &x);
+  return x;
+}
+
Index: clang/test/CodeGen/arm-swiftcall.c
===
--- clang/test/CodeGen/arm-swiftcall.c
+++ clang/test/CodeGen/arm-swiftcall.c
@@ -27,9 +27,15 @@
 SW

[PATCH] D95984: [CodeGen] Fix codegen for __attribute__((swiftasynccall)).

2021-02-03 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added a comment.

I am planning to add more tests, figured it is better to put up the patch 
sooner rather than later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95984

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


[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-02-04 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 321501.
varungandhi-apple added a comment.

1. Update whitespace and add documentation for swiftasynccall.
2. Update commit message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/CodeGen/SwiftCallingConv.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/Sema/attr-c2x.c
  clang/test/Sema/attr-swiftcall.c
  clang/test/Sema/no_callconv.cpp
  clang/test/SemaCXX/attr-swiftcall.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-mangle.test

Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -341,6 +341,9 @@
 ?swift_func@@YSXXZ
 ; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
 
+?swift_async_func@@YTXXZ
+; CHECK: void __attribute__((__swiftasynccall__)) swift_async_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -110,6 +110,9 @@
   case CallingConv::Swift:
 OS << "__attribute__((__swiftcall__)) ";
 break;
+  case CallingConv::SwiftAsync:
+OS << "__attribute__((__swiftasynccall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1713,6 +1713,8 @@
 return CallingConv::Vectorcall;
   case 'S':
 return CallingConv::Swift;
+  case 'T':
+return CallingConv::SwiftAsync;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,7 +67,8 @@
   Eabi,
   Vectorcall,
   Regcall,
-  Swift, // Clang-only
+  Swift,  // Clang-only
+  SwiftAsync, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -664,6 +664,7 @@
   TCALLINGCONV(AAPCS_VFP);
   TCALLINGCONV(IntelOclBicc);
   TCALLINGCONV(Swift);
+  TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/attr-swiftcall.cpp
===
--- clang/test/SemaCXX/attr-swiftcall.cpp
+++ clang/test/SemaCXX/attr-swiftcall.cpp
@@ -1,14 +1,20 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
 
 #define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
 #define INDIRECT_RESULT __attribute__((swift_indirect_result))
 #define ERROR_RESULT __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
 
 int notAFunction SWIFTCALL; // expected-warning {{'swiftcall' only applies to function types; type here is 'int'}}
+int notAnAsyncFunction SWIFTASYNCCALL; // expected-warning {{'swiftasynccall' only applies to function types; type here is 'int'}}
 void variadic(int x, ...) SWIFTCALL; // expected-error {{variadic function cannot use swiftcall calling convention}}
+void variadic_async(int x, ...) SWIFTASYNCCALL; // expected-error {{variadic function cannot use swiftasynccall calling convention}}
 void multiple_ccs(int x) SWIFTCALL __attribute__((vectorcall)); // expected-error {{vectorcall and swiftcall attributes are not compatible}}
+vo

[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-02-05 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 321801.
varungandhi-apple added a comment.

Correct documentation on tail call behavior as pointed out by John.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/CodeGen/SwiftCallingConv.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/Sema/attr-c2x.c
  clang/test/Sema/attr-swiftcall.c
  clang/test/Sema/no_callconv.cpp
  clang/test/SemaCXX/attr-swiftcall.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-mangle.test

Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -341,6 +341,9 @@
 ?swift_func@@YSXXZ
 ; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
 
+?swift_async_func@@YTXXZ
+; CHECK: void __attribute__((__swiftasynccall__)) swift_async_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -110,6 +110,9 @@
   case CallingConv::Swift:
 OS << "__attribute__((__swiftcall__)) ";
 break;
+  case CallingConv::SwiftAsync:
+OS << "__attribute__((__swiftasynccall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1713,6 +1713,8 @@
 return CallingConv::Vectorcall;
   case 'S':
 return CallingConv::Swift;
+  case 'T':
+return CallingConv::SwiftAsync;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,7 +67,8 @@
   Eabi,
   Vectorcall,
   Regcall,
-  Swift, // Clang-only
+  Swift,  // Clang-only
+  SwiftAsync, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -664,6 +664,7 @@
   TCALLINGCONV(AAPCS_VFP);
   TCALLINGCONV(IntelOclBicc);
   TCALLINGCONV(Swift);
+  TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/attr-swiftcall.cpp
===
--- clang/test/SemaCXX/attr-swiftcall.cpp
+++ clang/test/SemaCXX/attr-swiftcall.cpp
@@ -1,14 +1,20 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
 
 #define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
 #define INDIRECT_RESULT __attribute__((swift_indirect_result))
 #define ERROR_RESULT __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
 
 int notAFunction SWIFTCALL; // expected-warning {{'swiftcall' only applies to function types; type here is 'int'}}
+int notAnAsyncFunction SWIFTASYNCCALL; // expected-warning {{'swiftasynccall' only applies to function types; type here is 'int'}}
 void variadic(int x, ...) SWIFTCALL; // expected-error {{variadic function cannot use swiftcall calling convention}}
+void variadic_async(int x, ...) SWIFTASYNCCALL; // expected-error {{variadic function cannot use swiftasynccall calling convention}}
 void multiple_ccs(int x) SWIFTCALL __attribute__((vectorcall)); // expected-error {{vectorcall and swiftcall attributes are not compatible}}
+void multiple_ccs_async

[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-02-12 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added inline comments.



Comment at: clang/test/CodeGen/debug-info-cc.c:60-66
+// [FIXME: swiftasynccc] Update debuginfo tag to SwiftAsync once LLVM support 
lands.
+// LINUX: !DISubprogram({{.*}}"add_swiftasynccall", {{.*}}type: ![[FTY:[0-9]+]]
+// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_Swift,
+__attribute__((swiftasynccall)) int add_swiftasynccall(int a, int b) {
+  return a+b;
+}
+

This needs to be changed in some way, it triggers a test failure in its current 
state. https://github.com/apple/llvm-project/pull/2444


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

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


[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-02-12 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 323363.
varungandhi-apple added a comment.

Fix test case for debuginfo.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/CodeGen/SwiftCallingConv.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/Sema/attr-c2x.c
  clang/test/Sema/attr-swiftcall.c
  clang/test/Sema/no_callconv.cpp
  clang/test/SemaCXX/attr-swiftcall.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-mangle.test

Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -341,6 +341,9 @@
 ?swift_func@@YSXXZ
 ; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
 
+?swift_async_func@@YTXXZ
+; CHECK: void __attribute__((__swiftasynccall__)) swift_async_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -110,6 +110,9 @@
   case CallingConv::Swift:
 OS << "__attribute__((__swiftcall__)) ";
 break;
+  case CallingConv::SwiftAsync:
+OS << "__attribute__((__swiftasynccall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1713,6 +1713,8 @@
 return CallingConv::Vectorcall;
   case 'S':
 return CallingConv::Swift;
+  case 'T':
+return CallingConv::SwiftAsync;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,7 +67,8 @@
   Eabi,
   Vectorcall,
   Regcall,
-  Swift, // Clang-only
+  Swift,  // Clang-only
+  SwiftAsync, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -664,6 +664,7 @@
   TCALLINGCONV(AAPCS_VFP);
   TCALLINGCONV(IntelOclBicc);
   TCALLINGCONV(Swift);
+  TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/attr-swiftcall.cpp
===
--- clang/test/SemaCXX/attr-swiftcall.cpp
+++ clang/test/SemaCXX/attr-swiftcall.cpp
@@ -1,14 +1,20 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
 
 #define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
 #define INDIRECT_RESULT __attribute__((swift_indirect_result))
 #define ERROR_RESULT __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
 
 int notAFunction SWIFTCALL; // expected-warning {{'swiftcall' only applies to function types; type here is 'int'}}
+int notAnAsyncFunction SWIFTASYNCCALL; // expected-warning {{'swiftasynccall' only applies to function types; type here is 'int'}}
 void variadic(int x, ...) SWIFTCALL; // expected-error {{variadic function cannot use swiftcall calling convention}}
+void variadic_async(int x, ...) SWIFTASYNCCALL; // expected-error {{variadic function cannot use swiftasynccall calling convention}}
 void multiple_ccs(int x) SWIFTCALL __attribute__((vectorcall)); // expected-error {{vectorcall and swiftcall attributes are not compatible}}
+void multiple_ccs_async(int x) SWIFTASYNCCALL __attribute__((v

[PATCH] D95704: [CodeGen] Introduce DWARF tag for SwiftTail and emit it in CodeGen.

2021-02-12 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 323364.
varungandhi-apple added a comment.

Tweak test case diff to adjust for change in previous commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95704

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGen/debug-info-cc.c
  llvm/include/llvm/BinaryFormat/Dwarf.def


Index: llvm/include/llvm/BinaryFormat/Dwarf.def
===
--- llvm/include/llvm/BinaryFormat/Dwarf.def
+++ llvm/include/llvm/BinaryFormat/Dwarf.def
@@ -788,6 +788,7 @@
 HANDLE_DW_CC(0xc9, LLVM_PreserveMost)
 HANDLE_DW_CC(0xca, LLVM_PreserveAll)
 HANDLE_DW_CC(0xcb, LLVM_X86RegCall)
+HANDLE_DW_CC(0xcc, LLVM_SwiftTail)
 // From GCC source code (include/dwarf2.h): This DW_CC_ value is not currently
 // generated by any toolchain.  It is used internally to GDB to indicate 
OpenCL C
 // functions that have been compiled with the IBM XL C for OpenCL compiler and 
use
Index: clang/test/CodeGen/debug-info-cc.c
===
--- clang/test/CodeGen/debug-info-cc.c
+++ clang/test/CodeGen/debug-info-cc.c
@@ -57,11 +57,10 @@
   return a+b;
 }
 
-// [FIXME: swiftasynccc] Update debuginfo tag to SwiftAsync once LLVM support 
lands.
 // LINUX: !DISubprogram({{.*}}"add_swiftasynccall", {{.*}}type: ![[FTY:[0-9]+]]
-// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_Swift,
-__attribute__((swiftasynccall)) int add_swiftasynccall(int a, int b, int c) {
-  return a+b+c;
+// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_SwiftTail,
+__attribute__((swiftasynccall)) int add_swiftasynccall(int a, int b) {
+  return a+b;
 }
 
 // LINUX: !DISubprogram({{.*}}"add_inteloclbicc", {{.*}}type: ![[FTY:[0-9]+]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1249,8 +1249,7 @@
   case CC_Swift:
 return llvm::dwarf::DW_CC_LLVM_Swift;
   case CC_SwiftAsync:
-// [FIXME: swiftasynccc] Update to SwiftAsync once LLVM support lands.
-return llvm::dwarf::DW_CC_LLVM_Swift;
+return llvm::dwarf::DW_CC_LLVM_SwiftTail;
   case CC_PreserveMost:
 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
   case CC_PreserveAll:


Index: llvm/include/llvm/BinaryFormat/Dwarf.def
===
--- llvm/include/llvm/BinaryFormat/Dwarf.def
+++ llvm/include/llvm/BinaryFormat/Dwarf.def
@@ -788,6 +788,7 @@
 HANDLE_DW_CC(0xc9, LLVM_PreserveMost)
 HANDLE_DW_CC(0xca, LLVM_PreserveAll)
 HANDLE_DW_CC(0xcb, LLVM_X86RegCall)
+HANDLE_DW_CC(0xcc, LLVM_SwiftTail)
 // From GCC source code (include/dwarf2.h): This DW_CC_ value is not currently
 // generated by any toolchain.  It is used internally to GDB to indicate OpenCL C
 // functions that have been compiled with the IBM XL C for OpenCL compiler and use
Index: clang/test/CodeGen/debug-info-cc.c
===
--- clang/test/CodeGen/debug-info-cc.c
+++ clang/test/CodeGen/debug-info-cc.c
@@ -57,11 +57,10 @@
   return a+b;
 }
 
-// [FIXME: swiftasynccc] Update debuginfo tag to SwiftAsync once LLVM support lands.
 // LINUX: !DISubprogram({{.*}}"add_swiftasynccall", {{.*}}type: ![[FTY:[0-9]+]]
-// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_Swift,
-__attribute__((swiftasynccall)) int add_swiftasynccall(int a, int b, int c) {
-  return a+b+c;
+// LINUX: ![[FTY]] = !DISubroutineType({{.*}}cc: DW_CC_LLVM_SwiftTail,
+__attribute__((swiftasynccall)) int add_swiftasynccall(int a, int b) {
+  return a+b;
 }
 
 // LINUX: !DISubprogram({{.*}}"add_inteloclbicc", {{.*}}type: ![[FTY:[0-9]+]]
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1249,8 +1249,7 @@
   case CC_Swift:
 return llvm::dwarf::DW_CC_LLVM_Swift;
   case CC_SwiftAsync:
-// [FIXME: swiftasynccc] Update to SwiftAsync once LLVM support lands.
-return llvm::dwarf::DW_CC_LLVM_Swift;
+return llvm::dwarf::DW_CC_LLVM_SwiftTail;
   case CC_PreserveMost:
 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
   case CC_PreserveAll:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D96802: [Clang] Add proper target checks for SwiftAsync convention.

2021-02-16 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple created this revision.
varungandhi-apple added a reviewer: rjmccall.
Herald added subscribers: dexonsmith, pengfei, kbarton, kristof.beyls, 
jgravelle-google, sbc100, nemanjai, dschuff.
varungandhi-apple requested review of this revision.
Herald added subscribers: cfe-commits, aheejin.
Herald added a project: clang.

Previously, we erroneously claimed that all targets were supported.
However, at the moment, only x86_64 and ARM are known to be working.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96802

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h

Index: clang/lib/Basic/Targets/X86.h
===
--- clang/lib/Basic/Targets/X86.h
+++ clang/lib/Basic/Targets/X86.h
@@ -344,11 +344,12 @@
 case CC_C:
 case CC_PreserveMost:
 case CC_Swift:
-case CC_SwiftAsync:
 case CC_X86Pascal:
 case CC_IntelOclBicc:
 case CC_OpenCLKernel:
   return CCCR_OK;
+case CC_SwiftAsync:
+  return checkSwiftAsyncCCSupported();
 default:
   return CCCR_Warning;
 }
@@ -703,7 +704,6 @@
 switch (CC) {
 case CC_C:
 case CC_Swift:
-case CC_SwiftAsync:
 case CC_X86VectorCall:
 case CC_IntelOclBicc:
 case CC_Win64:
@@ -712,6 +712,8 @@
 case CC_X86RegCall:
 case CC_OpenCLKernel:
   return CCCR_OK;
+case CC_SwiftAsync:
+  return checkSwiftAsyncCCSupported();
 default:
   return CCCR_Warning;
 }
@@ -785,10 +787,11 @@
 case CC_PreserveAll:
 case CC_X86_64SysV:
 case CC_Swift:
-case CC_SwiftAsync:
 case CC_X86RegCall:
 case CC_OpenCLKernel:
   return CCCR_OK;
+case CC_SwiftAsync:
+  return checkSwiftAsyncCCSupported();
 default:
   return CCCR_Warning;
 }
Index: clang/lib/Basic/Targets/WebAssembly.h
===
--- clang/lib/Basic/Targets/WebAssembly.h
+++ clang/lib/Basic/Targets/WebAssembly.h
@@ -129,8 +129,9 @@
 switch (CC) {
 case CC_C:
 case CC_Swift:
-case CC_SwiftAsync:
   return CCCR_OK;
+case CC_SwiftAsync:
+  return checkSwiftAsyncCCSupported();
 default:
   return CCCR_Warning;
 }
Index: clang/lib/Basic/Targets/SystemZ.h
===
--- clang/lib/Basic/Targets/SystemZ.h
+++ clang/lib/Basic/Targets/SystemZ.h
@@ -141,9 +141,10 @@
 switch (CC) {
 case CC_C:
 case CC_Swift:
-case CC_SwiftAsync:
 case CC_OpenCLKernel:
   return CCCR_OK;
+case CC_SwiftAsync:
+  return checkSwiftAsyncCCSupported();
 default:
   return CCCR_Warning;
 }
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -450,8 +450,9 @@
   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
 switch (CC) {
 case CC_Swift:
-case CC_SwiftAsync:
   return CCCR_OK;
+case CC_SwiftAsync:
+  return checkSwiftAsyncCCSupported();
 default:
   return CCCR_Warning;
 }
Index: clang/lib/Basic/Targets/ARM.cpp
===
--- clang/lib/Basic/Targets/ARM.cpp
+++ clang/lib/Basic/Targets/ARM.cpp
@@ -1120,9 +1120,10 @@
   case CC_AAPCS:
   case CC_AAPCS_VFP:
   case CC_Swift:
-  case CC_SwiftAsync:
   case CC_OpenCLKernel:
 return CCCR_OK;
+  case CC_SwiftAsync:
+return checkSwiftAsyncCCSupported();
   default:
 return CCCR_Warning;
   }
@@ -1200,8 +1201,9 @@
   case CC_PreserveMost:
   case CC_PreserveAll:
   case CC_Swift:
-  case CC_SwiftAsync:
 return CCCR_OK;
+  case CC_SwiftAsync:
+return checkSwiftAsyncCCSupported();
   default:
 return CCCR_Warning;
   }
Index: clang/lib/Basic/Targets/AArch64.cpp
===
--- clang/lib/Basic/Targets/AArch64.cpp
+++ clang/lib/Basic/Targets/AArch64.cpp
@@ -537,13 +537,14 @@
   switch (CC) {
   case CC_C:
   case CC_Swift:
-  case CC_SwiftAsync:
   case CC_PreserveMost:
   case CC_PreserveAll:
   case CC_OpenCLKernel:
   case CC_AArch64VectorCall:
   case CC_Win64:
 return CCCR_OK;
+  case CC_SwiftAsync:
+return checkSwiftAsyncCCSupported();
   default:
 return CCCR_Warning;
   }
@@ -811,9 +812,10 @@
   case CC_PreserveMost:
   case CC_PreserveAll:
   case CC_Swift:
-  case CC_SwiftAsync:
   case CC_Win64:
 return CCCR_OK;
+  case CC_SwiftAsync:
+return checkSwiftAsyncCCSupported();
   default:
 return CCCR_Warning;
   }
Index: clang/include/clang/Basic/TargetInfo.h
==

[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-02-17 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 324389.
varungandhi-apple added a comment.

- Remove semantic restriction of swift_async_context being only applicable to 
swiftasynccall.
- Update target checks to make sure we only allow supported targets.
- Update doc comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/CodeGen/SwiftCallingConv.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/CodeGen/swift-call-conv.c
  clang/test/Sema/attr-c2x.c
  clang/test/Sema/attr-swiftcall.c
  clang/test/Sema/no_callconv.cpp
  clang/test/SemaCXX/attr-swiftcall.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-mangle.test

Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -341,6 +341,9 @@
 ?swift_func@@YSXXZ
 ; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
 
+?swift_async_func@@YTXXZ
+; CHECK: void __attribute__((__swiftasynccall__)) swift_async_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -110,6 +110,9 @@
   case CallingConv::Swift:
 OS << "__attribute__((__swiftcall__)) ";
 break;
+  case CallingConv::SwiftAsync:
+OS << "__attribute__((__swiftasynccall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1713,6 +1713,8 @@
 return CallingConv::Vectorcall;
   case 'S':
 return CallingConv::Swift;
+  case 'T':
+return CallingConv::SwiftAsync;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,7 +67,8 @@
   Eabi,
   Vectorcall,
   Regcall,
-  Swift, // Clang-only
+  Swift,  // Clang-only
+  SwiftAsync, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -664,6 +664,7 @@
   TCALLINGCONV(AAPCS_VFP);
   TCALLINGCONV(IntelOclBicc);
   TCALLINGCONV(Swift);
+  TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/attr-swiftcall.cpp
===
--- clang/test/SemaCXX/attr-swiftcall.cpp
+++ clang/test/SemaCXX/attr-swiftcall.cpp
@@ -1,14 +1,20 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
 
 #define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
 #define INDIRECT_RESULT __attribute__((swift_indirect_result))
 #define ERROR_RESULT __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
 
 int notAFunction SWIFTCALL; // expected-warning {{'swiftcall' only applies to function types; type here is 'int'}}
+int notAnAsyncFunction SWIFTASYNCCALL; // expected-warning {{'swiftasynccall' only applies to function types; type here is 'int'}}
 void variadic(int x, ...) SWIFTCALL; // expected-error {{variadic function cannot use swiftcall calling convention}}
+void variadic_async(int x, ...) SWIFTASYNCCALL; // expected-error {{variadic function cannot use swiftasynccall

[PATCH] D96802: [Clang] Add proper target checks for SwiftAsync convention.

2021-02-17 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added a comment.

> The TargetInfo classes are already target-architecture-specific, so it's 
> somewhat strange for them all to funnel to a single function that then 
> immediately switches on the target architecture.

IMO ideally, the whole thing would be stored as a table of Target x 
CallingConvention. Each entry of the table would have a CallingConvCheckResult. 
That way, you can quickly figure out both:

- which targets is a calling convention supported for
- what calling conventions are supported for a particular target

Certainly, that's not the state of the code right now. So I do agree with your 
point that it looks a bit strange. However, given that things are somewhat in 
flux for `CC_SwiftAsync`, I think it is valuable to centralize the information 
for it in one place instead of spreading it out over multiple files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96802

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


[PATCH] D96802: [Clang] Add proper target checks for SwiftAsync convention.

2021-02-17 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple abandoned this revision.
varungandhi-apple added a comment.

I've updated the earlier patch https://reviews.llvm.org/D95561 to include this 
change, so that we don't have an in-between state where we erroneously claim 
that we support a bunch of targets which we don't actually support.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D96802

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


[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-02-24 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 326194.
varungandhi-apple added a comment.

Address review feedback; remove centralized target check for CC_SwiftAsync.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/CodeGen/SwiftCallingConv.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/CodeGen/swift-call-conv.c
  clang/test/Sema/attr-c2x.c
  clang/test/Sema/attr-swiftcall.c
  clang/test/Sema/no_callconv.cpp
  clang/test/SemaCXX/attr-swiftcall.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-mangle.test

Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -341,6 +341,9 @@
 ?swift_func@@YSXXZ
 ; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
 
+?swift_async_func@@YTXXZ
+; CHECK: void __attribute__((__swiftasynccall__)) swift_async_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -110,6 +110,9 @@
   case CallingConv::Swift:
 OS << "__attribute__((__swiftcall__)) ";
 break;
+  case CallingConv::SwiftAsync:
+OS << "__attribute__((__swiftasynccall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1713,6 +1713,8 @@
 return CallingConv::Vectorcall;
   case 'S':
 return CallingConv::Swift;
+  case 'T':
+return CallingConv::SwiftAsync;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,7 +67,8 @@
   Eabi,
   Vectorcall,
   Regcall,
-  Swift, // Clang-only
+  Swift,  // Clang-only
+  SwiftAsync, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -664,6 +664,7 @@
   TCALLINGCONV(AAPCS_VFP);
   TCALLINGCONV(IntelOclBicc);
   TCALLINGCONV(Swift);
+  TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/attr-swiftcall.cpp
===
--- clang/test/SemaCXX/attr-swiftcall.cpp
+++ clang/test/SemaCXX/attr-swiftcall.cpp
@@ -1,14 +1,20 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
 
 #define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
 #define INDIRECT_RESULT __attribute__((swift_indirect_result))
 #define ERROR_RESULT __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
 
 int notAFunction SWIFTCALL; // expected-warning {{'swiftcall' only applies to function types; type here is 'int'}}
+int notAnAsyncFunction SWIFTASYNCCALL; // expected-warning {{'swiftasynccall' only applies to function types; type here is 'int'}}
 void variadic(int x, ...) SWIFTCALL; // expected-error {{variadic function cannot use swiftcall calling convention}}
+void variadic_async(int x, ...) SWIFTASYNCCALL; // expected-error {{variadic function cannot use swiftasynccall calling convention}}
 void multiple_ccs(int x) SWIFTCALL __attribute__((vectorcall)); // expected-error {{vectorcall and swiftcall attributes are not 

[PATCH] D95984: [CodeGen] Fix codegen for __attribute__((swiftasynccall)).

2021-02-24 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 326203.
varungandhi-apple added a comment.

Generate tail call when doing codegen for return statement.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95984

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/64bit-swiftcall.c
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/swift-async-call-conv.c
  clang/test/CodeGen/swift-call-conv.c

Index: clang/test/CodeGen/swift-call-conv.c
===
--- clang/test/CodeGen/swift-call-conv.c
+++ clang/test/CodeGen/swift-call-conv.c
@@ -6,3 +6,5 @@
 void __attribute__((__swiftcall__)) f(void) {}
 // CHECK-LABEL: define dso_local swiftcc void @f()
 
+void __attribute__((__swiftasynccall__)) f_async(void) {}
+// CHECK-LABEL: define dso_local swifttailcc void @f_async()
Index: clang/test/CodeGen/swift-async-call-conv.c
===
--- /dev/null
+++ clang/test/CodeGen/swift-async-call-conv.c
@@ -0,0 +1,126 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+
+// Test tail call behavior when a swiftasynccall function is called
+// from another swiftasynccall function.
+
+#define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
+
+// CHECK-LABEL: swifttailcc void @async_leaf1(i8* swiftasync
+SWIFTASYNCCALL void async_leaf1(char * ASYNC_CONTEXT ctx) {
+  *ctx += 1;
+}
+
+// CHECK-LABEL: swifttailcc void @async_leaf2(i8* swiftasync
+SWIFTASYNCCALL void async_leaf2(char * ASYNC_CONTEXT ctx) {
+  *ctx += 2;
+}
+
+// CHECK-LABEL: swifttailcc void @async_branch
+// CHECK: tail call swifttailcc void @async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @async_leaf2
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_branch(_Bool b, char * ASYNC_CONTEXT ctx) {
+  if (b) {
+return async_leaf1(ctx);
+  } else {
+return async_leaf2(ctx);
+  }
+}
+
+// CHECK-LABEL: swifttailcc void @async_not_all_tail
+// CHECK-NOT:  tail call swifttailcc void @async_leaf1
+// CHECK:  call swifttailcc void @async_leaf1
+// CHECK-NOT:  ret void
+// CHECK:  tail call swifttailcc void @async_leaf2
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_not_all_tail(char * ASYNC_CONTEXT ctx) {
+  async_leaf1(ctx);
+  return async_leaf2(ctx);
+}
+
+// CHECK-LABEL: swifttailcc void @async_loop
+// CHECK: tail call swifttailcc void @async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @async_leaf2
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @async_loop
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_loop(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_loop(u - 2, ctx);
+}
+
+// Forward-declaration + mutual recursion is okay.
+
+SWIFTASYNCCALL void async_mutual_loop2(unsigned u, char * ASYNC_CONTEXT ctx);
+
+// CHECK: swifttailcc void @async_mutual_loop
+// CHECK: tail call swifttailcc void @async_leaf
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @async_leaf
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @async_mutual_loop
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_mutual_loop1(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_mutual_loop2(u - 2, ctx);
+}
+
+// CHECK: swifttailcc void @async_mutual_loop
+// CHECK: tail call swifttailcc void @async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @async_leaf2
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @async_mutual_loop1
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_mutual_loop2(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_mutual_loop1(u - 2, ctx);
+}
+
+// When swiftasynccall functions are called by non-swiftasynccall functions,
+// the call isn't marked as a tail call.
+
+// CHECK-LABEL: swiftcc i8 @sync_calling_async
+// CHECK-NOT: tail call
+// CHECK: call swifttailcc void @async_branch
+// CHECK-NOT: tail call
+// CHECK: call swifttailcc void @async_loop
+SWIFTCALL char sync_calling_async(_Bool b, unsigned u) {
+  char x = 'a';
+  async_branch(b, &x);
+  async_loop(u, &x);
+ 

[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-06-23 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 354073.
varungandhi-apple added a comment.
Herald added a subscriber: ormris.

Combined D95984  into this patch since all 
necessary LLVM patches have landed, so having the patches separated out is not 
helpful.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/CodeGen/SwiftCallingConv.h
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/64bit-swiftcall.c
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/CodeGen/swift-async-call-conv.c
  clang/test/CodeGen/swift-call-conv.c
  clang/test/Sema/attr-c2x.c
  clang/test/Sema/attr-swiftcall.c
  clang/test/Sema/no_callconv.cpp
  clang/test/SemaCXX/attr-swiftcall.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/lib/Transforms/IPO/MergeFunctions.cpp
  llvm/test/Demangle/ms-mangle.test

Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -341,6 +341,9 @@
 ?swift_func@@YSXXZ
 ; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
 
+?swift_async_func@@YTXXZ
+; CHECK: void __attribute__((__swiftasynccall__)) swift_async_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Transforms/IPO/MergeFunctions.cpp
===
--- llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -709,7 +709,10 @@
 
   CallInst *CI = Builder.CreateCall(F, Args);
   ReturnInst *RI = nullptr;
-  CI->setTailCall();
+  bool isSwiftTailCall = F->getCallingConv() == CallingConv::SwiftTail &&
+ G->getCallingConv() == CallingConv::SwiftTail;
+  CI->setTailCallKind(isSwiftTailCall ? llvm::CallInst::TCK_MustTail
+  : llvm::CallInst::TCK_Tail);
   CI->setCallingConv(F->getCallingConv());
   CI->setAttributes(F->getAttributes());
   if (H->getReturnType()->isVoidTy()) {
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -110,6 +110,9 @@
   case CallingConv::Swift:
 OS << "__attribute__((__swiftcall__)) ";
 break;
+  case CallingConv::SwiftAsync:
+OS << "__attribute__((__swiftasynccall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1713,6 +1713,8 @@
 return CallingConv::Vectorcall;
   case 'S':
 return CallingConv::Swift;
+  case 'T':
+return CallingConv::SwiftAsync;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,7 +67,8 @@
   Eabi,
   Vectorcall,
   Regcall,
-  Swift, // Clang-only
+  Swift,  // Clang-only
+  SwiftAsync, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -664,6 +664,7 @@
   TCALLINGCONV(AAPCS_VFP);
   TCALLINGCONV(IntelOclBicc);
   TCALLINGCONV(Swift);
+  TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/attr-swiftcall.cpp
===
--- clang/test/SemaCXX/attr-swif

[PATCH] D95984: [CodeGen] Fix codegen for __attribute__((swiftasynccall)).

2021-06-23 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple abandoned this revision.
varungandhi-apple added a comment.
Herald added a subscriber: ormris.

Combined changes into D95561 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95984

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


[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-07-09 Thread Varun Gandhi 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 rG92dcb1d2db8c: [Clang] Introduce Swift async calling 
convention. (authored by varungandhi-apple).

Changed prior to commit:
  https://reviews.llvm.org/D95561?vs=354073&id=357587#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/CodeGen/SwiftCallingConv.h
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/64bit-swiftcall.c
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/CodeGen/swift-async-call-conv.c
  clang/test/CodeGen/swift-call-conv.c
  clang/test/Sema/attr-c2x.c
  clang/test/Sema/attr-swiftcall.c
  clang/test/Sema/no_callconv.cpp
  clang/test/SemaCXX/attr-swiftcall.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/lib/Transforms/IPO/MergeFunctions.cpp
  llvm/test/Demangle/ms-mangle.test

Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -341,6 +341,9 @@
 ?swift_func@@YSXXZ
 ; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
 
+?swift_async_func@@YTXXZ
+; CHECK: void __attribute__((__swiftasynccall__)) swift_async_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Transforms/IPO/MergeFunctions.cpp
===
--- llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -709,7 +709,10 @@
 
   CallInst *CI = Builder.CreateCall(F, Args);
   ReturnInst *RI = nullptr;
-  CI->setTailCall();
+  bool isSwiftTailCall = F->getCallingConv() == CallingConv::SwiftTail &&
+ G->getCallingConv() == CallingConv::SwiftTail;
+  CI->setTailCallKind(isSwiftTailCall ? llvm::CallInst::TCK_MustTail
+  : llvm::CallInst::TCK_Tail);
   CI->setCallingConv(F->getCallingConv());
   CI->setAttributes(F->getAttributes());
   if (H->getReturnType()->isVoidTy()) {
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -110,6 +110,9 @@
   case CallingConv::Swift:
 OS << "__attribute__((__swiftcall__)) ";
 break;
+  case CallingConv::SwiftAsync:
+OS << "__attribute__((__swiftasynccall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1713,6 +1713,8 @@
 return CallingConv::Vectorcall;
   case 'S':
 return CallingConv::Swift;
+  case 'T':
+return CallingConv::SwiftAsync;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,7 +67,8 @@
   Eabi,
   Vectorcall,
   Regcall,
-  Swift, // Clang-only
+  Swift,  // Clang-only
+  SwiftAsync, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -664,6 +664,7 @@
   TCALLINGCONV(AAPCS_VFP);
   TCALLINGCONV(IntelOclBicc);
   TCALLINGCONV(Swift);
+  TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/attr-swiftcall.cpp
===

[PATCH] D95984: [CodeGen] Fix codegen for __attribute__((swiftasynccall)).

2021-02-26 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 326762.
varungandhi-apple added a comment.

Added checks for C++.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95984

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/64bit-swiftcall.c
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/swift-async-call-conv.c
  clang/test/CodeGen/swift-call-conv.c

Index: clang/test/CodeGen/swift-call-conv.c
===
--- clang/test/CodeGen/swift-call-conv.c
+++ clang/test/CodeGen/swift-call-conv.c
@@ -6,3 +6,5 @@
 void __attribute__((__swiftcall__)) f(void) {}
 // CHECK-LABEL: define dso_local swiftcc void @f()
 
+void __attribute__((__swiftasynccall__)) f_async(void) {}
+// CHECK-LABEL: define dso_local swifttailcc void @f_async()
Index: clang/test/CodeGen/swift-async-call-conv.c
===
--- /dev/null
+++ clang/test/CodeGen/swift-async-call-conv.c
@@ -0,0 +1,138 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -x c++ -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+
+// Test tail call behavior when a swiftasynccall function is called
+// from another swiftasynccall function.
+
+#define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_leaf1{{.*}}(i8* swiftasync
+SWIFTASYNCCALL void async_leaf1(char * ASYNC_CONTEXT ctx) {
+  *ctx += 1;
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_leaf2{{.*}}(i8* swiftasync
+SWIFTASYNCCALL void async_leaf2(char * ASYNC_CONTEXT ctx) {
+  *ctx += 2;
+}
+
+#if __cplusplus
+  #define MYBOOL bool
+#else
+  #define MYBOOL _Bool
+#endif
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_branch{{.*}}i8* swiftasync
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_branch(MYBOOL b, char * ASYNC_CONTEXT ctx) {
+  if (b) {
+return async_leaf1(ctx);
+  } else {
+return async_leaf2(ctx);
+  }
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_not_all_tail
+// CHECK-NOT:  tail call swifttailcc void @{{.*}}async_leaf1
+// CHECK:  call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NOT:  ret void
+// CHECK:  tail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_not_all_tail(char * ASYNC_CONTEXT ctx) {
+  async_leaf1(ctx);
+  return async_leaf2(ctx);
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_loop
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @{{.*}}async_loop
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_loop(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_loop(u - 2, ctx);
+}
+
+// Forward-declaration + mutual recursion is okay.
+
+SWIFTASYNCCALL void async_mutual_loop2(unsigned u, char * ASYNC_CONTEXT ctx);
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_mutual_loop1
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+// There is some bugginess around FileCheck's greediness/matching,
+// so skipping the check for async_mutual_loop2 here.
+SWIFTASYNCCALL void async_mutual_loop1(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_mutual_loop2(u - 2, ctx);
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_mutual_loop2
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailc

[PATCH] D95984: [CodeGen] Fix codegen for __attribute__((swiftasynccall)).

2021-03-02 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 327510.
varungandhi-apple added a comment.

Add null check for callee; instead of using getFunctionType() directly.

Otherwise, it leads to a crash when compiling gtest-all.cc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95984

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/64bit-swiftcall.c
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/swift-async-call-conv.c
  clang/test/CodeGen/swift-call-conv.c

Index: clang/test/CodeGen/swift-call-conv.c
===
--- clang/test/CodeGen/swift-call-conv.c
+++ clang/test/CodeGen/swift-call-conv.c
@@ -6,3 +6,5 @@
 void __attribute__((__swiftcall__)) f(void) {}
 // CHECK-LABEL: define dso_local swiftcc void @f()
 
+void __attribute__((__swiftasynccall__)) f_async(void) {}
+// CHECK-LABEL: define dso_local swifttailcc void @f_async()
Index: clang/test/CodeGen/swift-async-call-conv.c
===
--- /dev/null
+++ clang/test/CodeGen/swift-async-call-conv.c
@@ -0,0 +1,138 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -x c++ -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+
+// Test tail call behavior when a swiftasynccall function is called
+// from another swiftasynccall function.
+
+#define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_leaf1{{.*}}(i8* swiftasync
+SWIFTASYNCCALL void async_leaf1(char * ASYNC_CONTEXT ctx) {
+  *ctx += 1;
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_leaf2{{.*}}(i8* swiftasync
+SWIFTASYNCCALL void async_leaf2(char * ASYNC_CONTEXT ctx) {
+  *ctx += 2;
+}
+
+#if __cplusplus
+  #define MYBOOL bool
+#else
+  #define MYBOOL _Bool
+#endif
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_branch{{.*}}i8* swiftasync
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_branch(MYBOOL b, char * ASYNC_CONTEXT ctx) {
+  if (b) {
+return async_leaf1(ctx);
+  } else {
+return async_leaf2(ctx);
+  }
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_not_all_tail
+// CHECK-NOT:  tail call swifttailcc void @{{.*}}async_leaf1
+// CHECK:  call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NOT:  ret void
+// CHECK:  tail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_not_all_tail(char * ASYNC_CONTEXT ctx) {
+  async_leaf1(ctx);
+  return async_leaf2(ctx);
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_loop
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @{{.*}}async_loop
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_loop(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_loop(u - 2, ctx);
+}
+
+// Forward-declaration + mutual recursion is okay.
+
+SWIFTASYNCCALL void async_mutual_loop2(unsigned u, char * ASYNC_CONTEXT ctx);
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_mutual_loop1
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+// There is some bugginess around FileCheck's greediness/matching,
+// so skipping the check for async_mutual_loop2 here.
+SWIFTASYNCCALL void async_mutual_loop1(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_mutual_loop2(u - 2, ctx);
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_mutual_loop2
+// CHECK: tail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+/

[PATCH] D95561: [Clang] Introduce Swift async calling convention.

2021-03-11 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 329883.
varungandhi-apple added a comment.

Permit swift_context and swift_indirect_result parameters for
swiftasynccall functions. (Earlier, these were restricted to
swiftcall-only.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95561

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/CodeGen/SwiftCallingConv.h
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/PPC.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Basic/Targets/WebAssembly.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/debug-info-cc.c
  clang/test/CodeGen/swift-call-conv.c
  clang/test/Sema/attr-c2x.c
  clang/test/Sema/attr-swiftcall.c
  clang/test/Sema/no_callconv.cpp
  clang/test/SemaCXX/attr-swiftcall.cpp
  clang/tools/libclang/CXType.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-mangle.test

Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -341,6 +341,9 @@
 ?swift_func@@YSXXZ
 ; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
 
+?swift_async_func@@YTXXZ
+; CHECK: void __attribute__((__swiftasynccall__)) swift_async_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -110,6 +110,9 @@
   case CallingConv::Swift:
 OS << "__attribute__((__swiftcall__)) ";
 break;
+  case CallingConv::SwiftAsync:
+OS << "__attribute__((__swiftasynccall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1713,6 +1713,8 @@
 return CallingConv::Vectorcall;
   case 'S':
 return CallingConv::Swift;
+  case 'T':
+return CallingConv::SwiftAsync;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,7 +67,8 @@
   Eabi,
   Vectorcall,
   Regcall,
-  Swift, // Clang-only
+  Swift,  // Clang-only
+  SwiftAsync, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -664,6 +664,7 @@
   TCALLINGCONV(AAPCS_VFP);
   TCALLINGCONV(IntelOclBicc);
   TCALLINGCONV(Swift);
+  TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
Index: clang/test/SemaCXX/attr-swiftcall.cpp
===
--- clang/test/SemaCXX/attr-swiftcall.cpp
+++ clang/test/SemaCXX/attr-swiftcall.cpp
@@ -1,20 +1,29 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
 
 #define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
 #define INDIRECT_RESULT __attribute__((swift_indirect_result))
 #define ERROR_RESULT __attribute__((swift_error_result))
 #define CONTEXT __attribute__((swift_context))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
 
 int notAFunction SWIFTCALL; // expected-warning {{'swiftcall' only applies to function types; type here is 'int'}}
+int notAnAsyncFunction SWIFTASYNCCALL; // expected-warning {{'swiftasynccall' only applies to function types; type here is 'int'}}
 void variadic(int x, ...) SWIFTCALL; // expected-error {{variadic function cannot use swiftcall calling convention}}
+void variadic_async(int x, ...) SWIFTASYNCCALL; // expected-error {{variadic function cannot use swiftasynccall calling convention}}
 void multiple

[PATCH] D95984: [CodeGen] Fix codegen for __attribute__((swiftasynccall)).

2021-03-11 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 329889.
varungandhi-apple added a comment.

Use musttail call instead of tail call.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95984

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/64bit-swiftcall.c
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/swift-async-call-conv.c
  clang/test/CodeGen/swift-call-conv.c

Index: clang/test/CodeGen/swift-call-conv.c
===
--- clang/test/CodeGen/swift-call-conv.c
+++ clang/test/CodeGen/swift-call-conv.c
@@ -6,3 +6,5 @@
 void __attribute__((__swiftcall__)) f(void) {}
 // CHECK-LABEL: define dso_local swiftcc void @f()
 
+void __attribute__((__swiftasynccall__)) f_async(void) {}
+// CHECK-LABEL: define dso_local swifttailcc void @f_async()
Index: clang/test/CodeGen/swift-async-call-conv.c
===
--- /dev/null
+++ clang/test/CodeGen/swift-async-call-conv.c
@@ -0,0 +1,138 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -x c++ -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++ -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+
+// Test tail call behavior when a swiftasynccall function is called
+// from another swiftasynccall function.
+
+#define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_leaf1{{.*}}(i8* swiftasync
+SWIFTASYNCCALL void async_leaf1(char * ASYNC_CONTEXT ctx) {
+  *ctx += 1;
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_leaf2{{.*}}(i8* swiftasync
+SWIFTASYNCCALL void async_leaf2(char * ASYNC_CONTEXT ctx) {
+  *ctx += 2;
+}
+
+#if __cplusplus
+  #define MYBOOL bool
+#else
+  #define MYBOOL _Bool
+#endif
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_branch{{.*}}i8* swiftasync
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_branch(MYBOOL b, char * ASYNC_CONTEXT ctx) {
+  if (b) {
+return async_leaf1(ctx);
+  } else {
+return async_leaf2(ctx);
+  }
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_not_all_tail
+// CHECK-NOT:  musttail call swifttailcc void @{{.*}}async_leaf1
+// CHECK:  call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NOT:  ret void
+// CHECK:  musttail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_not_all_tail(char * ASYNC_CONTEXT ctx) {
+  async_leaf1(ctx);
+  return async_leaf2(ctx);
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_loop
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+// CHECK: musttail call swifttailcc void @{{.*}}async_loop
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_loop(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_loop(u - 2, ctx);
+}
+
+// Forward-declaration + mutual recursion is okay.
+
+SWIFTASYNCCALL void async_mutual_loop2(unsigned u, char * ASYNC_CONTEXT ctx);
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_mutual_loop1
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+// There is some bugginess around FileCheck's greediness/matching,
+// so skipping the check for async_mutual_loop2 here.
+SWIFTASYNCCALL void async_mutual_loop1(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_mutual_loop2(u - 2, ctx);
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_mutual_loop2
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: musttail call swifttailcc void @{{.*}}async_

[PATCH] D95984: [CodeGen] Fix codegen for __attribute__((swiftasynccall)).

2021-03-25 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 333421.
varungandhi-apple added a comment.

Fix codegen + add tests for methods and function pointers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95984

Files:
  clang/lib/AST/ExprCXX.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/64bit-swiftcall.c
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/swift-async-call-conv.c
  clang/test/CodeGen/swift-call-conv.c

Index: clang/test/CodeGen/swift-call-conv.c
===
--- clang/test/CodeGen/swift-call-conv.c
+++ clang/test/CodeGen/swift-call-conv.c
@@ -6,3 +6,5 @@
 void __attribute__((__swiftcall__)) f(void) {}
 // CHECK-LABEL: define dso_local swiftcc void @f()
 
+void __attribute__((__swiftasynccall__)) f_async(void) {}
+// CHECK-LABEL: define dso_local swifttailcc void @f_async()
Index: clang/test/CodeGen/swift-async-call-conv.c
===
--- /dev/null
+++ clang/test/CodeGen/swift-async-call-conv.c
@@ -0,0 +1,184 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -x c++ -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+// RUN: %clang_cc1 -x c++ -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+// RUN: %clang_cc1 -x c++ -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+// RUN: %clang_cc1 -x c++ -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+// RUN: %clang_cc1 -x c++ -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+
+// Test tail call behavior when a swiftasynccall function is called
+// from another swiftasynccall function.
+
+#define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_leaf1{{.*}}(i8* swiftasync
+SWIFTASYNCCALL void async_leaf1(char * ASYNC_CONTEXT ctx) {
+  *ctx += 1;
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_leaf2{{.*}}(i8* swiftasync
+SWIFTASYNCCALL void async_leaf2(char * ASYNC_CONTEXT ctx) {
+  *ctx += 2;
+}
+
+#if __cplusplus
+  #define MYBOOL bool
+#else
+  #define MYBOOL _Bool
+#endif
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_branch{{.*}}i8* swiftasync
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_branch(MYBOOL b, char * ASYNC_CONTEXT ctx) {
+  if (b) {
+return async_leaf1(ctx);
+  } else {
+return async_leaf2(ctx);
+  }
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_not_all_tail
+// CHECK-NOT:  musttail call swifttailcc void @{{.*}}async_leaf1
+// CHECK:  call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NOT:  ret void
+// CHECK:  musttail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_not_all_tail(char * ASYNC_CONTEXT ctx) {
+  async_leaf1(ctx);
+  return async_leaf2(ctx);
+}
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_loop
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+// CHECK: musttail call swifttailcc void @{{.*}}async_loop
+// CHECK-NEXT: ret void
+SWIFTASYNCCALL void async_loop(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return async_leaf2(ctx);
+  }
+  return async_loop(u - 2, ctx);
+}
+
+// Forward-declaration + mutual recursion is okay.
+
+SWIFTASYNCCALL void async_mutual_loop2(unsigned u, char * ASYNC_CONTEXT ctx);
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_mutual_loop1
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf1
+// CHECK-NEXT: ret void
+// CHECK: musttail call swifttailcc void @{{.*}}async_leaf2
+// CHECK-NEXT: ret void
+// There is some bugginess around FileCheck's greediness/matching,
+// so skipping the check for async_mutual_loop2 here.
+SWIFTASYNCCALL void async_mutual_loop1(unsigned u, char * ASYNC_CONTEXT ctx) {
+  if (u == 0) {
+return async_leaf1(ctx);
+  } else if (u == 1) {
+return asy

[PATCH] D95984: [CodeGen] Fix codegen for __attribute__((swiftasynccall)).

2021-04-05 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 335293.
varungandhi-apple added a comment.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Herald added a project: LLVM.

1. Remove '::' when calling static function.
2. Fix bug in function merging around missing musttail.
3. Add off-by-default check in verifier for swifttailcc->swifttailcc tail calls 
that are not marked musttail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95984

Files:
  clang/lib/AST/ExprCXX.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGen/64bit-swiftcall.c
  clang/test/CodeGen/arm-swiftcall.c
  clang/test/CodeGen/swift-async-call-conv.c
  clang/test/CodeGen/swift-call-conv.c
  llvm/lib/IR/Verifier.cpp
  llvm/lib/Transforms/IPO/MergeFunctions.cpp

Index: llvm/lib/Transforms/IPO/MergeFunctions.cpp
===
--- llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -713,7 +713,10 @@
 
   CallInst *CI = Builder.CreateCall(F, Args);
   ReturnInst *RI = nullptr;
-  CI->setTailCall();
+  bool isSwiftTailCall = F->getCallingConv() == CallingConv::SwiftTail &&
+ G->getCallingConv() == CallingConv::SwiftTail;
+  CI->setTailCallKind(isSwiftTailCall ? llvm::CallInst::TCK_MustTail
+  : llvm::CallInst::TCK_Tail);
   CI->setCallingConv(F->getCallingConv());
   CI->setAttributes(F->getAttributes());
   if (H->getReturnType()->isVoidTy()) {
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -3288,7 +3288,24 @@
   return Copy;
 }
 
+static cl::opt EnableSwiftTailCCMustTailCheck(
+"enable-swifttailcc-musttail-check", cl::init(false),
+cl::desc("Check that tail calls from swifttailcc functions to"
+ " swifttailcc functions are marked musttail."));
+
 void Verifier::verifyMustTailCall(CallInst &CI) {
+  if (!CI.isMustTailCall()) {
+if (EnableSwiftTailCCMustTailCheck &&
+CI.getCallingConv() == CallingConv::SwiftTail &&
+CI.getCaller()->getCallingConv() == CallingConv::SwiftTail &&
+isa_and_nonnull(CI.getNextNode())) {
+  Assert(false,
+ "tail call from swifttail->swiftail should be marked musttail",
+ &CI);
+}
+return;
+  }
+
   Assert(!CI.isInlineAsm(), "cannot use musttail call with inline asm", &CI);
 
   // - The caller and callee prototypes must match.  Pointer types of
@@ -3354,9 +3371,7 @@
 
 void Verifier::visitCallInst(CallInst &CI) {
   visitCallBase(CI);
-
-  if (CI.isMustTailCall())
-verifyMustTailCall(CI);
+  verifyMustTailCall(CI);
 }
 
 void Verifier::visitInvokeInst(InvokeInst &II) {
Index: clang/test/CodeGen/swift-call-conv.c
===
--- clang/test/CodeGen/swift-call-conv.c
+++ clang/test/CodeGen/swift-call-conv.c
@@ -6,3 +6,5 @@
 void __attribute__((__swiftcall__)) f(void) {}
 // CHECK-LABEL: define dso_local swiftcc void @f()
 
+void __attribute__((__swiftasynccall__)) f_async(void) {}
+// CHECK-LABEL: define dso_local swifttailcc void @f_async()
Index: clang/test/CodeGen/swift-async-call-conv.c
===
--- /dev/null
+++ clang/test/CodeGen/swift-async-call-conv.c
@@ -0,0 +1,184 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -x c++ -triple x86_64-apple-darwin10 -target-cpu core2 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+// RUN: %clang_cc1 -x c++ -triple arm64-apple-ios9 -target-cpu cyclone -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+// RUN: %clang_cc1 -x c++ -triple armv7-apple-darwin9 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+// RUN: %clang_cc1 -x c++ -triple armv7s-apple-ios9 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+// RUN: %clang_cc1 -x c++ -triple armv7k-apple-ios9 -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CPPONLY
+
+// Test tail call behavior when a swiftasynccall function is called
+// from another swiftasynccall function.
+
+#define SWIFTCALL __attribute__((swiftcall))
+#define SWIFTASYNCCALL __attribute__((swiftasynccall))
+#define ASYNC_CONTEXT __attribute__((swift_async_context))
+
+// CHECK-LABEL: swifttailcc void {{.*}}async_leaf1{{.*}}(i8*

[PATCH] D94196: [NFC] Move readAPValue/writeAPValue up the inheritance hierarchy

2021-01-06 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple created this revision.
varungandhi-apple added a reviewer: rjmccall.
varungandhi-apple requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The implementation for (de)serialization of APValues can be shared
between Clang and Swift, so we prefer pushing the methods up
the inheritance hierarchy, instead of having the methods live in
ASTReader/ASTWriter. Fixes rdar://72592937.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94196

Files:
  clang/include/clang/AST/APValue.h
  clang/include/clang/AST/AbstractBasicReader.h
  clang/include/clang/AST/AbstractBasicWriter.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/Serialization/ASTRecordReader.h
  clang/include/clang/Serialization/ASTRecordWriter.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/AST/APValue.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/utils/TableGen/ClangASTPropertiesEmitter.cpp

Index: clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
===
--- clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
+++ clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
@@ -708,15 +708,13 @@
   // Emit the Basic{Reader,Writer}Base template.
   Out << "template \n"
  "class Basic" << info.ClassSuffix << "Base {\n";
-  if (info.IsReader)
-Out << "  ASTContext &C;\n";
+  Out << "  ASTContext &C;\n";
   Out << "protected:\n"
- "  Basic" << info.ClassSuffix << "Base"
-   << (info.IsReader ? "(ASTContext &ctx) : C(ctx)" : "()")
-   << " {}\n"
+ "  Basic"
+  << info.ClassSuffix << "Base" << ("(ASTContext &ctx) : C(ctx)")
+  << " {}\n"
  "public:\n";
-  if (info.IsReader)
-Out << "  ASTContext &getASTContext() { return C; }\n";
+  Out << "  ASTContext &getASTContext() { return C; }\n";
   Out << "  Impl &asImpl() { return static_cast(*this); }\n";
 
   auto enterReaderWriterMethod = [&](StringRef cxxTypeName,
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -5121,144 +5121,6 @@
   AddAPInt(Value.bitcastToAPInt());
 }
 
-static void WriteFixedPointSemantics(ASTRecordWriter &Record,
- llvm::FixedPointSemantics FPSema) {
-  Record.push_back(FPSema.getWidth());
-  Record.push_back(FPSema.getScale());
-  Record.push_back(FPSema.isSigned() | FPSema.isSaturated() << 1 |
-   FPSema.hasUnsignedPadding() << 2);
-}
-
-void ASTRecordWriter::AddAPValue(const APValue &Value) {
-  APValue::ValueKind Kind = Value.getKind();
-  push_back(static_cast(Kind));
-  switch (Kind) {
-  case APValue::None:
-  case APValue::Indeterminate:
-return;
-  case APValue::Int:
-AddAPSInt(Value.getInt());
-return;
-  case APValue::Float:
-push_back(static_cast(
-llvm::APFloatBase::SemanticsToEnum(Value.getFloat().getSemantics(;
-AddAPFloat(Value.getFloat());
-return;
-  case APValue::FixedPoint: {
-WriteFixedPointSemantics(*this, Value.getFixedPoint().getSemantics());
-AddAPSInt(Value.getFixedPoint().getValue());
-return;
-  }
-  case APValue::ComplexInt: {
-AddAPSInt(Value.getComplexIntReal());
-AddAPSInt(Value.getComplexIntImag());
-return;
-  }
-  case APValue::ComplexFloat: {
-assert(llvm::APFloatBase::SemanticsToEnum(
-   Value.getComplexFloatImag().getSemantics()) ==
-   llvm::APFloatBase::SemanticsToEnum(
-   Value.getComplexFloatReal().getSemantics()));
-push_back(static_cast(llvm::APFloatBase::SemanticsToEnum(
-Value.getComplexFloatReal().getSemantics(;
-AddAPFloat(Value.getComplexFloatReal());
-AddAPFloat(Value.getComplexFloatImag());
-return;
-  }
-  case APValue::Vector:
-push_back(Value.getVectorLength());
-for (unsigned Idx = 0; Idx < Value.getVectorLength(); Idx++)
-  AddAPValue(Value.getVectorElt(Idx));
-return;
-  case APValue::Array:
-push_back(Value.getArrayInitializedElts());
-push_back(Value.getArraySize());
-for (unsigned Idx = 0; Idx < Value.getArrayInitializedElts(); Idx++)
-  AddAPValue(Value.getArrayInitializedElt(Idx));
-if (Value.hasArrayFiller())
-  AddAPValue(Value.getArrayFiller());
-return;
-  case APValue::Struct:
-push_back(Value.getStructNumBases());
-push_back(Value.getStructNumFields());
-for (unsigned Idx = 0; Idx < Value.getStructNumBases(); Idx++)
-  AddAPValue(Value.getStructBase(Idx));
-for (unsigned Idx = 0; Idx < Value.getStructNumFields(); Idx++)
-  AddAPValue(Value.getStructField(Idx));
-return;
-  case APValue::Union:
-AddDeclRef(Value.getUnionField());
-AddAPValue(Value.getUnionValue());
-return;
-  case APValue::AddrLabelDiff:
-AddStmt(const_cas

[PATCH] D94196: [NFC] Move readAPValue/writeAPValue up the inheritance hierarchy

2021-01-06 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 315005.
varungandhi-apple added a comment.

Appease clang-tidy.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94196

Files:
  clang/include/clang/AST/APValue.h
  clang/include/clang/AST/AbstractBasicReader.h
  clang/include/clang/AST/AbstractBasicWriter.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/Serialization/ASTRecordReader.h
  clang/include/clang/Serialization/ASTRecordWriter.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/AST/APValue.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/utils/TableGen/ClangASTPropertiesEmitter.cpp

Index: clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
===
--- clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
+++ clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
@@ -708,15 +708,13 @@
   // Emit the Basic{Reader,Writer}Base template.
   Out << "template \n"
  "class Basic" << info.ClassSuffix << "Base {\n";
-  if (info.IsReader)
-Out << "  ASTContext &C;\n";
+  Out << "  ASTContext &C;\n";
   Out << "protected:\n"
- "  Basic" << info.ClassSuffix << "Base"
-   << (info.IsReader ? "(ASTContext &ctx) : C(ctx)" : "()")
-   << " {}\n"
+ "  Basic"
+  << info.ClassSuffix << "Base" << ("(ASTContext &ctx) : C(ctx)")
+  << " {}\n"
  "public:\n";
-  if (info.IsReader)
-Out << "  ASTContext &getASTContext() { return C; }\n";
+  Out << "  ASTContext &getASTContext() { return C; }\n";
   Out << "  Impl &asImpl() { return static_cast(*this); }\n";
 
   auto enterReaderWriterMethod = [&](StringRef cxxTypeName,
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -5121,144 +5121,6 @@
   AddAPInt(Value.bitcastToAPInt());
 }
 
-static void WriteFixedPointSemantics(ASTRecordWriter &Record,
- llvm::FixedPointSemantics FPSema) {
-  Record.push_back(FPSema.getWidth());
-  Record.push_back(FPSema.getScale());
-  Record.push_back(FPSema.isSigned() | FPSema.isSaturated() << 1 |
-   FPSema.hasUnsignedPadding() << 2);
-}
-
-void ASTRecordWriter::AddAPValue(const APValue &Value) {
-  APValue::ValueKind Kind = Value.getKind();
-  push_back(static_cast(Kind));
-  switch (Kind) {
-  case APValue::None:
-  case APValue::Indeterminate:
-return;
-  case APValue::Int:
-AddAPSInt(Value.getInt());
-return;
-  case APValue::Float:
-push_back(static_cast(
-llvm::APFloatBase::SemanticsToEnum(Value.getFloat().getSemantics(;
-AddAPFloat(Value.getFloat());
-return;
-  case APValue::FixedPoint: {
-WriteFixedPointSemantics(*this, Value.getFixedPoint().getSemantics());
-AddAPSInt(Value.getFixedPoint().getValue());
-return;
-  }
-  case APValue::ComplexInt: {
-AddAPSInt(Value.getComplexIntReal());
-AddAPSInt(Value.getComplexIntImag());
-return;
-  }
-  case APValue::ComplexFloat: {
-assert(llvm::APFloatBase::SemanticsToEnum(
-   Value.getComplexFloatImag().getSemantics()) ==
-   llvm::APFloatBase::SemanticsToEnum(
-   Value.getComplexFloatReal().getSemantics()));
-push_back(static_cast(llvm::APFloatBase::SemanticsToEnum(
-Value.getComplexFloatReal().getSemantics(;
-AddAPFloat(Value.getComplexFloatReal());
-AddAPFloat(Value.getComplexFloatImag());
-return;
-  }
-  case APValue::Vector:
-push_back(Value.getVectorLength());
-for (unsigned Idx = 0; Idx < Value.getVectorLength(); Idx++)
-  AddAPValue(Value.getVectorElt(Idx));
-return;
-  case APValue::Array:
-push_back(Value.getArrayInitializedElts());
-push_back(Value.getArraySize());
-for (unsigned Idx = 0; Idx < Value.getArrayInitializedElts(); Idx++)
-  AddAPValue(Value.getArrayInitializedElt(Idx));
-if (Value.hasArrayFiller())
-  AddAPValue(Value.getArrayFiller());
-return;
-  case APValue::Struct:
-push_back(Value.getStructNumBases());
-push_back(Value.getStructNumFields());
-for (unsigned Idx = 0; Idx < Value.getStructNumBases(); Idx++)
-  AddAPValue(Value.getStructBase(Idx));
-for (unsigned Idx = 0; Idx < Value.getStructNumFields(); Idx++)
-  AddAPValue(Value.getStructField(Idx));
-return;
-  case APValue::Union:
-AddDeclRef(Value.getUnionField());
-AddAPValue(Value.getUnionValue());
-return;
-  case APValue::AddrLabelDiff:
-AddStmt(const_cast(Value.getAddrLabelDiffLHS()));
-AddStmt(const_cast(Value.getAddrLabelDiffRHS()));
-return;
-  case APValue::MemberPointer: {
-push_back(Value.isMemberPointerToDerivedMember());
-AddDeclRef(Value.getMemberPointerDecl());
-ArrayRef RecordPath = Value.

[PATCH] D94196: [NFC] Move readAPValue/writeAPValue up the inheritance hierarchy

2021-01-06 Thread Varun Gandhi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG37e83bc6db3a: [NFC] Move readAPValue/writeAPValue up the 
inheritance hierarchy (authored by varungandhi-apple).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94196

Files:
  clang/include/clang/AST/APValue.h
  clang/include/clang/AST/AbstractBasicReader.h
  clang/include/clang/AST/AbstractBasicWriter.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/Serialization/ASTRecordReader.h
  clang/include/clang/Serialization/ASTRecordWriter.h
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/AST/APValue.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/utils/TableGen/ClangASTPropertiesEmitter.cpp

Index: clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
===
--- clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
+++ clang/utils/TableGen/ClangASTPropertiesEmitter.cpp
@@ -708,15 +708,13 @@
   // Emit the Basic{Reader,Writer}Base template.
   Out << "template \n"
  "class Basic" << info.ClassSuffix << "Base {\n";
-  if (info.IsReader)
-Out << "  ASTContext &C;\n";
+  Out << "  ASTContext &C;\n";
   Out << "protected:\n"
- "  Basic" << info.ClassSuffix << "Base"
-   << (info.IsReader ? "(ASTContext &ctx) : C(ctx)" : "()")
-   << " {}\n"
+ "  Basic"
+  << info.ClassSuffix << "Base" << ("(ASTContext &ctx) : C(ctx)")
+  << " {}\n"
  "public:\n";
-  if (info.IsReader)
-Out << "  ASTContext &getASTContext() { return C; }\n";
+  Out << "  ASTContext &getASTContext() { return C; }\n";
   Out << "  Impl &asImpl() { return static_cast(*this); }\n";
 
   auto enterReaderWriterMethod = [&](StringRef cxxTypeName,
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -5121,144 +5121,6 @@
   AddAPInt(Value.bitcastToAPInt());
 }
 
-static void WriteFixedPointSemantics(ASTRecordWriter &Record,
- llvm::FixedPointSemantics FPSema) {
-  Record.push_back(FPSema.getWidth());
-  Record.push_back(FPSema.getScale());
-  Record.push_back(FPSema.isSigned() | FPSema.isSaturated() << 1 |
-   FPSema.hasUnsignedPadding() << 2);
-}
-
-void ASTRecordWriter::AddAPValue(const APValue &Value) {
-  APValue::ValueKind Kind = Value.getKind();
-  push_back(static_cast(Kind));
-  switch (Kind) {
-  case APValue::None:
-  case APValue::Indeterminate:
-return;
-  case APValue::Int:
-AddAPSInt(Value.getInt());
-return;
-  case APValue::Float:
-push_back(static_cast(
-llvm::APFloatBase::SemanticsToEnum(Value.getFloat().getSemantics(;
-AddAPFloat(Value.getFloat());
-return;
-  case APValue::FixedPoint: {
-WriteFixedPointSemantics(*this, Value.getFixedPoint().getSemantics());
-AddAPSInt(Value.getFixedPoint().getValue());
-return;
-  }
-  case APValue::ComplexInt: {
-AddAPSInt(Value.getComplexIntReal());
-AddAPSInt(Value.getComplexIntImag());
-return;
-  }
-  case APValue::ComplexFloat: {
-assert(llvm::APFloatBase::SemanticsToEnum(
-   Value.getComplexFloatImag().getSemantics()) ==
-   llvm::APFloatBase::SemanticsToEnum(
-   Value.getComplexFloatReal().getSemantics()));
-push_back(static_cast(llvm::APFloatBase::SemanticsToEnum(
-Value.getComplexFloatReal().getSemantics(;
-AddAPFloat(Value.getComplexFloatReal());
-AddAPFloat(Value.getComplexFloatImag());
-return;
-  }
-  case APValue::Vector:
-push_back(Value.getVectorLength());
-for (unsigned Idx = 0; Idx < Value.getVectorLength(); Idx++)
-  AddAPValue(Value.getVectorElt(Idx));
-return;
-  case APValue::Array:
-push_back(Value.getArrayInitializedElts());
-push_back(Value.getArraySize());
-for (unsigned Idx = 0; Idx < Value.getArrayInitializedElts(); Idx++)
-  AddAPValue(Value.getArrayInitializedElt(Idx));
-if (Value.hasArrayFiller())
-  AddAPValue(Value.getArrayFiller());
-return;
-  case APValue::Struct:
-push_back(Value.getStructNumBases());
-push_back(Value.getStructNumFields());
-for (unsigned Idx = 0; Idx < Value.getStructNumBases(); Idx++)
-  AddAPValue(Value.getStructBase(Idx));
-for (unsigned Idx = 0; Idx < Value.getStructNumFields(); Idx++)
-  AddAPValue(Value.getStructField(Idx));
-return;
-  case APValue::Union:
-AddDeclRef(Value.getUnionField());
-AddAPValue(Value.getUnionValue());
-return;
-  case APValue::AddrLabelDiff:
-AddStmt(const_cast(Value.getAddrLabelDiffLHS()));
-AddStmt(const_cast(Value.getAddrLabelDiffRHS()));
-return;
-  case APValue::MemberPointer: {
-push_back(Value.isMemberPointerToDeriv

[PATCH] D94854: [Clang] Fix SwiftCallingConv's aggregate lowering for _Atomic(_Bool).

2021-01-15 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple created this revision.
varungandhi-apple added reviewers: aschwaighofer, rjmccall.
Herald added a subscriber: jfb.
varungandhi-apple requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes rdar://72999296.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94854

Files:
  clang/lib/CodeGen/SwiftCallingConv.cpp


Index: clang/lib/CodeGen/SwiftCallingConv.cpp
===
--- clang/lib/CodeGen/SwiftCallingConv.cpp
+++ clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -99,6 +99,15 @@
 auto atomicSize = CGM.getContext().getTypeSizeInChars(atomicType);
 auto valueSize = CGM.getContext().getTypeSizeInChars(valueType);
 
+auto valueTy = atomicType->getValueType();
+// _Atomic(_Bool) does not correspond to i1.
+if (valueTy == CGM.getContext().BoolTy) {
+  addTypedData(llvm::Type::getIntNTy(CGM.getLLVMContext(),
+ CGM.getContext().toBits(valueSize)),
+   begin);
+} else {
+  addTypedData(atomicType->getValueType(), begin);
+}
 addTypedData(atomicType->getValueType(), begin);
 
 // Add atomic padding.


Index: clang/lib/CodeGen/SwiftCallingConv.cpp
===
--- clang/lib/CodeGen/SwiftCallingConv.cpp
+++ clang/lib/CodeGen/SwiftCallingConv.cpp
@@ -99,6 +99,15 @@
 auto atomicSize = CGM.getContext().getTypeSizeInChars(atomicType);
 auto valueSize = CGM.getContext().getTypeSizeInChars(valueType);
 
+auto valueTy = atomicType->getValueType();
+// _Atomic(_Bool) does not correspond to i1.
+if (valueTy == CGM.getContext().BoolTy) {
+  addTypedData(llvm::Type::getIntNTy(CGM.getLLVMContext(),
+ CGM.getContext().toBits(valueSize)),
+   begin);
+} else {
+  addTypedData(atomicType->getValueType(), begin);
+}
 addTypedData(atomicType->getValueType(), begin);
 
 // Add atomic padding.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D94854: [Clang] Fix SwiftCallingConv's aggregate lowering for _Atomic(_Bool).

2021-01-15 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added a comment.

I don't know how to test this on the LLVM-side (is there a way to do it?). 
Here's the Swift side test which trips over right now (but is fixed with this 
patch) by attempting a zext from an i8 to an i1 in Swift's 
`NativeConventionSchema::mapIntoNative`.

  +++ b/test/IRGen/Inputs/atomic_bool.h
  @@ -0,0 +1 @@
  +typedef struct { _Atomic(_Bool) value; } MyAtomicBool;
  +++ b/test/IRGen/Inputs/module.modulemap
  @@ -23 +23,6 @@ module AutolinkModuleMapLink {
   }
  +
  +module AtomicBoolModule {
  +  header "atomic_bool.h"
  +  export *
  +}
  +++ b/test/IRGen/atomic_bool.swift
  @@ -0,0 +1,7 @@
  +// RUN: not --crash %target-swift-emit-ir %s -I %S/Inputs
  +
  +import AtomicBoolModule
  +
  +public func f() -> MyAtomicBool {
  +  return MyAtomicBool()
  +}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94854

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


[PATCH] D94854: [Clang] Fix SwiftCallingConv's aggregate lowering for _Atomic(_Bool).

2021-01-16 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added a comment.

> The way you'd test it on the Clang side would be to just write a test case 
> that passes such an aggregate and tests that it's passed as an `i8`.

Ah, I just noticed an attribute `__attribute__((swiftcall))` that is used in 
some test cases, I can add a test for it.

---

> But I'm not sure it's at all unreasonable to pass this as an i1 rather than 
> an i8; seems like something that Swift should handle correctly in its 
> call-lowering code.

Here is the code in the compiler which is creating the `i8`.

  void addStructField(const clang::FieldDecl *clangField,
  VarDecl *swiftField) {
unsigned fieldOffset = 
ClangLayout.getFieldOffset(clangField->getFieldIndex());
assert(!clangField->isBitField());
Size offset(fieldOffset / 8);
  
// If we have a Swift import of this type, use our lowered information.
if (swiftField) { /* snip */ }
  
// Otherwise, add it as an opaque blob.
auto fieldSize = ClangContext.getTypeSizeInChars(clangField->getType());
return addOpaqueField(offset, Size(fieldSize.getQuantity()));
  }

From what I understand, the `i8` is actually correct. (I looked at LLVM IR 
generated by small examples and those seem to use `i8` for loads, stores and 
layout.)

That said, there is special handling in `NativeConventionSchema::mapIntoNative` 
and `NativeConventionSchema::mapFromNative`. Here's the code in `mapIntoNative`.

  if (fromNonNative.size() == 1) {
auto *elt = fromNonNative.claimNext();
if (nativeTy != elt->getType()) {
  if (isa(nativeTy) &&
  isa(elt->getType()))
elt = IGF.Builder.CreateZExt(elt, nativeTy);

This ends up trying to zext from i8 to i1 and trips over.

Are you suggesting that I change the code in `mapIntoNative`/`mapFromNative` to 
flip the zext/trunc the other way around based on sizes? Should I be adding the 
special case to `addStructField`? Something else?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94854

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


[PATCH] D94854: [Clang] Fix SwiftCallingConv's aggregate lowering for _Atomic(_Bool).

2021-01-19 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple abandoned this revision.
varungandhi-apple added a comment.

Closing this in favor of a Swift-side fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D94854

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


[PATCH] D95053: [Demangle] Support demangling Swift calling convention in MS demangler.

2021-01-20 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple created this revision.
varungandhi-apple added a reviewer: compnerd.
Herald added a subscriber: hiraditya.
varungandhi-apple requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Previously, Clang was able to mangle the Swift calling
convention but 'MicrosoftDemangle.cpp' was not able to demangle it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95053

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-mangle.test


Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -338,6 +338,9 @@
 ?vector_func@@YQXXZ
 ; CHECK: void __vectorcall vector_func(void)
 
+?swift_func@@YSXXZ
+; CHECK: void __attribute__((__swiftcall__))swift_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -107,6 +107,9 @@
   case CallingConv::Clrcall:
 OS << "__clrcall";
 break;
+  case CallingConv::Swift:
+OS << "__attribute__((__swiftcall__))";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1711,6 +1711,8 @@
 return CallingConv::Eabi;
   case 'Q':
 return CallingConv::Vectorcall;
+  case 'S':
+return CallingConv::Swift;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,6 +67,7 @@
   Eabi,
   Vectorcall,
   Regcall,
+  Swift, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -2695,6 +2695,7 @@
   //  ::= I # __fastcall
   //  ::= J # __export __fastcall
   //  ::= Q # __vectorcall
+  //  ::= S # __attribute__((__swiftcall__)) // Clang-only
   //  ::= w # __regcall
   // The 'export' calling conventions are from a bygone era
   // (*cough*Win16*cough*) when functions were declared for export with


Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -338,6 +338,9 @@
 ?vector_func@@YQXXZ
 ; CHECK: void __vectorcall vector_func(void)
 
+?swift_func@@YSXXZ
+; CHECK: void __attribute__((__swiftcall__))swift_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -107,6 +107,9 @@
   case CallingConv::Clrcall:
 OS << "__clrcall";
 break;
+  case CallingConv::Swift:
+OS << "__attribute__((__swiftcall__))";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1711,6 +1711,8 @@
 return CallingConv::Eabi;
   case 'Q':
 return CallingConv::Vectorcall;
+  case 'S':
+return CallingConv::Swift;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,6 +67,7 @@
   Eabi,
   Vectorcall,
   Regcall,
+  Swift, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -2695,6 +2695,7 @@
   //  ::= I # __fastcall
   //  ::= J # __export __fastcall
   //  ::= Q # __vector

[PATCH] D95053: [Demangle] Support demangling Swift calling convention in MS demangler.

2021-01-20 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple updated this revision to Diff 318050.
varungandhi-apple added a comment.

Add extra space for better readability, as suggested by @compnerd.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95053

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
  llvm/lib/Demangle/MicrosoftDemangle.cpp
  llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
  llvm/test/Demangle/ms-mangle.test


Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -338,6 +338,9 @@
 ?vector_func@@YQXXZ
 ; CHECK: void __vectorcall vector_func(void)
 
+?swift_func@@YSXXZ
+; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -107,6 +107,9 @@
   case CallingConv::Clrcall:
 OS << "__clrcall";
 break;
+  case CallingConv::Swift:
+OS << "__attribute__((__swiftcall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1711,6 +1711,8 @@
 return CallingConv::Eabi;
   case 'Q':
 return CallingConv::Vectorcall;
+  case 'S':
+return CallingConv::Swift;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,6 +67,7 @@
   Eabi,
   Vectorcall,
   Regcall,
+  Swift, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -2695,6 +2695,7 @@
   //  ::= I # __fastcall
   //  ::= J # __export __fastcall
   //  ::= Q # __vectorcall
+  //  ::= S # __attribute__((__swiftcall__)) // Clang-only
   //  ::= w # __regcall
   // The 'export' calling conventions are from a bygone era
   // (*cough*Win16*cough*) when functions were declared for export with


Index: llvm/test/Demangle/ms-mangle.test
===
--- llvm/test/Demangle/ms-mangle.test
+++ llvm/test/Demangle/ms-mangle.test
@@ -338,6 +338,9 @@
 ?vector_func@@YQXXZ
 ; CHECK: void __vectorcall vector_func(void)
 
+?swift_func@@YSXXZ
+; CHECK: void __attribute__((__swiftcall__)) swift_func(void)
+
 ??$fn_tmpl@$1?extern_c_func@@YAXXZ@@YAXXZ
 ; CHECK: void __cdecl fn_tmpl<&void __cdecl extern_c_func(void)>(void)
 
Index: llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
+++ llvm/lib/Demangle/MicrosoftDemangleNodes.cpp
@@ -107,6 +107,9 @@
   case CallingConv::Clrcall:
 OS << "__clrcall";
 break;
+  case CallingConv::Swift:
+OS << "__attribute__((__swiftcall__)) ";
+break;
   default:
 break;
   }
Index: llvm/lib/Demangle/MicrosoftDemangle.cpp
===
--- llvm/lib/Demangle/MicrosoftDemangle.cpp
+++ llvm/lib/Demangle/MicrosoftDemangle.cpp
@@ -1711,6 +1711,8 @@
 return CallingConv::Eabi;
   case 'Q':
 return CallingConv::Vectorcall;
+  case 'S':
+return CallingConv::Swift;
   }
 
   return CallingConv::None;
Index: llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
===
--- llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
+++ llvm/include/llvm/Demangle/MicrosoftDemangleNodes.h
@@ -67,6 +67,7 @@
   Eabi,
   Vectorcall,
   Regcall,
+  Swift, // Clang-only
 };
 
 enum class ReferenceKind : uint8_t { None, LValueRef, RValueRef };
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -2695,6 +2695,7 @@
   //  ::= I # __fastcall
   //  ::= J # __export __fastcall
   //  ::= Q # __vectorcall
+  //  ::= S # __attribute__((__swiftcall__)) // Clang-only
   //  ::= w # __regcall
   // The 'export' calling conve

[PATCH] D95053: [Demangle] Support demangling Swift calling convention in MS demangler.

2021-01-20 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple marked an inline comment as done.
varungandhi-apple added a comment.

I've fixed this by including an additional space in the string instead of using 
a method like `outputSpaceIfNecessary`; (1) that method doesn't work as it is 
and I think changing it for this purpose is not appropriate and (2) we probably 
want the space there unconditionally anyways.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95053

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


[PATCH] D109128: [VFS] Use original path when falling back to external FS

2021-09-02 Thread Varun Gandhi via Phabricator via cfe-commits
varungandhi-apple added a comment.

cc @JDevlieghere


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109128

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