[RFC][Preprocessor] Add a macro for -fno-gnu-inline-asm

Hi,

When building with -fno-gnu-inline-asm and -fmodules on Darwin, the
compilation might fail if some of the implicit modules try to use gnu
asm inline. For instance, it's an issue that happens when with LLVM
installed headers, e.g., building _Builtin_intrinsics because of
inline asm in cpuid.h

To solve that, and potential related issues, I propose to add the
__CLANG_NO_GNU_INLINE_ASM macro when -fno-gnu-inline-asm is used,
allowing the user to reason in the preprocessor level.

A simple patch that implement this is here: https://reviews.llvm.org/D23859

Suggestions? Alternative ideas?

Hi Bruno,

I actually came across a similar issue- when building with -ffreestanding and -fmodules, the compilation might fail while building _Builtin_intrinsics because mm_malloc.h tries to include stdlib.h (which might be absent in a freestanding environment).

An alternative fix I can think of for this kind of issues could be marking such header files with the 'textual header' property in the modulemap file (They will be compiled only if included explicitly if I understand correctly).

However, since 'gnu-inline-asm' and 'freestanding' are language options, a better solution in my opinion (that other cases could benefit from as well) will be to extend the modules 'requires-declaration' feature-list with 'freestanding' and 'gnuasm' keywords. (And of course mark their submodules with these requirements in the modulemap).

A patch I uploaded specifically for the 'freestanding' issue a short while ago: https://reviews.llvm.org/D23871

Does this sounds reasonable?

Thanks,
Elad

Hi Elad,

Hi Bruno,

I actually came across a similar issue- when building with -ffreestanding and -fmodules, the compilation might fail while building _Builtin_intrinsics because mm_malloc.h tries to include stdlib.h (which might be absent in a freestanding environment).

An alternative fix I can think of for this kind of issues could be marking such header files with the 'textual header' property in the modulemap file (They will be compiled only if included explicitly if I understand correctly).

I thought about this but it didn't seem like the most clean solution
in the long term.

However, since 'gnu-inline-asm' and 'freestanding' are language options, a better solution in my opinion (that other cases could benefit from as well) will be to extend the modules 'requires-declaration' feature-list with 'freestanding' and 'gnuasm' keywords. (And of course mark their submodules with these requirements in the modulemap).

A patch I uploaded specifically for the 'freestanding' issue a short while ago: ⚙ D23871 [Modules] Add 'freestanding' to the 'requires-declaration' feature-list.

Does this sounds reasonable?

I like this idea even better. Gonna try this out!

Thanks!