https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102676
Bug ID: 102676
Summary: Failure to optimize out malloc/nothrow allocation
that's only used for bool checking
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
#include <new>
#include <stdlib.h>
bool f()
{
return new(std::nothrow) int;
}
bool g()
{
return malloc(1);
}
Both these functions can be optimized to `return true;`. This optimization is
done by LLVM, but not by GCC.