From patchwork Thu Mar 30 08:05:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 67112 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E27FA3858000 for ; Thu, 30 Mar 2023 08:06:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E27FA3858000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680163565; bh=+4TwIdDzzHVssEwuyn0E6uR2oXHeziLPUUDF/F5JqFk=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=yJNANTkpt7TOwMrSYjCDp+Dotnw7PD3L8HJ7d3Dc0gaurt1dMts+1jei/7agwvYA2 CjRRb6qTwv/zpzRc2Dip3Qqn6nCIfXFWs1v0Qls2gCZ44CbvaOir52izmOLr4s2XrY I/0gwB9+Sn6C1kV9rjxYaVPxZoJ7DObJGd1KZfhU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9F5363858CDA for ; Thu, 30 Mar 2023 08:05:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9F5363858CDA Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-196-IzJn_lqWOuaY404YMiMllQ-1; Thu, 30 Mar 2023 04:05:36 -0400 X-MC-Unique: IzJn_lqWOuaY404YMiMllQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 94D48811E7C for ; Thu, 30 Mar 2023 08:05:36 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 50FFE492C3E; Thu, 30 Mar 2023 08:05:36 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 32U85XAW1701723 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 30 Mar 2023 10:05:34 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32U85XGj1701722; Thu, 30 Mar 2023 10:05:33 +0200 Date: Thu, 30 Mar 2023 10:05:32 +0200 To: David Malcolm Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] testsuite, analyzer: Fix up pipe-glibc.c testcase [PR107396] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The gcc.dg/analyzer/pipe-glibc.c test FAILs when using recent glibc headers and succeeds with older headers. The important change is that https://sourceware.org/git/?p=glibc.git;a=commit;h=c1760eaf3b575ad174fd88b252fd16bd525fa818 in 2021 added __attribute__ ((__malloc__ (fclose, 1))) attribute to fdopen, so in write_to_pipe there is an excess warning: .../gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c: In function 'write_to_pipe': .../gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c:28:3: warning: use of possibly-NULL 'stream' where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument] .../gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c:27:12: note: (1) this call could return NULL .../gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c:28:3: note: (2) argument 4 ('stream') from (1) could be NULL where non-null expected : note: argument 4 of '__builtin_fwrite' must be non-null Strangely, nothing is reported on the read_from_pipe function, seems fwrite/fprintf/fputc etc. are builtins in GCC and we mark the FILE * arguments as nonnull there on the builtin declarations, while fgetc/fread etc. aren't builtins and glibc doesn't mark any of those using nonnull. Shall we change that on the glibc side? Anyway, because this differs based on glibc version and I think the above warning is not the primary intention of the test, I think it is best to tweak it so that this warning isn't reported. Another option would be avoid using glibc headers and use our own declarations, or make sure we add the malloc with fclose attribute ourselves (but fdopen in the libc headers could be a macro, so not sure __typeof (fdopen) fdopen __attribute__ ((__malloc__, __malloc__ (fclose, 1))); would work). Or use -Wno-analyzer-possible-null-arguments in dg-additional-options? Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-03-30 Jakub Jelinek PR analyzer/107396 * gcc.dg/analyzer/pipe-glibc.c (read_from_pie, write_to_pipe): Exit if fdopen returns NULL. Jakub --- gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c.jj 2022-10-25 10:37:28.106531709 +0200 +++ gcc/testsuite/gcc.dg/analyzer/pipe-glibc.c 2023-03-29 19:14:48.789766475 +0200 @@ -13,6 +13,8 @@ read_from_pipe (int file) FILE *stream; int c; stream = fdopen (file, "r"); + if (stream == NULL) + exit (EXIT_FAILURE); while ((c = fgetc (stream)) != EOF) putchar (c); fclose (stream); @@ -25,6 +27,8 @@ write_to_pipe (int file) { FILE *stream; stream = fdopen (file, "w"); + if (stream == NULL) + exit (EXIT_FAILURE); fprintf (stream, "hello, world!\n"); fprintf (stream, "goodbye, world!\n"); fclose (stream);