tlively created this revision.
Herald added subscribers: pmatos, wingo, ecnelises, sunfish, jgravelle-google, 
sbc100, dschuff.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
tlively requested review of this revision.
Herald added subscribers: cfe-commits, aheejin.
Herald added a project: clang.

WebAssembly is not able to emit tail calls unless the `tail-call` target feature
is enabled and when it is not enabled, trying to compile musttail calls produces
a fatal error in the backend. To reflect this reality, disable support for the
`[[clang::musttail]]` attribute when targeting WebAssembly without the
`tail-call` feature.

Marked draft for further discussion because I'm not sure getting this:

  test.cpp:10:7: warning: unknown attribute 'musttail' ignored 
[-Wunknown-attributes]
      [[clang::musttail]] return bar(x * 10);

is actually better developer experience than getting a fatal error with a
description of the WebAssembly-specific problem. Users can also check for the
presence of the `__wasm_tail_call__` macro as an alternative to checking
`__has_cpp_attribute(clang::musttail)` with this patch, but I'm not sure that's
documented anywhere.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131990

Files:
  clang/include/clang/Basic/Attr.td


Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -414,6 +414,11 @@
 def TargetSupportsInitPriority : TargetSpec {
   let CustomCode = [{ !Target.getTriple().isOSzOS() }];
 }
+
+def TargetSupportsMustTail : TargetSpec {
+  let CustomCode = [{ !Target.getTriple().isWasm() || 
Target.hasFeature("tail-call") }];
+}
+
 // Attribute subject match rules that are used for #pragma clang attribute.
 //
 // A instance of AttrSubjectMatcherRule represents an individual match rule.
@@ -1433,7 +1438,7 @@
   let SimpleHandler = 1;
 }
 
-def MustTail : StmtAttr {
+def MustTail : StmtAttr, TargetSpecificAttr<TargetSupportsMustTail> {
   let Spellings = [Clang<"musttail">];
   let Documentation = [MustTailDocs];
   let Subjects = SubjectList<[ReturnStmt], ErrorDiag, "return statements">;


Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -414,6 +414,11 @@
 def TargetSupportsInitPriority : TargetSpec {
   let CustomCode = [{ !Target.getTriple().isOSzOS() }];
 }
+
+def TargetSupportsMustTail : TargetSpec {
+  let CustomCode = [{ !Target.getTriple().isWasm() || Target.hasFeature("tail-call") }];
+}
+
 // Attribute subject match rules that are used for #pragma clang attribute.
 //
 // A instance of AttrSubjectMatcherRule represents an individual match rule.
@@ -1433,7 +1438,7 @@
   let SimpleHandler = 1;
 }
 
-def MustTail : StmtAttr {
+def MustTail : StmtAttr, TargetSpecificAttr<TargetSupportsMustTail> {
   let Spellings = [Clang<"musttail">];
   let Documentation = [MustTailDocs];
   let Subjects = SubjectList<[ReturnStmt], ErrorDiag, "return statements">;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to