public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/60722] New: __builtin_choose_expr() does not allow 'CONST_EXP' using const variable
@ 2014-03-31 14:25 yann at droneaud dot fr
  2014-04-11  8:37 ` [Bug c/60722] " mpolacek at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: yann at droneaud dot fr @ 2014-03-31 14:25 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: 4512 bytes --]

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60722

            Bug ID: 60722
           Summary: __builtin_choose_expr() does not allow 'CONST_EXP'
                    using const variable
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yann at droneaud dot fr

Created attachment 32498
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32498&action=edit
testcase

Hi,

I'm trying to use __builtin_choose_expr() with a test against a const variable:

#define VALUE 123

int
test(void)
{
    const int value = VALUE;
    int v1, v2;

    v1 = __builtin_choose_expr(__builtin_constant_p(VALUE),
                   (__builtin_choose_expr(VALUE >= 10,
                              2,
                              (__builtin_choose_expr(VALUE >= 0,
                                         1,
                                         0)))),
                    -1);

    v1 = __builtin_choose_expr(__builtin_constant_p(value),
                   (__builtin_choose_expr(value >= 10,
                              2,
                              (__builtin_choose_expr(value >= 0,
                                         1,
                                         0)))),
                   -1);

    return v1 - v2;
}




The first expression is considering a constant defined as a macro.
And the second expression is considering a constant variable.

With gcc 4.9.0 20140313 (experimental), I'm facing the following error:

$ /opt/gcc/bin/gcc -O2 -c test.c 
test.c: In function ‘test’:
test.c:21:11: erreur: first argument to ‘__builtin_choose_expr’ not a constant
          (__builtin_choose_expr(value >= 0,
           ^
test.c:19:9: erreur: first argument to ‘__builtin_choose_expr’ not a constant
        (__builtin_choose_expr(value >= 10,
         ^

(Note: with gcc 4.8, I'm also having the issue with _builtin_constant_p(value),
as bug #19449)


It's a pity gcc is not able to consider (value >= 0) as a constant expression
while its obvious
that 'value' is a constant variable (!).

It makes usage of __builtin_choose_expr() not applicable in my case.
>From gcc-bugs-return-447955-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Mar 31 14:33:04 2014
Return-Path: <gcc-bugs-return-447955-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 8662 invoked by alias); 31 Mar 2014 14:33:04 -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 8529 invoked by uid 48); 31 Mar 2014 14:33:01 -0000
From: "burnus at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/60653] [4.9 Regression] gfortran: ICE (segmentation fault) in lra
Date: Mon, 31 Mar 2014 14:33:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: target
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords: ice-on-valid-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: burnus at gcc dot gnu.org
X-Bugzilla-Status: WAITING
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.9.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: attachments.created
Message-ID: <bug-60653-4-qyF0ruiAGH@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-60653-4@http.gcc.gnu.org/bugzilla/>
References: <bug-60653-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: 2014-03/txt/msg02824.txt.bz2
Content-length: 371

http://gcc.gnu.org/bugzilla/show_bug.cgi?id`653

--- Comment #8 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Created attachment 32499
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id2499&actioníit
Reduced Fortran test case (use .f or .f90 suffix)

Reduced test case attached. Compile on arm-linux-gnueabihf with "gfortran -O1";
works with "gfortran -O0".


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

* [Bug c/60722] __builtin_choose_expr() does not allow 'CONST_EXP' using const variable
  2014-03-31 14:25 [Bug c/60722] New: __builtin_choose_expr() does not allow 'CONST_EXP' using const variable yann at droneaud dot fr
@ 2014-04-11  8:37 ` mpolacek at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-04-11  8:37 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60722

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |mpolacek at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
So this is basically:

void
foo (void)
{
  const int ci = 12;
  int i;
  i = __builtin_choose_expr (ci, 1, 23);
}

but as ci is not an integer constant expression, we don't want to allow this
one in C, and C++ doesn't support __builtin_choose_expr since it has templates.
(Yes, there's decl_constant_value that would work for this particular example,
but I'm afraid it can't work e.g. for PARM_DECLs.)
So, closing.


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

end of thread, other threads:[~2014-04-11  8:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-31 14:25 [Bug c/60722] New: __builtin_choose_expr() does not allow 'CONST_EXP' using const variable yann at droneaud dot fr
2014-04-11  8:37 ` [Bug c/60722] " mpolacek 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).