https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117807
Bug ID: 117807 Summary: analyzer gets confused by integer promotion Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: felix-gcc at fefe dot de Target Milestone: --- Here is my example code: #include <unistd.h> #include <fcntl.h> int open_for_reading(int* retfd,const char* filename) { int fd=open(filename,O_RDONLY); if (fd!=-1) { *retfd=fd; return 1; } return 0; } int open_for_reading_long(signed long long int* d,const char* filename) { long fd=open(filename,O_RDONLY); if (fd != -1) {>------// gcc -fanalyze false positive *d=fd;>-----// no leak, we return in *d return 1; } return 0; } Run with -fanalyzer gcc will complain that open_for_reading_long contains a file descriptor leak. The warning goes away if I turn d into an int*, and it also goes away if I turn fd into an int.