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

            Bug ID: 98630
           Summary: Seg-fault when using a goto after condition (if)
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: k.even-mendoza at imperial dot ac.uk
  Target Milestone: ---

The following code snippet:

unsigned b=0; 
unsigned d=0;
static unsigned g = 1;
unsigned foo (unsigned ui1, unsigned ui2 ) { return (ui2 == 0) ? (ui1) : (ui1 %
ui2); }
unsigned j() {
  {
    unsigned *k = &b;
    unsigned *m = &d;
    unsigned **n = &m;
    unsigned ***o = &n;
    if (g)
      ;
    else
    p : {
      if (foo(2, *k)) {
        ***o = 0;
        return 2;
      }
    }
  }
  goto p;
}
int main() { j(); }

When compiling with GCC-10 (gcc-10 (Ubuntu 10.2.0-5ubuntu1~20.04) 10.2.0):
> gcc-10 -w -O2 r.c -pedantic -Wall -Wextra 
> ./a.out 
> Segmentation fault (core dumped)

The program in llvm, gcc-9, gcc-8, and gcc-7 exit without any output.  
> clang-11 -w -O0 r.c -pedantic -Wall -Wextra -fsanitize=undefined
> ./a.out
> 
or:
> clang-11 -w -O2 r.c -pedantic -Wall -Wextra
> ./a.out
> 
or:
> gcc-9 -w -O2 r.c -pedantic -Wall -Wextra 
> ./a.out

Reply via email to