Bug 14352 – Two goto cases in one case branch does not work correctly

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-03-28T15:58:00Z
Last change time
2015-06-17T21:03:53Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
shammah.chancellor

Comments

Comment #0 by shammah.chancellor — 2015-03-28T15:58:48Z
This compiles and works properly under SDC. However, when ran against DMD the assertions fail. It appears as if "goto case" is not working correctly in DMD based on what I can see. ```test0075.d //T compiles:yes //T has-passed:yes //T retval:0 //? desc:Test goto case multiple cases in case list. int transmogrify(int input) { int output = 0; switch (input) { case 0, 1: if (input == 0) goto case; else output++; goto case; case 2: output += 5; goto case; case 3: output += 5; break; case 4, 5, 6: goto default; case 7: case 8: output += 20; break; default: return -1; } return output; } int main() { bool defaultRan = false; switch(0) { default: defaultRan = true; break; case 0: goto default; } assert(defaultRan); assert(transmogrify(0) == 10); assert(transmogrify(1) == 11); assert(transmogrify(2) == 10); assert(transmogrify(3) == 5); assert(transmogrify(7) == 20); assert(transmogrify(8) == 20); assert(transmogrify(4) == -1); assert(transmogrify(5) == -1); assert(transmogrify(6) == -1); assert(transmogrify(128) == -1); return 0; } ```
Comment #1 by ag0aep6g — 2015-03-28T16:33:46Z
Slight reduction of transmogrify(0): ---- void main() { int[] output; switch (0) { case 0: output ~= 0; goto case; goto case; case 1: output ~= 1; goto case; case 2: output ~= 2; break; case 3: output ~= 3; break; default: assert(false); } import std.stdio; writeln(output); } ---- Should print "[0, 1, 2]". Actually prints "[0, 1, 3]", meaning that it jumps from case 1 to case 3. Having more than one `goto case;` seems to confuse dmd.
Comment #2 by k.hara.pg — 2015-03-29T09:00:25Z
Comment #3 by github-bugzilla — 2015-03-29T10:26:17Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/e522feb89f080b489eade882bd204006df506cf5 fix Issue 14352 - Two goto cases in one case branch does not work correctly https://github.com/D-Programming-Language/dmd/commit/83a949937d2b74f2a15215c7306530a8a39ba2f9 Merge pull request #4531 from 9rnsr/fix14352 Issue 14352 - Two goto cases in one case branch does not work correctly
Comment #4 by github-bugzilla — 2015-06-17T21:03:53Z