Bug 15585 – VRP incorrectly assumes that out-of-range dchar values don't exist

Status
NEW
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-01-20T19:37:13Z
Last change time
2024-12-13T18:46:37Z
Assigned to
No Owner
Creator
thomas.bockman
Moved to GitHub: dmd#19092 →

Comments

Comment #0 by thomas.bockman — 2016-01-20T19:37:13Z
This issue doesn't currently have much in the way of visible symptoms, but it will as VRP gets smarter in other ways: https://github.com/D-Programming-Language/dmd/pull/5229 Fixing this was been pre-approved by Walter Bright on the forums (although there are other aspects of the above PR which are still under review): http://forum.dlang.org/post/[email protected]
Comment #1 by hsteoh — 2016-01-20T20:29:56Z
Actually, it *does* already cause a very visible, nasty problem: https://issues.dlang.org/show_bug.cgi?id=15586 Basically, by assuming that dchar can never have invalid values (no matter where the dchar came from), the compiler has basically turned all code containing `cast(dchar)` into undefined behaviour, because it will optimize out all character range checks (under its wrong assumption, none of the checks can ever fail, since dchar can't possibly have invalid values). This means string-vetting functions are basically turned to no-ops, and code that's supposed to throw exceptions or assert errors upon invalid dchar values will instead continue running wildly forward. This could mean that a function that's supposed to return something may actually return nothing, and the caller will get a garbage value instead (from whatever detritus is left in the return register when it was last modified). These problems are already showing up, even in non-release mode. I'm raising the severity of this bug.
Comment #2 by andrei — 2016-10-12T15:50:50Z
Thomas, do you have a code sample that illustrates the problem?
Comment #3 by thomas.bockman — 2016-10-12T16:46:00Z
(In reply to Andrei Alexandrescu from comment #2) > Thomas, do you have a code sample that illustrates the problem? Sorry; I linked you to this issue by accident. Issue 14835 is the blocker that I mentioned. That said... bool isValidDChar(dchar cp) { if (cp > dchar.max) return false; else return true; } The compiler automatically assumes that (cp <= dchar.max), always. So, *IF* VRP propagated to comparisons, this function would be "optimized" to always return true - which it should not, because it's quite easy to generate dchar values that are greater than dchar.max, even in valid code. However, VRP isn't currently used for compile-time evaluation of comparisons, so there is (to my knowledge) no way to trigger this issue without my VRP upgrade PR ( https://github.com/dlang/dmd/pull/5229 ). It's a non-issue; the latest version of that PR already includes the fix for this, so no-one but me should ever be bothered by it, I hope.
Comment #4 by andrei — 2016-10-12T16:49:27Z
great, thx
Comment #5 by robert.schadek — 2024-12-13T18:46:37Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19092 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB