[Issue 21471] Backend assertion triggered with `-checkation=context` and `-inline`

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 31 14:41:50 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21471

moonlightsentinel at disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |moonlightsentinel at disroot.o
                   |                            |rg

--- Comment #1 from moonlightsentinel at disroot.org ---
Another self-contained example (without druntime & explicit -inline):

============= object.d =================

void main()
{
    auto c = 0;
    assert(isClose(c, exp(1)));
}

pragma(inline, true)
real exp(real x) pure nothrow
{
    return x;
}

bool isClose(int lhs, real rhs) pure nothrow
{
    return false;
}

alias string = immutable(char)[];
string _d_assert_fail(A)(string, A);

===========================================

The assertion failure depends on three things:
1. generate debug infos (-g)
2. inlined function call as a paramter
3. node side effects => no temporary

For example:

assert(isClose(c, exp(1)));

is rewritten to

assert(isClose(c, exp(1)), _d_assert_fail!bool("", isClose(c, exp(1)));

and inlined to

assert(isClose(c, ((real x = 1.0L;) , x), 0), _d_assert_fail("", isClose(c,
((real x = 1.0L;) , x), 0)));

The problem are the two temporaries x, inserting the second x into the debug
info triggers the assertion failure.
Debug generation fails only for `-checkaction=context`, manually compiling the
lowered expression suceeds without errors.

This indicates that the failure is caused by -checkaction=context re-using the
same AST node for the call to _d_assert_fail.
Copying the CallExp resolves this issue (not sure if that is the best
solution).

--


More information about the Digitalmars-d-bugs mailing list