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

--- Comment #6 from Gavin Howard <gavin at yzena dot com> ---
Created attachment 54302
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54302&action=edit
An Amalgamation to Reproduce

I have managed to make an amalgamation that reproduces the bug. When you unzip
the attachment, you should get `amal.c`.

Run the following:

```
$ gcc -std=c11 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -D_GNU_SOURCE
-DYC_BUILTIN_128=1 -DYC_ENABLE_STACKTRACES=1 -O2 -g -o amal amal.c
$ ./amal amal.c temp.txt temp 1
```

You should get an assert failure as follows:

```
Assert Failed: pointer is NULL
    Expected:  (stack != ((void *)0))
    Source:    yc/src/concurrency/strucon.c:439
    Function:  y_strucon_handleErrorHelper()

Aborted
```

This file was produced from a source file with the `strgen` main, a function it
needed, and a bunch of `#include` of C files that were needed. The original was
`amalgamation.c`, and I ran the following command on it:

```
$ gcc -Iyc/include -std=c11 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700
-D_GNU_SOURCE -DYC_BUILTIN_128=1 -E amalgamation.c > amal.c
```

(It was created in the directory above the repo directory.)

This created the `amal.c` file that I have attached.

The line 63558 has the pointer assignment. The next line has the memcpy()
commented out. Either one is elided. You can comment out 63558 and uncomment
the next to test.

If you add ASan and UBSan, like so:

```
$ gcc -std=c11 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -D_GNU_SOURCE
-DYC_BUILTIN_128=1 -DYC_ENABLE_STACKTRACES=1 -O2 -g -o amal amal.c
```

they report nothing. In fact, they then make the program work.

(The "Encountered end-of-file" is a bug in the original that didn't suppress
EOF as an error; just ignore it because it's not really an error.)

If you run Valgrind on the non-ASan/UBSan build, like so:

```
$ valgrind --error-exitcode=100 --leak-check=full --show-leak-kinds=all
--errors-for-leak-kinds=all --num-callers=500 --child-silent-after-fork=yes
./amal amal.c temp.txt temp 1
```

It also reports nothing until the abort.

Reply via email to