From patchwork Sun Nov 3 22:22:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005823 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cmQkocEi; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhTg82jKXz1xxN for ; Mon, 4 Nov 2024 09:24:52 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 98D403857C68 for ; Sun, 3 Nov 2024 22:24:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by sourceware.org (Postfix) with ESMTPS id 6A5733858D39 for ; Sun, 3 Nov 2024 22:22:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A5733858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6A5733858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672565; cv=none; b=xT/zP8q+bQu5tkW4n95KCswHURLJyF+DxGnqX5nlPkG+R77Rcyvoto75Zq+C6yBL6PE3AT3CVCmb4LU0Y3lFLUBV6JAKXof6bBBwyULyxmJ3uSLZRIwwhSzp+U6HmECj/cbc3ibwIzP5IDve2QLolZ7nFHGXJWhdi3tUC7HwlrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672565; c=relaxed/simple; bh=BvpVqgBEwNia7fu7hPbt7qyH+wrN2BFJ7fcTPKoAUn4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=LghUqiXOuFGyIYV1tB+k7ptB4kRHgBB/MKjQV1Kj3tZMNSaEu3QV+yKk7Whbr0jfMbEJvkOlr4dPgSODpHQuJoDkNIL1IaAg2AKS+z7g51l4ELDsstaj/2Cmt8w/J4DRpYWGsvUJRu5n9uxa0NKidrxjUw9Df1P8fxzm8hZ36cg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-6cbcc2bd7fcso25871506d6.1 for ; Sun, 03 Nov 2024 14:22:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672560; x=1731277360; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E7HWIT2HrjpUFD4mrOclEd35slH8lwRXMggs0JPU7YI=; b=cmQkocEiZdwt+FeRBNGiJE3MmaTVWAyP26bDEn8DzBElDzCQuDXS3v+cTViOPhKFAc ndXIBoJlbXdjzkhvp+AgfskBGUt5UViDHTonSXlPj5h0J9IqG/OTewxrlxFW7+2SixG0 DraZFAyJNFHb/vkZqGjl3ypH8yNyxoVd2/JLMyxzOBS4uS9pXjtHiTETyWuFcCKLDvvs elS1bEmU6fHjFYHGxUNvugQoi1IKiaMHOYo7JTJIqcbaDEbfYz1Ek/Hlnzpcg3zukVNv jOcq4GKUD2MamaFBPXIK93u7eU0L5rkuWaLwg1Dn+DzyaeED74bCMl+mcCvmU7/hbPUN dWEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672560; x=1731277360; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E7HWIT2HrjpUFD4mrOclEd35slH8lwRXMggs0JPU7YI=; b=uUruAzFYGrkAF8wkfuWtGhBc0G4WKH2oQsOCNMy2AK1IwGC9QPONGlCHyqk8gMHEOY SGWCwOxemdiGJLrvcX1h3IjR1OVza2SauEYH8LLvr97/ZDSgmUL0LGTOvuALEpuj8dwQ oQwRIsuF7fkZzFfgNRDdfrwHS+O6ptn/u3iM8b5F7N3cGsy3Eyv1dWNXsqAZM0C0+nOR nAR2Tcx7TuQnhTtZlGV9r5/HbWd4xvmkwSl8kOsKSyh2CF6Xax3IKNQ7olCDtAtEp8VC NQe8TvdsGWPFitQ3dGT3ailjh8XX2/Kt0CmaRxO6Lc/4C4uVvX6sZYYQRXsNsg/LMWqd p19g== X-Gm-Message-State: AOJu0Ywb1yK0kepBLtHVAycwsMi1mM7qc8D1KG7T8DYhKElBQbS5bdeJ dp9T2Tohi26oTXJMH2WHnMA5CCeIVO1liW20wkKNrKyjkw6X8bLNDXxOig== X-Google-Smtp-Source: AGHT+IF6qaTYqogVUTYXJ/7yKQcL4iOBcz3xZby0vRU0m1/Vdo/EEO0RL5aHd7UuBLeWSSawKAyUVw== X-Received: by 2002:a05:6214:498b:b0:6ce:348e:a8c4 with SMTP id 6a1803df08f44-6d351b19112mr181403266d6.48.1730672559136; Sun, 03 Nov 2024 14:22:39 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:37 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 01/15] Support for 64-bit location_t: libcpp parts Date: Sun, 3 Nov 2024 17:22:06 -0500 Message-Id: <20241103222220.933471-2-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org This patch adds support in the libcpp line-maps infrastructure for a 64-bit location_t type that is capable of representing more source locations than the current 32-bit location_t. The support will be made configurable at build time in a subsequent patch; for now it will be off by default. libcpp/ChangeLog: * include/line-map.h (location_t): Conditionally make this typedef a 64-bit integer if so configured, and adjust related constants to match. (line_map_uint_t): New typedef, the same type as location_t. (struct line_map): Adjust comments about the struct layout. (struct line_map_macro): Likewise. (struct line_map_ordinary): Likewise, and also reorder the fields to avoid padding in case 64-bit location was configured. (struct maps_info_ordinary): Change member types from "unsigned int" to "line_map_uint_t". (struct maps_info_macro): Likewise. (struct location_adhoc_data_map): Likewise. (LINEMAPS_ALLOCATED): Change return type from "unsigned int" to "line_map_uint_t". (LINEMAPS_ORDINARY_ALLOCATED): Likewise. (LINEMAPS_MACRO_ALLOCATED): Likewise. (LINEMAPS_USED): Likewise. (LINEMAPS_ORDINARY_USED): Likewise. (LINEMAPS_MACRO_USED): Likewise. (linemap_lookup_macro_index): Likewise. (LINEMAPS_MAP_AT): Change argument type from "unsigned int" to "line_map_uint_t". (LINEMAPS_ORDINARY_MAP_AT): Likewise. (LINEMAPS_MACRO_MAP_AT): Likewise. (line_map_new_raw): Likewise. (linemap_module_restore): Likewise. (linemap_dump): Likewise. (line_table_dump): Likewise. (LINEMAPS_LAST_MAP): Add a linemap_assert() for safety. (SOURCE_COLUMN): Handle 64-bit location_t. * line-map.cc (location_adhoc_data_hash): Don't truncate locations to 32-bit prematurely. (line_maps::get_or_create_combined_loc): Adapt types to support 64-bit location_t. Use MAX_LOCATION_T rather than a hard-coded constant. (line_maps::get_range_from_loc): Adapt types and constants to support 64-bit location_t. (line_maps::pure_location_p): Likewise. (line_maps::get_pure_location): Likewise. (line_map_new_raw): Likewise. (LAST_SOURCE_LINE_LOCATION): Likewise. (linemap_add): Likewise. (linemap_module_restore): Likewise. (linemap_line_start): Likewise. (linemap_position_for_column): Likewise. (linemap_position_for_line_and_column): Likewise. (linemap_position_for_loc_and_offset): Likewise. (linemap_ordinary_map_lookup): Likewise. (linemap_lookup_macro_index): Likewise. (linemap_dump): Likewise. (linemap_dump_location): Likewise. (linemap_get_file_highest_location): Likewise. (line_table_dump): Likewise. (linemap_compare_locations): Avoid signed int overflow in the result. * include/cpplib.h (struct cpp_identifier): Update comment about the struct layout. * macro.cc (num_expanded_macros_counter): Change type of global variable from "unsigned int" to "line_map_uint_t". (num_macro_tokens_counter): Likewise. --- libcpp/include/cpplib.h | 3 +- libcpp/include/line-map.h | 139 +++++++++++++++++++++++++------------- libcpp/line-map.cc | 138 +++++++++++++++++++++---------------- libcpp/macro.cc | 4 +- 4 files changed, 176 insertions(+), 108 deletions(-) diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 267d28147ab..f4913ac4313 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -256,7 +256,8 @@ struct GTY(()) cpp_identifier { }; /* A preprocessing token. This has been carefully packed and should - occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts. */ + occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts. With + 64-bit locations enabled, it occupies rather 32 bytes. */ struct GTY(()) cpp_token { /* Location of first char of token, together with range of full token. */ diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 732ec5e6445..65610b5a2ef 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -291,7 +291,12 @@ enum lc_reason To further see how location_t works in practice, see the worked example in libcpp/location-example.txt. */ + +#ifndef ENABLE_LARGE_SOURCE_LOCATIONS + +static constexpr bool LINE_MAP_LARGE_MODE = false; typedef unsigned int location_t; +typedef int location_diff_t; /* Do not track column numbers higher than this one. As a result, the range of column_bits is [12, 18] (or 0 if column numbers are @@ -311,6 +316,43 @@ const location_t LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000; /* Highest possible source location encoded within an ordinary map. */ const location_t LINE_MAP_MAX_LOCATION = 0x70000000; +/* This is the highest possible source location encoded within an + ordinary or macro map. */ +const location_t MAX_LOCATION_T = 0x7FFFFFFF; + +/* This is the number of range bits suggested to enable, if range tracking is + desired. */ +const int line_map_suggested_range_bits = 5; + +#else + +static constexpr bool LINE_MAP_LARGE_MODE = true; +typedef uint64_t location_t; +typedef int64_t location_diff_t; + +/* In 64-bit mode, we only use 63 of the 64 bits, so that two location_t can be + safely subtracted and stored in an int64_t. As in the 32-bit case, we + reserve half of the values for ad-hoc locations and the other half for + ordinary and macro map locations. We do not limit the max column number, + other than ensuring it fits in a signed 32-bit int. */ + +const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 31) - 1; +const location_t LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES + = location_t (0x50000000) << 31; +const location_t LINE_MAP_MAX_LOCATION_WITH_COLS + = location_t (0x60000000) << 31; +const location_t LINE_MAP_MAX_LOCATION = location_t (0x70000000) << 31; +const location_t MAX_LOCATION_T = location_t (-1) >> 2; +const int line_map_suggested_range_bits = 7; + +#endif + +/* Sometimes we need a type that has the same size as location_t but that does + not represent a location. This typedef provides more clarity in those + cases. */ + +typedef location_t line_map_uint_t; + /* A range of source locations. Ranges are closed: @@ -387,7 +429,7 @@ typedef size_t (*line_map_round_alloc_size_func) (size_t); struct GTY((tag ("0"), desc ("MAP_ORDINARY_P (&%h) ? 1 : 2"))) line_map { location_t start_location; - /* Size and alignment is (usually) 4 bytes. */ + /* Size and alignment is 4 (8) bytes for 32-bit (64-bit) locations. */ }; /* An ordinary line map encodes physical source locations. Those @@ -403,7 +445,7 @@ struct GTY((tag ("0"), desc ("MAP_ORDINARY_P (&%h) ? 1 : 2"))) line_map { The highest possible source location is MAX_LOCATION_T. */ struct GTY((tag ("1"))) line_map_ordinary : public line_map { - /* Base class is 4 bytes. */ + /* Base class is 4 (8) bytes for 32-bit (64-bit) locations. */ /* 4 bytes of integers, each 1 byte for easy extraction/insertion. */ @@ -435,9 +477,7 @@ struct GTY((tag ("1"))) line_map_ordinary : public line_map { +-------------------------+-----------------------+-------------------+ */ unsigned int m_range_bits : 8; - /* Pointer alignment boundary on both 32 and 64-bit systems. */ - - const char *to_file; + /* 32-bit int even in 64-bit mode. */ linenum_type to_line; /* Location from whence this line map was included. For regular @@ -446,12 +486,14 @@ struct GTY((tag ("1"))) line_map_ordinary : public line_map { within a map. */ location_t included_from; - /* Size is 20 or 24 bytes, no padding */ -}; + /* Pointer alignment boundary, whether 32-bit or 64-bit mode. */ + const char *to_file; -/* This is the highest possible source location encoded within an - ordinary or macro map. */ -const location_t MAX_LOCATION_T = 0x7FFFFFFF; + /* Size is one of the following, no padding needed: + 32-bit system: 20 bytes + 64-bit system, 32-bit locations: 24 bytes + 64-bit system, 64-bit locations: 32 bytes. */ +}; struct cpp_hashnode; @@ -470,7 +512,7 @@ struct GTY((tag ("2"))) line_map_macro : public line_map { return m_expansion; } - /* Base is 4 bytes. */ + /* Base is 4 (8) bytes for 32-bit (64-bit) locations. */ /* The number of tokens inside the replacement-list of MACRO. */ unsigned int n_tokens; @@ -546,7 +588,10 @@ struct GTY((tag ("2"))) line_map_macro : public line_map { if we are in a nested expansion context not. */ location_t m_expansion; - /* Size is 20 or 32 (4 bytes padding on 64-bit). */ + /* Size is one of the following: + 32-bit system: 20 bytes (no padding) + 64-bit system, 32-bit locations: 32 bytes (4 of which are padding) + 64-bit system, 64-bit locations: 40 bytes (8 of which are padding). */ }; #if CHECKING_P && (GCC_VERSION >= 2007) @@ -728,15 +773,15 @@ struct GTY(()) maps_info_ordinary { line_map_ordinary * GTY ((length ("%h.used"))) maps; /* The total number of allocated maps. */ - unsigned int allocated; + line_map_uint_t allocated; /* The number of elements used in maps. This number is smaller or equal to ALLOCATED. */ - unsigned int used; + line_map_uint_t used; /* The index of the last ordinary map that was looked up with linemap_lookup. */ - mutable unsigned int m_cache; + mutable line_map_uint_t m_cache; }; struct GTY(()) maps_info_macro { @@ -745,15 +790,15 @@ struct GTY(()) maps_info_macro { line_map_macro * GTY ((length ("%h.used"))) maps; /* The total number of allocated maps. */ - unsigned int allocated; + line_map_uint_t allocated; /* The number of elements used in maps. This number is smaller or equal to ALLOCATED. */ - unsigned int used; + line_map_uint_t used; /* The index of the last macro map that was looked up with linemap_lookup. */ - mutable unsigned int m_cache; + mutable line_map_uint_t m_cache; }; /* Data structure to associate a source_range together with an arbitrary @@ -780,7 +825,7 @@ struct htab; struct GTY(()) location_adhoc_data_map { struct htab * GTY((skip)) htab; location_t curr_loc; - unsigned int allocated; + line_map_uint_t allocated; struct location_adhoc_data GTY((length ("%h.allocated"))) *data; }; @@ -861,13 +906,13 @@ public: /* The default value of range_bits in ordinary line maps. */ unsigned int default_range_bits; - unsigned int m_num_optimized_ranges; - unsigned int m_num_unoptimized_ranges; + line_map_uint_t m_num_optimized_ranges; + line_map_uint_t m_num_unoptimized_ranges; }; /* Returns the number of allocated maps so far. MAP_KIND shall be TRUE if we are interested in macro maps, FALSE otherwise. */ -inline unsigned int +inline line_map_uint_t LINEMAPS_ALLOCATED (const line_maps *set, bool map_kind) { if (map_kind) @@ -878,7 +923,7 @@ LINEMAPS_ALLOCATED (const line_maps *set, bool map_kind) /* As above, but by reference (e.g. as an lvalue). */ -inline unsigned int & +inline line_map_uint_t & LINEMAPS_ALLOCATED (line_maps *set, bool map_kind) { if (map_kind) @@ -889,7 +934,7 @@ LINEMAPS_ALLOCATED (line_maps *set, bool map_kind) /* Returns the number of used maps so far. MAP_KIND shall be TRUE if we are interested in macro maps, FALSE otherwise.*/ -inline unsigned int +inline line_map_uint_t LINEMAPS_USED (const line_maps *set, bool map_kind) { if (map_kind) @@ -900,7 +945,7 @@ LINEMAPS_USED (const line_maps *set, bool map_kind) /* As above, but by reference (e.g. as an lvalue). */ -inline unsigned int & +inline line_map_uint_t & LINEMAPS_USED (line_maps *set, bool map_kind) { if (map_kind) @@ -911,7 +956,7 @@ LINEMAPS_USED (line_maps *set, bool map_kind) /* Return the map at a given index. */ inline line_map * -LINEMAPS_MAP_AT (const line_maps *set, bool map_kind, int index) +LINEMAPS_MAP_AT (const line_maps *set, bool map_kind, line_map_uint_t index) { if (map_kind) return &set->info_macro.maps[index]; @@ -925,29 +970,29 @@ LINEMAPS_MAP_AT (const line_maps *set, bool map_kind, int index) inline line_map * LINEMAPS_LAST_MAP (const line_maps *set, bool map_kind) { + linemap_assert (LINEMAPS_USED (set, map_kind)); return LINEMAPS_MAP_AT (set, map_kind, LINEMAPS_USED (set, map_kind) - 1); } /* Returns the INDEXth ordinary map. */ inline line_map_ordinary * -LINEMAPS_ORDINARY_MAP_AT (const line_maps *set, int index) +LINEMAPS_ORDINARY_MAP_AT (const line_maps *set, line_map_uint_t index) { - linemap_assert (index >= 0 - && (unsigned int)index < LINEMAPS_USED (set, false)); + linemap_assert (index < LINEMAPS_USED (set, false)); return (line_map_ordinary *)LINEMAPS_MAP_AT (set, false, index); } /* Return the number of ordinary maps allocated in the line table SET. */ -inline unsigned int +inline line_map_uint_t LINEMAPS_ORDINARY_ALLOCATED (const line_maps *set) { return LINEMAPS_ALLOCATED (set, false); } /* Return the number of ordinary maps used in the line table SET. */ -inline unsigned int +inline line_map_uint_t LINEMAPS_ORDINARY_USED (const line_maps *set) { return LINEMAPS_USED (set, false); @@ -963,23 +1008,22 @@ LINEMAPS_LAST_ORDINARY_MAP (const line_maps *set) /* Returns the INDEXth macro map. */ inline line_map_macro * -LINEMAPS_MACRO_MAP_AT (const line_maps *set, int index) +LINEMAPS_MACRO_MAP_AT (const line_maps *set, line_map_uint_t index) { - linemap_assert (index >= 0 - && (unsigned int)index < LINEMAPS_USED (set, true)); + linemap_assert (index < LINEMAPS_USED (set, true)); return (line_map_macro *)LINEMAPS_MAP_AT (set, true, index); } /* Returns the number of macro maps that were allocated in the line table SET. */ -inline unsigned int +inline line_map_uint_t LINEMAPS_MACRO_ALLOCATED (const line_maps *set) { return LINEMAPS_ALLOCATED (set, true); } /* Returns the number of macro maps used in the line table SET. */ -inline unsigned int +inline line_map_uint_t LINEMAPS_MACRO_USED (const line_maps *set) { return LINEMAPS_USED (set, true); @@ -1044,7 +1088,7 @@ extern location_t linemap_line_start (class line_maps *set, linenum_type to_line, unsigned int max_column_hint); /* Allocate a raw block of line maps, zero initialized. */ -extern line_map *line_map_new_raw (line_maps *, bool, unsigned); +extern line_map *line_map_new_raw (line_maps *, bool, line_map_uint_t); /* Add a mapping of logical source line to physical source file and line number. This function creates an "ordinary map", which is a @@ -1094,8 +1138,8 @@ extern void linemap_module_reparent /* Restore the linemap state such that the map at LWM-1 continues. Return start location of the new map. */ -extern unsigned linemap_module_restore - (line_maps *, unsigned lwm); +extern location_t linemap_module_restore + (line_maps *, line_map_uint_t lwm); /* Given a logical source location, returns the map which the corresponding (source file, line, column) triplet can be deduced @@ -1106,7 +1150,7 @@ extern unsigned linemap_module_restore extern const line_map *linemap_lookup (const line_maps *, location_t); -unsigned linemap_lookup_macro_index (const line_maps *, location_t); +line_map_uint_t linemap_lookup_macro_index (const line_maps *, location_t); /* Returns TRUE if the line table set tracks token locations across macro expansion, FALSE otherwise. */ @@ -1165,7 +1209,8 @@ inline linenum_type SOURCE_COLUMN (const line_map_ordinary *ord_map, location_t loc) { return ((loc - ord_map->start_location) - & ((1 << ord_map->m_column_and_range_bits) - 1)) >> ord_map->m_range_bits; + & ((location_t (1) << ord_map->m_column_and_range_bits) - 1)) + >> ord_map->m_range_bits; } @@ -1244,9 +1289,10 @@ const struct line_map *first_map_in_common (const line_maps *set, comes before the token of POST, 0 if PRE denotes the location of the same token as the token for POST, and a negative value otherwise. */ -int linemap_compare_locations (const line_maps *set, - location_t pre, - location_t post); +int +linemap_compare_locations (const line_maps *set, + location_t pre, + location_t post); /* Return TRUE if LOC_A denotes the location a token that comes topogically before the token denoted by location LOC_B, or if they @@ -1413,12 +1459,13 @@ void linemap_dump_location (const line_maps *, location_t, FILE *); /* Dump line map at index IX in line table SET to STREAM. If STREAM is NULL, use stderr. IS_MACRO is true if the caller wants to dump a macro map, false otherwise. */ -void linemap_dump (FILE *, const line_maps *, unsigned, bool); +void linemap_dump (FILE *, const line_maps *, line_map_uint_t, bool); /* Dump line table SET to STREAM. If STREAM is NULL, stderr is used. NUM_ORDINARY specifies how many ordinary maps to dump. NUM_MACRO specifies how many macro maps to dump. */ -void line_table_dump (FILE *, const line_maps *, unsigned int, unsigned int); +void line_table_dump (FILE *, const line_maps *, + line_map_uint_t, line_map_uint_t); /* An enum for distinguishing the various parts within a location_t. */ diff --git a/libcpp/line-map.cc b/libcpp/line-map.cc index ac765c78bf5..8ad31b1e755 100644 --- a/libcpp/line-map.cc +++ b/libcpp/line-map.cc @@ -26,6 +26,10 @@ along with this program; see the file COPYING3. If not see #include "internal.h" #include "hashtab.h" +/* Useful for the bit manipulations in this file, since the size of a location_t + is configurable. */ +static constexpr location_t loc_one = 1; + static void trace_include (const line_maps *, const line_map_ordinary *); static const line_map_ordinary * linemap_ordinary_map_lookup (const line_maps *, location_t); @@ -45,8 +49,8 @@ static location_t linemap_macro_loc_to_exp_point (const line_maps *, const line_map_ordinary **); /* Counters defined in macro.cc. */ -extern unsigned num_expanded_macros_counter; -extern unsigned num_macro_tokens_counter; +extern line_map_uint_t num_expanded_macros_counter; +extern line_map_uint_t num_macro_tokens_counter; /* Destructor for class line_maps. Ensure non-GC-managed memory is released. */ @@ -64,11 +68,11 @@ location_adhoc_data_hash (const void *l) { const struct location_adhoc_data *lb = (const struct location_adhoc_data *) l; - return ((hashval_t) lb->locus - + (hashval_t) lb->src_range.m_start - + (hashval_t) lb->src_range.m_finish - + (size_t) lb->data - + lb->discriminator); + return lb->locus + + lb->src_range.m_start + + lb->src_range.m_finish + + (size_t) lb->data + + lb->discriminator; } /* Compare function for location_adhoc_data hashtable. */ @@ -197,9 +201,9 @@ line_maps::get_or_create_combined_loc (location_t locus, linemap_assert (pure_location_p (locus)); const line_map *map = linemap_lookup (this, locus); const line_map_ordinary *ordmap = linemap_check_ordinary (map); - unsigned int int_diff = src_range.m_finish - src_range.m_start; - unsigned int col_diff = (int_diff >> ordmap->m_range_bits); - if (col_diff < (1U << ordmap->m_range_bits)) + auto int_diff = src_range.m_finish - src_range.m_start; + auto col_diff = (int_diff >> ordmap->m_range_bits); + if (col_diff < (loc_one << ordmap->m_range_bits)) { location_t packed = locus | col_diff; m_num_optimized_ranges++; @@ -255,7 +259,7 @@ line_maps::get_or_create_combined_loc (location_t locus, m_location_adhoc_data_map.data[m_location_adhoc_data_map.curr_loc++] = lb; } - return ((*slot) - m_location_adhoc_data_map.data) | 0x80000000; + return ((*slot) - m_location_adhoc_data_map.data) | (1 + MAX_LOCATION_T); } /* Construct a location with caret at CARET, ranging from START to @@ -339,7 +343,7 @@ line_maps::get_range_from_loc (location_t loc) const const line_map *map = linemap_lookup (this, loc); const line_map_ordinary *ordmap = linemap_check_ordinary (map); source_range result; - int offset = loc & ((1 << ordmap->m_range_bits) - 1); + auto offset = loc & ((loc_one << ordmap->m_range_bits) - 1); result.m_start = loc - offset; result.m_finish = result.m_start + (offset << ordmap->m_range_bits); return result; @@ -378,7 +382,7 @@ line_maps::pure_location_p (location_t loc) const return true; const line_map_ordinary *ordmap = linemap_check_ordinary (map); - if (loc & ((1U << ordmap->m_range_bits) - 1)) + if (loc & ((loc_one << ordmap->m_range_bits) - 1)) return false; return true; @@ -408,7 +412,7 @@ line_maps::get_pure_location (location_t loc) const const line_map *map = linemap_lookup (this, loc); const line_map_ordinary *ordmap = linemap_check_ordinary (map); - return loc & ~((1 << ordmap->m_range_bits) - 1); + return loc & ~((loc_one << ordmap->m_range_bits) - 1); } location_t @@ -464,10 +468,10 @@ linemap_check_files_exited (const line_maps *set) /* Create NUM zero-initialized maps of type MACRO_P. */ line_map * -line_map_new_raw (line_maps *set, bool macro_p, unsigned num) +line_map_new_raw (line_maps *set, bool macro_p, line_map_uint_t num) { - unsigned num_maps_allocated = LINEMAPS_ALLOCATED (set, macro_p); - unsigned num_maps_used = LINEMAPS_USED (set, macro_p); + auto num_maps_allocated = LINEMAPS_ALLOCATED (set, macro_p); + auto num_maps_used = LINEMAPS_USED (set, macro_p); if (num > num_maps_allocated - num_maps_used) { @@ -504,7 +508,7 @@ line_map_new_raw (line_maps *set, bool macro_p, unsigned num) /* Now alloc_size contains the exact memory size we would get if we have asked for the initial alloc_size amount of memory. Let's get back to the number of map that amounts to. */ - unsigned num_maps = alloc_size / size_of_a_map; + line_map_uint_t num_maps = alloc_size / size_of_a_map; buffer = set->m_reallocator (buffer, num_maps * size_of_a_map); memset ((char *)buffer + num_maps_used * size_of_a_map, 0, (num_maps - num_maps_used) * size_of_a_map); @@ -546,7 +550,7 @@ LAST_SOURCE_LINE_LOCATION (const line_map_ordinary *map) { return (((map[1].start_location - 1 - map->start_location) - & ~((1 << map->m_column_and_range_bits) - 1)) + & ~((loc_one << map->m_column_and_range_bits) - 1)) + map->start_location); } @@ -573,8 +577,8 @@ linemap_add (line_maps *set, enum lc_reason reason, unsigned range_bits = 0; if (start_location < LINE_MAP_MAX_LOCATION_WITH_COLS) range_bits = set->default_range_bits; - start_location += (1 << range_bits) - 1; - start_location &= ~((1 << range_bits) - 1); + start_location += (loc_one << range_bits) - 1; + start_location &= ~((loc_one << range_bits) - 1); linemap_assert (!LINEMAPS_ORDINARY_USED (set) || (start_location @@ -660,7 +664,7 @@ linemap_add (line_maps *set, enum lc_reason reason, /* The location of the end of the just-closed map. */ map->included_from = (((map[0].start_location - 1 - map[-1].start_location) - & ~((1 << map[-1].m_column_and_range_bits) - 1)) + & ~((loc_one << map[-1].m_column_and_range_bits) - 1)) + map[-1].start_location); set->depth++; if (set->trace_includes) @@ -707,8 +711,8 @@ linemap_module_reparent (line_maps *set, location_t loc, location_t adoptor) Append a new map, continuing the interrupted one. Return the start location of the new map, or 0 if failed (because we ran out of locations. */ -unsigned -linemap_module_restore (line_maps *set, unsigned lwm) +location_t +linemap_module_restore (line_maps *set, line_map_uint_t lwm) { linemap_assert (lwm); @@ -847,7 +851,7 @@ linemap_line_start (line_maps *set, linenum_type to_line, location_t r; linenum_type last_line = SOURCE_LINE (map, set->highest_line); - int line_delta = to_line - last_line; + auto line_delta = (linenum_arith_t) to_line - (linenum_arith_t) last_line; bool add_map = false; linemap_assert (map->m_column_and_range_bits >= map->m_range_bits); int effective_column_bits = map->m_column_and_range_bits - map->m_range_bits; @@ -897,7 +901,8 @@ linemap_line_start (line_maps *set, linenum_type to_line, single line we can sometimes just increase its column_bits instead. */ if (line_delta < 0 || last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map) - || SOURCE_COLUMN (map, highest) >= (1U << (column_bits - range_bits)) + || SOURCE_COLUMN (map, highest) >= (loc_one + << (column_bits - range_bits)) || ( /* We can't reuse the map if the line offset is sufficiently large to cause overflow when computing location_t values. */ (to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map)) @@ -913,11 +918,12 @@ linemap_line_start (line_maps *set, linenum_type to_line, map->m_column_and_range_bits = column_bits; map->m_range_bits = range_bits; r = (MAP_START_LOCATION (map) - + ((to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map)) + + (location_t (to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map)) << column_bits)); } else - r = set->highest_line + (line_delta << map->m_column_and_range_bits); + r = set->highest_line + (location_t (line_delta) + << map->m_column_and_range_bits); /* Locations of ordinary tokens are always lower than locations of macro tokens. */ @@ -992,7 +998,7 @@ linemap_position_for_column (line_maps *set, unsigned int to_column) } } line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (set); - r = r + (to_column << map->m_range_bits); + r = r + (location_t (to_column) << map->m_range_bits); if (r >= set->highest_location) set->highest_location = r; return r; @@ -1010,10 +1016,10 @@ linemap_position_for_line_and_column (line_maps *set, linemap_assert (ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map) <= line); location_t r = MAP_START_LOCATION (ord_map); - r += ((line - ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map)) + r += (location_t (line - ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map)) << ord_map->m_column_and_range_bits); if (r <= LINE_MAP_MAX_LOCATION_WITH_COLS) - r += ((column & ((1 << ord_map->m_column_and_range_bits) - 1)) + r += ((column & ((loc_one << ord_map->m_column_and_range_bits) - 1)) << ord_map->m_range_bits); location_t upper_limit = LINEMAPS_MACRO_LOWEST_LOCATION (set); if (r >= upper_limit) @@ -1050,10 +1056,12 @@ linemap_position_for_loc_and_offset (line_maps *set, /* We find the real location and shift it. */ loc = linemap_resolve_location (set, loc, LRK_SPELLING_LOCATION, &map); + auto shifted_offset = location_t (column_offset) << map->m_range_bits; + /* The new location (loc + offset) should be higher than the first location encoded by MAP. This can fail if the line information is messed up because of line directives (see PR66415). */ - if (MAP_START_LOCATION (map) >= loc + (column_offset << map->m_range_bits)) + if (MAP_START_LOCATION (map) >= loc + shifted_offset) return loc; linenum_type line = SOURCE_LINE (map, loc); @@ -1064,8 +1072,7 @@ linemap_position_for_loc_and_offset (line_maps *set, the next line map of the set. Otherwise, we try to encode the location in the next map. */ for (; map != LINEMAPS_LAST_ORDINARY_MAP (set) - && (loc + (column_offset << map->m_range_bits) - >= MAP_START_LOCATION (map + 1)); map++) + && loc + shifted_offset >= MAP_START_LOCATION (map + 1); map++) /* If the next map is a different file, or starts in a higher line, we cannot encode the location there. */ if ((map + 1)->reason != LC_RENAME @@ -1116,8 +1123,8 @@ linemap_ordinary_map_lookup (const line_maps *set, location_t line) if (set == NULL || line < RESERVED_LOCATION_COUNT) return NULL; - unsigned mn = set->info_ordinary.m_cache; - unsigned mx = LINEMAPS_ORDINARY_USED (set); + auto mn = set->info_ordinary.m_cache; + auto mx = LINEMAPS_ORDINARY_USED (set); const line_map_ordinary *cached = LINEMAPS_ORDINARY_MAP_AT (set, mn); /* We should get a segfault if no line_maps have been added yet. */ @@ -1134,7 +1141,7 @@ linemap_ordinary_map_lookup (const line_maps *set, location_t line) while (mx - mn > 1) { - unsigned md = (mn + mx) / 2; + auto md = (mn + mx) / 2; if (MAP_START_LOCATION (LINEMAPS_ORDINARY_MAP_AT (set, md)) > line) mx = md; else @@ -1163,18 +1170,18 @@ linemap_macro_map_lookup (const line_maps *set, location_t line) if (set == NULL) return NULL; - unsigned ix = linemap_lookup_macro_index (set, line); + auto ix = linemap_lookup_macro_index (set, line); const struct line_map_macro *result = LINEMAPS_MACRO_MAP_AT (set, ix); linemap_assert (MAP_START_LOCATION (result) <= line); return result; } -unsigned +line_map_uint_t linemap_lookup_macro_index (const line_maps *set, location_t line) { - unsigned mn = set->info_macro.m_cache; - unsigned mx = LINEMAPS_MACRO_USED (set); + auto mn = set->info_macro.m_cache; + auto mx = LINEMAPS_MACRO_USED (set); const struct line_map_macro *cached = LINEMAPS_MACRO_MAP_AT (set, mn); if (line >= MAP_START_LOCATION (cached)) @@ -1188,7 +1195,7 @@ linemap_lookup_macro_index (const line_maps *set, location_t line) while (mn < mx) { - unsigned md = (mx + mn) / 2; + auto md = (mx + mn) / 2; if (MAP_START_LOCATION (LINEMAPS_MACRO_MAP_AT (set, md)) > line) mn = md + 1; else @@ -1529,7 +1536,10 @@ linemap_compare_locations (const line_maps *set, if (IS_ADHOC_LOC (l1)) l1 = get_location_from_adhoc_loc (set, l1); - return l1 - l0; + /* This function is intended e.g. for implementing a qsort() comparator, so it + needs to return really an "int" and not something larger. */ + const location_diff_t res = l1 - l0; + return res < INT_MIN ? INT_MIN : res > INT_MAX ? INT_MAX : res; } /* Print an include trace, for e.g. the -H option of the preprocessor. */ @@ -1914,7 +1924,8 @@ linemap_expand_location (const line_maps *set, dump a macro map, false otherwise. */ void -linemap_dump (FILE *stream, const line_maps *set, unsigned ix, bool is_macro) +linemap_dump (FILE *stream, const line_maps *set, line_map_uint_t ix, + bool is_macro) { const char *const lc_reasons_v[LC_HWM] = { "LC_ENTER", "LC_LEAVE", "LC_RENAME", "LC_RENAME_VERBATIM", @@ -1936,8 +1947,10 @@ linemap_dump (FILE *stream, const line_maps *set, unsigned ix, bool is_macro) reason = LC_ENTER_MACRO; } - fprintf (stream, "Map #%u [%p] - LOC: %u - REASON: %s - SYSP: %s\n", - ix, (void *) map, map->start_location, + fprintf (stream, "Map #%llu [%p] - LOC: %llu - REASON: %s - SYSP: %s\n", + (unsigned long long) ix, + (void *) map, + (unsigned long long) map->start_location, reason < LC_HWM ? lc_reasons_v[reason] : "???", ((!is_macro && ORDINARY_MAP_IN_SYSTEM_HEADER_P (linemap_check_ordinary (map))) @@ -1948,10 +1961,12 @@ linemap_dump (FILE *stream, const line_maps *set, unsigned ix, bool is_macro) const line_map_ordinary *includer_map = linemap_included_from_linemap (set, ord_map); - fprintf (stream, "File: %s:%d\n", ORDINARY_MAP_FILE_NAME (ord_map), + fprintf (stream, "File: %s:%u\n", ORDINARY_MAP_FILE_NAME (ord_map), ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map)); - fprintf (stream, "Included from: [%d] %s\n", - includer_map ? int (includer_map - set->info_ordinary.maps) : -1, + const long long from_ind + = includer_map ? includer_map - set->info_ordinary.maps : -1; + fprintf (stream, "Included from: [%lld] %s\n", + from_ind, includer_map ? ORDINARY_MAP_FILE_NAME (includer_map) : "None"); } else @@ -2010,8 +2025,10 @@ linemap_dump_location (const line_maps *set, /* P: path, L: line, C: column, S: in-system-header, M: map address, E: macro expansion?, LOC: original location, R: resolved location */ - fprintf (stream, "{P:%s;F:%s;L:%d;C:%d;S:%d;M:%p;E:%d,LOC:%d,R:%d}", - path, from, l, c, s, (void*)map, e, loc, location); + fprintf (stream, "{P:%s;F:%s;L:%d;C:%d;S:%d;M:%p;E:%d,LOC:%llu,R:%llu}", + path, from, l, c, s, (void*)map, e, + (unsigned long long) loc, + (unsigned long long) location); } /* Return the highest location emitted for a given file for which @@ -2030,7 +2047,7 @@ linemap_get_file_highest_location (const line_maps *set, return false; /* Now look for the last ordinary map created for FILE_NAME. */ - int i; + location_diff_t i; for (i = set->info_ordinary.used - 1; i >= 0; --i) { const char *fname = set->info_ordinary.maps[i].to_file; @@ -2045,7 +2062,7 @@ linemap_get_file_highest_location (const line_maps *set, location of the next map minus one, or -- if the map is the latest one -- the highest location of the set. */ location_t result; - if (i == (int) set->info_ordinary.used - 1) + if ((location_t) i == set->info_ordinary.used - 1) result = set->highest_location; else result = set->info_ordinary.maps[i + 1].start_location - 1; @@ -2122,10 +2139,10 @@ linemap_get_statistics (const line_maps *set, specifies how many macro maps to dump. */ void -line_table_dump (FILE *stream, const line_maps *set, unsigned int num_ordinary, - unsigned int num_macro) +line_table_dump (FILE *stream, const line_maps *set, + line_map_uint_t num_ordinary, line_map_uint_t num_macro) { - unsigned int i; + line_map_uint_t i; if (set == NULL) return; @@ -2133,10 +2150,13 @@ line_table_dump (FILE *stream, const line_maps *set, unsigned int num_ordinary, if (stream == NULL) stream = stderr; - fprintf (stream, "# of ordinary maps: %d\n", LINEMAPS_ORDINARY_USED (set)); - fprintf (stream, "# of macro maps: %d\n", LINEMAPS_MACRO_USED (set)); + fprintf (stream, "# of ordinary maps: %llu\n", + (unsigned long long) LINEMAPS_ORDINARY_USED (set)); + fprintf (stream, "# of macro maps: %llu\n", + (unsigned long long) LINEMAPS_MACRO_USED (set)); fprintf (stream, "Include stack depth: %d\n", set->depth); - fprintf (stream, "Highest location: %u\n", set->highest_location); + fprintf (stream, "Highest location: %llu\n", + (unsigned long long) set->highest_location); if (num_ordinary) { diff --git a/libcpp/macro.cc b/libcpp/macro.cc index 907af873df1..0b8eebee061 100644 --- a/libcpp/macro.cc +++ b/libcpp/macro.cc @@ -364,10 +364,10 @@ static cpp_hashnode* macro_of_context (cpp_context *context); /* Statistical counter tracking the number of macros that got expanded. */ -unsigned num_expanded_macros_counter = 0; +line_map_uint_t num_expanded_macros_counter = 0; /* Statistical counter tracking the total number tokens resulting from macro expansion. */ -unsigned num_macro_tokens_counter = 0; +line_map_uint_t num_macro_tokens_counter = 0; /* Wrapper around cpp_get_token to skip CPP_PADDING tokens and not consume CPP_EOF. */ From patchwork Sun Nov 3 22:22:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005818 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=nTm4laWY; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhTdD1rQcz1xyH for ; Mon, 4 Nov 2024 09:23:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C217A3858D39 for ; Sun, 3 Nov 2024 22:23:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by sourceware.org (Postfix) with ESMTPS id E15353858403 for ; Sun, 3 Nov 2024 22:22:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E15353858403 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E15353858403 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672564; cv=none; b=xm/4WDRa3tc4UyM7BUjnSiw1rLD8buA01X9oKgTdHiu3ztmos5RhsPKqalumu21VuEn2zE33urdvoklkjQ16Gxa3RXoxNP6ClK8MT/xCMnrluS0Xl4vX0o286vuE/gFxFkdRQkMSqHx8orEt6IMdVLbogBKNHgD7yO7jvepsxT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672564; c=relaxed/simple; bh=yVvCfHw7kzCh9NUek+o9zHsNCkyLdq6PAk7vx5OCSoQ=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=WrXxfTlIlvNWGF6foiJolPFAKbU8jf0NN2SPVScLjV3QCtXukvJ555YPbLfA+0TQxfiFRVtFM/Cavjet4vZ6bkAOCLqFYI0OtHvNI/NNdmTaMLOBisVEwW6feGvrvqaM6YhhWGuLFtjNIhAFdeHsVzxrGoQOnvRbeJfrC7fHAeg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf2c.google.com with SMTP id 6a1803df08f44-6cbceb321b3so30381276d6.3 for ; Sun, 03 Nov 2024 14:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672561; x=1731277361; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kwBwD0EyuQx1He9qxZ/PLJa5bs7lQd2tUQp3nmH4eAc=; b=nTm4laWYZDfqni4YuoQ/8am5K3YdiPJAdQjiPvZEalpSev6Pf4OxiR/BL4b7a1NK+c +JxNKnQRAn0TfLHFLVdjQ1vqAoKOGWgrYrK6FhVRpyQkQuhvXHDy69XSHDzKN9h0Xz1h A2wohawMXRYCL6ei/LxW0bt1tJ/GXZDjDgiSJ3Qz3AAR3cz1bYxwKE+epANlD5ORHbx6 J9o4+4oexpGxbPSTug9F8iZxcaDFmADUQnn6EAvh/EsKeNBv8o3atA48MCRmRjthDBle vvvVl20nrgHQ0X/VU3xiOdzAiDintL5Qb98X2Qq4Lc77s6vSA99yk2dZDxftYaNR6bcw lfrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672561; x=1731277361; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kwBwD0EyuQx1He9qxZ/PLJa5bs7lQd2tUQp3nmH4eAc=; b=sxT0MhhcCm79HR3Cv0yC/9mrjz5crWoPzD+oLeaDxvUnl2dDmRJbnJTEw3Cg/vKH64 B50Hx463cgUj2XE5LKZXST7ERv0SloHqlNpLbf3QYnGk5H1WsNNM/hDAT15f5XwYWnrW Cse0OT4GmysnqFLGZpH6JA5/RSO1v9JqNje7MqarFSsJYpBKcLM6mDpoPX7VOEuvD1fA H4T8pRoInkwpKdvxuQrIRDNlT8Llu8jCxLLXg14mdu5rMnmB/BfWlE1Zis639tSHnl5M ZVfs486E/AuN4Tv2j79vi3EWMLf8uIbq24D4OzEliGM744jS6OJd/QGt//MzMl0wShng tfeA== X-Gm-Message-State: AOJu0Yx0vNTarRI4oJfyUIqCX3TNkP5vqgJ6xHhqSON454k8KRvwTW7I RfGnTJHQVj8MxoSu0iQy77PuDbhf5H4T3XonZZIHcV8bh5MjUAKpWIDkLw== X-Google-Smtp-Source: AGHT+IHBdc7P6nXL5/n8GrSkeelavtdEtzjiDAAPQFmR8ht+ZFmqnQ7L8e6cIkvDjvAVO65Dj/44QQ== X-Received: by 2002:a05:6214:5991:b0:6cb:ec71:f1a1 with SMTP id 6a1803df08f44-6d185690ad8mr434589836d6.17.1730672561234; Sun, 03 Nov 2024 14:22:41 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:40 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 02/15] libcpp: Fix potential unaligned access in cpp_buffer Date: Sun, 3 Nov 2024 17:22:07 -0500 Message-Id: <20241103222220.933471-3-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org libcpp makes use of the cpp_buffer pfile->a_buff to store things while it is handling macros. It uses it to store pointers (cpp_hashnode*, for macro arguments) and cpp_macro objects. This works fine because a cpp_hashnode* and a cpp_macro have the same alignment requirement on either 32-bit or 64-bit systems (namely, the same alignment as a pointer.) When 64-bit location_t is enabled on a 32-bit sytem, the alignment requirement may cease to be the same, because the alignment requirement of a cpp_macro object changes to that of a uint64_t, which be larger than that of a pointer. It's not the case for x86 32-bit, but for example, on sparc, a pointer has 4-byte alignment while a uint64_t has 8. In that case, intermixing the two within the same cpp_buffer leads to a misaligned access. The code path that triggers this is the one in _cpp_commit_buff in which a hash table with its own allocator (i.e. ggc) is not being used, so it doesn't happen within the compiler itself, but it happens in the other libcpp clients, such as genmatch. Fix that up by ensuring _cpp_commit_buff commits a fully aligned chunk of the buffer, so it's ready for anything it may be used for next. For good measure, also modify CPP_ALIGN so that it guarantees to return an alignment at least the size of location_t. Currently it returns the max of a pointer and a double. I am not aware of any platform where a double may have smaller alignment than a uint64_t, but it does not hurt to add location_t here to be sure. libcpp/ChangeLog: * lex.cc (_cpp_commit_buff): Make sure that the buffer is properly aligned for the next allocation. * internal.h (struct dummy): Make sure alignment is large enough for a location_t, just in case. --- libcpp/internal.h | 1 + libcpp/lex.cc | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libcpp/internal.h b/libcpp/internal.h index e65198e89da..358e77cd622 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -85,6 +85,7 @@ struct dummy { double d; int *p; + location_t l; } u; }; diff --git a/libcpp/lex.cc b/libcpp/lex.cc index 849447eb4d7..858970b5d17 100644 --- a/libcpp/lex.cc +++ b/libcpp/lex.cc @@ -4997,7 +4997,8 @@ _cpp_aligned_alloc (cpp_reader *pfile, size_t len) void * _cpp_commit_buff (cpp_reader *pfile, size_t size) { - void *ptr = BUFF_FRONT (pfile->a_buff); + const auto buff = pfile->a_buff; + void *ptr = BUFF_FRONT (buff); if (pfile->hash_table->alloc_subobject) { @@ -5006,7 +5007,12 @@ _cpp_commit_buff (cpp_reader *pfile, size_t size) ptr = copy; } else - BUFF_FRONT (pfile->a_buff) += size; + { + BUFF_FRONT (buff) += size; + /* Make sure the remaining space is maximally aligned for whatever this + buffer holds next. */ + BUFF_FRONT (buff) += BUFF_ROOM (buff) % DEFAULT_ALIGNMENT; + } return ptr; } From patchwork Sun Nov 3 22:22:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005819 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=NfhR4TGB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhTdd2DD7z1xxN for ; Mon, 4 Nov 2024 09:23:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7921B3857BAF for ; Sun, 3 Nov 2024 22:23:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2b.google.com (mail-qv1-xf2b.google.com [IPv6:2607:f8b0:4864:20::f2b]) by sourceware.org (Postfix) with ESMTPS id EEA763858C33 for ; Sun, 3 Nov 2024 22:22:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EEA763858C33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EEA763858C33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672568; cv=none; b=Cq1vvQkX7J/ZvR0WKueVlf5i5khwuJdNL96uDgWgiX2+Ec6ryj9cB3/Jcn7eaE4erzYaC43Ms8/3Pi4OexswcujRHW9nCI9F9gyeG/sgmp16EYFMjG4eRQk9yg2GI5cRBXIgWmpe9CeD59SpIYONX7CZtiotmTGufXg0+URtDIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672568; c=relaxed/simple; bh=OwWzYxpUvzTxDbbELfTiqgT46UHOZAgo/yOIRN1u054=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=kQs1Jq5cN1M7WRolPPYFKNPNYA4XtjEdzaCKnYzyzIHLcp247bX0e5VgzcA9DbqYr88U0J7TouKCY9cfeeFSYX+MKF2uz+JTnT+JST6vN9UcNPbslQkNTSb1fdjXxwkh20/oKSrXO01n/3vORnX9pMkL0GQH+1NsibuG3/3HJSQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf2b.google.com with SMTP id 6a1803df08f44-6cbe3ea8e3fso27069136d6.0 for ; Sun, 03 Nov 2024 14:22:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672563; x=1731277363; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RjbYYHMbCdJIdhec+jj2aUo4yr55exoLC5ycAy20qVo=; b=NfhR4TGBQOoCy7/nnwlmGlRedRbauWGiJDuvqpD2cfu+yneJCwhNeC91Bln0j4ajmn QWdI8lQIDAFPoq+vsysedtcJmQRUlPR5wlZXXSwEdTNwHoc2b3xMGn2SWCrI3feORr4S ybyRLQr4Y3Dx495PQLGkvon4Uef6eSgULDVdjk3eiKkcS6DMZTdMZHV/H97SBOmAEn0x OQ0mGnMlrBqaXj+udfsEuZk9QqyyBH+mRfnWxzoOAsCFsD+B2o6cvHBvCbIE+2YYXoWd cKIdpMw/p9ac+QmAc7CdrRZ7j044KYivFOf30Eu8E21T5zinlxDBX9mPwsA3MT3bvHc1 ZONA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672563; x=1731277363; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RjbYYHMbCdJIdhec+jj2aUo4yr55exoLC5ycAy20qVo=; b=dOHsMU6iuWrobvBy04V1HrWFpaxCRiIH1MW6mZK8oEO/ASRA406f+wlMRSY7MF7NGV Pfh9I2H7+3ZxMMHkTZeTkqe/DcqRItjuZeM4u2RFKeyf4pxLGpebHUX+xZcsESVPVchS bvcefjA39uFepM7fIVIPcNjlBlrcOvXbx9WEzK2GjLUENlyBkdFOId6z9001jkbwgxqs jbXyXCSZp9ODHv0xe3qw7rCzuqxDG8SNjVzsk6sA9JrwuXvHdM8BLyJunBtIOMhL7MFi oS+ObU+sGmWvBNbWjUnmstMMmB1XorhrqBlRuSgi2fhuRJW0hNEWvuuf67eC/6aNRVfy 7cMA== X-Gm-Message-State: AOJu0YxjJ6aT7Yixp7bwL1/4zENWdBqC5NQMZJsbz/sVMh2LzXhS94CA 7cE/UT5UBnNyyF63U9Mkk7W7BtEH5PmO8Nzyf4BZXZvEMfHcVkrclsTRwQ== X-Google-Smtp-Source: AGHT+IG5llyh4Ni2B3jpj+/obePPDq2vZJn4h24B38BEpUaM2uqeBH9HdBysYn8xjKIx8R/uul6vmQ== X-Received: by 2002:a05:6214:5885:b0:6c5:b6de:5ee with SMTP id 6a1803df08f44-6d351adf3f3mr196284726d6.30.1730672563205; Sun, 03 Nov 2024 14:22:43 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:42 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 03/15] tree-cfg: Fix call to next_discriminator_for_locus() Date: Sun, 3 Nov 2024 17:22:08 -0500 Message-Id: <20241103222220.933471-4-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org While testing 64-bit location_t support, I ran into an -fcompare-debug issue that was traced back here. Despite the name, next_discriminator_for_locus() is meant to take an integer line number argument, not a location_t. There is one call site which has been passing a location_t instead. For the most part that is harmless, although in case there are two CALL stmts on the same line with different location_t, it may fail to generate a unique discriminator where it should. Once location_t is configured to be 64-bit, however, it produces an -fcompare-debug failure which is what I noticed. Fix it by passing the line number rather than the location_t. I am not aware of a testcase that demonstrates any observable wrong behavior, but the file debug/pr53466.C is an example where the discriminator assignment is indeed different before and after this change. gcc/ChangeLog: * tree-cfg.cc (assign_discriminators): Fix incorrect value passed to next_discriminator_for_locus(). --- gcc/tree-cfg.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index 3eede0d61cd..c2100a51a7a 100644 --- a/gcc/tree-cfg.cc +++ b/gcc/tree-cfg.cc @@ -1251,7 +1251,7 @@ assign_discriminators (void) } /* Allocate a new discriminator for CALL stmt. */ if (gimple_code (stmt) == GIMPLE_CALL) - curr_discr = next_discriminator_for_locus (curr_locus); + curr_discr = next_discriminator_for_locus (curr_locus_e.line); } gimple *last = last_nondebug_stmt (bb); From patchwork Sun Nov 3 22:22:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005827 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=FtmWGEwp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhThN6NG9z1xwV for ; Mon, 4 Nov 2024 09:25:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B3C7385841D for ; Sun, 3 Nov 2024 22:25:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by sourceware.org (Postfix) with ESMTPS id 079E23858C56 for ; Sun, 3 Nov 2024 22:22:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 079E23858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 079E23858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672568; cv=none; b=vizw/lfiha6tTWN/niQpSamZ4cjR0OuIQRkcGhIGZxfJsegz4lJvntBmM6nOQ3wJjqbMbroERsyiyd7SNE3XXjtcpLLHkoyWupSsFUG32uSppAiHqOIIrbu2oABOCq3DMoA8YNnFvN8X8FN6uHvwWU8tUivTUA2o7pP8xg0bhTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672568; c=relaxed/simple; bh=6P4h5spvSKVkS5oE6M/C0vS6W1aMLqA4Pf9lXx75vnI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Aim9xpZOLxUjVcUE6Eg7oAsOvkINyEhxmL8f3NPXFkirxXW/hdT7EkrDgkv+RoWgekTZwIDkmlh9/VASQgrKNUPa/3MDUUquIGmuMvXUJ+uZT6GUBlsvUU6YhpICXA/9xYPfJwcWisrJOG8QO/qni1fU4uMcow8wrDoW06kKhUY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-6cc1b20ce54so32335216d6.0 for ; Sun, 03 Nov 2024 14:22:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672565; x=1731277365; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G4Ft5DMmJiRWxGTzHRMQr4BXfSkLaJ56kREhiA8n7DM=; b=FtmWGEwpouMf2DLt/xNW1WrHQEUjN//E0NS7om7WD49XYQUKa+DbXb7gRki6p2bGy7 vfCkCXKZCkaBpaaomugs5Zpph1ZR7FR0XXnZmu1kxbo12rA9irPtFsC9dZO9OcVA5yg5 31jB7v+JLBsMrjmfaKcupPlkF58Y/noebS2ZSyARRPzKHGXbxRyaLXgvW1Qkt8AGvpl6 qdFTAf6mJNTV5heMUIBKiL31u0gIa3GYD6sofZ1kQV6ZmfQXunVkpN/MChmwCPnumd/7 eTGahALUmuWV7uzddWg4jQXQVlz8LIPxc8jXzkJYvKbYwzwAUxYaGuJbwfyFr9vn2Y2/ S6zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672565; x=1731277365; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G4Ft5DMmJiRWxGTzHRMQr4BXfSkLaJ56kREhiA8n7DM=; b=Jbc6IdEXNue1HrnYQAzkDN7CNbghos5i8/E5RxH1mYrsqfcN36xMY9YkbsQLT83qIG kHFtgD2ClBmezNfVUwuL5ZUotidxNzSJt7j3qD2yMBChCt7pyBOV00GhMSEo13YpsbWg CN/EWdff6MGRxDVdjGlB5tAVCHhcSuaSpOmzgidjral77vOxDySpX/KJrP8/3zFTZr2A /MO+154ukiqL4gqXM5uhdqTA/r5COk9HbFVRvCU3Kqecy8gre/QOFLFn803rmYBcNRLr YnRqCXplBPDVCa/s6uaWj3wAP7hmRW7szwiTHEsau3hRhrK4JBQze1J8SWxkpXrcE49O l7yQ== X-Gm-Message-State: AOJu0YynYn75c+ThXwXgc6Zi3DYId75r57uiVgo6O5WZm1vyZ+yOr6E0 bMraJcvf/it3t03FQTtVHKJR8xn6K+G5PKTzG+Guml44UCS9iJP8D5F+JA== X-Google-Smtp-Source: AGHT+IFOL+T9hyfcWuz6OszGCLiDxoOpn38sSvovGPbv6HaiC/j+GIN9HUbx7STM+NGFw9sq3Aq35A== X-Received: by 2002:a05:6214:4387:b0:6d1:85a7:3cc0 with SMTP id 6a1803df08f44-6d35c0f5494mr133343506d6.12.1730672565327; Sun, 03 Nov 2024 14:22:45 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:44 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 04/15] tree-phinodes: Use 4 instead of 2 as the minimum number of phi args Date: Sun, 3 Nov 2024 17:22:09 -0500 Message-Id: <20241103222220.933471-5-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Currently, when we allocate a gphi object, we round up the capacity for the trailing arguments array such that it will make full use of the page size that ggc will allocate. While there is also an explicit minimum of 2 arguments, in practice after rounding to the ggc page size there is always room for at least 4. It seems we have some code that has come to depend on there being this much room before reallocation of a PHI is required. For example, the function loop_version () used during loop optimization will make sure there is room for an additional edge on each PHI that it processes. But there are call sites which cache a PHI pointer prior to calling loop_version () and assume it remains valid afterward, thus implicitly assuming that the PHI will have spare capacity. Examples include split_loop () and gen_parallel_loop (). This works fine now, but if the size of a gphi becomes larger, e.g. due to configuring location_t to be a 64-bit type, then on 32-bit platforms it ends up being possible to get a gphi with only 2 arguments of capacity, causing the above call sites of loop_version () to fail. (They store a pointer to a gphi object that no longer has the same meaning it did before it got reallocated.) The testcases gcc.dg/torture/pr113707-2.c and gcc.dg/graphite/pr81945.c exhibit that failure mode. It may be necessary to adjust those call sites to make this more robust, but in the meantime, changing the minimum from 2 to 4 does no harm given the minimum is practically 4 anyway, and it resolves the issue for 32-bit platforms. gcc/ChangeLog: * tree-phinodes.cc (MIN_PHI_ARGS): New constant. (allocate_phi_node): Change from hard-coded value 2 to MIN_PHI_ARGS, which is now 4. (ideal_phi_node_len): Likewise. (release_phi_node): Likewise. --- gcc/tree-phinodes.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/gcc/tree-phinodes.cc b/gcc/tree-phinodes.cc index 5a7e4a94e57..9d8e16ac200 100644 --- a/gcc/tree-phinodes.cc +++ b/gcc/tree-phinodes.cc @@ -63,11 +63,12 @@ along with GCC; see the file COPYING3. If not see walking the elements of the last array entry would result in finding less than .1% additional reusable PHI nodes. - Note that we can never have less than two PHI argument slots. Thus, - the -2 on all the calculations below. */ + Note that we can never have less than MIN_PHI_ARGS argument slots. Thus, + the subtraction of MIN_PHI_ARGS on all the calculations below. */ #define NUM_BUCKETS 10 -static GTY ((deletable (""))) vec *free_phinodes[NUM_BUCKETS - 2]; +#define MIN_PHI_ARGS 4 +static GTY ((deletable (""))) vec *free_phinodes[NUM_BUCKETS - MIN_PHI_ARGS]; static unsigned long free_phinode_count; static int ideal_phi_node_len (int); @@ -94,17 +95,18 @@ static inline gphi * allocate_phi_node (size_t len) { gphi *phi; - size_t bucket = NUM_BUCKETS - 2; + size_t bucket = NUM_BUCKETS - MIN_PHI_ARGS; size_t size = sizeof (struct gphi) + (len - 1) * sizeof (struct phi_arg_d); if (free_phinode_count) - for (bucket = len - 2; bucket < NUM_BUCKETS - 2; bucket++) + for (bucket = len - MIN_PHI_ARGS; bucket < NUM_BUCKETS - MIN_PHI_ARGS; + bucket++) if (free_phinodes[bucket]) break; /* If our free list has an element, then use it. */ - if (bucket < NUM_BUCKETS - 2 + if (bucket < NUM_BUCKETS - MIN_PHI_ARGS && gimple_phi_capacity ((*free_phinodes[bucket])[0]) >= len) { free_phinode_count--; @@ -145,9 +147,8 @@ ideal_phi_node_len (int len) size_t size, new_size; int log2, new_len; - /* We do not support allocations of less than two PHI argument slots. */ - if (len < 2) - len = 2; + /* We do not support allocations of less than MIN_PHI_ARGS argument slots. */ + len = MAX (len, MIN_PHI_ARGS); /* Compute the number of bytes of the original request. */ size = sizeof (struct gphi) @@ -225,14 +226,13 @@ release_phi_node (gimple *phi) /* Immediately return the memory to the allocator when we would only ever re-use it for a smaller size allocation. */ - if (len - 2 >= NUM_BUCKETS - 2) + if (len >= NUM_BUCKETS) { ggc_free (phi); return; } - bucket = len > NUM_BUCKETS - 1 ? NUM_BUCKETS - 1 : len; - bucket -= 2; + bucket = len - MIN_PHI_ARGS; vec_safe_push (free_phinodes[bucket], phi); free_phinode_count++; } From patchwork Sun Nov 3 22:22:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005822 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=EHxi+PQE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhTfw1NWwz1xxN for ; Mon, 4 Nov 2024 09:24:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 64D53385773C for ; Sun, 3 Nov 2024 22:24:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by sourceware.org (Postfix) with ESMTPS id 12296385842D for ; Sun, 3 Nov 2024 22:22:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12296385842D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 12296385842D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672579; cv=none; b=FhDp+wRfXOwV3suFDZU5dw26mrL6POvwHqq7k5YQ97WqXKeIBGtrxAQ452TLogttL7w+CF5HxWUAlsqQ+WkHrnSWILl/QVsxOXHgwGculHkPPwxV1uFNbXUSZp46ZIBYvOd6k3RxKLNifrJQ9MDUmtdayoj3y4uMTRQ3Wr/0p6w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672579; c=relaxed/simple; bh=HGtzUKXOSiXfTWMpqeAHVmqbXhGOftgPNsheoSa5kNk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=i38suL8x/70z8SJiVAt5zhtObeDzwXEhBOHOOtCqsDjll9n+3eZ44MNVv7MHAw8WAMMWwWRwt4dCf/rkETPqS9nf6IIGyWXxvr7r/DFZt5x47tsRFZuYcvnuxIw9hicuH5gNOp+xLqYcR659bB1ud1GdN4y7F35HweBobvCoTtU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-6cc250bbc9eso30676046d6.2 for ; Sun, 03 Nov 2024 14:22:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672567; x=1731277367; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5x4xBDFOdammAkxeNrXV7KUjyA0B/B4uM2wtumEiUwA=; b=EHxi+PQEjqZoCWuYFTPzvxeS4QhBBLh1y/BfRrFreMDm7tWoW/ZL1xuHJnjjSbd50W BYkpu3GXep+ZIyMJv240U+4qnZAioCz2YGZZA9CtUyvwq9Gxpmle+laBLztmPvOA4ZIP lmcrt0psfmYdSBiCNwRCZDW58i1Pzmr9qgthwd7IMjfUuwz1KF4C/KuvcXBNfaoCk9Wy qq7kejrg931fD152B/64n3aPR6OEh84r4QjRk+mWIpfZC+79xK6+LD/zvERPGMUQUWm3 4k7cjCpQUEvcq09BckH2TRVsDeH3fVyYMlsMJsrnRAPWuhSV+P8jVDUUS07FoBOUYJqw FSEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672567; x=1731277367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5x4xBDFOdammAkxeNrXV7KUjyA0B/B4uM2wtumEiUwA=; b=q4UsZ+skBG82UtdZXVkj2awL7M5U3ySoVtOmxaLXzPaBk38DojiZxmq1KYKYk4GetT P/LikrF9Cg7muyhSway8oaC+/u17vPrmaftGzzyhlWH0iuy67tkxtsb76D271/cbw3a2 m5FUAXuJIikDcSeCbYi3wWdGmx21xhtEeIEqORi0mL6llHavw+nLferLqXJir6E38UMe mqJn+eHHcKcs04Cra9uT/r0ZE36QSlpnrs87zyq+6qsHWebESpXVoeHeG9xTmSTR7Kn9 HA8xDtMi0RlzuM1YhIM+rWlI1aD5L/8BMrn0jd9XsGv4WVBsiQpN3qhZNfSAZOsgVnw8 dN5Q== X-Gm-Message-State: AOJu0Yz36o9hlZILtUIepXDS0ePTvVgrx7tZsjvmlswN6AORic+DPi1Y P6s9LOpfgr7PmqLmtJnjPSWmlaI5bQZlz7kDQDs7AnfnDf9zGtdIY7uWkQ== X-Google-Smtp-Source: AGHT+IHicWXErvg/3AXIZL5TeZOtvxS1QTuD3N14m/+rDED85u/RkrTnX5eNY0q0OTi1sBbX1WeLEw== X-Received: by 2002:a05:6214:3f88:b0:6c7:5e6d:3f79 with SMTP id 6a1803df08f44-6d351b2fb6dmr190727256d6.48.1730672567417; Sun, 03 Nov 2024 14:22:47 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:46 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 05/15] c++: Fix tree_contains_struct for TRAIT_EXPR Date: Sun, 3 Nov 2024 17:22:10 -0500 Message-Id: <20241103222220.933471-6-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org CODE_CONTAINS_STRUCT () currently reports that a TRAIT_EXPR contains a TS_EXP struct, but it does not actually start with a TS_EXP as an initial sequence. In modules.cc, when we stream out a tree, we explicitly check for the TS_EXP case and call note_location(t->exp.locus) if so. Currently, this actually queries the tree_common::chain field of a tree_trait_expr, which seems not to be used, returning 0, which is interpreted as UNKNOWN_LOCATION and does no harm. If location_t has been configured to be 64 bytes, then on 32-bit platforms (well those, such as sparc, on which uint64_t has higher alignment requirement than a pointer), reading t->exp.locus ends up reading a different field (tree_trait_expr::type1) due to padding offsets. That field is not generally 0, and the resulting bogus location_t is sufficiently problematic to cause an ICE in the line_map code. Pretty much any modules testcase displays the issue, such as partial-2_a.C. Resolve by initializing tree_contains_struct with the correct value for TRAIT_EXPR, namely TS_TYPED. gcc/cp/ChangeLog: * cp-objcp-common.cc (cp_common_init_ts): Change TRAIT_EXPR from TS_EXP to TS_TYPED. --- gcc/cp/cp-objcp-common.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index 7a0636f1653..1e43db31db8 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -617,6 +617,7 @@ cp_common_init_ts (void) MARK_TS_TYPED (PTRMEM_CST); MARK_TS_TYPED (LAMBDA_EXPR); MARK_TS_TYPED (TYPE_ARGUMENT_PACK); + MARK_TS_TYPED (TRAIT_EXPR); /* Random new trees. */ MARK_TS_COMMON (BASELINK); @@ -684,7 +685,6 @@ cp_common_init_ts (void) MARK_TS_EXP (TAG_DEFN); MARK_TS_EXP (TEMPLATE_ID_EXPR); MARK_TS_EXP (THROW_EXPR); - MARK_TS_EXP (TRAIT_EXPR); MARK_TS_EXP (TYPEID_EXPR); MARK_TS_EXP (TYPE_EXPR); MARK_TS_EXP (UNARY_PLUS_EXPR); From patchwork Sun Nov 3 22:22:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005821 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=MmRmedPk; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhTfs4f2lz1xxN for ; Mon, 4 Nov 2024 09:24:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D7C003857BA0 for ; Sun, 3 Nov 2024 22:24:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by sourceware.org (Postfix) with ESMTPS id 804673857BA9 for ; Sun, 3 Nov 2024 22:22:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 804673857BA9 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 804673857BA9 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f31 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672575; cv=none; b=mdhvYZm0GQq6qSj2BvSgK6Y56WeYCoGA6kU2Hvdm/ty/5TT98ylNfDRmQFPpoDgDJwWjmrgNJJHcaHiH/8XHTFqEeC5MbXzp3FA5S1IAyrKtWvjExsoLC6x+3Loe/Ly3uI+ItptBCSILD93AYN3U4uwv1v1XKXqHUcGQhDxZjMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672575; c=relaxed/simple; bh=bEH/qWxsiNyhjAFgzt6hOIf6F4W8OnjqpjF4EzJqAJM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=KKz1sTvSyDg/WhKedfto0njffDG23Rz+GTrQuNXdPKg+8tGYGcIO1YeYoYJSJXAIlFahwaLvHZVf9ZTtmVnMY/lU5naHHSOAaSJv7kUHtkoDComczD/pK8lycvShTz1XGWVbkHdWu88vAiTtTH2vPg3bkTngshZhIuiZBajvoTo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-6cbd1ae26a6so27130156d6.1 for ; Sun, 03 Nov 2024 14:22:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672569; x=1731277369; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZXNxqoaHV/1lB3n7jzuAb7cInbmAG5Ic8s8lghOZBrE=; b=MmRmedPk/kSbu3sZnGTuCniZbp3XXjbb4LKrB7fdiM2XrWskXS9at285iOZT0Si2GR qyVd+KkDeZPf7PjBDSVE8xp5odxdGkNXteWMZr0L8WbdG0YkPHq/okGceCdiSEpxt6Ql kLqRt7W0XVBWARiPghgy9lqB2vJjODS2z0Dl6Fl6sOarKodZWVT7UDokKykgsWXYJNjq TuKumVpNPfNEet/MlWQtwhvrvt0sZzqWy0F+W8807NEYBlmRRAFoxhALk2jGlpWju+3T OJjkI6Zr0Cr4x3dOZNvFBtjPJm5j0tN2q1Z+JRbfaCGE/h+NehT+xmgoxD8gESUCJASI u/mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672569; x=1731277369; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZXNxqoaHV/1lB3n7jzuAb7cInbmAG5Ic8s8lghOZBrE=; b=JFLqmGCXMXR+Jz5xvdSgBSXBE3GP7xkeqV7nlRInCYcTz71lREzpgkkDu0Jki+dFzK 9HojpeDoG4TpZL1Xpfye909rpjgLPtaxiHWFGgCU9mEzWDSsUkMDHrdwyZ5tNYmAjnA0 b3RYqCBvVBPuEXpxxH7jgEal/Lur4HdifEc/TKHLikwsTE6FeyCovNa1c9EMdZ3f0ZPY keQK7TWQXZ/L1rZOcE1VTBwP5hIN3aV2IZdeSmWYpWJpSCHs3Wl2v0+LCWUTKlF5Z75y lsbAuCjnsIfdADPzHMfkdk/PDXNZjc36Ac7qN2TxPNqCLHIG3qsWeX1iW2PMXm7MfN3r Th0Q== X-Gm-Message-State: AOJu0YzDiIzcavGEV6kLtNrwKWPZImpTh81K2rJJ/X475fTXFu17mMen 8nwnFYcbzVL9LXfu4AXWVfbuuYoxFiErQaFjTJG7P0Co6n3vV3pLWMwehA== X-Google-Smtp-Source: AGHT+IGQSm4bfI4d1iCQvX1oOjOKC3rYDv93FVm5Qoe+OgNhfS6LhbsQB01gb4xW3rzjGX+fEfp/qw== X-Received: by 2002:a05:6214:327:b0:6d3:45e3:d794 with SMTP id 6a1803df08f44-6d345e3d98bmr217422606d6.11.1730672568792; Sun, 03 Nov 2024 14:22:48 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:47 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 06/15] gimple: Handle tail padding when computing gimple_ops_offset Date: Sun, 3 Nov 2024 17:22:11 -0500 Message-Id: <20241103222220.933471-7-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org The array gimple_ops_offset_[], which is used to find the trailing op[] array for a given gimple struct, is computed assuming that op[] will be found at sizeof(tree) bytes away from the end of the struct. This is only correct if the alignment requirement of a pointer is the same as the alignment requirement of the struct, otherwise there will be padding bytes that invalidate the calculation. On 64-bit platforms, this generally works fine because a pointer has 8-byte alignment and none of the structs make use of more than that. On 32-bit platforms, it also currently works fine because there are no 64-bit integers in the gimple structs. There are 32-bit platforms (e.g. sparc) on which a pointer has 4-byte alignment and a uint64_t has 8-byte alignment. On such platforms, adding a uint64_t to the gimple structs (such as a location_t with --enable-large-source-locations) causes gimple_ops_offset_ to be 4 bytes too large. It would be nice to use offsetof() to compute the offset exactly, but offsetof() is not guaranteed to work for these types, because they use inheritance and so are not standard layout types. This patch attempts to detect the presence of tail padding by detecting when such padding is reused by inheritance; the padding should generally be reused for the same reason that offsetof() is not available, namely that all the relevant types use inheritance. One could envision systems on which this fix does not go far enough (e.g., if the ABI forbids reuse of tail padding), but it makes things better without affecting anything that currently works. gcc/ChangeLog: * gimple.cc (get_tail_padding_adjustment): New function. (DEFGSSTRUCT): Adjust the computation of gimple_ops_offset_ to be correct in the presence of tail padding. --- gcc/gimple.cc | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/gcc/gimple.cc b/gcc/gimple.cc index f7b313be40e..f0a642f5b51 100644 --- a/gcc/gimple.cc +++ b/gcc/gimple.cc @@ -52,12 +52,36 @@ along with GCC; see the file COPYING3. If not see #include "ipa-modref.h" #include "dbgcnt.h" -/* All the tuples have their operand vector (if present) at the very bottom - of the structure. Therefore, the offset required to find the - operands vector the size of the structure minus the size of the 1 - element tree array at the end (see gimple_ops). */ +/* All the tuples have their operand vector (if present) at the very bottom of + the structure. Therefore, the offset required to find the operands vector is + the size of the structure minus the size of the 1-element tree array at the + end (see gimple_ops). An adjustment may be required if there is tail + padding, as may happen on a host (e.g. sparc) where a pointer has 4-byte + alignment while a uint64_t has 8-byte alignment. + + Unfortunately, we can't use offsetof to do this computation 100% + straightforwardly, because these structs use inheritance and so are not + standard layout types. However, the fact that they are not standard layout + types also means that tail padding will be reused in inheritance, which makes + it possible to check for the problematic case with the following logic + instead. If tail padding is detected, the offset should be decreased + accordingly. */ + +template +static constexpr size_t +get_tail_padding_adjustment () +{ + struct padding_check : G + { + tree t; + }; + return sizeof (padding_check) == sizeof (G) ? sizeof (tree) : 0; +} + #define DEFGSSTRUCT(SYM, STRUCT, HAS_TREE_OP) \ - (HAS_TREE_OP ? sizeof (struct STRUCT) - sizeof (tree) : 0), + (HAS_TREE_OP \ + ? sizeof (STRUCT) - sizeof (tree) - get_tail_padding_adjustment () \ + : 0), EXPORTED_CONST size_t gimple_ops_offset_[] = { #include "gsstruct.def" }; From patchwork Sun Nov 3 22:22:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005829 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=IOAvxRDr; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhTjg3nzGz1xwV for ; Mon, 4 Nov 2024 09:27:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B7B123857BA9 for ; Sun, 3 Nov 2024 22:27:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by sourceware.org (Postfix) with ESMTPS id 2BEF2385802C for ; Sun, 3 Nov 2024 22:22:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2BEF2385802C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2BEF2385802C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672575; cv=none; b=rABFWfrTS1gI5fyXkQ0MW6WEJEscDcUisJliw4argfzcctqxczF9l2cxBNlMFYLMt9hUQNuqt2ussmb7h3twb2PRaZmlB9TvBEsaUPBJHMEEiItcpG3YVtLcJzy9s+OkHCcz1Mk/vMQ+DQ5yKmrfFdRFD8DTmalAUEi7eSqD184= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672575; c=relaxed/simple; bh=f5AN9arV+NL/BpaYBxlkiEz2h/e/bFC5rxyltTJ3oN0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=g+AtGCYQPCWHatxCmP0HsZJVuOhOu/jZQ/lbCCshGRDgLvGUtcPwhq3MK0KSjeGBPPw/EJnt/ScIlmfHXcI0h1PtmbIotaHa6aBECq+IlEG3Ooo8U0CPZTXYh2FCN2tS4emYXfIbl5d7jXgNACgzDdK5Ngan9clkQVrvpEqux98= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-6cbf347dc66so25014806d6.3 for ; Sun, 03 Nov 2024 14:22:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672569; x=1731277369; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6S1fLGJBlqzK7AlLuXip3BMMQl3M1tZg5K15L5R9Y0Q=; b=IOAvxRDrc7NzROU+Ta5l7gE0DJm/0I5ioLMgc1y16A109qKzJ9/LlTi2CxAs5vri7b 7LXvCT/adhT1GXP8UOrWBsC04lRLXz/kKCLNXLbKHMup6/sR3ccPAvBDkUFbhBMQytga uSQXtvztrsFE9X9lTKMfxJXiINBWB3Lm0R7VEk0cobfrq3FCvCXYEx8fgbk7knv1KPh4 62glqtd8c0qUvhxD/fC0isEB3REBqSSJf67Ii+Ta3WUvZrfd5zQ1vQmvCnYKgWUjBhZC Nn0wjm8u1XdVCsZSyt5zo2vkv0NfCnlsDA1pTzhLuXrKebzbrMwnrmRx2R/hsCIU99Bk 9LKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672569; x=1731277369; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6S1fLGJBlqzK7AlLuXip3BMMQl3M1tZg5K15L5R9Y0Q=; b=PbMjRULrt64YSivFhGsMZ5KnYPZDXaRDXtmWgA4yS/jEgIkhrZ9U6IQPgReMHvLQTM d4WygwULIPp/nmLAM1Av/ANyZ3xYmzELrjt0zuCvVwjzhhyzRL272BLKiyA6cMA5bhUb D+rxNPohTItqiSnfmX7Ez0QdLgXhsJgFVEJuzQ+1vncFUzv6I+V3YE1qi+bnom09OcCw sN5wznr5WcnunS1WZyizMyd1q7jkglJ5oStKlJeNBc3sFGVkdUywTFcAcNtQ/fXFmc+Y Wy+z+qyYFQEv0Fmohq1FimsVcTHyiAaXJzhduQSaCTEAPK9Layq9FT6Q69pd9SDR+5nW 8vEw== X-Gm-Message-State: AOJu0YyD0BHNWHYOzkFB/rhyeHYLmPgcQtI1BSVR9+JOISSXOqxdbE9U AUCSsxxSl5GmQiyfOiizV/l4CuzJ9vRqU+0O49JMk6Abk73wEPQN7bK/KA== X-Google-Smtp-Source: AGHT+IGSrvCCveJNIYt0Oy6+NrIFPufqhkbgS0q/NSosHHTO/WGisStyHxHBnopNUzwH7anLDATGBQ== X-Received: by 2002:a05:6214:54c4:b0:6ce:37cc:4911 with SMTP id 6a1803df08f44-6d35c08821dmr177843546d6.8.1730672569541; Sun, 03 Nov 2024 14:22:49 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:49 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 07/15] Support for 64-bit location_t: toplev parts Date: Sun, 3 Nov 2024 17:22:12 -0500 Message-Id: <20241103222220.933471-8-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org The recommended bits reserved in a line_map to store ranges has always been 5, meaning that identifiers up to length 32 can be stored without generating an ad-hoc location. When 64-bit location_t is configured, there are plenty of bits to go around, and so the recommended default is larger. line-map.h now exports the recommended setting based on what was configured, so make use of that when setting up the line map rather than hard-coding 5. Also silently ignore -flarge-source-files when configured with 64-bit location_t. That flag is a workaround for cases where we run out of 32-bit location_t entries; it effectively makes every token's location an ad-hoc location, making more of the location_t space available for tracking source locations. This workaround is not necessary with a 64-bit location_t. gcc/ChangeLog: * toplev.cc (general_init): Use constant line_map_suggested_range_bits instead of hard-coded integer. (process_options): Silently ignore -flarge-source-files if 64-bit location_t is in use. --- gcc/toplev.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcc/toplev.cc b/gcc/toplev.cc index 779049674b4..655be409a36 100644 --- a/gcc/toplev.cc +++ b/gcc/toplev.cc @@ -1137,7 +1137,7 @@ general_init (const char *argv0, bool init_signals, unique_argv original_argv) linemap_init (line_table, BUILTINS_LOCATION); line_table->m_reallocator = realloc_for_line_map; line_table->m_round_alloc_size = ggc_round_alloc_size; - line_table->default_range_bits = 5; + line_table->default_range_bits = line_map_suggested_range_bits; init_ttree (); /* Initialize register usage now so switches may override. */ @@ -1765,8 +1765,10 @@ process_options () hash_table_sanitize_eq_limit = param_hash_table_verification_limit; + #ifndef ENABLE_LARGE_SOURCE_LOCATIONS if (flag_large_source_files) line_table->default_range_bits = 0; + #endif diagnose_options (&global_options, &global_options_set, UNKNOWN_LOCATION); From patchwork Sun Nov 3 22:22:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005820 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=IZS7VLu/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhTfM06cKz1xxN for ; Mon, 4 Nov 2024 09:24:11 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3CA7C3857000 for ; Sun, 3 Nov 2024 22:24:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by sourceware.org (Postfix) with ESMTPS id 53EE1385841D for ; Sun, 3 Nov 2024 22:22:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 53EE1385841D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 53EE1385841D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672580; cv=none; b=gfmqSKw4m9iEjH3b60UDhOCwmR4nrCd46D6aSnbJFr8JCoLqW+QDcD3kn3z7K6XtXmEWbBVZO4IGHxCm81Eu6lE+cYYHE+aawCiga+Nt9yLl3xQT6jSRr/8p+EuES5M1Z2b8+R1oGZ7q7W2slyvqc6ooLQWVs/BR+tleCibwwC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672580; c=relaxed/simple; bh=HSoCJPiz9Vt8lgTOunG0o3wlhVT1N2NaceS429IicNA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=KsoGbt2qF0DjDiwZWs7AwgFghGEx28rHTdVHwmgTgJzJLBw2m3yXMZH7GhT9yUr7cSxzONCu7KzvfcaoDWOPn2k5zwQWGCJ8zwMc0zTIKNvUo3NEOC6YPiT9eG4h8lpr9P/gyyOSUSzRFvOkmxizLpRyAd8ZSGK0VeS8NCQOim8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf32.google.com with SMTP id 6a1803df08f44-6cbe3e99680so20730946d6.3 for ; Sun, 03 Nov 2024 14:22:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672571; x=1731277371; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=A8XE3yt/EZII79g4rt0VsO894nr+xhphYsgHew1XD08=; b=IZS7VLu/Qd3pe0BbmAiew8AaHQCwhRL4pt1afbIK2USI19dnJxp5GIU8y1TOZ9FTFa mFAu9x+ihhcqxY8oGKLrq2yw2d8vvgr0idKjqFDjo+o48tNPuhL0MYIbudQCFijKQmrw 95RxTc9dTNa30kp4AL370aXL3X1vE0U0r/7Ui25fli1gucB+k0L7H0Ox8Jtf7uP3ABzQ WA5w5Doq2XhQsM/roR0xNuSsgOB7IBRkLAKq4mujeUjVKiHP7ePioZ3W0sctUoyVYZmX 3WBBXerFjv3bxu9uwbd/m40iWWcpk2NBgole8UQYjcJPJPpl7rkg5A6Ja/vPFCXK9Lzi +ndg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672571; x=1731277371; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A8XE3yt/EZII79g4rt0VsO894nr+xhphYsgHew1XD08=; b=C2+ZtkRAQFJPUbN9ZBizQsMUBkUMwMC0ocwhugDDr86Miq7AMRokgNTCSzYIYy7Hcn CHvY0LAin4qerH2NMbVBQzAfEu8aN49rMcBJV9BYLwKDb/CZCRNqgXOqqZ9c+OguO+6m 2h0ct4ebGrth8k7ZFh0jBVwL+BZnyflcIKufvLv/1LYR0Qo9Fa47KFhDMZbkUzdaogmv SF2azn5mTtLydVfodL0zFj/yTH+gEN6M4QO9J5fqLcLKdHphUjlhNsO5al0mZmacq3z0 yONgEILOViAZi03OYIl8+sM6DI3LK4Be2P750hsGTxmHjyx87YuzxTkKdjq+oUTZMWJv VdQw== X-Gm-Message-State: AOJu0YxkC7zTWzd/0wc9neleodKWhcxeHp+MAuNVIhOPJj83V4QwNkUZ pE/WyVMy4aW0iGmi9XQPUh05wm1uXZLgtTa5Q63hWF6+bch6OuVuLdPYnA== X-Google-Smtp-Source: AGHT+IEpcVRZUQv6qAyTN4VDmvdxtpL0uoNbnU5Ovt7RvibjuR6X46QsGRnI9TiWYLI8V1GYL1tnjA== X-Received: by 2002:a05:6214:4a05:b0:6cb:f075:57da with SMTP id 6a1803df08f44-6d185674354mr491769576d6.7.1730672571536; Sun, 03 Nov 2024 14:22:51 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:50 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 08/15] Support for 64-bit location_t: Analyzer parts Date: Sun, 3 Nov 2024 17:22:13 -0500 Message-Id: <20241103222220.933471-9-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org The analyzer occasionally prints internal location_t values for debugging; adjust those parts so they will work if location_t is 64-bit. For simplicity, to avoid hassling with the printf format string, just convert to (unsigned long long) in either case. gcc/analyzer/ChangeLog: * checker-event.cc (checker_event::dump): Support printing either 32- or 64-bit location_t values. * checker-path.cc (checker_path::inject_any_inlined_call_events): Likewise. --- gcc/analyzer/checker-event.cc | 4 ++-- gcc/analyzer/checker-path.cc | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gcc/analyzer/checker-event.cc b/gcc/analyzer/checker-event.cc index 5a292377e93..bb26f71e4b4 100644 --- a/gcc/analyzer/checker-event.cc +++ b/gcc/analyzer/checker-event.cc @@ -188,8 +188,8 @@ checker_event::dump (pretty_printer *pp) const if (m_effective_fndecl != m_original_fndecl) pp_printf (pp, " corrected from %qE", m_original_fndecl); } - pp_printf (pp, ", m_loc=%x)", - get_location ()); + pp_printf (pp, ", m_loc=%llx)", + (unsigned long long) get_location ()); } /* Dump this event to stderr (for debugging/logging purposes). */ diff --git a/gcc/analyzer/checker-path.cc b/gcc/analyzer/checker-path.cc index 98b59884174..25d95fe0bfc 100644 --- a/gcc/analyzer/checker-path.cc +++ b/gcc/analyzer/checker-path.cc @@ -281,8 +281,9 @@ checker_path::inject_any_inlined_call_events (logger *logger) logger->log_partial (" %qE", iter.get_block ()); if (!flag_dump_noaddr) logger->log_partial (" (%p)", iter.get_block ()); - logger->log_partial (", fndecl: %qE, callsite: 0x%x", - iter.get_fndecl (), iter.get_callsite ()); + logger->log_partial (", fndecl: %qE, callsite: 0x%llx", + iter.get_fndecl (), + (unsigned long long) iter.get_callsite ()); if (iter.get_callsite ()) dump_location (logger->get_printer (), iter.get_callsite ()); logger->end_log_line (); From patchwork Sun Nov 3 22:22:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005825 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=NRCyNyTT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhTgj2gMBz1xwV for ; Mon, 4 Nov 2024 09:25:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 90F743857C7A for ; Sun, 3 Nov 2024 22:25:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by sourceware.org (Postfix) with ESMTPS id 50B203857705 for ; Sun, 3 Nov 2024 22:22:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 50B203857705 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 50B203857705 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672585; cv=none; b=uQvjRFqboNcv7N9uSoUqGnChST1TKT3tu/nJ/DKxNLa1fLW0UqZJ46dFu3MAEhuDwAlO+QQXrSwZGcuOCrEwJdhaTyxW5jZj5OoYAQ5DFUsEV6Q0514hNABa8pP43XKZBMCtYXOJeJNee9V8g/0WOv7NsylAJlfoQtTwBtwVaiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672585; c=relaxed/simple; bh=BimFA5NtBLqwJK1VlCx2iKtU3YXngOkHdEBrycPEn4s=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=to5FSGydqLRtaflEVytmYhVO5Kzi7EHQCRBiv0IduIrpTdSUMks+327yhKfyQHaz9ayraEJnSgbaduX22U0XgIBDRIAA7wluWvSYVY2F4rRzizizWohMCHV3TZlh3+k98D1WkobMau3TUFAjYF3sVP7vokZetMyTts6COzzFfeo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-6cbf2fc28feso26528596d6.0 for ; Sun, 03 Nov 2024 14:22:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672573; x=1731277373; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+DsZ08HYY4nHVDv5+r7nKZYj0TeTNyRHNgRpQdW7hXw=; b=NRCyNyTTYU0lbiFdRJ2S3MMfRPgMCJQww0E99UB3J3/IdhpLxZ/pJAST3SVnR+SsJS q4L+OxLVhJpXT6JEkxhQ5uhOPRzq9MXlOaLZOBN1eaQW/JIYW7yoXgrb2ejCJCChEJZ6 +KxVy50w4ygQpERe9PeRkamP/Xs6IGIbAJG/41QABxaE/4dKotqynpvcsJq9zYEkXUJ8 Okm1LIngpdo62utZaohuBgJ+KyCzDn9rIOH/sR8I+dq6zaiucpVtZDi8qySVNSO6yQKa HKEERb5sQGw1XBu5qfowEh7yIh4qxgmh5qzo39NCnhDZ4lDiWoMkbKjh0CYTlMWem5dO PIBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672573; x=1731277373; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+DsZ08HYY4nHVDv5+r7nKZYj0TeTNyRHNgRpQdW7hXw=; b=cj0ziBz0h1Xq70LsOlu93K9Om0L8EK+DGg8ZlMbvJ3ftzztdoNdb5NDNyw8LFqIXqQ mTJIWCp6VShZeekVJfCR4IY33rYMJcnE5w54m75wubVhz+KmghUmYz8bZoMapzWCfkPI EqkIyjDaBlGMMPWcoG5Xcb9QzZnn00u7iuikA5pZ63ruU/Az560JQbWarRO/Or28nTBh S9+AgP5wufVKnSjaE29opt/aM0BqnKnJn+i/Z0/HvGEb5UtCfQY64pXUoMH4YVc2XFKA BfxRoCj6CIfGlI6tLX7OqB/QLLmXdfaJtd9d/9ELEiE8EVUiIlwBL2znrgpvgfBHeR9h vw0Q== X-Gm-Message-State: AOJu0YwqmAQ2sFiHTpQhKnpBXt/k2K55ZTileKESY9tAZitCJPp4GW39 wDb+Kkhuuy9fzGNhZVhUi20gUy9mHqfhvFBNPUm3QI7bq7drvjjrKon1Xw== X-Google-Smtp-Source: AGHT+IFncZK79TShKZqUquPBoXqFUmtwIwFl4RebFyi7gaB4sOzVBpxCAA7HUfCltndYdgu0ZyNcjw== X-Received: by 2002:a05:6214:5248:b0:6cb:ef96:c79e with SMTP id 6a1803df08f44-6d185843521mr526787276d6.34.1730672573673; Sun, 03 Nov 2024 14:22:53 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:52 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 09/15] Support for 64-bit location_t: Frontend parts Date: Sun, 3 Nov 2024 17:22:14 -0500 Message-Id: <20241103222220.933471-10-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org The C/C++ frontend code contains a couple instances where a callback receiving a "location_t" argument is prototyped to take "unsigned int" instead. This will make a difference once location_t can be configured to a different type, so adjust that now. gcc/c-family/ChangeLog: * c-lex.cc (cb_ident): Change "unsigned int" argument to type "location_t". (cb_def_pragma): Likewise. (cb_define): Likewise. (cb_undef): Likewise. --- gcc/c-family/c-lex.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc index f7168ce6fc0..b14f942b87b 100644 --- a/gcc/c-family/c-lex.cc +++ b/gcc/c-family/c-lex.cc @@ -54,10 +54,10 @@ static tree lex_charconst (const cpp_token *); static void update_header_times (const char *); static int dump_one_header (splay_tree_node, void *); static void cb_line_change (cpp_reader *, const cpp_token *, int); -static void cb_ident (cpp_reader *, unsigned int, const cpp_string *); -static void cb_def_pragma (cpp_reader *, unsigned int); -static void cb_define (cpp_reader *, unsigned int, cpp_hashnode *); -static void cb_undef (cpp_reader *, unsigned int, cpp_hashnode *); +static void cb_ident (cpp_reader *, location_t, const cpp_string *); +static void cb_def_pragma (cpp_reader *, location_t); +static void cb_define (cpp_reader *, location_t, cpp_hashnode *); +static void cb_undef (cpp_reader *, location_t, cpp_hashnode *); void init_c_lex (void) @@ -164,7 +164,7 @@ dump_time_statistics (void) static void cb_ident (cpp_reader * ARG_UNUSED (pfile), - unsigned int ARG_UNUSED (line), + location_t ARG_UNUSED (line), const cpp_string * ARG_UNUSED (str)) { if (!flag_no_ident) From patchwork Sun Nov 3 22:22:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005828 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=CnefTI3G; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhThz14RWz1xwV for ; Mon, 4 Nov 2024 09:26:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5BEC93858027 for ; Sun, 3 Nov 2024 22:26:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by sourceware.org (Postfix) with ESMTPS id 46E6D3858D29 for ; Sun, 3 Nov 2024 22:22:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 46E6D3858D29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 46E6D3858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672589; cv=none; b=h0yOYoJ8kN62uYUk1VQ/alLD6YJcZie96U/guFrJucyG6Mj9oKw3hwqMJ5plP1q4moNzwOzF3LJlblbJThXh1vDZ8DZO78ndh0/r/Hk/XjWMrYn45ZMXg2yyamLaS/Nt/1T7jgI1W4uHF5Cmir9EOCJ1SQ+feG/ojsWP+BAkkqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672589; c=relaxed/simple; bh=z+HbZ+2KMFeT7whhGh2K3jp6kSPv+Fo7p+gAPqGffcY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=gztA6Tm4R0g3GhMM1mVvRFVoPc5tUrXGUPOJwQ+MUqJ4eL7oVgnbcrn10tyGacEXjjUaYSVolxEAOdeF1CGRQ7Ss6LQ6+UEzsyc8cDnPvRQ934WTU7+pJzeHlJdUqq6kGWlOel8gWvnA4kFS+1AFj1VA/esPyfJNTXTPBbqG85M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf2c.google.com with SMTP id 6a1803df08f44-6cbd00dd21cso22175536d6.3 for ; Sun, 03 Nov 2024 14:22:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672574; x=1731277374; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LmZXo6miDHFS3bi4m3maQVHoBqUbhu9H/UYkyJJKk1s=; b=CnefTI3GBS37aOPZUAL7A7iZZbY3hAi7elRiUGXgHDZ++iS2oB6Nmh3CcBrHI8K/r/ yGWgvJslUGj2oxZ0RYAhy3PuvxJ+KnptABHv+MeS3mKsk4ssnrq4TfwjehIufeOcK7HN Yu78BrKSIKiog2d2kcMkXLLgSNXoAPeF7JUoH5qFC3poINQm/5QY5Mcfkiknb1ASEbX3 GtsWpm225lWgMT7wUZpu28VByrw/5J4eJ+2eXPWYI54dgPJ/BnorYzJV9B6sJJ18JEWs 1wZ55COM8dsKqtmlhPM1qQrb5QQFd0pCLegVvtJNlAQz9jw6dXt+4/YjPL5lL3A5Nv7t FJMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672574; x=1731277374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LmZXo6miDHFS3bi4m3maQVHoBqUbhu9H/UYkyJJKk1s=; b=WBkKuBjq2Yk8V66VKeDvrjiFs2P4+VNWWgRS6VkrnOZ9PCHXqdeNQwqhSFa6T+DmR+ owY+SLY+eIktvC/dcaKY2lhBVu8UR0EkMPHY5dkuJjF4itrEJYjX6s20hPJBhIsaUUO7 leEKs+yMd0W2Yx8oWE4PHA6iOjXSXk6XKLGDEsFB5U1L1vcrCkZX1cGhggIMlQs2BhCO aMLGbXeqKiiwG8HP/1PEmMAU/lrFo5lT4woI3daBgzTdryHWszZA4THE/UP88vUpNSG3 dTzTZ4F63jXggEVzBc4a5xzkVAoqjkuVpqoV/tAv7ZUhe4DewGwm4vXSgbM6jitOp+Gg P4hQ== X-Gm-Message-State: AOJu0YyNja5bFUjMdVBs+MOBRqP+8ARyrd9eZsMwCSpDQEFHYJ8sUREC JjHRzLLb9xLGeaaAxPFgOw/jMx8tUffrWD37K4dM4bYZm+IVJ3nzV7aGaA== X-Google-Smtp-Source: AGHT+IEOl4ZJwZucK/lSULv0EvScxNa3kvB4a8ufY4tNFSKda/MkAXwwsrmfDDV0MBe1o2ZhQtFXTg== X-Received: by 2002:a05:6214:3d09:b0:6d1:992e:4c5a with SMTP id 6a1803df08f44-6d3460b89famr253409466d6.45.1730672574484; Sun, 03 Nov 2024 14:22:54 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:53 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 10/15] Support for 64-bit location_t: C++ modules parts Date: Sun, 3 Nov 2024 17:22:15 -0500 Message-Id: <20241103222220.933471-11-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org The modules implementation is necessarily sensitive to the internal workings of class line_map, and so it needed changes in order to handle a 64-bit location_t. The changes mostly boil down to supporting that in the debug dumping routines (which is accomplished by using a new custom code %K for that purpose), and supporting that when streaming in and out from the module (which is accomplished by using a new loc() function to go along with existing abstractions like u() or z() for streaming in and out different data types). gcc/cp/ChangeLog: * module.cc (bytes_out::loc): New function. (bytes_in::loc): New function. (struct span): Change int fields to location_diff_t. (range_t): Change from "unsigned int" to "line_map_uint_t". (struct ord_loc_info): Likewise. (struct macro_loc_info): Likewise. (class module_state): Likewise. (dumper::operator()): Add new code 'K' for dumping a location_t. (loc_spans::init): Use %K instead of %u for location_t dumps. (loc_spans::open): Likewise. (loc_spans::close): Likewise. Adjust bitwise expressions to support 64-bit location_t as well. (struct module_state_config): Change ordinary_locs and macro_locs from "unsigned int" to "line_map_uint_t". Reorder fields to improve packing. Rather than changing the constructor initializer list to match the new order, switch to NSDMI instead. (module_state::note_location): Adjust to support 64-bit location_t. (module_state::write_location): Use %K instead of %u for location_t dumps. Use loc() instead of u() for streaming location_t. (module_state::read_location): Likewise. (module_state::write_ordinary_maps): Likewise. (module_state::write_macro_maps): Likewise. (module_state::write_config): Likewise. (module_state::read_config): Likewise. (module_state::write_prepare_maps): Use %K instead of %u for location_t dumps. Adjust variable types and bitwise expressions to support 64-bit location_t. (module_state::read_ordinary_maps): Likewise. (module_state::read_macro_maps): Likewise. (preprocess_module): Adjust data types to support 64-bit number of line maps. --- gcc/cp/module.cc | 229 +++++++++++++++++++++++++++-------------------- 1 file changed, 130 insertions(+), 99 deletions(-) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index dde7e5f6dbf..415bdd41ea3 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -350,6 +350,9 @@ typedef hash_map ptr_int_hash_map; /* Variable length buffer. */ namespace { + +constexpr line_map_uint_t loc_one = 1; + class data { public: class allocator { @@ -549,6 +552,7 @@ public: int i (); /* Read a signed int. */ unsigned u (); /* Read an unsigned int. */ size_t z (); /* Read a size_t. */ + location_t loc (); /* Read a location_t. */ HOST_WIDE_INT wi (); /* Read a HOST_WIDE_INT. */ unsigned HOST_WIDE_INT wu (); /* Read an unsigned HOST_WIDE_INT. */ const char *str (size_t * = NULL); /* Read a string. */ @@ -633,6 +637,7 @@ public: void i (int); /* Write signed int. */ void u (unsigned); /* Write unsigned int. */ void z (size_t s); /* Write size_t. */ + void loc (location_t); /* Write location_t. */ void wi (HOST_WIDE_INT); /* Write HOST_WIDE_INT. */ void wu (unsigned HOST_WIDE_INT); /* Write unsigned HOST_WIDE_INT. */ void str (const char *ptr) @@ -1057,6 +1062,26 @@ bytes_in::z () return wu (); } +/* location_t written as 32- or 64-bit as needed. */ + +inline void bytes_out::loc (location_t l) +{ +#ifdef ENABLE_LARGE_SOURCE_LOCATIONS + wu (l); +#else + u (l); +#endif +} + +inline location_t bytes_in::loc () +{ +#ifdef ENABLE_LARGE_SOURCE_LOCATIONS + return wu (); +#else + return u (); +#endif +} + /* Buffer simply memcpied. */ void * bytes_out::buf (size_t len) @@ -3210,7 +3235,7 @@ trees_out::~trees_out () /* I use half-open [first,second) ranges. */ -typedef std::pair range_t; +typedef std::pair range_t; /* A range of locations. */ typedef std::pair loc_range_t; @@ -3227,8 +3252,9 @@ public: struct span { loc_range_t ordinary; /* Ordinary map location range. */ loc_range_t macro; /* Macro map location range. */ - int ordinary_delta; /* Add to ordinary loc to get serialized loc. */ - int macro_delta; /* Likewise for macro loc. */ + /* Add to locs to get serialized loc. */ + location_diff_t ordinary_delta; + location_diff_t macro_delta; }; private: @@ -3304,9 +3330,9 @@ static loc_spans spans; struct ord_loc_info { const line_map_ordinary *src; // line map we're based on - unsigned offset; // offset to this line - unsigned span; // number of locs we span - unsigned remap; // serialization + line_map_uint_t offset; // offset to this line + line_map_uint_t span; // number of locs we span + line_map_uint_t remap; // serialization static int compare (const void *a_, const void *b_) { @@ -3364,7 +3390,7 @@ static vec *ord_loc_remap; struct macro_loc_info { const line_map_macro *src; // original expansion - unsigned remap; // serialization + line_map_uint_t remap; // serialization static int compare (const void *a_, const void *b_) { @@ -3785,7 +3811,7 @@ class GTY((chain_next ("%h.parent"), for_user)) module_state { bool, unsigned *crc_ptr); bool read_ordinary_maps (unsigned, unsigned); void write_macro_maps (elf_out *to, range_t &, unsigned *crc_ptr); - bool read_macro_maps (unsigned); + bool read_macro_maps (line_map_uint_t); private: void write_define (bytes_out &, const cpp_macro *); @@ -4420,6 +4446,7 @@ dumper::impl::nested_name (tree t) Escapes: %C - tree_code %I - identifier + %K - location_t or line_map_uint_t %M - module_state %N - name -- DECL_NAME %P - context:name pair @@ -4496,6 +4523,13 @@ dumper::operator () (const char *format, ...) } break; + case 'K': /* location_t, either 32- or 64-bit. */ + { + unsigned long long u = va_arg (args, location_t); + fprintf (dumps->stream, "%llu", u); + } + break; + case 'M': /* Module. */ { const char *str = "(none)"; @@ -4565,7 +4599,7 @@ dumper::operator () (const char *format, ...) } break; - case 'V': /* Verson. */ + case 'V': /* Version. */ { unsigned v = va_arg (args, unsigned); verstr_t string; @@ -14264,7 +14298,7 @@ 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:[%K,%K) macro:[%K,%K)", spans->length (), interval.ordinary.first, interval.ordinary.second, interval.macro.first, interval.macro.second); spans->quick_push (interval); @@ -14278,7 +14312,7 @@ 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:[%K,%K) macro:[%K,%K)", spans->length (), interval.ordinary.first, interval.ordinary.second, interval.macro.first, interval.macro.second); spans->quick_push (interval); @@ -14287,7 +14321,7 @@ loc_spans::init (const line_maps *lmaps, const line_map_ordinary *map) 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:[%K,*) macro:[*,%K)", spans->length (), interval.ordinary.first, interval.macro.second); spans->quick_push (interval); } @@ -14318,7 +14352,7 @@ loc_spans::open (location_t hwm) = LINEMAPS_MACRO_LOWEST_LOCATION (line_table); interval.ordinary_delta = interval.macro_delta = 0; dump (dumper::LOCATION) - && dump ("Opening span %u ordinary:[%u,... macro:...,%u)", + && dump ("Opening span %u ordinary:[%K,... macro:...,%K)", spans->length (), interval.ordinary.first, interval.macro.second); if (spans->length ()) @@ -14340,11 +14374,12 @@ loc_spans::close () span &interval = spans->last (); interval.ordinary.second - = ((line_table->highest_location + (1 << line_table->default_range_bits)) - & ~((1u << line_table->default_range_bits) - 1)); + = ((line_table->highest_location + + (loc_one << line_table->default_range_bits)) + & ~((loc_one << line_table->default_range_bits) - 1)); interval.macro.first = LINEMAPS_MACRO_LOWEST_LOCATION (line_table); dump (dumper::LOCATION) - && dump ("Closing span %u ordinary:[%u,%u) macro:[%u,%u)", + && dump ("Closing span %u ordinary:[%K,%K) macro:[%K,%K)", spans->length () - 1, interval.ordinary.first,interval.ordinary.second, interval.macro.first, interval.macro.second); @@ -15054,23 +15089,14 @@ module_state::read_partitions (unsigned count) /* Data for config reading and writing. */ struct module_state_config { - const char *dialect_str; - unsigned num_imports; - unsigned num_partitions; - unsigned num_entities; - unsigned ordinary_locs; - unsigned macro_locs; - unsigned loc_range_bits; - unsigned active_init; - -public: - module_state_config () - :dialect_str (get_dialect ()), - num_imports (0), num_partitions (0), num_entities (0), - ordinary_locs (0), macro_locs (0), loc_range_bits (0), - active_init (0) - { - } + const char *dialect_str = get_dialect (); + line_map_uint_t ordinary_locs = 0; + line_map_uint_t macro_locs = 0; + unsigned num_imports = 0; + unsigned num_partitions = 0; + unsigned num_entities = 0; + unsigned loc_range_bits = 0; + unsigned active_init = 0; static void release () { @@ -16356,7 +16382,7 @@ module_state::note_location (location_t loc) const line_map_ordinary *ord_map = linemap_check_ordinary (map); ord_loc_info lkup; lkup.src = ord_map; - lkup.span = 1 << ord_map->m_column_and_range_bits; + lkup.span = loc_one << ord_map->m_column_and_range_bits; lkup.offset = (loc - MAP_START_LOCATION (ord_map)) & ~(lkup.span - 1); lkup.remap = 0; ord_loc_info *slot = (ord_loc_table->find_slot_with_hash @@ -16387,8 +16413,8 @@ module_state::write_location (bytes_out &sec, location_t loc) if (loc < RESERVED_LOCATION_COUNT) { - dump (dumper::LOCATION) && dump ("Reserved location %u", unsigned (loc)); - sec.u (LK_RESERVED + loc); + dump (dumper::LOCATION) && dump ("Reserved location %K", loc); + sec.loc (LK_RESERVED + loc); } else if (IS_ADHOC_LOC (loc)) { @@ -16408,7 +16434,7 @@ module_state::write_location (bytes_out &sec, location_t loc) else if (loc >= LINEMAPS_MACRO_LOWEST_LOCATION (line_table)) { const macro_loc_info *info = nullptr; - unsigned offset = 0; + line_map_uint_t offset = 0; if (unsigned hwm = macro_loc_remap->length ()) { info = macro_loc_remap->begin (); @@ -16434,18 +16460,18 @@ module_state::write_location (bytes_out &sec, location_t loc) { offset += info->remap; sec.u (LK_MACRO); - sec.u (offset); + sec.loc (offset); dump (dumper::LOCATION) - && dump ("Macro location %u output %u", loc, offset); + && dump ("Macro location %K output %K", loc, offset); } else if (const module_state *import = module_for_macro_loc (loc)) { - unsigned off = loc - import->macro_locs.first; + auto off = loc - import->macro_locs.first; sec.u (LK_IMPORT_MACRO); sec.u (import->remap); - sec.u (off); + sec.loc (off); dump (dumper::LOCATION) - && dump ("Imported macro location %u output %u:%u", + && dump ("Imported macro location %K output %u:%K", loc, import->remap, off); } else @@ -16454,13 +16480,13 @@ module_state::write_location (bytes_out &sec, location_t loc) else if (IS_ORDINARY_LOC (loc)) { const ord_loc_info *info = nullptr; - unsigned offset = 0; - if (unsigned hwm = ord_loc_remap->length ()) + line_map_uint_t offset = 0; + if (line_map_uint_t hwm = ord_loc_remap->length ()) { info = ord_loc_remap->begin (); while (hwm != 1) { - unsigned mid = hwm / 2; + auto mid = hwm / 2; if (MAP_START_LOCATION (info[mid].src) + info[mid].offset <= loc) { info += mid; @@ -16480,20 +16506,20 @@ module_state::write_location (bytes_out &sec, location_t loc) { offset += info->remap; sec.u (LK_ORDINARY); - sec.u (offset); + sec.loc (offset); dump (dumper::LOCATION) - && dump ("Ordinary location %u output %u", loc, offset); + && dump ("Ordinary location %K output %K", loc, offset); } else if (const module_state *import = module_for_ordinary_loc (loc)) { - unsigned off = loc - import->ordinary_locs.first; + auto off = loc - import->ordinary_locs.first; sec.u (LK_IMPORT_ORDINARY); sec.u (import->remap); - sec.u (off); + sec.loc (off); dump (dumper::LOCATION) - && dump ("Imported ordinary location %u output %u:%u", - import->remap, import->remap, off); + && dump ("Imported ordinary location %K output %u:%K", + loc, import->remap, off); } else gcc_unreachable (); @@ -16516,7 +16542,7 @@ module_state::read_location (bytes_in &sec) const else sec.set_overrun (); dump (dumper::LOCATION) - && dump ("Reserved location %u", unsigned (locus)); + && dump ("Reserved location %K", locus); } break; @@ -16538,7 +16564,7 @@ module_state::read_location (bytes_in &sec) const case LK_MACRO: { - unsigned off = sec.u (); + auto off = sec.loc (); if (macro_locs.second) { @@ -16550,13 +16576,13 @@ module_state::read_location (bytes_in &sec) const else locus = loc; dump (dumper::LOCATION) - && dump ("Macro %u becoming %u", off, locus); + && dump ("Macro %K becoming %K", off, locus); } break; case LK_ORDINARY: { - unsigned off = sec.u (); + auto off = sec.loc (); if (ordinary_locs.second) { if (off < ordinary_locs.second) @@ -16568,7 +16594,7 @@ module_state::read_location (bytes_in &sec) const locus = loc; dump (dumper::LOCATION) - && dump ("Ordinary location %u becoming %u", off, locus); + && dump ("Ordinary location %K becoming %K", off, locus); } break; @@ -16576,7 +16602,7 @@ module_state::read_location (bytes_in &sec) const case LK_IMPORT_ORDINARY: { unsigned mod = sec.u (); - unsigned off = sec.u (); + location_t off = sec.loc (); const module_state *import = NULL; if (!mod && !slurp->remap) @@ -16639,7 +16665,7 @@ module_state::write_prepare_maps (module_state_config *cfg, bool has_partitions) dump () && dump ("Preparing locations"); dump.indent (); - dump () && dump ("Reserved locations [%u,%u) macro [%u,%u)", + dump () && dump ("Reserved locations [%K,%K) macro [%K,%K)", spans[loc_spans::SPAN_RESERVED].ordinary.first, spans[loc_spans::SPAN_RESERVED].ordinary.second, spans[loc_spans::SPAN_RESERVED].macro.first, @@ -16695,10 +16721,11 @@ module_state::write_prepare_maps (module_state_config *cfg, bool has_partitions) ord_loc_table = nullptr; // Merge (sufficiently) adjacent spans, and calculate remapping. - constexpr unsigned adjacency = 2; // Allow 2 missing lines. + constexpr line_map_uint_t adjacency = 2; // Allow 2 missing lines. auto begin = ord_loc_remap->begin (), end = ord_loc_remap->end (); auto dst = begin; - unsigned offset = 0, range_bits = 0; + line_map_uint_t offset = 0; + unsigned range_bits = 0; ord_loc_info *base = nullptr; for (auto iter = begin; iter != end; ++iter) { @@ -16720,8 +16747,8 @@ module_state::write_prepare_maps (module_state_config *cfg, bool has_partitions) else if (range_bits < iter->src->m_range_bits) range_bits = iter->src->m_range_bits; - offset += ((1u << iter->src->m_range_bits) - 1); - offset &= ~((1u << iter->src->m_range_bits) - 1); + offset += ((loc_one << iter->src->m_range_bits) - 1); + offset &= ~((loc_one << iter->src->m_range_bits) - 1); iter->remap = offset; offset += iter->span; base = dst; @@ -16732,8 +16759,9 @@ module_state::write_prepare_maps (module_state_config *cfg, bool has_partitions) info.first = ord_loc_remap->length (); cfg->ordinary_locs = offset; cfg->loc_range_bits = range_bits; - dump () && dump ("Ordinary maps:%u locs:%u range_bits:%u", - info.first, cfg->ordinary_locs, + dump () && dump ("Ordinary maps:%K locs:%K range_bits:%u", + info.first, + cfg->ordinary_locs, cfg->loc_range_bits); // Remap the macro locations. @@ -16756,7 +16784,7 @@ module_state::write_prepare_maps (module_state_config *cfg, bool has_partitions) info.second = macro_loc_remap->length (); cfg->macro_locs = offset; - dump () && dump ("Macro maps:%u locs:%u", info.second, cfg->macro_locs); + dump () && dump ("Macro maps:%K locs:%K", info.second, cfg->macro_locs); dump.outdent (); @@ -16853,20 +16881,21 @@ module_state::write_ordinary_maps (elf_out *to, range_t &info, sec.str (fname); } - sec.u (info.first); /* Num maps. */ + sec.loc (info.first); /* Num maps. */ const ord_loc_info *base = nullptr; for (auto iter = ord_loc_remap->begin (), end = ord_loc_remap->end (); iter != end; ++iter) { dump (dumper::LOCATION) - && dump ("Span:%u ordinary [%u+%u,+%u)->[%u,+%u)", - iter - ord_loc_remap->begin (), - MAP_START_LOCATION (iter->src), iter->offset, iter->span, - iter->remap, iter->span); + && dump ("Span:%K ordinary [%K+%K,+%K)->[%K,+%K)", + (location_t) (iter - ord_loc_remap->begin ()), + MAP_START_LOCATION (iter->src), + iter->offset, iter->span, iter->remap, + iter->span); if (!base || iter->src != base->src) base = iter; - sec.u (iter->offset - base->offset); + sec.loc (iter->offset - base->offset); if (base == iter) { sec.u (iter->src->sysp); @@ -16884,7 +16913,7 @@ module_state::write_ordinary_maps (elf_out *to, range_t &info, line += iter->offset >> iter->src->m_column_and_range_bits; sec.u (line); } - sec.u (iter->remap); + sec.loc (iter->remap); if (base == iter) { /* Write the included from location, which means reading it @@ -16920,15 +16949,15 @@ module_state::write_macro_maps (elf_out *to, range_t &info, unsigned *crc_p) bytes_out sec (to); sec.begin (); - dump () && dump ("Macro maps:%u", info.second); - sec.u (info.second); + dump () && dump ("Macro maps:%K", info.second); + sec.loc (info.second); - unsigned macro_num = 0; + line_map_uint_t macro_num = 0; for (auto iter = macro_loc_remap->end (), begin = macro_loc_remap->begin (); iter-- != begin;) { auto mac = iter->src; - sec.u (iter->remap); + sec.loc (iter->remap); sec.u (mac->n_tokens); sec.cpp_node (mac->macro); write_location (sec, mac->m_expansion); @@ -16953,7 +16982,7 @@ module_state::write_macro_maps (elf_out *to, range_t &info, unsigned *crc_p) } sec.u (count); dump (dumper::LOCATION) - && dump ("Macro:%u %I %u/%u*2 locations [%u,%u)->%u", + && dump ("Macro:%K %I %u/%u*2 locations [%K,%K)->%K", macro_num, identifier (mac->macro), runs, mac->n_tokens, MAP_START_LOCATION (mac), @@ -16994,12 +17023,13 @@ module_state::read_ordinary_maps (unsigned num_ord_locs, unsigned range_bits) filenames.quick_push (fname); } - unsigned num_ordinary = sec.u (); - dump () && dump ("Ordinary maps:%u, range_bits:%u", num_ordinary, range_bits); + line_map_uint_t num_ordinary = sec.loc (); + dump () && dump ("Ordinary maps:%K, range_bits:%u", + num_ordinary, range_bits); location_t offset = line_table->highest_location + 1; - offset += ((1u << range_bits) - 1); - offset &= ~((1u << range_bits) - 1); + offset += ((loc_one << range_bits) - 1); + offset &= ~((loc_one << range_bits) - 1); ordinary_locs.first = offset; bool propagated = spans.maybe_propagate (this, offset); @@ -17007,11 +17037,11 @@ module_state::read_ordinary_maps (unsigned num_ord_locs, unsigned range_bits) (line_map_new_raw (line_table, false, num_ordinary)); const line_map_ordinary *base = nullptr; - for (unsigned ix = 0; ix != num_ordinary && !sec.get_overrun (); ix++) + for (line_map_uint_t ix = 0; ix != num_ordinary && !sec.get_overrun (); ix++) { line_map_ordinary *map = &maps[ix]; - unsigned offset = sec.u (); + location_t offset = sec.loc (); if (!offset) { map->reason = LC_RENAME; @@ -17028,7 +17058,7 @@ module_state::read_ordinary_maps (unsigned num_ord_locs, unsigned range_bits) *map = *base; map->to_line += offset >> map->m_column_and_range_bits; } - unsigned remap = sec.u (); + location_t remap = sec.loc (); map->start_location = remap + ordinary_locs.first; if (base == map) { @@ -17048,7 +17078,7 @@ module_state::read_ordinary_maps (unsigned num_ord_locs, unsigned range_bits) /* We shouldn't run out of locations, as we checked before starting. */ sec.set_overrun (); - dump () && dump ("Ordinary location [%u,+%u)", + dump () && dump ("Ordinary location [%K,+%K)", ordinary_locs.first, ordinary_locs.second); if (propagated) @@ -17064,7 +17094,7 @@ module_state::read_ordinary_maps (unsigned num_ord_locs, unsigned range_bits) } bool -module_state::read_macro_maps (unsigned num_macro_locs) +module_state::read_macro_maps (line_map_uint_t num_macro_locs) { bytes_in sec; @@ -17073,8 +17103,9 @@ module_state::read_macro_maps (unsigned num_macro_locs) dump () && dump ("Reading macro location maps"); dump.indent (); - unsigned num_macros = sec.u (); - dump () && dump ("Macro maps:%u locs:%u", num_macros, num_macro_locs); + line_map_uint_t num_macros = sec.loc (); + dump () && dump ("Macro maps:%K locs:%K", + num_macros, num_macro_locs); bool propagated = spans.maybe_propagate (this, line_table->highest_location + 1); @@ -17083,13 +17114,13 @@ module_state::read_macro_maps (unsigned num_macro_locs) macro_locs.second = num_macro_locs; macro_locs.first = offset - num_macro_locs; - dump () && dump ("Macro loc delta %d", offset); - dump () && dump ("Macro locations [%u,%u)", + dump () && dump ("Macro loc delta %K", offset); + dump () && dump ("Macro locations [%K,%K)", macro_locs.first, macro_locs.second); - for (unsigned ix = 0; ix != num_macros && !sec.get_overrun (); ix++) + for (line_map_uint_t ix = 0; ix != num_macros && !sec.get_overrun (); ix++) { - unsigned offset = sec.u (); + location_t offset = sec.loc (); unsigned n_tokens = sec.u (); cpp_hashnode *node = sec.cpp_node (); location_t exp_loc = read_location (sec); @@ -17120,13 +17151,13 @@ module_state::read_macro_maps (unsigned num_macro_locs) if (count) sec.set_overrun (); dump (dumper::LOCATION) - && dump ("Macro:%u %I %u/%u*2 locations [%u,%u)", + && dump ("Macro:%K %I %u/%u*2 locations [%K,%K)", ix, identifier (node), runs, n_tokens, MAP_START_LOCATION (macro), MAP_START_LOCATION (macro) + n_tokens); } - dump () && dump ("Macro location lwm:%u", macro_locs.first); + dump () && dump ("Macro location lwm:%K", macro_locs.first); if (propagated) spans.close (); @@ -18167,8 +18198,8 @@ module_state::write_config (elf_out *to, module_state_config &config, cfg.u (config.num_partitions); cfg.u (config.num_entities); - cfg.u (config.ordinary_locs); - cfg.u (config.macro_locs); + cfg.loc (config.ordinary_locs); + cfg.loc (config.macro_locs); cfg.u (config.loc_range_bits); cfg.u (config.active_init); @@ -18354,8 +18385,8 @@ module_state::read_config (module_state_config &config) config.num_partitions = cfg.u (); config.num_entities = cfg.u (); - config.ordinary_locs = cfg.u (); - config.macro_locs = cfg.u (); + config.ordinary_locs = cfg.loc (); + config.macro_locs = cfg.loc (); config.loc_range_bits = cfg.u (); config.active_init = cfg.u (); @@ -20460,7 +20491,7 @@ preprocess_module (module_state *module, location_t from_loc, name_pending_imports (reader); /* Preserve the state of the line-map. */ - unsigned pre_hwm = LINEMAPS_ORDINARY_USED (line_table); + auto pre_hwm = LINEMAPS_ORDINARY_USED (line_table); /* We only need to close the span, if we're going to emit a CMI. But that's a little tricky -- our token scanner From patchwork Sun Nov 3 22:22:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YOclAsr9; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhTkC0K1Dz1xwV for ; Mon, 4 Nov 2024 09:27:31 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3DB8C3858D38 for ; Sun, 3 Nov 2024 22:27:29 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by sourceware.org (Postfix) with ESMTPS id 741023858435 for ; Sun, 3 Nov 2024 22:22:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 741023858435 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 741023858435 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672592; cv=none; b=aH+oyJi4P7Ex05mU8xG/lWOdT17LdSALqiDca014bf46SXHOdsKwb2c6V6aAEhof5iU1bvtoOvbLHO5KpXbDtRuqG9yFhsMY/IMWpabJbQboEwO896qJD3qTcC0MSouNoJCwjDgziHmorejfBhgvjbEj42/7322ojzECQca8sXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672592; c=relaxed/simple; bh=8IYQolmJvZO5UdB8yPWqdWhd7+K5iMK8O0ogActjUHA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=FEM48Pk48q/XTQ1skcvLiyJpt33UuZqiaafnTP0YXBF6fW2KldMO23hXBP2OXV5DbOE/9QzipMx8ttjGA8R/9E51KU2a/l3d7XJIy8cz5xnMOy0MYE/gGt1mZ9PMAsW6iE2fs1III8gXR3OiMZFGlKJPA94cC6KYenHIHlKMFjk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf2d.google.com with SMTP id 6a1803df08f44-6cbd57cc35bso39837586d6.1 for ; Sun, 03 Nov 2024 14:22:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672577; x=1731277377; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o0Qf7IJ7n9W8vZNw4mYL8cpmHcrTpoJfqVtNKepctCY=; b=YOclAsr9AYnigSMMK8zC+McTvB1JWxoh3Mp1U9lHgt91sZHRSM0NCONbxQUvMRzhIV eOtUZyKe6NNDgmHrThn9DLPKlFh2EWTblT2E5RdTGYIGnKUmJXQJn357uE3VmmBz7NmF sD+lhyU5rwV+Bz7T125pvLMVfaIonRNLcZXqL2BBtVJLHl38OsNXAdClCAckNvRZ/WAn 5XHnz21EQkV88rs54Zw7l352zunO6+NOcXcBmYJ5S4D+hFBQO74pc56ss8jwGic/SA56 oe4PI+lKfBnIZM5Br1vEkA/S2NG1fb46L7lzVWopo9Gha+rKAoY37b2e5lWo0kHmZDMR MAJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672577; x=1731277377; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o0Qf7IJ7n9W8vZNw4mYL8cpmHcrTpoJfqVtNKepctCY=; b=MPm0FMeNkLn0hgAyGAZtKWxLjnsSABexjrMf+CrN3EF+4o5E81Ro1udBVbFOt30m0D z1JPSpGZn4RY5T5SFsLoSiUnzUDwPZ76O7r0JFgmTu11ib0w9cmzSXCYQUXuExdoh+ZN cD+o6TIFlqTEg1Y91KErZjnHJFvwPEhgwe+uJQEvwioxSJCfEtc9//rn1rxuco1HQHlW 6PQlWteyLj17OcOrngnza3cx4Ll9cutiWHzsegUEO7PEzreAm9QR/2Rcy/+J8ylnIBzL KpDfZMHl1ZHjImtd117OKPAVTt8Wm/F0YivW7nNLQY2TkyvIJ7rxuV1v5pQ8an7yU8UQ pI2A== X-Gm-Message-State: AOJu0YxvqOUA67/wQH1XCybwWvYTHzaaKAtVBKwir3HB/tbgp6PeOMJK SxdigmOdoUpOzYOgk8sx0VDcXsidv0mDN7j7QmF4fESlvwzJF3WywpREMQ== X-Google-Smtp-Source: AGHT+IGJqLK8Y4dtflly7Uv/1IHTsIBl6sB1ia4R+PgNVIKkMxFDJDZAHBVkr7bzHUKNyvQHlEnBcg== X-Received: by 2002:a05:6214:4984:b0:6cb:81ba:8ac1 with SMTP id 6a1803df08f44-6d353feda01mr238560736d6.0.1730672576526; Sun, 03 Nov 2024 14:22:56 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:55 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 11/15] Support for 64-bit location_t: RTL parts Date: Sun, 3 Nov 2024 17:22:16 -0500 Message-Id: <20241103222220.933471-12-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Some RTL objects need to store a location_t. Currently, they store it in the rt_int field of union rtunion, but in a world where location_t could be 64-bit, they need to store it in a larger variable. Unfortunately, rtunion does not currently have a 64-bit int type for that purpose, so add one. In order to avoid increasing any overhead when 64-bit locations are not in use, the new field is dedicated for location_t storage only and has type "location_t" so it will only be 64-bit if necessary. This necessitates adding a new RTX format code 'L' for locations. There are very many switch statements in the codebase that inspect the RTX format code. I took the approach of finding all of them that handle code 'i' or 'n' and making sure they handle 'L' too. I am sure that some of these call sites can never see an 'L' code, but I thought it would be safer and more future-proof to handle as many as possible, given it's just a line or two to add in most cases. While testing this with --enable-checking=rtl, I came across one place in final.cc that seems to be a (currently) harmless misuse of RTL: set_cur_block_to_this_block: if (! this_block) { if (INSN_LOCATION (insn) == UNKNOWN_LOCATION) continue; else this_block = DECL_INITIAL (cfun->decl); } In this part of reemit_insn_block_notes(), the insn variable could actually be a NOTE and not an INSN. In that case, INSN_LOCATION() shouldn't be called on it. It works fine currently because the field is properly accessed by XINT() either way. (For an INSN, it is a location, but for a NOTE, it is the note type enum). Currently, if insn is a NOTE, the comparison must always be false because the note type is not equal to 0==UNKNOWN_LOCATION. Once locations and ints are differentiated, this line leads to a checking failure, which I resolved by checking for the NOTE_P case before calling INSN_LOCATION. gcc/ChangeLog: * rtl.def (DEBUG_INSN): Use new format code 'L' for location_t fields. (INSN): Likewise. (JUMP_INSN): Likewise. (CALL_INSN): Likewise. (ASM_INPUT): Likewise. (ASM_OPERANDS): Likewise. * rtl.h (union rtunion): Add new location_t RT_LOC member for use by the 'L' format. (struct rtx_debug_insn): Adjust comment. (struct rtx_nonjump_insn): Adjust comment. (struct rtx_call_insn): Adjust comment. (XLOC): New accessor macro for rtunion::rt_loc. (X0LOC): Likewise. (XCLOC): Likewise. (INSN_LOCATION): Use XLOC instead of XUINT to retrieve a location_t. (NOTE_MARKER_LOCATION): Likewise for XCUINT -> XCLOC. (ASM_OPERANDS_SOURCE_LOCATION): Likewise. (ASM_INPUT_SOURCE_LOCATION):Likewise. (gen_rtx_ASM_INPUT): Adjust to use sL format instead of si. (gen_rtx_INSN): Adjust prototype to use location_r rather than int for the location. * cfgrtl.cc (force_nonfallthru_and_redirect): Change type of LOC local variable from int to location_t. * rtlhash.cc (add_rtx): Support 'L' format in the switch statement. * var-tracking.cc (loc_cmp): Likewise. * alias.cc (rtx_equal_for_memref_p): Likewise. * config/alpha/alpha.cc (summarize_insn): Likewise. * config/ia64/ia64.cc (rtx_needs_barrier): Likewise. * config/rs6000/rs6000.cc (rs6000_hash_constant): Likewise. * cse.cc (hash_rtx): Likewise. (exp_equiv_p): Likewise. * cselib.cc (rtx_equal_for_cselib_1): Likewise. (cselib_hash_rtx): Likewise. (cselib_expand_value_rtx_1): Likewise. * emit-rtl.cc (copy_insn_1): Likewise. (gen_rtx_INSN): Change the location argument from int to location_t, and call the corresponding gen_rtf_fmt_* function. * final.cc (reemit_insn_block_notes): Don't call INSN_LOCATION if NOTE_P; the field being accessed is not a location in this case. (leaf_renumber_regs_insn): Support 'L' format in the switch statement. * genattrtab.cc (attr_rtx_1): Likewise. * genemit.cc (gen_exp): Likewise. * gengenrtl.cc (type_from_format): Likewise. (accessor_from_format): Likewise. * gengtype.cc (adjust_field_rtx_def): Likewise. * genpeep.cc (match_rtx): Likewise; just mark gcc_unreachable() for now. * genrecog.cc (find_operand): Support 'L' format in the switch statement. (find_matching_operand): Likewise. (validate_pattern): Likewise. * gensupport.cc (subst_pattern_match): Likewise. (get_alternatives_number): Likewise. (collect_insn_data): Likewise. (alter_predicate_for_insn): Likewise. (alter_constraints): Likewise. (subst_dup): Likewise. * jump.cc (rtx_renumbered_equal_p): Likewise. * loop-invariant.cc (hash_invariant_expr_1): Likewise. * lra-constraints.cc (operands_match_p): Likewise. * lra.cc (lra_rtx_hash): Likewise. * print-rtl.cc (rtx_writer::print_rtx_operand_code_i): Refactor location_t-relevant code to... (rtx_writer::print_rtx_operand_code_L): ...new function here. (rtx_writer::print_rtx_operand): Support 'L' format in the switch statement. * print-rtl.h (rtx_writer::print_rtx_operand_code_L): Add prototype for new function. * read-rtl-function.cc (function_reader::read_rtx_operand): Support 'L' format in the switch statement. (function_reader::read_rtx_operand_i_or_n): Rename to... (function_reader::read_rtx_operand_inL): ...this, and support 'L' as well. * read-rtl.cc (apply_int_iterator): Support 'L' format in the switch statement. (rtx_reader::read_rtx_operand): Likewise. * reload.cc (operands_match_p): Likewise. * rtl.cc (rtx_format): Add new code 'L'. (rtx_equal_p): Support 'L' in the switch statement. Remove dead code in the handling for 'i' and 'n'. --- gcc/alias.cc | 5 +++++ gcc/cfgrtl.cc | 3 +-- gcc/config/alpha/alpha.cc | 1 + gcc/config/ia64/ia64.cc | 1 + gcc/config/rs6000/rs6000.cc | 25 +++++++++++++++---------- gcc/cse.cc | 9 +++++++++ gcc/cselib.cc | 10 ++++++++++ gcc/emit-rtl.cc | 5 +++-- gcc/final.cc | 3 ++- gcc/genattrtab.cc | 4 ++++ gcc/genemit.cc | 4 ++++ gcc/gengenrtl.cc | 6 ++++++ gcc/gengtype.cc | 5 +++++ gcc/genpeep.cc | 2 ++ gcc/genrecog.cc | 6 +++--- gcc/gensupport.cc | 9 ++++++--- gcc/jump.cc | 5 +++++ gcc/loop-invariant.cc | 2 ++ gcc/lra-constraints.cc | 5 +++++ gcc/lra.cc | 4 ++++ gcc/print-rtl.cc | 19 ++++++++++++++++--- gcc/print-rtl.h | 1 + gcc/read-rtl-function.cc | 13 ++++++++----- gcc/read-rtl.cc | 4 ++++ gcc/reload.cc | 5 +++++ gcc/rtl.cc | 18 +++++++++--------- gcc/rtl.def | 12 ++++++------ gcc/rtl.h | 32 ++++++++++++++++++-------------- gcc/rtlhash.cc | 3 +++ gcc/var-tracking.cc | 8 ++++++++ 30 files changed, 171 insertions(+), 58 deletions(-) diff --git a/gcc/alias.cc b/gcc/alias.cc index 7c1c07d0284..a354c14cdbf 100644 --- a/gcc/alias.cc +++ b/gcc/alias.cc @@ -1861,6 +1861,11 @@ rtx_equal_for_memref_p (const_rtx x, const_rtx y) return false; break; + case 'L': + if (XLOC (x, i) != XLOC (y, i)) + return false; + break; + case 'p': if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y))) return false; diff --git a/gcc/cfgrtl.cc b/gcc/cfgrtl.cc index d9c851f72ff..516316c7ad1 100644 --- a/gcc/cfgrtl.cc +++ b/gcc/cfgrtl.cc @@ -1512,7 +1512,6 @@ force_nonfallthru_and_redirect (edge e, basic_block target, rtx jump_label) edge new_edge; int abnormal_edge_flags = 0; bool asm_goto_edge = false; - int loc; /* In the case the last instruction is conditional jump to the next instruction, first redirect the jump itself and then continue @@ -1697,7 +1696,7 @@ force_nonfallthru_and_redirect (edge e, basic_block target, rtx jump_label) else jump_block = e->src; - loc = e->goto_locus; + const location_t loc = e->goto_locus; e->flags &= ~EDGE_FALLTHRU; if (target == EXIT_BLOCK_PTR_FOR_FN (cfun)) { diff --git a/gcc/config/alpha/alpha.cc b/gcc/config/alpha/alpha.cc index d7f5e3b8751..f196524dfa1 100644 --- a/gcc/config/alpha/alpha.cc +++ b/gcc/config/alpha/alpha.cc @@ -8642,6 +8642,7 @@ summarize_insn (rtx x, struct shadow_summary *sum, int set) break; case 'i': + case 'L': break; default: diff --git a/gcc/config/ia64/ia64.cc b/gcc/config/ia64/ia64.cc index 4acbd82bc65..daec32bb49f 100644 --- a/gcc/config/ia64/ia64.cc +++ b/gcc/config/ia64/ia64.cc @@ -6902,6 +6902,7 @@ rtx_needs_barrier (rtx x, struct reg_flags flags, int pred) case '0': /* unused field */ case 'i': /* integer */ case 'n': /* note */ + case 'L': /* location_t */ case 'w': /* wide integer */ case 's': /* pointer to string */ case 'S': /* optional pointer to string */ diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 950fd947fda..2d7a6aa3c9c 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -17425,16 +17425,21 @@ rs6000_hash_constant (rtx k) result = result * 613 + (unsigned) XINT (k, fidx); break; case 'w': - if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT)) - result = result * 613 + (unsigned) XWINT (k, fidx); - else - { - size_t i; - for (i = 0; i < sizeof (HOST_WIDE_INT) / sizeof (unsigned); i++) - result = result * 613 + (unsigned) (XWINT (k, fidx) - >> CHAR_BIT * i); - } - break; + case 'L': + { + const HOST_WIDE_INT val + = (format[fidx] == 'L' ? XLOC (k, fidx) : XWINT (k, fidx)); + if (sizeof (unsigned) >= sizeof (HOST_WIDE_INT)) + result = result * 613 + (unsigned) val; + else + { + size_t i; + for (i = 0; i < sizeof (HOST_WIDE_INT) / sizeof (unsigned); i++) + result = result * 613 + (unsigned) (val + >> CHAR_BIT * i); + } + break; + } case '0': break; default: diff --git a/gcc/cse.cc b/gcc/cse.cc index 6a5fe236bb0..c60a4bca3e3 100644 --- a/gcc/cse.cc +++ b/gcc/cse.cc @@ -2534,6 +2534,10 @@ hash_rtx (const_rtx x, machine_mode mode, hash += (unsigned int) XINT (x, i); break; + case 'L': + hash += (unsigned int) XLOC (x, i); + break; + case 'p': hash += constant_lower_bound (SUBREG_BYTE (x)); break; @@ -2766,6 +2770,11 @@ exp_equiv_p (const_rtx x, const_rtx y, int validate, bool for_gcse) return false; break; + case 'L': + if (XLOC (x, i) != XLOC (y, i)) + return false; + break; + case 'w': if (XWINT (x, i) != XWINT (y, i)) return false; diff --git a/gcc/cselib.cc b/gcc/cselib.cc index e6a36e892bb..947782b6f6b 100644 --- a/gcc/cselib.cc +++ b/gcc/cselib.cc @@ -1122,6 +1122,11 @@ rtx_equal_for_cselib_1 (rtx x, rtx y, machine_mode memmode, int depth) return false; break; + case 'L': + if (XLOC (x, i) != XLOC (y, i)) + return false; + break; + case 'p': if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y))) return false; @@ -1565,6 +1570,10 @@ cselib_hash_rtx (rtx x, int create, machine_mode memmode) hash.add_hwi (XINT (x, i)); break; + case 'L': + hash.add_hwi (XLOC (x, i)); + break; + case 'p': hash.add_int (constant_lower_bound (SUBREG_BYTE (x))); break; @@ -2079,6 +2088,7 @@ cselib_expand_value_rtx_1 (rtx orig, struct expand_value_data *evd, case 't': case 'w': case 'i': + case 'L': case 's': case 'S': case 'T': diff --git a/gcc/emit-rtl.cc b/gcc/emit-rtl.cc index 9ad0c56f96f..a556692e8a0 100644 --- a/gcc/emit-rtl.cc +++ b/gcc/emit-rtl.cc @@ -511,10 +511,10 @@ gen_rtx_INSN_LIST (machine_mode mode, rtx insn, rtx insn_list) rtx_insn * gen_rtx_INSN (machine_mode mode, rtx_insn *prev_insn, rtx_insn *next_insn, - basic_block bb, rtx pattern, int location, int code, + basic_block bb, rtx pattern, location_t location, int code, rtx reg_notes) { - return as_a (gen_rtx_fmt_uuBeiie (INSN, mode, + return as_a (gen_rtx_fmt_uuBeLie (INSN, mode, prev_insn, next_insn, bb, pattern, location, code, reg_notes)); @@ -5892,6 +5892,7 @@ copy_insn_1 (rtx orig) case 't': case 'w': case 'i': + case 'L': case 'p': case 's': case 'S': diff --git a/gcc/final.cc b/gcc/final.cc index 11141f2b56c..a721622904c 100644 --- a/gcc/final.cc +++ b/gcc/final.cc @@ -1542,7 +1542,7 @@ reemit_insn_block_notes (void) set_cur_block_to_this_block: if (! this_block) { - if (INSN_LOCATION (insn) == UNKNOWN_LOCATION) + if (!NOTE_P (insn) && INSN_LOCATION (insn) == UNKNOWN_LOCATION) continue; else this_block = DECL_INITIAL (cfun->decl); @@ -4211,6 +4211,7 @@ leaf_renumber_regs_insn (rtx in_rtx) case 's': case '0': case 'i': + case 'L': case 'w': case 'p': case 'n': diff --git a/gcc/genattrtab.cc b/gcc/genattrtab.cc index 931e06957f2..d67fae627e2 100644 --- a/gcc/genattrtab.cc +++ b/gcc/genattrtab.cc @@ -551,6 +551,10 @@ attr_rtx_1 (enum rtx_code code, va_list p) XINT (rt_val, i) = va_arg (p, int); break; + case 'L': /* A location_t? */ + XLOC (rt_val, i) = va_arg (p, location_t); + break; + case 'w': /* A wide integer? */ XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT); break; diff --git a/gcc/genemit.cc b/gcc/genemit.cc index 5d3d10f5061..82c39e9b59a 100644 --- a/gcc/genemit.cc +++ b/gcc/genemit.cc @@ -238,6 +238,10 @@ gen_exp (rtx x, enum rtx_code subroutine_type, char *used, md_rtx_info *info, fprintf (file, "%u", XINT (x, i)); break; + case 'L': + fprintf (file, "%llu", (unsigned long long) XLOC (x, i)); + break; + case 'r': fprintf (file, "%u", REGNO (x)); break; diff --git a/gcc/gengenrtl.cc b/gcc/gengenrtl.cc index c9ba471ac20..3da48e7dca9 100644 --- a/gcc/gengenrtl.cc +++ b/gcc/gengenrtl.cc @@ -51,6 +51,9 @@ type_from_format (int c) case 'i': return "int "; + case 'L': + return "location_t "; + case 'w': return "HOST_WIDE_INT "; @@ -84,6 +87,9 @@ accessor_from_format (int c) case 'i': return "XINT"; + case 'L': + return "XLOC"; + case 'w': return "XWINT"; diff --git a/gcc/gengtype.cc b/gcc/gengtype.cc index 29f91e30826..25a955fe538 100644 --- a/gcc/gengtype.cc +++ b/gcc/gengtype.cc @@ -1254,6 +1254,11 @@ adjust_field_rtx_def (type_p t, options_p ARG_UNUSED (opt)) subname = "rt_int"; break; + case 'L': + t = scalar_tp; + subname = "rt_loc"; + break; + case 'p': t = scalar_tp; subname = "rt_subreg"; diff --git a/gcc/genpeep.cc b/gcc/genpeep.cc index 9d9e5eb2e8b..ec459616ddd 100644 --- a/gcc/genpeep.cc +++ b/gcc/genpeep.cc @@ -273,6 +273,8 @@ match_rtx (rtx x, struct link *path, int fail_label) printf (" if (XINT (x, %d) != %d) goto L%d;\n", i, XINT (x, i), fail_label); } + else if (fmt[i] == 'L') + gcc_unreachable (); else if (fmt[i] == 'r') { gcc_assert (i == 0); diff --git a/gcc/genrecog.cc b/gcc/genrecog.cc index ba09ec3b600..719b1d44387 100644 --- a/gcc/genrecog.cc +++ b/gcc/genrecog.cc @@ -388,7 +388,7 @@ find_operand (rtx pattern, int n, rtx stop) return r; break; - case 'r': case 'p': case 'i': case 'w': case '0': case 's': + case 'r': case 'p': case 'i': case 'w': case '0': case 's': case 'L': break; default: @@ -439,7 +439,7 @@ find_matching_operand (rtx pattern, int n) return r; break; - case 'r': case 'p': case 'i': case 'w': case '0': case 's': + case 'r': case 'p': case 'i': case 'w': case '0': case 's': case 'L': break; default: @@ -801,7 +801,7 @@ validate_pattern (rtx pattern, md_rtx_info *info, rtx set, int set_code) validate_pattern (XVECEXP (pattern, i, j), info, NULL_RTX, 0); break; - case 'r': case 'p': case 'i': case 'w': case '0': case 's': + case 'r': case 'p': case 'i': case 'w': case '0': case 's': case 'L': break; default: diff --git a/gcc/gensupport.cc b/gcc/gensupport.cc index 3a02132c876..79e45d46217 100644 --- a/gcc/gensupport.cc +++ b/gcc/gensupport.cc @@ -1496,7 +1496,7 @@ subst_pattern_match (rtx x, rtx pt, file_location loc) switch (fmt[i]) { - case 'r': case 'p': case 'i': case 'w': case 's': + case 'r': case 'p': case 'i': case 'w': case 's': case 'L': continue; case 'e': case 'u': @@ -1662,6 +1662,7 @@ get_alternatives_number (rtx pattern, int *n_alt, file_location loc) case 'r': case 'p': case 'i': case 'w': case '0': case 's': case 'S': case 'T': + case 'L': break; default: @@ -1722,6 +1723,7 @@ collect_insn_data (rtx pattern, int *palt, int *pmax) case 'r': case 'p': case 'i': case 'w': case '0': case 's': case 'S': case 'T': + case 'L': break; default: @@ -1806,7 +1808,7 @@ alter_predicate_for_insn (rtx pattern, int alt, int max_op, } break; - case 'r': case 'p': case 'i': case 'w': case '0': case 's': + case 'r': case 'p': case 'i': case 'w': case '0': case 's': case 'L': break; default: @@ -1867,7 +1869,7 @@ alter_constraints (rtx pattern, int n_dup, constraints_handler_t alter) } break; - case 'r': case 'p': case 'i': case 'w': case '0': case 's': + case 'r': case 'p': case 'i': case 'w': case '0': case 's': case 'L': break; default: @@ -2785,6 +2787,7 @@ subst_dup (rtx pattern, int n_alt, int n_subst_alt) case 'r': case 'p': case 'i': case 'w': case '0': case 's': case 'S': case 'T': + case 'L': break; default: diff --git a/gcc/jump.cc b/gcc/jump.cc index 5b9e9ac4722..643c8a07cba 100644 --- a/gcc/jump.cc +++ b/gcc/jump.cc @@ -1801,6 +1801,11 @@ rtx_renumbered_equal_p (const_rtx x, const_rtx y) case 'i': if (XINT (x, i) != XINT (y, i)) + return false; + break; + + case 'L': + if (XLOC (x, i) != XLOC (y, i)) { if (((code == ASM_OPERANDS && i == 6) || (code == ASM_INPUT && i == 1))) diff --git a/gcc/loop-invariant.cc b/gcc/loop-invariant.cc index 4f2bcd158b0..f4347a6f973 100644 --- a/gcc/loop-invariant.cc +++ b/gcc/loop-invariant.cc @@ -334,6 +334,8 @@ hash_invariant_expr_1 (rtx_insn *insn, rtx x) } else if (fmt[i] == 'i' || fmt[i] == 'n') val ^= XINT (x, i); + else if (fmt[i] == 'L') + val ^= XLOC (x, i); else if (fmt[i] == 'p') val ^= constant_lower_bound (SUBREG_BYTE (x)); } diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc index 61bbb930b7f..319be74b1c9 100644 --- a/gcc/lra-constraints.cc +++ b/gcc/lra-constraints.cc @@ -898,6 +898,11 @@ operands_match_p (rtx x, rtx y, int y_hard_regno) return false; break; + case 'L': + if (XLOC (x, i) != XLOC (y, i)) + return false; + break; + case 'p': if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y))) return false; diff --git a/gcc/lra.cc b/gcc/lra.cc index bc46f56cf20..a84e321519d 100644 --- a/gcc/lra.cc +++ b/gcc/lra.cc @@ -1749,6 +1749,10 @@ lra_rtx_hash (rtx x) val += XINT (x, i); break; + case 'L': + val += XLOC (x, i); + break; + case 'V': case 'E': val += XVECLEN (x, i); diff --git a/gcc/print-rtl.cc b/gcc/print-rtl.cc index 1688d4ec5c8..7ff737e98ed 100644 --- a/gcc/print-rtl.cc +++ b/gcc/print-rtl.cc @@ -436,10 +436,10 @@ rtx_writer::print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx) m_indent -= 2; } -/* Subroutine of print_rtx_operand for handling code 'i'. */ +/* Subroutine of print_rtx_operand for handling code 'L'. */ void -rtx_writer::print_rtx_operand_code_i (const_rtx in_rtx, int idx) +rtx_writer::print_rtx_operand_code_L (const_rtx in_rtx, int idx) { if (idx == 4 && INSN_P (in_rtx)) { @@ -479,7 +479,16 @@ rtx_writer::print_rtx_operand_code_i (const_rtx in_rtx, int idx) LOCATION_LINE (ASM_INPUT_SOURCE_LOCATION (in_rtx))); #endif } - else if (idx == 5 && NOTE_P (in_rtx)) + else + gcc_unreachable (); +} + +/* Subroutine of print_rtx_operand for handling code 'i'. */ + +void +rtx_writer::print_rtx_operand_code_i (const_rtx in_rtx, int idx) +{ + if (idx == 5 && NOTE_P (in_rtx)) { /* This field is only used for NOTE_INSN_DELETED_LABEL, and other times often contains garbage from INSN->NOTE death. */ @@ -697,6 +706,10 @@ rtx_writer::print_rtx_operand (const_rtx in_rtx, int idx) print_rtx_operand_code_i (in_rtx, idx); break; + case 'L': + print_rtx_operand_code_L (in_rtx, idx); + break; + case 'p': fprintf (m_outfile, " "); print_poly_int (m_outfile, SUBREG_BYTE (in_rtx)); diff --git a/gcc/print-rtl.h b/gcc/print-rtl.h index 820f8a5c2bc..f56a452706c 100644 --- a/gcc/print-rtl.h +++ b/gcc/print-rtl.h @@ -45,6 +45,7 @@ class rtx_writer void print_rtx_operand_code_e (const_rtx in_rtx, int idx); void print_rtx_operand_codes_E_and_V (const_rtx in_rtx, int idx); void print_rtx_operand_code_i (const_rtx in_rtx, int idx); + void print_rtx_operand_code_L (const_rtx in_rtx, int idx); void print_rtx_operand_code_r (const_rtx in_rtx); void print_rtx_operand_code_u (const_rtx in_rtx, int idx); void print_rtx_operand (const_rtx in_rtx, int idx); diff --git a/gcc/read-rtl-function.cc b/gcc/read-rtl-function.cc index 51dc11928d0..855fb540b11 100644 --- a/gcc/read-rtl-function.cc +++ b/gcc/read-rtl-function.cc @@ -105,7 +105,7 @@ class function_reader : public rtx_reader int parse_enum_value (int num_values, const char *const *strings); void read_rtx_operand_u (rtx x, int idx); - void read_rtx_operand_i_or_n (rtx x, int idx, char format_char); + void read_rtx_operand_inL (rtx x, int idx, char format_char); rtx read_rtx_operand_r (rtx x); rtx extra_parsing_for_operand_code_0 (rtx x, int idx); @@ -903,7 +903,8 @@ function_reader::read_rtx_operand (rtx x, int idx) case 'i': case 'n': - read_rtx_operand_i_or_n (x, idx, format_char); + case 'L': + read_rtx_operand_inL (x, idx, format_char); /* Don't run regular parser for these codes. */ return x; @@ -992,8 +993,7 @@ function_reader::parse_enum_value (int num_values, const char *const *strings) Special-cased handling of these, for reading function dumps. */ void -function_reader::read_rtx_operand_i_or_n (rtx x, int idx, - char format_char) +function_reader::read_rtx_operand_inL (rtx x, int idx, char format_char) { /* Handle some of the extra information that print_rtx can write out for these cases. */ @@ -1046,7 +1046,10 @@ function_reader::read_rtx_operand_i_or_n (rtx x, int idx, if (format_char == 'n') value = parse_note_insn_name (name.string); else - value = atoi (name.string); + { + gcc_checking_assert (format_char == 'i'); + value = atoi (name.string); + } XINT (x, idx) = value; } diff --git a/gcc/read-rtl.cc b/gcc/read-rtl.cc index bfce806f9d6..e6e5c9ecb7e 100644 --- a/gcc/read-rtl.cc +++ b/gcc/read-rtl.cc @@ -327,6 +327,9 @@ apply_int_iterator (rtx x, unsigned int index, HOST_WIDE_INT value) case 'n': XINT (x, index) = value; break; + case 'L': + XLOC (x, index) = value; + break; case 'w': XWINT (x, index) = value; break; @@ -2048,6 +2051,7 @@ rtx_reader::read_rtx_operand (rtx return_rtx, int idx) case 'n': case 'w': case 'p': + case 'L': { /* Can be an iterator or an integer constant. */ file_location loc = read_name (&name); diff --git a/gcc/reload.cc b/gcc/reload.cc index 27ca8a57f3c..5707b7fce59 100644 --- a/gcc/reload.cc +++ b/gcc/reload.cc @@ -2332,6 +2332,11 @@ operands_match_p (rtx x, rtx y) return 0; break; + case 'L': + if (XLOC (x, i) != XLOC (y, i)) + return 0; + break; + case 'p': if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y))) return 0; diff --git a/gcc/rtl.cc b/gcc/rtl.cc index dc2c8e02755..cda7a44319c 100644 --- a/gcc/rtl.cc +++ b/gcc/rtl.cc @@ -70,6 +70,8 @@ const char * const rtx_format[NUM_RTX_CODE] = { "i" an integer prints the integer "n" like "i", but prints entries from `note_insn_name' + "L" like "i", but correctly sized to hold a location_t, + which may be configured as 32- or 64-bit. "w" an integer of width HOST_BITS_PER_WIDE_INT prints the integer "s" a pointer to a string @@ -355,6 +357,7 @@ copy_rtx (rtx orig) case 't': case 'w': case 'i': + case 'L': case 'p': case 's': case 'S': @@ -506,15 +509,12 @@ rtx_equal_p (const_rtx x, const_rtx y, rtx_equal_p_callback_function cb) case 'n': case 'i': if (XINT (x, i) != XINT (y, i)) - { -#ifndef GENERATOR_FILE - if (((code == ASM_OPERANDS && i == 6) - || (code == ASM_INPUT && i == 1)) - && XINT (x, i) == XINT (y, i)) - break; -#endif - return false; - } + return false; + break; + + case 'L': + if (XLOC (x, i) != XLOC (y, i)) + return false; break; case 'p': diff --git a/gcc/rtl.def b/gcc/rtl.def index 6eec284d281..5c0af957942 100644 --- a/gcc/rtl.def +++ b/gcc/rtl.def @@ -139,21 +139,21 @@ DEF_RTL_EXPR(ADDRESS, "address", "i", RTX_EXTRA) ---------------------------------------------------------------------- */ /* An annotation for variable assignment tracking. */ -DEF_RTL_EXPR(DEBUG_INSN, "debug_insn", "uuBeiie", RTX_INSN) +DEF_RTL_EXPR(DEBUG_INSN, "debug_insn", "uuBeLie", RTX_INSN) /* An instruction that cannot jump. */ -DEF_RTL_EXPR(INSN, "insn", "uuBeiie", RTX_INSN) +DEF_RTL_EXPR(INSN, "insn", "uuBeLie", RTX_INSN) /* An instruction that can possibly jump. Fields ( rtx->u.fld[] ) have exact same meaning as INSN's. */ -DEF_RTL_EXPR(JUMP_INSN, "jump_insn", "uuBeiie0", RTX_INSN) +DEF_RTL_EXPR(JUMP_INSN, "jump_insn", "uuBeLie0", RTX_INSN) /* An instruction that can possibly call a subroutine but which will not change which instruction comes next in the current function. Field ( rtx->u.fld[8] ) is CALL_INSN_FUNCTION_USAGE. All other fields ( rtx->u.fld[] ) have exact same meaning as INSN's. */ -DEF_RTL_EXPR(CALL_INSN, "call_insn", "uuBeiiee", RTX_INSN) +DEF_RTL_EXPR(CALL_INSN, "call_insn", "uuBeLiee", RTX_INSN) /* Placeholder for tablejump JUMP_INSNs. The pattern of this kind of rtx is always either an ADDR_VEC or an ADDR_DIFF_VEC. These @@ -202,7 +202,7 @@ DEF_RTL_EXPR(PARALLEL, "parallel", "E", RTX_EXTRA) These occur in an insn all by themselves as the PATTERN. They also appear inside an ASM_OPERANDS as a convenient way to hold a string. */ -DEF_RTL_EXPR(ASM_INPUT, "asm_input", "si", RTX_EXTRA) +DEF_RTL_EXPR(ASM_INPUT, "asm_input", "sL", RTX_EXTRA) /* An assembler instruction with operands. 1st operand is the instruction template. @@ -216,7 +216,7 @@ DEF_RTL_EXPR(ASM_INPUT, "asm_input", "si", RTX_EXTRA) and whose mode indicates the mode of the input operand. 6th is a vector of labels that may be branched to by the asm. 7th is the source line number. */ -DEF_RTL_EXPR(ASM_OPERANDS, "asm_operands", "ssiEEEi", RTX_EXTRA) +DEF_RTL_EXPR(ASM_OPERANDS, "asm_operands", "ssiEEEL", RTX_EXTRA) /* A machine-specific operation. 1st operand is a vector of operands being used by the operation so that diff --git a/gcc/rtl.h b/gcc/rtl.h index f298096a5a6..0369e550573 100644 --- a/gcc/rtl.h +++ b/gcc/rtl.h @@ -204,6 +204,7 @@ union rtunion { int rt_int; unsigned int rt_uint; + location_t rt_loc; poly_uint16 rt_subreg; const char *rt_str; rtx rt_rtx; @@ -584,7 +585,7 @@ struct GTY(()) rtx_debug_insn : public rtx_insn i.e. an annotation for tracking variable assignments. This is an instance of: - DEF_RTL_EXPR(DEBUG_INSN, "debug_insn", "uuBeiie", RTX_INSN) + DEF_RTL_EXPR(DEBUG_INSN, "debug_insn", "uuBeLie", RTX_INSN) from rtl.def. */ }; @@ -595,7 +596,7 @@ struct GTY(()) rtx_nonjump_insn : public rtx_insn i.e an instruction that cannot jump. This is an instance of: - DEF_RTL_EXPR(INSN, "insn", "uuBeiie", RTX_INSN) + DEF_RTL_EXPR(INSN, "insn", "uuBeLie", RTX_INSN) from rtl.def. */ }; @@ -607,7 +608,7 @@ public: i.e. an instruction that can possibly jump. This is an instance of: - DEF_RTL_EXPR(JUMP_INSN, "jump_insn", "uuBeiie0", RTX_INSN) + DEF_RTL_EXPR(JUMP_INSN, "jump_insn", "uuBeLie0", RTX_INSN) from rtl.def. */ /* Returns jump target of this instruction. The returned value is not @@ -635,7 +636,7 @@ struct GTY(()) rtx_call_insn : public rtx_insn in the current function. This is an instance of: - DEF_RTL_EXPR(CALL_INSN, "call_insn", "uuBeiiee", RTX_INSN) + DEF_RTL_EXPR(CALL_INSN, "call_insn", "uuBeLiee", RTX_INSN) from rtl.def. */ }; @@ -1347,6 +1348,7 @@ extern void rtl_check_failed_flag (const char *, const_rtx, const char *, #define XINT(RTX, N) (RTL_CHECK2 (RTX, N, 'i', 'n').rt_int) #define XUINT(RTX, N) (RTL_CHECK2 (RTX, N, 'i', 'n').rt_uint) +#define XLOC(RTX, N) (RTL_CHECK1 (RTX, N, 'L').rt_loc) #define XSTR(RTX, N) (RTL_CHECK2 (RTX, N, 's', 'S').rt_str) #define XEXP(RTX, N) (RTL_CHECK2 (RTX, N, 'e', 'u').rt_rtx) #define XVEC(RTX, N) (RTL_CHECK2 (RTX, N, 'E', 'V').rt_rtvec) @@ -1364,6 +1366,7 @@ extern void rtl_check_failed_flag (const char *, const_rtx, const char *, #define X0INT(RTX, N) (RTL_CHECK1 (RTX, N, '0').rt_int) #define X0UINT(RTX, N) (RTL_CHECK1 (RTX, N, '0').rt_uint) +#define X0LOC(RTX, N) (RTL_CHECK1 (RTX, N, '0').rt_loc) #define X0STR(RTX, N) (RTL_CHECK1 (RTX, N, '0').rt_str) #define X0EXP(RTX, N) (RTL_CHECK1 (RTX, N, '0').rt_rtx) #define X0VEC(RTX, N) (RTL_CHECK1 (RTX, N, '0').rt_rtvec) @@ -1380,6 +1383,7 @@ extern void rtl_check_failed_flag (const char *, const_rtx, const char *, #define XCINT(RTX, N, C) (RTL_CHECKC1 (RTX, N, C).rt_int) #define XCUINT(RTX, N, C) (RTL_CHECKC1 (RTX, N, C).rt_uint) +#define XCLOC(RTX, N, C) (RTL_CHECKC1 (RTX, N, C).rt_loc) #define XCSUBREG(RTX, N, C) (RTL_CHECKC1 (RTX, N, C).rt_subreg) #define XCSTR(RTX, N, C) (RTL_CHECKC1 (RTX, N, C).rt_str) #define XCEXP(RTX, N, C) (RTL_CHECKC1 (RTX, N, C).rt_rtx) @@ -1511,14 +1515,14 @@ inline rtx& PATTERN (rtx insn) return XEXP (insn, 3); } -inline unsigned int INSN_LOCATION (const rtx_insn *insn) +inline location_t INSN_LOCATION (const rtx_insn *insn) { - return XUINT (insn, 4); + return XLOC (insn, 4); } -inline unsigned int& INSN_LOCATION (rtx_insn *insn) +inline location_t& INSN_LOCATION (rtx_insn *insn) { - return XUINT (insn, 4); + return XLOC (insn, 4); } inline bool INSN_HAS_LOCATION (const rtx_insn *insn) @@ -1676,7 +1680,7 @@ extern const char * const reg_note_name[]; #define NOTE_EH_HANDLER(INSN) XCINT (INSN, 3, NOTE) #define NOTE_BASIC_BLOCK(INSN) XCBBDEF (INSN, 3, NOTE) #define NOTE_VAR_LOCATION(INSN) XCEXP (INSN, 3, NOTE) -#define NOTE_MARKER_LOCATION(INSN) XCUINT (INSN, 3, NOTE) +#define NOTE_MARKER_LOCATION(INSN) XCLOC (INSN, 3, NOTE) #define NOTE_CFI(INSN) XCCFI (INSN, 3, NOTE) #define NOTE_LABEL_NUMBER(INSN) XCINT (INSN, 3, NOTE) @@ -2610,8 +2614,8 @@ do { \ #define ASM_OPERANDS_LABEL_VEC(RTX) XCVEC (RTX, 5, ASM_OPERANDS) #define ASM_OPERANDS_LABEL_LENGTH(RTX) XCVECLEN (RTX, 5, ASM_OPERANDS) #define ASM_OPERANDS_LABEL(RTX, N) XCVECEXP (RTX, 5, N, ASM_OPERANDS) -#define ASM_OPERANDS_SOURCE_LOCATION(RTX) XCUINT (RTX, 6, ASM_OPERANDS) -#define ASM_INPUT_SOURCE_LOCATION(RTX) XCUINT (RTX, 1, ASM_INPUT) +#define ASM_OPERANDS_SOURCE_LOCATION(RTX) XCLOC (RTX, 6, ASM_OPERANDS) +#define ASM_INPUT_SOURCE_LOCATION(RTX) XCLOC (RTX, 1, ASM_INPUT) /* 1 if RTX is a mem that is statically allocated in read-only memory. */ #define MEM_READONLY_P(RTX) \ @@ -3983,9 +3987,9 @@ get_mem_attrs (const_rtx x) #include "genrtl.h" #undef gen_rtx_ASM_INPUT #define gen_rtx_ASM_INPUT(MODE, ARG0) \ - gen_rtx_fmt_si (ASM_INPUT, (MODE), (ARG0), 0) + gen_rtx_fmt_sL (ASM_INPUT, (MODE), (ARG0), 0) #define gen_rtx_ASM_INPUT_loc(MODE, ARG0, LOC) \ - gen_rtx_fmt_si (ASM_INPUT, (MODE), (ARG0), (LOC)) + gen_rtx_fmt_sL (ASM_INPUT, (MODE), (ARG0), (LOC)) #endif /* There are some RTL codes that require special attention; the @@ -3996,7 +4000,7 @@ extern rtx_expr_list *gen_rtx_EXPR_LIST (machine_mode, rtx, rtx); extern rtx_insn_list *gen_rtx_INSN_LIST (machine_mode, rtx, rtx); extern rtx_insn * gen_rtx_INSN (machine_mode mode, rtx_insn *prev_insn, rtx_insn *next_insn, - basic_block bb, rtx pattern, int location, int code, + basic_block bb, rtx pattern, location_t location, int code, rtx reg_notes); extern rtx gen_rtx_CONST_INT (machine_mode, HOST_WIDE_INT); extern rtx gen_rtx_CONST_VECTOR (machine_mode, rtvec); diff --git a/gcc/rtlhash.cc b/gcc/rtlhash.cc index 7d6910f4486..240e56e5ab3 100644 --- a/gcc/rtlhash.cc +++ b/gcc/rtlhash.cc @@ -87,6 +87,9 @@ add_rtx (const_rtx x, hash &hstate) case 'i': hstate.add_int (XINT (x, i)); break; + case 'L': + hstate.add_hwi (XLOC (x, i)); + break; case 'p': hstate.add_poly_int (SUBREG_BYTE (x)); break; diff --git a/gcc/var-tracking.cc b/gcc/var-tracking.cc index 5f1358c1ac2..f07fe723b62 100644 --- a/gcc/var-tracking.cc +++ b/gcc/var-tracking.cc @@ -3536,6 +3536,14 @@ loc_cmp (rtx x, rtx y) else return 1; + case 'L': + if (XLOC (x, i) == XLOC (y, i)) + break; + else if (XLOC (x, i) < XLOC (y, i)) + return -1; + else + return 1; + case 'p': r = compare_sizes_for_sort (SUBREG_BYTE (x), SUBREG_BYTE (y)); if (r != 0) From patchwork Sun Nov 3 22:22:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=C1n0hADh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhTgN06ZVz1xxN for ; Mon, 4 Nov 2024 09:25:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3081B385AC09 for ; Sun, 3 Nov 2024 22:25:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by sourceware.org (Postfix) with ESMTPS id 71C303858C39 for ; Sun, 3 Nov 2024 22:22:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71C303858C39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 71C303858C39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672592; cv=none; b=E9O8+U0NfF2LdHS2XFqZJQYUKAt224djFWHvIGA0uFo0GiycC7INzuaQlr2kg+8grYUYKpAuQjmW8jH46AVt3nNpwtkFynF4tYqgCxCzDxbfdC+R1klNrvzdzIQia1uXuw+FEuFiplye+YXMttV3e9FoBc/Ab2WKNETy7oZg1R4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672592; c=relaxed/simple; bh=O/m3rli9bxBDc2QHbd6W+wXFHgbAX4/QmJAoLAJvKWo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=GXJWC8IyshIO6bdcJRoUIGyeEDTrJ0lSl8XOPE8no2/hxTr69UVy4gI+dwmwAHMcSGmKpIpe7qyuDnpNKmRIosxjt9SRApZ1e/Lsud6nfh0M+eEu2nRPqSufXNLDtj2R+L6nN8njTutQEBVKK10cO7PU27TggiXAaQEHjo8HuQ4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-6cbcc2bd7fcso25872986d6.1 for ; Sun, 03 Nov 2024 14:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672579; x=1731277379; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pYJyy/13reXidBj7+M0wAVdYimasvXNF/du/f6xRqTQ=; b=C1n0hADhRDz5/z1uG6oOvKD1pRcDS2sD4baJ0RyumDTj0uvRZ3RAcacehXKuYk5Twf h48Co7/JddPaNEk9zE1AnB8hwWClbEHUcm+2BV2QzqQDwxG/PuBqeiglcEiCF3SqJz7S +JU9NjFBO3h1c5H9hgHCiIj0/rx4kUn8WLYxW1+MXb3KQ0Ep/PhXmYP9FWfvDIwx/kpL xDaHTMH/6BlW9DdAzygVDszXx9xh6jd7Ei0Ox0TmojMiYFvUzBpu6ueBW7LXqnWhj6KU D8rqTUQo5rl+L/tMbvIHLtfJN1pO91RLFzvj7NTvWPRUEN5d7copJDis6k35oEk1KcKl 1gaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672579; x=1731277379; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pYJyy/13reXidBj7+M0wAVdYimasvXNF/du/f6xRqTQ=; b=Am0t1MN2UEn+8jKO+/r0dHTWa27nNh+KnQwaJEsyNKvNEOSgjPEosGzBBOiLzooGcJ epED8Lx0vfMltdOPSx7MSvt999ZWwvulDOkvnxVmmWteWyrQ0YLLXBk0CbalbekzFZbA 5Zhbc+m4z3VDUYfDTQTx1TjDlSizHPN6EB/y6/Hnp83qTA8cB/11EHDYXaRePX6xrnGp ZbyczWMlzpH31pQl0xvZLc6k3KQGNGGBHBcHgKxEHy5LroAidn2M6FfzMWYSjTL+fAbL ExpqJ7etSI7ciw/NnEQSmYiYL7dTG6U8OZD+0SD0iZOfqkx0rVyp8ppxILMrpxKqN5sq +uwg== X-Gm-Message-State: AOJu0YyL3w/wnl0ewkgKdP+iudn7hrho85D98v/VZ5cMQkc7tOElpOwR PYU/th3P3UjHZ8SMbZtM+YBwhia7biPDDfEPB0X6xqkwBCXhtvEJZaCEBg== X-Google-Smtp-Source: AGHT+IFskeg9so6ElA3+BD1LvVHoFvWcs890cd8q0/UhpP1l8IOS8KSciA4wVJ1miWuoWCNTax/+rA== X-Received: by 2002:a05:6214:588a:b0:6cb:be8f:a6b1 with SMTP id 6a1803df08f44-6d351ac399amr209690546d6.25.1730672578648; Sun, 03 Nov 2024 14:22:58 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:57 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 12/15] Support for 64-bit location_t: Backend parts Date: Sun, 3 Nov 2024 17:22:17 -0500 Message-Id: <20241103222220.933471-13-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org A few targets have been using "unsigned int" function arguments that need to receive a "location_t". Change to "location_t" to prepare for the possibility that location_t can be configured to be a different type. gcc/ChangeLog: * config/aarch64/aarch64-c.cc (aarch64_resolve_overloaded_builtin): Change "unsigned int" argument to "location_t". * config/avr/avr-c.cc (avr_resolve_overloaded_builtin): Likewise. * config/riscv/riscv-c.cc (riscv_resolve_overloaded_builtin): Likewise. * target.def: Likewise. * doc/tm.texi: Regenerate. --- gcc/config/aarch64/aarch64-c.cc | 3 +-- gcc/config/avr/avr-c.cc | 3 +-- gcc/config/riscv/riscv-c.cc | 3 +-- gcc/doc/tm.texi | 2 +- gcc/target.def | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/gcc/config/aarch64/aarch64-c.cc b/gcc/config/aarch64/aarch64-c.cc index f9b9e379375..fff10337fb3 100644 --- a/gcc/config/aarch64/aarch64-c.cc +++ b/gcc/config/aarch64/aarch64-c.cc @@ -365,11 +365,10 @@ aarch64_pragma_aarch64 (cpp_reader *) /* Implement TARGET_RESOLVE_OVERLOADED_BUILTIN. */ static tree -aarch64_resolve_overloaded_builtin (unsigned int uncast_location, +aarch64_resolve_overloaded_builtin (location_t location, tree fndecl, void *uncast_arglist) { vec empty = {}; - location_t location = (location_t) uncast_location; vec *arglist = (uncast_arglist ? (vec *) uncast_arglist : &empty); diff --git a/gcc/config/avr/avr-c.cc b/gcc/config/avr/avr-c.cc index d3c40d73043..7cf8344c1c7 100644 --- a/gcc/config/avr/avr-c.cc +++ b/gcc/config/avr/avr-c.cc @@ -48,11 +48,10 @@ enum avr_builtin_id /* Implement `TARGET_RESOLVE_OVERLOADED_PLUGIN'. */ static tree -avr_resolve_overloaded_builtin (unsigned int iloc, tree fndecl, void *vargs) +avr_resolve_overloaded_builtin (location_t loc, tree fndecl, void *vargs) { tree type0, type1, fold = NULL_TREE; avr_builtin_id id = AVR_BUILTIN_COUNT; - location_t loc = (location_t) iloc; vec &args = * (vec*) vargs; switch (DECL_MD_FUNCTION_CODE (fndecl)) diff --git a/gcc/config/riscv/riscv-c.cc b/gcc/config/riscv/riscv-c.cc index c59f408d3a8..7f78e2cf019 100644 --- a/gcc/config/riscv/riscv-c.cc +++ b/gcc/config/riscv/riscv-c.cc @@ -312,11 +312,10 @@ riscv_check_builtin_call (location_t loc, vec arg_loc, tree fndecl, /* Implement TARGET_RESOLVE_OVERLOADED_BUILTIN. */ static tree -riscv_resolve_overloaded_builtin (unsigned int uncast_location, tree fndecl, +riscv_resolve_overloaded_builtin (location_t loc, tree fndecl, void *uncast_arglist) { vec empty = {}; - location_t loc = (location_t) uncast_location; vec *arglist = (vec *) uncast_arglist; unsigned int code = DECL_MD_FUNCTION_CODE (fndecl); unsigned int subcode = code >> RISCV_BUILTIN_SHIFT; diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 4deb3d2c283..4b739578f4f 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -12108,7 +12108,7 @@ ignored. This function should return the result of the call to the built-in function. @end deftypefn -@deftypefn {Target Hook} tree TARGET_RESOLVE_OVERLOADED_BUILTIN (unsigned int @var{loc}, tree @var{fndecl}, void *@var{arglist}) +@deftypefn {Target Hook} tree TARGET_RESOLVE_OVERLOADED_BUILTIN (location_t @var{loc}, tree @var{fndecl}, void *@var{arglist}) Select a replacement for a machine specific built-in function that was set up by @samp{TARGET_INIT_BUILTINS}. This is done @emph{before} regular type checking, and so allows the target to diff --git a/gcc/target.def b/gcc/target.def index 523ae7ec9aa..e285cef5743 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -2497,7 +2497,7 @@ arguments passed to the built-in function. The result is a\n\ complete expression that implements the operation, usually\n\ another @code{CALL_EXPR}.\n\ @var{arglist} really has type @samp{VEC(tree,gc)*}", - tree, (unsigned int /*location_t*/ loc, tree fndecl, void *arglist), NULL) + tree, (location_t loc, tree fndecl, void *arglist), NULL) DEFHOOK (check_builtin_call, From patchwork Sun Nov 3 22:22:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005831 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=INtZqNQV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhTkm2p1vz1xwV for ; Mon, 4 Nov 2024 09:28:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9178B3857833 for ; Sun, 3 Nov 2024 22:27:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by sourceware.org (Postfix) with ESMTPS id 12DC73858027 for ; Sun, 3 Nov 2024 22:23:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12DC73858027 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 12DC73858027 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672589; cv=none; b=ZQjNM92fRLGqMdBi5rBchbLtf2w5yrPWlqxdgU7yX3RJfYdWs7kmepTNEMfA8q0IPpFsQEhbYiBYJsvdgEhOeycnFvlXHtpndPPMrN+s9Ork6J1JrKslrpYdZs15/faBIhEDYVEwPNkJL1D8Sm4fMhPBLBYCOzlNoP4q8Olz1Qs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672589; c=relaxed/simple; bh=v9HZJCuNH++Zgd3a9m57zVK1lasdtLMxdbgYCaC3+f0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Pz4+V07PJEeQnHe7PdtcGbt9eJ+6iO0cvupoP/Coxy2394hfnDEjawAVC3CKbfd1x4wTnkmbYVMyzJ4HOqiO28hejHH/Eeu2QQRMqYadE71Y6mrdwPeFcHAHB4caTlOLQm0QNDh/fTgVKI0d+qhb/Z3EvluTUdJCAnUvOEO6cs4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf34.google.com with SMTP id 6a1803df08f44-6cbf2fc28feso26529116d6.0 for ; Sun, 03 Nov 2024 14:23:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672580; x=1731277380; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f3/ESJuEUwYkYfLE05xzYp1ThoknwKe/M3vJGwIJOfc=; b=INtZqNQVSCFxLYvIka/+iX33NBb+N1JQUq6XqZ0JDBH7q4juztMeM6aboCWo32lolB yYQpCwGPeL/NbqilPMyFucigB7jgaKkTXA5YvUAxgKAmJiJgR/FyElyxosT6aQol3xvG tap4NMfWkmb8hDsnpS6m44No7oRHMin0SufgR67p7iatjS47RTnj+77qQn7qmkwCz53I v09jF8+lXG2Mbz/MXh6iG6hiXZNUS1zvjSfDP8HjpDG2Sgifi6eZoE2j3IdpRZ38Gth4 Flp79+UPr1ditcZnBsyt/9LXwZSBXQ/VfbbkOiloZo6vWiUP8xQVur2XgNEnadOwquRP iOrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672580; x=1731277380; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f3/ESJuEUwYkYfLE05xzYp1ThoknwKe/M3vJGwIJOfc=; b=IUgMzBsaECfqTGPf+Nd9acfqadiVGA0H5hLiaWmIMlg8Jln6Npn47iWrW0yh3RHd5D rEBw5IUhvToG8qp1V0YPHCIs5WNqTilXOHfSnJvI0SisKqq3/AVTUwpR765fahlflXUe GheWhjgtWAA6KFXrtQ4XBuM9yuO85TtkJEUTpGFQZgychKtVI0WkCjWR9XP3fkgazUXd Uv36gmizQW7Xuve9Cntn2SAxD+1YnOZ7krzwRrP9xX+1lgl5WADVO8C/65c+yF8ZDXOX tLNCefuqis/JMNisymAdHuzt1e79xCpfbbIk66YkuQ9bILq0fWa9t6gb6vfo0BClC5tt Z4nw== X-Gm-Message-State: AOJu0YxR/x4SDh9qpBUTlIWwss81etZSLQcU1GgE2nLO6RkbTCBW2u44 6QRjhLLmme3EOA7/3gJ19xSY/NE+3b0zM2EkoVkZdGn4Iz5Rui2Iut+dxA== X-Google-Smtp-Source: AGHT+IGzGC2vIEh/0KjQJ+/gpJhVtCaXn+Ji9JMPdOPdt1HNljgV0AjuOPE5ocvaxV6ftyJBehfm3w== X-Received: by 2002:a05:6214:5543:b0:6cc:37bb:40b with SMTP id 6a1803df08f44-6d185841246mr527169566d6.37.1730672580218; Sun, 03 Nov 2024 14:23:00 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.22.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:22:58 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 13/15] Support for 64-bit location_t: Internal parts Date: Sun, 3 Nov 2024 17:22:18 -0500 Message-Id: <20241103222220.933471-14-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Several of the selftests in diagnostic-show-locus.cc and input.cc are sensitive to linemap internals. Adjust them here so they will support 64-bit location_t if configured. Likewise, handle 64-bit location_t in the support for -fdump-internal-locations. As was done with the analyzer, convert to (unsigned long long) explicitly so that 32- and 64-bit can be handled with the same printf formats. gcc/ChangeLog: * diagnostic-show-locus.cc (test_one_liner_fixit_validation_adhoc_locations): Adapt so it can effectively test 7-bit ranges instead of 5-bit ranges. (test_one_liner_fixit_validation_adhoc_locations_utf8): Likewise. * input.cc (get_end_location): Adjust types to support 64-bit location_t. (write_digit_row): Likewise. (dump_location_range): Likewise. (dump_location_info): Likewise. (class line_table_case): Likewise. (test_accessing_ordinary_linemaps): Replace some hard-coded constants with the values defined in line-map.h. (for_each_line_table_case): Likewise. --- gcc/diagnostic-show-locus.cc | 128 +++++++++++++++++++++++++++++------ gcc/input.cc | 100 ++++++++++++++------------- 2 files changed, 157 insertions(+), 71 deletions(-) diff --git a/gcc/diagnostic-show-locus.cc b/gcc/diagnostic-show-locus.cc index a2a4b047ff9..ffe9e807104 100644 --- a/gcc/diagnostic-show-locus.cc +++ b/gcc/diagnostic-show-locus.cc @@ -4013,12 +4013,12 @@ test_one_liner_fixit_validation_adhoc_locations () { /* Generate a range that's too long to be packed, so must be stored as an ad-hoc location (given the defaults - of 5 bits or 0 bits of packed range); 41 columns > 2**5. */ + of 5 or 7 bits or 0 bits of packed range); 150 columns > 2**7. */ const location_t c7 = linemap_position_for_column (line_table, 7); - const location_t c47 = linemap_position_for_column (line_table, 47); - const location_t loc = make_location (c7, c7, c47); + const location_t c157 = linemap_position_for_column (line_table, 157); + const location_t loc = make_location (c7, c7, c157); - if (c47 > LINE_MAP_MAX_LOCATION_WITH_COLS) + if (c157 > LINE_MAP_MAX_LOCATION_WITH_COLS) return; ASSERT_TRUE (IS_ADHOC_LOC (loc)); @@ -4032,7 +4032,18 @@ test_one_liner_fixit_validation_adhoc_locations () test_diagnostic_context dc; ASSERT_STREQ (" foo = bar.field;\n" - " ^~~~~~~~~~ \n" + " ^~~~~~~~~~ " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " \n" " test\n", dc.test_show_locus (richloc)); } @@ -4040,29 +4051,62 @@ test_one_liner_fixit_validation_adhoc_locations () /* Remove. */ { rich_location richloc (line_table, loc); - source_range range = source_range::from_locations (loc, c47); + source_range range = source_range::from_locations (loc, c157); richloc.add_fixit_remove (range); /* It should not have been discarded by the validator. */ ASSERT_EQ (1, richloc.get_num_fixit_hints ()); test_diagnostic_context dc; ASSERT_STREQ (" foo = bar.field;\n" - " ^~~~~~~~~~ \n" - " -----------------------------------------\n", + " ^~~~~~~~~~ " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " \n" + " -----------------------------------------" + "----------" + "----------" + "----------" + "----------" + "----------" + "----------" + "----------" + "----------" + "----------" + "----------" + "----------\n", dc.test_show_locus (richloc)); } /* Replace. */ { rich_location richloc (line_table, loc); - source_range range = source_range::from_locations (loc, c47); + source_range range = source_range::from_locations (loc, c157); richloc.add_fixit_replace (range, "test"); /* It should not have been discarded by the validator. */ ASSERT_EQ (1, richloc.get_num_fixit_hints ()); test_diagnostic_context dc; ASSERT_STREQ (" foo = bar.field;\n" - " ^~~~~~~~~~ \n" + " ^~~~~~~~~~ " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " \n" " test\n", dc.test_show_locus (richloc)); } @@ -4552,12 +4596,12 @@ test_one_liner_fixit_validation_adhoc_locations_utf8 () { /* Generate a range that's too long to be packed, so must be stored as an ad-hoc location (given the defaults - of 5 bits or 0 bits of packed range); 41 columns > 2**5. */ + of 5 bits or 7 bits or 0 bits of packed range); 150 columns > 2**7. */ const location_t c12 = linemap_position_for_column (line_table, 12); - const location_t c52 = linemap_position_for_column (line_table, 52); - const location_t loc = make_location (c12, c12, c52); + const location_t c162 = linemap_position_for_column (line_table, 162); + const location_t loc = make_location (c12, c12, c162); - if (c52 > LINE_MAP_MAX_LOCATION_WITH_COLS) + if (c162 > LINE_MAP_MAX_LOCATION_WITH_COLS) return; ASSERT_TRUE (IS_ADHOC_LOC (loc)); @@ -4575,7 +4619,18 @@ test_one_liner_fixit_validation_adhoc_locations_utf8 () "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" ";\n" - " ^~~~~~~~~~~~~~~~ \n" + " ^~~~~~~~~~~~~~~~ " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " \n" " test\n", dc.test_show_locus (richloc)); } @@ -4583,7 +4638,7 @@ test_one_liner_fixit_validation_adhoc_locations_utf8 () /* Remove. */ { rich_location richloc (line_table, loc); - source_range range = source_range::from_locations (loc, c52); + source_range range = source_range::from_locations (loc, c162); richloc.add_fixit_remove (range); /* It should not have been discarded by the validator. */ ASSERT_EQ (1, richloc.get_num_fixit_hints ()); @@ -4594,15 +4649,37 @@ test_one_liner_fixit_validation_adhoc_locations_utf8 () "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" ";\n" - " ^~~~~~~~~~~~~~~~ \n" - " -------------------------------------\n", + " ^~~~~~~~~~~~~~~~ " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " \n" + " -------------------------------------" + "----------" + "----------" + "----------" + "----------" + "----------" + "----------" + "----------" + "----------" + "----------" + "----------" + "----------\n", dc.test_show_locus (richloc)); } /* Replace. */ { rich_location richloc (line_table, loc); - source_range range = source_range::from_locations (loc, c52); + source_range range = source_range::from_locations (loc, c162); richloc.add_fixit_replace (range, "test"); /* It should not have been discarded by the validator. */ ASSERT_EQ (1, richloc.get_num_fixit_hints ()); @@ -4613,7 +4690,18 @@ test_one_liner_fixit_validation_adhoc_locations_utf8 () "_bar.\xf0\x9f\x98\x82" "_field\xcf\x80" ";\n" - " ^~~~~~~~~~~~~~~~ \n" + " ^~~~~~~~~~~~~~~~ " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " \n" " test\n", dc.test_show_locus (richloc)); } diff --git a/gcc/input.cc b/gcc/input.cc index 04462ef6f5a..1629e4aeee8 100644 --- a/gcc/input.cc +++ b/gcc/input.cc @@ -1271,7 +1271,7 @@ dump_line_table_statistics (void) /* Get location one beyond the final location in ordinary map IDX. */ static location_t -get_end_location (class line_maps *set, unsigned int idx) +get_end_location (class line_maps *set, line_map_uint_t idx) { if (idx == LINEMAPS_ORDINARY_USED (set) - 1) return set->highest_location; @@ -1301,7 +1301,7 @@ write_digit_row (FILE *stream, int indent, fprintf (stream, "|"); for (int column = 1; column < max_col; column++) { - location_t column_loc = loc + (column << map->m_range_bits); + location_t column_loc = loc + (location_t (column) << map->m_range_bits); write_digit (stream, column_loc / divisor); } fprintf (stream, "\n"); @@ -1315,8 +1315,8 @@ dump_location_range (FILE *stream, location_t start, location_t end) { fprintf (stream, - " location_t interval: %u <= loc < %u\n", - start, end); + " location_t interval: %llu <= loc < %llu\n", + (unsigned long long) start, (unsigned long long) end); } /* Write a labelled description of a half-closed (START) / half-open (END) @@ -1343,15 +1343,18 @@ dump_location_info (FILE *stream) dump_labelled_location_range (stream, "RESERVED LOCATIONS", 0, RESERVED_LOCATION_COUNT); + using ULL = unsigned long long; + /* Visualize the ordinary line_map instances, rendering the sources. */ - for (unsigned int idx = 0; idx < LINEMAPS_ORDINARY_USED (line_table); idx++) + for (line_map_uint_t idx = 0; idx < LINEMAPS_ORDINARY_USED (line_table); + idx++) { location_t end_location = get_end_location (line_table, idx); /* half-closed: doesn't include this one. */ const line_map_ordinary *map = LINEMAPS_ORDINARY_MAP_AT (line_table, idx); - fprintf (stream, "ORDINARY MAP: %i\n", idx); + fprintf (stream, "ORDINARY MAP: %llu\n", (ULL) idx); dump_location_range (stream, MAP_START_LOCATION (map), end_location); fprintf (stream, " file: %s\n", ORDINARY_MAP_FILE_NAME (map)); @@ -1387,18 +1390,18 @@ dump_location_info (FILE *stream) const line_map_ordinary *includer_map = linemap_included_from_linemap (line_table, map); - fprintf (stream, " included from location: %d", - linemap_included_from (map)); + fprintf (stream, " included from location: %llu", + (ULL) linemap_included_from (map)); if (includer_map) { - fprintf (stream, " (in ordinary map %d)", - int (includer_map - line_table->info_ordinary.maps)); + fprintf (stream, " (in ordinary map %llu)", + ULL (includer_map - line_table->info_ordinary.maps)); } fprintf (stream, "\n"); /* Render the span of source lines that this "map" covers. */ for (location_t loc = MAP_START_LOCATION (map); loc < end_location; - loc += (1 << map->m_range_bits) ) + loc += (location_t (1) << map->m_range_bits)) { gcc_assert (pure_location_p (line_table, loc) ); @@ -1414,16 +1417,16 @@ dump_location_info (FILE *stream) if (!line_text) break; fprintf (stream, - "%s:%3i|loc:%5i|%.*s\n", + "%s:%3i|loc:%5llu|%.*s\n", exploc.file, exploc.line, - loc, + (ULL) loc, (int)line_text.length (), line_text.get_buffer ()); /* "loc" is at column 0, which means "the whole line". Render the locations *within* the line, by underlining it, showing the location_t numeric values at each column. */ - size_t max_col = (1 << map->m_column_and_range_bits) - 1; + auto max_col = (ULL (1) << map->m_column_and_range_bits) - 1; if (max_col > line_text.length ()) max_col = line_text.length () + 1; @@ -1460,19 +1463,19 @@ dump_location_info (FILE *stream) LINEMAPS_MACRO_LOWEST_LOCATION (line_table)); /* Visualize the macro line_map instances, rendering the sources. */ - for (unsigned int i = 0; i < LINEMAPS_MACRO_USED (line_table); i++) + for (line_map_uint_t i = 0; i < LINEMAPS_MACRO_USED (line_table); i++) { /* Each macro map that is allocated owns location_t values that are *lower* that the one before them. Hence it's meaningful to view them either in order of ascending source locations, or in order of ascending macro map index. */ const bool ascending_location_ts = true; - unsigned int idx = (ascending_location_ts - ? (LINEMAPS_MACRO_USED (line_table) - (i + 1)) - : i); + auto idx = (ascending_location_ts + ? (LINEMAPS_MACRO_USED (line_table) - (i + 1)) + : i); const line_map_macro *map = LINEMAPS_MACRO_MAP_AT (line_table, idx); - fprintf (stream, "MACRO %i: %s (%u tokens)\n", - idx, + fprintf (stream, "MACRO %llu: %s (%u tokens)\n", + (ULL) idx, linemap_map_get_macro_name (map), MACRO_MAP_NUM_MACRO_TOKENS (map)); dump_location_range (stream, @@ -1480,10 +1483,10 @@ dump_location_info (FILE *stream) (map->start_location + MACRO_MAP_NUM_MACRO_TOKENS (map))); inform (map->get_expansion_point_location (), - "expansion point is location %i", - map->get_expansion_point_location ()); - fprintf (stream, " map->start_location: %u\n", - map->start_location); + "expansion point is location %llu", + (ULL) map->get_expansion_point_location ()); + fprintf (stream, " map->start_location: %llu\n", + (ULL) map->start_location); fprintf (stream, " macro_locations:\n"); for (unsigned int i = 0; i < MACRO_MAP_NUM_MACRO_TOKENS (map); i++) @@ -1503,24 +1506,26 @@ dump_location_info (FILE *stream) This would explain there being up to 4 location_ts slots that may be uninitialized. */ - fprintf (stream, " %u: %u, %u\n", + fprintf (stream, " %u: %llu, %llu\n", i, - x, - y); + (ULL) x, + (ULL) y); if (x == y) { if (x < MAP_START_LOCATION (map)) - inform (x, "token %u has %", - i, x); + inform (x, "token %u has %", + i, (ULL) x); else fprintf (stream, - "x-location == y-location == %u encodes token # %u\n", - x, x - MAP_START_LOCATION (map)); - } + "x-location == y-location == %llu" + " encodes token # %u\n", + (ULL) x, + (unsigned int)(x - MAP_START_LOCATION (map))); + } else { - inform (x, "token %u has %", i, x); - inform (x, "token %u has %", i, y); + inform (x, "token %u has %", i, (ULL) x); + inform (x, "token %u has %", i, (ULL) y); } } fprintf (stream, "\n"); @@ -1536,7 +1541,7 @@ dump_location_info (FILE *stream) /* Visualize ad-hoc values. */ dump_labelled_location_range (stream, "AD-HOC LOCATIONS", - MAX_LOCATION_T + 1, UINT_MAX); + MAX_LOCATION_T + 1, location_t (-1)); } /* string_concat's constructor. */ @@ -2036,13 +2041,13 @@ assert_loceq (const char *exp_filename, int exp_linenum, int exp_colnum, class line_table_case { public: - line_table_case (int default_range_bits, int base_location) + line_table_case (int default_range_bits, location_t base_location) : m_default_range_bits (default_range_bits), m_base_location (base_location) {} int m_default_range_bits; - int m_base_location; + location_t m_base_location; }; /* Constructor. Store the old value of line_table, and create a new @@ -2132,9 +2137,9 @@ test_accessing_ordinary_linemaps (const line_table_case &case_) location_t loc_start_of_very_long_line = linemap_position_for_column (line_table, 2000); location_t loc_too_wide - = linemap_position_for_column (line_table, 4097); + = linemap_position_for_column (line_table, LINE_MAP_MAX_COLUMN_NUMBER + 1); location_t loc_too_wide_2 - = linemap_position_for_column (line_table, 4098); + = linemap_position_for_column (line_table, LINE_MAP_MAX_COLUMN_NUMBER + 2); /* ...and back to a sane line length. */ linemap_line_start (line_table, 6, 100); @@ -3865,11 +3870,11 @@ static const location_t boundary_locations[] = { LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES + 0x100, /* Values near LINE_MAP_MAX_LOCATION_WITH_COLS. */ - LINE_MAP_MAX_LOCATION_WITH_COLS - 0x100, + LINE_MAP_MAX_LOCATION_WITH_COLS - 0x200, LINE_MAP_MAX_LOCATION_WITH_COLS - 1, LINE_MAP_MAX_LOCATION_WITH_COLS, LINE_MAP_MAX_LOCATION_WITH_COLS + 1, - LINE_MAP_MAX_LOCATION_WITH_COLS + 0x100, + LINE_MAP_MAX_LOCATION_WITH_COLS + 0x200, }; /* Run TESTCASE multiple times, once for each case in our test matrix. */ @@ -3884,10 +3889,9 @@ for_each_line_table_case (void (*testcase) (const line_table_case &)) /* Run all tests with: (a) line_table->default_range_bits == 0, and - (b) line_table->default_range_bits == 5. */ - int num_cases_tested = 0; - for (int default_range_bits = 0; default_range_bits <= 5; - default_range_bits += 5) + (b) line_table->default_range_bits == line_map_suggested_range_bits. */ + + for (int default_range_bits: {0, line_map_suggested_range_bits}) { /* ...and use each of the "interesting" location values as the starting location within line_table. */ @@ -3895,15 +3899,9 @@ for_each_line_table_case (void (*testcase) (const line_table_case &)) for (int loc_idx = 0; loc_idx < num_boundary_locations; loc_idx++) { line_table_case c (default_range_bits, boundary_locations[loc_idx]); - testcase (c); - - num_cases_tested++; } } - - /* Verify that we fully covered the test matrix. */ - ASSERT_EQ (num_cases_tested, 2 * 12); } /* Verify that when presented with a consecutive pair of locations with From patchwork Sun Nov 3 22:22:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005826 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=m8rO+piG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhThC6CNdz1xwV for ; Mon, 4 Nov 2024 09:25:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 138C7385843F for ; Sun, 3 Nov 2024 22:25:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by sourceware.org (Postfix) with ESMTPS id 4DEB0385782C for ; Sun, 3 Nov 2024 22:23:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DEB0385782C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4DEB0385782C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672596; cv=none; b=uuuvSKGAUBPXq4IVY6VGJ7KIwxrwRSVpCNyoq/MCWUdsPF6aIar7/App5KS+mXwexXl3dRxT/4zhp7zBXsm/fXznI7cR0ddZG0YDPfZjGGEn6f1Wk3fimKrssaKhrRLSvJuV+MhH9CPPH5PJVjfPgN26OHQwk1/F/up6ItK+dKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672596; c=relaxed/simple; bh=93mo04Y5MdhgVdOS2qA/rxUdFfXp3rLP8/u+ZWoYEAM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Kxc5B6QdlaRf4046YwVnIRQEGPKJQXlv1flaO5KD0NfI0g1W6JUUwwLv8ngcRdTVQ7jGtcbHJ7HS/wm2nhUPS8oXTNtPwyh3F1Zw3j3g61WRdtOsNDbfvTuR6XYsq7VQA/A4JcPRTkcSGQTb3G4lYDsKf2Gd1/Wc6g/Ym3fVlhM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-6cbe9914487so26860786d6.1 for ; Sun, 03 Nov 2024 14:23:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672582; x=1731277382; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yjavlwy73Qcmjvc90z0/4Dq7kOFgTWsxoGo4U+aly+I=; b=m8rO+piGRm6dFGuRwkGBfdvK9JF6PbQowpn/YhI9dbkFMqA9orboEoD+gDsrbZwdm5 YD8fZDTRp7Wu7GJp5x75zws7w1uoyc5vrfz0z1ZGOO5FwhWIQT5k3ox0AxUebf7Bv7bJ 1lODLNGbZHNX6ShevtrM+uXoEwKLdljEQ7jA/lDExAqUHsxuINDTlPSShrYKqxlFFIzE 7wQb8zRy6KTK9TEtnvl4S8RLIiKNu4aNbRh8/4O9dK3U0PmLDG4EEMHnNxslsGW3ri45 MBjn6StJviQ0MxI3uDYE0uPoJMusRyXnMdoCa0K+qQkXX6gfWh/r6PhTWGtj9X5QjQaV gAyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672582; x=1731277382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yjavlwy73Qcmjvc90z0/4Dq7kOFgTWsxoGo4U+aly+I=; b=dLXpnGqwTOsTETTl7t1JGNEj+1Qu+aOoha2l3JEumX2ohpxOKLXO35jtl1EOJomzIk wJu18eEgJByDfGGxRmTBgdaSWij7I9eiKP8a3MgZU1Sf86o/5ond0rZOsA0VWTZAfqde djDKlTJFpb/qugpuB4BjvGAzA4IPuDtvDN2hbOTmIPiUcUwYL9pLy3jg7SPCP/8gIZmQ CR+RJGlcJjI044/RfCdydQUqw+mSA6mlxJQwm2O7Rr5UvyD+KP517qAKYOIRyx9WwK4w Y/175+FRIZoF5lAAR8ZDIw2GKZVc9l5Xa/Ny3jvvWPylAcYWfC+rUygnhrxiWjWw0rwo ar2w== X-Gm-Message-State: AOJu0YyUigj4mZu0UK+/JoNSN7FKn8Hz/ZfCIhk4jwZoHboPgbjtN26a XkQmbGfwmy7iE0ef7MFciyUiPALEOEFQCy/M0gdDjbnzs+vo1gro5ClDiA== X-Google-Smtp-Source: AGHT+IFEU6wdfJ/Paw2/DQrr1g7SLdaZJkx90K0kFEFNK3v0xc3lAA8fa3Xknsp0w0uzJMoVxmfMiA== X-Received: by 2002:a05:6214:3f88:b0:6cb:e952:8096 with SMTP id 6a1803df08f44-6d351b35b82mr199741316d6.50.1730672581624; Sun, 03 Nov 2024 14:23:01 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.23.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:23:01 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 14/15] Support for 64-bit location_t: Testsuite parts Date: Sun, 3 Nov 2024 17:22:19 -0500 Message-Id: <20241103222220.933471-15-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Add support to the testsuite for effective target "large_location_t" indicating if 64-bit location support has been configured. Adjust the tests that are sensitive to location_t internals so they can test large locations too. gcc/testsuite/ChangeLog: * lib/target-supports.exp (check_no_compiler_messages_nocache): Refactor the code for retrieving compiler messages to... (get_compiler_messages_nocache) ...here. New function. (get_compiler_messages): New function. (check_effective_target_large_location_t): New function. * g++.dg/diagnostic/pr77949.C: Adapt the test for 64-bit location_t, when the expected failure doesn't actually happen. * g++.dg/modules/loc-prune-4.C: Adjust the expected output for the 64-bit location_t case * gcc.dg/plugin/expensive_selftests_plugin.c: Don't try to test the maximum supported column number in 64-bit location_t mode. * gcc.dg/plugin/location_overflow_plugin.c: Adjust the base_location so it can effectively test 64-bit location_t as well. --- gcc/testsuite/g++.dg/diagnostic/pr77949.C | 5 ++- gcc/testsuite/g++.dg/modules/loc-prune-4.C | 11 ++++-- .../plugin/expensive_selftests_plugin.c | 7 ++-- .../gcc.dg/plugin/location_overflow_plugin.c | 7 ++++ gcc/testsuite/lib/target-supports.exp | 34 +++++++++++++++++-- 5 files changed, 55 insertions(+), 9 deletions(-) diff --git a/gcc/testsuite/g++.dg/diagnostic/pr77949.C b/gcc/testsuite/g++.dg/diagnostic/pr77949.C index b81d6e2bb46..35922e9bb23 100644 --- a/gcc/testsuite/g++.dg/diagnostic/pr77949.C +++ b/gcc/testsuite/g++.dg/diagnostic/pr77949.C @@ -1,7 +1,10 @@ -// Ensure that no fix-it hints are emitted +// Ensure that no fix-it hints are emitted unless large locations are available. // { dg-options "-fdiagnostics-parseable-fixits" } /* Very long line, where a missing semicolon would be suggested for insertion at column 4097. */ class test { } // { dg-error "-: expected .;. after class definition" "" { target *-*-* } .-1 } +/* { dg-begin-multiline-output "" } +fix-it: +{ dg-end-multiline-output "" { target large_location_t } } */ diff --git a/gcc/testsuite/g++.dg/modules/loc-prune-4.C b/gcc/testsuite/g++.dg/modules/loc-prune-4.C index aa8f248b52b..a6c62a3385c 100644 --- a/gcc/testsuite/g++.dg/modules/loc-prune-4.C +++ b/gcc/testsuite/g++.dg/modules/loc-prune-4.C @@ -16,7 +16,12 @@ int bar (int); // merge lines int baz (int); -// { dg-final { scan-lang-dump {Ordinary maps:2 locs:12288 range_bits:5} module } } // { dg-final { scan-lang-dump { 1 source file names\n Source file...=[^\n]*loc-prune-4.C\n} module } } -// { dg-final { scan-lang-dump { Span:0 ordinary \[[0-9]+\+12288,\+4096\)->\[0,\+4096\)} module } } -// { dg-final { scan-lang-dump { Span:1 ordinary \[[0-9]+\+40960,\+8192\)->\[4096,\+8192\)} module } } + +// { dg-final { scan-lang-dump {Ordinary maps:2 locs:12288 range_bits:5} module { target { ! large_location_t } } } } +// { dg-final { scan-lang-dump { Span:0 ordinary \[[0-9]+\+12288,\+4096\)->\[0,\+4096\)} module { target { ! large_location_t } } } } +// { dg-final { scan-lang-dump { Span:1 ordinary \[[0-9]+\+40960,\+8192\)->\[4096,\+8192\)} module { target { ! large_location_t } } } } + +// { dg-final { scan-lang-dump {Ordinary maps:2 locs:49152 range_bits:7} module { target large_location_t } } } +// { dg-final { scan-lang-dump { Span:0 ordinary \[[0-9]+\+49152,\+16384\)->\[0,\+16384\)} module { target large_location_t } } } +// { dg-final { scan-lang-dump { Span:1 ordinary \[[0-9]+\+163840,\+32768\)->\[16384,\+32768\)} module { target large_location_t } } } diff --git a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c index e96efe0bed5..1b487ad63b6 100644 --- a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.c @@ -63,17 +63,20 @@ test_richloc (rich_location *richloc) static void test_fixit_on_very_long_line (const line_table_case &case_) { - /* Various interesting column/line-width values, to try to tickle - out bugs. */ + /* Various interesting column/line-width values, to try to tickle out bugs. In + 64-bit location mode, we can't test the max because the maximum supported + column is unreasonably large. */ const int VERY_LONG_LINE = 8192; const int columns[] = {0, 1, 80, +#ifndef ENABLE_LARGE_SOURCE_LOCATIONS LINE_MAP_MAX_COLUMN_NUMBER - 2, LINE_MAP_MAX_COLUMN_NUMBER - 1, LINE_MAP_MAX_COLUMN_NUMBER, LINE_MAP_MAX_COLUMN_NUMBER + 1, LINE_MAP_MAX_COLUMN_NUMBER + 2, +#endif VERY_LONG_LINE, VERY_LONG_LINE + 5}; for (unsigned int width_idx = 0; width_idx < ARRAY_SIZE (columns); diff --git a/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.c b/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.c index 45a01b5f917..f7d7ca4b57c 100644 --- a/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.c +++ b/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.c @@ -84,6 +84,13 @@ plugin_init (struct plugin_name_args *plugin_info, if (!base_location) error_at (UNKNOWN_LOCATION, "missing plugin argument"); + /* With 64-bit sources, the thresholds are larger, so shift the base + location argument accordingly. */ +#ifdef ENABLE_LARGE_SOURCE_LOCATIONS + gcc_assert (sizeof (location_t) == sizeof (uint64_t)); + base_location = 1 + ((base_location - 1) << 31); +#endif + register_callback (plugin_info->base_name, PLUGIN_PRAGMAS, on_pragma_registration, diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 75703ddca60..f92dda583b1 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -180,13 +180,27 @@ proc clear_effective_target_cache { } { array unset et_cache } -# Like check_compile, but delete the output file and return true if the -# compiler printed no messages. -proc check_no_compiler_messages_nocache {args} { +# Like check_compile, but delete the output file and return just the +# compiler output as a string. +proc get_compiler_messages_nocache {args} { set result [eval check_compile $args] set lines [lindex $result 0] set output [lindex $result 1] remote_file build delete $output + return $lines +} + +# And the cached version. +proc get_compiler_messages {prop args} { + return [check_cached_effective_target $prop { + eval [list get_compiler_messages_nocache $prop] $args + }] +} + +# Like check_compile, but delete the output file and return true if the +# compiler printed no messages. +proc check_no_compiler_messages_nocache {args} { + set lines [eval get_compiler_messages_nocache $args ] return [string match "" $lines] } @@ -13939,3 +13953,17 @@ proc add_options_for_nvptx_alias_ptx { flags } { return $flags } + + +# Return 1 if GCC was configured with large (64-bit) location_t. + +proc check_effective_target_large_location_t { } { + set lines [get_compiler_messages large_location_t assembly ";" "-fdump-internal-locations" ] + if ![ regexp {\nMAX_LOCATION_T\s*location_t interval: (\d*)} $lines dummy max_loc ] { + verbose "Could not parse output of -fdump-internal-locations. Assuming small location_t." 2 + return 0 + } + # No need to rely on 64-bit capable TCL here. The max for 32-bit locations + # is 2147483647, which is 10 characters long. + return [ expr { [string length $max_loc] > 10 } ] +} From patchwork Sun Nov 3 22:22:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lewis Hyatt X-Patchwork-Id: 2005832 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=kiLpWS7d; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XhTm26C1Rz1xwV for ; Mon, 4 Nov 2024 09:29:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C765F3857C63 for ; Sun, 3 Nov 2024 22:28:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by sourceware.org (Postfix) with ESMTPS id 391993857833 for ; Sun, 3 Nov 2024 22:23:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 391993857833 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 391993857833 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672595; cv=none; b=RqcvV21Fi1Z4+zksFkYPlSL5Zit3ai+b0NpFevH1bXwz1w3Np/l6RjfQiLEItTwoBS2Mew7TYuVQszOZ6PF5g0WvWX2vHydabqaC6RHtFym1GjSO3CA5RxEpI2HDY7X0Juy8Lp74OWG/1pUuJ1KrwcADVlzFSgE4Z7y2JZ2NDik= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730672595; c=relaxed/simple; bh=Tp7IufBTE4bAFbdBQfC9ZV3toPyLqUjFHxo5KieLl+M=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=MYwVAqmrj7WnyQ+aAexJMN+mbgauYpkyuvIF7zpHsR3HD6YRSj95RpzEYS2fGl3ljgYFk6cTfu53kgu+36OzhzigZ1VQ/Ux6FJXl00rVgmvflHSQn+J6BTy0/FHKDq7t2MGoLHbwCidTAu/h34ZF0aaCFvqOWhbPI4nhR4yQXlE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf33.google.com with SMTP id 6a1803df08f44-6cbf0e6414aso20394126d6.1 for ; Sun, 03 Nov 2024 14:23:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730672582; x=1731277382; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EdpW2EHv3bE0RnxLOpJhkvUWJxdEjv4mpVymeDKzZBY=; b=kiLpWS7dAx2T08U1j1yQkt0qCGAHUWokWJHSlShPMV67nIWcZI1tFkAx2e627FMkxP wpLahzDtqxXUcfrDh8V7o2prq39rwpjwktVpaKn1tIvxm9Vj+ZgZqw5uDYf1E99hp+Cb c7c5fDcQOlkerhdwnvjnYwpgBdsuynZDc7jcv8FTHvsQ0eHW5GHFnxhRZqJyOESDt9kl Re8302pFiaWC6JH/f4Lb5IcwAVitKXWi4EMbgg02JwQ+v74yxBGGl369OatdZt1N5Uy4 T2Faf4tniHIGLZq7zn/ysIx3e+8kFTgF7BkQmWg23zUpMK6r0O/A+lVzbNEzzff/ZoG8 VJMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730672582; x=1731277382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EdpW2EHv3bE0RnxLOpJhkvUWJxdEjv4mpVymeDKzZBY=; b=HQ3lTGvK3rkAkop6FpzmV7qTc6V77oTX9+DF+iwyE3HdW8qiUoy9FRDlMFJNOoWGBD 1JdVIj/vGmr5xdMSFScbHQ1sHsq0FjtxQIOHBDZBaFnnCKFjsj+3FMvxg9NAM5NIMHbP cxA4PkcD23YCFY5cuwo3MuDdkMwoyIZSh2t6FATHfkecjlM/Vymv1ydbGOQhZIcchXwl SCTSWhWPWcOhd5szBcidsgOJiB6qRj7pbVHXl8t5ENtZmiffnImEctSWAbjHTXolwYaQ UOjpoXWIp5opCYToiXmz1XX8IZs+gr0X3b3r1eYIScNq5j3Zl2CWzMEWxADpHNSV0wQF C1Iw== X-Gm-Message-State: AOJu0YyLCoVl6lJx/qQofHSqhXWvSJEE2cPXLMaxIOGZRtrpB+7y7Mce AZXjGH9h7f7JHID+/lKxJwmsc7fElcv+zh29UIBt+o3+Pt7nPEwOiCuKaA== X-Google-Smtp-Source: AGHT+IEKeJs2JtI/+4wkGxyLDJ3zUptW02FimPQl1NvPpzz5NIULvW86ZLbw/xHIirzEbcL+eA4u7w== X-Received: by 2002:a05:6214:4b02:b0:6cb:afe7:1403 with SMTP id 6a1803df08f44-6d185866d2fmr471694406d6.48.1730672582492; Sun, 03 Nov 2024 14:23:02 -0800 (PST) Received: from localhost.localdomain ([173.54.240.58]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d35415b2fesm42025866d6.92.2024.11.03.14.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Nov 2024 14:23:01 -0800 (PST) From: Lewis Hyatt To: gcc-patches@gcc.gnu.org Cc: Lewis Hyatt Subject: [PATCH 15/15] Support for 64-bit location_t: Configury parts Date: Sun, 3 Nov 2024 17:22:20 -0500 Message-Id: <20241103222220.933471-16-lhyatt@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241103222220.933471-1-lhyatt@gmail.com> References: <20241103222220.933471-1-lhyatt@gmail.com> MIME-Version: 1.0 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Add --enable-large-source-locations (off by default for now) to enable 64-bit location_t. gcc/ChangeLog: * configure.ac: Add --enable-large-source-locations. * config.in: Regenerate. * configure: Regenerate. * doc/install.texi: Document the new option. libcpp/ChangeLog: * configure.ac: Add --enable-large-source-locations. * config.in: Regenerate. * configure: Regenerate. --- libcpp/config.in | 3 +++ libcpp/configure | 17 +++++++++++++++++ libcpp/configure.ac | 11 +++++++++++ gcc/config.in | 6 ++++++ gcc/configure | 21 +++++++++++++++++++-- gcc/configure.ac | 11 +++++++++++ gcc/doc/install.texi | 15 +++++++++++++++ 7 files changed, 82 insertions(+), 2 deletions(-) diff --git a/libcpp/config.in b/libcpp/config.in index b2e2f4e842c..74ff169a322 100644 --- a/libcpp/config.in +++ b/libcpp/config.in @@ -20,6 +20,9 @@ /* Define to enable system headers canonicalization. */ #undef ENABLE_CANONICAL_SYSTEM_HEADERS +/* Define to enable 64-bit locations. */ +#undef ENABLE_LARGE_SOURCE_LOCATIONS + /* Define to 1 if translation of program messages to the user's native language is requested. */ #undef ENABLE_NLS diff --git a/libcpp/configure b/libcpp/configure index 1391081ba09..eca82ab568f 100755 --- a/libcpp/configure +++ b/libcpp/configure @@ -753,6 +753,7 @@ enable_host_shared enable_host_pie enable_cet enable_valgrind_annotations +enable_large_source_locations ' ac_precious_vars='build_alias host_alias @@ -1397,6 +1398,8 @@ Optional Features: --enable-cet enable Intel CET in host libraries [default=auto] --enable-valgrind-annotations enable valgrind runtime interaction + --enable-large-source-locations + enable 64-bit source locations Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -9416,6 +9419,20 @@ $as_echo "#define ENABLE_VALGRIND_WORKAROUNDS 1" >>confdefs.h fi +# Specify whether to use 64-bit locations +# Check whether --enable-large-source-locations was given. +if test "${enable_large_source_locations+set}" = set; then : + enableval=$enable_large_source_locations; +else + enable_large_source_locations=no +fi + +if test x$enable_large_source_locations != xno; then + +$as_echo "#define ENABLE_LARGE_SOURCE_LOCATIONS 1" >>confdefs.h + +fi + # Output. ac_config_headers="$ac_config_headers config.h:config.in" diff --git a/libcpp/configure.ac b/libcpp/configure.ac index 981f97c4abd..091bbc44537 100644 --- a/libcpp/configure.ac +++ b/libcpp/configure.ac @@ -246,6 +246,17 @@ if test x$enable_valgrind_annotations != xno \ possible memory leaks because of libcpp use of interior pointers.]) fi +# Specify whether to use 64-bit locations +AC_ARG_ENABLE([large-source-locations], +[AC_HELP_STRING([--enable-large-source-locations], + [enable 64-bit source locations])], +[], +enable_large_source_locations=no) +if test x$enable_large_source_locations != xno; then + AC_DEFINE(ENABLE_LARGE_SOURCE_LOCATIONS, + 1, [Define to enable 64-bit locations.]) +fi + # Output. AC_CONFIG_HEADERS(config.h:config.in, [echo timestamp > stamp-h1]) diff --git a/gcc/config.in b/gcc/config.in index 0a506d1783a..ed779e78a12 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -206,6 +206,12 @@ #endif +/* Define to enable 64-bit locations. */ +#ifndef USED_FOR_TARGET +#undef ENABLE_LARGE_SOURCE_LOCATIONS +#endif + + /* Define if gcc should always pass --build-id to linker. */ #ifndef USED_FOR_TARGET #undef ENABLE_LD_BUILDID diff --git a/gcc/configure b/gcc/configure index 150ab616414..490f070c820 100755 --- a/gcc/configure +++ b/gcc/configure @@ -1059,6 +1059,7 @@ with_diagnostics_urls enable_default_pie enable_cet enable_s390_excess_float_precision +enable_large_source_locations ' ac_precious_vars='build_alias host_alias @@ -1832,6 +1833,8 @@ Optional Features: --enable-s390-excess-float-precision on s390 targets, evaluate float with double precision when in standards-conforming mode + --enable-large-source-locations + enable 64-bit source locations Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -21454,7 +21457,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 21457 "configure" +#line 21460 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -21560,7 +21563,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 21563 "configure" +#line 21566 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -34912,6 +34915,20 @@ _ACEOF { $as_echo "$as_me:${as_lineno-$LINENO}: result: $fhardened_support" >&5 $as_echo "$fhardened_support" >&6; } +# Specify whether to use 64-bit locations +# Check whether --enable-large-source-locations was given. +if test "${enable_large_source_locations+set}" = set; then : + enableval=$enable_large_source_locations; +else + enable_large_source_locations=no +fi + +if test x$enable_large_source_locations != xno; then + +$as_echo "#define ENABLE_LARGE_SOURCE_LOCATIONS 1" >>confdefs.h + +fi + # Configure the subdirectories # AC_CONFIG_SUBDIRS($subdirs) diff --git a/gcc/configure.ac b/gcc/configure.ac index bdb22d53e2c..c742229db47 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -7951,6 +7951,17 @@ AC_DEFINE_UNQUOTED(HAVE_FHARDENED_SUPPORT, [Define 0/1 if -fhardened is supported]) AC_MSG_RESULT($fhardened_support) +# Specify whether to use 64-bit locations +AC_ARG_ENABLE([large-source-locations], +[AC_HELP_STRING([--enable-large-source-locations], + [enable 64-bit source locations])], +[], +enable_large_source_locations=no) +if test x$enable_large_source_locations != xno; then + AC_DEFINE(ENABLE_LARGE_SOURCE_LOCATIONS, + 1, [Define to enable 64-bit locations.]) +fi + # Configure the subdirectories # AC_CONFIG_SUBDIRS($subdirs) diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi index b562b0f38d6..7bb643be8aa 100644 --- a/gcc/doc/install.texi +++ b/gcc/doc/install.texi @@ -2607,6 +2607,21 @@ include and lib options directly. These flags are applicable to the host platform only. When building a cross compiler, they will not be used to configure target libraries. + +@item --enable-large-source-locations +In order to reduce peak memory usage, GCC uses an optimized data +structure for storing the locations of source code it has parsed from +its input. This structure uses a 32-bit key to represent source +locations, which restricts the number of lines and columns that can be +tracked (per source file, or within one source file) for sufficiently +large source files. This can become evident as a degradation in the +quality of diagnostics; those users who want to support large source +files without encountering such issues and do not mind the extra +memory consumption may use @option{--enable-large-source-locations} +to switch to a 64-bit location type that is free of such practical +issues. This may become the default for some targets in a future +version of GCC. + @end table @subheading Cross-Compiler-Specific Options