[PATCH 4/5][GIMPLE FE] PR testsuite/80580. Handle invalid __MEM

Mikhail Maltsev maltsevm@gmail.com
Mon May 1 18:08:00 GMT 2017


This patch deals with invalid __MEM construct. Before we start building an
expression for __MEM, we must check that parsing succeeded and that the __MEM
operand is a pointer.

-- 
Regards,
   Mikhail Maltsev


gcc/c/ChangeLog:

2017-05-01  Mikhail Maltsev  <maltsevm@gmail.com>

	* gimple-parser.c (c_parser_gimple_postfix_expression): Handle
	invalid __MEM.

gcc/testsuite/ChangeLog:

2017-05-01  Mikhail Maltsev  <maltsevm@gmail.com>

	* gcc.dg/gimplefe-error-9.c: New test.



-------------- next part --------------
From fc2fe1f2f74ce399f9617fb526668bf1d57b0162 Mon Sep 17 00:00:00 2001
From: Mikhail Maltsev <maltsevm@gmail.com>
Date: Fri, 24 Feb 2017 20:45:45 +0300
Subject: [PATCH 4/5] GIMPLEFE: handle invalid __MEM

---
 gcc/c/gimple-parser.c                   | 10 ++++++++++
 gcc/testsuite/gcc.dg/gimplefe-error-9.c |  7 +++++++
 2 files changed, 17 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/gimplefe-error-9.c

diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index 5249e8a..f3af840 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -804,6 +804,16 @@ c_parser_gimple_postfix_expression (c_parser *parser)
 			}
 		    }
 		  ptr = c_parser_gimple_unary_expression (parser);
+		  if (ptr.value == error_mark_node
+		      || ! POINTER_TYPE_P (TREE_TYPE (ptr.value)))
+		    {
+		      if (ptr.value != error_mark_node)
+			error_at (ptr.get_start (),
+				  "invalid type of %<__MEM%> operand");
+		      c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
+						 "expected %<)%>");
+		      return expr;
+		    }
 		  if (! alias_type)
 		    alias_type = TREE_TYPE (ptr.value);
 		  /* Optional constant offset.  */
diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-9.c b/gcc/testsuite/gcc.dg/gimplefe-error-9.c
new file mode 100644
index 0000000..2bdb398
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-error-9.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+__GIMPLE() void a()
+{
+  __MEM() = 0; /* { dg-error "expected .<." } */
+}
-- 
2.1.4



More information about the Gcc-patches mailing list