diff options
| author | Yong He <yonghe@outlook.com> | 2017-12-28 06:53:19 -0500 |
|---|---|---|
| committer | Yong He <yonghe@outlook.com> | 2017-12-28 06:53:19 -0500 |
| commit | d46aeb030fa76854d2e7e64a25849b887defe4da (patch) | |
| tree | 73ea3653ef9b9c98b1bc286e904d037c77d63074 /tests | |
| parent | 57d9498b69b8c751f631e0097e6316d04bf2425b (diff) | |
Fix NameExprType returning deleted canonical type when it's in a generic parent.
fixes #339
`NamedExpressionType::CreateCanonicalType()` may return a deleted pointer. The original implementation is as follows:
```
Type* NamedExpressionType::CreateCanonicalType()
{
return GetType(declRef)->GetCanonicalType();
}
```
If `GetType()` returns a newly constructed Type (this happens when the `typedef` is defined inside a generic parent, which triggers a non-trivial substitution), the temporary type will be deleted when the function returns. The fix is to store the temporary type as a field of NamedExpressionType (`innerType`).
A relevant fix (though not the true cause of issue #339) is to have `Type::GetCanonicalType()` also hold a `RefPtr` to the constructed canonical type, when the canonical type is not `this`. This prevents a returned canonical type being assigned to a RefPtr, which makes it possible for that RefPtr to be the sole owner of the canonical type and deleteing the canonical type when that RefPtr is destroyed.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compute/typedef-member.slang | 38 | ||||
| -rw-r--r-- | tests/compute/typedef-member.slang.expected.txt | 4 |
2 files changed, 42 insertions, 0 deletions
diff --git a/tests/compute/typedef-member.slang b/tests/compute/typedef-member.slang new file mode 100644 index 000000000..dbf4dcdc1 --- /dev/null +++ b/tests/compute/typedef-member.slang @@ -0,0 +1,38 @@ +//TEST(compute):COMPARE_COMPUTE:-xslang -use-ir +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out + +// Confirm that a struct type defined in a generic parent works + +RWStructuredBuffer<float> outputBuffer; + +struct SubType<T> +{ + T x; +}; + +struct GenStruct<T> +{ + typedef SubType<T> SubTypeT; + T getVal(SubTypeT v) + { + return v.x; + } +}; + +float test(float val) +{ + GenStruct<float>.SubTypeT sb; + sb.x = val; + GenStruct<float> obj; + return obj.getVal(sb); +} + + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + float inVal = float(tid); + float outVal = test(inVal); + outputBuffer[tid] = outVal.x; +}
\ No newline at end of file diff --git a/tests/compute/typedef-member.slang.expected.txt b/tests/compute/typedef-member.slang.expected.txt new file mode 100644 index 000000000..98798bd61 --- /dev/null +++ b/tests/compute/typedef-member.slang.expected.txt @@ -0,0 +1,4 @@ +0 +3F800000 +40000000 +40400000
\ No newline at end of file |
