public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/39252]  New: Request new feature __builtin_not_reached();
@ 2009-02-19 20:42 hpa at zytor dot com
  2009-02-19 20:46 ` [Bug c/39252] " hjl dot tools at gmail dot com
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: hpa at zytor dot com @ 2009-02-19 20:42 UTC (permalink / raw)
  To: gcc-bugs

In the Linux kernel, we use assembly constructs (asm volatile) which trap or
otherwise terminate execution.  gcc doesn't know about this, so it doesn't
terminate its flow analysis.  These assembly constructs are more complex than a
simple __builtin_trap(); will permit -- we have tried using assembly constructs
in conjunction with __builtin_trap(); but that relies too much on undefined
behaviour.

A much better solution would be to give us __builtin_not_reached(); which is
simply an annotation truncating the flow of control at that point.  You can
think of it from an implementation perspective as __builtin_trap(); that
doesn't actually generate any code.  This allows any arbitrary assembly that
truncates the flow of control to be annotated as such, without the overhead of
a compiler-generated catch loop which is never actually reached.


-- 
           Summary: Request new feature __builtin_not_reached();
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: hpa at zytor dot com
 GCC build triplet: All
  GCC host triplet: All
GCC target triplet: All


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
@ 2009-02-19 20:46 ` hjl dot tools at gmail dot com
  2009-02-19 20:51 ` hjl dot tools at gmail dot com
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: hjl dot tools at gmail dot com @ 2009-02-19 20:46 UTC (permalink / raw)
  To: gcc-bugs



-- 

hjl dot tools at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hjl dot tools at gmail dot
                   |                            |com
   Target Milestone|---                         |4.5.0
            Version|unknown                     |4.4.0


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
  2009-02-19 20:46 ` [Bug c/39252] " hjl dot tools at gmail dot com
@ 2009-02-19 20:51 ` hjl dot tools at gmail dot com
  2009-02-19 21:50 ` pinskia at gcc dot gnu dot org
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: hjl dot tools at gmail dot com @ 2009-02-19 20:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from hjl dot tools at gmail dot com  2009-02-19 20:51 -------
So __builtin_not_reached is just __builtin_trap which doesn't generate
any insn. It shouldn't be too hard to implement.


-- 


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
  2009-02-19 20:46 ` [Bug c/39252] " hjl dot tools at gmail dot com
  2009-02-19 20:51 ` hjl dot tools at gmail dot com
@ 2009-02-19 21:50 ` pinskia at gcc dot gnu dot org
  2009-02-19 21:58 ` hpa at zytor dot com
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-02-19 21:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2009-02-19 21:50 -------
Why again is __builtin_trap not useful for this purpose? You mention about
"assembly constructs"  but why not instead implement those as builtins instead
of providing something which really can be abused?


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Target Milestone|4.5.0                       |---


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (2 preceding siblings ...)
  2009-02-19 21:50 ` pinskia at gcc dot gnu dot org
@ 2009-02-19 21:58 ` hpa at zytor dot com
  2009-02-19 22:13 ` hpa at zytor dot com
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: hpa at zytor dot com @ 2009-02-19 21:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from hpa at zytor dot com  2009-02-19 21:58 -------
Two reasons:

1. We have no control over what instruction __builtin_trap() will generate.
2. We require the address of the faulting instruction.

In particular, we currently have a construct which looks like:

#ifdef CONFIG_X86_32
# define __BUG_C0       "2:\t.long 1b, %c0\n"
#else
# define __BUG_C0       "2:\t.long 1b - 2b, %c0 - 2b\n"
#endif

#define BUG()                                                   \
do {                                                            \
        asm volatile("1:\tud2\n"                                \
                     ".pushsection __bug_table,\"a\"\n"         \
                     __BUG_C0                                   \
                     "\t.word %c1, 0\n"                         \
                     "\t.org 2b+%c2\n"                          \
                     ".popsection"                              \
                     : : "i" (__FILE__), "i" (__LINE__),        \
                     "i" (sizeof(struct bug_entry)));           \
        for (;;) ;                                              \
} while (0)


-- 


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (3 preceding siblings ...)
  2009-02-19 21:58 ` hpa at zytor dot com
@ 2009-02-19 22:13 ` hpa at zytor dot com
  2009-02-19 22:14 ` pinskia at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: hpa at zytor dot com @ 2009-02-19 22:13 UTC (permalink / raw)
  To: gcc-bugs



-- 

hpa at zytor dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |UNCONFIRMED


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (4 preceding siblings ...)
  2009-02-19 22:13 ` hpa at zytor dot com
@ 2009-02-19 22:14 ` pinskia at gcc dot gnu dot org
  2009-02-19 22:21 ` hpa at zytor dot com
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-02-19 22:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2009-02-19 22:14 -------
Still you can make a builtin that does that.  Even if it is a target builtin. 
I think of having a target builtin is better than creating a generic
__builtin_not_reached.


-- 


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (5 preceding siblings ...)
  2009-02-19 22:14 ` pinskia at gcc dot gnu dot org
@ 2009-02-19 22:21 ` hpa at zytor dot com
  2009-02-19 23:02 ` jakub at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: hpa at zytor dot com @ 2009-02-19 22:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from hpa at zytor dot com  2009-02-19 22:21 -------
Let me respectfully disagree, and explain why.

*You* can just create a builtin, but for us (the Linux kernel community) we
stare a multi-year pipeline in the face whenever we have to request a gcc
change.  This feature would allow us to do arbitrary trapping constructs via
the existing generic asm feature, without having to do wait for this pipeline
to flush every time we want to do something new.

In theory, ALL asm() constructs could be turned into builtins, and on some
level, that would be the right thing to do.  However, I think you can see why
this is completely unrealistic, at least with anything less than us forking gcc
and have an ad hoc compiler for the kernel.

Yes, this feature can be abused.  So can *any* use of asm().


-- 


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (6 preceding siblings ...)
  2009-02-19 22:21 ` hpa at zytor dot com
@ 2009-02-19 23:02 ` jakub at gcc dot gnu dot org
  2009-02-20  4:34 ` hpa at zytor dot com
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-02-19 23:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from jakub at gcc dot gnu dot org  2009-02-19 23:02 -------
Wouldn't be a special "noreturn" clobber in inline asm better suited for this
then?


-- 


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (7 preceding siblings ...)
  2009-02-19 23:02 ` jakub at gcc dot gnu dot org
@ 2009-02-20  4:34 ` hpa at zytor dot com
  2009-02-20  9:57 ` rguenth at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: hpa at zytor dot com @ 2009-02-20  4:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from hpa at zytor dot com  2009-02-20 04:34 -------
A "noreturn" clobber would work just as well, obviously.


-- 


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (8 preceding siblings ...)
  2009-02-20  4:34 ` hpa at zytor dot com
@ 2009-02-20  9:57 ` rguenth at gcc dot gnu dot org
  2009-03-01 22:34 ` hpa at zytor dot com
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-02-20  9:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenth at gcc dot gnu dot org  2009-02-20 09:57 -------
Though __builtin_not_reached () can be used to implement __builtin_assume (),
so it may be more generally useful.  if (i > 0) __builtin_not_reached (); will
make GCC assume that i <= 0 on the other edge (of course we'd have to preserve
this until some point to take advantage of it).


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2009-02-20 09:57:15
               date|                            |


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (9 preceding siblings ...)
  2009-02-20  9:57 ` rguenth at gcc dot gnu dot org
@ 2009-03-01 22:34 ` hpa at zytor dot com
  2009-03-01 22:42 ` rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: hpa at zytor dot com @ 2009-03-01 22:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from hpa at zytor dot com  2009-03-01 22:34 -------
> Though __builtin_not_reached () can be used to implement __builtin_assume (),
> so it may be more generally useful.  if (i > 0) __builtin_not_reached (); will
> make GCC assume that i <= 0 on the other edge (of course we'd have to preserve
> this until some point to take advantage of it).

This seems rather elegant to me, although I'm happy to get this feature in any
form.


-- 


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (10 preceding siblings ...)
  2009-03-01 22:34 ` hpa at zytor dot com
@ 2009-03-01 22:42 ` rguenth at gcc dot gnu dot org
  2009-06-09 20:12 ` daney at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-01 22:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from rguenth at gcc dot gnu dot org  2009-03-01 22:41 -------
Oh, patches welcome!


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (11 preceding siblings ...)
  2009-03-01 22:42 ` rguenth at gcc dot gnu dot org
@ 2009-06-09 20:12 ` daney at gcc dot gnu dot org
  2009-06-09 20:16 ` daney at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 17+ messages in thread
From: daney at gcc dot gnu dot org @ 2009-06-09 20:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from daney at gcc dot gnu dot org  2009-06-09 20:12 -------
This is essentially __builtin_unreachable() for which I am working on a patch.

http://gcc.gnu.org/ml/gcc-patches/2009-06/msg00787.html


-- 

daney at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |daney at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
           Keywords|                            |patch


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


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

* [Bug c/39252] Request new feature __builtin_not_reached();
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (12 preceding siblings ...)
  2009-06-09 20:12 ` daney at gcc dot gnu dot org
@ 2009-06-09 20:16 ` daney at gcc dot gnu dot org
  2009-06-11 23:56 ` [Bug c/39252] Request new feature __builtin_unreachable () daney at gcc dot gnu dot org
  2009-06-12  0:29 ` daney at gcc dot gnu dot org
  15 siblings, 0 replies; 17+ messages in thread
From: daney at gcc dot gnu dot org @ 2009-06-09 20:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from daney at gcc dot gnu dot org  2009-06-09 20:16 -------
(In reply to comment #6)
> Wouldn't be a special "noreturn" clobber in inline asm better suited for this
> then?
> 

See: http://gcc.gnu.org/ml/gcc-patches/2000-01/msg00190.html for an opposing
opinion.


-- 


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


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

* [Bug c/39252] Request new feature __builtin_unreachable ()
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (13 preceding siblings ...)
  2009-06-09 20:16 ` daney at gcc dot gnu dot org
@ 2009-06-11 23:56 ` daney at gcc dot gnu dot org
  2009-06-12  0:29 ` daney at gcc dot gnu dot org
  15 siblings, 0 replies; 17+ messages in thread
From: daney at gcc dot gnu dot org @ 2009-06-11 23:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #13 from daney at gcc dot gnu dot org  2009-06-11 23:55 -------
Subject: Bug 39252

Author: daney
Date: Thu Jun 11 23:55:45 2009
New Revision: 148403

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=148403
Log:
2009-06-11  David Daney  <ddaney@caviumnetworks.com>

        PR c/39252
        * doc/extend.texi ( __builtin_unreachable): Document new builtin.
        * builtins.c (expand_builtin_unreachable): New function.
        (expand_builtin): Handle BUILT_IN_UNREACHABLE case.
        * builtins.def (BUILT_IN_UNREACHABLE): Add new builtin.
        * cfgcleanup.c (try_optimize_cfg): Delete empty blocks with no
        successors.
        * cfgrtl.c (rtl_verify_flow_info): Handle empty blocks when
        searching for missing barriers.

2009-06-11  David Daney  <ddaney@caviumnetworks.com>

        PR c/39252
        * gcc.dg/builtin-unreachable-1.c: New test.
        * gcc.dg/builtin-unreachable-2.c: Same.

Added:
    trunk/gcc/testsuite/gcc.dg/builtin-unreachable-1.c
    trunk/gcc/testsuite/gcc.dg/builtin-unreachable-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/builtins.c
    trunk/gcc/builtins.def
    trunk/gcc/cfgcleanup.c
    trunk/gcc/cfgrtl.c
    trunk/gcc/doc/extend.texi
    trunk/gcc/system.h
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c/39252] Request new feature __builtin_unreachable ()
  2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
                   ` (14 preceding siblings ...)
  2009-06-11 23:56 ` [Bug c/39252] Request new feature __builtin_unreachable () daney at gcc dot gnu dot org
@ 2009-06-12  0:29 ` daney at gcc dot gnu dot org
  15 siblings, 0 replies; 17+ messages in thread
From: daney at gcc dot gnu dot org @ 2009-06-12  0:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #14 from daney at gcc dot gnu dot org  2009-06-12 00:29 -------
Fixed by the patch.


-- 

daney at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.0


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


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

end of thread, other threads:[~2009-06-12  0:29 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-19 20:42 [Bug c/39252] New: Request new feature __builtin_not_reached(); hpa at zytor dot com
2009-02-19 20:46 ` [Bug c/39252] " hjl dot tools at gmail dot com
2009-02-19 20:51 ` hjl dot tools at gmail dot com
2009-02-19 21:50 ` pinskia at gcc dot gnu dot org
2009-02-19 21:58 ` hpa at zytor dot com
2009-02-19 22:13 ` hpa at zytor dot com
2009-02-19 22:14 ` pinskia at gcc dot gnu dot org
2009-02-19 22:21 ` hpa at zytor dot com
2009-02-19 23:02 ` jakub at gcc dot gnu dot org
2009-02-20  4:34 ` hpa at zytor dot com
2009-02-20  9:57 ` rguenth at gcc dot gnu dot org
2009-03-01 22:34 ` hpa at zytor dot com
2009-03-01 22:42 ` rguenth at gcc dot gnu dot org
2009-06-09 20:12 ` daney at gcc dot gnu dot org
2009-06-09 20:16 ` daney at gcc dot gnu dot org
2009-06-11 23:56 ` [Bug c/39252] Request new feature __builtin_unreachable () daney at gcc dot gnu dot org
2009-06-12  0:29 ` daney at gcc dot gnu dot 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).