* C++ PATCH to fix ICE with memset warning (PR c++/77321)
@ 2016-08-22 16:38 Marek Polacek
2016-08-22 21:51 ` Marek Polacek
0 siblings, 1 reply; 2+ messages in thread
From: Marek Polacek @ 2016-08-22 16:38 UTC (permalink / raw)
To: GCC Patches, Jason Merrill
Here we were crashing because the code wasn't prepared for NULL_TREE types.
Thus fixed in a rather obvious way.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2016-08-22 Marek Polacek <polacek@redhat.com>
PR c++/77321
* c-common.c (warn_for_memset): Check type for null.
* g++.dg/cpp1y/pr77321.C: New test.
diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 32468ca..3feb910 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -11991,7 +11991,7 @@ warn_for_memset (location_t loc, tree arg0, tree arg2,
if (TREE_CODE (arg0) == ADDR_EXPR)
arg0 = TREE_OPERAND (arg0, 0);
tree type = TREE_TYPE (arg0);
- if (TREE_CODE (type) == ARRAY_TYPE)
+ if (type != NULL_TREE && TREE_CODE (type) == ARRAY_TYPE)
{
tree elt_type = TREE_TYPE (type);
tree domain = TYPE_DOMAIN (type);
diff --git gcc/testsuite/g++.dg/cpp1y/pr77321.C gcc/testsuite/g++.dg/cpp1y/pr77321.C
index e69de29..ff33437 100644
--- gcc/testsuite/g++.dg/cpp1y/pr77321.C
+++ gcc/testsuite/g++.dg/cpp1y/pr77321.C
@@ -0,0 +1,10 @@
+// PR c++/77321
+// { dg-do compile { target c++14 } }
+// { dg-options "-Wall" }
+
+template <typename>
+void foo (void)
+{
+ auto &a();
+ __builtin_memset(a, 'X', 4);
+}
Marek
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: C++ PATCH to fix ICE with memset warning (PR c++/77321)
2016-08-22 16:38 C++ PATCH to fix ICE with memset warning (PR c++/77321) Marek Polacek
@ 2016-08-22 21:51 ` Marek Polacek
0 siblings, 0 replies; 2+ messages in thread
From: Marek Polacek @ 2016-08-22 21:51 UTC (permalink / raw)
To: GCC Patches, Jason Merrill
On Mon, Aug 22, 2016 at 06:38:10PM +0200, Marek Polacek wrote:
> Here we were crashing because the code wasn't prepared for NULL_TREE types.
> Thus fixed in a rather obvious way.
Bernd approved the patch in the BZ, but I'm going to commit this version, with
the original unreduced testcase:
2016-08-22 Marek Polacek <polacek@redhat.com>
PR c++/77321
* c-common.c (warn_for_memset): Check type for null.
* g++.dg/cpp1y/pr77321.C: New test.
diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 32468ca..3feb910 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -11991,7 +11991,7 @@ warn_for_memset (location_t loc, tree arg0, tree arg2,
if (TREE_CODE (arg0) == ADDR_EXPR)
arg0 = TREE_OPERAND (arg0, 0);
tree type = TREE_TYPE (arg0);
- if (TREE_CODE (type) == ARRAY_TYPE)
+ if (type != NULL_TREE && TREE_CODE (type) == ARRAY_TYPE)
{
tree elt_type = TREE_TYPE (type);
tree domain = TYPE_DOMAIN (type);
diff --git gcc/testsuite/g++.dg/cpp1y/pr77321.C gcc/testsuite/g++.dg/cpp1y/pr77321.C
index e69de29..b25f492 100644
--- gcc/testsuite/g++.dg/cpp1y/pr77321.C
+++ gcc/testsuite/g++.dg/cpp1y/pr77321.C
@@ -0,0 +1,24 @@
+// PR c++/77321
+// { dg-do compile { target c++14 } }
+// { dg-options "-Wall" }
+
+extern "C" void *memset (void *, int, __SIZE_TYPE__);
+extern "C" void *malloc(__SIZE_TYPE__);
+
+struct S {
+ char *a;
+};
+
+template <typename T>
+void Test(T & Obj) {
+ auto && a(Obj.a);
+ a = (char*)::malloc(1024 * 1024);
+ ::memset(a + 28, 'X', 6);
+}
+
+int main()
+{
+ S d;
+ Test(d);
+ return 0;
+}
Marek
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-08-22 21:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-22 16:38 C++ PATCH to fix ICE with memset warning (PR c++/77321) Marek Polacek
2016-08-22 21:51 ` Marek Polacek
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).