diff options
| author | T. Foley <tfoleyNV@users.noreply.github.com> | 2021-05-27 13:40:17 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-27 13:40:17 -0700 |
| commit | 63dcc7acf4784d95407866730a70f5d37d391b88 (patch) | |
| tree | 58cf716422ba5842a5a06230509a5d83eb370f4f /tests/language-feature | |
| parent | 15f5cffc3026a5faed7046ae7d75ec6b56cf4a4c (diff) | |
Fix a bug in struct inheritance (#1861)
During lowering from AST to IR, the Slang compiler translates code that uses `struct` inheritance:
```hlsl
struct Base { int a; }
struct Derived : Base {}
```
into code where the inheritance relationship is "witnessed" by a simple field:
```hlsl
struct Base { int a; }
struct Derived { Base __anonymous_field__; }
```
The underlying bug here is that the `__anonymous_field__` that the compiler generated during IR lowering was not being given any linkage decorations (no mangled name). As a result, if multiple separately-compiled modules all access that field they could disagree on its identity as an IR instruction. This could lead to output code being generated where the declaration of `__anonymous_field__` uses one IR instruction, but accesses use another.
This change includes a fix for the issue, and a test that serves as a reproducer for the original problem.
Diffstat (limited to 'tests/language-feature')
3 files changed, 44 insertions, 0 deletions
diff --git a/tests/language-feature/inheritance/struct-inheritance-import.slang b/tests/language-feature/inheritance/struct-inheritance-import.slang new file mode 100644 index 000000000..0ea49957e --- /dev/null +++ b/tests/language-feature/inheritance/struct-inheritance-import.slang @@ -0,0 +1,28 @@ +// struct-inheritance-import.slang + +//TEST(compute):COMPARE_COMPUTE: + +// This test confirms that the synthesized code for struct type inheritance +// includes proper linkage decorations so that it can work across modules. + +import struct_inheritance_imported; + +int test(int val) +{ + Derived d; + d.a = val; + + return 0x100 + d.a*0x10 + getA(d); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + int inVal = tid; + int outVal = test(inVal); + outputBuffer[tid] = outVal; +} diff --git a/tests/language-feature/inheritance/struct-inheritance-import.slang.expected.txt b/tests/language-feature/inheritance/struct-inheritance-import.slang.expected.txt new file mode 100644 index 000000000..60d3d339d --- /dev/null +++ b/tests/language-feature/inheritance/struct-inheritance-import.slang.expected.txt @@ -0,0 +1,4 @@ +100 +111 +122 +133 diff --git a/tests/language-feature/inheritance/struct-inheritance-imported.slang b/tests/language-feature/inheritance/struct-inheritance-imported.slang new file mode 100644 index 000000000..8786b851c --- /dev/null +++ b/tests/language-feature/inheritance/struct-inheritance-imported.slang @@ -0,0 +1,12 @@ +//TEST_IGNORE_FILE: +// struct-inheritance-imported.slang + +struct Base +{ + int a; +} + +struct Derived : Base +{} + +int getA(Derived d) { return d.a; } |
