digitalmars.D.bugs - [Issue 11510] New: Relax restriction for overlapped pointer field access in safe code/during CTFE
- d-bugmail puremagic.com (66/66) Nov 13 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11510
- d-bugmail puremagic.com (7/9) Nov 13 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11510
- d-bugmail puremagic.com (10/10) Nov 13 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11510
- d-bugmail puremagic.com (15/15) Dec 16 2013 https://d.puremagic.com/issues/show_bug.cgi?id=11510
- d-bugmail puremagic.com (10/10) Jan 14 2014 https://d.puremagic.com/issues/show_bug.cgi?id=11510
https://d.puremagic.com/issues/show_bug.cgi?id=11510 Summary: Relax restriction for overlapped pointer field access in safe code/during CTFE Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: CTFE, spec Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: k.hara.pg gmail.com Currently in safe code, declaring struct variable which contains any overlapped pointer(==reference) fields is entirely disallowed. struct S { union { size_t x; int* y; // pointer field } int[] arr; } // This is necessary to avoid related compiler bug S _dummy = S(); void test() safe { S s; // Error: variable s unions containing pointers are not allowed // in safe functions } However I think this is too limited behavior. Even if S.y is an overlapped pointer field, 1. Declaring a variable typed S 2. Both reading and writing unoverlapped field S.arr 3. Both reading and writing overlapped field S.x 4. Writing overlapped pointer field S.y should be allowed. the safe code. But it is nothing wrong, as same as declaring size_t variable with void initializer. void test() safe { size_t num = void; } Even the value of 'num' is garbage, using it won't cause any memory corruption in safe. So currently it is properly accepted by compiler. --- And the semantics should also work during CTFE. For CTFE, one following restriction is necessary. - Any field value reinterpretation by using two overlapped fields is disallowed. If it's detected in CTFE, should raise compile-time error. Therefore, following code should work as expected. bool test() { S s; // declaration is OK s.y = [1,2,3].ptr; // writing overlapped pointer field is OK assert(s.y[0..3] == [1,2,3]); // reading valid field is OK s.x = 10; assert(s.x == 10); // There's no reinterpretation between S.x and S.y return true; } static assert(test()); // run CTFE -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 13 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11510// This is necessary to avoid related compiler bug S _dummy = S();The "related bug" is bug 11427. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 13 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11510 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull https://github.com/D-Programming-Language/dmd/pull/2757 -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 13 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11510 Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/a2932981ee03abe13e9fdacf07ad29d162fc4b16 fix Issue 11510 - Relax restriction for overlapped pointer field access in safe code/during CTFE Check overlapped field default initializations immediately after the struct size is determined. https://github.com/D-Programming-Language/dmd/commit/475c5437525d759891be381961c076d2e1dc3e2b Issue 11510 - Relax restriction for overlapped pointer field access in safe code/during CTFE -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 16 2013
https://d.puremagic.com/issues/show_bug.cgi?id=11510 Kenji Hara <k.hara.pg gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jmdavisProg gmx.com *** Issue 10035 has been marked as a duplicate of this issue. *** -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 14 2014