]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
s390x: Minor fix for vbit-test
authorFlorian Krohm <flo2030@eich-krohm.de>
Mon, 7 Jul 2025 13:51:29 +0000 (13:51 +0000)
committerFlorian Krohm <flo2030@eich-krohm.de>
Mon, 7 Jul 2025 13:51:29 +0000 (13:51 +0000)
Add a big comment as to why Ity_I1 type values are stored in a
32-bit entity.

VEX/priv/ir_inject.c
memcheck/tests/vbit-test/util.c
memcheck/tests/vbit-test/valgrind.c
memcheck/tests/vbit-test/vbits.h

index 26e8ca2787526f07a458b437c4ffc4e2fdf69aab..e62a2d8506771511f7fff01ea93576ed6c85df8a 100644 (file)
@@ -67,7 +67,8 @@ load_aux(IREndness endian, IRType type, IRExpr *addr)
                   IRExpr_Load(endian, Ity_I64, addr));
    }
    if (type == Ity_I1) {
-      /* A Boolean value is stored as a 32-bit entity (see store_aux). */
+      /* A Boolean value is stored as a 32-bit entity. For an explanation
+         see comment in vbit-test/vbits.h */
       return unop(Iop_32to1, IRExpr_Load(endian, Ity_I32, addr));
    }
 
@@ -131,8 +132,8 @@ store_aux(IRSB *irsb, IREndness endian, IRExpr *addr, IRExpr *data)
       data = unop(Iop_ReinterpD64asI64, data);
    }
    if (typeOfIRExpr(irsb->tyenv, data) == Ity_I1) {
-      /* We cannot store a single bit. So we store it in a 32-bit container.
-         See also load_aux. */
+      /* A Boolean value is stored as a 32-bit entity. For an explanation
+         see comment in vbit-test/vbits.h */
       data = unop(Iop_1Uto32, data);
    }
    stmt(irsb, IRStmt_Store(endian, addr, data));
index 63eabc8993a9ecbd3eb570afd24cb335905c33e6..3e57cfa70354192cc61705e788edab88b2483069 100644 (file)
@@ -86,7 +86,7 @@ static void
 print_value(FILE *fp, value_t val, unsigned num_bits)
 {
    switch (num_bits) {
-   case 1:  fprintf(fp, "%02x",   val.u8);  break;
+   case 1:  fprintf(fp, "%01x",   val.u32); break; // see comment in vbits.h
    case 8:  fprintf(fp, "%02x",   val.u8);  break;
    case 16: fprintf(fp, "%04x",   val.u16); break;
    case 32: fprintf(fp, "%08x",   val.u32); break;
index c24a06d649c754bb8d2e79ae51dee9549d44e723..55ff3647dac427017e15ed219b8ede23ac391d7e 100644 (file)
@@ -64,7 +64,7 @@ valgrind_set_vbits(opnd_t *opnd)
 {
    unsigned rc, num_bytes;
    
-   /* 1-bit wide values cannot be read. So we read 4 bytes here */
+   /* 1-bit wide values cannot be read. So we read 4 bytes here */
    num_bytes = opnd->type == Ity_I1 ? 4 : sizeof_irtype(opnd->type);
    rc = VALGRIND_SET_VBITS(&opnd->value, &opnd->vbits.bits, num_bytes);
    assert(rc == 1);
@@ -83,8 +83,8 @@ valgrind_get_vbits(opnd_t *opnd)
 {
    unsigned rc, num_bytes;
 
-   /* 1-bit wide values cannot be stored. So we store them by writing a
-      single byte */
+   /* 1-bit wide values cannot be stored. So we store them by writing
+      4 bytes which is what ir_inject.c expects. */
    num_bytes = opnd->type == Ity_I1 ? 4 : sizeof_irtype(opnd->type);
    opnd->vbits.num_bits = bitsof_irtype(opnd->type);
    rc = VALGRIND_GET_VBITS(&opnd->value, &opnd->vbits.bits, num_bytes);
index 53ba328aa041b70c19a2218d9747412c3681da51..7d0002d32fecce4b154c30bfac7b10c224b679f4 100644 (file)
@@ -48,7 +48,19 @@ typedef struct {
 
 /* A type large enough to hold any IRType'd value. At this point
    we do not expect to test with specific floating point values.
-   So we don't need to represent them. */
+   So we don't need to represent them.
+
+   NOTE: Values of type Ity_I1 are stored in the u32 variant. This is
+   inconsistent with the way such values are stored elsewhere in VEX,
+   namely, in an 8-bit container. Why is that?
+   The reason is that libvex_ir.h does not provide an Iop_8to1 operator.
+   However, that would be needed in ir_inject.c when loading a 1-bit value
+   from memory (see function load_aux there). Instead of today's
+      return unop(Iop_32to1, IRExpr_Load(endian, Ity_I32, addr));
+   we'd like to write
+      return unop(Iop_8to1, IRExpr_Load(endian, Ity_I8, addr));
+   But cannot do. Grrrrr...
+ */
 typedef union {
    uint8_t   u8;
    uint16_t  u16;