xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/mips-transparent-union.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple mips64-linux-gnu -S -o - -emit-llvm %s | FileCheck %s
2*0a6a1f1dSLionel Sambuc //
3*0a6a1f1dSLionel Sambuc // Transparent unions are passed according to the calling convention rules of
4*0a6a1f1dSLionel Sambuc // the first member. In this case, it is as if it were a void pointer so we
5*0a6a1f1dSLionel Sambuc // do not have the inreg attribute we would normally have for unions.
6*0a6a1f1dSLionel Sambuc //
7*0a6a1f1dSLionel Sambuc // This comes up in glibc's wait() function and matters for the big-endian N32
8*0a6a1f1dSLionel Sambuc // case where pointers are promoted to i64 and a non-transparent union would be
9*0a6a1f1dSLionel Sambuc // passed in the upper 32-bits of an i64.
10*0a6a1f1dSLionel Sambuc 
11*0a6a1f1dSLionel Sambuc union either_pointer {
12*0a6a1f1dSLionel Sambuc   void *void_ptr;
13*0a6a1f1dSLionel Sambuc   int *int_ptr;
14*0a6a1f1dSLionel Sambuc } __attribute__((transparent_union));
15*0a6a1f1dSLionel Sambuc 
16*0a6a1f1dSLionel Sambuc extern void foo(union either_pointer p);
17*0a6a1f1dSLionel Sambuc 
18*0a6a1f1dSLionel Sambuc int data;
19*0a6a1f1dSLionel Sambuc 
bar(void)20*0a6a1f1dSLionel Sambuc void bar(void) {
21*0a6a1f1dSLionel Sambuc   return foo(&data);
22*0a6a1f1dSLionel Sambuc }
23*0a6a1f1dSLionel Sambuc 
24*0a6a1f1dSLionel Sambuc // CHECK-LABEL: define void @bar()
25*0a6a1f1dSLionel Sambuc // CHECK:         call void @foo(i8* %{{[0-9]+}})
26*0a6a1f1dSLionel Sambuc 
27*0a6a1f1dSLionel Sambuc // CHECK: declare void @foo(i8*)
28