Skip to content

Commit 947bfe7

Browse files
committed
[WebAssembly] Make sret parameter work with AddMissingPrototypes
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 llvm-svn: 365426
1 parent 0e344e9 commit 947bfe7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

llvm/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ bool WebAssemblyAddMissingPrototypes::runOnModule(Module &M) {
7878
report_fatal_error(
7979
"Functions with 'no-prototype' attribute must take varargs: " +
8080
F.getName());
81-
if (F.getFunctionType()->getNumParams() != 0)
82-
report_fatal_error(
83-
"Functions with 'no-prototype' attribute should not have params: " +
84-
F.getName());
81+
unsigned NumParams = F.getFunctionType()->getNumParams();
82+
if (NumParams != 0) {
83+
if (!(NumParams == 1 && F.arg_begin()->hasStructRetAttr()))
84+
report_fatal_error("Functions with 'no-prototype' attribute should "
85+
"not have params: " +
86+
F.getName());
87+
}
8588

8689
// Create a function prototype based on the first call site (first bitcast)
8790
// that we find.

llvm/test/CodeGen/WebAssembly/add-prototypes.ll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ define void @as_paramater() {
5656
ret void
5757
}
5858

59+
; Check if a sret parameter works in a no-prototype function.
60+
; CHECK-LABEL: @sret_param
61+
; CHECK: call void @make_struct_foo(%struct.foo* sret %foo)
62+
%struct.foo = type { i32, i32 }
63+
declare void @make_struct_foo(%struct.foo* sret, ...) #1
64+
define void @sret_param() {
65+
%foo = alloca %struct.foo, align 4
66+
call void bitcast (void (%struct.foo*, ...)* @make_struct_foo to void (%struct.foo*)*)(%struct.foo* sret %foo)
67+
ret void
68+
}
69+
5970
declare void @func_param(i64 (...)*)
6071

6172
; CHECK: declare void @func_not_called()

0 commit comments

Comments
 (0)