On Tue, 18 Apr 2000, Robert Dinse wrote:
> Can anybody tell me what the gcc flag "-fno-strict-aliasing" does?
> It's used by default on kernel builts but not documented in the gcc man page.
> I'm curious how many other flags exist that also aren't documented, or if there
> is some place these are actually documented?
It's documented in gcc's info page:
`-fstrict-aliasing'
Allows the compiler to assume the strictest aliasing rules
applicable to the language being compiled. For C (and C++), this
activates optimizations based on the type of expressions. In
particular, an object of one type is assumed never to reside at
the same address as an object of a different type, unless the
types are almost the same. For example, an `unsigned int' can
alias an `int', but not a `void*' or a `double'. A character type
may alias any other type.
Pay special attention to code like this:
union a_union {
int i;
double d;
};
int f() {
a_union t;
t.d = 3.0;
return t.i;
}
The practice of reading from a different union member than the one
most recently written to (called "type-punning") is common. Even
with `-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:
int f() {
a_union t;
int* ip;
t.d = 3.0;
ip = &t.i;
return *ip;
}
Every language that wishes to perform language-specific alias
analysis should define a function that computes, given an `tree'
node, an alias set for the node. Nodes in different alias sets
are not allowed to alias. For an example, see the C front-end
function `c_get_alias_set'.
In general, use -fno-strict-aliasing for dirty code...
LLaP
bero
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Sun Apr 23 2000 - 21:00:13 EST