From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qv1-xf2d.google.com (mail-qv1-xf2d.google.com [IPv6:2607:f8b0:4864:20::f2d]) by sourceware.org (Postfix) with ESMTPS id B59F93857C66 for ; Thu, 15 Apr 2021 20:15:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B59F93857C66 Received: by mail-qv1-xf2d.google.com with SMTP id x27so12387070qvd.2 for ; Thu, 15 Apr 2021 13:15:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=JM59FTHOq0UENJeMd4GYTcUZRHTCfZrhSrtJi5WSFLY=; b=tWs5aXhfZ4p7YYxlSjTLs/jrohCSnfcsWX1h5Yc3ZxxdkD/37amLdvuni2iHwTqAyk XRUQCJtqwcsVRW4Mt3vEHIbEA2WnVjhgKN+8a9ZlyOVlLcEQXyGoZ7GczUfatAhxmoeu Q5sArcFjAc2d3hxFvL7ZzVarEJkHPWVDgLkJSHDUmPjVRtd6XzNwIDjlvoQMPbRXz0VU 4eRadArnQva0kzlXGSrROLS9iKov9/rlPqVZcH2XolYnZEmbfgn/BbMqU3jkLRiHl1tg SVmBWIokRqtpzzIwQGct0b3L9UdFbUaAVFCaPHhG4YrO2HPM69F2KPGxPY0W7n/D12sr afRw== X-Gm-Message-State: AOAM531Mi9Y1pbCuDqlLUy9GIBM1a/vtDF8sUtFq98b8onvoknAnUIbK CaUntk3W/6SkcoZ6h6w5xobSEfypWcQ= X-Google-Smtp-Source: ABdhPJymhMM3EOx0cRujMbWxsj0WF20L45kZKqKq5H+0ns3+g4+IwIF03Tz3yky3u6pu+x3VM1UtEQ== X-Received: by 2002:a0c:e14e:: with SMTP id c14mr4974231qvl.36.1618517737076; Thu, 15 Apr 2021 13:15:37 -0700 (PDT) Received: from [192.168.0.41] (71-218-23-248.hlrn.qwest.net. [71.218.23.248]) by smtp.gmail.com with ESMTPSA id w4sm2757869qkd.94.2021.04.15.13.15.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Apr 2021 13:15:36 -0700 (PDT) To: gcc-patches From: Martin Sebor Subject: [committed] add tests for Bug 89230 Message-ID: <314b6ce4-fa5e-7908-ad0d-ed55be3c337e@gmail.com> Date: Thu, 15 Apr 2021 14:15:35 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------72E3AE37BD0273D007EE60BB" Content-Language: en-US X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Apr 2021 20:15:39 -0000 This is a multi-part message in MIME format. --------------72E3AE37BD0273D007EE60BB Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit The false positives have disappeared thanks to g:520d5ad337eaa15860a5a964daf7ca46cf31c029. I have added the two test cases in the attached diff in r11-8202 after testing on aarch64, arm, powerpc64le, and x86_64, out of an abundance of caution. Martin --------------72E3AE37BD0273D007EE60BB Content-Type: text/x-patch; charset=UTF-8; name="gcc-89230.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-89230.diff" commit 2dbbbe893f75f587c48111ab4c97cf5e74fb91bb Author: Martin Sebor Date: Thu Apr 15 14:09:56 2021 -0600 PR middle-end/89230 - Bogus uninited usage warning with printf gcc/testsuite/ChangeLog: * gcc.dg/uninit-pr89230-1.c: New test. * gcc.dg/uninit-pr89230-2.c: Same. diff --git a/gcc/testsuite/gcc.dg/uninit-pr89230-1.c b/gcc/testsuite/gcc.dg/uninit-pr89230-1.c new file mode 100644 index 00000000000..1c07c4f6d78 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr89230-1.c @@ -0,0 +1,25 @@ +/* PR middle-end/89230 - Bogus uninited usage warning with printf + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +struct S { int i, j; }; + +/* attribute__ ((malloc)) */ struct S* f (void); + +int g (void) +{ + struct S *p = f (), *q; + + if (p->i || !(q = f ()) || p->j != q->i) + { + __builtin_printf ("%i", p->i); + + if (p->i) + return 1; + + if (!q) // { dg-bogus "\\\[-Wmaybe-uninitialized" } + return 2; + } + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/uninit-pr89230-2.c b/gcc/testsuite/gcc.dg/uninit-pr89230-2.c new file mode 100644 index 00000000000..473d2da5d3d --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr89230-2.c @@ -0,0 +1,54 @@ +/* PR middle-end/89230 - Bogus uninited usage warning with printf + { dg-do compile } + { dg-options "-O2 -Wall" } */ + +typedef __SIZE_TYPE__ size_t; + +extern void* memset (void*, int, size_t); +extern int printf (const char*, ...); +extern int rand (void); + +struct S +{ + int a; + int b; +}; + +struct H +{ + int c; + int d; +}; + +void getblk (void* blk) +{ + struct S* s = (struct S*) blk; + memset (blk, 0, 512); + s->a = rand () & 1; +} + +struct H* gethdr (void* blk) +{ + memset (blk, 0, 512); + return rand () & 1 ? (struct H*) blk : 0; +} + +int main (void) +{ + char blk[512], tmp[512]; + struct S *s = (struct S*) blk; + struct H *h; + + getblk (blk); + + if (s->a || !(h = gethdr (tmp)) || s->a != h->d) { + + printf ("%d\n", s->b); + if (s->a) + printf ("s->a = %d\n", s->a); + else if (!h) + printf ("!h\n"); + else + printf ("h->d = %d\n", h->d); + } +} --------------72E3AE37BD0273D007EE60BB--