Thread overview
[Issue 14323] Bad code generation in dfmt
Mar 30, 2015
Vladimir Panteleev
March 30, 2015
https://issues.dlang.org/show_bug.cgi?id=14323

Vladimir Panteleev <thecybershadow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow@gmail.com

--- Comment #1 from Vladimir Panteleev <thecybershadow@gmail.com> ---
What DMD version?

With 2.066.0 I get:

src/dfmt/wrapping.d(187): Error: pure function
'dfmt.wrapping.validMoves!(RedBlackTree!(State, "a < b", false)).validMoves'
cannot call impure function 'std.container.rbtree.RedBlackTree!(State, "a < b",
false).RedBlackTree.stableInsert!(State).stableInsert'
src/dfmt/wrapping.d(165): Error: template instance
dfmt.wrapping.validMoves!(RedBlackTree!(State, "a < b", false)) error
instantiating

And then it seems to freeze up.

--
March 30, 2015
https://issues.dlang.org/show_bug.cgi?id=14323

--- Comment #2 from briancschott@gmail.com ---
Reduced to a single file:

https://gist.github.com/Hackerpilot/9708cfa7ce0e259f1600

Compiler + flags        | Output
------------------------+-------
ldc -d-version=WTF_DMD  | 2400
ldc                     | 2400
dmd -version=WTF_DMD    | 2400
dmd                     | 3080
dmd -version=WTF_DMD -O | 2400
dmd                  -O | 2400

Setting the version flag OR enabling optimizations causes good code generaton.

--
March 31, 2015
https://issues.dlang.org/show_bug.cgi?id=14323

briancschott@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from briancschott@gmail.com ---
The code was calling bsf with an argument of 0, which is undefined. It behaved consistently, and the version and optimization flags could change its return value.

The real issue is that bsf is marked as a pure function when it isn't: https://issues.dlang.org/show_bug.cgi?id=14380

--