Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the Union Type derived in LLVM

Tags:

llvm

unions

union u{
 char ch[41];
 int b[10];  
}un;

The LLVM compiles to this

%union.u = type { [10 x i32], [4 x i8] }

and this

union un{
  struct s{
    int a;
    float f;
    double d;
  }st;

  int intArr[10];
}uno;

compiles to this

%union.un = type { %struct.s, [24 x i8] }
%struct.s = type { i32, float, double }

Can any one explain how the union type is derived ?

like image 487
Vikash Joshi Avatar asked Oct 07 '22 10:10

Vikash Joshi


1 Answers

The first member is just the most aligned member of the union (it arbitrarily picks one if there are multiple such members), and an array of i8 is appended to make it the right size.

like image 69
servn Avatar answered Oct 10 '22 03:10

servn