sunfish updated this revision to Diff 32109.
sunfish added a comment.

- use more default values in WebAssemblyTargetInfo etc.
- add a comment about using ARM-C++-ABI-style guard variables (for now)
- fix diff to include context for Phabricator


Repository:
  rL LLVM

http://reviews.llvm.org/D12002

Files:
  include/clang/Basic/BuiltinsWebAssembly.def
  include/clang/Basic/TargetBuiltins.h
  include/clang/Basic/TargetCXXABI.h
  include/clang/module.modulemap
  lib/AST/ASTContext.cpp
  lib/Basic/Targets.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Driver/ToolChains.h
  lib/Driver/Tools.cpp
  test/CodeGen/builtins-wasm.c
  test/CodeGen/target-data.c
  test/CodeGen/wasm-arguments.c
  test/CodeGen/wasm-regparm.c
  test/CodeGenCXX/member-alignment.cpp
  test/CodeGenCXX/member-function-pointers.cpp
  test/CodeGenCXX/static-init-wasm.cpp
  test/Driver/wasm32-unknown-unknown.cpp
  test/Driver/wasm64-unknown-unknown.cpp
  test/Preprocessor/init.c

Index: test/Preprocessor/init.c
===================================================================
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -8419,3 +8419,603 @@
 // XCORE:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
 // XCORE:#define __LITTLE_ENDIAN__ 1
 // XCORE:#define __XS1B__ 1
+//
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=wasm32-unknown-unknown < /dev/null | FileCheck -check-prefix=WEBASSEMBLY32 %s
+//
+// WEBASSEMBLY32:#define _ILP32 1
+// WEBASSEMBLY32-NOT:#define _LP64
+// WEBASSEMBLY32:#define __ATOMIC_ACQUIRE 2
+// WEBASSEMBLY32:#define __ATOMIC_ACQ_REL 4
+// WEBASSEMBLY32:#define __ATOMIC_CONSUME 1
+// WEBASSEMBLY32:#define __ATOMIC_RELAXED 0
+// WEBASSEMBLY32:#define __ATOMIC_RELEASE 3
+// WEBASSEMBLY32:#define __ATOMIC_SEQ_CST 5
+// WEBASSEMBLY32:#define __BIGGEST_ALIGNMENT__ 16
+// WEBASSEMBLY32:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+// WEBASSEMBLY32:#define __CHAR16_TYPE__ unsigned short
+// WEBASSEMBLY32:#define __CHAR32_TYPE__ unsigned int
+// WEBASSEMBLY32:#define __CHAR_BIT__ 8
+// WEBASSEMBLY32:#define __CONSTANT_CFSTRINGS__ 1
+// WEBASSEMBLY32:#define __DBL_DECIMAL_DIG__ 17
+// WEBASSEMBLY32:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
+// WEBASSEMBLY32:#define __DBL_DIG__ 15
+// WEBASSEMBLY32:#define __DBL_EPSILON__ 2.2204460492503131e-16
+// WEBASSEMBLY32:#define __DBL_HAS_DENORM__ 1
+// WEBASSEMBLY32:#define __DBL_HAS_INFINITY__ 1
+// WEBASSEMBLY32:#define __DBL_HAS_QUIET_NAN__ 1
+// WEBASSEMBLY32:#define __DBL_MANT_DIG__ 53
+// WEBASSEMBLY32:#define __DBL_MAX_10_EXP__ 308
+// WEBASSEMBLY32:#define __DBL_MAX_EXP__ 1024
+// WEBASSEMBLY32:#define __DBL_MAX__ 1.7976931348623157e+308
+// WEBASSEMBLY32:#define __DBL_MIN_10_EXP__ (-307)
+// WEBASSEMBLY32:#define __DBL_MIN_EXP__ (-1021)
+// WEBASSEMBLY32:#define __DBL_MIN__ 2.2250738585072014e-308
+// WEBASSEMBLY32:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
+// WEBASSEMBLY32:#define __FINITE_MATH_ONLY__ 0
+// WEBASSEMBLY32:#define __FLT_DECIMAL_DIG__ 9
+// WEBASSEMBLY32:#define __FLT_DENORM_MIN__ 1.40129846e-45F
+// WEBASSEMBLY32:#define __FLT_DIG__ 6
+// WEBASSEMBLY32:#define __FLT_EPSILON__ 1.19209290e-7F
+// WEBASSEMBLY32:#define __FLT_EVAL_METHOD__ 0
+// WEBASSEMBLY32:#define __FLT_HAS_DENORM__ 1
+// WEBASSEMBLY32:#define __FLT_HAS_INFINITY__ 1
+// WEBASSEMBLY32:#define __FLT_HAS_QUIET_NAN__ 1
+// WEBASSEMBLY32:#define __FLT_MANT_DIG__ 24
+// WEBASSEMBLY32:#define __FLT_MAX_10_EXP__ 38
+// WEBASSEMBLY32:#define __FLT_MAX_EXP__ 128
+// WEBASSEMBLY32:#define __FLT_MAX__ 3.40282347e+38F
+// WEBASSEMBLY32:#define __FLT_MIN_10_EXP__ (-37)
+// WEBASSEMBLY32:#define __FLT_MIN_EXP__ (-125)
+// WEBASSEMBLY32:#define __FLT_MIN__ 1.17549435e-38F
+// WEBASSEMBLY32:#define __FLT_RADIX__ 2
+// WEBASSEMBLY32:#define __GCC_ATOMIC_BOOL_LOCK_FREE 2
+// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
+// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
+// WEBASSEMBLY32:#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
+// WEBASSEMBLY32:#define __GCC_ATOMIC_INT_LOCK_FREE 2
+// WEBASSEMBLY32:#define __GCC_ATOMIC_LLONG_LOCK_FREE 1
+// WEBASSEMBLY32:#define __GCC_ATOMIC_LONG_LOCK_FREE 2
+// WEBASSEMBLY32:#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
+// WEBASSEMBLY32:#define __GCC_ATOMIC_SHORT_LOCK_FREE 2
+// WEBASSEMBLY32:#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
+// WEBASSEMBLY32:#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
+// WEBASSEMBLY32:#define __GNUC_MINOR__
+// WEBASSEMBLY32:#define __GNUC_PATCHLEVEL__
+// WEBASSEMBLY32:#define __GNUC_STDC_INLINE__ 1
+// WEBASSEMBLY32:#define __GNUC__
+// WEBASSEMBLY32:#define __GXX_ABI_VERSION 1002
+// WEBASSEMBLY32:#define __GXX_RTTI 1
+// WEBASSEMBLY32:#define __ILP32__ 1
+// WEBASSEMBLY32:#define __INT16_C_SUFFIX__ {{$}}
+// WEBASSEMBLY32:#define __INT16_FMTd__ "hd"
+// WEBASSEMBLY32:#define __INT16_FMTi__ "hi"
+// WEBASSEMBLY32:#define __INT16_MAX__ 32767
+// WEBASSEMBLY32:#define __INT16_TYPE__ short
+// WEBASSEMBLY32:#define __INT32_C_SUFFIX__ {{$}}
+// WEBASSEMBLY32:#define __INT32_FMTd__ "d"
+// WEBASSEMBLY32:#define __INT32_FMTi__ "i"
+// WEBASSEMBLY32:#define __INT32_MAX__ 2147483647
+// WEBASSEMBLY32:#define __INT32_TYPE__ int
+// WEBASSEMBLY32:#define __INT64_C_SUFFIX__ LL
+// WEBASSEMBLY32:#define __INT64_FMTd__ "lld"
+// WEBASSEMBLY32:#define __INT64_FMTi__ "lli"
+// WEBASSEMBLY32:#define __INT64_MAX__ 9223372036854775807LL
+// WEBASSEMBLY32:#define __INT64_TYPE__ long long int
+// WEBASSEMBLY32:#define __INT8_C_SUFFIX__ {{$}}
+// WEBASSEMBLY32:#define __INT8_FMTd__ "hhd"
+// WEBASSEMBLY32:#define __INT8_FMTi__ "hhi"
+// WEBASSEMBLY32:#define __INT8_MAX__ 127
+// WEBASSEMBLY32:#define __INT8_TYPE__ signed char
+// WEBASSEMBLY32:#define __INTMAX_C_SUFFIX__ LL
+// WEBASSEMBLY32:#define __INTMAX_FMTd__ "lld"
+// WEBASSEMBLY32:#define __INTMAX_FMTi__ "lli"
+// WEBASSEMBLY32:#define __INTMAX_MAX__ 9223372036854775807LL
+// WEBASSEMBLY32:#define __INTMAX_TYPE__ long long int
+// WEBASSEMBLY32:#define __INTMAX_WIDTH__ 64
+// WEBASSEMBLY32:#define __INTPTR_FMTd__ "ld"
+// WEBASSEMBLY32:#define __INTPTR_FMTi__ "li"
+// WEBASSEMBLY32:#define __INTPTR_MAX__ 2147483647
+// WEBASSEMBLY32:#define __INTPTR_TYPE__ long
+// WEBASSEMBLY32:#define __INTPTR_WIDTH__ 32
+// WEBASSEMBLY32:#define __INT_FAST16_FMTd__ "hd"
+// WEBASSEMBLY32:#define __INT_FAST16_FMTi__ "hi"
+// WEBASSEMBLY32:#define __INT_FAST16_MAX__ 32767
+// WEBASSEMBLY32:#define __INT_FAST16_TYPE__ short
+// WEBASSEMBLY32:#define __INT_FAST32_FMTd__ "d"
+// WEBASSEMBLY32:#define __INT_FAST32_FMTi__ "i"
+// WEBASSEMBLY32:#define __INT_FAST32_MAX__ 2147483647
+// WEBASSEMBLY32:#define __INT_FAST32_TYPE__ int
+// WEBASSEMBLY32:#define __INT_FAST64_FMTd__ "lld"
+// WEBASSEMBLY32:#define __INT_FAST64_FMTi__ "lli"
+// WEBASSEMBLY32:#define __INT_FAST64_MAX__ 9223372036854775807LL
+// WEBASSEMBLY32:#define __INT_FAST64_TYPE__ long long int
+// WEBASSEMBLY32:#define __INT_FAST8_FMTd__ "hhd"
+// WEBASSEMBLY32:#define __INT_FAST8_FMTi__ "hhi"
+// WEBASSEMBLY32:#define __INT_FAST8_MAX__ 127
+// WEBASSEMBLY32:#define __INT_FAST8_TYPE__ signed char
+// WEBASSEMBLY32:#define __INT_LEAST16_FMTd__ "hd"
+// WEBASSEMBLY32:#define __INT_LEAST16_FMTi__ "hi"
+// WEBASSEMBLY32:#define __INT_LEAST16_MAX__ 32767
+// WEBASSEMBLY32:#define __INT_LEAST16_TYPE__ short
+// WEBASSEMBLY32:#define __INT_LEAST32_FMTd__ "d"
+// WEBASSEMBLY32:#define __INT_LEAST32_FMTi__ "i"
+// WEBASSEMBLY32:#define __INT_LEAST32_MAX__ 2147483647
+// WEBASSEMBLY32:#define __INT_LEAST32_TYPE__ int
+// WEBASSEMBLY32:#define __INT_LEAST64_FMTd__ "lld"
+// WEBASSEMBLY32:#define __INT_LEAST64_FMTi__ "lli"
+// WEBASSEMBLY32:#define __INT_LEAST64_MAX__ 9223372036854775807LL
+// WEBASSEMBLY32:#define __INT_LEAST64_TYPE__ long long int
+// WEBASSEMBLY32:#define __INT_LEAST8_FMTd__ "hhd"
+// WEBASSEMBLY32:#define __INT_LEAST8_FMTi__ "hhi"
+// WEBASSEMBLY32:#define __INT_LEAST8_MAX__ 127
+// WEBASSEMBLY32:#define __INT_LEAST8_TYPE__ signed char
+// WEBASSEMBLY32:#define __INT_MAX__ 2147483647
+// WEBASSEMBLY32:#define __LDBL_DECIMAL_DIG__ 17
+// WEBASSEMBLY32:#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L
+// WEBASSEMBLY32:#define __LDBL_DIG__ 15
+// WEBASSEMBLY32:#define __LDBL_EPSILON__ 2.2204460492503131e-16L
+// WEBASSEMBLY32:#define __LDBL_HAS_DENORM__ 1
+// WEBASSEMBLY32:#define __LDBL_HAS_INFINITY__ 1
+// WEBASSEMBLY32:#define __LDBL_HAS_QUIET_NAN__ 1
+// WEBASSEMBLY32:#define __LDBL_MANT_DIG__ 53
+// WEBASSEMBLY32:#define __LDBL_MAX_10_EXP__ 308
+// WEBASSEMBLY32:#define __LDBL_MAX_EXP__ 1024
+// WEBASSEMBLY32:#define __LDBL_MAX__ 1.7976931348623157e+308L
+// WEBASSEMBLY32:#define __LDBL_MIN_10_EXP__ (-307)
+// WEBASSEMBLY32:#define __LDBL_MIN_EXP__ (-1021)
+// WEBASSEMBLY32:#define __LDBL_MIN__ 2.2250738585072014e-308L
+// WEBASSEMBLY32:#define __LITTLE_ENDIAN__ 1
+// WEBASSEMBLY32:#define __LONG_LONG_MAX__ 9223372036854775807LL
+// WEBASSEMBLY32:#define __LONG_MAX__ 2147483647L
+// WEBASSEMBLY32-NOT:#define __LP64__
+// WEBASSEMBLY32:#define __NO_INLINE__ 1
+// WEBASSEMBLY32:#define __ORDER_BIG_ENDIAN__ 4321
+// WEBASSEMBLY32:#define __ORDER_LITTLE_ENDIAN__ 1234
+// WEBASSEMBLY32:#define __ORDER_PDP_ENDIAN__ 3412
+// WEBASSEMBLY32:#define __POINTER_WIDTH__ 32
+// WEBASSEMBLY32:#define __PRAGMA_REDEFINE_EXTNAME 1
+// WEBASSEMBLY32:#define __PTRDIFF_FMTd__ "ld"
+// WEBASSEMBLY32:#define __PTRDIFF_FMTi__ "li"
+// WEBASSEMBLY32:#define __PTRDIFF_MAX__ 2147483647
+// WEBASSEMBLY32:#define __PTRDIFF_TYPE__ long
+// WEBASSEMBLY32:#define __PTRDIFF_WIDTH__ 32
+// WEBASSEMBLY32:#define __REGISTER_PREFIX__ {{$}}
+// WEBASSEMBLY32:#define __SCHAR_MAX__ 127
+// WEBASSEMBLY32:#define __SHRT_MAX__ 32767
+// WEBASSEMBLY32:#define __SIG_ATOMIC_MAX__ 2147483647
+// WEBASSEMBLY32:#define __SIG_ATOMIC_WIDTH__ 32
+// WEBASSEMBLY32:#define __SIZEOF_DOUBLE__ 8
+// WEBASSEMBLY32:#define __SIZEOF_FLOAT__ 4
+// WEBASSEMBLY32:#define __SIZEOF_INT__ 4
+// WEBASSEMBLY32:#define __SIZEOF_LONG_DOUBLE__ 8
+// WEBASSEMBLY32:#define __SIZEOF_LONG_LONG__ 8
+// WEBASSEMBLY32:#define __SIZEOF_LONG__ 4
+// WEBASSEMBLY32:#define __SIZEOF_POINTER__ 4
+// WEBASSEMBLY32:#define __SIZEOF_PTRDIFF_T__ 4
+// WEBASSEMBLY32:#define __SIZEOF_SHORT__ 2
+// WEBASSEMBLY32:#define __SIZEOF_SIZE_T__ 4
+// WEBASSEMBLY32:#define __SIZEOF_WCHAR_T__ 4
+// WEBASSEMBLY32:#define __SIZEOF_WINT_T__ 4
+// WEBASSEMBLY32:#define __SIZE_FMTX__ "lX"
+// WEBASSEMBLY32:#define __SIZE_FMTo__ "lo"
+// WEBASSEMBLY32:#define __SIZE_FMTu__ "lu"
+// WEBASSEMBLY32:#define __SIZE_FMTx__ "lx"
+// WEBASSEMBLY32:#define __SIZE_MAX__ 4294967295UL
+// WEBASSEMBLY32:#define __SIZE_TYPE__ long unsigned int
+// WEBASSEMBLY32:#define __SIZE_WIDTH__ 32
+// WEBASSEMBLY32:#define __STDC_HOSTED__ 0
+// WEBASSEMBLY32:#define __STDC_UTF_16__ 1
+// WEBASSEMBLY32:#define __STDC_UTF_32__ 1
+// WEBASSEMBLY32:#define __STDC_VERSION__ 201112L
+// WEBASSEMBLY32:#define __STDC__ 1
+// WEBASSEMBLY32:#define __UINT16_C_SUFFIX__ {{$}}
+// WEBASSEMBLY32:#define __UINT16_FMTX__ "hX"
+// WEBASSEMBLY32:#define __UINT16_FMTo__ "ho"
+// WEBASSEMBLY32:#define __UINT16_FMTu__ "hu"
+// WEBASSEMBLY32:#define __UINT16_FMTx__ "hx"
+// WEBASSEMBLY32:#define __UINT16_MAX__ 65535
+// WEBASSEMBLY32:#define __UINT16_TYPE__ unsigned short
+// WEBASSEMBLY32:#define __UINT32_C_SUFFIX__ U
+// WEBASSEMBLY32:#define __UINT32_FMTX__ "X"
+// WEBASSEMBLY32:#define __UINT32_FMTo__ "o"
+// WEBASSEMBLY32:#define __UINT32_FMTu__ "u"
+// WEBASSEMBLY32:#define __UINT32_FMTx__ "x"
+// WEBASSEMBLY32:#define __UINT32_MAX__ 4294967295U
+// WEBASSEMBLY32:#define __UINT32_TYPE__ unsigned int
+// WEBASSEMBLY32:#define __UINT64_C_SUFFIX__ ULL
+// WEBASSEMBLY32:#define __UINT64_FMTX__ "llX"
+// WEBASSEMBLY32:#define __UINT64_FMTo__ "llo"
+// WEBASSEMBLY32:#define __UINT64_FMTu__ "llu"
+// WEBASSEMBLY32:#define __UINT64_FMTx__ "llx"
+// WEBASSEMBLY32:#define __UINT64_MAX__ 18446744073709551615ULL
+// WEBASSEMBLY32:#define __UINT64_TYPE__ long long unsigned int
+// WEBASSEMBLY32:#define __UINT8_C_SUFFIX__ {{$}}
+// WEBASSEMBLY32:#define __UINT8_FMTX__ "hhX"
+// WEBASSEMBLY32:#define __UINT8_FMTo__ "hho"
+// WEBASSEMBLY32:#define __UINT8_FMTu__ "hhu"
+// WEBASSEMBLY32:#define __UINT8_FMTx__ "hhx"
+// WEBASSEMBLY32:#define __UINT8_MAX__ 255
+// WEBASSEMBLY32:#define __UINT8_TYPE__ unsigned char
+// WEBASSEMBLY32:#define __UINTMAX_C_SUFFIX__ ULL
+// WEBASSEMBLY32:#define __UINTMAX_FMTX__ "llX"
+// WEBASSEMBLY32:#define __UINTMAX_FMTo__ "llo"
+// WEBASSEMBLY32:#define __UINTMAX_FMTu__ "llu"
+// WEBASSEMBLY32:#define __UINTMAX_FMTx__ "llx"
+// WEBASSEMBLY32:#define __UINTMAX_MAX__ 18446744073709551615ULL
+// WEBASSEMBLY32:#define __UINTMAX_TYPE__ long long unsigned int
+// WEBASSEMBLY32:#define __UINTMAX_WIDTH__ 64
+// WEBASSEMBLY32:#define __UINTPTR_FMTX__ "lX"
+// WEBASSEMBLY32:#define __UINTPTR_FMTo__ "lo"
+// WEBASSEMBLY32:#define __UINTPTR_FMTu__ "lu"
+// WEBASSEMBLY32:#define __UINTPTR_FMTx__ "lx"
+// WEBASSEMBLY32:#define __UINTPTR_MAX__ 4294967295UL
+// WEBASSEMBLY32:#define __UINTPTR_TYPE__ long unsigned int
+// WEBASSEMBLY32:#define __UINTPTR_WIDTH__ 32
+// WEBASSEMBLY32:#define __UINT_FAST16_FMTX__ "hX"
+// WEBASSEMBLY32:#define __UINT_FAST16_FMTo__ "ho"
+// WEBASSEMBLY32:#define __UINT_FAST16_FMTu__ "hu"
+// WEBASSEMBLY32:#define __UINT_FAST16_FMTx__ "hx"
+// WEBASSEMBLY32:#define __UINT_FAST16_MAX__ 65535
+// WEBASSEMBLY32:#define __UINT_FAST16_TYPE__ unsigned short
+// WEBASSEMBLY32:#define __UINT_FAST32_FMTX__ "X"
+// WEBASSEMBLY32:#define __UINT_FAST32_FMTo__ "o"
+// WEBASSEMBLY32:#define __UINT_FAST32_FMTu__ "u"
+// WEBASSEMBLY32:#define __UINT_FAST32_FMTx__ "x"
+// WEBASSEMBLY32:#define __UINT_FAST32_MAX__ 4294967295U
+// WEBASSEMBLY32:#define __UINT_FAST32_TYPE__ unsigned int
+// WEBASSEMBLY32:#define __UINT_FAST64_FMTX__ "llX"
+// WEBASSEMBLY32:#define __UINT_FAST64_FMTo__ "llo"
+// WEBASSEMBLY32:#define __UINT_FAST64_FMTu__ "llu"
+// WEBASSEMBLY32:#define __UINT_FAST64_FMTx__ "llx"
+// WEBASSEMBLY32:#define __UINT_FAST64_MAX__ 18446744073709551615ULL
+// WEBASSEMBLY32:#define __UINT_FAST64_TYPE__ long long unsigned int
+// WEBASSEMBLY32:#define __UINT_FAST8_FMTX__ "hhX"
+// WEBASSEMBLY32:#define __UINT_FAST8_FMTo__ "hho"
+// WEBASSEMBLY32:#define __UINT_FAST8_FMTu__ "hhu"
+// WEBASSEMBLY32:#define __UINT_FAST8_FMTx__ "hhx"
+// WEBASSEMBLY32:#define __UINT_FAST8_MAX__ 255
+// WEBASSEMBLY32:#define __UINT_FAST8_TYPE__ unsigned char
+// WEBASSEMBLY32:#define __UINT_LEAST16_FMTX__ "hX"
+// WEBASSEMBLY32:#define __UINT_LEAST16_FMTo__ "ho"
+// WEBASSEMBLY32:#define __UINT_LEAST16_FMTu__ "hu"
+// WEBASSEMBLY32:#define __UINT_LEAST16_FMTx__ "hx"
+// WEBASSEMBLY32:#define __UINT_LEAST16_MAX__ 65535
+// WEBASSEMBLY32:#define __UINT_LEAST16_TYPE__ unsigned short
+// WEBASSEMBLY32:#define __UINT_LEAST32_FMTX__ "X"
+// WEBASSEMBLY32:#define __UINT_LEAST32_FMTo__ "o"
+// WEBASSEMBLY32:#define __UINT_LEAST32_FMTu__ "u"
+// WEBASSEMBLY32:#define __UINT_LEAST32_FMTx__ "x"
+// WEBASSEMBLY32:#define __UINT_LEAST32_MAX__ 4294967295U
+// WEBASSEMBLY32:#define __UINT_LEAST32_TYPE__ unsigned int
+// WEBASSEMBLY32:#define __UINT_LEAST64_FMTX__ "llX"
+// WEBASSEMBLY32:#define __UINT_LEAST64_FMTo__ "llo"
+// WEBASSEMBLY32:#define __UINT_LEAST64_FMTu__ "llu"
+// WEBASSEMBLY32:#define __UINT_LEAST64_FMTx__ "llx"
+// WEBASSEMBLY32:#define __UINT_LEAST64_MAX__ 18446744073709551615ULL
+// WEBASSEMBLY32:#define __UINT_LEAST64_TYPE__ long long unsigned int
+// WEBASSEMBLY32:#define __UINT_LEAST8_FMTX__ "hhX"
+// WEBASSEMBLY32:#define __UINT_LEAST8_FMTo__ "hho"
+// WEBASSEMBLY32:#define __UINT_LEAST8_FMTu__ "hhu"
+// WEBASSEMBLY32:#define __UINT_LEAST8_FMTx__ "hhx"
+// WEBASSEMBLY32:#define __UINT_LEAST8_MAX__ 255
+// WEBASSEMBLY32:#define __UINT_LEAST8_TYPE__ unsigned char
+// WEBASSEMBLY32:#define __USER_LABEL_PREFIX__ {{$}}
+// WEBASSEMBLY32:#define __VERSION__
+// WEBASSEMBLY32:#define __WCHAR_MAX__ 2147483647
+// WEBASSEMBLY32:#define __WCHAR_TYPE__ int
+// WEBASSEMBLY32:#define __WCHAR_WIDTH__ 32
+// WEBASSEMBLY32:#define __WINT_TYPE__ int
+// WEBASSEMBLY32-NOT: #define __WINT_UNSIGNED__
+// WEBASSEMBLY32:#define __WINT_WIDTH__ 32
+// WEBASSEMBLY32:#define __clang__ 1
+// WEBASSEMBLY32:#define __clang_major__
+// WEBASSEMBLY32:#define __clang_minor__
+// WEBASSEMBLY32:#define __clang_patchlevel__
+// WEBASSEMBLY32:#define __clang_version__
+// WEBASSEMBLY32:#define __llvm__ 1
+// WEBASSEMBLY32-NOT:#define __unix
+// WEBASSEMBLY32-NOT:#define __unix__
+// WEBASSEMBLY32:#define __wasm 1
+// WEBASSEMBLY32:#define __wasm32 1
+// WEBASSEMBLY32:#define __wasm32__ 1
+// WEBASSEMBLY32:#define __wasm__ 1
+//
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=wasm64-unknown-unknown < /dev/null | FileCheck -check-prefix=WEBASSEMBLY64 %s
+//
+// WEBASSEMBLY64-NOT:#define _ILP32
+// WEBASSEMBLY64:#define _LP64 1
+// WEBASSEMBLY64:#define __ATOMIC_ACQUIRE 2
+// WEBASSEMBLY64:#define __ATOMIC_ACQ_REL 4
+// WEBASSEMBLY64:#define __ATOMIC_CONSUME 1
+// WEBASSEMBLY64:#define __ATOMIC_RELAXED 0
+// WEBASSEMBLY64:#define __ATOMIC_RELEASE 3
+// WEBASSEMBLY64:#define __ATOMIC_SEQ_CST 5
+// WEBASSEMBLY64:#define __BIGGEST_ALIGNMENT__ 16
+// WEBASSEMBLY64:#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+// WEBASSEMBLY64:#define __CHAR16_TYPE__ unsigned short
+// WEBASSEMBLY64:#define __CHAR32_TYPE__ unsigned int
+// WEBASSEMBLY64:#define __CHAR_BIT__ 8
+// WEBASSEMBLY64:#define __CONSTANT_CFSTRINGS__ 1
+// WEBASSEMBLY64:#define __DBL_DECIMAL_DIG__ 17
+// WEBASSEMBLY64:#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
+// WEBASSEMBLY64:#define __DBL_DIG__ 15
+// WEBASSEMBLY64:#define __DBL_EPSILON__ 2.2204460492503131e-16
+// WEBASSEMBLY64:#define __DBL_HAS_DENORM__ 1
+// WEBASSEMBLY64:#define __DBL_HAS_INFINITY__ 1
+// WEBASSEMBLY64:#define __DBL_HAS_QUIET_NAN__ 1
+// WEBASSEMBLY64:#define __DBL_MANT_DIG__ 53
+// WEBASSEMBLY64:#define __DBL_MAX_10_EXP__ 308
+// WEBASSEMBLY64:#define __DBL_MAX_EXP__ 1024
+// WEBASSEMBLY64:#define __DBL_MAX__ 1.7976931348623157e+308
+// WEBASSEMBLY64:#define __DBL_MIN_10_EXP__ (-307)
+// WEBASSEMBLY64:#define __DBL_MIN_EXP__ (-1021)
+// WEBASSEMBLY64:#define __DBL_MIN__ 2.2250738585072014e-308
+// WEBASSEMBLY64:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
+// WEBASSEMBLY64:#define __FINITE_MATH_ONLY__ 0
+// WEBASSEMBLY64:#define __FLT_DECIMAL_DIG__ 9
+// WEBASSEMBLY64:#define __FLT_DENORM_MIN__ 1.40129846e-45F
+// WEBASSEMBLY64:#define __FLT_DIG__ 6
+// WEBASSEMBLY64:#define __FLT_EPSILON__ 1.19209290e-7F
+// WEBASSEMBLY64:#define __FLT_EVAL_METHOD__ 0
+// WEBASSEMBLY64:#define __FLT_HAS_DENORM__ 1
+// WEBASSEMBLY64:#define __FLT_HAS_INFINITY__ 1
+// WEBASSEMBLY64:#define __FLT_HAS_QUIET_NAN__ 1
+// WEBASSEMBLY64:#define __FLT_MANT_DIG__ 24
+// WEBASSEMBLY64:#define __FLT_MAX_10_EXP__ 38
+// WEBASSEMBLY64:#define __FLT_MAX_EXP__ 128
+// WEBASSEMBLY64:#define __FLT_MAX__ 3.40282347e+38F
+// WEBASSEMBLY64:#define __FLT_MIN_10_EXP__ (-37)
+// WEBASSEMBLY64:#define __FLT_MIN_EXP__ (-125)
+// WEBASSEMBLY64:#define __FLT_MIN__ 1.17549435e-38F
+// WEBASSEMBLY64:#define __FLT_RADIX__ 2
+// WEBASSEMBLY64:#define __GCC_ATOMIC_BOOL_LOCK_FREE 2
+// WEBASSEMBLY64:#define __GCC_ATOMIC_CHAR16_T_LOCK_FREE 2
+// WEBASSEMBLY64:#define __GCC_ATOMIC_CHAR32_T_LOCK_FREE 2
+// WEBASSEMBLY64:#define __GCC_ATOMIC_CHAR_LOCK_FREE 2
+// WEBASSEMBLY64:#define __GCC_ATOMIC_INT_LOCK_FREE 2
+// WEBASSEMBLY64:#define __GCC_ATOMIC_LLONG_LOCK_FREE 2
+// WEBASSEMBLY64:#define __GCC_ATOMIC_LONG_LOCK_FREE 2
+// WEBASSEMBLY64:#define __GCC_ATOMIC_POINTER_LOCK_FREE 2
+// WEBASSEMBLY64:#define __GCC_ATOMIC_SHORT_LOCK_FREE 2
+// WEBASSEMBLY64:#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1
+// WEBASSEMBLY64:#define __GCC_ATOMIC_WCHAR_T_LOCK_FREE 2
+// WEBASSEMBLY64:#define __GNUC_MINOR__
+// WEBASSEMBLY64:#define __GNUC_PATCHLEVEL__
+// WEBASSEMBLY64:#define __GNUC_STDC_INLINE__ 1
+// WEBASSEMBLY64:#define __GNUC__
+// WEBASSEMBLY64:#define __GXX_ABI_VERSION 1002
+// WEBASSEMBLY64:#define __GXX_RTTI 1
+// WEBASSEMBLY64-NOT:#define __ILP32__ 1
+// WEBASSEMBLY64:#define __INT16_C_SUFFIX__ {{$}}
+// WEBASSEMBLY64:#define __INT16_FMTd__ "hd"
+// WEBASSEMBLY64:#define __INT16_FMTi__ "hi"
+// WEBASSEMBLY64:#define __INT16_MAX__ 32767
+// WEBASSEMBLY64:#define __INT16_TYPE__ short
+// WEBASSEMBLY64:#define __INT32_C_SUFFIX__ {{$}}
+// WEBASSEMBLY64:#define __INT32_FMTd__ "d"
+// WEBASSEMBLY64:#define __INT32_FMTi__ "i"
+// WEBASSEMBLY64:#define __INT32_MAX__ 2147483647
+// WEBASSEMBLY64:#define __INT32_TYPE__ int
+// WEBASSEMBLY64:#define __INT64_C_SUFFIX__ L
+// WEBASSEMBLY64:#define __INT64_FMTd__ "lld"
+// WEBASSEMBLY64:#define __INT64_FMTi__ "lli"
+// WEBASSEMBLY64:#define __INT64_MAX__ 9223372036854775807LL
+// WEBASSEMBLY64:#define __INT64_TYPE__ long long int
+// WEBASSEMBLY64:#define __INT8_C_SUFFIX__ {{$}}
+// WEBASSEMBLY64:#define __INT8_FMTd__ "hhd"
+// WEBASSEMBLY64:#define __INT8_FMTi__ "hhi"
+// WEBASSEMBLY64:#define __INT8_MAX__ 127
+// WEBASSEMBLY64:#define __INT8_TYPE__ signed char
+// WEBASSEMBLY64:#define __INTMAX_C_SUFFIX__ LL
+// WEBASSEMBLY64:#define __INTMAX_FMTd__ "lld"
+// WEBASSEMBLY64:#define __INTMAX_FMTi__ "lli"
+// WEBASSEMBLY64:#define __INTMAX_MAX__ 9223372036854775807LL
+// WEBASSEMBLY64:#define __INTMAX_TYPE__ long long int
+// WEBASSEMBLY64:#define __INTMAX_WIDTH__ 64
+// WEBASSEMBLY64:#define __INTPTR_FMTd__ "ld"
+// WEBASSEMBLY64:#define __INTPTR_FMTi__ "li"
+// WEBASSEMBLY64:#define __INTPTR_MAX__ 9223372036854775807L
+// WEBASSEMBLY64:#define __INTPTR_TYPE__ long
+// WEBASSEMBLY64:#define __INTPTR_WIDTH__ 64
+// WEBASSEMBLY64:#define __INT_FAST16_FMTd__ "hd"
+// WEBASSEMBLY64:#define __INT_FAST16_FMTi__ "hi"
+// WEBASSEMBLY64:#define __INT_FAST16_MAX__ 32767
+// WEBASSEMBLY64:#define __INT_FAST16_TYPE__ short
+// WEBASSEMBLY64:#define __INT_FAST32_FMTd__ "d"
+// WEBASSEMBLY64:#define __INT_FAST32_FMTi__ "i"
+// WEBASSEMBLY64:#define __INT_FAST32_MAX__ 2147483647
+// WEBASSEMBLY64:#define __INT_FAST32_TYPE__ int
+// WEBASSEMBLY64:#define __INT_FAST64_FMTd__ "ld"
+// WEBASSEMBLY64:#define __INT_FAST64_FMTi__ "li"
+// WEBASSEMBLY64:#define __INT_FAST64_MAX__ 9223372036854775807L
+// WEBASSEMBLY64:#define __INT_FAST64_TYPE__ long int
+// WEBASSEMBLY64:#define __INT_FAST8_FMTd__ "hhd"
+// WEBASSEMBLY64:#define __INT_FAST8_FMTi__ "hhi"
+// WEBASSEMBLY64:#define __INT_FAST8_MAX__ 127
+// WEBASSEMBLY64:#define __INT_FAST8_TYPE__ signed char
+// WEBASSEMBLY64:#define __INT_LEAST16_FMTd__ "hd"
+// WEBASSEMBLY64:#define __INT_LEAST16_FMTi__ "hi"
+// WEBASSEMBLY64:#define __INT_LEAST16_MAX__ 32767
+// WEBASSEMBLY64:#define __INT_LEAST16_TYPE__ short
+// WEBASSEMBLY64:#define __INT_LEAST32_FMTd__ "d"
+// WEBASSEMBLY64:#define __INT_LEAST32_FMTi__ "i"
+// WEBASSEMBLY64:#define __INT_LEAST32_MAX__ 2147483647
+// WEBASSEMBLY64:#define __INT_LEAST32_TYPE__ int
+// WEBASSEMBLY64:#define __INT_LEAST64_FMTd__ "ld"
+// WEBASSEMBLY64:#define __INT_LEAST64_FMTi__ "li"
+// WEBASSEMBLY64:#define __INT_LEAST64_MAX__ 9223372036854775807L
+// WEBASSEMBLY64:#define __INT_LEAST64_TYPE__ long int
+// WEBASSEMBLY64:#define __INT_LEAST8_FMTd__ "hhd"
+// WEBASSEMBLY64:#define __INT_LEAST8_FMTi__ "hhi"
+// WEBASSEMBLY64:#define __INT_LEAST8_MAX__ 127
+// WEBASSEMBLY64:#define __INT_LEAST8_TYPE__ signed char
+// WEBASSEMBLY64:#define __INT_MAX__ 2147483647
+// WEBASSEMBLY64:#define __LDBL_DECIMAL_DIG__ 17
+// WEBASSEMBLY64:#define __LDBL_DENORM_MIN__ 4.9406564584124654e-324L
+// WEBASSEMBLY64:#define __LDBL_DIG__ 15
+// WEBASSEMBLY64:#define __LDBL_EPSILON__ 2.2204460492503131e-16L
+// WEBASSEMBLY64:#define __LDBL_HAS_DENORM__ 1
+// WEBASSEMBLY64:#define __LDBL_HAS_INFINITY__ 1
+// WEBASSEMBLY64:#define __LDBL_HAS_QUIET_NAN__ 1
+// WEBASSEMBLY64:#define __LDBL_MANT_DIG__ 53
+// WEBASSEMBLY64:#define __LDBL_MAX_10_EXP__ 308
+// WEBASSEMBLY64:#define __LDBL_MAX_EXP__ 1024
+// WEBASSEMBLY64:#define __LDBL_MAX__ 1.7976931348623157e+308L
+// WEBASSEMBLY64:#define __LDBL_MIN_10_EXP__ (-307)
+// WEBASSEMBLY64:#define __LDBL_MIN_EXP__ (-1021)
+// WEBASSEMBLY64:#define __LDBL_MIN__ 2.2250738585072014e-308L
+// WEBASSEMBLY64:#define __LITTLE_ENDIAN__ 1
+// WEBASSEMBLY64:#define __LONG_LONG_MAX__ 9223372036854775807LL
+// WEBASSEMBLY64:#define __LONG_MAX__ 9223372036854775807L
+// WEBASSEMBLY64:#define __LP64__
+// WEBASSEMBLY64:#define __NO_INLINE__ 1
+// WEBASSEMBLY64:#define __ORDER_BIG_ENDIAN__ 4321
+// WEBASSEMBLY64:#define __ORDER_LITTLE_ENDIAN__ 1234
+// WEBASSEMBLY64:#define __ORDER_PDP_ENDIAN__ 3412
+// WEBASSEMBLY64:#define __POINTER_WIDTH__ 64
+// WEBASSEMBLY64:#define __PRAGMA_REDEFINE_EXTNAME 1
+// WEBASSEMBLY64:#define __PTRDIFF_FMTd__ "ld"
+// WEBASSEMBLY64:#define __PTRDIFF_FMTi__ "li"
+// WEBASSEMBLY64:#define __PTRDIFF_MAX__ 9223372036854775807L
+// WEBASSEMBLY64:#define __PTRDIFF_TYPE__ long
+// WEBASSEMBLY64:#define __PTRDIFF_WIDTH__ 64
+// WEBASSEMBLY64:#define __REGISTER_PREFIX__ {{$}}
+// WEBASSEMBLY64:#define __SCHAR_MAX__ 127
+// WEBASSEMBLY64:#define __SHRT_MAX__ 32767
+// WEBASSEMBLY64:#define __SIG_ATOMIC_MAX__ 2147483647
+// WEBASSEMBLY64:#define __SIG_ATOMIC_WIDTH__ 32
+// WEBASSEMBLY64:#define __SIZEOF_DOUBLE__ 8
+// WEBASSEMBLY64:#define __SIZEOF_FLOAT__ 4
+// WEBASSEMBLY64:#define __SIZEOF_INT__ 4
+// WEBASSEMBLY64:#define __SIZEOF_LONG_DOUBLE__ 8
+// WEBASSEMBLY64:#define __SIZEOF_LONG_LONG__ 8
+// WEBASSEMBLY64:#define __SIZEOF_LONG__ 8
+// WEBASSEMBLY64:#define __SIZEOF_POINTER__ 8
+// WEBASSEMBLY64:#define __SIZEOF_PTRDIFF_T__ 8
+// WEBASSEMBLY64:#define __SIZEOF_SHORT__ 2
+// WEBASSEMBLY64:#define __SIZEOF_SIZE_T__ 8
+// WEBASSEMBLY64:#define __SIZEOF_WCHAR_T__ 4
+// WEBASSEMBLY64:#define __SIZEOF_WINT_T__ 4
+// WEBASSEMBLY64:#define __SIZE_FMTX__ "lX"
+// WEBASSEMBLY64:#define __SIZE_FMTo__ "lo"
+// WEBASSEMBLY64:#define __SIZE_FMTu__ "lu"
+// WEBASSEMBLY64:#define __SIZE_FMTx__ "lx"
+// WEBASSEMBLY64:#define __SIZE_MAX__ 18446744073709551615UL
+// WEBASSEMBLY64:#define __SIZE_TYPE__ long unsigned int
+// WEBASSEMBLY64:#define __SIZE_WIDTH__ 64
+// WEBASSEMBLY64:#define __STDC_HOSTED__ 0
+// WEBASSEMBLY64:#define __STDC_UTF_16__ 1
+// WEBASSEMBLY64:#define __STDC_UTF_32__ 1
+// WEBASSEMBLY64:#define __STDC_VERSION__ 201112L
+// WEBASSEMBLY64:#define __STDC__ 1
+// WEBASSEMBLY64:#define __UINT16_C_SUFFIX__ {{$}}
+// WEBASSEMBLY64:#define __UINT16_FMTX__ "hX"
+// WEBASSEMBLY64:#define __UINT16_FMTo__ "ho"
+// WEBASSEMBLY64:#define __UINT16_FMTu__ "hu"
+// WEBASSEMBLY64:#define __UINT16_FMTx__ "hx"
+// WEBASSEMBLY64:#define __UINT16_MAX__ 65535
+// WEBASSEMBLY64:#define __UINT16_TYPE__ unsigned short
+// WEBASSEMBLY64:#define __UINT32_C_SUFFIX__ U
+// WEBASSEMBLY64:#define __UINT32_FMTX__ "X"
+// WEBASSEMBLY64:#define __UINT32_FMTo__ "o"
+// WEBASSEMBLY64:#define __UINT32_FMTu__ "u"
+// WEBASSEMBLY64:#define __UINT32_FMTx__ "x"
+// WEBASSEMBLY64:#define __UINT32_MAX__ 4294967295U
+// WEBASSEMBLY64:#define __UINT32_TYPE__ unsigned int
+// WEBASSEMBLY64:#define __UINT64_C_SUFFIX__ UL
+// WEBASSEMBLY64:#define __UINT64_FMTX__ "llX"
+// WEBASSEMBLY64:#define __UINT64_FMTo__ "llo"
+// WEBASSEMBLY64:#define __UINT64_FMTu__ "llu"
+// WEBASSEMBLY64:#define __UINT64_FMTx__ "llx"
+// WEBASSEMBLY64:#define __UINT64_MAX__ 18446744073709551615ULL
+// WEBASSEMBLY64:#define __UINT64_TYPE__ long long unsigned int
+// WEBASSEMBLY64:#define __UINT8_C_SUFFIX__ {{$}}
+// WEBASSEMBLY64:#define __UINT8_FMTX__ "hhX"
+// WEBASSEMBLY64:#define __UINT8_FMTo__ "hho"
+// WEBASSEMBLY64:#define __UINT8_FMTu__ "hhu"
+// WEBASSEMBLY64:#define __UINT8_FMTx__ "hhx"
+// WEBASSEMBLY64:#define __UINT8_MAX__ 255
+// WEBASSEMBLY64:#define __UINT8_TYPE__ unsigned char
+// WEBASSEMBLY64:#define __UINTMAX_C_SUFFIX__ ULL
+// WEBASSEMBLY64:#define __UINTMAX_FMTX__ "llX"
+// WEBASSEMBLY64:#define __UINTMAX_FMTo__ "llo"
+// WEBASSEMBLY64:#define __UINTMAX_FMTu__ "llu"
+// WEBASSEMBLY64:#define __UINTMAX_FMTx__ "llx"
+// WEBASSEMBLY64:#define __UINTMAX_MAX__ 18446744073709551615ULL
+// WEBASSEMBLY64:#define __UINTMAX_TYPE__ long long unsigned int
+// WEBASSEMBLY64:#define __UINTMAX_WIDTH__ 64
+// WEBASSEMBLY64:#define __UINTPTR_FMTX__ "lX"
+// WEBASSEMBLY64:#define __UINTPTR_FMTo__ "lo"
+// WEBASSEMBLY64:#define __UINTPTR_FMTu__ "lu"
+// WEBASSEMBLY64:#define __UINTPTR_FMTx__ "lx"
+// WEBASSEMBLY64:#define __UINTPTR_MAX__ 18446744073709551615UL
+// WEBASSEMBLY64:#define __UINTPTR_TYPE__ long unsigned int
+// WEBASSEMBLY64:#define __UINTPTR_WIDTH__ 64
+// WEBASSEMBLY64:#define __UINT_FAST16_FMTX__ "hX"
+// WEBASSEMBLY64:#define __UINT_FAST16_FMTo__ "ho"
+// WEBASSEMBLY64:#define __UINT_FAST16_FMTu__ "hu"
+// WEBASSEMBLY64:#define __UINT_FAST16_FMTx__ "hx"
+// WEBASSEMBLY64:#define __UINT_FAST16_MAX__ 65535
+// WEBASSEMBLY64:#define __UINT_FAST16_TYPE__ unsigned short
+// WEBASSEMBLY64:#define __UINT_FAST32_FMTX__ "X"
+// WEBASSEMBLY64:#define __UINT_FAST32_FMTo__ "o"
+// WEBASSEMBLY64:#define __UINT_FAST32_FMTu__ "u"
+// WEBASSEMBLY64:#define __UINT_FAST32_FMTx__ "x"
+// WEBASSEMBLY64:#define __UINT_FAST32_MAX__ 4294967295U
+// WEBASSEMBLY64:#define __UINT_FAST32_TYPE__ unsigned int
+// WEBASSEMBLY64:#define __UINT_FAST64_FMTX__ "lX"
+// WEBASSEMBLY64:#define __UINT_FAST64_FMTo__ "lo"
+// WEBASSEMBLY64:#define __UINT_FAST64_FMTu__ "lu"
+// WEBASSEMBLY64:#define __UINT_FAST64_FMTx__ "lx"
+// WEBASSEMBLY64:#define __UINT_FAST64_MAX__ 18446744073709551615UL
+// WEBASSEMBLY64:#define __UINT_FAST64_TYPE__ long unsigned int
+// WEBASSEMBLY64:#define __UINT_FAST8_FMTX__ "hhX"
+// WEBASSEMBLY64:#define __UINT_FAST8_FMTo__ "hho"
+// WEBASSEMBLY64:#define __UINT_FAST8_FMTu__ "hhu"
+// WEBASSEMBLY64:#define __UINT_FAST8_FMTx__ "hhx"
+// WEBASSEMBLY64:#define __UINT_FAST8_MAX__ 255
+// WEBASSEMBLY64:#define __UINT_FAST8_TYPE__ unsigned char
+// WEBASSEMBLY64:#define __UINT_LEAST16_FMTX__ "hX"
+// WEBASSEMBLY64:#define __UINT_LEAST16_FMTo__ "ho"
+// WEBASSEMBLY64:#define __UINT_LEAST16_FMTu__ "hu"
+// WEBASSEMBLY64:#define __UINT_LEAST16_FMTx__ "hx"
+// WEBASSEMBLY64:#define __UINT_LEAST16_MAX__ 65535
+// WEBASSEMBLY64:#define __UINT_LEAST16_TYPE__ unsigned short
+// WEBASSEMBLY64:#define __UINT_LEAST32_FMTX__ "X"
+// WEBASSEMBLY64:#define __UINT_LEAST32_FMTo__ "o"
+// WEBASSEMBLY64:#define __UINT_LEAST32_FMTu__ "u"
+// WEBASSEMBLY64:#define __UINT_LEAST32_FMTx__ "x"
+// WEBASSEMBLY64:#define __UINT_LEAST32_MAX__ 4294967295U
+// WEBASSEMBLY64:#define __UINT_LEAST32_TYPE__ unsigned int
+// WEBASSEMBLY64:#define __UINT_LEAST64_FMTX__ "lX"
+// WEBASSEMBLY64:#define __UINT_LEAST64_FMTo__ "lo"
+// WEBASSEMBLY64:#define __UINT_LEAST64_FMTu__ "lu"
+// WEBASSEMBLY64:#define __UINT_LEAST64_FMTx__ "lx"
+// WEBASSEMBLY64:#define __UINT_LEAST64_MAX__ 18446744073709551615UL
+// WEBASSEMBLY64:#define __UINT_LEAST64_TYPE__ long unsigned int
+// WEBASSEMBLY64:#define __UINT_LEAST8_FMTX__ "hhX"
+// WEBASSEMBLY64:#define __UINT_LEAST8_FMTo__ "hho"
+// WEBASSEMBLY64:#define __UINT_LEAST8_FMTu__ "hhu"
+// WEBASSEMBLY64:#define __UINT_LEAST8_FMTx__ "hhx"
+// WEBASSEMBLY64:#define __UINT_LEAST8_MAX__ 255
+// WEBASSEMBLY64:#define __UINT_LEAST8_TYPE__ unsigned char
+// WEBASSEMBLY64:#define __USER_LABEL_PREFIX__ {{$}}
+// WEBASSEMBLY64:#define __VERSION__
+// WEBASSEMBLY64:#define __WCHAR_MAX__ 2147483647
+// WEBASSEMBLY64:#define __WCHAR_TYPE__ int
+// WEBASSEMBLY64:#define __WCHAR_WIDTH__ 32
+// WEBASSEMBLY64:#define __WINT_TYPE__ int
+// WEBASSEMBLY64-NOT: #define __WINT_UNSIGNED__
+// WEBASSEMBLY64:#define __WINT_WIDTH__ 32
+// WEBASSEMBLY64:#define __clang__ 1
+// WEBASSEMBLY64:#define __clang_major__
+// WEBASSEMBLY64:#define __clang_minor__
+// WEBASSEMBLY64:#define __clang_patchlevel__
+// WEBASSEMBLY64:#define __clang_version__
+// WEBASSEMBLY64:#define __llvm__ 1
+// WEBASSEMBLY64-NOT:#define __unix
+// WEBASSEMBLY64-NOT:#define __unix__
+// WEBASSEMBLY64:#define __wasm 1
+// WEBASSEMBLY64:#define __wasm64 1
+// WEBASSEMBLY64:#define __wasm64__ 1
+// WEBASSEMBLY64:#define __wasm__ 1
Index: test/Driver/wasm64-unknown-unknown.cpp
===================================================================
--- test/Driver/wasm64-unknown-unknown.cpp
+++ test/Driver/wasm64-unknown-unknown.cpp
@@ -0,0 +1,126 @@
+// RUN: %clang -target wasm64-unknown-unknown -### %s -emit-llvm-only -c 2>&1 | FileCheck %s -check-prefix=ECHO
+// RUN: %clang -target wasm64-unknown-unknown %s -emit-llvm -S -c -o - | FileCheck %s
+// RUN: %clang -target wasm64-unknown-unknown %s -emit-llvm -S -c -pthread -o - | FileCheck %s -check-prefix=THREADS
+
+// ECHO: {{.*}} "-cc1" {{.*}}wasm64-unknown-unknown.c
+
+typedef __builtin_va_list va_list;
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+
+extern "C" {
+
+// CHECK: @align_c = global i32 1
+int align_c = __alignof(char);
+
+// CHECK: @align_s = global i32 2
+int align_s = __alignof(short);
+
+// CHECK: @align_i = global i32 4
+int align_i = __alignof(int);
+
+// CHECK: @align_l = global i32 8
+int align_l = __alignof(long);
+
+// CHECK: @align_ll = global i32 8
+int align_ll = __alignof(long long);
+
+// CHECK: @align_p = global i32 8
+int align_p = __alignof(void*);
+
+// CHECK: @align_f = global i32 4
+int align_f = __alignof(float);
+
+// CHECK: @align_d = global i32 8
+int align_d = __alignof(double);
+
+// CHECK: @align_ld = global i32 8
+int align_ld = __alignof(long double);
+
+// CHECK: @align_vl = global i32 8
+int align_vl = __alignof(va_list);
+
+// CHECK: __LITTLE_ENDIAN__defined
+#ifdef __LITTLE_ENDIAN__
+void __LITTLE_ENDIAN__defined() {}
+#endif
+
+// CHECK: __wasm__defined
+#ifdef __wasm__
+void __wasm__defined() {}
+#endif
+
+// CHECK: _GNU_SOURCEdefined
+#ifdef _GNU_SOURCE
+void _GNU_SOURCEdefined() {}
+#endif
+
+// THREADS: _REENTRANTdefined
+// CHECK: _REENTRANTundefined
+#ifdef _REENTRANT
+void _REENTRANTdefined() {}
+#else
+void _REENTRANTundefined() {}
+#endif
+
+// Check types
+
+// CHECK: signext i8 @check_char()
+char check_char() { return 0; }
+
+// CHECK: signext i16 @check_short()
+short check_short() { return 0; }
+
+// CHECK: i32 @check_int()
+int check_int() { return 0; }
+
+// CHECK: i64 @check_long()
+long check_long() { return 0; }
+
+// CHECK: i64 @check_longlong()
+long long check_longlong() { return 0; }
+
+// CHECK: zeroext i8 @check_uchar()
+unsigned char check_uchar() { return 0; }
+
+// CHECK: zeroext i16 @check_ushort()
+unsigned short check_ushort() { return 0; }
+
+// CHECK: i32 @check_uint()
+unsigned int check_uint() { return 0; }
+
+// CHECK: i64 @check_ulong()
+unsigned long check_ulong() { return 0; }
+
+// CHECK: i64 @check_ulonglong()
+unsigned long long check_ulonglong() { return 0; }
+
+// CHECK: i64 @check_size_t()
+size_t check_size_t() { return 0; }
+
+// CHECK: float @check_float()
+float check_float() { return 0; }
+
+// CHECK: double @check_double()
+double check_double() { return 0; }
+
+// CHECK: double @check_longdouble()
+long double check_longdouble() { return 0; }
+
+}
+
+template<int> void Switch();
+template<> void Switch<4>();
+template<> void Switch<8>();
+template<> void Switch<16>();
+
+void check_pointer_size() {
+  // CHECK: SwitchILi8
+  Switch<sizeof(void*)>();
+
+  // CHECK: SwitchILi8
+  Switch<sizeof(long long)>();
+
+  // CHECK: SwitchILi8
+  Switch<sizeof(va_list)>();
+}
Index: test/Driver/wasm32-unknown-unknown.cpp
===================================================================
--- test/Driver/wasm32-unknown-unknown.cpp
+++ test/Driver/wasm32-unknown-unknown.cpp
@@ -0,0 +1,126 @@
+// RUN: %clang -target wasm32-unknown-unknown -### %s -emit-llvm-only -c 2>&1 | FileCheck %s -check-prefix=ECHO
+// RUN: %clang -target wasm32-unknown-unknown %s -emit-llvm -S -c -o - | FileCheck %s
+// RUN: %clang -target wasm32-unknown-unknown %s -emit-llvm -S -c -pthread -o - | FileCheck %s -check-prefix=THREADS
+
+// ECHO: {{.*}} "-cc1" {{.*}}wasm32-unknown-unknown.c
+
+typedef __builtin_va_list va_list;
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+
+extern "C" {
+
+// CHECK: @align_c = global i32 1
+int align_c = __alignof(char);
+
+// CHECK: @align_s = global i32 2
+int align_s = __alignof(short);
+
+// CHECK: @align_i = global i32 4
+int align_i = __alignof(int);
+
+// CHECK: @align_l = global i32 4
+int align_l = __alignof(long);
+
+// CHECK: @align_ll = global i32 8
+int align_ll = __alignof(long long);
+
+// CHECK: @align_p = global i32 4
+int align_p = __alignof(void*);
+
+// CHECK: @align_f = global i32 4
+int align_f = __alignof(float);
+
+// CHECK: @align_d = global i32 8
+int align_d = __alignof(double);
+
+// CHECK: @align_ld = global i32 8
+int align_ld = __alignof(long double);
+
+// CHECK: @align_vl = global i32 4
+int align_vl = __alignof(va_list);
+
+// CHECK: __LITTLE_ENDIAN__defined
+#ifdef __LITTLE_ENDIAN__
+void __LITTLE_ENDIAN__defined() {}
+#endif
+
+// CHECK: __wasm__defined
+#ifdef __wasm__
+void __wasm__defined() {}
+#endif
+
+// CHECK: _GNU_SOURCEdefined
+#ifdef _GNU_SOURCE
+void _GNU_SOURCEdefined() {}
+#endif
+
+// THREADS: _REENTRANTdefined
+// CHECK: _REENTRANTundefined
+#ifdef _REENTRANT
+void _REENTRANTdefined() {}
+#else
+void _REENTRANTundefined() {}
+#endif
+
+// Check types
+
+// CHECK: signext i8 @check_char()
+char check_char() { return 0; }
+
+// CHECK: signext i16 @check_short()
+short check_short() { return 0; }
+
+// CHECK: i32 @check_int()
+int check_int() { return 0; }
+
+// CHECK: i32 @check_long()
+long check_long() { return 0; }
+
+// CHECK: i64 @check_longlong()
+long long check_longlong() { return 0; }
+
+// CHECK: zeroext i8 @check_uchar()
+unsigned char check_uchar() { return 0; }
+
+// CHECK: zeroext i16 @check_ushort()
+unsigned short check_ushort() { return 0; }
+
+// CHECK: i32 @check_uint()
+unsigned int check_uint() { return 0; }
+
+// CHECK: i32 @check_ulong()
+unsigned long check_ulong() { return 0; }
+
+// CHECK: i64 @check_ulonglong()
+unsigned long long check_ulonglong() { return 0; }
+
+// CHECK: i32 @check_size_t()
+size_t check_size_t() { return 0; }
+
+// CHECK: float @check_float()
+float check_float() { return 0; }
+
+// CHECK: double @check_double()
+double check_double() { return 0; }
+
+// CHECK: double @check_longdouble()
+long double check_longdouble() { return 0; }
+
+}
+
+template<int> void Switch();
+template<> void Switch<4>();
+template<> void Switch<8>();
+template<> void Switch<16>();
+
+void check_pointer_size() {
+  // CHECK: SwitchILi4
+  Switch<sizeof(void*)>();
+
+  // CHECK: SwitchILi8
+  Switch<sizeof(long long)>();
+
+  // CHECK: SwitchILi4
+  Switch<sizeof(va_list)>();
+}
Index: test/CodeGenCXX/static-init-wasm.cpp
===================================================================
--- test/CodeGenCXX/static-init-wasm.cpp
+++ test/CodeGenCXX/static-init-wasm.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -emit-llvm -triple=wasm32-unknown-unknown -o - %s | FileCheck %s -check-prefix=WEBASSEMBLY32
+// RUN: %clang_cc1 -emit-llvm -triple=wasm64-unknown-unknown -o - %s | FileCheck %s -check-prefix=WEBASSEMBLY64
+
+int f();
+
+// Test that WebAssembly uses the ARM-style ABI in which the static
+// variable's guard variable is tested via "load i8 and test the
+// bottom bit" rather than the Itanium/x86 ABI which uses "load i8
+// and compare with zero".
+void g() {
+  static int a = f();
+}
+
+// WEBASSEMBLY32-LABEL: @_Z1gv()
+// WEBASSEMBLY32:       %[[R0:.+]] = load atomic i8, i8* bitcast (i32* @_ZGVZ1gvE1a to i8*) acquire, align 1
+// WEBASSEMBLY32-NEXT:  %[[R1:.+]] = and i8 %[[R0]], 1
+// WEBASSEMBLY32-NEXT:  %[[R2:.+]] = icmp eq i8 %[[R1]], 0
+// WEBASSEMBLY32-NEXT:  br i1 %[[R2]], label %[[CHECK:.+]], label %[[END:.+]]
+// WEBASSEMBLY32:       [[CHECK]]
+// WEBASSEMBLY32:       call i32 @__cxa_guard_acquire
+// WEBASSEMBLY32:       [[END]]
+// WEBASSEMBLY32:       call void @__cxa_guard_release
+//
+// WEBASSEMBLY64-LABEL: @_Z1gv()
+// WEBASSEMBLY64:       %[[R0:.+]] = load atomic i8, i8* bitcast (i64* @_ZGVZ1gvE1a to i8*) acquire, align 1
+// WEBASSEMBLY64-NEXT:  %[[R1:.+]] = and i8 %[[R0]], 1
+// WEBASSEMBLY64-NEXT:  %[[R2:.+]] = icmp eq i8 %[[R1]], 0
+// WEBASSEMBLY64-NEXT:  br i1 %[[R2]], label %[[CHECK:.+]], label %[[END:.+]]
+// WEBASSEMBLY64:       [[CHECK]]
+// WEBASSEMBLY64:       call i32 @__cxa_guard_acquire
+// WEBASSEMBLY64:       [[END]]
+// WEBASSEMBLY64:       call void @__cxa_guard_release
Index: test/CodeGenCXX/member-function-pointers.cpp
===================================================================
--- test/CodeGenCXX/member-function-pointers.cpp
+++ test/CodeGenCXX/member-function-pointers.cpp
@@ -8,6 +8,8 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=le32-unknown-nacl | FileCheck -check-prefix GLOBAL-ARM %s
 // MIPS uses the same representation of method pointers as ARM.
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple=mips-unknown-linux-gnu | FileCheck -check-prefix GLOBAL-ARM %s
+// WebAssembly uses the same representation of method pointers as ARM.
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=wasm32-unknown-unknown | FileCheck -check-prefix GLOBAL-ARM %s
 
 struct A { int a; void f(); virtual void vf1(); virtual void vf2(); };
 struct B { int b; virtual void g(); };
Index: test/CodeGenCXX/member-alignment.cpp
===================================================================
--- test/CodeGenCXX/member-alignment.cpp
+++ test/CodeGenCXX/member-alignment.cpp
@@ -1,4 +1,9 @@
-// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple %s -o - | \
+// RUN: FileCheck -check-prefix CHECK-ITANIUM %s
+// RUN: %clang_cc1 -emit-llvm -triple wasm32-unknown-unknown %s -o - | \
+// RUN: FileCheck -check-prefix CHECK-WEBASSEMBLY32 %s
+// RUN: %clang_cc1 -emit-llvm -triple wasm64-unknown-unknown %s -o - | \
+// RUN: FileCheck -check-prefix CHECK-WEBASSEMBLY64 %s
 
 // rdar://7268289
 
@@ -10,10 +15,14 @@
 
 void
 t::bar(void) {
-// CHECK: _ZN1t3barEv{{.*}} align 2
+// CHECK-ITANIUM: _ZN1t3barEv{{.*}} align 2
+// CHECK-WEBASSEMBLY32: _ZN1t3barEv{{.*}}
+// CHECK-WEBASSEMBLY64: _ZN1t3barEv{{.*}}
 }
 
 void
 t::foo(void) {
-// CHECK: _ZN1t3fooEv{{.*}} align 2
+// CHECK-ITANIUM: _ZN1t3fooEv{{.*}} align 2
+// CHECK-WEBASSEMBLY32: _ZN1t3fooEv{{.*}}
+// CHECK-WEBASSEMBLY64: _ZN1t3fooEv{{.*}}
 }
Index: test/CodeGen/wasm-regparm.c
===================================================================
--- test/CodeGen/wasm-regparm.c
+++ test/CodeGen/wasm-regparm.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown %s -fsyntax-only -verify
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown %s -fsyntax-only -verify
+
+void __attribute__((regparm(2))) fc_f1(int i, int j, int k) {} // expected-error{{'regparm' is not valid on this platform}}
Index: test/CodeGen/wasm-arguments.c
===================================================================
--- test/CodeGen/wasm-arguments.c
+++ test/CodeGen/wasm-arguments.c
@@ -0,0 +1,91 @@
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown %s -emit-llvm -o - | FileCheck %s -check-prefix=WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown %s -emit-llvm -o - | FileCheck %s -check-prefix=WEBASSEMBLY64
+
+// Basic argument/attribute tests for WebAssembly
+
+// WEBASSEMBLY32: define void @f0(i32 %i, i32 %j, i64 %k, double %l, double %m)
+// WEBASSEMBLY64: define void @f0(i32 %i, i64 %j, i64 %k, double %l, double %m)
+void f0(int i, long j, long long k, double l, long double m) {}
+
+typedef struct {
+  int aa;
+  int bb;
+} s1;
+// Structs should be passed byval and not split up.
+// WEBASSEMBLY32: define void @f1(%struct.s1* byval align 4 %i)
+// WEBASSEMBLY64: define void @f1(%struct.s1* byval align 4 %i)
+void f1(s1 i) {}
+
+typedef struct {
+  int cc;
+} s2;
+// Single-element structs should be returned as the one element.
+// WEBASSEMBLY32: define i32 @f2()
+// WEBASSEMBLY64: define i32 @f2()
+s2 f2() {
+  s2 foo;
+  return foo;
+}
+
+typedef struct {
+  int cc;
+  int dd;
+} s3;
+// Structs should be returned sret and not simplified by the frontend.
+// WEBASSEMBLY32: define void @f3(%struct.s3* noalias sret %agg.result)
+// WEBASSEMBLY64: define void @f3(%struct.s3* noalias sret %agg.result)
+s3 f3() {
+  s3 foo;
+  return foo;
+}
+
+// WEBASSEMBLY32: define void @f4(i64 %i)
+// WEBASSEMBLY64: define void @f4(i64 %i)
+void f4(long long i) {}
+
+// i8/i16 should be signext, i32 and higher should not.
+// WEBASSEMBLY32: define void @f5(i8 signext %a, i16 signext %b)
+// WEBASSEMBLY64: define void @f5(i8 signext %a, i16 signext %b)
+void f5(char a, short b) {}
+
+// WEBASSEMBLY32: define void @f6(i8 zeroext %a, i16 zeroext %b)
+// WEBASSEMBLY64: define void @f6(i8 zeroext %a, i16 zeroext %b)
+void f6(unsigned char a, unsigned short b) {}
+
+
+enum my_enum {
+  ENUM1,
+  ENUM2,
+  ENUM3,
+};
+// Enums should be treated as the underlying i32.
+// WEBASSEMBLY32: define void @f7(i32 %a)
+// WEBASSEMBLY64: define void @f7(i32 %a)
+void f7(enum my_enum a) {}
+
+enum my_big_enum {
+  ENUM4 = 0xFFFFFFFFFFFFFFFF,
+};
+// Big enums should be treated as the underlying i64.
+// WEBASSEMBLY32: define void @f8(i64 %a)
+// WEBASSEMBLY64: define void @f8(i64 %a)
+void f8(enum my_big_enum a) {}
+
+union simple_union {
+  int a;
+  char b;
+};
+// Unions should be passed as byval structs.
+// WEBASSEMBLY32: define void @f9(%union.simple_union* byval align 4 %s)
+// WEBASSEMBLY64: define void @f9(%union.simple_union* byval align 4 %s)
+void f9(union simple_union s) {}
+
+typedef struct {
+  int b4 : 4;
+  int b3 : 3;
+  int b8 : 8;
+} bitfield1;
+// Bitfields should be passed as byval structs.
+// WEBASSEMBLY32: define void @f10(%struct.bitfield1* byval align 4 %bf1)
+// WEBASSEMBLY64: define void @f10(%struct.bitfield1* byval align 4 %bf1)
+void f10(bitfield1 bf1) {}
Index: test/CodeGen/target-data.c
===================================================================
--- test/CodeGen/target-data.c
+++ test/CodeGen/target-data.c
@@ -78,6 +78,14 @@
 // RUN: FileCheck %s -check-prefix=LE32-NACL
 // LE32-NACL: target datalayout = "e-p:32:32-i64:64"
 
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -o - -emit-llvm %s | \
+// RUN: FileCheck %s -check-prefix=WEBASSEMBLY32
+// WEBASSEMBLY32: target datalayout = "e-p:32:32-i64:64-v128:8:128-n32:64-S128"
+
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -o - -emit-llvm %s | \
+// RUN: FileCheck %s -check-prefix=WEBASSEMBLY64
+// WEBASSEMBLY64: target datalayout = "e-p:64:64-i64:64-v128:8:128-n32:64-S128"
+
 // RUN: %clang_cc1 -triple powerpc-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=PPC
 // PPC: target datalayout = "E-m:e-p:32:32-i64:64-n32"
Index: test/CodeGen/builtins-wasm.c
===================================================================
--- test/CodeGen/builtins-wasm.c
+++ test/CodeGen/builtins-wasm.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple wasm32-unknown-unknown -O3 -emit-llvm -o - %s | FileCheck %s -check-prefix=WEBASSEMBLY32
+// RUN: %clang_cc1 -triple wasm64-unknown-unknown -O3 -emit-llvm -o - %s | FileCheck %s -check-prefix=WEBASSEMBLY64
+
+__SIZE_TYPE__ f0(void) {
+  return __builtin_wasm_page_size();
+// WEBASSEMBLY32: call {{i.*}} @llvm.wasm.page.size.i32()
+// WEBASSEMBLY64: call {{i.*}} @llvm.wasm.page.size.i64()
+}
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1556,6 +1556,27 @@
   }
 }
 
+/// Get the (LLVM) name of the WebAssembly cpu we are targeting.
+static std::string getWebAssemblyTargetCPU(const ArgList &Args) {
+  Arg *A;
+  std::string CPU;
+  // If we have -mtune or -mcpu, use that.
+  if ((A = Args.getLastArg(options::OPT_mtune_EQ))) {
+    CPU = StringRef(A->getValue()).lower();
+  } else if ((A = Args.getLastArg(options::OPT_mcpu_EQ))) {
+    StringRef Mcpu = A->getValue();
+    CPU = Mcpu.split("+").first.lower();
+  }
+
+  // Handle CPU name is 'native'.
+  if (CPU == "native")
+    return llvm::sys::getHostCPUName();
+  else if (CPU.size())
+    return CPU;
+
+  return "generic";
+}
+
 static std::string getCPUName(const ArgList &Args, const llvm::Triple &T,
                               bool FromAs = false) {
   switch (T.getArch()) {
@@ -1628,6 +1649,10 @@
   case llvm::Triple::r600:
   case llvm::Triple::amdgcn:
     return getR600TargetGPU(Args);
+
+  case llvm::Triple::wasm32:
+  case llvm::Triple::wasm64:
+    return getWebAssemblyTargetCPU(Args);
   }
 }
 
Index: lib/Driver/ToolChains.h
===================================================================
--- lib/Driver/ToolChains.h
+++ lib/Driver/ToolChains.h
@@ -925,6 +925,29 @@
   mutable std::unique_ptr<Tool> Assembler;
 };
 
+class LLVM_LIBRARY_VISIBILITY WebAssembly final : public ToolChain {
+public:
+  WebAssembly(const Driver &D, const llvm::Triple &Triple,
+              const llvm::opt::ArgList &Args)
+      : ToolChain(D, Triple, Args) {}
+  ~WebAssembly() override {}
+
+  bool IsMathErrnoDefault() const override { return false; }
+  bool IsObjCNonFragileABIDefault() const override { return true; }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return false; }
+  bool isPICDefaultForced() const override { return false; }
+
+  // TODO: Support Objective C stuff.
+  bool hasBlocksRuntime() const override { return false; }
+  bool SupportsObjCGC() const override { return false; }
+
+  // TODO: Support profiling.
+  bool SupportsProfiling() const override { return false; }
+
+  bool IsIntegratedAssemblerDefault() const override { return true; }
+};
+
 } // end namespace toolchains
 } // end namespace driver
 } // end namespace clang
Index: lib/CodeGen/TargetInfo.cpp
===================================================================
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -445,6 +445,61 @@
 }
 
 //===----------------------------------------------------------------------===//
+// WebAssembly ABI Implementation
+//
+// This is a very simple ABI that relies a lot on DefaultABIInfo.
+//===----------------------------------------------------------------------===//
+
+class WebAssemblyABIInfo final : public DefaultABIInfo {
+public:
+  explicit WebAssemblyABIInfo(CodeGen::CodeGenTypes &CGT)
+      : DefaultABIInfo(CGT) {}
+
+  ABIArgInfo classifyReturnType(QualType RetTy) const;
+  ABIArgInfo classifyArgumentType(QualType Ty) const;
+
+  // DefaultABIInfo's classifyReturnType and classifyArgumentType are
+  // non-virtual, but computeInfo is virtual, so we overload that.
+  void computeInfo(CGFunctionInfo &FI) const override {
+    FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+    for (auto &Arg : FI.arguments())
+      Arg.info = classifyArgumentType(Arg.type);
+  }
+};
+
+class WebAssemblyTargetCodeGenInfo final : public TargetCodeGenInfo {
+public:
+  explicit WebAssemblyTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
+      : TargetCodeGenInfo(new WebAssemblyABIInfo(CGT)) {}
+};
+
+/// \brief Classify argument of given type \p Ty.
+ABIArgInfo WebAssemblyABIInfo::classifyArgumentType(QualType Ty) const {
+  if (isAggregateTypeForABI(Ty)) {
+    unsigned TypeAlign = getContext().getTypeAlignInChars(Ty).getQuantity();
+    if (auto RAA = getRecordArgABI(Ty, getCXXABI()))
+      return ABIArgInfo::getIndirect(TypeAlign,
+                                     RAA == CGCXXABI::RAA_DirectInMemory);
+    return ABIArgInfo::getIndirect(TypeAlign);
+  }
+
+  // Otherwise just do the default thing.
+  return DefaultABIInfo::classifyArgumentType(Ty);
+}
+
+ABIArgInfo WebAssemblyABIInfo::classifyReturnType(QualType RetTy) const {
+  if (isAggregateTypeForABI(RetTy)) {
+    // As an optimization, lower single-element structs to just return a regular
+    // value.
+    if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext()))
+      return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
+  }
+
+  // Otherwise just do the default thing.
+  return DefaultABIInfo::classifyReturnType(RetTy);
+}
+
+//===----------------------------------------------------------------------===//
 // le32/PNaCl bitcode ABI Implementation
 //
 // This is a simplified version of the x86_32 ABI.  Arguments and return values
@@ -7135,6 +7190,10 @@
     return *(TheTargetCodeGenInfo = new AArch64TargetCodeGenInfo(Types, Kind));
   }
 
+  case llvm::Triple::wasm32:
+  case llvm::Triple::wasm64:
+    return *(TheTargetCodeGenInfo = new WebAssemblyTargetCodeGenInfo(Types));
+
   case llvm::Triple::arm:
   case llvm::Triple::armeb:
   case llvm::Triple::thumb:
Index: lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -373,6 +373,7 @@
   // include the other 32-bit ARM oddities: constructor/destructor return values
   // and array cookies.
   case TargetCXXABI::GenericAArch64:
+  case TargetCXXABI::GenericWebAssembly:
     return new ItaniumCXXABI(CGM, /* UseARMMethodPtrABI = */ true,
                              /* UseARMGuardVarABI = */ true);
 
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -66,6 +66,7 @@
   case TargetCXXABI::iOS64:
   case TargetCXXABI::GenericMIPS:
   case TargetCXXABI::GenericItanium:
+  case TargetCXXABI::GenericWebAssembly:
     return CreateItaniumCXXABI(CGM);
   case TargetCXXABI::Microsoft:
     return CreateMicrosoftCXXABI(CGM);
@@ -804,9 +805,11 @@
   if (alignment)
     F->setAlignment(alignment);
 
-  // C++ ABI requires 2-byte alignment for member functions.
-  if (F->getAlignment() < 2 && isa<CXXMethodDecl>(D))
-    F->setAlignment(2);
+  if (getTarget().getCXXABI().areMemberFunctionsAligned()) {
+    // C++ ABI requires 2-byte alignment for member functions.
+    if (F->getAlignment() < 2 && isa<CXXMethodDecl>(D))
+      F->setAlignment(2);
+  }
 }
 
 void CodeGenModule::SetCommonAttributes(const Decl *D,
Index: lib/CodeGen/CodeGenFunction.h
===================================================================
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -2623,6 +2623,8 @@
   llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
   llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
   llvm::Value *EmitNVPTXBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
+  llvm::Value *EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
+                                          const CallExpr *E);
 
   llvm::Value *EmitObjCProtocolExpr(const ObjCProtocolExpr *E);
   llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp
+++ lib/CodeGen/CGBuiltin.cpp
@@ -1882,6 +1882,9 @@
   case llvm::Triple::nvptx:
   case llvm::Triple::nvptx64:
     return EmitNVPTXBuiltinExpr(BuiltinID, E);
+  case llvm::Triple::wasm32:
+  case llvm::Triple::wasm64:
+    return EmitWebAssemblyBuiltinExpr(BuiltinID, E);
   default:
     return nullptr;
   }
@@ -7056,3 +7059,17 @@
     return nullptr;
   }
 }
+
+Value *CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
+                                                   const CallExpr *E) {
+  switch (BuiltinID) {
+  case WebAssembly::BI__builtin_wasm_page_size: {
+    llvm::Type *ResultType = ConvertType(E->getType());
+    Value *Callee = CGM.getIntrinsic(Intrinsic::wasm_page_size, ResultType);
+    return Builder.CreateCall(Callee);
+  }
+
+  default:
+    return nullptr;
+  }
+}
Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -734,6 +734,34 @@
   }
 };
 
+namespace {
+// WebAssembly target
+template <typename Target>
+class WebAssemblyOSTargetInfo : public OSTargetInfo<Target> {
+protected:
+  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
+                    MacroBuilder &Builder) const override final {
+    // A common platform macro.
+    if (Opts.POSIXThreads)
+      Builder.defineMacro("_REENTRANT");
+    // Follow g++ convention and predefine _GNU_SOURCE for C++.
+    if (Opts.CPlusPlus)
+      Builder.defineMacro("_GNU_SOURCE");
+  }
+
+public:
+  explicit WebAssemblyOSTargetInfo(const llvm::Triple &Triple)
+      : OSTargetInfo<Target>(Triple) {
+    this->UserLabelPrefix = "";
+
+    // WebAssembly uses the Itanium ABI mostly, but it uses ARM-style pointers
+    // to member functions so that it can avoid having to align function
+    // addresses.
+    this->TheCXXABI.set(TargetCXXABI::GenericWebAssembly);
+  }
+};
+} // end anonymous namespace
+
 //===----------------------------------------------------------------------===//
 // Specific target implementations.
 //===----------------------------------------------------------------------===//
@@ -6898,6 +6926,105 @@
 
   bool hasProtectedVisibility() const override { return false; }
 };
+
+class WebAssemblyTargetInfo : public TargetInfo {
+  static const Builtin::Info BuiltinInfo[];
+
+  std::string CPU;
+
+public:
+  explicit WebAssemblyTargetInfo(const llvm::Triple &T) : TargetInfo(T) {
+    BigEndian = false;
+    NoAsmVariants = true;
+    SuitableAlign = 128;
+  }
+
+  void
+  getDefaultFeatures(llvm::StringMap<bool> &Features) const override final {}
+  bool setCPU(const std::string &Name) override final {
+    bool CPUKnown = llvm::StringSwitch<bool>(Name)
+                        .Case("generic", true)
+                        .Case("mvp", true)
+                        .Case("bleeding-edge", true)
+                        .Default(false);
+    if (CPUKnown)
+      CPU = Name;
+    return CPUKnown;
+  }
+  void getTargetDefines(const LangOptions &Opts,
+                        MacroBuilder &Builder) const override {
+    defineCPUMacros(Builder, "wasm", /*Tuning=*/false);
+
+    Builder.defineMacro("__REGISTER_PREFIX__", "");
+  }
+  void getTargetBuiltins(const Builtin::Info *&Records,
+                         unsigned &NumRecords) const override final {
+    Records = BuiltinInfo;
+    NumRecords = clang::WebAssembly::LastTSBuiltin - Builtin::FirstTSBuiltin;
+  }
+  BuiltinVaListKind getBuiltinVaListKind() const override final {
+    // TODO: Implement va_list properly.
+    return VoidPtrBuiltinVaList;
+  }
+  void getGCCRegNames(const char *const *&Names,
+                      unsigned &NumNames) const override final {
+    Names = nullptr;
+    NumNames = 0;
+  }
+  void getGCCRegAliases(const GCCRegAlias *&Aliases,
+                        unsigned &NumAliases) const override final {
+    Aliases = nullptr;
+    NumAliases = 0;
+  }
+  bool
+  validateAsmConstraint(const char *&Name,
+                        TargetInfo::ConstraintInfo &Info) const override final {
+    return false;
+  }
+  const char *getClobbers() const override final { return ""; }
+  bool isCLZForZeroUndef() const override final { return false; }
+};
+
+const Builtin::Info WebAssemblyTargetInfo::BuiltinInfo[] = {
+#define BUILTIN(ID, TYPE, ATTRS) \
+  { #ID, TYPE, ATTRS, nullptr, ALL_LANGUAGES, nullptr },
+#define LIBBUILTIN(ID, TYPE, ATTRS, HEADER) \
+  { #ID, TYPE, ATTRS, HEADER, ALL_LANGUAGES, nullptr },
+#include "clang/Basic/BuiltinsWebAssembly.def"
+};
+
+class WebAssembly32TargetInfo : public WebAssemblyTargetInfo {
+public:
+  explicit WebAssembly32TargetInfo(const llvm::Triple &T)
+      : WebAssemblyTargetInfo(T) {
+    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
+    DataLayoutString = "e-p:32:32-i64:64-v128:8:128-n32:64-S128";
+  }
+
+  void getTargetDefines(const LangOptions &Opts,
+                        MacroBuilder &Builder) const override {
+    WebAssemblyTargetInfo::getTargetDefines(Opts, Builder);
+    defineCPUMacros(Builder, "wasm32", /*Tuning=*/false);
+  }
+};
+
+class WebAssembly64TargetInfo : public WebAssemblyTargetInfo {
+public:
+  explicit WebAssembly64TargetInfo(const llvm::Triple &T)
+      : WebAssemblyTargetInfo(T) {
+    LongAlign = LongWidth = 64;
+    PointerAlign = PointerWidth = 64;
+    MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
+    DataLayoutString = "e-p:64:64-i64:64-v128:8:128-n32:64-S128";
+  }
+
+  void getTargetDefines(const LangOptions &Opts,
+                        MacroBuilder &Builder) const override {
+    WebAssemblyTargetInfo::getTargetDefines(Opts, Builder);
+    defineCPUMacros(Builder, "wasm64", /*Tuning=*/false);
+  }
+};
+
 } // end anonymous namespace.
 
 const Builtin::Info Le64TargetInfo::BuiltinInfo[] = {
@@ -7502,6 +7629,18 @@
       return nullptr;
     return new SPIR64TargetInfo(Triple);
   }
+  case llvm::Triple::wasm32: {
+    if (Triple.getVendor() != llvm::Triple::UnknownVendor ||
+        Triple.getOS() != llvm::Triple::UnknownOS)
+      return nullptr;
+    return new WebAssemblyOSTargetInfo<WebAssembly32TargetInfo>(Triple);
+  }
+  case llvm::Triple::wasm64: {
+    if (Triple.getVendor() != llvm::Triple::UnknownVendor ||
+        Triple.getOS() != llvm::Triple::UnknownOS)
+      return nullptr;
+    return new WebAssemblyOSTargetInfo<WebAssembly64TargetInfo>(Triple);
+  }
   }
 }
 
Index: lib/AST/ASTContext.cpp
===================================================================
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -684,6 +684,7 @@
   case TargetCXXABI::GenericAArch64:
   case TargetCXXABI::GenericMIPS:
   case TargetCXXABI::GenericItanium:
+  case TargetCXXABI::GenericWebAssembly:
     return CreateItaniumCXXABI(*this);
   case TargetCXXABI::Microsoft:
     return CreateMicrosoftCXXABI(*this);
@@ -8417,6 +8418,7 @@
   case TargetCXXABI::GenericItanium:
   case TargetCXXABI::GenericARM:
   case TargetCXXABI::GenericMIPS:
+  case TargetCXXABI::GenericWebAssembly:
   case TargetCXXABI::iOS:
   case TargetCXXABI::iOS64:
     return ItaniumMangleContext::create(*this, getDiagnostics());
Index: include/clang/module.modulemap
===================================================================
--- include/clang/module.modulemap
+++ include/clang/module.modulemap
@@ -37,6 +37,7 @@
   textual header "Basic/BuiltinsSystemZ.def"
   textual header "Basic/BuiltinsX86.def"
   textual header "Basic/BuiltinsXCore.def"
+  textual header "Basic/BuiltinsWebAssembly.def"
   textual header "Basic/DiagnosticOptions.def"
   textual header "Basic/LangOptions.def"
   textual header "Basic/OpenCLExtensions.def"
Index: include/clang/Basic/TargetCXXABI.h
===================================================================
--- include/clang/Basic/TargetCXXABI.h
+++ include/clang/Basic/TargetCXXABI.h
@@ -85,6 +85,13 @@
     ///   - representation of member function pointers adjusted as in ARM.
     GenericMIPS,
 
+    /// The generic WebAssembly ABI is a modified version of the Itanium ABI.
+    ///
+    /// The relevant changes from the generic ABI in this case are:
+    ///   - representation of member function pointers adjusted as in ARM;
+    ///   - guard variables are smaller.
+    GenericWebAssembly,
+
     /// The Microsoft ABI is the ABI used by Microsoft Visual Studio (and
     /// compatible compilers).
     ///
@@ -121,6 +128,7 @@
     case iOS:
     case iOS64:
     case GenericMIPS:
+    case GenericWebAssembly:
       return true;
 
     case Microsoft:
@@ -138,14 +146,36 @@
     case iOS:
     case iOS64:
     case GenericMIPS:
+    case GenericWebAssembly:
       return false;
 
     case Microsoft:
       return true;
     }
     llvm_unreachable("bad ABI kind");
   }
 
+  /// \brief Are member functions differently aligned?
+  bool areMemberFunctionsAligned() const {
+    switch (getKind()) {
+    case GenericWebAssembly:
+      // WebAssembly doesn't require any special alignment for member functions.
+      return false;
+    case GenericARM:
+    case GenericAArch64:
+    case GenericMIPS:
+      // TODO: ARM-style pointers to member functions put the discriminator in
+      //       the this adjustment, so they don't require functions to have any
+      //       special alignment and could therefore also return false.
+    case GenericItanium:
+    case iOS:
+    case iOS64:
+    case Microsoft:
+      return true;
+    }
+    llvm_unreachable("bad ABI kind");
+  }
+
   /// \brief Is the default C++ member function calling convention
   /// the same as the default calling convention?
   bool isMemberFunctionCCDefault() const {
@@ -214,6 +244,7 @@
     switch (getKind()) {
     case GenericARM:
     case iOS64:
+    case GenericWebAssembly:
       return false;
 
     case GenericAArch64:
@@ -272,6 +303,7 @@
     // iOS on ARM64 uses the C++11 POD rules.  It does not honor the
     // Itanium exception about classes with over-large bitfields.
     case iOS64:
+    case GenericWebAssembly:
       return UseTailPaddingUnlessPOD11;
 
     // MSVC always allocates fields in the tail-padding of a base class
Index: include/clang/Basic/TargetBuiltins.h
===================================================================
--- include/clang/Basic/TargetBuiltins.h
+++ include/clang/Basic/TargetBuiltins.h
@@ -185,6 +185,17 @@
         LastTSBuiltin
     };
   }
+
+  /// \brief WebAssembly builtins
+  namespace WebAssembly {
+    enum {
+      LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/BuiltinsWebAssembly.def"
+      LastTSBuiltin
+    };
+  }
+
 } // end namespace clang.
 
 #endif
Index: include/clang/Basic/BuiltinsWebAssembly.def
===================================================================
--- include/clang/Basic/BuiltinsWebAssembly.def
+++ include/clang/Basic/BuiltinsWebAssembly.def
@@ -0,0 +1,21 @@
+// BuiltinsWebAssembly.def - WebAssembly Builtin function database -*- C++ -*-//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// \brief This file defines the WebAssembly-specific builtin function database.
+/// Users of this file must define the BUILTIN macro to make use of this
+/// information.
+///
+//===----------------------------------------------------------------------===//
+
+// The format of this database matches clang/Basic/Builtins.def.
+
+BUILTIN(__builtin_wasm_page_size, "z", "")
+
+#undef BUILTIN
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to