From patchwork Fri Apr 21 10:45:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 753273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3w8XTf5tW4z9rxl for ; Fri, 21 Apr 2017 20:46:14 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="AUb2lbXu"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=yDTCQcNrn6eshsVXcai+4MrvXS3jW+CSyREvZ+gSyQZm6mWV2yERJ ZRWm/rABD5gpUYzAn2zlOBQm4bx/c09rjrlKGEmK4cZYPuJto+1egVIZprZvh72p AU3Ixt4Z6XTkhYIaOtn+Yr8CKNaMz42YyLMN7QzEnRIwOeZzJ9Ii0Q= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=2U+X4PsEVcL8Tkx4/wiObf0t3SE=; b=AUb2lbXumg7eZKRCSzgY RcsbxkW7WZweopJFH9IdVkc/wboRImm8hDLJZ4/l2W5wjx+xYz+JAO2ipJtKYzTt g24gCA3oxoHTpgAglFn9K3QvBh6dpTWtYEP5fcbQ/6CpuENhXJCu6diTY8YvyQCP KcFbNgZWsxlHNmM2ilfYlGM= Received: (qmail 12583 invoked by alias); 21 Apr 2017 10:46:01 -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 12552 invoked by uid 89); 21 Apr 2017 10:46:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=killing, fg X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Apr 2017 10:45:59 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id EC0B9AC04 for ; Fri, 21 Apr 2017 10:45:58 +0000 (UTC) Date: Fri, 21 Apr 2017 12:45:58 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix PR2972 Message-ID: User-Agent: Alpine 2.20 (LSU 67 2015-01-07) MIME-Version: 1.0 This adds handling of uninitialized uses of members in constructors to the uninit warning machinery. Bootstrap and regtest on x86_64-unknown-linux-gnu in progress together with a bootstrap fix to the pass_manager. Richard. 2017-04-21 Richard Biener PR c++/2972 * tree-ssa-uninit.c (warn_uninitialized_vars): Handle some pointer-based references. * g++.dg/warn/Wuninitialized-10.C: New testcase. Index: gcc/tree-ssa-uninit.c =================================================================== --- gcc/tree-ssa-uninit.c (revision 247049) +++ gcc/tree-ssa-uninit.c (working copy) @@ -279,20 +279,22 @@ warn_uninitialized_vars (bool warn_possi ao_ref ref; ao_ref_init (&ref, rhs); - /* Do not warn if it can be initialized outside this function. */ + /* Do not warn if the base was marked so or this is a + hard register var. */ tree base = ao_ref_base (&ref); - if (!VAR_P (base) - || DECL_HARD_REGISTER (base) - || is_global_var (base) + if ((VAR_P (base) + && DECL_HARD_REGISTER (base)) || TREE_NO_WARNING (base)) continue; /* Do not warn if the access is fully outside of the variable. */ - if (ref.size != -1 + if (DECL_P (base) + && ref.size != -1 && ref.max_size == ref.size && (ref.offset + ref.size <= 0 || (ref.offset >= 0 + && DECL_SIZE (base) && TREE_CODE (DECL_SIZE (base)) == INTEGER_CST && compare_tree_int (DECL_SIZE (base), ref.offset) <= 0))) @@ -305,11 +307,12 @@ warn_uninitialized_vars (bool warn_possi && oracle_cnt > vdef_cnt * 2) limit = 32; check_defs_data data; + bool fentry_reached = false; data.found_may_defs = false; use = gimple_vuse (stmt); int res = walk_aliased_vdefs (&ref, use, check_defs, &data, NULL, - NULL, limit); + &fentry_reached, limit); if (res == -1) { oracle_cnt += limit; @@ -318,6 +321,16 @@ warn_uninitialized_vars (bool warn_possi oracle_cnt += res; if (data.found_may_defs) continue; + /* Do not warn if it can be initialized outside this function. + If we did not reach function entry then we found killing + clobbers on all paths to entry. */ + if (fentry_reached + /* ??? We'd like to use ref_may_alias_global_p but that + excludes global readonly memory and thus we get bougs + warnings from p = cond ? "a" : "b" for example. */ + && (!VAR_P (base) + || is_global_var (base))) + continue; /* We didn't find any may-defs so on all paths either reached function entry or a killing clobber. */ Index: gcc/testsuite/g++.dg/warn/Wuninitialized-10.C =================================================================== --- gcc/testsuite/g++.dg/warn/Wuninitialized-10.C (nonexistent) +++ gcc/testsuite/g++.dg/warn/Wuninitialized-10.C (working copy) @@ -0,0 +1,14 @@ +// { dg-do compile } +// { dg-options "-Wuninitialized" } + +struct A +{ + int f,g; + + A() + { + f = g; // { dg-warning "g. is used uninitialized" } + } +}; + +A a;