public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/65656] New: __builtin_constant_p should be constexpr
@ 2015-04-01 18:52 scovich at gmail dot com
  2015-04-02  8:46 ` [Bug c++/65656] __builtin_constant_p should always " rguenth at gcc dot gnu.org
  2015-04-28 14:44 ` jason at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: scovich at gmail dot com @ 2015-04-01 18:52 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="UTF-8", Size: 6055 bytes --]

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65656

            Bug ID: 65656
           Summary: __builtin_constant_p should be constexpr
           Product: gcc
           Version: 4.8.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: scovich at gmail dot com

Consider the following program compiled with `gcc -std=c++11'
===== bug.cpp =====
#include <cstdio>
int main(int argc, char *argv[]) { 
  constexpr bool x = __builtin_constant_p(argc);
  std::printf("x=%d\n", x);
}
===================

With optimizations disabled, it correctly treats __builtin_constant_p() as
constexpr and prints "0" as expected (because the value of argc is not a
compile-time constant).

With optimizations enabled (-O1 or higher), compilation fails:
bug.cpp: In function ‘int main(int, char**)’:
bug.cpp:3:48: error: ‘argc’ is not a constant expression
    constexpr bool x = __builtin_constant_p(argc);
                                                ^
Clang 3.4 handles the case just fine. 

While I can 100% understand that the return value of __builtin_constant_p()
might change depending on what information the optimizer has available, I'm
pretty sure __builtin_constant_p() should always return a value computable at
compile time.

NOTE: this issue is *NOT* the same as Bug #54021, in spite of the two sharing
the same title. The latter is mis-named: It actually requests support for
constant folding for ternary expressions involving __builtin_constant_p, even
when optimizations are disabled and such folding would not normally occur.
>From gcc-bugs-return-482529-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Apr 01 19:41:27 2015
Return-Path: <gcc-bugs-return-482529-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 96559 invoked by alias); 1 Apr 2015 19:41:26 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 96528 invoked by uid 48); 1 Apr 2015 19:41:22 -0000
From: "jonathan.creekmore@synapse-wireless.com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/65657] New: [avr] read from __memx address space tramples argument to following function
Date: Wed, 01 Apr 2015 19:41:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: target
X-Bugzilla-Version: 4.8.1
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jonathan.creekmore@synapse-wireless.com
X-Bugzilla-Status: UNCONFIRMED
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 attachments.created
Message-ID: <bug-65657-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-04/txt/msg00081.txt.bz2
Content-length: 2481

https://gcc.gnu.org/bugzilla/show_bug.cgi?ide657

            Bug ID: 65657
           Summary: [avr] read from __memx address space tramples argument
                    to following function
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jonathan.creekmore@synapse-wireless.com

Created attachment 35207
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id5207&actioníit
Test snippet that exhibits the problem.

For an AVR target, the following code that reads from the __memx address space
results in the wrong code and tramples the handle variable:

extern void writeFlashByte(uint8_t byte, uint16_t handle);

void writeBuf(const uint8_t __memx *from, const uint8_t __memx *to)
{
    uint16_t handle = ((uint16_t)(((__uint24)to) & 0xFFFFUL));
    writeFlashByte(*from++, handle++);
}

The relevant assembly code is as follows:

mov r27,r22    # Move 'from' out of the way
mov r26,r23    # Move 'from' out of the way
mov r21,r24    # Move 'from' out of the way
mov r24,r20    # Move 'to' into 'handle' for calling writeFlashByte
movw r22,r18   # Move 'to' into 'handle' for calling writeFlashByte
mov r30,r27    # Put the relevant bits of 'from' into place to call __xload_1
mov r31,r26    # Put the relevant bits of 'from' into place to call __xload_1
call __xload_1 # <-- Returns into r22, corrupting the lower byte of 'handle'
mov r24,r22    # Move the result of __xload_1 for calling writeFlashByte
jmp writeFlashByte

The line marked <-- is where the badness occurs. Since __xload_1 returns into
r22, the 'handle' argument to writeFlashByte (which should be in r22 and r23),
gets its r22 portion corrupted by the value __xload_1.

PR target/52484 mentioned adding R22 to the register footprint for xload, but
that was targeted to 4.7.1, so I am not sure why this is failing in 4.8.1.

== compile =
avr-gcc -save-temps -mmcu=atmega128rfa1 -Os -v -Wall -Wextra -c test.c

== configure =
../src/configure -v --enable-languages=c,c++ --prefix=/usr/lib
--infodir=/usr/share/info --mandir=/usr/share/man --bindir=/usr/bin
--libexecdir=/usr/lib --libdir=/usr/lib --enable-shared --with-system-zlib
--enable-long-long --enable-nls --without-included-gettext --disable-libssp
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=avr
Thread model: single
gcc version 4.8.1 (GCC)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/65656] __builtin_constant_p should always be constexpr
  2015-04-01 18:52 [Bug c++/65656] New: __builtin_constant_p should be constexpr scovich at gmail dot com
@ 2015-04-02  8:46 ` rguenth at gcc dot gnu.org
  2015-04-28 14:44 ` jason at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2015-04-02  8:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65656

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-04-02
     Ever confirmed|0                           |1
      Known to fail|                            |5.0

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
If it's arg is a constexpr then it should return true and if not, false.

Confirmed.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/65656] __builtin_constant_p should always be constexpr
  2015-04-01 18:52 [Bug c++/65656] New: __builtin_constant_p should be constexpr scovich at gmail dot com
  2015-04-02  8:46 ` [Bug c++/65656] __builtin_constant_p should always " rguenth at gcc dot gnu.org
@ 2015-04-28 14:44 ` jason at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jason at gcc dot gnu.org @ 2015-04-28 14:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65656

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Tue Apr 28 14:43:59 2015
New Revision: 222531

URL: https://gcc.gnu.org/viewcvs?rev=222531&root=gcc&view=rev
Log:
        PR c++/65656
        * constexpr.c (cxx_eval_builtin_function_call): Fix
        __builtin_constant_p.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-builtin3.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-04-28 14:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-01 18:52 [Bug c++/65656] New: __builtin_constant_p should be constexpr scovich at gmail dot com
2015-04-02  8:46 ` [Bug c++/65656] __builtin_constant_p should always " rguenth at gcc dot gnu.org
2015-04-28 14:44 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).