diff --git a/lib/Basic/Targets/WebAssembly.cpp b/lib/Basic/Targets/WebAssembly.cpp index b16442b99b6..78402153a7c 100644 --- a/lib/Basic/Targets/WebAssembly.cpp +++ b/lib/Basic/Targets/WebAssembly.cpp @@ -60,6 +60,10 @@ void WebAssemblyTargetInfo::fillValidCPUList( void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const { defineCPUMacros(Builder, "wasm", /*Tuning=*/false); + // HACK: too lazy to backport the WASI target here + Builder.defineMacro("__wasi__"); + // HACK: globally enable WASI mmap emulation + Builder.defineMacro("_WASI_EMULATED_MMAN"); if (SIMDLevel >= SIMD128) Builder.defineMacro("__wasm_simd128__"); if (SIMDLevel >= UnimplementedSIMD128) diff --git a/lib/Basic/Targets/WebAssembly.h b/lib/Basic/Targets/WebAssembly.h index 9665156b143..55d90db267e 100644 --- a/lib/Basic/Targets/WebAssembly.h +++ b/lib/Basic/Targets/WebAssembly.h @@ -114,6 +114,16 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo { ? (IsSigned ? SignedLongLong : UnsignedLongLong) : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned); } + + CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { + switch (CC) { + case CC_C: + case CC_Swift: + return CCCR_OK; + default: + return CCCR_Warning; + } + } }; class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo : public WebAssemblyTargetInfo { diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index a126b764dea..8cb8760eabe 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -448,6 +448,9 @@ static void addExceptionArgs(const ArgList &Args, types::ID InputType, // Disable C++ EH by default on XCore and PS4. bool CXXExceptionsEnabled = Triple.getArch() != llvm::Triple::xcore && !Triple.isPS4CPU(); + // WebAssembly: no exception handling on WASI + if (Triple.isOSBinFormatWasm()) + CXXExceptionsEnabled = false; Arg *ExceptionArg = Args.getLastArg( options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions, options::OPT_fexceptions, options::OPT_fno_exceptions);