Re: why are we not using const?

2006-07-14 Thread Kaveh R. Ghazi
Kaveh R. Ghazi [EMAIL PROTECTED] writes: [...] | I'd like to do for tree and rtx what I did for const char *, | namely constify those tree/rtx functions that aren't supposed to | modify their arguments. This would require introducing the | const_tree and const_rtx typedefs

RE: why are we not using const?

2006-07-14 Thread Dave Korn
On 14 July 2006 18:22, Kaveh R. Ghazi wrote: Now imagine if I change the type of __t to const_tree like so: typedef const union tree_node *const_tree; #define TREE_CHECK(T, CODE) __extension__ \ ({ const_tree const __t = (T); \ if (TREE_CODE (__t) != (CODE)) \ tree_check_failed

Re: why are we not using const?

2006-07-14 Thread Ian Lance Taylor
Kaveh R. Ghazi [EMAIL PROTECTED] writes: #define TREE_CHECK(T, CODE) __extension__ \ ({ const_tree const __t = (T); \ How about typeof(T) const __t = (T); ? Ian

Re: why are we not using const?

2006-07-14 Thread Kaveh R. Ghazi
How about typeof(T) const __t = (T); ? Ian Oops, I didn't realize that using typeof preserves const-ness and doesn't evaluate side-effects in T. After some quick testing it turns out typeof is exactly what I needed. I'm regtesting some patches now. Thanks!

Re: why are we not using const?

2006-06-29 Thread Richard Guenther
On 6/29/06, Kaveh R. Ghazi [EMAIL PROTECTED] wrote: Notice that the value of the parameter b is never changed in the function body. Consequently, if the current optimizers cannot figure that simple cases out (where b is not annotated const), then the optimizers in deficient in that

RE: why are we not using const?

2006-06-29 Thread Dave Korn
On 29 June 2006 14:44, Richard Guenther wrote: But with C language constructs you cannot assume that an object passed to a function via a const pointer is not modified. So, there is no real const regarding to objects pointed to. Consider void foo(const int *i) { int *k = (int *)i;

Re: why are we not using const?

2006-06-29 Thread Andrew Pinski
On Jun 29, 2006, at 9:51 AM, Dave Korn wrote: That's cheating! You casted away const, it's a blatant aliasing violation, you deserve everything you get. No it is not, in fact it is legal C and there is no aliasing violation as you are still accessing the memory as an int. --

RE: why are we not using const?

2006-06-29 Thread Dave Korn
On 29 June 2006 14:55, Andrew Pinski wrote: On Jun 29, 2006, at 9:51 AM, Dave Korn wrote: That's cheating! You casted away const, it's a blatant aliasing violation, you deserve everything you get. No it is not, in fact it is legal C and there is no aliasing violation as you are

Re: why are we not using const?

2006-06-29 Thread Andreas Schwab
Dave Korn [EMAIL PROTECTED] writes: But it's really legal to cast away const? All that matters is the effective type of the accessed object, see 6.5#7. Andreas. -- Andreas Schwab, SuSE Labs, [EMAIL PROTECTED] SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany PGP key

Re: why are we not using const?

2006-06-29 Thread Richard Guenther
On 6/29/06, Dave Korn [EMAIL PROTECTED] wrote: On 29 June 2006 14:55, Andrew Pinski wrote: On Jun 29, 2006, at 9:51 AM, Dave Korn wrote: That's cheating! You casted away const, it's a blatant aliasing violation, you deserve everything you get. No it is not, in fact it is legal C and

RE: why are we not using const?

2006-06-29 Thread Dave Korn
On 29 June 2006 15:12, Andreas Schwab wrote: Dave Korn [EMAIL PROTECTED] writes: But it's really legal to cast away const? All that matters is the effective type of the accessed object, see 6.5#7. Andreas. Ah yes, now I remember... we had a long thread on this sometime last year,

Re: why are we not using const?

2006-06-29 Thread Kaveh R. Ghazi
On Jun 29, 2006, at 9:51 AM, Dave Korn wrote: That's cheating! You casted away const, it's a blatant aliasing violation, you deserve everything you get. No it is not, in fact it is legal C and there is no aliasing violation as you are still accessing the memory as an int. --

RE: why are we not using const?

2006-06-29 Thread Dave Korn
On 29 June 2006 16:15, Kaveh R. Ghazi wrote: On Jun 29, 2006, at 9:51 AM, Dave Korn wrote: That's cheating! You casted away const, it's a blatant aliasing violation, you deserve everything you get. No it is not, in fact it is legal C and there is no aliasing violation as you

Re: why are we not using const?

2006-06-29 Thread Chris Lattner
On Jun 29, 2006, at 6:51 AM, Dave Korn wrote: That's cheating! You casted away const, it's a blatant aliasing violation, you deserve everything you get. The compiler is specifically *allowed* to assume you don't pull stunts like this *in order to* make const- optimisation possible and

Re: why are we not using const?

2006-06-29 Thread Gabriel Dos Reis
Dave Korn [EMAIL PROTECTED] writes: | On 29 June 2006 14:44, Richard Guenther wrote: | | But with C language constructs you cannot assume that an object | passed to a function via a const pointer is not modified. So, there | is no real const regarding to objects pointed to. Consider | |

Re: why are we not using const?

2006-06-29 Thread Paolo Bonzini
int G; void foo(const int *P1) { G = *P1 + 1; } int bar() { int tmp = G; foo(G); return G-tmp; } bar returns 1, not 0, and there is no pointer casting happening. Well, G is known to escape anyway here. Even worse is this: -- f1.c -- extern int G; void foo(const int *P1) {

Re: why are we not using const?

2006-06-29 Thread Andrew Haley
Andreas Schwab writes: Dave Korn [EMAIL PROTECTED] writes: But it's really legal to cast away const? All that matters is the effective type of the accessed object, see 6.5#7. It's not clear to me that it's legal to convert (const int*) to (int*). 6.3.2.3, Pointers, says 2 For any

Re: why are we not using const?

2006-06-28 Thread Gabriel Dos Reis
Andrew Pinski [EMAIL PROTECTED] writes: | On Jun 27, 2006, at 7:58 AM, Gabriel Dos Reis wrote: | | We we do have numbers that support that claim for real programs, then | we have a bug in the optimizers :-) | | Huh? Yes. | Stupid example where a const argument can change: | tree a; | int

Re: why are we not using const?

2006-06-28 Thread Kaveh R. Ghazi
Notice that the value of the parameter b is never changed in the function body. Consequently, if the current optimizers cannot figure that simple cases out (where b is not annotated const), then the optimizers in deficient in that respect. That is the point. -- Gaby I agree that the

Re: why are we not using const?

2006-06-28 Thread Andrew Pinski
On Jun 28, 2006, at 7:14 PM, Kaveh R. Ghazi wrote: Notice that the value of the parameter b is never changed in the function body. Consequently, if the current optimizers cannot figure that simple cases out (where b is not annotated const), then the optimizers in deficient in that respect.

Re: why are we not using const?

2006-06-28 Thread Gabriel Dos Reis
Kaveh R. Ghazi [EMAIL PROTECTED] writes: [...] | I'd like to do for tree and rtx what I did for const char *, namely | constify those tree/rtx functions that aren't supposed to modify their | arguments. This would require introducing the const_tree and | const_rtx typedefs Tristan suggested.

why are we not using const?

2006-06-27 Thread Manuel López-Ibáñez
Dear all, from comments in the #gcc irc channel, I understood that it is not advisable for gcc patches to use the const qualifier in function prototypes. I would like to understand why. Apart from its main purpose, I believed that the use of 'const' helps the compiler to optimise the code. Of

Re: why are we not using const?

2006-06-27 Thread Manuel López-Ibáñez
On 27/06/06, Andrew Haley [EMAIL PROTECTED] wrote: Well, const functions are nonstandard, and gcc itself is written in Standard C so they can't be used. But As for const args, I can't see any good reason not to use them, and there are 400 uses in gcc. I meant const arguments, sorry for the

Re: why are we not using const?

2006-06-27 Thread Gabriel Dos Reis
Manuel López-Ibáñez [EMAIL PROTECTED] writes: | Dear all, | | from comments in the #gcc irc channel, I understood that it is not | advisable for gcc patches to use the const qualifier in function | prototypes. I would like to understand why. Apart from its main | purpose, I believed that the use

Re: why are we not using const?

2006-06-27 Thread Andrew Pinski
On Jun 27, 2006, at 6:29 AM, Manuel López-Ibáñez wrote: On 27/06/06, Andrew Haley [EMAIL PROTECTED] wrote: Well, const functions are nonstandard, and gcc itself is written in Standard C so they can't be used. But As for const args, I can't see any good reason not to use them, and there are

Re: why are we not using const?

2006-06-27 Thread Andrew Pinski
On Jun 27, 2006, at 7:58 AM, Gabriel Dos Reis wrote: We we do have numbers that support that claim for real programs, then we have a bug in the optimizers :-) Huh? Stupid example where a const argument can change: tree a; int f(const tree b) { TREE_CODE(a) = TREE_CODE (b) + 1; return

Re: why are we not using const?

2006-06-27 Thread Theodore Papadopoulo
On Tue, 2006-06-27 at 13:51 +0100, Manuel López-Ibáñez wrote: from comments in the #gcc irc channel, I understood that it is not advisable for gcc patches to use the const qualifier in function prototypes. I would like to understand why. Apart from its main purpose, I believed that the use of

Re: why are we not using const?

2006-06-27 Thread Ross Ridge
Andrew Pinski wrote: Stupid example where a const argument can change: tree a; int f(const tree b) { TREE_CODE(a) = TREE_CODE (b) + 1; return TREE_CODE (b); } You're not changing the constant argument b, just what b might point to. I don't think there are any optimizing opportunities for

Re: why are we not using const?

2006-06-27 Thread Daniel Berlin
Manuel López-Ibáñez wrote: Dear all, from comments in the #gcc irc channel, I understood that it is not advisable for gcc patches to use the const qualifier in function prototypes. I would like to understand why. Apart from its main purpose, I believed that the use of 'const' helps the

Re: why are we not using const?

2006-06-27 Thread Manuel López-Ibáñez
On 27/06/06, Daniel Berlin [EMAIL PROTECTED] wrote: Manuel López-Ibáñez wrote: Apart from its main purpose, I believed that the use of 'const' helps the compiler to optimise the code. It generally doesn't, unless you apply const to the underlying type, and not just the pointer. IE you say

Re: why are we not using const?

2006-06-27 Thread Manuel López-Ibáñez
On 27/06/06, Andrew Haley [EMAIL PROTECTED] wrote: OK, now you're getting the idea, you need to think about the difference between const union tree_node * union tree_node *const const union tree_node *const My fault then, I was erroneously assuming that if tree is equal to union

Re: why are we not using const?

2006-06-27 Thread Tristan Wibberley
Manuel López-Ibáñez wrote: On 27/06/06, Daniel Berlin [EMAIL PROTECTED] wrote: Manuel López-Ibáñez wrote: Apart from its main purpose, I believed that the use of 'const' helps the compiler to optimise the code. It generally doesn't, unless you apply const to the underlying type, and not