From patchwork Wed Jun 16 15:40:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1492966 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@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=cno73EA6; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4G4qDW3RdDz9sWF for ; Thu, 17 Jun 2021 01:41:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2038398081D for ; Wed, 16 Jun 2021 15:41:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2038398081D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623858102; bh=jJqNm1jhbR+zBaH9Tm7h0vnjsmwK3eTSMFoJzCftnII=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=cno73EA69Pt445ikI4qx1vlVTkBjuuWvJ8tNPw5c/aZb/dCVV69yGbLyXm/SAx9OY 4yVc22EAMX6l4ZI/zIGXnUX2hpwJp/4J9WELg9ad1CUe3MnXUNXUHixwmIVEZ5eDbb dfTIpMXjK3HIl/Agt6js1sg//nHuy3gixZKFE54k= 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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id C4BE83891C3F for ; Wed, 16 Jun 2021 15:40:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C4BE83891C3F Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-380-pMKIK2aVOliQeBTG9pyIpw-1; Wed, 16 Jun 2021 11:40:56 -0400 X-MC-Unique: pMKIK2aVOliQeBTG9pyIpw-1 Received: by mail-qk1-f200.google.com with SMTP id 190-20020a3708c70000b02903aa60e6d8c1so2055900qki.19 for ; Wed, 16 Jun 2021 08:40:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jJqNm1jhbR+zBaH9Tm7h0vnjsmwK3eTSMFoJzCftnII=; b=R5dHaTcsywKqfYHjNJHZ42l9zvZeE7u2F1PB1VzWeaYtLHb1N0eP7wgkqdFQoiBLKN Jn7wcphypYZscjoX97yxW57oG8XY9d4GjrNQYcGvSX6mHbi8GkWWWYklMy9KvA1XVsVU 2JsUBnElEXOFRar+2er0vOOH+GgdMJXbbLZv5sH3Ie+t6Ow2apE2TegMFtCYLw7XC32z sHVoTYYhrCEW+NNa8J4nwcuoLu9XVU6hK9AaviU4mKh7zfD7Y09AzISCRW2PfZeMGEnf LezrXnc0TKoiuMX4riBPz1zVRnh0+TuG5EvzTkFBIYMT6OGnPwH34w0Fhu1L1VDyjyNf rBxw== X-Gm-Message-State: AOAM532EkPtxxiB/nGqrNS34jTO0no1nlozBhY9MF131VpZYK/5Daiqo iFQ79DNEHAnyZMzQA+jEC2z+vGFrbED3FCekIUE9gQO4oP3o5/M9cMv1bx2Lj6bRTHp2UVFkgyT UYvabi7QZNqabxTHDEicoxLiigB6Z+PYHvh7rhI5r2xfUNzO8FL0dfmPYG+tCOtYggw== X-Received: by 2002:ac8:7e81:: with SMTP id w1mr496484qtj.130.1623858055366; Wed, 16 Jun 2021 08:40:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUaemTYSRG2QFs1FuSj8diHdUkPismZu3PHZn7OMRiNHeehjPYaqbRqnBMwHQES78/FJeSmA== X-Received: by 2002:ac8:7e81:: with SMTP id w1mr496455qtj.130.1623858054927; Wed, 16 Jun 2021 08:40:54 -0700 (PDT) Received: from barrymore.cygnus.csb (130-44-159-43.s11817.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id 75sm1797906qkm.57.2021.06.16.08.40.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 08:40:54 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] libcpp: location comparison within macro [PR100796] Date: Wed, 16 Jun 2021 11:40:52 -0400 Message-Id: <20210616154052.2133322-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.1 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_H4, 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The patch for 96391 changed linemap_compare_locations to give up on comparing locations from macro expansions if we don't have column information. But in this testcase, the BOILERPLATE macro is multiple lines long, so we do want to compare locations within the macro. So this patch moves the LINE_MAP_MAX_LOCATION_WITH_COLS check inside the block, to use it for failing gracefully. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/100796 PR preprocessor/96391 libcpp/ChangeLog: * line-map.c (linemap_compare_locations): Only use comparison with LINE_MAP_MAX_LOCATION_WITH_COLS to avoid abort. gcc/testsuite/ChangeLog: * g++.dg/plugin/location-overflow-test-pr100796.c: New test. * g++.dg/plugin/plugin.exp: Run it. --- .../plugin/location-overflow-test-pr100796.c | 25 +++++++++++++++++++ libcpp/line-map.c | 20 ++++++++------- gcc/testsuite/g++.dg/plugin/plugin.exp | 3 ++- 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/plugin/location-overflow-test-pr100796.c base-commit: 3155d51bfd1de8b6c4645dcb2292248a8d7cc3c9 diff --git a/gcc/testsuite/g++.dg/plugin/location-overflow-test-pr100796.c b/gcc/testsuite/g++.dg/plugin/location-overflow-test-pr100796.c new file mode 100644 index 00000000000..7fa964c07e5 --- /dev/null +++ b/gcc/testsuite/g++.dg/plugin/location-overflow-test-pr100796.c @@ -0,0 +1,25 @@ +// PR c++/100796 +// { dg-additional-options "-Wsuggest-override -fplugin-arg-location_overflow_plugin-value=0x60000001" } +// Passing LINE_MAP_MAX_LOCATION_WITH_COLS meant we stopped distinguishing between lines in a macro. + +#define DO_PRAGMA(text) _Pragma(#text) +#define WARNING_PUSH DO_PRAGMA(GCC diagnostic push) +#define WARNING_POP DO_PRAGMA(GCC diagnostic pop) +#define WARNING_DISABLE(text) DO_PRAGMA(GCC diagnostic ignored text) +#define NO_OVERRIDE_WARNING WARNING_DISABLE("-Wsuggest-override") + +#define BOILERPLATE \ + WARNING_PUSH \ + NO_OVERRIDE_WARNING \ + void f(); \ + WARNING_POP + +struct B +{ + virtual void f(); +}; + +struct D: B +{ + BOILERPLATE +}; diff --git a/libcpp/line-map.c b/libcpp/line-map.c index a03d6760a8e..1a6902acdb7 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -1421,23 +1421,25 @@ linemap_compare_locations (line_maps *set, if (l0 == l1 && pre_virtual_p - && post_virtual_p - && l0 <= LINE_MAP_MAX_LOCATION_WITH_COLS) + && post_virtual_p) { /* So pre and post represent two tokens that are present in a same macro expansion. Let's see if the token for pre was before the token for post in that expansion. */ - unsigned i0, i1; const struct line_map *map = first_map_in_common (set, pre, post, &l0, &l1); if (map == NULL) - /* This should not be possible. */ - abort (); - - i0 = l0 - MAP_START_LOCATION (map); - i1 = l1 - MAP_START_LOCATION (map); - return i1 - i0; + /* This should not be possible while we have column information, but if + we don't, the tokens could be from separate macro expansions on the + same line. */ + gcc_assert (l0 > LINE_MAP_MAX_LOCATION_WITH_COLS); + else + { + unsigned i0 = l0 - MAP_START_LOCATION (map); + unsigned i1 = l1 - MAP_START_LOCATION (map); + return i1 - i0; + } } if (IS_ADHOC_LOC (l0)) diff --git a/gcc/testsuite/g++.dg/plugin/plugin.exp b/gcc/testsuite/g++.dg/plugin/plugin.exp index 5cd4b4bff90..74e12df207c 100644 --- a/gcc/testsuite/g++.dg/plugin/plugin.exp +++ b/gcc/testsuite/g++.dg/plugin/plugin.exp @@ -73,7 +73,8 @@ set plugin_test_list [list \ ../../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 } \ + location-overflow-test-pr96391.c \ + location-overflow-test-pr100796.c } \ { show_template_tree_color_plugin.c \ show-template-tree-color.C \ show-template-tree-color-labels.C \