diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CodeGen/emscripten-arguments.c | 61 | ||||
-rw-r--r-- | test/CodeGen/emscripten-regparm.c | 4 | ||||
-rw-r--r-- | test/CodeGenCXX/member-function-pointers.cpp | 2 | ||||
-rw-r--r-- | test/CodeGenCXX/static-init-emscripten.cpp | 14 | ||||
-rw-r--r-- | test/Driver/asmjs-unknown-emscripten.cpp | 146 |
5 files changed, 227 insertions, 0 deletions
diff --git a/test/CodeGen/emscripten-arguments.c b/test/CodeGen/emscripten-arguments.c new file mode 100644 index 0000000000..afa0d9c57b --- /dev/null +++ b/test/CodeGen/emscripten-arguments.c @@ -0,0 +1,61 @@ +// RUN: %clang_cc1 -triple asmjs-unknown-emscripten %s -emit-llvm -o - | FileCheck %s + +// Basic argument/attribute tests for asmjs/Emscripten + +// CHECK: define void @f0(i32 %i, i32 %j, double %k) +void f0(int i, long j, double k) {} + +typedef struct { + int aa; + int bb; +} s1; +// Structs should be passed byval and not split up +// CHECK: define void @f1(%struct.s1* byval %i) +void f1(s1 i) {} + +typedef struct { + int cc; +} s2; +// Structs should be returned sret and not simplified by the frontend +// CHECK: define void @f2(%struct.s2* noalias sret %agg.result) +s2 f2() { + s2 foo; + return foo; +} + +// CHECK: define void @f3(i64 %i) +void f3(long long i) {} + +// i8/i16 should be signext, i32 and higher should not +// CHECK: define void @f4(i8 signext %a, i16 signext %b) +void f4(char a, short b) {} + +// CHECK: define void @f5(i8 zeroext %a, i16 zeroext %b) +void f5(unsigned char a, unsigned short b) {} + + +enum my_enum { + ENUM1, + ENUM2, + ENUM3, +}; +// Enums should be treated as the underlying i32 +// CHECK: define void @f6(i32 %a) +void f6(enum my_enum a) {} + +union simple_union { + int a; + char b; +}; +// Unions should be passed as byval structs +// CHECK: define void @f7(%union.simple_union* byval %s) +void f7(union simple_union s) {} + +typedef struct { + int b4 : 4; + int b3 : 3; + int b8 : 8; +} bitfield1; +// Bitfields should be passed as byval structs +// CHECK: define void @f8(%struct.bitfield1* byval %bf1) +void f8(bitfield1 bf1) {} diff --git a/test/CodeGen/emscripten-regparm.c b/test/CodeGen/emscripten-regparm.c new file mode 100644 index 0000000000..20ffc9dec0 --- /dev/null +++ b/test/CodeGen/emscripten-regparm.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -triple asmjs-unknown-emscripten %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}} + diff --git a/test/CodeGenCXX/member-function-pointers.cpp b/test/CodeGenCXX/member-function-pointers.cpp index 23a7b0009f..c29f0e75e5 100644 --- a/test/CodeGenCXX/member-function-pointers.cpp +++ b/test/CodeGenCXX/member-function-pointers.cpp @@ -6,6 +6,8 @@ // PNaCl uses the same representation of method pointers as ARM. // RUN: %clang_cc1 %s -emit-llvm -o - -triple=le32-unknown-nacl | FileCheck -check-prefix GLOBAL-ARM %s +// Emscripten uses the same representation of method pointers as ARM. +// RUN: %clang_cc1 %s -emit-llvm -o - -triple=asmjs-unknown-emscripten | 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(); }; diff --git a/test/CodeGenCXX/static-init-emscripten.cpp b/test/CodeGenCXX/static-init-emscripten.cpp new file mode 100644 index 0000000000..b9d0271ae1 --- /dev/null +++ b/test/CodeGenCXX/static-init-emscripten.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -emit-llvm -triple=asmjs-unknown-emscripten -o - %s | FileCheck %s + +int f(); + +// Test that Emscripten uses the Itanium/x86 ABI in which the static +// variable's guard variable is tested via "load i8 and compare with +// zero" rather than the ARM ABI which uses "load i32 and test the +// bottom bit". +void g() { + static int a = f(); +} +// CHECK: load atomic i8* bitcast (i64* @_ZGVZ1gvE1a to i8*) acquire +// CHECK-NEXT: %guard.uninitialized = icmp eq i8 %0, 0 +// CHECK-NEXT: br i1 %guard.uninitialized, label %init.check, label %init.end diff --git a/test/Driver/asmjs-unknown-emscripten.cpp b/test/Driver/asmjs-unknown-emscripten.cpp new file mode 100644 index 0000000000..fb94f0ecf9 --- /dev/null +++ b/test/Driver/asmjs-unknown-emscripten.cpp @@ -0,0 +1,146 @@ +// RUN: %clang -target asmjs-unknown-emscripten -ccc-echo %s -emit-llvm-only -c 2>&1 | FileCheck %s -check-prefix=ECHO +// RUN: %clang -target asmjs-unknown-emscripten %s -emit-llvm -S -c -o - | FileCheck %s +// RUN: %clang -target asmjs-unknown-emscripten %s -emit-llvm -S -c -pthread -o - | FileCheck %s -check-prefix=THREADS + +// ECHO: {{.*}} -cc1 {{.*}}asmjs-unknown-emscripten.c + +// Check platform defines +#include <stdarg.h> +#include <stddef.h> + +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: __native_client__defined +#ifdef __native_client__ +void __native_client__defined() {} +#endif + +// CHECK: __le32__defined +#ifdef __le32__ +void __le32__defined() {} +#endif + +// CHECK: __pnacl__defined +#ifdef __pnacl__ +void __pnacl__defined() {} +#endif + +// CHECK: unixdefined +#ifdef unix +void unixdefined() {} +#endif + +// CHECK: __ELF__defined +#ifdef __ELF__ +void __ELF__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: SwitchILi16 + Switch<sizeof(va_list)>(); +} |