From patchwork Wed Oct 25 20:49:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 830371 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-465123-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="ajEtCQFh"; 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 3yMj292KPHz9t4V for ; Thu, 26 Oct 2017 07:50:07 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=RtgeYzRGW0Cr8GkvDVbWIMXJENwsUTKSTBDyAbUi9H1Di5nq4M iDSJjWKAVAorD0TnXtYSq6p3TNWfzqRmLSbafdyId2GB2WvCPllJu9mZbGj+sFfs tbspsMzOl9SqjrxzQsVnByxT4G2AaVfB7mSFqwDrJQTTic/8gR93jnpgE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=EiPZ/iuQbAFZZBUC+tnha4aL1aQ=; b=ajEtCQFhlBPvMLrT2LDL xsJ5bzN33iZ+JIo1jaCGeplzVA17WBKPDgYsFzhyjQrTIraYOsHSEpQxs4fQx1ZJ zbco8DxXzIoWs965cr+/6eICKDanBVud6xFaEQwDPPeSF3pIEHT6nJUog6If4uEH LwPuoZmc2nDsKSEL/ktEf+s= Received: (qmail 126475 invoked by alias); 25 Oct 2017 20:50:00 -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 126285 invoked by uid 89); 25 Oct 2017 20:49:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=254060, Say X-HELO: mail-yw0-f179.google.com Received: from mail-yw0-f179.google.com (HELO mail-yw0-f179.google.com) (209.85.161.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 25 Oct 2017 20:49:57 +0000 Received: by mail-yw0-f179.google.com with SMTP id l32so1155300ywh.13 for ; Wed, 25 Oct 2017 13:49:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=O5t1IaGyimCADXvtXIDPdsbnYQDcITGARzgp1vRSy3c=; b=g1eu0aZHUdgZg5VzsHqi/FLASpJcWzvM0Z3ASMurxEFQcZPfXhWOEtjSbnMiymPAxs 91iujPSblg3Ch6P/eLmSJijpluKKScXggQi1l9q27nyd04KQOU3rDd61YsaBMtl3m5WN 2dCcPhZHwTWkqy1WKKTcjVxyPqDsu4QqnTu8T3ERs60J6ut+rnH32kb6aubNLgHpH093 ZeqtzwouqwgQA7On439rWEEPI316mtK55LVkAXbQJbYoQJ1lRPK2WG2lhH30tQSPbawK 6Z8xNm/aBA1pBBLAyEiFEvoc5oe/83AteOFsvIv9ZagNyDldv3uAugmzfmhCJrY4N5T1 1soA== X-Gm-Message-State: AMCzsaXnK4JDhmMGFI3pLhnlwlbmwXfxPGASnCMygrbvzDHBbQngZXfy tEtogHA200LyIY4VukpDnCc= X-Google-Smtp-Source: ABhQp+QqzCfGz+v5BZem1zgtJPnItDg/SyvMO5TlagUdpBTG+/J0Vuik6cyDvQKKqmKOUsV1ax10aw== X-Received: by 10.129.162.147 with SMTP id z141mr13748824ywg.331.1508964595957; Wed, 25 Oct 2017 13:49:55 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a1:1102:495f:7267:5ff:a250? ([2620:10d:c091:180::1:8548]) by smtp.googlemail.com with ESMTPSA id g2sm1657054ywa.94.2017.10.25.13.49.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Oct 2017 13:49:54 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] Label checking cleanups Message-ID: Date: Wed, 25 Oct 2017 16:49:52 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In killing IDENTIFIER_LABEL_VALUE, I made some cleanups deduping code and using modern C++ idioms. applying to trunk in advance of the Label killer. nathan 2017-10-25 Nathan Sidwell * decl.c (identifier_goto): Reduce duplication. (check_previous_goto_1): Likewise. (check_goto): Move var decls to initialization. (check_omp_return, define_label_1, define_label): Likewise. Index: decl.c =================================================================== --- decl.c (revision 254060) +++ decl.c (working copy) @@ -3091,8 +3091,9 @@ identify_goto (tree decl, location_t loc diagnostic_t diag_kind) { bool complained - = (decl ? emit_diagnostic (diag_kind, loc, 0, "jump to label %qD", decl) - : emit_diagnostic (diag_kind, loc, 0, "jump to case label")); + = emit_diagnostic (diag_kind, loc, 0, + decl ? "jump to label %qD" : "jump to case label", + decl); if (complained && locus) inform (*locus, " from here"); return complained; @@ -3147,68 +3148,62 @@ check_previous_goto_1 (tree decl, cp_bin " crosses initialization of %q#D", new_decls); else inform (DECL_SOURCE_LOCATION (new_decls), - " enters scope of %q#D which has " + " enters scope of %q#D, which has " "non-trivial destructor", new_decls); } } if (b == level) break; - if ((b->kind == sk_try || b->kind == sk_catch) && !saw_eh) + + const char *inf = NULL; + location_t loc = input_location; + switch (b->kind) { - if (identified < 2) - { - complained = identify_goto (decl, input_location, locus, - DK_ERROR); - identified = 2; - } - if (complained) - { - if (b->kind == sk_try) - inform (input_location, " enters try block"); - else - inform (input_location, " enters catch block"); - } + case sk_try: + if (!saw_eh) + inf = "enters try block"; saw_eh = true; - } - if (b->kind == sk_omp && !saw_omp) - { - if (identified < 2) - { - complained = identify_goto (decl, input_location, locus, - DK_ERROR); - identified = 2; - } - if (complained) - inform (input_location, " enters OpenMP structured block"); + break; + + case sk_catch: + if (!saw_eh) + inf = "enters catch block"; + saw_eh = true; + break; + + case sk_omp: + if (!saw_omp) + inf = "enters OpenMP structured block"; saw_omp = true; - } - if (b->kind == sk_transaction && !saw_tm) - { - if (identified < 2) + break; + + case sk_transaction: + if (!saw_tm) + inf = "enters synchronized or atomic statement"; + saw_tm = true; + break; + + case sk_block: + if (!saw_cxif && level_for_constexpr_if (b->level_chain)) { - complained = identify_goto (decl, input_location, locus, - DK_ERROR); - identified = 2; + inf = "enters constexpr if statement"; + loc = EXPR_LOCATION (b->level_chain->this_entity); + saw_cxif = true; } - if (complained) - inform (input_location, - " enters synchronized or atomic statement"); - saw_tm = true; + break; + + default: + break; } - if (!saw_cxif && b->kind == sk_block - && level_for_constexpr_if (b->level_chain)) + + if (inf) { if (identified < 2) - { - complained = identify_goto (decl, input_location, locus, - DK_ERROR); - identified = 2; - } + complained = identify_goto (decl, input_location, locus, DK_ERROR); + identified = 2; if (complained) - inform (EXPR_LOCATION (b->level_chain->this_entity), - " enters constexpr if statement"); - saw_cxif = true; + inform (loc, " %s", inf); } } @@ -3236,10 +3231,6 @@ void check_goto (tree decl) { struct named_label_entry *ent, dummy; - bool saw_catch = false, complained = false; - int identified = 0; - tree bad; - unsigned ix; /* We can't know where a computed goto is jumping. So we assume that it's OK. */ @@ -3277,6 +3268,11 @@ check_goto (tree decl) return; } + bool saw_catch = false, complained = false; + int identified = 0; + tree bad; + unsigned ix; + if (ent->in_try_scope || ent->in_catch_scope || ent->in_transaction_scope || ent->in_constexpr_if || ent->in_omp_scope || !vec_safe_is_empty (ent->bad_decls)) @@ -3337,27 +3333,24 @@ check_goto (tree decl) inform (input_location, " enters OpenMP structured block"); } else if (flag_openmp) - { - cp_binding_level *b; - for (b = current_binding_level; b ; b = b->level_chain) - { - if (b == ent->binding_level) + for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain) + { + if (b == ent->binding_level) + break; + if (b->kind == sk_omp) + { + if (identified < 2) + { + complained = identify_goto (decl, + DECL_SOURCE_LOCATION (decl), + &input_location, DK_ERROR); + identified = 2; + } + if (complained) + inform (input_location, " exits OpenMP structured block"); break; - if (b->kind == sk_omp) - { - if (identified < 2) - { - complained = identify_goto (decl, - DECL_SOURCE_LOCATION (decl), - &input_location, DK_ERROR); - identified = 2; - } - if (complained) - inform (input_location, " exits OpenMP structured block"); - break; - } - } - } + } + } } /* Check that a return is ok wrt OpenMP structured blocks. @@ -3366,8 +3359,7 @@ check_goto (tree decl) bool check_omp_return (void) { - cp_binding_level *b; - for (b = current_binding_level; b ; b = b->level_chain) + for (cp_binding_level *b = current_binding_level; b ; b = b->level_chain) if (b->kind == sk_omp) { error ("invalid exit from OpenMP structured block"); @@ -3411,8 +3403,6 @@ define_label_1 (location_t location, tre } else { - struct named_label_use_entry *use; - /* Mark label as having been defined. */ DECL_INITIAL (decl) = error_mark_node; /* Say where in the source. */ @@ -3421,7 +3411,7 @@ define_label_1 (location_t location, tre ent->binding_level = current_binding_level; ent->names_in_scope = current_binding_level->names; - for (use = ent->uses; use ; use = use->next) + for (named_label_use_entry *use = ent->uses; use; use = use->next) check_previous_goto (decl, use); ent->uses = NULL; } @@ -3434,9 +3424,8 @@ define_label_1 (location_t location, tre tree define_label (location_t location, tree name) { - tree ret; bool running = timevar_cond_start (TV_NAME_LOOKUP); - ret = define_label_1 (location, name); + tree ret = define_label_1 (location, name); timevar_cond_stop (TV_NAME_LOOKUP, running); return ret; }