laurentlb / shader-minifier

Minify and obfuscate GLSL or HLSL code

Home Page:https://ctrl-alt-test.fr/minifier/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Some ternary expressions are minified incorrectly

LeStahL opened this issue · comments

I stumbled onto a problem with some ternary expressions containing assignments:

#version 450

out vec4 out_color;

void main() {
    float a = 1., b = 1., E = 5., t = 1.;
    ( E < 0.0 ) ? a = t : b = t;
}

gets minified to

#version 450
out vec4 m;void main(){1.=1.;}

which produces a compilation error because of the literal assignment to a literal.

nr4@BEEFY-HARDWARE:~/code$ glslangValidator minifierbug.min.frag 
minifierbug.min.frag
ERROR: 0:2: 'assign' :  l-value required (can't modify a const)
ERROR: 0:2: '' : compilation terminated 
ERROR: 2 compilation errors.  No code generated.

This workaround solved it for me:

#version 450

out vec4 out_color;

void main() {
    float a = 1., b = 1., E = 5., t = 1.;
    ( E < 0.0 ) ? (a = t) : (b = t);
}

gets minified correctly to

#version 450
out vec4 m;void main(){float m=1.;m=1.;}

Thanks for the detailed report. It's a bug in the parser.

The line is parsed as:

(E < 0.0 ? a = t : b) = t;

So adding extra parentheses is a good workaround.