Skip to content

[BUG] -fmodules usage broke with including <cstring> since NDK 29 #2242

Description

@finagolfin

Description

The Swift compiler testsuite generates a header for C++ interoperability and checks it using the NDK clang++ for Android, but it has been broken since NDK 29, though hidden behind the earlier #2230 issue till now.

Reducing it, I get the following simple header and command:

> cat free.h
#include <cstring>
#include <cstdint>
#include <stdlib.h>
void opaqueFree(void *_Nonnull p) noexcept {
    free(p);
}

# works fine with NDK 28
> /home/finagolfin/android-ndk-r28c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -target aarch64-unknown-linux-android23 -isystem /home/finagolfin/android-ndk-r28c/toolchains/llvm/prebuilt/linux-x86_64/sysroot -x c++-header -c free.h  -fmodules -fcxx-modules

# breaks with NDK 30 beta 2
> /home/finagolfin/android-ndk-r30-beta2/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -target aarch64-unknown-linux-android23 -isystem /home/finagolfin/android-ndk-r30-beta2/toolchains/llvm/prebuilt/linux-x86_64/sysroot -x c++-header -c free.h  -fmodules -fcxx-modules
free.h:5:5: error: missing '#include <malloc.h>'; 'free' must be declared before it is used
    5 |     free(p);
      |     ^
/home/finagolfin/android-ndk-r30-beta2/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/malloc.h:108:6: note: declaration here is not visible
  108 | void free(void* _Nullable __ptr);
      |      ^
1 error generated.

I applied the fix for #2230 to NDK 29 and see the same error with that NDK too. Removing the -fmodules flag or the first <cstring> include gets it to not error again.

Since this isn't reproducible with other libc++ platforms, it is most likely a C++ modularity problem caused by some incompatibility between libc++ changes after NDK 28 and the Bionic headers in the NDK.

I am using a supported NDK

  • I have checked and the NDK I'm using is currently supported

Affected versions

r29, r30

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions