From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C75C8384AB6F; Fri, 19 Apr 2024 08:49:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C75C8384AB6F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1713516549; bh=a6YsJueKhamG+Npj3DmQyzG9lZSomHlewhm7WsFtoHs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=giZv6qd2/vrY6mzCawhWdrM/zD+nNdSpTKALa9RwNvmzqgm9D0CeCRT++oy3ZpPTD E/uP/Ny27YK54NckxCaIyOH748WHPAsR/uOiBz4Htq694cayPMwukUXMsfMEkjlt4k vdjR6M66RbWeJ3YyVfDLygEZeKSohS9rqHw64s/Q= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114779] __builtin_constant_p does not work in inline functions Date: Fri, 19 Apr 2024 08:49:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.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: 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=3D114779 --- Comment #3 from Jakub Jelinek --- But in that case the POINTER_TYPE_P case doesn't trigger, because it is INTEGER_CST and so /* If we know this is a constant, emit the constant of one. */ if (CONSTANT_CLASS_P (arg) || (TREE_CODE (arg) =3D=3D CONSTRUCTOR && TREE_CONSTANT (arg))) return integer_one_node; triggers first. There is another case where the builtin can return true for a pointer, and = that is when it is called with a string literal (__builtin_constant_p ("abcd")): if (TREE_CODE (arg) =3D=3D ADDR_EXPR) { tree op =3D TREE_OPERAND (arg, 0);=20=20=20=20=20=20=20=20=20=20=20 if (TREE_CODE (op) =3D=3D STRING_CST || (TREE_CODE (op) =3D=3D ARRAY_REF && integer_zerop (TREE_OPERAND (op, 1)) && TREE_CODE (TREE_OPERAND (op, 0)) =3D=3D STRING_CST)) return integer_one_node; } But if you use even in the same function int volatile *psfr =3D SFR; __builtin_constant_p (psfr) it will fold to 0.=