]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] Make sret parameter work with AddMissingPrototypes
authorHeejin Ahn <aheejin@gmail.com>
Tue, 9 Jul 2019 02:10:33 +0000 (02:10 +0000)
committerHeejin Ahn <aheejin@gmail.com>
Tue, 9 Jul 2019 02:10:33 +0000 (02:10 +0000)
Summary:
Even with functions with `no-prototype` attribute, there can be an
argument `sret` (structure return) attribute, which is an optimization
when a function return type is a struct. Fixes PR42420.

Reviewers: sbc100

Subscribers: dschuff, jgravelle-google, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365426 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp
test/CodeGen/WebAssembly/add-prototypes.ll

index 3e13369f33e07cc5b195abc2ec458b3010d5804b..b7a701f1578297c986eb9363764e790c87577db7 100644 (file)
@@ -78,10 +78,13 @@ bool WebAssemblyAddMissingPrototypes::runOnModule(Module &M) {
       report_fatal_error(
           "Functions with 'no-prototype' attribute must take varargs: " +
           F.getName());
-    if (F.getFunctionType()->getNumParams() != 0)
-      report_fatal_error(
-          "Functions with 'no-prototype' attribute should not have params: " +
-          F.getName());
+    unsigned NumParams = F.getFunctionType()->getNumParams();
+    if (NumParams != 0) {
+      if (!(NumParams == 1 && F.arg_begin()->hasStructRetAttr()))
+        report_fatal_error("Functions with 'no-prototype' attribute should "
+                           "not have params: " +
+                           F.getName());
+    }
 
     // Create a function prototype based on the first call site (first bitcast)
     // that we find.
index f42e4827d2fde3c76acebb573053f9a6ef8ed574..84d7657e9830f3ec8ee8ac9d157eab38d27390b7 100644 (file)
@@ -56,6 +56,17 @@ define void @as_paramater() {
   ret void
 }
 
+; Check if a sret parameter works in a no-prototype function.
+; CHECK-LABEL: @sret_param
+; CHECK: call void @make_struct_foo(%struct.foo* sret %foo)
+%struct.foo = type { i32, i32 }
+declare void @make_struct_foo(%struct.foo* sret, ...) #1
+define void @sret_param() {
+  %foo = alloca %struct.foo, align 4
+  call void bitcast (void (%struct.foo*, ...)* @make_struct_foo to void (%struct.foo*)*)(%struct.foo* sret %foo)
+  ret void
+}
+
 declare void @func_param(i64 (...)*)
 
 ; CHECK: declare void @func_not_called()