From patchwork Wed Nov 14 14:51:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Matz X-Patchwork-Id: 997780 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-490070-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Hlo1SvDX"; dkim-atps=neutral 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 42w6sH1z8dz9s5c for ; Thu, 15 Nov 2018 01:52:02 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=SgLKG6v4uFups+kmHkOJ5fNLWGsqlkh1UtAg3ThkyM0p+MzyuV11E wqzC7AakPxGVs1wIz6PVLq8Tg20d5FKBs9599zepXEy3VdAUxcFDfinlIOcQdWFC 0RRpWUVdmhy7GEoxYFqmWo/DhjlNfj3hAZBUXdurhBNUKZFpaucW8Y= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=LnJVM1mpgkDsJKvGLMLrcc7lsQ0=; b=Hlo1SvDXCg10jr7ageEf fYObJpklFhpoDI6eeg7UC8uoBhh0UUt9nC/JFLD0QLkazuXn2KUoSf2+UXcL/AbI /I+DshUR3J1GKMN+bBI6dG7d1LkRiYcugw7nQxV4TYU/6j6pjd1JZy/ezFsX2BWb rRu0Rrh7wk2slXLC8XbV0H0= Received: (qmail 66935 invoked by alias); 14 Nov 2018 14:51:55 -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 66562 invoked by uid 89); 14 Nov 2018 14:51:54 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, SPF_PASS autolearn=ham version=3.3.2 spammy=our X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 14 Nov 2018 14:51:48 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 247A7AF0E for ; Wed, 14 Nov 2018 14:51:46 +0000 (UTC) Date: Wed, 14 Nov 2018 14:51:45 +0000 (UTC) From: Michael Matz To: gcc-patches@gcc.gnu.org Subject: Fix PR86575 Message-ID: User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 X-IsSubscribed: yes Hi, our warning code sometimes adds locations to statement which didn't have them before, which can in turn lead to code changes (here only label numbers change). It seems better to not do that from warning code, and here it's easy to do: just return the location we want to use for warnings, don't change it in the statement itself. Regstrapped on x86-64, okay for trunk? Ciao, Michael. PR middle-end/86575 * gimplify.c (collect_fallthrough_labels): Add new argument, return location via that, don't modify statements. (warn_implicit_fallthrough_r): Adjust call, don't use statement location directly. diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 509fc2f3f5be..22dff0e546c9 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1938,10 +1938,12 @@ last_stmt_in_scope (gimple *stmt) static gimple * collect_fallthrough_labels (gimple_stmt_iterator *gsi_p, - auto_vec *labels) + auto_vec *labels, + location_t *prevloc) { gimple *prev = NULL; + *prevloc = UNKNOWN_LOCATION; do { if (gimple_code (gsi_stmt (*gsi_p)) == GIMPLE_BIND) @@ -1978,7 +1980,7 @@ collect_fallthrough_labels (gimple_stmt_iterator *gsi_p, /* It might be a label without a location. Use the location of the scope then. */ if (!gimple_has_location (prev)) - gimple_set_location (prev, bind_loc); + *prevloc = bind_loc; } gsi_next (gsi_p); continue; @@ -2061,6 +2063,8 @@ collect_fallthrough_labels (gimple_stmt_iterator *gsi_p, && (gimple_code (gsi_stmt (*gsi_p)) != GIMPLE_LABEL || !gimple_has_location (gsi_stmt (*gsi_p)))); + if (prev && gimple_has_location (prev)) + *prevloc = gimple_location (prev); return prev; } @@ -2157,7 +2161,8 @@ warn_implicit_fallthrough_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p, /* Vector of labels that fall through. */ auto_vec labels; - gimple *prev = collect_fallthrough_labels (gsi_p, &labels); + location_t prevloc; + gimple *prev = collect_fallthrough_labels (gsi_p, &labels, &prevloc); /* There might be no more statements. */ if (gsi_end_p (*gsi_p)) @@ -2185,8 +2190,8 @@ warn_implicit_fallthrough_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p, /* Try to be clever and don't warn when the statement can't actually fall through. */ && gimple_stmt_may_fallthru (prev) - && gimple_has_location (prev)) - warned_p = warning_at (gimple_location (prev), + && prevloc != UNKNOWN_LOCATION) + warned_p = warning_at (prevloc, OPT_Wimplicit_fallthrough_, "this statement may fall through"); if (warned_p)