diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-10-11 11:17:40 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-11 11:17:40 -0700 |
| commit | 13c6b69cc2601ff4764f095fb45ad9573d34ff2f (patch) | |
| tree | 4ec7fbf824e81504db5a2b07e162d58ca394c84b /tests | |
| parent | dcd9f78b972a4b7b88e9c3403bd1e887d628b40a (diff) | |
Fix error when one constant is defined equal to another (#670)
* Fix error when one constant is defined equal to another
Fixes #666
When a user declares one constant (usually a `static const` variable) to be exactly equal to another by name:
```hlsl
static const a = 999;
static const b = a;
```
Then the IR-level representation of `b` is an `IRGlobalConstant` whose value expression is just a pointer to the definition of `a`.
The logic in `emitIRGlobalConstantInitializer()` was trying to always call `emitIRInstExpr` to emit the value of the constant as an expression, but that function only handles complex/compound expressions and not the case of simple named values (e.g., constants like `a`).
The intention is for code to call `emitIROperand()` instead, and let it decide whether to emit an expression or a named reference using its own decision-making. The `IRGlobalConstant` case really just wants to pass in the "mode" flag it uses to influence that decision-making, but shouldn't be working around it.
This change just replaces the `emitIRInstExp()` call with `emitIROpernad()` and adds a test case to confirm that this fixes the reported problem.
* Fixups for bugs in previous change
The first problem was that certain instruction ops were being special-cased to opt out of "folding" into expressions *before* we make the universal check to always fold when inside an initializer for a global constant.
The second problem is that the `emitIROperand()` logic was always putting expressions around sub-expressions, which breaks parsing when the sub-expression is an initializer list (`{...}`). This fixup is pretty much a hack, but will be something we can remove once we don't emit unncessary parentheses overall, which is a better fix.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/bugs/gh-666.slang | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/bugs/gh-666.slang b/tests/bugs/gh-666.slang new file mode 100644 index 000000000..fa46d1de7 --- /dev/null +++ b/tests/bugs/gh-666.slang @@ -0,0 +1,11 @@ +// gh-666.slang + +//TEST:COMPARE_HLSL:-no-mangle -profile ps_5_0 -entry main + +static const uint foo = 1; +static const uint bar = foo; + +float4 main() : SV_TARGET +{ + return bar; +} |
