Bug 13165 – Using -profile does extra control flow analysis, leading to spurious statement is not reachable warning

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-07-20T02:28:11Z
Last change time
2021-07-14T11:40:15Z
Keywords
pull
Assigned to
No Owner
Creator
sinkuupump

Comments

Comment #0 by sinkuupump — 2014-07-20T02:28:11Z
void main() { return; // Warning: statement is not reachable // (No location reported, but removing `return;` prevents this warning.) } Same warning with always true condition: void main() { if (true) return; } No warnings: void main(string[] args) { if (args) return; } int main() { return 0; } void myFunc() { return; } // happens only in void main()
Comment #1 by nick — 2014-11-07T18:38:31Z
I can't reproduce this with dmd 2.066.0.
Comment #2 by nick — 2014-11-07T18:39:42Z
Sorry, I can reproduce it with -profile.
Comment #3 by pro.mathias.lang — 2018-07-03T01:31:50Z
Renamed the issue, as an extra case was reported here: https://github.com/dlang/phobos/pull/6621#issuecomment-401980976 It seems the compiler is now able to propagate the fact that a function never returns, e.g.: ``` struct S { @trusted void error(string msg) { throw new Exception(""); } void fun2(){} void fun1() { error(""); fun2; } } ``` Leads to a warning.
Comment #4 by vitali.karabitski — 2018-08-01T07:44:27Z
Additional issue opened in vibe.d project, this time the generated warning leads to compilation failure https://github.com/vibe-d/vibe.d/issues/2193
Comment #5 by tobias — 2019-10-31T10:08:05Z
Also occurs when using pegged. Fails in std.regex.
Comment #6 by pro.mathias.lang — 2020-10-08T04:17:53Z
*** Issue 21297 has been marked as a duplicate of this issue. ***
Comment #7 by pro.mathias.lang — 2021-07-14T02:34:22Z
Comment #8 by bugzilla — 2021-07-14T08:05:02Z
This is caused by the compiler (helpfully) inserting a `return 0;` statement at the end of main() if there isn't one there already. Since the statement in some cases is not reachable, then the warning is emitted.
Comment #9 by dlang-bot — 2021-07-14T08:20:00Z
@WalterBright created dlang/dmd pull request #12873 "fix Issue 13165 - Using -profile does extra control flow analysis, le…" fixing this issue: - fix Issue 13165 - Using -profile does extra control flow analysis, leading to spurious statement is not reachable warning https://github.com/dlang/dmd/pull/12873
Comment #10 by bugzilla — 2021-07-14T08:32:38Z
-profile affects it because extra code is injected in glue.d to support profiling.
Comment #11 by dlang-bot — 2021-07-14T11:40:15Z
dlang/dmd pull request #12873 "fix Issue 13165 - Using -profile does extra control flow analysis, le…" was merged into master: - 32683fbad1daf2da3e1c9059f5fb447987affc1c by Walter Bright: fix Issue 13165 - Using -profile does extra control flow analysis, leading to spurious statement is not reachable warning https://github.com/dlang/dmd/pull/12873