From patchwork Wed Nov 15 14:31:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 838196 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-466865-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="VnI+lSFe"; 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 3ycRf64Wvxz9s7v for ; Thu, 16 Nov 2017 01:31:56 +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:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=tagIeq7wUu8HHGHjepiRQi8qyGZ+YQ7ti9SnJNM0Ean7MxRrDp90B zb6Fc1/10bPt/xMKOLMH9SmAJEUD/uU+hDgSwjrtPwYxw6uVkWA44X191ZcIUkrR 57gWBJwdt7Pc03cxCGmV8xpIX79Xay6CttVbcbzEYoTmfu8IXQV5wg= 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=3ShjPthy6ja7tiMAvmEcwTrTXtw=; b=VnI+lSFew8kurz/6kBF0 1RzFchoZJ71fOccAZZm/+IvzIokZ1GMHq18z9ywsmPEhqmtw1SkSBW6gKxX10vvB zKpAakejyapkG1tWiGgOo+HQRk6hn2rZgpkk0ot95R/Xkb1Z3LQPrk3pvsqwEYsV Aj6+OJjhlIFhjdJIM++8wCw= Received: (qmail 41065 invoked by alias); 15 Nov 2017 14:31:45 -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 41052 invoked by uid 89); 15 Nov 2017 14:31:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KB_WAM_FROM_NAME_SINGLEWORD, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=spite X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Nov 2017 14:31:42 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BDCBEC052423 for ; Wed, 15 Nov 2017 14:31:41 +0000 (UTC) Received: from localhost (unknown [10.33.36.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F32B5D9CB for ; Wed, 15 Nov 2017 14:31:41 +0000 (UTC) Date: Wed, 15 Nov 2017 14:31:40 +0000 From: Jonathan Wakely To: gcc-patches@gcc.gnu.org Subject: [PATCH] Improve -Wmaybe-uninitialized documentation Message-ID: <20171115143140.GA4279@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.1 (2017-09-22) The docs for -Wmaybe-uninitialized have some issues: - That first sentence is looooooong. - Apparently some C++ programmers think "automatic variable" means one declared with C++11 `auto`, rather than simply a local variable. - The sentence about only warning when optimizing is stuck in between two chunks talking about longjmp, which could be inferred to mean only the setjmp/longjmp part of the warning depends on optimization. This attempts to make it easier to parse and understand. OK for trunk? commit a923e297acfd7c0ca3d3820463450f38230ab4ea Author: Jonathan Wakely Date: Wed Nov 15 14:25:09 2017 +0000 Improve -Wmaybe-uninitialized documentation * doc/invoke.texi (-Wmaybe-uninitialized): Rephrase more accurately. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 44273284483..fac4122fe3e 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -4970,14 +4970,17 @@ void store (int *i) @item -Wmaybe-uninitialized @opindex Wmaybe-uninitialized @opindex Wno-maybe-uninitialized -For an automatic variable, if there exists a path from the function -entry to a use of the variable that is initialized, but there exist -some other paths for which the variable is not initialized, the compiler -emits a warning if it cannot prove the uninitialized paths are not -executed at run time. These warnings are made optional because GCC is -not smart enough to see all the reasons why the code might be correct -in spite of appearing to have an error. Here is one example of how -this can happen: +Warn if there exists a path from entry to a function to a use of an automatic +(i.e.@ local) variable, for which the variable is not initialized, and the +compiler cannot prove that the uninitialized path will not be executed at run +time. + +These warnings are only possible in optimizing compilation, because otherwise +GCC does not keep track of the state of variables. + +These warnings are optional because GCC is not smart enough to see all the +reasons why the code might be correct in spite of appearing to have an error. +Here is one example of how this can happen: @smallexample @group @@ -5003,19 +5006,15 @@ warning, you need to provide a default case with assert(0) or similar code. @cindex @code{longjmp} warnings -This option also warns when a non-volatile automatic variable might be -changed by a call to @code{longjmp}. These warnings as well are possible -only in optimizing compilation. - -The compiler sees only the calls to @code{setjmp}. It cannot know -where @code{longjmp} will be called; in fact, a signal handler could -call it at any point in the code. As a result, you may get a warning -even when there is in fact no problem because @code{longjmp} cannot -in fact be called at the place that would cause a problem. +This option also warns when a non-volatile automatic variable might be changed +by a call to @code{longjmp}. The compiler sees only the calls to +@code{setjmp}. It cannot know where @code{longjmp} will be called; in fact, a +signal handler could call it at any point in the code. As a result, you may +get a warning even when there is in fact no problem because @code{longjmp} +cannot in fact be called at the place that would cause a problem. Some spurious warnings can be avoided if you declare all the functions -you use that never return as @code{noreturn}. @xref{Function -Attributes}. +you use that never return as @code{noreturn}. @xref{Function Attributes}. This warning is enabled by @option{-Wall} or @option{-Wextra}.