* [PATCH][C fam] Fix PR80593, bogus strict-aliasing warnings
@ 2017-05-18 11:01 Richard Biener
2017-05-19 12:30 ` Marek Polacek
0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2017-05-18 11:01 UTC (permalink / raw)
To: gcc-patches; +Cc: jason, polacek
The following reverts an earlier change of mine (2008) to explicitely
warn about accessing alias-set zero memory with alias-set non-zero.
That was supposed to catch the case in g++.dg/warn/Wstrict-aliasing-6.C
which is
int foo ()
{
char buf[8];
return *((int *)buf); /* { dg-warning "strict-aliasing" } */
}
but at least since the typeless storage work this is considered valid
and thus this warning is really bogus.
Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
Ok for trunk and GCC 7 branch?
Thanks,
Richard.
2017-05-18 Richard Biener <rguenther@suse.de>
PR c++/80593
* c-warn.c (strict_aliasing_warning): Do not warn for accesses
to alias-set zero memory.
* g++.dg/warn/Wstrict-aliasing-bogus-char-2.C: New testcase.
* g++.dg/warn/Wstrict-aliasing-6.C: Adjust expected outcome.
Index: gcc/c-family/c-warn.c
===================================================================
--- gcc/c-family/c-warn.c (revision 248179)
+++ gcc/c-family/c-warn.c (working copy)
@@ -537,10 +537,10 @@ strict_aliasing_warning (tree otype, tre
= get_alias_set (TREE_TYPE (TREE_OPERAND (expr, 0)));
alias_set_type set2 = get_alias_set (TREE_TYPE (type));
- if (set1 != set2 && set2 != 0
- && (set1 == 0
- || (!alias_set_subset_of (set2, set1)
- && !alias_sets_conflict_p (set1, set2))))
+ if (set2 != 0
+ && set1 != set2
+ && !alias_set_subset_of (set2, set1)
+ && !alias_sets_conflict_p (set1, set2))
{
warning (OPT_Wstrict_aliasing, "dereferencing type-punned "
"pointer will break strict-aliasing rules");
Index: gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-char-2.C
===================================================================
--- gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-char-2.C (nonexistent)
+++ gcc/testsuite/g++.dg/warn/Wstrict-aliasing-bogus-char-2.C (working copy)
@@ -0,0 +1,19 @@
+// { dg-do compile }
+// { dg-options "-O2 -Wstrict-aliasing" }
+
+template<unsigned _Len, unsigned _Align>
+struct aligned_storage
+{
+ union type
+ {
+ unsigned char __data[_Len];
+ struct __attribute__((__aligned__((_Align)))) { } __align;
+ };
+};
+
+aligned_storage<sizeof(int), __alignof__(int)>::type storage;
+
+int main()
+{
+ *reinterpret_cast<int*>(&storage) = 42; // { dg-bogus "break strict-aliasing" }
+}
Index: gcc/testsuite/g++.dg/warn/Wstrict-aliasing-6.C
===================================================================
--- gcc/testsuite/g++.dg/warn/Wstrict-aliasing-6.C (revision 248179)
+++ gcc/testsuite/g++.dg/warn/Wstrict-aliasing-6.C (working copy)
@@ -4,6 +4,6 @@
int foo ()
{
char buf[8];
- return *((int *)buf); /* { dg-warning "strict-aliasing" } */
+ return *((int *)buf); /* { dg-bogus "strict-aliasing" } */
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][C fam] Fix PR80593, bogus strict-aliasing warnings
2017-05-18 11:01 [PATCH][C fam] Fix PR80593, bogus strict-aliasing warnings Richard Biener
@ 2017-05-19 12:30 ` Marek Polacek
2017-05-19 12:42 ` Richard Biener
0 siblings, 1 reply; 3+ messages in thread
From: Marek Polacek @ 2017-05-19 12:30 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches, jason
On Thu, May 18, 2017 at 01:00:39PM +0200, Richard Biener wrote:
>
> The following reverts an earlier change of mine (2008) to explicitely
> warn about accessing alias-set zero memory with alias-set non-zero.
> That was supposed to catch the case in g++.dg/warn/Wstrict-aliasing-6.C
> which is
>
> int foo ()
> {
> char buf[8];
> return *((int *)buf); /* { dg-warning "strict-aliasing" } */
> }
>
> but at least since the typeless storage work this is considered valid
> and thus this warning is really bogus.
>
> Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
>
> Ok for trunk and GCC 7 branch?
I think this is fine.
Marek
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH][C fam] Fix PR80593, bogus strict-aliasing warnings
2017-05-19 12:30 ` Marek Polacek
@ 2017-05-19 12:42 ` Richard Biener
0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2017-05-19 12:42 UTC (permalink / raw)
To: Marek Polacek; +Cc: gcc-patches, jason
On Fri, 19 May 2017, Marek Polacek wrote:
> On Thu, May 18, 2017 at 01:00:39PM +0200, Richard Biener wrote:
> >
> > The following reverts an earlier change of mine (2008) to explicitely
> > warn about accessing alias-set zero memory with alias-set non-zero.
> > That was supposed to catch the case in g++.dg/warn/Wstrict-aliasing-6.C
> > which is
> >
> > int foo ()
> > {
> > char buf[8];
> > return *((int *)buf); /* { dg-warning "strict-aliasing" } */
> > }
> >
> > but at least since the typeless storage work this is considered valid
> > and thus this warning is really bogus.
> >
> > Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.
> >
> > Ok for trunk and GCC 7 branch?
>
> I think this is fine.
Thanks.
Committed to trunk sofar.
Richard.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-05-19 12:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-18 11:01 [PATCH][C fam] Fix PR80593, bogus strict-aliasing warnings Richard Biener
2017-05-19 12:30 ` Marek Polacek
2017-05-19 12:42 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).