From patchwork Thu Oct 11 12:41:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 982458 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-487321-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YgdQZZ7f"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42W9ZP275Qz9s9N for ; Thu, 11 Oct 2018 23:41:32 +1100 (AEDT) Received: (qmail 95168 invoked by alias); 11 Oct 2018 12:41:26 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 95158 invoked by uid 89); 11 Oct 2018 12:41:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=nathan@acm.org, nathanacmorg, Sidwell, thusly X-HELO: mail-yw1-f50.google.com Received: from mail-yw1-f50.google.com (HELO mail-yw1-f50.google.com) (209.85.161.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 11 Oct 2018 12:41:23 +0000 Received: by mail-yw1-f50.google.com with SMTP id j202-v6so3497945ywa.13 for ; Thu, 11 Oct 2018 05:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:cc:from:subject:message-id:date:user-agent:mime-version :content-language; bh=35PgZM2kX4X/HDMv716wvAFqEswJl3s/DJXfvVomcrA=; b=YgdQZZ7fZZ11pksKJZHjORNjhLGqjl0CH+oI/IY3+nwLTvsrw9jZM0YRH7K0YJQti6 pql4fn9zOGj0BwbGUFqOhcseUVq47hfAgCZJfWicFLW+JyFsaMgy3FxSsg9V1IzGg32o GQ6a5gYVRit2+UhpQ9JhU5BYTKAmYbR1/3B8lMaRGTRntDGw3AQAFgNybLw12/lSzhBp fpxYpzxgrhyTjxynNQACYh4K3R31pmkM9JUZItHo6ehcDAun31SQxDD3VeSGKyVcNY7Z Gv10r2sLLaQZdO7vwW1ZbGjeDPDmTmHp7MoLuKA4jl6YacE9jAUlNxmvTmGairGpjVk1 7+FA== Received: from ?IPv6:2620:10d:c0a3:20fb::822? ([2620:10d:c091:200::5:24da]) by smtp.googlemail.com with ESMTPSA id z20-v6sm12790478ywz.75.2018.10.11.05.41.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 05:41:21 -0700 (PDT) Sender: Nathan Sidwell To: GCC Patches Cc: David Malcolm From: Nathan Sidwell Subject: [PATCH] A couple of line map fixes Message-ID: <183f246f-b7a5-d881-1220-253efc42387f@acm.org> Date: Thu, 11 Oct 2018 08:41:19 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 I discovered a couple of line map bugs when working on streaming macro locations on the modules branch: 1) LINEMAPS_MACRO_LOWEST_LOCATION has an off-by-one error. It is returning the lowest macro loc handed out. MAX_SOURCE_LOCATION is the highest location that could be handed out. If we've not created any macros, then we've not handed out MAX_SOURCE_LOCATION, and should return one more than that. (The impact here is that the first macro created wouldn't use MAX_SOURCE_LOCATION.) 2) linemap_enter_macro allocates num_tokens * 2 locations, but only clears num_tokens locations. It seems we don't always use all those locations, and so can have trailing garbage. booted & tested on x86_64-linux. Fixing thusly. nathan 2018-10-11 Nathan Sidwell * include/line-map.h (LINEMAPS_MACRO_LOWEST_LOCATION): Fix off-by-one error. * line-map.c (linemap_enter_macro): Use RAII. Clear all of the macro_locations. Index: include/line-map.h =================================================================== --- include/line-map.h (revision 265035) +++ include/line-map.h (working copy) @@ -1017,7 +1017,7 @@ LINEMAPS_MACRO_LOWEST_LOCATION (const li { return LINEMAPS_MACRO_USED (set) ? MAP_START_LOCATION (LINEMAPS_LAST_MACRO_MAP (set)) - : MAX_SOURCE_LOCATION; + : MAX_SOURCE_LOCATION + 1; } /* Returns the last macro map allocated in the line table SET. */ Index: line-map.c =================================================================== --- line-map.c (revision 265035) +++ line-map.c (working copy) @@ -612,30 +612,24 @@ const line_map_macro * linemap_enter_macro (struct line_maps *set, struct cpp_hashnode *macro_node, source_location expansion, unsigned int num_tokens) { - line_map_macro *map; - source_location start_location; - /* Cast away extern "C" from the type of xrealloc. */ - line_map_realloc reallocator = (set->reallocator - ? set->reallocator - : (line_map_realloc) xrealloc); - - start_location = LINEMAPS_MACRO_LOWEST_LOCATION (set) - num_tokens; + source_location start_location + = LINEMAPS_MACRO_LOWEST_LOCATION (set) - num_tokens; if (start_location < LINE_MAP_MAX_LOCATION) /* We ran out of macro map space. */ return NULL; - map = linemap_check_macro (new_linemap (set, start_location)); + line_map_macro *map = linemap_check_macro (new_linemap (set, start_location)); map->macro = macro_node; map->n_tokens = num_tokens; map->macro_locations - = (source_location*) reallocator (NULL, - 2 * num_tokens - * sizeof (source_location)); + = (source_location*) set->reallocator (NULL, + 2 * num_tokens + * sizeof (source_location)); map->expansion = expansion; memset (MACRO_MAP_LOCATIONS (map), 0, - num_tokens * sizeof (source_location)); + 2 * num_tokens * sizeof (source_location)); LINEMAPS_MACRO_CACHE (set) = LINEMAPS_MACRO_USED (set) - 1;