https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85248
Bug ID: 85248
Summary: [6/7/8 Regression] Miscompilation when using error
function that returns
Product: gcc
Version: unknown
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: lto
Assignee: unassigned at gcc dot gnu.org
Reporter: marxin at gcc dot gnu.org
CC: hubicka at gcc dot gnu.org, jamborm at gcc dot gnu.org,
marxin at gcc dot gnu.org
Target Milestone: ---
Isolated from dwz program:
$ cat dwz.c
#include <error.h>
int a;
int get(void)
{
return a;
}
static void
dwz (void)
{
error (0, 1, "");
__builtin_printf ("PES\n");
}
static void usage ()
{
error (1, 0, "usage\n");
}
int
main (int argc)
{
if (get())
usage ();
dwz ();
return 0;
}
Note that error does not return when 1st argument == 0.
Without LTO:
$ gcc dwz.c -O1 && ./a.out
./a.out: : Operation not permitted
PES
With LTO:
$ gcc dwz.c -O1 -flto && ./a.out
./a.out: : Operation not permitted
Segmentation fault (core dumped)
Where inliner decides to inline usage function and then removes the BB with PES
printf:
Inlining usage to main with frequency 0
Updating SSA:
Registering new PHI nodes in block #0
Registering new PHI nodes in block #2
Updating SSA information for statement __error_noreturn (0, 1, "");
Updating SSA information for statement __builtin_puts (&"PES"[0]);
Updating SSA information for statement return;
Symbols to be put in SSA form
{ D.4014 }
Incremental SSA update started at block: 0
Number of blocks in CFG: 3
Number of blocks to update: 2 ( 67%)
Affected blocks: 0 2
Inlining dwz to main with frequency 999
Removing basic block 7
basic block 7, loop depth 0
pred:
succ:
Removing basic block 9
basic block 9, loop depth 0
pred: 11
return 0;
succ: EXIT
Removing basic block 11
basic block 11, loop depth 0
pred: 10
# DEBUG __status => NULL
# DEBUG __errnum => NULL
# DEBUG __format => NULL
__builtin_puts (&"PES"[0]);
succ: