This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH, GAS/ARM] Clarify relation between reg_expected_msgs and arm_reg_type
- From: Nick Clifton <nickc at redhat dot com>
- To: Thomas Preudhomme <thomas dot preudhomme at foss dot arm dot com>, Richard Earnshaw <richard dot earnshaw at arm dot com>, Alan Modra <amodra at gmail dot com>, "binutils at sourceware dot org" <binutils at sourceware dot org>
- Date: Wed, 22 Nov 2017 10:55:53 +0000
- Subject: Re: [PATCH, GAS/ARM] Clarify relation between reg_expected_msgs and arm_reg_type
- Authentication-results: sourceware.org; auth=none
- References: <59cf2ec2-ca7c-575c-4441-66aca271a2ea@foss.arm.com>
Hi Thomas,
> Uses of reg_expected_msgs rely on each arm_reg_type enumerator to have a
> message entry in the same order as the enumerator declaration. This is
> not clearly stated in the definition of both the arm_reg_type enum and
> the reg_expected_msgs. Worse, there is nothing to ensure both are kept
> in sync.
There is a similar problem in other parts of the binutils sources too.
The usual way to solve it is to arrange for a compile time error if the
enum and the array are different sizes. For example, in bfd/dwarf2.c
there is:
extern int dwarf_debug_section_assert[ARRAY_SIZE (dwarf_debug_sections)
== debug_max + 1 ? 1 : -1];
> As an attempt towards this, this patch uses C99 array designators to
> ensure that each message is associated with the right arm_reg_type.
[I was going to add a whole paragraph here about how we need the sources
to remain compilable on older machines with older compilers that do not
have C99 support. But then it occurred to me that C99 is almost 20 years
old now and we really should be able to use its features. So ...]
Sure - this makes sense.
> A comment is also added near the definition of arm_reg_type to point to
> the reg_expected_msgs array.
Comments are good. I like comments.
> Finally, the array is synced with
> arm_reg_type by adding the missing error message for REG_TYPE_RNB.
No problems with that.
> 2017-11-14 Thomas Preud'homme <thomas.preudhomme@arm.com>
>
> * config/tc-arm.c (arm_reg_type): Comment on the link with
> reg_expected_msgs.
> (reg_expected_msgs): Initialize using array designators with
> arm_reg_type index.
Approved - please apply.
Cheers
Nick