This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Strict volatile bit-fields clean-up
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- Cc: gcc-patches at gcc dot gnu dot org, Richard Biener <richard dot guenther at gmail dot com>
- Date: Tue, 03 Dec 2013 11:33:10 +0100
- Subject: Re: [PATCH] Strict volatile bit-fields clean-up
- Authentication-results: sourceware.org; auth=none
- References: <DUB122-W30342E15CACDDA6AAE2376E4E60 at phx dot gbl> <CAFiYyc1gN_M2vrBN6_D_Yu_19PyYTds=zKGoVi5z4p7RnfkhEg at mail dot gmail dot com> <DUB122-W452F2FB018699B5B2BEB02E4D50 at phx dot gbl>
> The trigger is a latent problem in the ada gcc_interface.
>
> That is we have a bit-field of exactly 8 bit size, which is not
> byte-aligned, but DECL_MODE=QImode, DECL_BIT_FIELD=false which looks quite
> strange, and is totally different from how C structures look like. I should
> mention that there are even some places in the target back-ends, where the
> attribute DECL_BIT_FIELD is used for whatever.
This needs to be investigated because the intent is very clear in gigi, see
create_field_decl and finish_record_type: we set DECL_BIT_FIELD conservatively
and clear it only when we know that we can. This code is quite old now.
> However even without that patch, I can arrange for "volatilep &&
> flag_strict_volatile_bitfields> 0" to be true in Ada (even on X86_64, or
> whatever platform you like):
>
> -- { dg-do run }
> -- { dg-options "-gnatp -fstrict-volatile-bitfields" }
>
> procedure Misaligned_Volatile is
>
> type Byte is mod 2**8;
>
> type Block is record
> B : Boolean;
> V : Byte;
> end record;
> pragma Volatile (Block);
> pragma Pack (Block);
> for Block'Alignment use 1;
>
> type Pair is array (1 .. 2) of Block;
>
> P : Pair;
> begin
> for K in P'Range loop
> P(K).V := 237;
> end loop;
> for K in P'Range loop
> if P(K).V /= 237 then
> raise Program_error;
> end if;
> end loop;
> end;
>
>
> This Ada test case causes either wrong code generation or an ICE at compile
> time, if the -fstrict-volatile-bitfields option is either given by the
> user, or by the target-specific default as it is on ARM for instance
> (which is completely pointless on Ada, I know!)...
The test indeed raises Program_Error on x86-64.
--
Eric Botcazou