Bug 11612 – Inconsistent error on negative new array size

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-11-26T18:52:17Z
Last change time
2024-02-10T12:10:24Z
Keywords
accepts-invalid, bootcamp, pull
Assigned to
No Owner
Creator
yebblies
See also
https://issues.dlang.org/show_bug.cgi?id=24377

Comments

Comment #0 by yebblies — 2013-11-26T18:52:17Z
This program void main() { auto x = new int[-1]; } compiles with no error with -m32, but with -m64 gives this error: testx.d(4): Error: negative array index 18446744073709551615LU This should behave the same on both platforms, one way or the other
Comment #1 by andrej.mitrovich — 2014-04-19T13:41:02Z
The change introducing this seems to date 0.72, it's something ancient: ----- commit 0ad54c6d37b62631d48d452dfb06bb9a932ceb96 Author: Brad Roberts <[email protected]> Date: Thu Jul 2 07:08:34 2009 +0000 dmd 0.72 ----- I think it's fair to change this.
Comment #2 by andrej.mitrovich — 2014-04-19T14:11:47Z
Actually nevermind my last comment. AFAICT an IntegerExp ends up having type->ty equal Tuns32 instead of Tint32. From the callstack it seems IntegerExp is constructed with this from one of these calls: 011ee64c 004dfbd4 image00400000!IntegerExp::IntegerExp+0x54 [C:\dmd-git\dmd2\src\dmd\src\expression.c @ 2592] 011ee708 004c4404 image00400000!Neg+0x1ad [C:\dmd-git\dmd2\src\dmd\src\constfold.c @ 88] 011ee738 00481c75 image00400000!OptimizeVisitor::visit+0x54 [C:\dmd-git\dmd2\src\dmd\src\optimize.c @ 263] 011ee748 004c217f image00400000!NegExp::accept+0x15 [C:\dmd-git\dmd2\src\dmd\src\expression.h @ 976] 011ee77c 004b4855 image00400000!Expression_optimize+0x41 [C:\dmd-git\dmd2\src\dmd\src\optimize.c @ 1224] 011ee83c 00425e29 image00400000!ImplicitConvTo::visit+0x65 [C:\dmd-git\dmd2\src\dmd\src\cast.c @ 181] 011ee84c 00425c85 image00400000!Visitor::visit+0x15 [C:\dmd-git\dmd2\src\dmd\src\visitor.h @ 541] 011ee85c 00481c75 image00400000!Visitor::visit+0x15 [C:\dmd-git\dmd2\src\dmd\src\visitor.h @ 541] 011ee86c 004aff6b image00400000!NegExp::accept+0x15 [C:\dmd-git\dmd2\src\dmd\src\expression.h @ 976] 011ee894 004b275b image00400000!implicitConvTo+0x39 [C:\dmd-git\dmd2\src\dmd\src\cast.c @ 1222] 011ee8e8 00425e29 image00400000!ImplicitCastTo::visit+0x1f [C:\dmd-git\dmd2\src\dmd\src\cast.c @ 54] 011ee8f8 00425c85 image00400000!Visitor::visit+0x15 [C:\dmd-git\dmd2\src\dmd\src\visitor.h @ 541] 011ee908 00481c75 image00400000!Visitor::visit+0x15 [C:\dmd-git\dmd2\src\dmd\src\visitor.h @ 541] 011ee918 004aff2b image00400000!NegExp::accept+0x15 [C:\dmd-git\dmd2\src\dmd\src\expression.h @ 976] 011ee94c 00468267 image00400000!implicitCastTo+0x43 [C:\dmd-git\dmd2\src\dmd\src\cast.c @ 145] 011eeb8c 004c8b2b image00400000!NewExp::semantic+0x1378 [C:\dmd-git\dmd2\src\dmd\src\expression.c @ 5122] 011eebc4 0049448a image00400000!ExpInitializer::inferType+0x1c [C:\dmd-git\dmd2\src\dmd\src\init.c @ 920] 011eef0c 00469e65 image00400000!VarDeclaration::semantic+0x21e [C:\dmd-git\dmd2\src\dmd\src\declaration.c @ 857] 011eef60 004c973e image00400000!DeclarationExp::semantic+0xa3 [C:\dmd-git\dmd2\src\dmd\src\expression.c @ 5858] I guess I could just emit an error in NewExp::semantic or something, we'll see..
Comment #3 by dlang-bugzilla — 2017-07-07T16:04:38Z
Marking this as accepts-invalid because, ideally, we want to reject all negative integer literals where they don't belong, before their conversion to size_t.
Comment #4 by dlang-bot — 2023-06-27T16:42:16Z
@ntrel created dlang/dmd pull request #15359 "Fix Issue 11612 - Inconsistent error on negative new array size" fixing this issue: - Fix Issue 11612 - Inconsistent error on negative new array size https://github.com/dlang/dmd/pull/15359
Comment #5 by dlang-bot — 2023-06-28T07:20:50Z
dlang/dmd pull request #15359 "Fix Issue 11612 - Inconsistent error on negative new array size" was merged into master: - b02ed4b9c759fbc1b4fee9a4a0cc7d00095792ce by Nick Treleaven: Fix Issue 11612 - Inconsistent error on negative new array size https://github.com/dlang/dmd/pull/15359