nddrylliog/rock — Issue #351: Assignment on return sometimes generates bad C code
Author: tm512
Created: 2011-12-12 05:36:54+00:00
State: open

While porting a XORshift PRNG to ooc, I ran into an issue where the following code generated erroneous C code, causing gcc to fail:

`
get32 : func -> UInt32
{
tmp := state32 [0] ^ (state32 [0] << 11)
state32 [0] = state32 [1]
state32 [1] = state32 [2]
state32 [2] = state32 [3]

return state32 [3] = (state32 [3] ^ (state32 [3] >> 19)) ^ (tmp ^ (tmp >> 8))
}
`

GCC prints out:
`
rock_tmp/./xorshift.c: In function ‘xorshift__xorgen_init_withSeed’:
rock_tmp/./xorshift.c:29:5: warning: suggest parentheses around ‘+’ inside ‘<<’ [-Wparentheses]
rock_tmp/./xorshift.c:30:5: warning: suggest parentheses around ‘+’ inside ‘<<’ [-Wparentheses]
rock_tmp/./xorshift.c:31:5: warning: suggest parentheses around ‘+’ inside ‘<<’ [-Wparentheses]
rock_tmp/./xorshift.c:32:5: warning: suggest parentheses around ‘+’ inside ‘<<’ [-Wparentheses]
rock_tmp/./xorshift.c:33:5: warning: suggest parentheses around ‘+’ inside ‘<<’ [-Wparentheses]
rock_tmp/./xorshift.c:34:5: warning: suggest parentheses around ‘+’ inside ‘<<’ [-Wparentheses]
rock_tmp/./xorshift.c: In function ‘xorshift__xorgen_get32_impl’:
rock_tmp/./xorshift.c:46:37: error: expected expression before ‘if’
rock_tmp/./xorshift.c:42:26: warning: unused variable ‘tmp’ [-Wunused-variable]
rock_tmp/./xorshift.c:47:1: warning: control reaches end of non-void function [-Wreturn-type]
`