aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2021-05-28 13:05:39 +0200
committerRichard Biener <rguenther@suse.de>2021-05-28 14:25:33 +0200
commit8b2b32ab2d8cff4eb0dad0ef4e72e33257574cb6 (patch)
treeaa42c7a633285545c834b2abe8501c42ad11917c /gcc
parentd2a913c76f41692fd0bb955d1768f462133d813a (diff)
downloadgcc-8b2b32ab2d8cff4eb0dad0ef4e72e33257574cb6.zip
gcc-8b2b32ab2d8cff4eb0dad0ef4e72e33257574cb6.tar.gz
gcc-8b2b32ab2d8cff4eb0dad0ef4e72e33257574cb6.tar.bz2
c/100803 - diagnose invalid GIMPLE condition
another easy fix for GIMPLE FE parser robustness. 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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/c/gimple-parser.c8
-rw-r--r--gcc/testsuite/gcc.dg/gimplefe-error-11.c12
2 files changed, 20 insertions, 0 deletions
diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c
index dfacf23..c8d9db6 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 0000000..9c29717
--- /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;
+}