From patchwork Tue Mar 28 06:27:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 744092 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 3vsgvC6Vhhz9s7K for ; Tue, 28 Mar 2017 17:28:21 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="NsdWKz39"; 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:cc:message-id:date:mime-version:content-type; q= dns; s=default; b=uQV7dtv2BBru2t9jQRTVpoP+xvtsLjaUGaPFvjSsm659cx /YRURuWbBKcHoOADM54n85ZCssHzM/aNKzrz3ZKX+YJedFVhpQc4uxv8YoM20hDk dBXWXPJ9OwIBfbY/ZMe8N5cVAxce/Auhv3QZLAg3egOJyt8hpRd1DxJoxFukc= 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:cc:message-id:date:mime-version:content-type; s= default; bh=7sgspiUMge5mPyoOZq9t7uOJTSA=; b=NsdWKz39m+UYtRgPzX2z YXitifILAeaNsYCvlR5qrGANvyK5eN1Cf3OLlsnDWeyRWnRcHELT2OchEJPyDVB/ +05R6qqfq9cSFb6noc8ApvS1SXCXb0+0HE5ncaSLHt8VwCkOABNcce9qDboPa4l1 IkxSBYfiu4FRgmAJiGFEICU= Received: (qmail 109273 invoked by alias); 28 Mar 2017 06:28:08 -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 109163 invoked by uid 89); 28 Mar 2017 06:28:07 -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, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 28 Mar 2017 06:28:05 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-04.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1cskbr-0000Xx-Ne from Tom_deVries@mentor.com ; Mon, 27 Mar 2017 23:28:03 -0700 Received: from [127.0.0.1] (137.202.0.87) by SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Tue, 28 Mar 2017 07:27:59 +0100 To: Mike Stump , Rainer Orth From: Tom de Vries Subject: [PATCH, testsuite] Allow braces around relative line numbers CC: GCC Patches Message-ID: <31cf86fd-eda4-e373-5263-a3b36854109e@mentor.com> Date: Tue, 28 Mar 2017 08:27:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) Hi, this patch fixes testsuite PR80220 - "relative line numbers don't work when put between braces". Consider gcc/testsuite/gcc.dg/990506-0.c, which has absolute line numbers between braces: ... $ cat -n 990506-0.c 1 /* Verify that a diagnostic is issued without crashing due to 2 --enable-checking catching a bug in the C front end. */ 3 /* { dg-do compile } */ 4 x() 5 { 6 foo (i); 7 /* { dg-error "undeclared" "undeclared-variable message" { target *-*-* } { 6 } } */ 8 /* { dg-message "function it appears in" "reminder message" { target *-*-* } { 6 } } */ 9 } ... When we rewrite the test to use relative line numbers: ... *-*-* } { .-1 } } */ + /* { dg-message "function it appears in" "reminder message" { target *-*-* } { .-2 } } */ } ... we run into trouble: ... ERROR: gcc.dg/990506-0.c: expected integer but got " .-1 " for " dg-error 7 "undeclared" "undeclared-variable message" { target *-*-* } { .-1 } " ... The problem is that the relative line number is written between braces, which results in whitespace before and after the number, and the relative line number handling in process-message doesn't handle that whitespace well. This patch fixes that. Bootstrapped and reg-tested on x86_64. OK for stage4 or stage1 trunk? Thanks, - Tom Allow braces around relative line numbers 2017-03-27 Tom de Vries PR testsuite/80220 * gcc.dg/dg-test-1.c: Add dg-error tests using relative line numbers between braces. (foo2): New function. * lib/gcc-dg.exp (process-message): Handle whitespace in relative line number argument. --- gcc/testsuite/gcc.dg/dg-test-1.c | 7 +++++++ gcc/testsuite/lib/gcc-dg.exp | 16 +++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/gcc/testsuite/gcc.dg/dg-test-1.c b/gcc/testsuite/gcc.dg/dg-test-1.c index c67f93b..2414ecc 100644 --- a/gcc/testsuite/gcc.dg/dg-test-1.c +++ b/gcc/testsuite/gcc.dg/dg-test-1.c @@ -40,3 +40,10 @@ baz (int i, int j) /* { dg-warning "unused parameter 'j'" "warn6" { target *-*-* } .-10 } */ + +/* Test for relative line numbers in braces */ +void +foo2 (void) +{ /* { dg-error "'a' undeclared" "err1" { target *-*-* } { .+1 } } */ + int z = a + b + c; /* { dg-error "'b' undeclared" "err2" { target *-*-* } { . } } */ +} /* { dg-error "'c' undeclared" "err3" { target *-*-* } { .-1 } } */ diff --git a/gcc/testsuite/lib/gcc-dg.exp b/gcc/testsuite/lib/gcc-dg.exp index 83c38cf..e986d64 100644 --- a/gcc/testsuite/lib/gcc-dg.exp +++ b/gcc/testsuite/lib/gcc-dg.exp @@ -988,11 +988,17 @@ if { [info procs saved-dg-error] == [list] \ proc process-message { msgproc msgprefix dgargs } { upvar dg-messages dg-messages - # Handle relative line specification, .+1 or .-1 etc. - if { [llength $dgargs] == 5 - && [regsub "^\.\[+-\](\[0-9\]+)$" [lindex $dgargs 4] "\\1" num] } { - set num [expr [lindex $dgargs 0] [string index [lindex $dgargs 4] 1] $num] - set dgargs [lreplace $dgargs 4 4 $num] + if { [llength $dgargs] == 5 } { + set linenr [lindex $dgargs 4] + # Strip whitespace added by using braces. + set linenr [string trimleft [string trimright $linenr]] + # Handle relative line specification, .+1 or .-1 etc. + if { [regsub "^\.\[+-\](\[0-9\]+)$" $linenr "\\1" num] } { + set directivelinenr [lindex $dgargs 0] + set op [string index $linenr 1] + set linenr [expr $directivelinenr $op $num] + } + set dgargs [lreplace $dgargs 4 4 $linenr] } # Process the dg- directive, including adding the regular expression