https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87489
Bug ID: 87489 Summary: Spurious -Wnonnull warning Product: gcc Version: 8.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: andres at anarazel dot de Target Milestone: --- Created attachment 44775 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44775&action=edit Repro Hi, With the attached, obviously heavily condensed, testcase I get a spurious -Wnonnull warning. It's quite true that the argument to strlen is NULL, but the code isn't reachable if so. As the warning isn't phrased as "may be", that doesn't seem quite right. $ gcc-8 -Wnonnull -O2 -c xact.stripped.i In function ‘XactLogCommitRecord.constprop’, inlined from ‘RecordTransactionCommit’ at xact.stripped.i:51:3: xact.stripped.i:44:50: warning: argument 1 null where non-null expected [-Wnonnull] XLogRegisterData((const char *) twophase_gid, strlen(twophase_gid) + 1); ^~~~~~~~~~~~~~~~~~~~ xact.stripped.i: In function ‘RecordTransactionCommit’: xact.stripped.i:19:15: note: in a call to function ‘strlen’ declared here extern size_t strlen (const char *__s) ^~~~~~ While the concrete problem in postgres only triggers for gcc-8 at -O3, the simplified testcase triggers for 7, 8, and a recent-ish trunk, and even with -O1. Without the first XLogRegisterData() call the warning does not appear. - Andres