https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98444
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |msebor at gcc dot gnu.org Last reconfirmed| |2020-12-27 Status|UNCONFIRMED |NEW Known to work| |11.0, 9.3.0 Ever confirmed|0 |1 Known to fail| |10.2.0 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- The warning is based on the IL below where the %s argument is null, so it's working correctly. It doesn't consider the complex control flow (bb2 -> b10 -> bb5) from which it could deduce the asprintf call with the null pointer is only reachable conditionally to issue a more nuanced message, but that wouldn't prevent it, only make its conditional nature more apparent (all warnings are conditional on the function they're in being called). The assertion that the runtime pointer is nonnull is in export_legacy_dbus_address's caller, configure_runtime_directory, which is inlined into its caller, and has no effect on the code in export_legacy_dbus_address. Adding something like: if (!runtime) __builtin_unreachable (); just before the problematic call to asprintf() avoids the warning. In GCC 9 or on trunk (GCC 11), jump threading doesn't introduce the the invalid call so the warning doesn't trigger. So I can confirm this regression for GCC 10 but I don't expect to be able to do anything about it there. Longer term, we're aware of these warnings for synthesized code but we're still looking for a solution to avoid them. export_legacy_dbus_address (struct pam_handle_t * handle, const char * runtime) { ... <bb 2> [local count: 397250656]: t = 0B; if (runtime_22(D) != 0B) goto <bb 3>; [94.50%] else goto <bb 10>; [5.50%] <bb 3> [local count: 382684072]: _65 = strlen (runtime_22(D)); _n__16 = _65 + 5; if (_n__16 > 4194304) goto <bb 4>; [10.58%] else goto <bb 11>; [89.42%] <bb 4> [local count: 39725066]: log_assert_failed_realm (0, "sizeof(char)*_n_ <= ALLOCA_MAX", &"../src/login/pam_elogind.c"[3], 311, &__PRETTY_FUNCTION__); <bb 5> [local count: 7591956]: _10 = asprintf (&t, "unix:path=%s/bus", 0B); <<< warning here if (_10 < 0) goto <bb 6>; [26.36%] else goto <bb 7>; [73.64%] ... <bb 10> [local count: 21848788]: _29 = __builtin_alloca (1); *_29 = 0; _appendees_ ={v} {CLOBBER}; _9 = access (_29, 0); if (_9 < 0) goto <bb 9>; [42.09%] else goto <bb 5>; [57.91%]