From patchwork Wed Dec 16 13:55:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1417183 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; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=r0Jz4Vos; 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 4CwxTy0Xtcz9sRR for ; Thu, 17 Dec 2020 00:55:31 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7CB31383E809; Wed, 16 Dec 2020 13:55:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id 1C6A638708E1 for ; Wed, 16 Dec 2020 13:55:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1C6A638708E1 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qk1-x731.google.com with SMTP id d14so21824484qkc.13 for ; Wed, 16 Dec 2020 05:55:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=eQMRmj262euXezeccXVHFPzcV5DYhnmD/S3xNq6A/Fs=; b=r0Jz4VospdQeQlCuPeuVgLzazRSwS055NWgfzM/Ip+diggslS3e+xzYgwKiqMj0jx5 y72W+LbTKmVk2vSdMiJdMEk9TA28Ao0EgtJcdpk+FrJqd+GtedN5l1CRGz7FDtRB1/IP bnF4zT1xYkn7knOYB3vuKqTNgwTiNDeEaL0IjJc4bRAGIYN40WM5Crzpd8rEnM1cQ3aJ 38FGZF8hms7nHn2Ve7HQvsMVYEDbjY+qbI7EWiS1yJ3h+pqqppnVDGDq2MrAHe1E0nRH BwUPQ8vxjrNKKDj/Xqism3r+5ZQ6LcHW5zMRQ8mpOLh7HgzaWYnaqhhBdKabz5whXkT3 hEiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=eQMRmj262euXezeccXVHFPzcV5DYhnmD/S3xNq6A/Fs=; b=rfnfPbs4jjQueKtmhVjmpl5csBiUMKJ8wyD848WoQnxKHwB0ZJ1xyUE9lMOceQmt4e +u7x3/J7yD8xVav9gYPhwlIeP/b7nZ4Ez1seYtpIcXQ99KirSlTbJvqYZJ8K2gRGI8x4 Bh6D10c4NVUBrxDV98MMBB94kQXSgaGYkB6LKiRkIYihIKnG5L51yKZ77apRllz1j+/m 73nGl/4zDgVdKsLomxXhOfN2p1yvs7rcxu4eG0z4rK0R9NhM4deNr4M7XSocHiRAcLdg 3Vxt9FKDb0+1q1nsEO/1vAWKoFFD1zUPlPfbXUIGCjBKe2i3pj48ew1FkzEswn0E0AQ9 petA== X-Gm-Message-State: AOAM533v1nin3HEqzZdrLLUITpE0SrnbNtr80QnASxzz5KOyp8M44vTX JW9gUzYy3RJtcfv919lz4lc= X-Google-Smtp-Source: ABdhPJxcUj/m7RTB3CAlhTmwpA99wmptU9wrLuKUsF/ZZVUFYsrpd80QzKx1ZRGnKhKUfhpo1AC/dA== X-Received: by 2002:a05:620a:1512:: with SMTP id i18mr45607468qkk.470.1608126926167; Wed, 16 Dec 2020 05:55:26 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:58ca:9b62:2bcb:bb64? ([2620:10d:c091:480::1:a32c]) by smtp.googlemail.com with ESMTPSA id m8sm1134816qkn.41.2020.12.16.05.55.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 16 Dec 2020 05:55:24 -0800 (PST) To: GCC Patches , =?utf-8?q?Martin_Li=C5=A1ka?= From: Nathan Sidwell Subject: c++: Fix detailed-mem-stat breakage Message-ID: <452d458b-9809-6bef-e772-ff6335192430@acm.org> Date: Wed, 16 Dec 2020 08:55:23 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" module.cc has a static initializer that ends up in a circular dependency when detailed mem stats are enabled. This removes the need for that initializer to be dynamic, and we punt to the lazy initializing we already had inside the object in question anyway. At the cost of an additional indirection. gcc/cp/ * module.cc (loc_spans): Make spans a pointer, not inline. Adjust all accesses. pushing to trunk diff --git i/gcc/cp/module.cc w/gcc/cp/module.cc index 1b40a72a0d6..d2806966e43 100644 --- i/gcc/cp/module.cc +++ w/gcc/cp/module.cc @@ -3273,32 +3273,34 @@ public: }; private: - vec spans; + vec *spans; public: loc_spans () + /* Do not preallocate spans, as that causes + --enable-detailed-mem-stats problems. */ + : spans (nullptr) { - spans.create (20); } ~loc_spans () { - spans.release (); + delete spans; } public: span &operator[] (unsigned ix) { - return spans[ix]; + return (*spans)[ix]; } unsigned length () const { - return spans.length (); + return spans->length (); } public: bool init_p () const { - return spans.length () != 0; + return spans != nullptr; } /* Initializer. */ void init (const line_maps *lmaps, const line_map_ordinary *map); @@ -3321,7 +3323,7 @@ public: public: location_t main_start () const { - return spans[SPAN_MAIN].ordinary.first; + return (*spans)[SPAN_MAIN].ordinary.first; } public: @@ -13656,7 +13658,8 @@ void loc_spans::init (const line_maps *lmaps, const line_map_ordinary *map) { gcc_checking_assert (!init_p ()); - spans.reserve (20); + spans = new vec (); + spans->reserve (20); span interval; interval.ordinary.first = 0; @@ -13668,10 +13671,10 @@ loc_spans::init (const line_maps *lmaps, const line_map_ordinary *map) = MAP_START_LOCATION (LINEMAPS_ORDINARY_MAP_AT (line_table, 0)); interval.macro.first = interval.macro.second; dump (dumper::LOCATION) - && dump ("Fixed span %u ordinary:[%u,%u) macro:[%u,%u)", spans.length (), + && dump ("Fixed span %u ordinary:[%u,%u) macro:[%u,%u)", spans->length (), interval.ordinary.first, interval.ordinary.second, interval.macro.first, interval.macro.second); - spans.quick_push (interval); + spans->quick_push (interval); /* A span for command line & forced headers. */ interval.ordinary.first = interval.ordinary.second; @@ -13682,18 +13685,18 @@ loc_spans::init (const line_maps *lmaps, const line_map_ordinary *map) interval.macro.first = LINEMAPS_MACRO_LOWEST_LOCATION (lmaps); } dump (dumper::LOCATION) - && dump ("Pre span %u ordinary:[%u,%u) macro:[%u,%u)", spans.length (), + && dump ("Pre span %u ordinary:[%u,%u) macro:[%u,%u)", spans->length (), interval.ordinary.first, interval.ordinary.second, interval.macro.first, interval.macro.second); - spans.quick_push (interval); + spans->quick_push (interval); /* Start an interval for the main file. */ interval.ordinary.first = interval.ordinary.second; interval.macro.second = interval.macro.first; dump (dumper::LOCATION) - && dump ("Main span %u ordinary:[%u,*) macro:[*,%u)", spans.length (), + && dump ("Main span %u ordinary:[%u,*) macro:[*,%u)", spans->length (), interval.ordinary.first, interval.macro.second); - spans.quick_push (interval); + spans->quick_push (interval); } /* Reopen the span, if we want the about-to-be-inserted set of maps to @@ -13727,9 +13730,9 @@ loc_spans::open (location_t hwm = UNKNOWN_LOCATION) interval.ordinary_delta = interval.macro_delta = 0; dump (dumper::LOCATION) && dump ("Opening span %u ordinary:[%u,... macro:...,%u)", - spans.length (), interval.ordinary.first, + spans->length (), interval.ordinary.first, interval.macro.second); - spans.safe_push (interval); + spans->safe_push (interval); } /* Close out the current linemap interval. The last maps are within @@ -13738,7 +13741,7 @@ loc_spans::open (location_t hwm = UNKNOWN_LOCATION) void loc_spans::close () { - span &interval = spans.last (); + span &interval = spans->last (); interval.ordinary.second = ((line_table->highest_location + (1 << line_table->default_range_bits)) @@ -13746,7 +13749,7 @@ loc_spans::close () interval.macro.first = LINEMAPS_MACRO_LOWEST_LOCATION (line_table); dump (dumper::LOCATION) && dump ("Closing span %u ordinary:[%u,%u) macro:[%u,%u)", - spans.length () - 1, + spans->length () - 1, interval.ordinary.first,interval.ordinary.second, interval.macro.first, interval.macro.second); } @@ -13757,12 +13760,12 @@ loc_spans::close () const loc_spans::span * loc_spans::ordinary (location_t loc) { - unsigned len = spans.length (); + unsigned len = spans->length (); unsigned pos = 0; while (len) { unsigned half = len / 2; - const span &probe = spans[pos + half]; + const span &probe = (*spans)[pos + half]; if (loc < probe.ordinary.first) len = half; else if (loc < probe.ordinary.second) @@ -13782,12 +13785,12 @@ loc_spans::ordinary (location_t loc) const loc_spans::span * loc_spans::macro (location_t loc) { - unsigned len = spans.length (); + unsigned len = spans->length (); unsigned pos = 0; while (len) { unsigned half = len / 2; - const span &probe = spans[pos + half]; + const span &probe = (*spans)[pos + half]; if (loc >= probe.macro.second) len = half; else if (loc >= probe.macro.first)