[Issue 18461] core.bitop.bt returns garbage in release code

2018-02-21 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18461

Ketmar Dark  changed:

   What|Removed |Added

 CC||ket...@ketmar.no-ip.org

--


[Issue 18461] core.bitop.bt returns garbage in release code

2018-02-20 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18461

bitter.ta...@gmx.com changed:

   What|Removed |Added

 CC||bitter.ta...@gmx.com
  Component|phobos  |dmd

--- Comment #9 from bitter.ta...@gmx.com ---
This is a (major?) codegen bug in dmd, the joint action of -inline and -release
makes the rmdeadass kill the `test_val' definition and fold the argument `p' of
the `bt' function into `_val': that's right, the variable is gone but the
reference to it is still there, leading to the generation of the silly `lea'
instruction pointing into the stack.

Some more details for the lovers of the gory details:

```
ambiguous lvalue: test_val(0) =  16LL 
assnod[0]: test_val(0) =  16LL 
POSS
DEAD=0, live=0
dead assignment (test_val(0) =  16LL ) Boutlv
elimass
el:0x55687ec1d360 cnt=0 =  TYuns long long 0x55687ec1d170 0x55687ec1d300
 el:0x55687ec1d170 cnt=0 var  TYuns long long  test_val
 el:0x55687ec1d300 cnt=0 const  TYuns long long 16LL 
assnod[1]: p(1) =  #test_val(0)
POSS
DEAD=0, live=0
dead assignment (p(1) =  #test_val(0)) Boutlv
elimass
el:0x55687ec1d9f0 cnt=0 =  mTYconst|TY* 0x55687ec1d810 0x55687ec1d8d0
 el:0x55687ec1d810 cnt=0 var  mTYconst|TY*  p
 el:0x55687ec1d8d0 cnt=0 relconst  TY*  0+& test_val
assnod[2]: bitnum(2) =  4LL 
POSS
DEAD=0, live=0
dead assignment (bitnum(2) =  4LL ) Boutlv
elimass
el:0x55687ec1dcc0 cnt=0 =  TYuns long long 0x55687ec1dba0 0x55687ec1dc60
 el:0x55687ec1dba0 cnt=0 var  TYuns long long  bitnum
 el:0x55687ec1dc60 cnt=0 const  TYuns long long 4LL 
```

If I understand correctly what's going on the variables are killed even though
they're not dead because they don't escape the block (they're not in Boutlv).

--


[Issue 18461] core.bitop.bt returns garbage in release code

2018-02-18 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18461

feklushkin.de...@gmail.com changed:

   What|Removed |Added

   Keywords|wrong-code  |
  Component|dmd |phobos

--- Comment #8 from feklushkin.de...@gmail.com ---
> Tried it 100x times without any change:

Reproduceable if -O and -inline switches used both

--


[Issue 18461] core.bitop.bt returns garbage in release code

2018-02-18 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18461

ag0ae...@gmail.com changed:

   What|Removed |Added

   Keywords||wrong-code
  Component|phobos  |dmd

--- Comment #7 from ag0ae...@gmail.com ---
Good code generated with `-O -inline` (no `-release`):


 <_Dmain>:
   0:   55  push   rbp
   1:   48 8b ecmovrbp,rsp
   4:   48 83 ec 10 subrsp,0x10
   8:   48 c7 45 f8 10 00 00movQWORD PTR [rbp-0x8],0x10
   f:   00 
  10:   48 8d 45 f8 learax,[rbp-0x8]
  14:   48 0f ba 20 04  bt QWORD PTR [rax],0x4
 

Bad code with `-release -O -inline`:


 <_Dmain>:
   0:   55  push   rbp
   1:   48 8b ecmovrbp,rsp
   4:   48 83 ec 10 subrsp,0x10
   8:   48 8d 45 f8 learax,[rbp-0x8]
   c:   48 0f ba 20 04  bt QWORD PTR [rax],0x4


Note that `mov QWORD PTR [rbp-0x8],0x10` is missing in the bad code. I.e.,
`test_val` doesn't get initialized.

--


[Issue 18461] core.bitop.bt returns garbage in release code

2018-02-18 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18461

Seb  changed:

   What|Removed |Added

 CC||greensunn...@gmail.com

--- Comment #6 from Seb  ---
The object files produced by DMD are identical and in fact since a few releases
DMD produced reproducible builds.
However, that's the problem:

---
> dmd -inline -O -release bitop.d
> ./bitop
illegal hardware instruction (core dumped)  ./bitop
> ./bitop
illegal hardware instruction (core dumped)  ./bitop
> ./bitop
illegal hardware instruction (core dumped)  ./bitop
> ./bitop
illegal hardware instruction (core dumped)  ./bitop
> ./bitop
<-- works fine
---

--


[Issue 18461] core.bitop.bt returns garbage in release code

2018-02-18 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18461

--- Comment #5 from Seb  ---
Here's the verbose log from a failed dub build:


---
Using dub registry url 'https://code.dlang.org/'
Refreshing local packages (refresh existing: true)...
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/seb/.dub/packages/local-packages.json
Try to load local package map at /home/seb/.dub/packages/local-packages.json
Ignoring version specification (>=0.0.0) for path based dependency .
Ignoring version specification (>=0.0.0) for path based dependency .
Ignoring version specification (>=0.0.0) for path based dependency .
Ignoring version specification (>=0.0.0) for path based dependency .
Ignoring version specification (>=0.0.0) for path based dependency .
Ignoring version specification (>=0.0.0) for path based dependency .
Ignoring version specification (>=0.0.0) for path based dependency .
Determined package version using GIT: dlang-tour 1.0.13+commit.19.gb19a18c
Refreshing local packages (refresh existing: false)...
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/seb/.dub/packages/local-packages.json
Try to load local package map at /home/seb/.dub/packages/local-packages.json
Refreshing local packages (refresh existing: false)...
Looking for local package map at /var/lib/dub/packages/local-packages.json
Looking for local package map at /home/seb/.dub/packages/local-packages.json
Try to load local package map at /home/seb/.dub/packages/local-packages.json
Generating using build
Generate target bitop_bt (executable /home/seb/dlang/dlang-tour/core bitop_bt)
File '.' modified, need rebuild.
/usr/bin/dmd -c
-of.dub/build/application-release-linux.posix-x86_64-dmd_2078-B8815426D54654557310BC2B463B825C/bitop_bt.o
-release -inline -O -w -version=Have_bitop_bt -Jviews bitop.d -vcolumns
/usr/bin/dmd
-of.dub/build/application-release-linux.posix-x86_64-dmd_2078-B8815426D54654557310BC2B463B825C/bitop_bt
.dub/build/application-release-linux.posix-x86_64-dmd_2078-B8815426D54654557310BC2B463B825C/bitop_bt.o
-L--no-as-needed
Copying target from
/home/seb/dlang/dlang-tour/core/.dub/build/application-release-linux.posix-x86_64-dmd_2078-B8815426D54654557310BC2B463B825C/bitop_bt
to /home/seb/dlang/dlang-tour/core
---

and indeed running ./bitop_bt locally doesn't result in an error.

---
 for i in $(seq 100) ; do
 echo "Running"
 dmd -release -run - <

[Issue 18461] core.bitop.bt returns garbage in release code

2018-02-18 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18461

ag0ae...@gmail.com changed:

   What|Removed |Added

 CC||ag0ae...@gmail.com

--- Comment #4 from ag0ae...@gmail.com ---
(In reply to Seb from comment #2)
> I wonder whether this has something to do with DUB (probably not).
> 
> 1) Can you reproduce the same with just running DMD? (I couldn't on my
> machine)
> 
> 
> ---
> dmd -release -run - < ---

You're missing `-O -inline`. DUB's release mode implies them.

> 2) Did you check whether it's maybe something with your standard library?
> A simple check would be to try including core.bitop.bt in your file:
> 
> https://github.com/dlang/druntime/blob/master/src/core/bitop.d#L270

Same behavior.

--


[Issue 18461] core.bitop.bt returns garbage in release code

2018-02-18 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18461

--- Comment #3 from Seb  ---
> It is important to clarify: please run example several times, 10-20 times or 
> so and you will see difference in exit code values.

Tried it 100x times without any change:

---
for i in $(seq 100) ; do dmd -release -run - < seq 10 | parallel -j1 -n0 dub -v run --single bitop.d --build=release 2>&1 | 
> grep "exited with code -4" 
Program exited with code -4
Program exited with code -4
Program exited with code -4
Program exited with code -4
---

--


[Issue 18461] core.bitop.bt returns garbage in release code

2018-02-18 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18461

--- Comment #2 from Seb  ---
I wonder whether this has something to do with DUB (probably not).

1) Can you reproduce the same with just running DMD? (I couldn't on my machine)


---
dmd -release -run - 

[Issue 18461] core.bitop.bt returns garbage in release code

2018-02-18 Thread d-bugmail--- via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=18461

--- Comment #1 from feklushkin.de...@gmail.com ---
It is important to clarify: please run example several times, 10-20 times or so
and you will see difference in exit code values.

--