Bug 32122 - indirect goto to an integer accepted
Summary: indirect goto to an integer accepted
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 12.0
Assignee: Andrew Pinski
URL: https://gcc.gnu.org/pipermail/gcc-pat...
Keywords: accepts-invalid, patch
: 69704 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-05-28 07:28 UTC by Chris Lattner
Modified: 2021-10-01 10:51 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 2.95.3, 3.0.4, 3.2.3, 3.3.3, 3.4.0, 4.0.0, 4.1.0
Last reconfirmed: 2021-09-16 00:00:00


Attachments
Patch which I am testing (1.51 KB, patch)
2021-09-17 05:19 UTC, Andrew Pinski
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2007-05-28 07:28:36 UTC
GCC accepts this:

void foo() { goto *1; }

The "Labels as Values" section of the doc states that indirect gotos take "Any expression of type void *".  1 is not of type void*.

it looks like gcc accepts anything convertible to a pointer type.  Trying to jump to a structure yields:
t.c:15: error: cannot convert to a pointer type

-Chris
Comment 1 Andrew Pinski 2007-06-10 02:21:55 UTC
Confirmed, not a regression as far as the eyes can see.
Comment 2 Shaun Jackman 2007-11-23 17:30:39 UTC
I've always used `goto *123;' on embedded targets as a feature to be able to jump to a constant address. This particularly useful feature should not be removed. Is a simple change of syntax being suggested, such as `goto *(void *)123;'? Dereferencing a void pointer looks strange to me, but I guess no stranger than dereferencing an integer.
Comment 3 Andrew Pinski 2016-02-06 04:28:56 UTC
*** Bug 69704 has been marked as a duplicate of this bug. ***
Comment 4 Andrew Pinski 2021-09-17 04:37:58 UTC
Mine, I have a patch.
Comment 5 Andrew Pinski 2021-09-17 05:19:15 UTC
Created attachment 51472 [details]
Patch which I am testing

It passes all of gcc.dg/dg.exp I am doing a full bootstrap/test right now.
Comment 6 Andrew Pinski 2021-09-20 04:14:55 UTC
Patch finally submitted:
https://gcc.gnu.org/pipermail/gcc-patches/2021-September/579792.html
Comment 7 CVS Commits 2021-09-28 20:02:50 UTC
The trunk branch has been updated by Andrew Pinski <pinskia@gcc.gnu.org>:

https://gcc.gnu.org/g:e12f66d96fe41c8ef8a0d01b6a8394cd6bce3978

commit r12-3947-ge12f66d96fe41c8ef8a0d01b6a8394cd6bce3978
Author: Andrew Pinski <apinski@marvell.com>
Date:   Fri Sep 17 04:59:03 2021 +0000

    c: [PR32122] Require pointer types for computed gotos
    
    So GCC has always accepted non-pointer types in computed gotos but
    that was wrong based on the documentation:
    Any expression of type void * is allowed.
    
    So this fixes the problem by requiring the type to
    be a pointer type.
    
    OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.
    
            PR c/32122
    
    gcc/c/ChangeLog:
    
            * c-parser.c (c_parser_statement_after_labels): Pass
            the c_expr instead of the tree to c_finish_goto_ptr.
            * c-typeck.c (c_finish_goto_ptr): Change the second
            argument type to c_expr.
            * c-tree.h (c_finish_goto_ptr): Likewise.
            Error out if the expression was not of a pointer type.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/comp-goto-5.c: New test.
            * gcc.dg/comp-goto-6.c: New test.
Comment 8 Andrew Pinski 2021-09-28 20:07:51 UTC
Fixed.