From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.4 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 2A5011F55B for ; Sat, 6 Jun 2020 08:26:21 +0000 (UTC) Received: from localhost ([::1]:42570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhU9j-0008Mt-Ol for normalperson@yhbt.net; Sat, 06 Jun 2020 04:26:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhU3e-0006sL-M9 for bug-gnulib@gnu.org; Sat, 06 Jun 2020 04:20:02 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.217]:25251) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhU3c-0000q7-9p for bug-gnulib@gnu.org; Sat, 06 Jun 2020 04:20:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1591431596; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=UBh81vzVyARObid523/2POv20NIDT5aI/BP7W4KsGgs=; b=WkQm5eM8XCvM4F9RAx660S7ocwzl223xnEh9Sf+7Y44N5rroyeGYPFRZaQtZXUGmII udKtYQELaFgFgDOMOH/tTFd9jCnVTFDAMmpyE8SCEMurfWJDWvw4JmR4r+k+vJJkDh8c +XyL3jbxePtyg663LId1Yhkm+snksbcUNrcCZe5peai/2cxd6reQq4k2jLWXGg9TsfXY e/mtkKSaCe2Lqxw7lwLtNdbe2xbLdG7gJbYQeozBqsgChg0GHdcO6Y6UopnrzzORUi0I r4eTrrKzjvgH8p9wZ1KjjMKHo3I522hB03TSf0fRGmWKgIzyzuNVjwLaB2eRTb7k+asG rBvw== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOH6fzxfs=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 46.9.1 DYNA|AUTH) with ESMTPSA id V0a757w568JsI4s (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Sat, 6 Jun 2020 10:19:54 +0200 (CEST) From: Bruno Haible To: Tim =?ISO-8859-1?Q?R=FChsen?= Subject: Re: Fix calloc.m4 test Date: Sat, 06 Jun 2020 10:19:54 +0200 Message-ID: <2687257.hS50TXvTxk@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-177-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <1872257.AoR9L2n4HY@omega> References: <1872257.AoR9L2n4HY@omega> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=81.169.146.217; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/06 04:19:56 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Eggert , bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" On 2020-05-23 I wrote: > As you can see: > > 1) clang has eliminated the calloc() and free() calls from the program. > Apparently it "knows" how to optimize matching calloc - free pairs. > > 2) It has estimated that the second call would return a non-NULL pointer, > although the address space does not allow this. > Reported at . But some > people claim it is not a bug. Paul, can you please help with ISO C > citations? > > This patch provides a workaround. > > > 2020-05-23 Bruno Haible > > calloc-gnu: Avoid wrong configure results with clang. > * m4/calloc.m4 (_AC_FUNC_CALLOC_IF): Mark the pointer variable as > 'volatile', to defeat compiler optimizations. The same problem occurs also in the test suite. The continuous integration [1] detected it. [1] https://gitlab.com/gnulib/gnulib-ci/-/pipelines/153500376 2020-06-06 Bruno Haible calloc-gnu tests: Avoid a test failure with clang. * tests/test-calloc-gnu.c (main): Mark the pointer variable as 'volatile', to defeat compiler optimizations. diff --git a/tests/test-calloc-gnu.c b/tests/test-calloc-gnu.c index c13ba47..2ae3925 100644 --- a/tests/test-calloc-gnu.c +++ b/tests/test-calloc-gnu.c @@ -36,20 +36,26 @@ int main () { /* Check that calloc (0, 0) is not a NULL pointer. */ - void *p = calloc (0, 0); - if (p == NULL) - return 1; - free (p); + { + void * volatile p = calloc (0, 0); + if (p == NULL) + return 1; + free (p); + } /* Check that calloc fails when requested to allocate a block of memory larger than SIZE_MAX bytes. - We use eight (), not 8, to avoid a compiler warning from GCC 7. */ - p = calloc ((size_t) -1 / 8 + 1, eight ()); - if (p != NULL) - { - free (p); - return 1; - } + We use eight (), not 8, to avoid a compiler warning from GCC 7. + 'volatile' is needed to defeat an incorrect optimization by clang 10, + see . */ + { + void * volatile p = calloc ((size_t) -1 / 8 + 1, eight ()); + if (p != NULL) + { + free (p); + return 2; + } + } return 0; }