From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3B42E3857C7D; Mon, 10 Aug 2020 11:16:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B42E3857C7D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597058210; bh=Xbwqb29wHdNqyjrFOr7BqCNc2jlif12Hv724T6MhfK0=; h=From:To:Subject:Date:From; b=JG2aXkPCRadMyNavmBCXiGWS+YKWq/SfYWYU+NsdX6qRU9wBzoU5emRi3wqvH+Az6 IxwnST6ntod8LoTgDPzQZeudJ7oTydcv5FInEMo11rTp7x5GSC/b6gYEdDvyWCWX0J LGfWBxUKS7XBJMI/bS4rnOXhpATtmMLmzuuvn4CU= From: "R.E.Wolff at BitWizard dot nl" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/96550] New: gcc is smart in figuring out a non-returning function. Date: Mon, 10 Aug 2020 11:16:49 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: R.E.Wolff at BitWizard dot nl X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Aug 2020 11:16:50 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96550 Bug ID: 96550 Summary: gcc is smart in figuring out a non-returning function. Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: R.E.Wolff at BitWizard dot nl Target Milestone: --- This is the small probgram that reproduces this:=20 ----------------------- #include #define FAIL struct test { #ifdef FAIL char *t; #else char t[8]; #endif } ;=20 extern void somefunc (struct test *t); void myfunc (void)=20 { struct test mt; memset (&mt, 0, sizeof (mt)); mt.t[0] =3D 1; somefunc (&mt); } ----------------------- Here the struct was defined in another part of the code, and I'd guessed (wrong) that the declaration was like in the FALSE branch of the IFDEF. As = it turns out the declaration was different.=20 So what happens is that the compiler decides that I set the pointer to zero, and that the assignment through that pointer WILL fail.=20 So the generated assembly starts with:=20 --------------------------- myfunc: @ Function supports interworking. @ Volatile: function does not return. --------------------------- So... without saying anything the compiler decided that my function will ne= ver return. It might be right about that (That's not true: This is on an embedd= ed system and I can map RAM to address zero!) but then IMHO, a warning would be warranted. A function goes from not being declared volatile by me to being volatile (not returning).=20 It's perfectly legal C code in there, but might not be what the user wanted= .... Just like if (a =3D 3) ... I think a warning might be issued.=20 Reproduced on: gcc (Raspbian 6.3.0-18+rpi1+deb9u1) 6.3.0 20170516 not reproduced on: gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0 20160609 reproduced on (originally ran into): arm-none-eabi-gcc (GNU Arm Embedded Toolchain 9-2020-q2-update) 9.3.1 20200408 (release)=