Bug 11049 – array bounds error uses module file name rather than file name modified by #line directive

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-09-15T22:45:05Z
Last change time
2020-09-23T02:17:28Z
Keywords
backend, pull, wrong-code
Assigned to
No Owner
Creator
Kenji Hara

Comments

Comment #0 by k.hara.pg — 2013-09-15T22:45:05Z
This test case cannot pass assertions. void main() { int[] arr = [1,2,3]; #line 100 "foo" try { auto n = arr[3]; } catch (Error e) { assert(e.file == "foo"); // fails assert(e.line == 100); } #line 200 "bar" try { auto a = arr[3..9]; } catch (Error e) { assert(e.file == "bar"); // fails assert(e.line == 200); } }
Comment #1 by k.hara.pg — 2013-09-15T23:25:57Z
Comment #2 by schveiguy — 2019-11-23T02:41:02Z
Just ran into this today. Removing the pull description because even though the PR was pulled, this is not fixed, not sure what happened.
Comment #3 by schveiguy — 2019-11-23T02:42:09Z
I'll note this is important to fix, as vibe.d is a showcase project of D, and diet templates use #line to help diagnose issues with diet templates.
Comment #4 by bugzilla — 2020-08-09T10:03:14Z
This is apparently caused by the code in e2ir.d: elem *buildArrayBoundsError(IRState *irs, const ref Loc loc) { if (irs.params.checkAction == CHECKACTION.C) { return callCAssert(irs, loc, null, null, "array overflow"); } if (irs.params.checkAction == CHECKACTION.halt) { return genHalt(loc); } auto eassert = el_var(getRtlsym(RTLSYM_DARRAYP)); auto efile = toEfilenamePtr(cast(Module)irs.blx._module); *** auto eline = el_long(TYint, loc.linnum); return el_bin(OPcall, TYvoid, eassert, el_param(eline, efile)); } Note that it gets the filename from _module rather than loc. I believe it is this way to stop the redundant generation of filename strings into the object file. The previous function filelineFunction() gets it fro the loc.
Comment #5 by dlang-bot — 2020-09-16T09:35:26Z
@WalterBright created dlang/dmd pull request #11741 "fix Issue 11049 - array bounds error uses module file name rather tha…" fixing this issue: - fix Issue 11049 - array bounds error uses module file name rather than file name modified by #line directive https://github.com/dlang/dmd/pull/11741
Comment #6 by dlang-bot — 2020-09-23T02:17:28Z
dlang/dmd pull request #11741 "fix Issue 11049 - array bounds error uses module file name rather tha…" was merged into master: - 26d0f3557d125b2ec43ead7b61e08d855fc12751 by Walter Bright: fix Issue 11049 - array bounds error uses module file name rather than file name modified by #line directive https://github.com/dlang/dmd/pull/11741