TREE_READONLY vs TREE_CONSTANT

Josh Conner jconner@apple.com
Wed Aug 24 18:57:00 GMT 2005


In looking at PR23237, I ran into a bit of confusion over the  
difference between TREE_READONLY and TREE_CONSTANT.  Andrew Pinski  
indicated in PR logs that I am misunderstanding their uses, so rather  
than bogging down the PR logs trying to clear up my confusion (which  
isn't really fair to Andrew), I thought I would bring up the question  
in a more general forum to see if there is someone willing to offer  
some insight.

In the example from this PR, the TREE_READONLY attribute of a static  
variable declaration is being set in the ipa-reference pass if is  
determined that the variable is never modified.  The problem is that  
when the assembly code is generated for this variable, the section  
flags are also set based on TREE_READONLY, so it ends up in a section  
inconsistent with its declaration.

When I started digging into the tree flags, the descriptions in  
tree.h seemed to imply that TREE_CONSTANT is the appropriate  
attribute for a variable whose value doesn't change:

     /* Value of expression is constant.  Always on in all ..._CST  
nodes.  May
        also appear in an expression or decl where the value is  
constant.  */
     #define TREE_CONSTANT(NODE) (NON_TYPE_CHECK (NODE)- 
 >common.constant_flag)

And, based on other bits of source, TREE_READONLY seems to represent  
whether the variable was actually declared constant.

Can someone provide a bit of insight here - what is the difference  
between TREE_READONLY and TREE_CONSTANT (and why is TREE_READONLY the  
one that ipa-reference should be setting)?

Thanks for any help you can offer.

- Josh



More information about the Gcc mailing list