From patchwork Fri Aug 12 19:18:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 109882 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]) by ozlabs.org (Postfix) with SMTP id 788E2B70B1 for ; Sat, 13 Aug 2011 05:18:49 +1000 (EST) Received: (qmail 18273 invoked by alias); 12 Aug 2011 19:18:47 -0000 Received: (qmail 18259 invoked by uid 22791); 12 Aug 2011 19:18:46 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, TW_TM, T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-gw0-f47.google.com (HELO mail-gw0-f47.google.com) (74.125.83.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 12 Aug 2011 19:18:32 +0000 Received: by gwb11 with SMTP id 11so2288639gwb.20 for ; Fri, 12 Aug 2011 12:18:32 -0700 (PDT) MIME-Version: 1.0 Received: by 10.236.115.233 with SMTP id e69mr2946979yhh.16.1313176712153; Fri, 12 Aug 2011 12:18:32 -0700 (PDT) Received: by 10.236.105.229 with HTTP; Fri, 12 Aug 2011 12:18:32 -0700 (PDT) Date: Sat, 13 Aug 2011 00:48:32 +0530 Message-ID: Subject: [PATCH] PR c++/50055: Location information for the throw() specification in a function may be incorrect From: Siddhesh Poyarekar To: gcc-patches@gcc.gnu.org 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 Hi, When the location for throw() exception specification is not the same as the function it is written against, it leads gcov to give incorrect results. See bug 50055 for details of the the same. The following patch makes sure that the exception specification block (nothrow or otherwise) is always associated with the function definition line number. I have a test case included with the patch. I ran the c++ test suite and found no regressions due to this patch. --- Siddhesh cp/ChangeLog: PR c++/50055 * except.c (begin_eh_spec_block): Build EH_SPEC block on the same line as the function. testsuite/ChangeLog: PR c++/50055 * g++.dg/gcov/gcov-7.C: New test. Index: gcc/testsuite/g++.dg/gcov/gcov-7.C =================================================================== --- gcc/testsuite/g++.dg/gcov/gcov-7.C (revision 0) +++ gcc/testsuite/g++.dg/gcov/gcov-7.C (revision 0) @@ -0,0 +1,28 @@ +/* Check that Exception handler specification is not + mapped to the curly braces below the function + declaration. */ + +/* { dg-options "-fprofile-arcs -ftest-coverage" } */ +/* { dg-do run { target native } } */ + +struct foo +{ + foo () throw (int) + { /* count (-) */ + throw (1); + } +}; + +int main () +{ + try + { + foo f; + } + catch ( ...) + { + return 0; + } +} + +/* { dg-final { run-gcov gcov-7.C } } */ Index: gcc/cp/except.c =================================================================== --- gcc/cp/except.c (revision 177613) +++ gcc/cp/except.c (working copy) @@ -527,15 +527,17 @@ begin_eh_spec_block (void) { tree r; + location_t spec_location = DECL_SOURCE_LOCATION (current_function_decl); + /* A noexcept specification (or throw() with -fnothrow-opt) is a MUST_NOT_THROW_EXPR. */ if (TYPE_NOEXCEPT_P (TREE_TYPE (current_function_decl))) { - r = build_stmt (input_location, MUST_NOT_THROW_EXPR, NULL_TREE); + r = build_stmt (spec_location, MUST_NOT_THROW_EXPR, NULL_TREE); TREE_SIDE_EFFECTS (r) = 1; } else - r = build_stmt (input_location, EH_SPEC_BLOCK, NULL_TREE, NULL_TREE); + r = build_stmt (spec_location, EH_SPEC_BLOCK, NULL_TREE, NULL_TREE); add_stmt (r); TREE_OPERAND (r, 0) = push_stmt_list (); return r;