brintos

brintos / llvm-project-archived public Read only

0
0

clang Support/Compiler.h checks __WASM__ (never defined) → CLANG_ABI undefined on wasm, breaks Attrs.inc #2

Open sasha opened this issue · 0 comments
S sasha commented

Summary

Cross-building clang/LLVM for wasm32-hwjs, ~370 TUs fail with:

Attrs.inc:19:17: error: variable has incomplete type 'class CLANG_ABI'
   class CLANG_ABI AArch64SVEPcsAttr : public InheritableAttr {

CLANG_ABI (clang's export/visibility macro) is left undefined on the wasm target.

Root cause

clang/include/clang/Support/Compiler.h selects CLANG_ABI by platform; the wasm branch gates on defined(__WASM__), but the compiler predefines __wasm__ (lowercase) — __WASM__ is never defined (wasmcc -dM -E lists __wasm__/__wasm32__, not __WASM__). Unlike llvm/include/llvm/Support/Compiler.h, the clang copy has no #else to define it empty. So on wasm no branch matches → CLANG_ABI undefined → tblgen-generated Attrs.inc fails to parse. The line is vendored upstream LLVM (60513b8d6), so it's also an upstream typo the fork inherits (candidate to fix upstream too).

Reproduction

Cross-build clang for wasm32-hwjs from brintos/llvm-project@7ca43933 (LLVM_ENABLE_PROJECTS=clang, LLVM_TARGETS_TO_BUILD=WebAssembly, wasmcc/wasmld). Every Attrs.inc consumer fails with the incomplete-type error.

Proposed fix

Correct the dead macro __WASM____wasm__ so the wasm target takes the visibility-default branch.

Branch: fix/clang-abi-wasm-macro Commit: cf96a9c

--- a/clang/include/clang/Support/Compiler.h
+++ b/clang/include/clang/Support/Compiler.h
@@ -54,7 +54,7 @@
 #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define CLANG_TEMPLATE_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define CLANG_EXPORT_TEMPLATE
-#elif defined(__MACH__) || defined(__WASM__) || defined(__EMSCRIPTEN__)
+#elif defined(__MACH__) || defined(__wasm__) || defined(__EMSCRIPTEN__)
 #define CLANG_ABI LLVM_ATTRIBUTE_VISIBILITY_DEFAULT
 #define CLANG_TEMPLATE_ABI
 #define CLANG_EXPORT_TEMPLATE

Verified by differential compile: a previously-failing Attrs.inc consumer (clang AST DeclBase.cpp) fails with the vendored header and compiles with the patched header, with no -DCLANG_BUILD_STATIC workaround.

Interim workaround until merged: -DCLANG_BUILD_STATIC -DLLVM_BUILD_STATIC (makes CLANG_ABI/LLVM_ABI expand empty via the static-build branch).

Proposed fix targets brintos/llvm-project only — no distro submodule pins moved. All distros share one lineage, so pin bumps are coordinated on merge, not per-engineer.