From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) by sourceware.org (Postfix) with ESMTPS id 11A013858418 for ; Tue, 12 Dec 2023 11:08:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11A013858418 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=ispras.ru ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 11A013858418 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702379299; cv=none; b=epSz0BM585i3LgSgYo5Ai9wrQVU4WATA6KKJZXU9FByrFjZg81hymXiPbKG1DAJn29mC8OzUn2gIFyMtez8KG/xF3g5YX2pEr/cK7nd5Sfc1DzBDa84UZPbfAuzHoLOCE3+0V52htEabjmxMqk8qn82QHfNWfJSgcV/OSJtDHtI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702379299; c=relaxed/simple; bh=GnvSmpt5dmdp5FMt5XtK9HTcRK41txfS4UYx1BtlaUw=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=dBk4Ea5ECJZspmFjmP39rw5ptOGh9TYfizcVzYpL+FlQEo4LqAJymruCiNIXw/gd1j32kGq7w1tLAjQnineIkKFDruijsA1QhrHSa53L/dGUan8ZkZSD4K47Iyposx2Nw8YYmKsMGnuaQAEZJ23J+4tE5G7asb0v7yi6mOkk8lI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.10.3.121] (unknown [10.10.3.121]) by mail.ispras.ru (Postfix) with ESMTPS id 0836E40F1DDC; Tue, 12 Dec 2023 11:08:07 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru 0836E40F1DDC Date: Tue, 12 Dec 2023 14:08:06 +0300 (MSK) From: Alexander Monakov To: Jonathan Wakely cc: Jingwen Wu , "gcc@gcc.gnu.org" Subject: Re: issue: unexpected results in optimizations In-Reply-To: Message-ID: <60362582-7546-3dc4-6035-9be925db9b06@ispras.ru> References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,KAM_SHORT,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 Tue, 12 Dec 2023, Jonathan Wakely via Gcc wrote: > On Mon, 11 Dec 2023, 17:08 Jingwen Wu via Gcc, wrote: > > > Hello, I'm sorry to bother you. And I have some gcc compiler optimization > > questions to ask you. > > First of all, I used csmith tools to generate c files randomly. Meanwhile, > > the final running result was the checksum for global variables in a c file. > > For the two c files in the attachment, I performed the equivalent > > transformation of loop from *initial.**c* to *transformed.c*. And the two > > files produced different results (i.e. different checksum values) when > > using *-O2* optimization level, while the results of both were the same > > when using other levels of optimization such as *-O0*, *-O1*, *-O3*, *-Os*, > > *-Ofast*. > > Please help me to explain why this is, thank you. > > > > Sometimes csmith can generate invalid code that gets miscompiled. It looks > like you're compiling with no warnings, which is a terrible idea: > > > > command line: *gcc file.c -O2 -lm -I $CSMITH_HOME/include && ./a.out* > > > > You should **at least** enable warnings and make sure gcc isn't pointing > out any problems in the code. > > You should also try the options suggested at http://gcc.gnu.org/bugs/ which > help identify invalid code. Let me also link the "Testing Compilers Using Csmith" page, which is currently available via the Wayback Machine, but not its original URL: https://web.archive.org/web/20230316072811/http://embed.cs.utah.edu/csmith/using.html It was written by the developers of Csmith. Alexander