digitalmars.D.bugs - [Issue 6306] New: [CTFE] Strange behavior of indirect recursive call in CTFE
- d-bugmail puremagic.com (82/82) Jul 13 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6306
- d-bugmail puremagic.com (25/25) Jul 27 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6306
- d-bugmail puremagic.com (12/12) Jul 27 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6306
- d-bugmail puremagic.com (13/13) Jul 31 2011 http://d.puremagic.com/issues/show_bug.cgi?id=6306
http://d.puremagic.com/issues/show_bug.cgi?id=6306 Summary: [CTFE] Strange behavior of indirect recursive call in CTFE Product: D Version: D2 Platform: x86 OS/Version: Windows Status: NEW Severity: critical Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: youxkei gmail.com --- Comment #0 from Hisayuki Mima <youxkei gmail.com> 2011-07-13 02:06:02 PDT --- void main(){} struct Result{bool match; string value; string rest;} Result paren(string input){ if(input[0] == '('){ input = input[1..$]; }else{ return Result(false, "", input); } string[] strs; while(true){ Result r = function(string input){ Result r = paren(input); if(r.match){ return r; } if(input[0] == ')'){ return Result(false, "", input); }else{ return Result(true, input[0..1], input[1..$]); } }(input); if(r.match){ strs = strs ~ r.value; input = r.rest; }else{ break; } } if(input[0] == ')'){ input = input[1..$]; }else{ return Result(false, "", input); } string value = "("; foreach(str; strs){ value = value ~ str; } value = value ~ ")"; return Result(true, value, input); } bool test(){//unittest auto r = paren("((a))"); assert(r.match); assert(r.rest == ""); assert(r.value == "((a))"); //assertion1 return true; } unittest{ static assert(test()); //line1 test(); } This code cannot be compiled by dmd v2.054 because the assertion1, which is the compile-time assertion, fails. (Incidentally, r.value is "(a(a))" at assertion1.) However, dmd v2.052 can compile this code well. When I commented out the line 1, the code became able to be compiled dmd v2.054 and the run-time unittest succeeded. The function paren is a function which parses string in balanced-parentheses and returns parsed string. It has indirect recursive call or it calls a function which calls it. When I rewrote the code as a code which has direct recursive call, the code the code became able to be compiled dmd v2.054 and the run-time unittest succeeded, too. This is why I think indirect recursive call has strange behavior and it causes the assertion1 to fail. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 13 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6306 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |wrong-code CC| |clugdbug yahoo.com.au --- Comment #1 from Don <clugdbug yahoo.com.au> 2011-07-27 00:25:42 PDT --- Reduced test case shows this is very nasty bug in failing to restore local variable values after an indirect recursive call. ------------- void recurse6306() { bug6306(false); } bool bug6306(bool b) { int x = 0; if (b) recurse6306(); assert(x == 0); // fails!!!!! x = 1; return true; } static assert( bug6306(true) ); -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 27 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6306 Don <clugdbug yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|[CTFE] Strange behavior of |Regression(2.054): [CTFE] |indirect recursive call in |Strange behavior of |CTFE |indirect recursive call in | |CTFE Severity|critical |regression -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 27 2011
http://d.puremagic.com/issues/show_bug.cgi?id=6306 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |bugzilla digitalmars.com Resolution| |FIXED --- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2011-07-31 12:08:56 PDT --- https://github.com/D-Programming-Language/dmd/commit/7ef3b2bb9e740df39108957ae5e3b2aa8253d351 https://github.com/D-Programming-Language/dmd/pull/284 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 31 2011