This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug exp/18617] New: Incorrect expression bytecode generated for narrowing conversions


https://sourceware.org/bugzilla/show_bug.cgi?id=18617

            Bug ID: 18617
           Summary: Incorrect expression bytecode generated for narrowing
                    conversions
           Product: gdb
           Version: 7.9
            Status: NEW
          Severity: normal
          Priority: P2
         Component: exp
          Assignee: unassigned at sourceware dot org
          Reporter: robert at ocallahan dot org
  Target Milestone: ---

Given the program:

uint64_t u64max = (uint64_t)(int64_t)-1;
int main(int argc, char* argv[]) {
  return 0;
}

and the commands

break main
cond 1 (unsigned char)u64max==255

the following expression bytecode is generated:

{0x24, 0x0, 0x60, 0xd, 0x38, 0x1a, 0x2a, 0x40, 0x23, 0x0, 0xff, 0x13, 0x27}

That is:

  const32 0x600d38
  ref64
  zero_ext 64
  const16 0xff
  equal
  end

The zero_ext operand is incorrect. It should have been 8, to keep the low 8
bits and zero the rest. The breakpoint condition therefore returns false when
it should return true.

The bug is in ax-gdb.c:

  /* If we're converting to a narrower type, then we need to clear out
     the upper bits.  */
  if (TYPE_LENGTH (to) < TYPE_LENGTH (from))
    gen_extend (ax, from);

That should be
    gen_extend (ax, to);
to keep `to` bits and zero the rest.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]