How to track down a bad llvm optimization pass

Johan Engelen via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Thu Jun 30 04:55:16 PDT 2016


Just now I discovered that the optimization bug in my inlining 
branch is exactly this: a shift outside the defined range 
happens, and LLVM happily optimizes the program using the 
undefined behavior and terrible things happen.

A runtime check would have been a great help here, saving me 
hours of bug hunting.

The bug is in std.range.primitives, BitsSet(T)::popFront():
```
     void popFront()
     {
         assert(_value, "Cannot call popFront on empty range.");

         _value >>>= 1;
         uint n = countTrailingZeros(_value); // returns 
sizeof(_value) * 8 when _value==0
         _value >>>= n; // BOOM!
```


More information about the digitalmars-d-ldc mailing list