Skip to content

Commit e6f921a

Browse files
committed
Fix oslc assertion when passing stucts with operator overloading. (762)
The recent patch that allows users to specify operator overloading for structs means that, in this particular spot, the AST node type that might be passed as the argument to a function might be a binary or unary expression -- those could never have returned a struct before, so were not enumerated in the list of nodes of this conditional, causing an assertion to hit.
1 parent eb7b872 commit e6f921a

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/liboslcomp/codegen.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,9 @@ ASTfunction_call::codegen (Symbol *dest)
17321732
// If the formal parameter is a struct, we also need to
17331733
// alias each of the fields
17341734
if (a->nodetype() == variable_ref_node ||
1735-
a->nodetype() == function_call_node) {
1735+
a->nodetype() == function_call_node ||
1736+
a->nodetype() == binary_expression_node ||
1737+
a->nodetype() == unary_expression_node) {
17361738
// Passed a variable that is a struct ; make the struct
17371739
// fields of the formal param alias to the struct fields
17381740
// of the actual param. Exact same logic if passed the

testsuite/operator-overloading/test.osl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ vector4 __operator__neg__ (vector4 a) {
2424
}
2525

2626

27+
// Make a function to double check it's ok to pass the result of a
28+
// binary operator into a function argument
29+
vector4 add (vector4 a, vector4 b)
30+
{
31+
return a+b;
32+
}
33+
34+
35+
2736
shader test ()
2837
{
2938
vector4 a = vector4 (.2, .3, .4, .5);
@@ -46,4 +55,8 @@ shader test ()
4655

4756
c = -a;
4857
printf ("-a = %g %g %g %g\n", c.x, c.y, c.z, c.w);
58+
59+
// regression test: #762 fixed a bug where passing a struct-returning
60+
// binary expression into a function argument would hit an asseriton.
61+
c = add (c,c);
4962
}

0 commit comments

Comments
 (0)