www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17676] New: [REG 2.075] bad inlining of functions with

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

          Issue ID: 17676
           Summary: [REG 2.075] bad inlining of functions with multiple
                    return values
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: r.sagitario gmx.de

import core.stdc.stdio;

__gshared bool bgEnable = 1;

void smallAlloc() nothrow
{
    fullcollect();
}

size_t fullcollect() nothrow
{
    if(bgEnable)
       return fullcollectTrigger();

    return fullcollectNow();
}

size_t fullcollectNow() nothrow
{
    pragma(inline, false);
    printf("fullcollectNow\n");
    return 1;
}

size_t fullcollectTrigger() nothrow
{
    pragma(inline, false);
    printf("fullcollectTrigger\n");
    return 0;
}

void main()
{
    smallAlloc();
}

Without inlining, this just prints "fullcollectTrigger", while compiling with
-inline causes both messages to be printed.

The assembly of smallAlloc looks like this (dmd -O -inline -release):

_D7reg681510smallAllocFNbZv:
  0000000000000000: 55                 push        rbp
  0000000000000001: 48 8B EC           mov         rbp,rsp
  0000000000000004: 48 83 EC 20        sub         rsp,20h
  0000000000000008: 40 80 3D 00 00 00  cmp         byte ptr
[_D7reg68158bgEnableb],0
                    00 00
  0000000000000010: 74 05              je          0000000000000017
  0000000000000012: E8 00 00 00 00     call       
_D7reg681518fullcollectTriggerFNbZm
  0000000000000017: E8 00 00 00 00     call       
_D7reg681514fullcollectNowFNbZm
  000000000000001C: 48 8B E5           mov         rsp,rbp
  000000000000001F: 5D                 pop         rbp
  0000000000000020: C3                 ret


Note the missing jump between the two calls. If an "else" is inserted between
the two return statements in fullCollect(), it works correctly.

This doesn't happen with dmd 2.074. Introduced by
https://github.com/dlang/dmd/pull/6815

--
Jul 23 2017