skia2/tests/sksl/inliner/golden/InlinerAvoidsVariableNameOverlap.glsl
John Stiles 8f026259d8 Demonstrate name reuse error in inliner.
The following conditions lead to the error:
- A pair of nested functions, both of which must be inlined.
- Both inlined functions create a variable with the same name.
- The outer function passes its variable to the inner function.
- The initialization of the inner variable uses the value from the outer
  variable.
- The inner function does not mutate the variable, use it as an out-
  parameter, or otherwise cause it to receive a temporary copy.

When all these conditions are met, both variable declarations are
inlined as-is without performing any name salting, because it's
seemingly safe to do so. The name overlap issue is not considered in the
safety checks. Inlined variable declarations are not subject to name
salting but they should be; I suspect other adversarial examples could
be crafted as well where unhandled name overlap leads to errors.

Change-Id: Ia754bee8e45c8a5c7548436594bbf04abc7a8396
Bug: skia:10722
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/316945
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-09-15 13:03:22 +00:00

22 lines
415 B
GLSL

precision mediump float;
precision mediump sampler2D;
in mediump vec2 x;
mediump vec4 main() {
mediump vec2 _1_InlineA;
{
mediump vec2 reusedName = x + vec2(1.0, 2.0);
mediump vec2 _0_InlineB;
{
mediump vec2 reusedName = reusedName + vec2(3.0, 4.0);
_0_InlineB = reusedName;
}
_1_InlineA = _0_InlineB;
}
return _1_InlineA.xyxy;
}