[proposed but not yet applied patch for PR28865 (PR39383 and PR56880 are dups) ] Date: Wed, 22 Apr 2009 18:13:42 -0500 (CDT) From: "Anmol P dot Paralkar" Subject: PATCH RFA: Fix for PR 39383 for generic ELF systems. List-Archive: Hello, Please find attached, a fix for PR 39383 in the case of generic ELF systems and a test-case for inclusion in the test-suite. Per Comment #6 in the PR, the .size assembler directive emitted ought to contain the "true" size of the object (when the object is of type struct containing a flexible array - using the size of the type is going to be off). The fix involves changing the definition of the ASM_DECLARE_OBJECT_NAME macro to use the size of the variable's initializer instead of the type of the variable. The fixed GCC was bootstrapped and tested on a PowerBook G4 (7447A altivec supported), running Linux 2.6.27.5-117.fc10.ppc (compared post-fix relative to pre-fix for each of: gcc, g++, libgomp, libmudflap, objc, gfortran, libffi, libjava, libstdc++ - there were no regressions - please let me know in case you wish to see the summaries/logs) in native configuration: powerpc-unknown-linux-gnu This is my zeroeth attempt to contribute to GCC; any advice (especially, if the ASM_FINISH_DECLARE_OBJECT macro needs the same change as well) is gratefully received. Thank you. Sincerely, Anmol P. Paralkar 2009-04-22 Anmol P. Paralkar PR c/39383 * config/elfos.h (ASM_DECLARE_OBJECT_NAME): Use the size of the variable's initializer instead of the size of its type. 2009-04-22 Anmol P. Paralkar PR c/39383 * gcc.dg/pr39383.c: New testcase. --- gcc-4.7.3/gcc/config/elfos.h.~1~ 2011-11-14 17:55:56.000000000 +0100 +++ gcc-4.7.3/gcc/config/elfos.h 2013-04-20 12:52:04.129290034 +0200 @@ -316,7 +316,7 @@ see the files COPYING3 and COPYING.RUNTI && (DECL) && DECL_SIZE (DECL)) \ { \ size_directive_output = 1; \ - size = int_size_in_bytes (TREE_TYPE (DECL)); \ + size = tree_low_cst (DECL_SIZE_UNIT (DECL), 1); \ ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size); \ } \ \ --- gcc-4.7.3/gcc/testsuite/gcc.dg/pr39383.c.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.7.3/gcc/testsuite/gcc.dg/pr39383.c 2013-04-20 12:52:04.129290034 +0200 @@ -0,0 +1,16 @@ +/* Verify that when a struct has a flexible array member, + the size in the emitted .size assembler directive for + a statically initialized object (of that type) is based + on the actual size of the object (as determined by its + initializer) and not on the type of the object. */ + +/* { dg-do compile } */ +/* { dg-options "" } */ + +struct text +{ + char len; + char txt[]; +} vowels = { 5, { 'a', 'e', 'i', 'o', 'u' } }; + +/* { dg-final { scan-assembler "\.size\[ \t\]+vowels,\[ \t\]+6" } } */