From patchwork Wed Feb 10 19:37:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 1439191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=dd+agFOt; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DbVQM1nvKz9sRf for ; Thu, 11 Feb 2021 06:37:13 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8CE22384800B; Wed, 10 Feb 2021 19:37:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8CE22384800B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1612985828; bh=J8JPuowK8uzjqUlmRnyG0I/RU1PeJcsYYw5/0hLl8fE=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=dd+agFOt58hAXwyuBycipjxITohtuugt8lYifYPnvDAlNuMbfbItEDeeFw9O/F1po GNbj1BiLvcBprt3Qzf7tJJjC3MyvW2BiRn4/z8qe1j0AoZP+8u3wOpAx6PaexdcX28 nT+lnrflCZel0zWhUfK9TE9Owi2C+buXCxW0F3E4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id B25213850435 for ; Wed, 10 Feb 2021 19:37:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B25213850435 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-463-P_z2mTn8OYSsBDGltlcdcA-1; Wed, 10 Feb 2021 14:37:04 -0500 X-MC-Unique: P_z2mTn8OYSsBDGltlcdcA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 83D90100A61E for ; Wed, 10 Feb 2021 19:37:03 +0000 (UTC) Received: from t14s.localdomain.com (ovpn-112-59.phx2.redhat.com [10.3.112.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 239E55D9D0; Wed, 10 Feb 2021 19:37:02 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [committed] libcpp: fix ICE comparing macro locations without column info [PR96391] Date: Wed, 10 Feb 2021 14:37:00 -0500 Message-Id: <20210210193700.1384931-1-dmalcolm@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" PR preprocessor/96391 describes an ICE in the C++ frontend on: #define CONST const #define VOID void typedef CONST VOID *PCVOID; where the typedef line occurs after enough code has been compiled that location_t values are beyond LINE_MAP_MAX_LOCATION_WITH_COLS, and hence no column numbers are available. The issue occurs in linemap_compare_locations when comparing the locations of the "const" and "void" tokens. Upon resolving the LRK_MACRO_EXPANSION_POINT, both have the same location_t, the line of the "typedef" (with no column), and so the l0 == l1 clause is triggered, but they are not from the same macro expansion, leading first_map_in_common to return NULL and triggering the "abort" condition. This patch fixes the issue by checking when the two macro expansion point location_t values are equal that the value <= LINE_MAP_MAX_LOCATION_WITH_COLS and thus has column information, fixing the issue. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r11-7179-g1f5c80883efce5242d892eb771ebb60830d20e0f gcc/testsuite/ChangeLog: PR preprocessor/96391 * g++.dg/plugin/location-overflow-test-pr96391.c: New test. * g++.dg/plugin/plugin.exp (plugin_test_list): Add it, using the location_overflow_plugin.c from gcc.dg/plugin. libcpp/ChangeLog: PR preprocessor/96391 * line-map.c (linemap_compare_locations): Require that the location be <= LINE_MAP_MAX_LOCATION_WITH_COLS when treating locations as coming from the same macro expansion. --- .../g++.dg/plugin/location-overflow-test-pr96391.c | 12 ++++++++++++ gcc/testsuite/g++.dg/plugin/plugin.exp | 2 ++ libcpp/line-map.c | 3 ++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/plugin/location-overflow-test-pr96391.c diff --git a/gcc/testsuite/g++.dg/plugin/location-overflow-test-pr96391.c b/gcc/testsuite/g++.dg/plugin/location-overflow-test-pr96391.c new file mode 100644 index 00000000000..18169617c0c --- /dev/null +++ b/gcc/testsuite/g++.dg/plugin/location-overflow-test-pr96391.c @@ -0,0 +1,12 @@ +/* { dg-options "-fplugin-arg-location_overflow_plugin-value=0x60000001" } */ + +/* We use location_overflow_plugin.c, which injects the case that location_t + values have exceeded LINE_MAP_MAX_LOCATION_WITH_COLS, and hence no column + numbers are available. */ + +/* Verify that we're in column-less mode. */ +extern unknown_type test; /* { dg-error "-:'unknown_type' does not name a type" } */ + +#define CONST const +#define VOID void +typedef CONST VOID *PCVOID; diff --git a/gcc/testsuite/g++.dg/plugin/plugin.exp b/gcc/testsuite/g++.dg/plugin/plugin.exp index 80c5355fb5e..5cd4b4bff90 100644 --- a/gcc/testsuite/g++.dg/plugin/plugin.exp +++ b/gcc/testsuite/g++.dg/plugin/plugin.exp @@ -72,6 +72,8 @@ set plugin_test_list [list \ ../../gcc.dg/plugin/diagnostic-test-string-literals-2.c \ ../../gcc.dg/plugin/diagnostic-test-string-literals-3.c \ ../../gcc.dg/plugin/diagnostic-test-string-literals-4.c } \ + { ../../gcc.dg/plugin/location_overflow_plugin.c \ + location-overflow-test-pr96391.c } \ { show_template_tree_color_plugin.c \ show-template-tree-color.C \ show-template-tree-color-labels.C \ diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 2432cd50d26..cccacf2fe5b 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -1417,7 +1417,8 @@ linemap_compare_locations (line_maps *set, if (l0 == l1 && pre_virtual_p - && post_virtual_p) + && post_virtual_p + && l0 <= LINE_MAP_MAX_LOCATION_WITH_COLS) { /* So pre and post represent two tokens that are present in a same macro expansion. Let's see if the token for pre was