Home | History | Annotate | Download | only in CodeGen
      1 // RUN: %clang_cc1 -triple wasm32-unknown-unknown %s -emit-llvm -o - \
      2 // RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY32
      3 // RUN: %clang_cc1 -triple wasm64-unknown-unknown %s -emit-llvm -o - \
      4 // RUN:   | FileCheck %s -check-prefix=WEBASSEMBLY64
      5 
      6 // Basic argument/attribute tests for WebAssembly
      7 
      8 // WEBASSEMBLY32: define void @f0(i32 %i, i32 %j, i64 %k, double %l, fp128 %m)
      9 // WEBASSEMBLY64: define void @f0(i32 %i, i64 %j, i64 %k, double %l, fp128 %m)
     10 void f0(int i, long j, long long k, double l, long double m) {}
     11 
     12 typedef struct {
     13   int aa;
     14   int bb;
     15 } s1;
     16 // Structs should be passed byval and not split up.
     17 // WEBASSEMBLY32: define void @f1(%struct.s1* byval align 4 %i)
     18 // WEBASSEMBLY64: define void @f1(%struct.s1* byval align 4 %i)
     19 void f1(s1 i) {}
     20 
     21 typedef struct {
     22   int cc;
     23 } s2;
     24 // Single-element structs should be returned as the one element.
     25 // WEBASSEMBLY32: define i32 @f2()
     26 // WEBASSEMBLY64: define i32 @f2()
     27 s2 f2() {
     28   s2 foo;
     29   return foo;
     30 }
     31 
     32 typedef struct {
     33   int cc;
     34   int dd;
     35 } s3;
     36 // Structs should be returned sret and not simplified by the frontend.
     37 // WEBASSEMBLY32: define void @f3(%struct.s3* noalias sret %agg.result)
     38 // WEBASSEMBLY64: define void @f3(%struct.s3* noalias sret %agg.result)
     39 s3 f3() {
     40   s3 foo;
     41   return foo;
     42 }
     43 
     44 // WEBASSEMBLY32: define void @f4(i64 %i)
     45 // WEBASSEMBLY64: define void @f4(i64 %i)
     46 void f4(long long i) {}
     47 
     48 // i8/i16 should be signext, i32 and higher should not.
     49 // WEBASSEMBLY32: define void @f5(i8 signext %a, i16 signext %b)
     50 // WEBASSEMBLY64: define void @f5(i8 signext %a, i16 signext %b)
     51 void f5(char a, short b) {}
     52 
     53 // WEBASSEMBLY32: define void @f6(i8 zeroext %a, i16 zeroext %b)
     54 // WEBASSEMBLY64: define void @f6(i8 zeroext %a, i16 zeroext %b)
     55 void f6(unsigned char a, unsigned short b) {}
     56 
     57 
     58 enum my_enum {
     59   ENUM1,
     60   ENUM2,
     61   ENUM3,
     62 };
     63 // Enums should be treated as the underlying i32.
     64 // WEBASSEMBLY32: define void @f7(i32 %a)
     65 // WEBASSEMBLY64: define void @f7(i32 %a)
     66 void f7(enum my_enum a) {}
     67 
     68 enum my_big_enum {
     69   ENUM4 = 0xFFFFFFFFFFFFFFFF,
     70 };
     71 // Big enums should be treated as the underlying i64.
     72 // WEBASSEMBLY32: define void @f8(i64 %a)
     73 // WEBASSEMBLY64: define void @f8(i64 %a)
     74 void f8(enum my_big_enum a) {}
     75 
     76 union simple_union {
     77   int a;
     78   char b;
     79 };
     80 // Unions should be passed as byval structs.
     81 // WEBASSEMBLY32: define void @f9(%union.simple_union* byval align 4 %s)
     82 // WEBASSEMBLY64: define void @f9(%union.simple_union* byval align 4 %s)
     83 void f9(union simple_union s) {}
     84 
     85 typedef struct {
     86   int b4 : 4;
     87   int b3 : 3;
     88   int b8 : 8;
     89 } bitfield1;
     90 // Bitfields should be passed as byval structs.
     91 // WEBASSEMBLY32: define void @f10(%struct.bitfield1* byval align 4 %bf1)
     92 // WEBASSEMBLY64: define void @f10(%struct.bitfield1* byval align 4 %bf1)
     93 void f10(bitfield1 bf1) {}
     94