[PATCH] Reject > word sign extensions in initializers (PR middle-end/80163)

Jeff Law law@redhat.com
Mon Mar 27 15:51:00 GMT 2017

On 03/24/2017 01:27 PM, Jakub Jelinek wrote:
> Hi!
> I'm not aware of any target that would support sign extension of
> something that can't be folded in the compiler into some type
> larger than word/pointer.  Zero extension is doable and assemble_variable
> is able to deal with it by emitting low/high subregs of it (where the
> low one will contain some expression that needs to be computed by assembler
> or even have relocation and upper part will be all zeros), but for
> sign extension we'd need assembler support that would for some
> asm expression shift it arithmetically right.
> So, this patch just rejects it in initializers (in C++ handles through
> dynamic initialization) in that case.  clang also rejects it, ICC silently
> miscompiles (performs zero extension).
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 2017-03-24  Jakub Jelinek  <jakub@redhat.com>
> 	PR middle-end/80163
> 	* varasm.c (initializer_constant_valid_p_1): Disallow sign-extending
> 	conversions to integer types wider than word and pointer.
> 	* gcc.dg/pr80163.c: New test.
FWIW, the old PA 32 bit SOM model had relocations that would allow 
supporting this case.  We never exposed them as never seemed worth the 
effort, given it's a relatively obscure issue on a dead platform, I 
don't think it's worth trying to do anything to support it there.

OK for the trunk.


More information about the Gcc-patches mailing list