D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17559 - [REG2.073.0] Wrong line number in stack trace
Summary: [REG2.073.0] Wrong line number in stack trace
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 regression
Assignee: No Owner
URL:
Keywords: DebugInfo, pull
Depends on:
Blocks:
 
Reported: 2017-06-26 17:13 UTC by Vladimir Panteleev
Modified: 2017-12-18 22:54 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vladimir Panteleev 2017-06-26 17:13:00 UTC
///////////// test.d /////////////
import mod;

void main()
{
    fun(1);
    fun(2);
    fun(3);
    fun(4);
}
////////////// mod.d /////////////
void fun(int n, int defParam = 10)
{
    assert(n != 4);
}
//////////////////////////////////

Test command: dmd -g test.d mod.d ; ./test 2>&1 | grep _Dmain
Output with 2.072.2: test.d:8 _Dmain [0x427dc7]
Output with 2.073.0: test.d:5 _Dmain [0x427d37]

The correct line number is 8, not 5.

Introduced in https://github.com/dlang/dmd/pull/6327
Comment 1 Rainer Schuetze 2017-06-26 17:56:52 UTC
Works alright on Windows. Anything special in mod.d or can it be omitted?
Comment 2 Vladimir Panteleev 2017-06-26 18:18:49 UTC
(In reply to Rainer Schuetze from comment #1)
> Works alright on Windows.

Linux x64 here.

> Anything special in mod.d or can it be omitted?

If fun is in the same file as main, the line number still changes between versions, but it points at the line containing fun's signature. That's not so bad - it's not useful but at least it's not misleading wrong, as when fun is in a separate module.
Comment 3 Rainer Schuetze 2017-06-26 21:43:23 UTC
Ok, I can reproduce it with Win64 if I remove the (bad) condition that disallows   decreasing line numbers.
Comment 4 Rainer Schuetze 2017-06-27 07:32:05 UTC
You get the same result without default parameters, too:

///////////// test.d /////////////
import mod;

void main()
{
    fun(1, 10);
    fun(2, 10);
    fun(3, 10);
    fun(4, 10);
}
////////////// mod.d /////////////
void fun(int n, int defParam)
{
    assert(n != 4);
}
//////////////////////////////////


The problem seems to be that the backend always performs common sub expression elimination, mapping all instances of "10" to the same expression instance and then emitting its location.

I suspect this exists since forever, but I haven't tried older versions yet.
Comment 5 Walter Bright 2017-06-28 22:22:55 UTC
This is not a regression. The code deleted by https://github.com/dlang/dmd/pull/6947 has been there for 30 years.
Comment 6 Vladimir Panteleev 2017-06-28 22:24:58 UTC
How do you define a regression? If something worked and now it doesn't work then it's a regression from the user's perspective. When latent bugs are exposed by some change or another, it doesn't matter how long said bugs were there.
Comment 7 Rainer Schuetze 2017-10-07 14:50:09 UTC
https://github.com/dlang/dmd/pull/6947
Comment 8 github-bugzilla 2017-11-18 06:51:49 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/127d639b6bbd82d1294da884a97de310e52985e0
fix issue 17559 - [REG2.073.0] Wrong line number in stack trace

only emit line number info for the first emission of common sub expressions

https://github.com/dlang/dmd/commit/c6a948b0bf11ce8a34d49614155507c1cb687484
Merge pull request #6947 from rainers/issue17559

fix issue 17559 - [REG2.073.0] Wrong line number in stack trace
Comment 9 github-bugzilla 2017-12-18 22:54:32 UTC
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/127d639b6bbd82d1294da884a97de310e52985e0
fix issue 17559 - [REG2.073.0] Wrong line number in stack trace

https://github.com/dlang/dmd/commit/c6a948b0bf11ce8a34d49614155507c1cb687484
Merge pull request #6947 from rainers/issue17559