diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -181,6 +181,7 @@ CODEGENOPT(FatalWarnings , 1, 0) ///< Set when -Wa,--fatal-warnings is ///< enabled. CODEGENOPT(NoWarn , 1, 0) ///< Set when -Wa,--no-warn is enabled. +CODEGENOPT(NoTypeCheck , 1, 0) ///< Set when -Wa,--no-type-check is enabled. CODEGENOPT(MisExpect , 1, 0) ///< Set when -Wmisexpect is enabled CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is enabled. CODEGENOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5289,6 +5289,9 @@ NormalizedValuesScope<"llvm::Reloc">, NormalizedValues<["Static", "PIC_", "ROPI", "RWPI", "ROPI_RWPI", "DynamicNoPIC"]>, MarshallingInfoEnum, "PIC_">; +def mno_type_check : Flag<["-"], "mno-type-check">, + HelpText<"Don't perform type checking of the assembly code (wasm only)">, + MarshallingInfoFlag>; def fno_math_builtin : Flag<["-"], "fno-math-builtin">, HelpText<"Disable implicit builtin knowledge of math functions">, MarshallingInfoFlag>; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2582,6 +2582,13 @@ switch (C.getDefaultToolChain().getArch()) { default: break; + case llvm::Triple::wasm32: + case llvm::Triple::wasm64: + if (Value == "--no-type-check") { + CmdArgs.push_back("-mno-type-check"); + continue; + } + break; case llvm::Triple::thumb: case llvm::Triple::thumbeb: case llvm::Triple::arm: diff --git a/clang/test/Driver/notypecheck.s b/clang/test/Driver/notypecheck.s new file mode 100644 --- /dev/null +++ b/clang/test/Driver/notypecheck.s @@ -0,0 +1,13 @@ +# REQUIRES: webassembly-registered-target + +# RUN: %clang -### %s -c -o tmp.o -target wasm32-unknown-unknown -Wa,--no-type-check 2>&1 | FileCheck %s +# CHECK: "-cc1as" {{.*}} "-mno-type-check" + +# Verify that without -Wa,--no-type-check the assembler will error out +# RUN: not %clang %s -c -o tmp.o -target wasm32-unknown-unknown 2>&1 | FileCheck --check-prefix=ERROR %s +# ERROR: error: popped i64, expected i32 + +foo: + .functype foo () -> (i32) + i64.const 42 + end_function diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp --- a/clang/tools/driver/cc1as_main.cpp +++ b/clang/tools/driver/cc1as_main.cpp @@ -134,6 +134,7 @@ unsigned NoExecStack : 1; unsigned FatalWarnings : 1; unsigned NoWarn : 1; + unsigned NoTypeCheck : 1; unsigned IncrementalLinkerCompatible : 1; unsigned EmbedBitcode : 1; @@ -166,6 +167,7 @@ NoExecStack = 0; FatalWarnings = 0; NoWarn = 0; + NoTypeCheck = 0; IncrementalLinkerCompatible = 0; Dwarf64 = 0; DwarfVersion = 0; @@ -304,6 +306,7 @@ Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack); Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings); Opts.NoWarn = Args.hasArg(OPT_massembler_no_warn); + Opts.NoTypeCheck = Args.hasArg(OPT_mno_type_check); Opts.RelocationModel = std::string(Args.getLastArgValue(OPT_mrelocation_model, "pic")); Opts.TargetABI = std::string(Args.getLastArgValue(OPT_target_abi)); @@ -468,6 +471,7 @@ MCOptions.MCNoWarn = Opts.NoWarn; MCOptions.MCFatalWarnings = Opts.FatalWarnings; + MCOptions.MCNoTypeCheck = Opts.NoTypeCheck; MCOptions.ABIName = Opts.TargetABI; // FIXME: There is a bit of code duplication with addPassesToEmitFile.