From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4CF7B385AC33; Mon, 5 Sep 2022 17:15:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4CF7B385AC33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662398110; bh=mGBO+s2QKhQ7UwNrJ+Suh0ilQ+DObaUo9gau4FeFykI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=kxlTxKSynGhfuUYVhsU1N9J597Oo3bBfLxDyBxAir/N7YhHOhKQa9wv+2Ac02rUYy bVvzQL5z3s6az2WkNoxsMb0/BHGrkubD7O9TJtizc4AZ02DQPZwiz1uDQghl4NF3sU nf1xicgvVxGKkcv0Ej2nR2xbKcHOH5tk8381RZnI= From: "sagebar at web dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/105682] [12/13 Regression] Both `-Wsuggest-attribute=pure` and `-Wsuggest-attribute=const` on same function since r12-5177-g494bdadf28d0fb35 Date: Mon, 05 Sep 2022 17:15:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ipa X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: sagebar at web dot de X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 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=3D105682 --- Comment #8 from sagebar at web dot de --- (In reply to Jan Hubicka from comment #6) > I think the conlcusion here is correct. callee has pure attribute and th= at > means that it has no side effects except for reading global memory. So > whatever volatile assembly does has to satisfy this. >=20 > Now since assembly is not declared as reading memory, GCC concludes that = the > function has no side effects and does not read global memory and this can= be > uprgraded to const. This assumes that reading memory is the only thing inline assembly can do to access (part of) the global state. But consider the following example where= the ARM FPU control word is read: ``` #include // HINT: this is arm assembly //#define _FPU_GETCW(cw) __asm__ __volatile__("vmrs %0, fpscr" : "=3Dr" (cw= )) //#define _FPU_SETCW(cw) __asm__ __volatile__("vmsr fpscr, %0" : : "r" (cw)) __attribute__((pure)) fpu_control_t getcw() { fpu_control_t result; _FPU_GETCW(result); return result; } int main() { fpu_control_t before, after; before =3D getcw(); _FPU_SETCW(0x1234); after =3D getcw() printf("oldcw: %d\n", before); printf("newcw: %d\n", after); } ``` If you're saying that a `__asm__ __volatile__` that doesn't access memory should be considered as `const`, then gcc should be allowed to remove the f= irst `getcw()` and simply assign the same value to `before` and `after` (since a `const` function's return value only depends on its arguments, meaning it c= alls can be removed and re-ordered however gcc pleases). I think you can see how that would be a problem in the above. However: I would understand gcc doing this if `_FPU_GETCW` was implemented using `__asm__` instead of `__asm__ __volatile__`. (If I'm misunderstanding how `pure` is meant to work, please correct me. Bu= t as far as I understand it, the above is a correct usage examle)=