APInt::sdivrem error?

> APInt q(bits, 1), r(bits, 1);

The APInt constructor has three arguments, the last one being whether or not the value is to be treated as signed.
It defaults to false, as you appear to have just verified.

The initial values of q and r shouldn't make a difference (note that
several of the correct examples give correct positive and negative
results). And trying it with a 3rd true argument made no difference.

Other ideas anyone?

My only other clue is that bits = 64.