From patchwork Thu Jan 2 09:23:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1217040 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-516571-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="JgDdBykb"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="q7sHjR/9"; 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 47pMz46kX2z9sPK for ; Thu, 2 Jan 2020 20:23:26 +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:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=qiA0ajiI5AwgAxmBFxvsI5l6ix9k8QQ8pD9VvIdEFOVjCmHHzb 6E5enRd7g2xyAHbzOTpAzv56hOGFJXu4dK05KbSo0Nh1bmP7ohIE1hINXnrrvpIx Z0BuVXJQaIvJ4BcVZ5IXqpSst0bbHSFaK0/dH0+MN8O/YRP0cOJQniJgc= 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:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=YtpRUDGegbR/Rd5hDDqq8UBZsos=; b=JgDdBykbHcRNcZkPpoO0 S0Yw+6Fw9a1RdcXDMkAMU8bHrTZFYn6Yq51A67Rvp7hPT5Vk1CzoYswfNNcYD8NT ck1RZd53EWzorrVodpNF79TcPF+IpD0BM9n78Uwmq28HcZgGZHXjFk5/HhZuAgT/ Z2D/OEmh0Fc808njOl7CFb4= Received: (qmail 2018 invoked by alias); 2 Jan 2020 09:23:16 -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 1927 invoked by uid 89); 2 Jan 2020 09:23:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=H*r:8.14.4 X-HELO: userp2120.oracle.com Received: from userp2120.oracle.com (HELO userp2120.oracle.com) (156.151.31.85) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 02 Jan 2020 09:23:13 +0000 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 0029JV5S088179; Thu, 2 Jan 2020 09:23:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : from : subject : message-id : date : mime-version : content-type; s=corp-2019-08-05; bh=UTxi12pcmoC6bYgtW+tJuX1RYjmL+CQY2pDjqHlON/8=; b=q7sHjR/9bi22iWGh33f+jQVjgUQsJFUjOCAW+IKuehIYOwGOe/jc2hw42l8SvaWtg8zy Mvr9n2Zn3HULp92bJQ/wKzHvX0FG+OclsGfYSbAt5f8P1CxF1KDN+KIo9eXLDf5Ow6V4 kQDUaoFK93ZPcrBI+HlTXN5pLCDK7i9az8iFdB/8VgClyShiwrOH3OYn6z4PwSdk5ZOn eqlj3n+HO37eKA1vO2xJhTHDYK3LfrGV11liPnI12y88SbbcSWoOvs6b70gm6vJdnGyC feXs+IK19uRDc9Xuf78Nc06qDWblPxECpz4UsuPOI7DqCVCZOIohEp2xJ65eet786Hk1 Dw== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 2x5ypqpaf5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Jan 2020 09:23:10 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 002937CV148742; Thu, 2 Jan 2020 09:23:10 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2x8bsstg34-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Jan 2020 09:23:10 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 0029N78C028617; Thu, 2 Jan 2020 09:23:07 GMT Received: from [192.168.1.4] (/79.26.35.95) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Jan 2020 01:23:06 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Improve build_new locations Message-ID: Date: Thu, 2 Jan 2020 10:23:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1 MIME-Version: 1.0 X-IsSubscribed: yes Hi, some rather straightforward bits for build_new / cp_parser_new_expression, almost a clean-up. It would be nice to do better for the diagnostic issued from build_new_1 too but having consistent locations for all the valid_array_size_p and invalid_array_size_error calls isn't trivial, I'd rather work on that at a later time. Tested x86_64-linux. Thanks, Paolo. /////////////////////////// /gcc/cp 2020-01-02 Paolo Carlini * init.c (build_new): Add location_t parameter and use it throughout. (build_raw_new_expr): Likewise. * parser.c (cp_parser_new_expression): Pass the combined_loc. * pt.c (tsubst_copy_and_build): Adjust call. * cp-tree.h: Update declarations. /libcc1 2020-01-02 Paolo Carlini * libcp1plugin.cc (plugin_build_new_expr): Update build_new call. /gcc/testsuite 2020-01-02 Paolo Carlini * g++.old-deja/g++.bugs/900208_03.C: Check locations too. * g++.old-deja/g++.bugs/900519_06.C: Likewise. Index: gcc/cp/cp-tree.h =================================================================== --- gcc/cp/cp-tree.h (revision 279768) +++ gcc/cp/cp-tree.h (working copy) @@ -6720,9 +6720,10 @@ extern tree throw_bad_array_new_length (void); extern bool type_has_new_extended_alignment (tree); extern unsigned malloc_alignment (void); extern tree build_new_constexpr_heap_type (tree, tree, tree); -extern tree build_new (vec **, tree, tree, - vec **, int, - tsubst_flags_t); +extern tree build_new (location_t, + vec **, tree, + tree, vec **, + int, tsubst_flags_t); extern tree get_temp_regvar (tree, tree); extern tree build_vec_init (tree, tree, tree, bool, int, tsubst_flags_t); Index: gcc/cp/init.c =================================================================== --- gcc/cp/init.c (revision 279768) +++ gcc/cp/init.c (working copy) @@ -2396,8 +2396,8 @@ decl_constant_value (tree decl) creates and returns a NEW_EXPR. */ static tree -build_raw_new_expr (vec *placement, tree type, tree nelts, - vec *init, int use_global_new) +build_raw_new_expr (location_t loc, vec *placement, tree type, + tree nelts, vec *init, int use_global_new) { tree init_list; tree new_expr; @@ -2413,9 +2413,9 @@ static tree else init_list = build_tree_list_vec (init); - new_expr = build4 (NEW_EXPR, build_pointer_type (type), - build_tree_list_vec (placement), type, nelts, - init_list); + new_expr = build4_loc (loc, NEW_EXPR, build_pointer_type (type), + build_tree_list_vec (placement), type, nelts, + init_list); NEW_EXPR_USE_GLOBAL (new_expr) = use_global_new; TREE_SIDE_EFFECTS (new_expr) = 1; @@ -3775,8 +3775,9 @@ build_new_1 (vec **placement, tree ty rather than just "new". This may change PLACEMENT and INIT. */ tree -build_new (vec **placement, tree type, tree nelts, - vec **init, int use_global_new, tsubst_flags_t complain) +build_new (location_t loc, vec **placement, tree type, + tree nelts, vec **init, int use_global_new, + tsubst_flags_t complain) { tree rval; vec *orig_placement = NULL; @@ -3826,7 +3827,7 @@ tree || (nelts && type_dependent_expression_p (nelts)) || (nelts && *init) || any_type_dependent_arguments_p (*init)) - return build_raw_new_expr (*placement, type, nelts, *init, + return build_raw_new_expr (loc, *placement, type, nelts, *init, use_global_new); orig_placement = make_tree_vector_copy (*placement); @@ -3852,10 +3853,11 @@ tree if (nelts) { + location_t nelts_loc = cp_expr_loc_or_loc (nelts, loc); if (!build_expr_type_conversion (WANT_INT | WANT_ENUM, nelts, false)) { if (complain & tf_error) - permerror (cp_expr_loc_or_input_loc (nelts), + permerror (nelts_loc, "size in array new must have integral type"); else return error_mark_node; @@ -3871,8 +3873,7 @@ tree less than zero. ... If the expression is a constant expression, the program is ill-fomed. */ if (TREE_CODE (cst_nelts) == INTEGER_CST - && !valid_array_size_p (cp_expr_loc_or_input_loc (nelts), - cst_nelts, NULL_TREE, + && !valid_array_size_p (nelts_loc, cst_nelts, NULL_TREE, complain & tf_error)) return error_mark_node; @@ -3886,7 +3887,7 @@ tree if (TYPE_REF_P (type)) { if (complain & tf_error) - error ("new cannot be applied to a reference type"); + error_at (loc, "new cannot be applied to a reference type"); else return error_mark_node; type = TREE_TYPE (type); @@ -3895,7 +3896,7 @@ tree if (TREE_CODE (type) == FUNCTION_TYPE) { if (complain & tf_error) - error ("new cannot be applied to a function type"); + error_at (loc, "new cannot be applied to a function type"); return error_mark_node; } @@ -3911,7 +3912,7 @@ tree if (processing_template_decl) { - tree ret = build_raw_new_expr (orig_placement, type, orig_nelts, + tree ret = build_raw_new_expr (loc, orig_placement, type, orig_nelts, orig_init, use_global_new); release_tree_vector (orig_placement); release_tree_vector (orig_init); @@ -3919,7 +3920,7 @@ tree } /* Wrap it in a NOP_EXPR so warn_if_unused_value doesn't complain. */ - rval = build1 (NOP_EXPR, TREE_TYPE (rval), rval); + rval = build1_loc (loc, NOP_EXPR, TREE_TYPE (rval), rval); TREE_NO_WARNING (rval) = 1; return rval; Index: gcc/cp/parser.c =================================================================== --- gcc/cp/parser.c (revision 279768) +++ gcc/cp/parser.c (working copy) @@ -8750,11 +8750,9 @@ cp_parser_new_expression (cp_parser* parser) at the end of the final token we consumed. */ location_t combined_loc = make_location (start_loc, start_loc, parser->lexer); - /* Create a representation of the new-expression. */ - ret = build_new (&placement, type, nelts, &initializer, global_scope_p, - tf_warning_or_error); - protected_set_expr_location (ret, combined_loc); + ret = build_new (combined_loc, &placement, type, nelts, &initializer, + global_scope_p, tf_warning_or_error); } if (placement != NULL) Index: gcc/cp/pt.c =================================================================== --- gcc/cp/pt.c (revision 279768) +++ gcc/cp/pt.c (working copy) @@ -19320,8 +19320,8 @@ tsubst_copy_and_build (tree t, tree op1 = tsubst (TREE_OPERAND (t, 1), args, complain, in_decl); tree op2 = RECUR (TREE_OPERAND (t, 2)); - ret = build_new (&placement_vec, op1, op2, &init_vec, - NEW_EXPR_USE_GLOBAL (t), + ret = build_new (input_location, &placement_vec, op1, op2, + &init_vec, NEW_EXPR_USE_GLOBAL (t), complain); if (placement_vec != NULL) Index: gcc/testsuite/g++.old-deja/g++.bugs/900208_03.C =================================================================== --- gcc/testsuite/g++.old-deja/g++.bugs/900208_03.C (revision 279767) +++ gcc/testsuite/g++.old-deja/g++.bugs/900208_03.C (working copy) @@ -13,7 +13,7 @@ typedef void (func_type) (); void global_function_0 () { - new func_type; // { dg-error "" } missed by both cfront 2.0 and g++ 1.36.1 + new func_type; // { dg-error "3:new cannot be applied to a function type" } missed by both cfront 2.0 and g++ 1.36.1 } int main () { return 0; } Index: gcc/testsuite/g++.old-deja/g++.bugs/900519_06.C =================================================================== --- gcc/testsuite/g++.old-deja/g++.bugs/900519_06.C (revision 279767) +++ gcc/testsuite/g++.old-deja/g++.bugs/900519_06.C (working copy) @@ -12,12 +12,12 @@ typedef int& int_ref; void test (int n) { - new int&; // { dg-error "" } missed - new int_ref; // { dg-error "" } missed + new int&; // { dg-error "3:new cannot be applied to a reference type" } missed + new int_ref; // { dg-error "3:new cannot be applied to a reference type" } missed new int&[n]; // { dg-error "" } missed - new int_ref[n]; // { dg-error "" } missed + new int_ref[n]; // { dg-error "3:new cannot be applied to a reference type" } missed new int&[3]; // { dg-error "" } missed - new int_ref[3]; // { dg-error "" } missed + new int_ref[3]; // { dg-error "3:new cannot be applied to a reference type" } missed } int main () { return 0; } Index: libcc1/libcp1plugin.cc =================================================================== --- libcc1/libcp1plugin.cc (revision 279768) +++ libcc1/libcp1plugin.cc (working copy) @@ -3258,8 +3258,8 @@ plugin_build_new_expr (cc1_plugin::connection *sel if (!template_dependent_p) processing_template_decl--; - tree result = build_new (&placement, type, nelts, &initializer, - global_scope_p, tf_error); + tree result = build_new (input_location, &placement, type, nelts, + &initializer, global_scope_p, tf_error); if (template_dependent_p) processing_template_decl--;