From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sourceware.org (Postfix) with ESMTPS id EDAC93858CDA for ; Fri, 22 Dec 2023 04:45:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EDAC93858CDA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=inria.fr Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=inria.fr ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EDAC93858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.134.164.104 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703220312; cv=none; b=xBbiEGreOomu5tp5S0QEN+JzgBQP2bVT5WUd32Nc0xHfs4gJhT3mnsNchnvTMdP19eYr4e27YCYVoZgvE7Pp9sqbPBlJR3d2EI+QhuF82XoyfRj5R0MGb9iaaXyT0ZqzqRQWyS1+Z3xEWK4ayDvEo7lHuxSERLW8vd21WWjxG7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703220312; c=relaxed/simple; bh=wO130FXVOse+G/JOpmMkJ7MT8Po37P0pjBJwv5HScfU=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=q/19vfIhZ1zcjeV7rR2TNa1j651q4ABiYpcSn4Nmv74itxEICW6otXJAYQ9QHnhBL4B9zQlsjCwpGLe+bl0QxxiQpQGQmGtD4LIaBqZ+l3rmv81lvJi/hP266+UAuVuPJO4aai7X6Oa3G7ZSCDJwVIq9+PzmQvlLwTG/7N7riaA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=date:from:reply-to:to:cc:subject:in-reply-to:message-id: references:mime-version:content-transfer-encoding; bh=BP3fBl9hiF3NbXfp72pl2UstOYnoyrX1qBMoHQUO44o=; b=CNKnE9jwgiaydniNH727n+nvMZGTStIvRhq6JjoO7fUhOaylWFEYzSm+ kc6PG8ULfqwl36ZLAoPMl14rhBWMdw0B5o8eT+tUSjbuf7Fw9VD2SBZmS HzJCciu2i6abqGjtC10dxPevKszyvGxJ1vMBk390vEf2GuGHMc74ny8v8 8=; Authentication-Results: mail3-relais-sop.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=marc.glisse@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.04,294,1695679200"; d="scan'208";a="75140359" Received: from 71.79.12.109.rev.sfr.net (HELO hippo) ([109.12.79.71]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 05:45:08 +0100 Date: Fri, 22 Dec 2023 05:45:07 +0100 (CET) From: Marc Glisse Reply-To: gcc@gcc.gnu.org To: David Malcolm cc: Eric Batchelor , gcc@gcc.gnu.org Subject: Re: Expected warning maybe-uninitialized does not appear using g++13.2.0? In-Reply-To: <8c605c042acb7ea3de38fdb7f953969a1560fd19.camel@redhat.com> Message-ID: References: <31bdc2a5-3556-4ccb-8a91-723ccd71652c@bookmanager.com> <8c605c042acb7ea3de38fdb7f953969a1560fd19.camel@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 21 Dec 2023, David Malcolm via Gcc wrote: > On Wed, 2023-12-20 at 11:16 -0800, Eric Batchelor wrote: >> Hello, I unintentionally stumbled upon some strange behaviour that >> occurred due to a typo. >> I reproduced the behaviour where an object (std::string in my case) >> can >> be passed to a function by reference, uninitialized, WITHOUT a >> compiler >> warning. >> Changing the code to pass the object by value DOES emit the warning. >> I don't think the compiled code is incorrect, it segfaults presumably >> due to uninitialized members. >> I understand there may seldom be a reason to use uninitialized >> objects, >> so "don't do that," but as I said this was unintentional and it seems >> that it should have generated a warning, which have saved some >> head-scratching. >> >> Code to reproduce: >> >> #include >> std::string f(std::string &s) { >>    s.append("x"); >>    return s; >> } >> int main() { >>    std::string a = f(a); >> } >> >> Compile and run (no warning): >> >> $ g++ -o uninit_obj uninit_obj.cpp -std=c++23 -Wall -Wpedantic - >> Wextra >> && ./uninit_obj >> Segmentation fault (core dumped) >> >> No difference whether using -O0 (or 1 2 3) > > As I understand it, -Wmaybe-uninitialized is purely intraprocedural > i.e. it works within each individual function, without considering the > interactions *between* functions. If you compile #include static std::string f(std::string &s) { s.append("x"); return s; } void g() { std::string a = f(a); } with -O3, by the time we get to the uninit pass, function g starts with void g () { size_type __dnew; struct string a; [...] [local count: 1073741824]: _26 = a._M_string_length; if (_26 == 4611686018427387903) which should not require any interprocedural logic. -- Marc Glisse