https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111669
Bug ID: 111669 Summary: bogus -Wnonnull in conditionally executed code Product: gcc Version: 13.2.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: zfigura at codeweavers dot com Target Milestone: --- Created attachment 56032 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56032&action=edit reduced testcase, compile with -O2 -Werror=nonnull Sorry about the rather useless title, but I can't really figure out what actually triggers this error. It seems to depend on some arcane combination of optimizations. I was able to reduce this down to a pretty minimal test case, attached here. It may be possible to reduce it further but I couldn't easily find a way. The actual code that triggers this is here [1]. lstrcpyA() and lstrcatA() are trivial wrappers around strcpy/strcat. The NULL comes from get_search_path() at line 192. The offending strcpy/strcat will never be reached if GetWindowsDirectoryA() returns nonzero, which it always should. However, gcc triggers a -Wnonnull warning anyway. Interestingly, the original Wine code only triggers the warning with -march=bdver2 (or other values of -march), but the reduced testcase triggers it with no -march flags. [1] https://source.winehq.org/git/wine.git/blob/HEAD:/dlls/krnl386.exe16/file.c#l639