From 935b629448fedc187243bfe88d4149bf30d89c05 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 23 Jan 2019 09:13:03 -0800 Subject: Fix IR emit logic for methods in `struct` types (#791) There was a bug in the logic for emitting initial IR, such that it was neglecting to emit "methods" (member functions) unless they were also referenced by a non-member (global) function, or were needed to satisfy an interface requirement. This would only matter for `import`ed modules, since for non-`import`ed code, anything relevant would be referenced by the entry point so that the problem would never surface. This change fixes the underlying problem by adding a step to the IR lowering pass called `ensureAllDeclsRec` that makes sure that not only global-scope declarations, but also anything nested under a `struct` type gets emitted to the initial IR module. There are also a few unrelated fixes in this PR, which are things I ran into while making the fix: * Deleted support for the (long gone) `IRDeclRef` type in our `slang.natvis` file * Added support for visualizing the value of IR string and integer literals when they appear in the debugger * Fixed IR dumping logic to not skip emitting `struct` and `interface` instructions. Switching those to inherit from `IRType` accidentally affected how they get printed in IR dumps by default. * Fixed up the IR linking logic so that it correctly takes `[export]` decorations into account, so that an exported definition will always be taken over any other (unless the latter is more specialized for the target). I initially implemented this in an attempt to fix the original issue, but found it wasn't a fix for the root cause. It is still a better approach than what was implemented previously, so I'm leaving it in place. --- tests/bugs/gl-33-ext.slang | 8 ++++++++ tests/bugs/gl-33.slang | 28 ++++++++++++++++++++++++++++ tests/bugs/gl-33.slang.expected.txt | 4 ++++ 3 files changed, 40 insertions(+) create mode 100644 tests/bugs/gl-33-ext.slang create mode 100644 tests/bugs/gl-33.slang create mode 100644 tests/bugs/gl-33.slang.expected.txt (limited to 'tests') diff --git a/tests/bugs/gl-33-ext.slang b/tests/bugs/gl-33-ext.slang new file mode 100644 index 000000000..ae70cfaf0 --- /dev/null +++ b/tests/bugs/gl-33-ext.slang @@ -0,0 +1,8 @@ +// gl-33-ext.slang +//TEST_IGNORE_FILE: + +struct A +{ + int state; + [mutating] int next() { return state; } +}; diff --git a/tests/bugs/gl-33.slang b/tests/bugs/gl-33.slang new file mode 100644 index 000000000..89cfa0aad --- /dev/null +++ b/tests/bugs/gl-33.slang @@ -0,0 +1,28 @@ +// gl-33.slang +//TEST(compute):COMPARE_COMPUTE: + +// Test for GitLab issue # 33 + +import gl_33_ext; + +typedef A B; + +int test(int val) +{ + B b = { val }; + return b.next(); +} + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out +RWStructuredBuffer gBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + + int val = tid; + val = test(val); + + gBuffer[tid] = val; +} diff --git a/tests/bugs/gl-33.slang.expected.txt b/tests/bugs/gl-33.slang.expected.txt new file mode 100644 index 000000000..bc856dafa --- /dev/null +++ b/tests/bugs/gl-33.slang.expected.txt @@ -0,0 +1,4 @@ +0 +1 +2 +3 -- cgit v1.2.3