This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Unreviewed patch for c-decl.c


Hi,


> -----Original Message-----
> From: Joseph S. Myers [mailto:jsm@polyomino.org.uk]
> Sent: Sunday, October 05, 2003 9:40 PM
> To: Dhananjay R. Deshpande
> Cc: gcc-patches@gcc.gnu.org
> Subject: RE: Unreviewed patch for c-decl.c
> 
> 
> Whether something is constant is a separate matter from 
> whether its type 
> is const-qualified.  The internal data structure for a declaration or 
> expression's type should accurately reflect the type it has in the C 
> standard.  The deduction of whether something can be 
> allocated in .rodata 
> can then be made by whatever logic is appropriate, but should 
> not cause a 
> type to be const-qualified if it isn't according to the standard.
> 
> Possibly TREE_READONLY on the DECL is what you want to set.  

Yes. Actually the patch sets the type_quals for the DECL and does not modify 
the type of DECL. The comment in the patch is wrong. Its not "apply type_quals 
of array elements to array_type", but to the current DECL.

>But this
> could cause other bugs, since Mark's patch
> <http://gcc.gnu.org/ml/gcc-patches/2001-06/msg00498.html> (which gave
> variables their correct types rather than relying on qualifications on
> their DECLs) has yet to be followed up with a general cleanup 
> of places in
> the C front end that look at TREE_READONLY (decl) to 
> determine whether a
> DECL is on const-qualified type.
> 
> The minimal test for not getting inappropriate 
> const-qualification leaking
> out would be that
> 
> static const int a[2] = { 1, 2 };
> typedef const int ci;
> static ci b[2] = { 3, 4 };
> typedef int ia[2];
> static const ia c = { 5, 6 };
> typedef const int cia[2];
> static cia d = { 7, 8 };
> void *p = &a;
> void *q = &b;
> void *r = &c;
> void *s = &d;
> 

Yes, the above test case compiles w/o any error.

> compiles silently (adapted appropriately as a testcase for 
> gcc.dg; testing
> that what you want to go in .rodata actually does so may be more
> difficult).  That test would suffice given a patch that only 
> tries to get 
> TREE_READONLY set properly on the DECL and doesn't attempt to 
> adjust the 
> type of the array itself.

I will come up with new patch that only sets TREE_READONLY along with 
the dejagnu test case. 

BTW, the C++ parser has similar implementation like my patch. Is there any difference in the C and C++ standards about cv qualifiers and array_types ( I couldn't find any )?

Regards,
Dhananjay

> 
> -- 
> Joseph S. Myers
> jsm@polyomino.org.uk
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]