[commit] Do not rely on FIELD_LOC_KIND_BITPOS being zero

Jan Kratochvil
2012-04-17T12:45:03Z

Hi,

FIELD_LOC_KIND_BITPOS is 0 and some code relied on it, using only
TYPE_FIELD_BITPOS (type, n) = foo;
instead of
SET_FIELD_BITPOS (TYPE_FIELD (type, n), foo);

This caused in consequence with TYPE_FIELD_ENUM from:
[PATCH] Allow 64-bit enum values
and a sanity check
-#define TYPE_FIELD_BITPOS(thistype, n) FIELD_BITPOS (TYPE_FIELD (thistype, n))
-#define TYPE_FIELD_ENUMVAL(thistype, n) FIELD_ENUMVAL (TYPE_FIELD (thistype, n))
+#define TYPE_FIELD_BITPOSL(thistype, n) FIELD_BITPOS (TYPE_FIELD (thistype, n))
+#define TYPE_FIELD_BITPOS(thistype, n) ({ gdb_assert (TYPE_CODE (thistype) != TYPE_CODE_ENUM); TYPE_FIELD_BITPOSL(thistype, n); })
+#define TYPE_FIELD_ENUMVALL(thistype, n) FIELD_ENUMVAL (TYPE_FIELD (thistype, n))
+#define TYPE_FIELD_ENUMVAL(thistype, n) ({ gdb_assert (TYPE_CODE (thistype) == TYPE_CODE_ENUM); TYPE_FIELD_ENUMVALL(thistype, n); })
regression with -gstabs+:
file^M
No executable file now.^M
Discard symbol table from `/unsafegdb/testsuite.unix.-m64/gdb.python/py-value'? (y or n) y^M
-Error in re-setting breakpoint 1: No symbol table is loaded. Use the "file" command.^M
-Error in re-setting breakpoint 2: No symbol table is loaded. Use the "file" command.^M
-No symbol file now.^M
-(gdb) PASS: gdb.python/py-value.exp: Discard the symbols
-python castval = arg0.cast(ptrtype.pointer())^M
+gdbtypes.c:3403: internal-error: copy_type_recursive: Assertion `TYPE_CODE (type) != TYPE_CODE_ENUM' failed.^M
+A problem internal to GDB has been detected,^M
+further debugging may prove unreliable.^M
+Quit this debugging session? (y or n) FAIL: gdb.python/py-value.exp: Discard the symbols (GDB internal error)

No regressions on {x86_64,x86_64-m32,i686}-fedora17-linux-gnu and with -gstabs+.

Checked in.

Thanks,
Jan

http://sourceware.org/ml/gdb-cvs/2012-04/msg00108.html

--- src/gdb/ChangeLog 2012/04/16 11:24:43 1.14107
+++ src/gdb/ChangeLog 2012/04/17 12:43:16 1.14108
@@ -1,3 +1,12 @@
+2012-04-17 Jan Kratochvil <jan.kratochvil@redhat.com>
+
+ Do not rely on FIELD_LOC_KIND_BITPOS being zero.
+ * ada-lang.c (ada_template_to_fixed_record_type_1): Replace
+ TYPE_FIELD_BITPOS used as lvalue by SET_FIELD_BITPOS.
+ * gdbtypes.c (append_flags_type_flag): Likewise, twice.
+ * jv-lang.c (java_link_class_type): Likewise, once.
+ * stabsread.c (read_enum_type): Likewise.
+
2012-04-16 Yao Qi <yao@codesourcery.com>

* common/agent.c (agent_run_command): Add one more parameter `len'.
--- src/gdb/ada-lang.c 2012/03/29 23:30:55 1.363
+++ src/gdb/ada-lang.c 2012/04/17 12:43:19 1.364
@@ -7445,7 +7445,7 @@
{
off = align_value (off, field_alignment (type, f))
+ TYPE_FIELD_BITPOS (type, f);
- TYPE_FIELD_BITPOS (rtype, f) = off;
+ SET_FIELD_BITPOS (TYPE_FIELD (rtype, f), off);
TYPE_FIELD_BITSIZE (rtype, f) = 0;

if (ada_is_variant_part (type, f))
--- src/gdb/gdbtypes.c 2012/02/07 04:48:20 1.226
+++ src/gdb/gdbtypes.c 2012/04/17 12:43:20 1.227
@@ -3606,12 +3606,12 @@
if (name)
{
TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
- TYPE_FIELD_BITPOS (type, bitpos) = bitpos;
+ SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), bitpos);
}
else
{
/* Don't show this field to the user. */
- TYPE_FIELD_BITPOS (type, bitpos) = -1;
+ SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), -1);
}
}

--- src/gdb/jv-lang.c 2012/03/02 19:29:00 1.101
+++ src/gdb/jv-lang.c 2012/04/17 12:43:20 1.102
@@ -480,7 +480,7 @@
if (accflags & 0x0008) /* ACC_STATIC */
SET_FIELD_PHYSADDR (TYPE_FIELD (type, i), boffset);
else
- TYPE_FIELD_BITPOS (type, i) = 8 * boffset;
+ SET_FIELD_BITPOS (TYPE_FIELD (type, i), 8 * boffset);
if (accflags & 0x8000) /* FIELD_UNRESOLVED_FLAG */
{
TYPE_FIELD_TYPE (type, i) = get_java_object_type (); /* FIXME */
--- src/gdb/stabsread.c 2012/03/13 16:29:16 1.144
+++ src/gdb/stabsread.c 2012/04/17 12:43:20 1.145
@@ -3730,7 +3730,7 @@

SYMBOL_TYPE (xsym) = type;
TYPE_FIELD_NAME (type, n) = SYMBOL_LINKAGE_NAME (xsym);
- TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
+ SET_FIELD_BITPOS (TYPE_FIELD (type, n), SYMBOL_VALUE (xsym));
TYPE_FIELD_BITSIZE (type, n) = 0;
}
if (syms == osyms)