From patchwork Tue Nov 12 08:57:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1193373 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-513047-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="cKmED/GP"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="OohZXf5d"; 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 47C1qM4bmjz9s4Y for ; Tue, 12 Nov 2019 19:58:06 +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=esDCsUnPhRnMOPIwNz41WyNmLxOFseTEZefHrB0YrTvYEv3djC pTCs70IhuPT1+AjlqBqucfC2E9WtVvxL2VKkLXLEfJ8r8ftVSDHgzB+QjvdGObFG NbE1d1s5ot5yiJUiTq15QaLwBV579OBej3t4ZX/UB7agOktqHNeov1XIM= 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=kI8LhJ0SIxhJazbPvMmb47XjNfQ=; b=cKmED/GPFU27jVISzhRZ MLLU45uCBjrFp/ekcVPxa2U2xrh8DKjcGPjrW3Z0OdIGeQGrwiEFV8nMLn32PfEp KrINRxPu2DJtRc3La7y3+yde7Z9/JJ3DqY9Lr+7IsvLY2Ihj+NbqiDFgIeVkC6Vn N6yf06bRY7gSBX9pKmN3U5c= Received: (qmail 114197 invoked by alias); 12 Nov 2019 08:57:58 -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 114182 invoked by uid 89); 12 Nov 2019 08:57:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 12 Nov 2019 08:57:55 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id xAC8sDn5148394; Tue, 12 Nov 2019 08:57:53 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=1qFFymas+d/6Q4a7FjLD8vJ6ag/gRmt16/y5mfWslzY=; b=OohZXf5dq+fN8yslq60OnXtb6N14jYq8jaE2rSZpDCrUZT+KeqbqrVwb8AzYRfzgfBqz m3eCRHsWNlr1nuVEINddOOTlw1hEdJ8Zv1H+Ni4+4sX2HTlc/fGfyn6qICYWE84cDcsM dIvoGXds/EufB910kc8hIn8sdlUAAk2THBeQ4MB9fY1a5xCmDMW9HtC0Klpr/CtvC2yX 785D/Dl3BMCtkL+0imPlXNDBZXH+pckKa0wVIAY8nXbCGai4UYElaisTNF9v7mwMxGH1 Ck3QtIyM7GvpNeBGKsMmQ77lTSmwjP+Hs4yetOIYcW/QZi//mkWa7YqgGFPTnnbiynai PQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2w5mvtkabw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Nov 2019 08:57:53 +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 xAC8s5ua162211; Tue, 12 Nov 2019 08:57:53 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2w67knbkg5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 12 Nov 2019 08:57:52 +0000 Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id xAC8vpRK019342; Tue, 12 Nov 2019 08:57:51 GMT Received: from [192.168.1.4] (/79.19.225.152) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 12 Nov 2019 00:57:50 -0800 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] Improve cp_truthvalue_conversion locations and more Message-ID: <747cd7ff-14fd-90a3-3ace-de9777ded0a0@oracle.com> Date: Tue, 12 Nov 2019 09:57:48 +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, a few days ago I noticed that we weren't doing the right thing location-wise for the first test of g++.dg/warn/Waddress-1.C: it seems clear that the ultimate reason is that we didn't pass an accurate location to build_binary_op called from cp_truthvalue_conversion. When I fixed that, I noticed that for testcases like warn/Walways-true-3.C we were issuing many duplicate warnings and I traced that to ocp_convert not using its tsubst_flags_t argument - which can come from cp_convert_and_check as tf_none - when calling cp_truthvalue_conversion. Thus I also added a tusbst_flags_t parameter to the latter and everything looks finally good for these testcases. Tested x86_64-linux. Thanks, Paolo. //////////////////////// /cp 2019-11-12 Paolo Carlini * typeck.c (cp_truthvalue_conversion): Add tsubst_flags_t parameter and use it in calls; also pass the location_t of the expression to cp_build_binary_op and c_common_truthvalue_conversion. * rtti.c (build_dynamic_cast_1): Adjust call. * cvt.c (ocp_convert): Likewise. * cp-gimplify.c (cp_fold): Likewise. * cp-tree.h (cp_truthvalue_conversion): Update declaration. /testsuite 2019-11-12 Paolo Carlini * g++.dg/warn/Walways-true-1.C: Check locations too. * g++.dg/warn/Walways-true-2.C: Likewise. * g++.dg/warn/Walways-true-3.C: Likewise. * g++.dg/warn/Waddress-1.C: Check additional location. Index: cp/cp-gimplify.c =================================================================== --- cp/cp-gimplify.c (revision 278059) +++ cp/cp-gimplify.c (working copy) @@ -2573,9 +2573,9 @@ cp_fold (tree x) { warning_sentinel s (warn_int_in_bool_context); if (!VOID_TYPE_P (TREE_TYPE (op1))) - op1 = cp_truthvalue_conversion (op1); + op1 = cp_truthvalue_conversion (op1, tf_warning_or_error); if (!VOID_TYPE_P (TREE_TYPE (op2))) - op2 = cp_truthvalue_conversion (op2); + op2 = cp_truthvalue_conversion (op2, tf_warning_or_error); } else if (VOID_TYPE_P (TREE_TYPE (x))) { Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 278059) +++ cp/cp-tree.h (working copy) @@ -7445,7 +7445,7 @@ enum compare_bounds_t { bounds_none, bounds_either extern bool cxx_mark_addressable (tree, bool = false); extern int string_conv_p (const_tree, const_tree, int); -extern tree cp_truthvalue_conversion (tree); +extern tree cp_truthvalue_conversion (tree, tsubst_flags_t); extern tree contextual_conv_bool (tree, tsubst_flags_t); extern tree condition_conversion (tree); extern tree require_complete_type (tree); Index: cp/cvt.c =================================================================== --- cp/cvt.c (revision 278059) +++ cp/cvt.c (working copy) @@ -841,13 +841,13 @@ ocp_convert (tree type, tree expr, int convtype, i if (SCOPED_ENUM_P (intype) && (convtype & CONV_STATIC)) e = build_nop (ENUM_UNDERLYING_TYPE (intype), e); if (complain & tf_warning) - return cp_truthvalue_conversion (e); + return cp_truthvalue_conversion (e, complain); else { /* Prevent bogus -Wint-in-bool-context warnings coming from c_common_truthvalue_conversion down the line. */ warning_sentinel w (warn_int_in_bool_context); - return cp_truthvalue_conversion (e); + return cp_truthvalue_conversion (e, complain); } } Index: cp/rtti.c =================================================================== --- cp/rtti.c (revision 278059) +++ cp/rtti.c (working copy) @@ -782,7 +782,7 @@ build_dynamic_cast_1 (tree type, tree expr, tsubst tree neq; result = save_expr (result); - neq = cp_truthvalue_conversion (result); + neq = cp_truthvalue_conversion (result, complain); return cp_convert (type, build3 (COND_EXPR, TREE_TYPE (result), neq, result, bad), complain); Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 278059) +++ cp/typeck.c (working copy) @@ -5975,15 +5975,16 @@ cp_build_addressof (location_t loc, tree arg, tsub -1. */ tree -cp_truthvalue_conversion (tree expr) +cp_truthvalue_conversion (tree expr, tsubst_flags_t complain) { tree type = TREE_TYPE (expr); + location_t loc = cp_expr_loc_or_input_loc (expr); if (TYPE_PTR_OR_PTRMEM_P (type) /* Avoid ICE on invalid use of non-static member function. */ || TREE_CODE (expr) == FUNCTION_DECL) - return build_binary_op (input_location, NE_EXPR, expr, nullptr_node, true); + return cp_build_binary_op (loc, NE_EXPR, expr, nullptr_node, complain); else - return c_common_truthvalue_conversion (input_location, expr); + return c_common_truthvalue_conversion (loc, expr); } /* Returns EXPR contextually converted to bool. */ Index: testsuite/g++.dg/warn/Waddress-1.C =================================================================== --- testsuite/g++.dg/warn/Waddress-1.C (revision 278070) +++ testsuite/g++.dg/warn/Waddress-1.C (working copy) @@ -13,7 +13,7 @@ S s; T t; double d; -void f() { if (z) z(); } // { dg-warning "address" } +void f() { if (z) z(); } // { dg-warning "17:address" } void gl() { if (z != 0) z(); } // { dg-warning "19:address" } void hl() { if (z != (ptrf)0) z(); } // { dg-warning "19:address" } Index: testsuite/g++.dg/warn/Walways-true-1.C =================================================================== --- testsuite/g++.dg/warn/Walways-true-1.C (revision 278070) +++ testsuite/g++.dg/warn/Walways-true-1.C (working copy) @@ -12,46 +12,46 @@ void bar (int a) { lab: - if (foo) // { dg-warning "always evaluate as|never be NULL" "correct warning" } + if (foo) // { dg-warning "7:the address of .int foo\\(int\\). will never be NULL" "correct warning" } foo (0); if (foo (1)) ; - if (&i) // { dg-warning "always evaluate as|never be NULL" "correct warning" } + if (&i) // { dg-warning "7:the address of .i. will never be NULL" "correct warning" } foo (2); if (i) foo (3); - if (&a) // { dg-warning "always evaluate as|never be NULL" "correct warning" } + if (&a) // { dg-warning "7:the address of .a. will never be NULL" "correct warning" } foo (4); if (a) foo (5); - if (&&lab) // { dg-warning "always evaluate as|never be NULL" "correct warning" } + if (&&lab) // { dg-warning "7:the address of .lab. will never be NULL" "correct warning" } foo (6); - if (foo == 0) // { dg-warning "never be NULL" "correct warning" } + if (foo == 0) // { dg-warning "11:the address of .int foo\\(int\\). will never be NULL" "correct warning" } foo (7); if (foo (1) == 0) foo (8); - if (&i == 0) // { dg-warning "never be NULL" "correct warning" } + if (&i == 0) // { dg-warning "10:the address of .i. will never be NULL" "correct warning" } foo (9); if (i == 0) foo (10); - if (&a == 0) // { dg-warning "never be NULL" "correct warning" } + if (&a == 0) // { dg-warning "10:the address of .a. will never be NULL" "correct warning" } foo (11); if (a == 0) foo (12); - if (&&lab == 0) // { dg-warning "never be NULL" "correct warning" } + if (&&lab == 0) // { dg-warning "13:the address of .lab. will never be NULL" "correct warning" } foo (13); - if (0 == foo) // { dg-warning "never be NULL" "correct warning" } + if (0 == foo) // { dg-warning "9:the address of .int foo\\(int\\). will never be NULL" "correct warning" } foo (14); if (0 == foo (1)) foo (15); - if (0 == &i) // { dg-warning "never be NULL" "correct warning" } + if (0 == &i) // { dg-warning "9:the address of .i. will never be NULL" "correct warning" } foo (16); if (0 == i) foo (17); - if (0 == &a) // { dg-warning "never be NULL" "correct warning" } + if (0 == &a) // { dg-warning "9:the address of .a. will never be NULL" "correct warning" } foo (18); if (0 == a) foo (19); - if (0 == &&lab) // { dg-warning "never be NULL" "correct warning" } + if (0 == &&lab) // { dg-warning "9:the address of .lab. will never be NULL" "correct warning" } foo (20); } Index: testsuite/g++.dg/warn/Walways-true-2.C =================================================================== --- testsuite/g++.dg/warn/Walways-true-2.C (revision 278070) +++ testsuite/g++.dg/warn/Walways-true-2.C (working copy) @@ -23,11 +23,11 @@ bar (int a) foo (2); if (i) foo (3); - if (&a) // { dg-warning "always evaluate as|never be NULL" "correct warning" } + if (&a) // { dg-warning "7:the address of .a. will never be NULL" "correct warning" } foo (4); if (a) foo (5); - if (&&lab) // { dg-warning "always evaluate as|never be NULL" "correct warning" } + if (&&lab) // { dg-warning "7:the address of .lab. will never be NULL" "correct warning" } foo (6); if (foo == 0) foo (7); @@ -37,11 +37,11 @@ bar (int a) foo (9); if (i == 0) foo (10); - if (&a == 0) // { dg-warning "never be NULL" "correct warning" } + if (&a == 0) // { dg-warning "10:the address of .a. will never be NULL" "correct warning" } foo (11); if (a == 0) foo (12); - if (&&lab == 0) // { dg-warning "never be NULL" "correct warning" } + if (&&lab == 0) // { dg-warning "13:the address of .lab. will never be NULL" "correct warning" } foo (13); if (0 == foo) foo (14); @@ -51,10 +51,10 @@ bar (int a) foo (16); if (0 == i) foo (17); - if (0 == &a) // { dg-warning "never be NULL" "correct warning" } + if (0 == &a) // { dg-warning "9:the address of .a. will never be NULL" "correct warning" } foo (18); if (0 == a) foo (19); - if (0 == &&lab) // { dg-warning "never be NULL" "correct warning" } + if (0 == &&lab) // { dg-warning "9:the address of .lab. will never be NULL" "correct warning" } foo (20); } Index: testsuite/g++.dg/warn/Walways-true-3.C =================================================================== --- testsuite/g++.dg/warn/Walways-true-3.C (revision 278070) +++ testsuite/g++.dg/warn/Walways-true-3.C (working copy) @@ -11,28 +11,28 @@ bar (int &a) { int &b = a; - if ((int *)&a) // { dg-warning "address of" } + if ((int *)&a) // { dg-warning "7:the compiler can assume that the address of" } foo (); - if (&b) // { dg-warning "address of" } + if (&b) // { dg-warning "7:the compiler can assume that the address of" } foo (); - if (!&c) // { dg-warning "address of" } + if (!&c) // { dg-warning "8:the compiler can assume that the address of" } foo (); - if (!&(int &)(int &)a) // { dg-warning "address of" } + if (!&(int &)(int &)a) // { dg-warning "8:the compiler can assume that the address of" } foo (); - if (&a == 0) // { dg-warning "never be NULL" } + if (&a == 0) // { dg-warning "10:the compiler can assume that the address of" } foo (); - if (&b != 0) // { dg-warning "never be NULL" } + if (&b != 0) // { dg-warning "10:the compiler can assume that the address of" } foo (); - if (0 == &(int &)(int &)c) // { dg-warning "never be NULL" } + if (0 == &(int &)(int &)c) // { dg-warning "9:the compiler can assume that the address of" } foo (); - if (&a != (int *)0) // { dg-warning "never be NULL" } + if (&a != (int *)0) // { dg-warning "10:the compiler can assume that the address of" } foo (); } @@ -40,7 +40,7 @@ bool bar_1 (int &a) { if (d == 5) - return &a; // { dg-warning "address of" } + return &a; // { dg-warning "12:the compiler can assume that the address of" } else - return !&(int &)(int &)a; // { dg-warning "address of" } + return !&(int &)(int &)a; // { dg-warning "13:the compiler can assume that the address of" } }