This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix middle-end/81737
- From: Marek Polacek <polacek at redhat dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 7 Aug 2017 10:47:51 +0200
- Subject: [PATCH] Fix middle-end/81737
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=polacek at redhat dot com
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ECB8F7F6A2
In my recent change I failed to check whether the type domain
of a type is non-NULL and this goof causes crashing on this
testcase.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2017-08-07 Marek Polacek <polacek@redhat.com>
PR middle-end/81737
* fold-const.c (fold_indirect_ref_1): Check type_domain.
* gcc.dg/pr81737.c: New test.
diff --git gcc/fold-const.c gcc/fold-const.c
index d563ba76766..8eaea6cce3a 100644
--- gcc/fold-const.c
+++ gcc/fold-const.c
@@ -14107,8 +14107,10 @@ fold_indirect_ref_1 (location_t loc, tree type, tree op0)
&& type == TREE_TYPE (op00type))
{
tree type_domain = TYPE_DOMAIN (op00type);
- tree min = TYPE_MIN_VALUE (type_domain);
- if (min && TREE_CODE (min) == INTEGER_CST)
+ tree min;
+ if (type_domain != NULL_TREE
+ && (min = TYPE_MIN_VALUE (type_domain))
+ && TREE_CODE (min) == INTEGER_CST)
{
offset_int off = wi::to_offset (op01);
offset_int el_sz = wi::to_offset (TYPE_SIZE_UNIT (type));
diff --git gcc/testsuite/gcc.dg/pr81737.c gcc/testsuite/gcc.dg/pr81737.c
index e69de29bb2d..493358956ef 100644
--- gcc/testsuite/gcc.dg/pr81737.c
+++ gcc/testsuite/gcc.dg/pr81737.c
@@ -0,0 +1,6 @@
+/* PR middle-end/81737 */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+extern int a[];
+void fn1() { (a + 0)[1]; }
Marek