From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E0A93385801D; Mon, 2 Nov 2020 22:42:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0A93385801D From: "ldalessandro at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/97681] noinline attribute ignored on constexpr function Date: Mon, 02 Nov 2020 22:42:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ldalessandro at gmail dot com 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 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, 02 Nov 2020 22:43:00 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D97681 --- Comment #5 from Luke Dalessandro --- The more I think about this the more it bothers me.=20 I recognize that it might be very difficult to implement in gcc's infrastructure, but I think the design decision that "if it _can_ be consta= nt evaluated it _will_ be constant evaluated" is too aggressive. Consider https://godbolt.org/z/cTYPaK. ``` [[gnu::noinline]] constexpr int a(int x) {=20 return x + 1;=20 } int main() { int i =3D a(1); return i; } ``` 1. The function is marked noinline. 2. The code is compile with "-O0 -g". 3. The calling context is not explicitly `constexpr`. The fact that gcc _still_ chooses to constant evaluate `a` at best violates= the principle of least surprise, and at worst makes it impractical to use gcc to debug more complex codebases. Honestly, the `noinline` annotation shouldn't even be necessary, `a` should simply not be constant evaluated with `-O0`. = It's not practical to find all of the uses of `a` and modify their call sites. >>From a software engineering perspective I believe that gcc must provide some way to disable this behavior.=