From patchwork Mon Dec 5 12:26:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 86556 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1448110qgi; Mon, 5 Dec 2016 04:27:25 -0800 (PST) X-Received: by 10.84.206.37 with SMTP id f34mr124714521ple.127.1480940845435; Mon, 05 Dec 2016 04:27:25 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 68si14515386pfn.75.2016.12.05.04.27.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Dec 2016 04:27:25 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-443470-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-443470-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-443470-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=ZBTwSdgh5ohpUKaJO QsEg/QVdRlQB6nkdh0HS267Ef16gEuMvINrXjvT7QXI35Yce+Gy8VKRIrfMbgRAJ d5g6CBZpTiyv9gquXvp7pFECb5OeB03Rv7U27urj7OD8/ODU8sj0S7IP+/WmNLtA HDVGkroLBjg7YUA75SKjAPKyGc= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=goswKzdnNLHOr8DwfSoj3a7 x0LU=; b=HilduZioXU1vX/6mjMWxedLZX6wjT8bKUCPOdooyOAToSWEjBMMSdGu 0p7SvFV3zbN/jC8NH7mOmVgw4g02zSs1r/bCBgZNyero7WyijN0aPUmeM/x7/WE+ u/LVxBVXdcEvbDIJYnnX0ohyzbMArsS30QdoLUIeIyLQhfRNEURg= Received: (qmail 12368 invoked by alias); 5 Dec 2016 12:27:03 -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 12270 invoked by uid 89); 5 Dec 2016 12:27:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=H*RU:sk:mail-yb, Hx-spam-relays-external:sk:mail-yb, HX-HELO:sk:mail-yb, 13717 X-HELO: mail-yb0-f193.google.com Received: from mail-yb0-f193.google.com (HELO mail-yb0-f193.google.com) (209.85.213.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Dec 2016 12:26:52 +0000 Received: by mail-yb0-f193.google.com with SMTP id d128so7269342ybh.3 for ; Mon, 05 Dec 2016 04:26:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to; bh=ZXW0U4rGQcfH5/mwEnGqTD6IV5x4//xtgRg9GsoWMGo=; b=ZYXSA1vCOH98clsVx/INdQeQ/6vC38h4BEGKgsM9T6Faow13ki/2pmcXAKb0dqa0Ur o8359Xnx4xmkiV2m9Km+Y0dHv3SQ0jzmTkM2VTWPp9o9oYLz6SIIuQPoXUIRXZ8hFiF9 Mn20NOElv6PLQmCs0QKY5Wg/Kv3ubnHGundAKTQ0w+0727S9wML2GC+Do73RP8pGK5Vy lsq+5QEPU8FLAHvJ0GiK82KhigA+sGkyjAwR5P3+Tvj80bVaGeH7cmppV7sXlb7MKwiv d8wc60uQwpUN9oE0IBNI+p/4nuiD/mTVe2btsBqB363ykSPnFMId4+QR+q1kRhid0Rd+ hmiA== X-Gm-Message-State: AKaTC03ZPTlelO8jidGAQ+uW2NE2lm4AZjxCNj+RiRXfJmxc7nhiOnblmeNvrpd/YaysZw== X-Received: by 10.37.252.28 with SMTP id v28mr28001277ybd.145.1480940810707; Mon, 05 Dec 2016 04:26:50 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::a:6eb0]) by smtp.googlemail.com with ESMTPSA id g9sm6707894ywa.47.2016.12.05.04.26.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Dec 2016 04:26:49 -0800 (PST) Subject: Re: [PATCH] fix -fmax-errors & notes, take 2 To: Bernd Schmidt , dmalcolm@redhat.com, schwab@linux-m68k.org References: <95ebd046-fb7c-174d-51fb-3e94b72e27bc@acm.org> Cc: GCC Patches From: Nathan Sidwell Message-ID: Date: Mon, 5 Dec 2016 07:26:48 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: On 12/02/2016 09:07 AM, Bernd Schmidt wrote: > Arguments should be documented. I really must get into the habit of adding FIXME when writing dev comments. >> + if (count >= (int) context->max_errors) > > Looks like there are some unnecessary type mismatches leading to this > cast. Maybe declare max_errors as int and remove the cast? Yeah, you'll see the original code had similar problems. Fixed as you suggest. committed the attached. nathan -- Nathan Sidwell 2016-12-05 Nathan Sidwell gcc/ * diagnostic.c (diagnostic_check_max_errors): New, broken out of ... (diagnostic_action_after_output): ... here. (diagnostic_report_diagnostic): Call it for non-notes. * diagnostic.h (struct diagnostic_context): Make max_errors signed int. (diagnostic_check_max_errors): Declare. gcc/fortran/ * error.c (gfc_warning_check): Call diagnostic_check_max_errors. (gfc_error_check): Likewise. gcc/testsuite/ * c-c++-common/fmax_errors.c: Check notes after last error are emitted. Index: gcc/diagnostic.c =================================================================== --- gcc/diagnostic.c (revision 243253) +++ gcc/diagnostic.c (working copy) @@ -446,6 +446,31 @@ bt_err_callback (void *data ATTRIBUTE_UN errnum == 0 ? "" : xstrerror (errnum)); } +/* Check if we've met the maximum error limit, and if so fatally exit + with a message. CONTEXT is the context to check, and FLUSH + indicates whether a diagnostic_finish call is needed. */ + +void +diagnostic_check_max_errors (diagnostic_context *context, bool flush) +{ + if (!context->max_errors) + return; + + int count = (diagnostic_kind_count (context, DK_ERROR) + + diagnostic_kind_count (context, DK_SORRY) + + diagnostic_kind_count (context, DK_WERROR)); + + if (count >= context->max_errors) + { + fnotice (stderr, + "compilation terminated due to -fmax-errors=%u.\n", + context->max_errors); + if (flush) + diagnostic_finish (context); + exit (FATAL_EXIT_CODE); + } +} + /* Take any action which is expected to happen after the diagnostic is written out. This function does not always return. */ void @@ -470,18 +495,6 @@ diagnostic_action_after_output (diagnost diagnostic_finish (context); exit (FATAL_EXIT_CODE); } - if (context->max_errors != 0 - && ((unsigned) (diagnostic_kind_count (context, DK_ERROR) - + diagnostic_kind_count (context, DK_SORRY) - + diagnostic_kind_count (context, DK_WERROR)) - >= context->max_errors)) - { - fnotice (stderr, - "compilation terminated due to -fmax-errors=%u.\n", - context->max_errors); - diagnostic_finish (context); - exit (FATAL_EXIT_CODE); - } break; case DK_ICE: @@ -890,6 +903,9 @@ diagnostic_report_diagnostic (diagnostic return false; } + if (diagnostic->kind != DK_NOTE) + diagnostic_check_max_errors (context); + context->lock++; if (diagnostic->kind == DK_ICE || diagnostic->kind == DK_ICE_NOBT) Index: gcc/diagnostic.h =================================================================== --- gcc/diagnostic.h (revision 243253) +++ gcc/diagnostic.h (working copy) @@ -143,7 +143,7 @@ struct diagnostic_context bool dc_warn_system_headers; /* Maximum number of errors to report. */ - unsigned int max_errors; + int max_errors; /* This function is called before any message is printed out. It is responsible for preparing message prefix and such. For example, it @@ -320,6 +320,7 @@ void default_diagnostic_start_span_fn (d void default_diagnostic_finalizer (diagnostic_context *, diagnostic_info *); void diagnostic_set_caret_max_width (diagnostic_context *context, int value); void diagnostic_action_after_output (diagnostic_context *, diagnostic_t); +void diagnostic_check_max_errors (diagnostic_context *, bool flush = false); void diagnostic_file_cache_fini (void); Index: gcc/fortran/error.c =================================================================== --- gcc/fortran/error.c (revision 243253) +++ gcc/fortran/error.c (working copy) @@ -1226,6 +1226,7 @@ gfc_warning_check (void) diagnostic_action_after_output (global_dc, warningcount_buffered ? DK_WARNING : DK_ERROR); + diagnostic_check_max_errors (global_dc, true); } } @@ -1370,6 +1371,7 @@ gfc_error_check (void) gcc_assert (gfc_output_buffer_empty_p (pp_error_buffer)); pp->buffer = tmp_buffer; diagnostic_action_after_output (global_dc, DK_ERROR); + diagnostic_check_max_errors (global_dc, true); return true; } Index: gcc/testsuite/c-c++-common/fmax-errors.c =================================================================== --- gcc/testsuite/c-c++-common/fmax-errors.c (revision 243253) +++ gcc/testsuite/c-c++-common/fmax-errors.c (working copy) @@ -1,11 +1,21 @@ /* PR c/44782 */ /* { dg-do compile } */ -/* { dg-options "-fmax-errors=3" } */ +/* { dg-options "-fmax-errors=3 -Wall" } */ void foo (unsigned int i, unsigned int j) { (i) (); /* { dg-error "" } */ (j) (); /* { dg-error "" } */ - (i+j) (); /* { dg-error "" } */ + + i + j; /* { dg-warning "" } */ + + (k) (); /* { dg-error "" } */ + /* Make sure we see the notes related to the final error we emit. */ + /* { dg-message "identifier" "" { target c } 12 } */ + + /* Warnings after the final error should not appear. */ + i + j; /* no warning. */ + (i*j) (); /* no error here due to -fmax-errors */ + } /* { dg-prune-output "compilation terminated" } */