The GNU C library includes headers from the _Builtin_intrinsics module. As the _Builtin_intrinsics module via
the mm_malloc.h header also includes the stdlib.h header from libc, we get a cyclic dependency with
-fmodules enabled. The best way to solve this is seems to be removing the stdlib.h include from mm_malloc.h
and make the redeclarations in there work without the include.
This patch is doing this in two steps:
- It reverts some of the changes done in r119958 which re-added the include to mm_malloc.h and removed the forward declarations.
- It expands the workaround in Sema::CheckEquivalentExceptionSpec to also work in the case where we first declare a function with a missing empty exception specification and then redeclare it with an empty exception specification.
The second part is necessary because the current workaround only works in the case where the redeclaration
is missing an empty exception specification and the #include <stdlib.h> before our redeclaration ensured that
we always have our declarations in this expected order.
I compiled a few projects with this patch (curl, ncnn, opencv, openjpeg, scummvm, sqlite, zlib), and it doesn't
seem to break any compilation there.