Commit 39aac208 by Richard Biener Committed by Richard Biener

re PR c++/80593 (GCC 7, aligned_storage and “dereferencing type-punned pointer…

re PR c++/80593 (GCC 7, aligned_storage and “dereferencing type-punned pointer will break strict-aliasing rules”)

2017-05-19  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.

From-SVN: r248269
parent f00e3d4e
2017-05-19 Richard Biener <rguenther@suse.de>
PR c++/80593
* c-warn.c (strict_aliasing_warning): Do not warn for accesses
to alias-set zero memory.
2017-05-18 Bernd Edlinger <bernd.edlinger@hotmail.de>
* c-format.c (local_tree_type_node): Add GTY attribute.
......
......@@ -537,10 +537,10 @@ strict_aliasing_warning (tree otype, tree type, tree expr)
= 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");
......
2017-05-19 Richard Biener <rguenther@suse.de>
PR c++/80593
* g++.dg/warn/Wstrict-aliasing-bogus-char-2.C: New testcase.
* g++.dg/warn/Wstrict-aliasing-6.C: Adjust expected outcome.
2017-05-19 Richard Biener <rguenther@suse.de>
PR middle-end/80764
* gcc.dg/torture/pr80764.c: New testcase.
......
......@@ -4,6 +4,6 @@
int foo ()
{
char buf[8];
return *((int *)buf); /* { dg-warning "strict-aliasing" } */
return *((int *)buf); /* { dg-bogus "strict-aliasing" } */
}
// { 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" }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment