This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/70143] [6 Regression] false strict-aliasing warning
- From: "rguenther at suse dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 09 Mar 2016 10:31:02 +0000
- Subject: [Bug c/70143] [6 Regression] false strict-aliasing warning
- Auto-submitted: auto-generated
- References: <bug-70143-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70143
--- Comment #5 from rguenther at suse dot de <rguenther at suse dot de> ---
On Wed, 9 Mar 2016, jakub at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70143
>
> --- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
> Note even GCC 5.x and earlier warn here with -Wstrict-aliasing=2 or
> -Wstrict-aliasing=1, it is just whether we warn about this with the most common
> one -Wstrict-aliasing=3.
Sure. I can trivially re-instantiate previous behavior with
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c (revision 234025)
+++ gcc/c-family/c-common.c (working copy)
@@ -1568,7 +1568,9 @@ strict_aliasing_warning (tree otype, tre
alias_set_type set2 = get_alias_set (TREE_TYPE (type));
if (set1 != set2 && set2 != 0
- && (set1 == 0 || !alias_set_subset_of (set2, set1)))
+ && (set1 == 0
+ || (!alias_set_subset_of (set2, set1)
+ && !alias_set_subset_of (set1, set2))))
{
warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
"pointer will break strict-aliasing rules");
or with the suggested && !alias_sets_conflict_p (set1, set2).
Though that will FAIL the gcc.dg/Wstrict-aliasing-struct-member.c
I added.
Note that we then also don't warn for
struct a {
int i;
int k;
};
struct b {
struct a a;
int j;
};
int main(void) {
static struct b b;
struct a *ap=(struct a *)&b;
return ((struct b *)&ap->k)->j;
}
then either. Doing this kind of warnings strictly based on alias
sets only is going to be "broken" - though I consider our strict-aliasing
warnings broken anyway (and I don't think we can ever implement something
sensible :/).