From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5042A3858D28; Thu, 19 Jan 2023 05:51:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5042A3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674107488; bh=lzRo3mNogDQ8nAQM/kxkcn6B1y0TVYofNwfDJHqnlc0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YJ1JxajT0VwCEjGrDDtOE/bvTc5NBXYoh2XZk7h7IlGE43fy7eOPPsPBOod3oFgqa fhDbznP2c6u9fliPgr224qhNjCD6OOdCKxzofgjLZJhqRXRV/5vZI1YVPVBvEVvDr9 5qKbMtCm/+vu2fjH39tHuCiOQu3lDACeNecZncPk= From: "gavin at yzena dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/108448] GCC Elides Assignment to Pointer and memcpy Date: Thu, 19 Jan 2023 05:51:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.3.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gavin at yzena dot com X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: attachments.created Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108448 --- Comment #6 from Gavin Howard --- Created attachment 54302 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D54302&action=3Dedit An Amalgamation to Reproduce I have managed to make an amalgamation that reproduces the bug. When you un= zip the attachment, you should get `amal.c`. Run the following: ``` $ gcc -std=3Dc11 -D_POSIX_C_SOURCE=3D200809L -D_XOPEN_SOURCE=3D700 -D_GNU_S= OURCE -DYC_BUILTIN_128=3D1 -DYC_ENABLE_STACKTRACES=3D1 -O2 -g -o amal amal.c $ ./amal amal.c temp.txt temp 1 ``` You should get an assert failure as follows: ``` Assert Failed: pointer is NULL Expected: (stack !=3D ((void *)0)) Source: yc/src/concurrency/strucon.c:439 Function: y_strucon_handleErrorHelper() Aborted ``` This file was produced from a source file with the `strgen` main, a functio= n it needed, and a bunch of `#include` of C files that were needed. The original= was `amalgamation.c`, and I ran the following command on it: ``` $ gcc -Iyc/include -std=3Dc11 -D_POSIX_C_SOURCE=3D200809L -D_XOPEN_SOURCE= =3D700 -D_GNU_SOURCE -DYC_BUILTIN_128=3D1 -E amalgamation.c > amal.c ``` (It was created in the directory above the repo directory.) This created the `amal.c` file that I have attached. The line 63558 has the pointer assignment. The next line has the memcpy() commented out. Either one is elided. You can comment out 63558 and uncomment the next to test. If you add ASan and UBSan, like so: ``` $ gcc -std=3Dc11 -D_POSIX_C_SOURCE=3D200809L -D_XOPEN_SOURCE=3D700 -D_GNU_S= OURCE -DYC_BUILTIN_128=3D1 -DYC_ENABLE_STACKTRACES=3D1 -O2 -g -o amal amal.c ``` they report nothing. In fact, they then make the program work. (The "Encountered end-of-file" is a bug in the original that didn't suppress EOF as an error; just ignore it because it's not really an error.) If you run Valgrind on the non-ASan/UBSan build, like so: ``` $ valgrind --error-exitcode=3D100 --leak-check=3Dfull --show-leak-kinds=3Da= ll --errors-for-leak-kinds=3Dall --num-callers=3D500 --child-silent-after-fork= =3Dyes ./amal amal.c temp.txt temp 1 ``` It also reports nothing until the abort.=