[Dwarf-Discuss] interpretation of DW_OP_mod
eager at eagercon.com
Tue Jan 19 13:04:02 PST 2010
Tom Tromey wrote:
> While looking into a gdb bug I came across an oddity in GCC's unwinder.
> It treats the operands of DW_OP_mod as signed:
> case DW_OP_mod:
> result = (_Unwind_Sword) second % (_Unwind_Sword) first;
> Other programs (valgrind 3.3.1, according to google code search) also
> follow this interpretation -- I assume because it seems strange to have
> signed division but unsigned modulus.
> Is this a (widespread) bug in these programs? Or an oversight in the
DW_OP_mod is defined to be an unsigned operation.
I believe that this is intentional, not an oversight. There is an
ambiguity in the modulus operation on signed values, where some
implementations compute the sign of the result to be the same as the
divisor and others have the sign the same as the dividend. So the
result of (-7 % 3) could be either -1 or 2.
There's no such ambiguity with unsigned modulus.
Michael Eager eager at eagercon.com
1960 Park Blvd., Palo Alto, CA 94306 650-325-8077
More information about the Dwarf-Discuss