From patchwork Wed Oct 31 15:25:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 991506 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-488746-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="bwaJ0aVs"; 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 42lXGk6xBNz9s3q for ; Thu, 1 Nov 2018 02:25:50 +1100 (AEDT) Received: (qmail 49597 invoked by alias); 31 Oct 2018 15:25:44 -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 49286 invoked by uid 89); 31 Oct 2018 15:25:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:BUILTIN X-HELO: mail-yw1-f46.google.com Received: from mail-yw1-f46.google.com (HELO mail-yw1-f46.google.com) (209.85.161.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 31 Oct 2018 15:25:08 +0000 Received: by mail-yw1-f46.google.com with SMTP id w135-v6so4396063ywd.2 for ; Wed, 31 Oct 2018 08:25:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:from:to:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=ZYgwUenoNVFTbkdCJaF/RNNZn8OeFCTw9drZiNsunOc=; b=bwaJ0aVsWLeHPvuUlE4xSaxKiZljU000+mOlNwcRrt6vl95VsDfJfMLECbHfM6OZKp faLNnZU2G1yDbAzDAo5fhdQ+H67PeJYSwMknfjR3x35bpjZPXdw0IkujnrkG6Am2S6ps 3zD8uk3OyySYF8xJRzqmday8Z+M7ZV+E+WP75dIoNPxhFJSZuTfqYWQDSw9Zgl+zA0Wr GjdR9Lbg9/91UWk+i8iDltyjseN6SdnNNXTSbJsQmcOJQpPivbk3hlv84O/1U0rMBkgJ FPUnRqp5Nu8F+AsKChcDRa+jlR29WjUGVLbORa5vAo+yq/Ga9uZrQQlQyghqsLn6hK5F I+kw== Received: from ?IPv6:2620:10d:c0a3:20fb:7903:c84d:a328:45c1? ([2620:10d:c091:200::7:9eec]) by smtp.googlemail.com with ESMTPSA id a189-v6sm6680625ywf.49.2018.10.31.08.25.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Oct 2018 08:25:05 -0700 (PDT) Sender: Nathan Sidwell Subject: [6/6] Preprocessor forced macro location From: Nathan Sidwell To: GCC Patches References: <96f6e7b4-8957-726d-800f-cbd46b3ded2d@acm.org> <3529fd28-7925-3d8d-3cb1-832ecb380d1c@acm.org> <298b861b-d54d-6e17-26c7-03206eeff703@acm.org> <705e9f3b-45ab-c91b-0f34-9eb06eb9f0e4@acm.org> Message-ID: Date: Wed, 31 Oct 2018 11:25:04 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <705e9f3b-45ab-c91b-0f34-9eb06eb9f0e4@acm.org> There's an API for forcing all macro definition token positions to be X. That takes a pointer to X, so one can distinguish between not forcing a location, and forcing the location to be UNKNOWN_LOCATION. However, we only use this to force BUILTINS_LOCATION, and if you're forcing UNKNOWN_LOCATION, I'd argue you're doing it wrong. This patch changes that API to take a location directly, and ban forcing UNKNOWN_LOCATION. booted & tested on x86_64-linux (as were all the others). Applying to trunk. nathan 2018-10-31 Nathan Sidwell libcpp/ * internal.h (struct cpp_reader): Rename forced_token_location_p to forced_token_location and drop its pointerness. * include/cpplib.h (cpp_force_token_locations): Take location, not pointer to one. * init.c (cpp_create_reader): Adjust. * lex.c (cpp_read_main_file): gcc/c-family/ * c-opts.c (c_finish_options): Adjust cpp_force_token_locations call. gcc/fortran/ * cpp.c (gfc_cpp_init): Adjust cpp_force_token_locations call. Index: libcpp/include/cpplib.h =================================================================== --- libcpp/include/cpplib.h (revision 265688) +++ libcpp/include/cpplib.h (working copy) @@ -1281,7 +1281,7 @@ extern int cpp_read_state (cpp_reader *, struct save_macro_data *); /* In lex.c */ -extern void cpp_force_token_locations (cpp_reader *, source_location *); +extern void cpp_force_token_locations (cpp_reader *, source_location); extern void cpp_stop_forcing_token_locations (cpp_reader *); /* In expr.c */ Index: libcpp/init.c =================================================================== --- libcpp/init.c (revision 265671) +++ libcpp/init.c (working copy) @@ -264,7 +264,7 @@ cpp_create_reader (enum c_lang lang, cpp pfile->pushed_macros = 0; /* Do not force token locations by default. */ - pfile->forced_token_location_p = NULL; + pfile->forced_token_location = 0; /* Initialize source_date_epoch to -2 (not yet set). */ pfile->source_date_epoch = (time_t) -2; Index: libcpp/internal.h =================================================================== --- libcpp/internal.h (revision 265671) +++ libcpp/internal.h (working copy) @@ -570,9 +570,9 @@ struct cpp_reader /* List of saved macros by push_macro. */ struct def_pragma_macro *pushed_macros; - /* If non-null, the lexer will use this location for the next token + /* If non-zero, the lexer will use this location for the next token instead of getting a location from the linemap. */ - source_location *forced_token_location_p; + source_location forced_token_location; }; /* Character classes. Based on the more primitive macros in safe-ctype.h. Index: libcpp/lex.c =================================================================== --- libcpp/lex.c (revision 265671) +++ libcpp/lex.c (working copy) @@ -2757,8 +2757,8 @@ _cpp_lex_direct (cpp_reader *pfile) } c = *buffer->cur++; - if (pfile->forced_token_location_p) - result->src_loc = *pfile->forced_token_location_p; + if (pfile->forced_token_location) + result->src_loc = pfile->forced_token_location; else result->src_loc = linemap_position_for_column (pfile->line_table, CPP_BUF_COLUMN (buffer, buffer->cur)); @@ -3773,14 +3773,14 @@ cpp_token_val_index (const cpp_token *to } } -/* All tokens lexed in R after calling this function will be forced to have - their source_location the same as the location referenced by P, until +/* All tokens lexed in R after calling this function will be forced to + have their source_location to be P, until cpp_stop_forcing_token_locations is called for R. */ void -cpp_force_token_locations (cpp_reader *r, source_location *p) +cpp_force_token_locations (cpp_reader *r, source_location loc) { - r->forced_token_location_p = p; + r->forced_token_location = loc; } /* Go back to assigning locations naturally for lexed tokens. */ @@ -3788,5 +3788,5 @@ cpp_force_token_locations (cpp_reader *r void cpp_stop_forcing_token_locations (cpp_reader *r) { - r->forced_token_location_p = NULL; + r->forced_token_location = 0; } Index: gcc/c-family/c-opts.c =================================================================== --- gcc/c-family/c-opts.c (revision 265671) +++ gcc/c-family/c-opts.c (working copy) @@ -1396,8 +1396,7 @@ c_finish_options (void) 0))); /* Make sure all of the builtins about to be declared have BUILTINS_LOCATION has their source_location. */ - source_location builtins_loc = BUILTINS_LOCATION; - cpp_force_token_locations (parse_in, &builtins_loc); + cpp_force_token_locations (parse_in, BUILTINS_LOCATION); cpp_init_builtins (parse_in, flag_hosted); c_cpp_builtins (parse_in); Index: gcc/fortran/cpp.c =================================================================== --- gcc/fortran/cpp.c (revision 265671) +++ gcc/fortran/cpp.c (working copy) @@ -579,8 +579,7 @@ gfc_cpp_init (void) { /* Make sure all of the builtins about to be declared have BUILTINS_LOCATION has their source_location. */ - source_location builtins_loc = BUILTINS_LOCATION; - cpp_force_token_locations (cpp_in, &builtins_loc); + cpp_force_token_locations (cpp_in, BUILTINS_LOCATION); cpp_define_builtins (cpp_in);