From patchwork Mon May 1 18:04:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Maltsev X-Patchwork-Id: 757238 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wGskj3KqSz9sN9 for ; Tue, 2 May 2017 04:04:29 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="g5Kq11PJ"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=R9Wyso4UPj4FHnrGXlMfuH9mhDzw4KfuuBmJDrcJJulK35Z/b1 jXcWOzOuQlEyj4ZzjsPaAzYyf6OUwg/P19qo3OVMn58KUpRq3KtuKiZtZEi+pKtR /aULoJg8UcCGCALM8/CyRdK/9vBXilTlZDp8ZP2S/pMOCKNPVt1ComZrc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=7LJdx6kzBhbRCvu1EBLWtTU212Y=; b=g5Kq11PJR4rJM9X3UDCi rlgSYww4fS0n0fZ2f5k1X9rf2e7xtNItIR8jaRGn9Aey/nwCK8z/e16bWFVFkDkt VHlnNkXpWf2CMgKsxAdZVrMe3+96T1phJ0LapKbiANM6ZplB93+KnSQKwqyn1Lw6 qBVTczVyftL5MmAg9bfJYK0= Received: (qmail 27190 invoked by alias); 1 May 2017 18:04:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 26274 invoked by uid 89); 1 May 2017 18:04:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=U*maltsevm, sk:maltsev, maltsevmgmailcom, maltsevm@gmail.com X-HELO: fencepost.gnu.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (208.118.235.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 01 May 2017 18:04:12 +0000 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37425) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1d5FgD-0003ZF-5t for gcc-patches@gnu.org; Mon, 01 May 2017 14:04:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d5FgB-0003F4-MN for gcc-patches@gnu.org; Mon, 01 May 2017 14:04:12 -0400 Received: from mail-lf0-x22b.google.com ([2a00:1450:4010:c07::22b]:34100) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d5FgB-0003Eu-BL for gcc-patches@gnu.org; Mon, 01 May 2017 14:04:11 -0400 Received: by mail-lf0-x22b.google.com with SMTP id t144so63587030lff.1 for ; Mon, 01 May 2017 11:04:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version; bh=OH2TTsjLxvmT+86udemuFCQnO/jwIoWtsCjXdKCEoWU=; b=ZSF8xfO28jdNmpVox4pB/yYy3SL/8Fnl+7qYwQFWly1wHS6NyC45F8R/tEaCbjR+sK kP5yPXwfVveDNDcGFwkCUmpBjR361ytIE1rlJpwEz4vnwckY0js5SHBmN5DzhaLdl/78 JppnpgidhOdszpMpiTp8ExbUfKGA3qnwkY8/PHlVsJ1V56ljP8rOOCfwKMh2HDoHEkEV LIv3/rquyZY3iidc3bQ87wfghnELvW4hdf+QZZ+7h7l+Kc5Ek/npxHi3CO9k4yNQIeRi HMKPlhQDuVCa2X7+E18/jOP4i1jtJafhxmq7gzjkaMSkHsbAiW0ePV7I/3Vy22TnYZNL yH6g== X-Gm-Message-State: AN3rC/5vWKXjejspq27nSp5LCPPtCxhSwvGRuEN5f4RSYs2LxRZFoZcK f1SjEvvl76hGTw== X-Received: by 10.46.88.76 with SMTP id x12mr9551026ljd.90.1493661850071; Mon, 01 May 2017 11:04:10 -0700 (PDT) Received: from [192.168.123.200] ([77.41.78.126]) by smtp.gmail.com with ESMTPSA id r38sm2843839lfi.67.2017.05.01.11.04.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 May 2017 11:04:09 -0700 (PDT) To: gcc-patches , Richard Biener , Prathamesh Kulkarni From: Mikhail Maltsev Subject: [PATCH 1/5][GIMPLE FE] PR testsuite/80580. Handle missing labels in goto statements Message-ID: <9e3b3ee6-0c67-f974-c38e-7f9f25249914@gmail.com> Date: Mon, 1 May 2017 21:04:07 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::22b X-IsSubscribed: yes The first problem happens because we don't check for missing labels when parsing 'goto' statements. I.e.: __GIMPLE() void fn1() { if (1) goto } The fix is pretty obvious: just add a check. My question is: which functions should I use to produce diagnostics? The surrounding code uses 'c_parser_error', but this function does not handle locations very well (in fact, it uses input_location). diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index 0d6384b..a99b502 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -1315,6 +1315,11 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq *seq) loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); label = c_parser_peek_token (parser)->value; + if (! label) + { + c_parser_error (parser, "expected label"); + return; + } t_label = lookup_label_for_goto (loc, label); c_parser_consume_token (parser); if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) @@ -1339,6 +1344,11 @@ c_parser_gimple_if_stmt (c_parser *parser, gimple_seq *seq) loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); label = c_parser_peek_token (parser)->value; + if (! label) + { + c_parser_error (parser, "expected label"); + return; + } f_label = lookup_label_for_goto (loc, label); c_parser_consume_token (parser); if (! c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-4.c b/gcc/testsuite/gcc.dg/gimplefe-error-4.c new file mode 100644 index 0000000..c61539c --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-error-4.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +__GIMPLE() void fn1() { + if (1) + goto +} /* { dg-error "expected label" } */ diff --git a/gcc/testsuite/gcc.dg/gimplefe-error-5.c b/gcc/testsuite/gcc.dg/gimplefe-error-5.c new file mode 100644 index 0000000..7398861 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-error-5.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +__GIMPLE() void fn1() { + if (1) + goto lbl; + else + goto +} /* { dg-error "expected label" } */