Commit d18b1ed8 by Osku Salerma Committed by Richard Henderson

c-common.c (c_common_attribute_table): Add "may_alias" entry.

        * c-common.c (c_common_attribute_table): Add "may_alias" entry.
        (c_common_get_alias_set): Handle it.
        * doc/extend.texi: Document it.

        * gcc.c-torture/execute/mayalias-1.c: New file.

From-SVN: r54074
parent a7943381
2002-05-30 Osku Salerma <osku@iki.fi>
* c-common.c (c_common_attribute_table): Add "may_alias" entry.
(c_common_get_alias_set): Handle it.
* doc/extend.texi: Document it.
2002-05-30 Richard Henderson <rth@redhat.com>
* defaults.h (TARGET_ALLOWS_PROFILING_WITHOUT_FRAME_POINTER): Kill.
......
......@@ -430,6 +430,7 @@ const struct attribute_spec c_common_attribute_table[] =
handle_nonnull_attribute },
{ "nothrow", 0, 0, true, false, false,
handle_nothrow_attribute },
{ "may_alias", 0, 0, false, true, false, NULL },
{ NULL, 0, 0, false, false, false, NULL }
};
......@@ -2551,6 +2552,10 @@ c_common_get_alias_set (t)
&& TYPE_PRECISION (TREE_TYPE (t)) == TYPE_PRECISION (char_type_node))
return 0;
/* If it has the may_alias attribute, it can alias anything. */
if (TYPE_P (t) && lookup_attribute ("may_alias", TYPE_ATTRIBUTES (t)))
return 0;
/* That's all the expressions we handle specially. */
if (! TYPE_P (t))
return -1;
......
......@@ -3149,10 +3149,11 @@ packed))}.
The keyword @code{__attribute__} allows you to specify special
attributes of @code{struct} and @code{union} types when you define such
types. This keyword is followed by an attribute specification inside
double parentheses. Five attributes are currently defined for types:
double parentheses. Six attributes are currently defined for types:
@code{aligned}, @code{packed}, @code{transparent_union}, @code{unused},
and @code{deprecated}. Other attributes are defined for functions
(@pxref{Function Attributes}) and for variables (@pxref{Variable Attributes}).
@code{deprecated} and @code{may_alias}. Other attributes are defined for
functions (@pxref{Function Attributes}) and for variables
(@pxref{Variable Attributes}).
You may also specify any one of these attributes with @samp{__}
preceding and following its keyword. This allows you to use these
......@@ -3363,6 +3364,36 @@ deprecated. Similarly for line 6.
The @code{deprecated} attribute can also be used for functions and
variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.)
@item may_alias
Accesses to objects with types with this attribute are not subjected to
type-based alias analysis, but are instead assumed to be able to alias
any other type of objects, just like the @code{char} type. See
@option{-fstrict-aliasing} for more information on aliasing issues.
Example of use:
@example
typedef short __attribute__((__may_alias__)) short_a;
int
main (void)
@{
int a = 0x12345678;
short_a *b = (short_a *) &a;
b[1] = 0;
if (a == 0x12345678)
abort();
exit(0);
@}
@end example
If you replaced @code{short_a} with @code{short} in the variable
declaration, the above program would abort when compiled with
@option{-fstrict-aliasing}, which is on by default at @option{-O2} or
above in recent GCC versions.
@end table
To specify multiple attributes, separate them by commas within the
......
2002-05-30 Osku Salerma <osku@iki.fi>
* gcc.c-torture/execute/mayalias-1.c: New file.
2002-05-29 Neil Booth <neil@daikokuya.demon.co.uk>
* gcc.dg/cpp/c++98-pedantic.c, gcc.dg/cpp/c89-pedantic.c,
......
/* Tests that the may_alias attribute works as expected.
Author: Osku Salerma <osku@iki.fi> Apr 2002. */
extern void abort(void);
extern void exit(int);
typedef short __attribute__((__may_alias__)) short_a;
int
main (void)
{
int a = 0x12345678;
short_a *b = (short_a*) &a;
b[1] = 0;
if (a == 0x12345678)
abort();
exit(0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment