https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86284
Bug ID: 86284 Summary: Insert trap instruction in place of missing return statement on dodgy code Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: ktkachov at gcc dot gnu.org Target Milestone: --- Consider a non-void function that's missing a return statement: int test() { volatile int i = 0; } g++ at -O2 for aarch64 will generate: _Z4testv: .LFB0: .cfi_startproc sub sp, sp, #16 .cfi_def_cfa_offset 16 str wzr, [sp, 12] .cfi_endproc .LFE0: .size _Z4testv, .-_Z4testv No return statement. That's fine (the code is undefined), and GCC even warns about it. We got a suggestion that GCC could insert a trap instruction at the end of such a function so that at runtime we get a trap rather than the execution running off into the abyss. GCC already inserts traps in unreachable paths in gimple-ssa-isolate-paths.c, so maybe we can also do this when we already detect that a function is broken in this way?