Skip to content

Commit 51092de

Browse files
committed
Fix crash with struct parameter assignment from function call. (#934)
Edge case that triggered an assert.
1 parent 2ace988 commit 51092de

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/liboslcomp/codegen.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -998,15 +998,15 @@ ASTNode::codegen_struct_initializers (ref init, Symbol *sym,
998998
continue;
999999
}
10001000

1001-
if (paraminit) {
1001+
if (paraminit && nodetype() == variable_declaration_node) {
10021002
// For parameter initialization, don't really generate ops if it
10031003
// can be statically initialized.
10041004
std::string out;
1005-
ASSERT (nodetype() == variable_declaration_node);
10061005
ASTvariable_declaration *v = (ASTvariable_declaration *)this;
10071006
if (v->param_default_literals (fieldsym, init.get(), out))
10081007
continue;
1009-
1008+
}
1009+
if (paraminit) {
10101010
// Delineate and remember the init ops for this field individually
10111011
m_compiler->codegen_method (fieldname);
10121012
fieldsym->initbegin (m_compiler->next_op_label ());

testsuite/struct-return/ref/out.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Compiled test.osl -> test.oso
2+
test struct param initialization: v2iparam = 19 20
23
test struct return
34
{2 3} + {10 20} = {12 23}
45
square({2 3}) = {4 9}

testsuite/struct-return/test.osl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ Complicated ugly ()
4545

4646

4747
shader
48-
test ()
48+
test (Vec2i v2iparam = Vec2i(19,20))
4949
{
50+
printf ("test struct param initialization: v2iparam = %d %d\n",
51+
v2iparam.x, v2iparam.y);
52+
5053
// Example of a function returning a struct in an inner scope
5154
Vec2i square (Vec2i a) {
5255
Vec2i r;

0 commit comments

Comments
 (0)