[cfe-dev] More C ABI questions with Clang

Christoffer Lernö via cfe-dev cfe-dev at lists.llvm.org
Wed Nov 11 16:20:16 PST 2020


1. In x86 it seems like a lost opportunity not to lower a union like 

> union Foo
> {
>   char x;
>   int y;
>   float z;
> };

To a float, since

> struct Foo
> {
>    float z;
> }

would be. Is it just an omission or what?

2. Is this ABI lowering reasonable on x64? Doesn’t the bitcast and consequent i64 load strictly speaking load things beyond the end of struct Foo as allocated in a?

> struct Foo
> {
>   int a;
>   char b;
> };
> 
> struct Foo getFoo(int x)
> {
>   struct Foo a;
>   return a;
> }

To

> %struct.Foo = type { i32, i8 }
> 
> define dso_local i64 @getFoo(i32 %0) #0 !dbg !7 {
>   %2 = alloca %struct.Foo, align 4
>   %3 = alloca i32, align 4
>   store i32 %0, i32* %3, align 4
>   %4 = bitcast %struct.Foo* %2 to i64*, !dbg !21
>   %5 = load i64, i64* %4, align 4, !dbg !21
>   ret i64 %5, !dbg !21
> }


/Christoffer



More information about the cfe-dev mailing list