From patchwork Sun Jun 7 23:09:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 481767 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 2B1B614016A for ; Mon, 8 Jun 2015 09:09:46 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=k65N9KxR; 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:from :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; q=dns; s=default; b=K/fbsPJQnT9X+1IW nmBZzownpXMUPGbHpywi7+n0Vcfx8Ti9qxCzPkxcM80g4xZWlmDAKmC5oQ3cvwZk lXsD5ZC2uYyZpDxHyHitYnApBFexEa4Rl+yMHUcrenv2wPBJj5ITWhvP2Be4LJCM 4S5PhQuCMz5eInBWLZ9Es1sgMNs= 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:from :date:to:cc:subject:in-reply-to:message-id:references :mime-version:content-type; s=default; bh=MXvaO60sslJKbwPcBXu1PA wQLF4=; b=k65N9KxR0LnVVLfgsjeUnYXLBRYUfWXeL2Zi5zxoFqT08ytWs2riZm raIgJhQCf+xOWE+4xEBdNj1GAa0Rby+tDVSJAyANiJLx66AWocMj+DOh+G7QY7zR 0Bt8ow4a9h1hGZt3iCtt3pKHQhL/IJRyH/AjNgYBQ2nYhYeYyNXzw= Received: (qmail 50700 invoked by alias); 7 Jun 2015 23:09:37 -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 50691 invoked by uid 89); 7 Jun 2015 23:09:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qk0-f173.google.com Received: from mail-qk0-f173.google.com (HELO mail-qk0-f173.google.com) (209.85.220.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 07 Jun 2015 23:09:35 +0000 Received: by qkoo18 with SMTP id o18so69884294qko.1 for ; Sun, 07 Jun 2015 16:09:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; bh=SqThPeNa+xYnSpYlQQg/T5LU1e4Ai5e1HWmdwwNFFHY=; b=kQDIYd3GaC25Y/DuFP5Y5WNTBITRlwO6qQOE9/+LEHw+PYL2z2KarZJgsml7t9Ao53 Ydkvl0XwVuog+6JtA8DXbAl4pvJhXpTWDPAI8L2eWqc34euYyUbs9o1gI0srG3aZMEpP I55FQ/QKfk+WYPAKUPAixKz/1sXwsxQ6T0m6xTxnfiT0NnStZ1m1cC9W5eMiMfucL945 c7Al/GgkKeIsMxiGfGEKx/BvYSWNfmRhLpUVr9AVCx2pHHJViNMQh2WxFQ74GZi6/vg4 r6CNexMDu3leBUEg8p/FwYuAAngCIIFfID5mZ3mK65xCdjtLvad3en4N6LR1fNVGBelO welg== X-Gm-Message-State: ALoCoQnsm1uJnS6U6XKYyH6CmF/MCGT3M2KvOFF9mWOPH/lzAy5vOYeww8adJVGMDagaPrulhSIM X-Received: by 10.55.40.199 with SMTP id o68mr27301406qko.23.1433718573574; Sun, 07 Jun 2015 16:09:33 -0700 (PDT) Received: from [192.168.1.130] (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by mx.google.com with ESMTPSA id g201sm432204qhc.6.2015.06.07.16.09.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 07 Jun 2015 16:09:32 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Sun, 7 Jun 2015 19:09:27 -0400 (EDT) To: Patrick Palka cc: gcc-patches@gcc.gnu.org, joseph@codesourcery.com, jason@redhat.com, dmalcolm@redhat.com Subject: Re: [PATCH] Refactor -Wmisleading-indentation API and extend coverage In-Reply-To: <1433707596-6988-1-git-send-email-patrick@parcs.ath.cx> Message-ID: References: <1433707596-6988-1-git-send-email-patrick@parcs.ath.cx> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 The new heuristic turns out to trigger a common false positive (see test case below) in many programs. I have applied this diff on top of the original patch to make the heuristic more strict. diff --git a/gcc/c-family/c-indentation.c b/gcc/c-family/c-indentation.c index d3e842b..5532ff4 100644 --- a/gcc/c-family/c-indentation.c +++ b/gcc/c-family/c-indentation.c @@ -390,7 +390,10 @@ should_warn_for_misleading_indentation (const common_token_info &guard_tinfo, unsigned int guard_vis_column; if (!get_visual_column (guard_exploc, &guard_vis_column)) return false; - if (next_stmt_vis_column != guard_vis_column + if (next_stmt_vis_column > guard_vis_column + || (guard_tinfo.keyword == RID_IF + && next_stmt_vis_column < guard_vis_column + && !is_first_nonwhitespace_on_line (guard_exploc)) || (next_tok_type == CPP_OPEN_BRACE && next_stmt_vis_column == guard_vis_column)) return true; diff --git a/gcc/testsuite/c-c++-common/Wmisleading-indentation.c b/gcc/testsuite/c-c++-common/Wmisleading-indentation.c index e8e04e3..fd25102 100644 --- a/gcc/testsuite/c-c++-common/Wmisleading-indentation.c +++ b/gcc/testsuite/c-c++-common/Wmisleading-indentation.c @@ -787,6 +787,13 @@ fn_37 (void) foo (3); } + if (i) + while (i++ < 10000); + foo (5); + + if (i) while (i++ < 10000); + foo (5); + #undef EMPTY #undef FOR_EACH }