From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 8B50C388A02F; Fri, 28 May 2021 12:25:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B50C388A02F MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-1112] c/100803 - diagnose invalid GIMPLE condition X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: d2a913c76f41692fd0bb955d1768f462133d813a X-Git-Newrev: 8b2b32ab2d8cff4eb0dad0ef4e72e33257574cb6 Message-Id: <20210528122550.8B50C388A02F@sourceware.org> Date: Fri, 28 May 2021 12:25:50 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 May 2021 12:25:50 -0000 https://gcc.gnu.org/g:8b2b32ab2d8cff4eb0dad0ef4e72e33257574cb6 commit r12-1112-g8b2b32ab2d8cff4eb0dad0ef4e72e33257574cb6 Author: Richard Biener Date: Fri May 28 13:05:39 2021 +0200 c/100803 - diagnose invalid GIMPLE condition another easy fix for GIMPLE FE parser robustness. 2021-05-28 Richard Biener 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. Diff: --- gcc/c/gimple-parser.c | 8 ++++++++ gcc/testsuite/gcc.dg/gimplefe-error-11.c | 12 ++++++++++++ 2 files changed, 20 insertions(+) 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; +}