From cb59f96973826a295b4f864bcda38b240ba33e44 Mon Sep 17 00:00:00 2001 From: rth Date: Thu, 30 May 2002 21:28:17 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@54074 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++ gcc/c-common.c | 5 ++++ gcc/doc/extend.texi | 37 ++++++++++++++++++++++-- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.c-torture/execute/mayalias-1.c | 21 ++++++++++++++ 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/mayalias-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f1451581a5a..4890db352f2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2002-05-30 Osku Salerma + + * 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 * defaults.h (TARGET_ALLOWS_PROFILING_WITHOUT_FRAME_POINTER): Kill. diff --git a/gcc/c-common.c b/gcc/c-common.c index b1a9205d119..8a554e89466 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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; diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 87701efca98..4b8d496c64e 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b3e2fde4adc..8e063176caf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2002-05-30 Osku Salerma + + * gcc.c-torture/execute/mayalias-1.c: New file. + 2002-05-29 Neil Booth * gcc.dg/cpp/c++98-pedantic.c, gcc.dg/cpp/c89-pedantic.c, diff --git a/gcc/testsuite/gcc.c-torture/execute/mayalias-1.c b/gcc/testsuite/gcc.c-torture/execute/mayalias-1.c new file mode 100644 index 00000000000..ba461cae196 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/mayalias-1.c @@ -0,0 +1,21 @@ +/* Tests that the may_alias attribute works as expected. + Author: Osku Salerma 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); +} -- 2.11.4.GIT