diff mbox series

c/100803 - diagnose invalid GIMPLE condition

Message ID qso89860-qpsp-r0q2-n07n-rr22n98566r@fhfr.qr
State New
Headers show
Series c/100803 - diagnose invalid GIMPLE condition | expand

Commit Message

Richard Biener May 28, 2021, 12:24 p.m. UTC
another easy fix for GIMPLE FE parser robustness.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

2021-05-28  Richard Biener   <rguenther@suse.de>

	PR c/100803
gcc/c/
	* gimple-parser.c (c_parser_gimple_paren_condition): Diagnose
	invalid if conditions.

gcc/testsuite/
	* gcc.dg/gimplefe-error-11.c: New testcase.
---
 gcc/c/gimple-parser.c                    |  8 ++++++++
 gcc/testsuite/gcc.dg/gimplefe-error-11.c | 12 ++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/gimplefe-error-11.c
diff mbox series

Patch

diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index dfacf23c40a..c8d9db61f0a 100644
--- a/gcc/c/gimple-parser.c
+++ b/gcc/c/gimple-parser.c
@@ -2112,6 +2112,14 @@  c_parser_gimple_paren_condition (gimple_parser &parser)
   if (! c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
     return error_mark_node;
   tree cond = c_parser_gimple_binary_expression (parser).value;
+  if (cond != error_mark_node
+      && ! COMPARISON_CLASS_P (cond)
+      && ! CONSTANT_CLASS_P (cond)
+      && ! SSA_VAR_P (cond))
+    {
+      c_parser_error (parser, "comparison required");
+      cond = error_mark_node;
+    }
   if (! c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"))
     return error_mark_node;
   return cond;
diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-11.c b/gcc/testsuite/gcc.dg/gimplefe-error-11.c
new file mode 100644
index 00000000000..9c29717676a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gimplefe-error-11.c
@@ -0,0 +1,12 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fgimple" } */
+
+int bar();
+__GIMPLE
+int foo()
+{
+  if (bar()) /* { dg-error "comparison required" } */
+    goto bb1;
+  else
+    goto bb2;
+}