Bug 18880 – [REG2.079] Miscompilation of unittests when two are mixed-in on one line

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-05-19T21:44:25Z
Last change time
2018-05-30T16:24:04Z
Assigned to
No Owner
Creator
johanengelen

Comments

Comment #0 by johanengelen — 2018-05-19T21:44:25Z
With the change to deterministic unittest function naming, this bug was introduced: When N unittests are mixed-in on the same line, the first one is run N times. Testcase: ``` mixin(genTest("666")); mixin(genTest("777")); int i; string genTest(string a) { return "unittest { i += " ~ a ~ "; }"; } void main() { // All unittests have been when we reach here. assert(i == 0 + 666 + 777); // Since 2.079 this passes! // assert(i == 0 + 666 + 666); } ``` fails with: dmd -unittest -run testcase.d since 2.079. It's caused by the naming of the unittest functions. The source location of the unittest is used in the name, but the source location inside mixins behaves strange: inside the mixin the linenumbers are offset with the line number of the mixin statement, but the column of the mixin statement is not reflected in Locs inside a mixin (only in the filename of the Loc). Thus only one function is made "...__unittest_L1_C1FZv" and it is called twice. (the second unittest gets the same name and is subsequently not codegenned because the symbol is already defined)
Comment #1 by johanengelen — 2018-05-19T21:53:06Z
Related issue discussing the mixin linecount problem: https://issues.dlang.org/show_bug.cgi?id=2887
Comment #2 by johanengelen — 2018-05-19T22:19:42Z
Things are worse: ``` static foreach(s; ["666", "777"]) { mixin(genTest(s)); } int i; string genTest(string a) { return "unittest { i += " ~ a ~ "; }"; } void main() { assert(i == 0 + 666 + 666); } ``` Thus: the exact source location is not necessarily unique and so an extra uniqueness factor is needed to generate the unittest function names. (note: must still be deterministic across separate compilations!)
Comment #3 by johanengelen — 2018-05-27T08:55:52Z
Comment #4 by bugzilla — 2018-05-28T21:49:26Z
(In reply to johanengelen from comment #3) > https://github.com/dlang/dmd/pull/8255 This was merged. Does it fix the issue?
Comment #5 by johanengelen — 2018-05-30T16:24:04Z
Yes, fixed by https://github.com/dlang/dmd/pull/8255 which adds a regression test for this bug.