From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4FCD6385BF92; Wed, 1 Apr 2020 09:55:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4FCD6385BF92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1585734948; bh=navk4evi5OC6FDxEfVgKv+e5zgGxPMgy1akcgHl94Rg=; h=From:To:Subject:Date:From; b=mGiy0SXmZy7NRuFjF/yuEbMtVnuy6jwhNNhTRRImVqSo0xoPimAlbNjcJ7MKZJHbm sx/aqgJJGW9xOlxKFeMU6BcPck2AzBewvNoOKAmiDZIoruRjAIoNm+SWWjziK3n8Xg O+zk4/3AJgKV+Bk0Op8T+qjo892MNHjxYArdJ8xU= From: "npfhrotynz-ptnqh.myvf at noclue dot notk.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug regression/94436] New: incompatible-pointer-types warning with container_of Date: Wed, 01 Apr 2020 09:55:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: regression X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: npfhrotynz-ptnqh.myvf at noclue dot notk.org 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 attachments.created 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: Wed, 01 Apr 2020 09:55:48 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94436 Bug ID: 94436 Summary: incompatible-pointer-types warning with container_of Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: regression Assignee: unassigned at gcc dot gnu.org Reporter: npfhrotynz-ptnqh.myvf at noclue dot notk.org Target Milestone: --- Created attachment 48157 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D48157&action=3Dedit test program.c This looks like a regression in warnings: passing an argument straight from= a container_of construct fails with incompatible type warning. In the attached code, the if 0'd implementation taken from the linux kernel works, but the other one also seen in the linux kernel (why do they have multiple implementations?!) produces the following warning: ------------ t.c: In function =E2=80=98main=E2=80=99: t.c:14:41: warning: passing argument 1 of =E2=80=98func=E2=80=99 from incom= patible pointer type [-Wincompatible-pointer-types] 14 | #define container_of(ptr, type, member) (type *)((char *)(ptr) - (c= har *) &((type *)0)->member) |=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | char * t.c:24:14: note: in expansion of macro =E2=80=98container_of=E2=80=99 24 | return func(container_of(&bar, struct foo, bar)); | ^~~~~~~~~~~~ t.c:17:22: note: expected =E2=80=98struct foo *=E2=80=99 but argument is of= type =E2=80=98char *=E2=80=99 17 | int func(struct foo* foo) { | ~~~~~~~~~~~~^~~ ------------- Here is -E preprocessed interesting line: return func((struct foo *)((char *)(&bar) - (char *) &((struct foo *)0)->ba= r)); For me the whole thing is cast with (struct foo*) so it should silence that warning as it used to do (tested with gcc 7.4.0 and gcc 9.2.0) In the case I'm looking at I could work around by using the other implementation, but I see that macro defined all the time so would be interested in seeing the old behaviour back. Thanks!=