From d3e255b31b39c9a8979a60023269567078d9dce3 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 15 Oct 2020 13:13:49 -0700 Subject: Fix a bug in IR lowering (#1578) The basic problem here is that when a function has multiple declarations with matching signatures (e.g., a forward declaration and then a later definition with a body), the IR lowering logic would lower all declarations whenever the first one was encountered, but then would only register an IR value as the lowered version of the first declaration. Other matching declarations would then run the risk of being lowered again, and in the case where they included features like loops with break/continue labels, that would create the risk of keys getting inserted into certain dictionaries more than one, leading to exceptions. This change ensures that when lowering a function that has multiple matching declarations to IR, we register an IR value for all of those declarations and not just the first. I have added a test case that leads to a crash without this change, to ensure that we don't introduce a regression down the line. --- tests/bugs/multiple-definitions.slang | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/bugs/multiple-definitions.slang (limited to 'tests') diff --git a/tests/bugs/multiple-definitions.slang b/tests/bugs/multiple-definitions.slang new file mode 100644 index 000000000..5361c97bc --- /dev/null +++ b/tests/bugs/multiple-definitions.slang @@ -0,0 +1,22 @@ +// multiple-definitions.slang +//TEST:SIMPLE:-entry main -o multiple-definitions.hlsl + +__specialized_for_target(hlsl) +int a(int x) +{ + int r = 0; + for(int i = 0; i < x; ++i) ++r; + return r; +} + +__specialized_for_target(glsl) +int a(int x) +{ + int r = 0; + for(int i = 0; i < x; ++i) ++r; + return r; +} + +[shader("compute")] +void main() +{} -- cgit v1.2.3