aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorHans-Peter Nilsson <hp@axis.com>2008-06-25 01:36:58 +0000
committerHans-Peter Nilsson <hp@gcc.gnu.org>2008-06-25 01:36:58 +0000
commit917db97b023775f3031e99040ed9d058ffdcbd21 (patch)
tree23bb4c272723918d0263fd3f7f67da2986a41d02 /gcc
parent9af5483ab3f3459aeecabb4207170eb6d4ebb79f (diff)
downloadgcc-917db97b023775f3031e99040ed9d058ffdcbd21.zip
gcc-917db97b023775f3031e99040ed9d058ffdcbd21.tar.gz
gcc-917db97b023775f3031e99040ed9d058ffdcbd21.tar.bz2
invoke.texi (Optimize Options): Add anchor for the type-punning blurb.
* doc/invoke.texi (Optimize Options) <fstrict-aliasing>: Add anchor for the type-punning blurb. Cross-reference "Structures unions enumerations and bit-fields implementation". Provide a cast-through-pointer example. Make final sentence self-contained. * doc/implement-c.texi (Structures unions enumerations and bit-fields implementation): Cross-reference the type-punning blurb in the -fstrict-aliasing documentation. From-SVN: r137095
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/doc/implement-c.texi4
-rw-r--r--gcc/doc/invoke.texi18
3 files changed, 27 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c68706e..90b7966 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2008-06-25 Hans-Peter Nilsson <hp@axis.com>
+
+ * doc/invoke.texi (Optimize Options) <fstrict-aliasing>: Add
+ anchor for the type-punning blurb. Cross-reference "Structures
+ unions enumerations and bit-fields implementation". Provide a
+ cast-through-pointer example. Make final sentence self-contained.
+ * doc/implement-c.texi (Structures unions enumerations and
+ bit-fields implementation): Cross-reference the type-punning blurb
+ in the -fstrict-aliasing documentation.
+
2008-06-24 Andrew Pinski <andrew_pinski@playstation.sony.com>
PR middle-end/36594
diff --git a/gcc/doc/implement-c.texi b/gcc/doc/implement-c.texi
index b7d34ee..6a1b59b 100644
--- a/gcc/doc/implement-c.texi
+++ b/gcc/doc/implement-c.texi
@@ -433,8 +433,8 @@ used to determine if a function has not been inlined and why not.
different type (C90 6.3.2.3).}
The relevant bytes of the representation of the object are treated as
-an object of the type used for the access. This may be a trap
-representation.
+an object of the type used for the access. @xref{Type-punning}. This
+may be a trap representation.
@item
@cite{Whether a ``plain'' @code{int} bit-field is treated as a
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index fd43812..f69f001 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -6146,7 +6146,7 @@ example, an @code{unsigned int} can alias an @code{int}, but not a
@code{void*} or a @code{double}. A character type may alias any other
type.
-Pay special attention to code like this:
+@anchor{Type-punning}Pay special attention to code like this:
@smallexample
union a_union @{
int i;
@@ -6163,7 +6163,8 @@ The practice of reading from a different union member than the one most
recently written to (called ``type-punning'') is common. Even with
@option{-fstrict-aliasing}, type-punning is allowed, provided the memory
is accessed through the union type. So, the code above will work as
-expected. However, this code might not:
+expected. @xref{Structures unions enumerations and bit-fields
+implementation}. However, this code might not:
@smallexample
int f() @{
a_union t;
@@ -6174,7 +6175,18 @@ int f() @{
@}
@end smallexample
-Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}.
+Similarly, access by taking the address, casting the resulting pointer
+and dereferencing the result has undefined behavior, even if the cast
+uses a union type, e.g.:
+@smallexample
+int f() @{
+ double d = 3.0;
+ return ((union a_union *) &d)->i;
+@}
+@end smallexample
+
+The @option{-fstrict-aliasing} option is enabled at levels
+@option{-O2}, @option{-O3}, @option{-Os}.
@item -fstrict-overflow
@opindex fstrict-overflow