Skip to content

Commit f95026d

Browse files
authored
[PowerPC] Fix codegen for transparent_union function params (#101738)
Update codegen for func param with transparent_union attr to be that of the first union member. PPC fix for: #76773
1 parent 42386dc commit f95026d

File tree

3 files changed

+76
-6
lines changed

3 files changed

+76
-6
lines changed

clang/lib/CodeGen/ABIInfoImpl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ ABIArgInfo DefaultABIInfo::classifyArgumentType(QualType Ty) const {
3838
: Context.LongLongTy))
3939
return getNaturalAlignIndirect(Ty);
4040

41-
return (isPromotableIntegerTypeForABI(Ty) ? ABIArgInfo::getExtend(Ty)
42-
: ABIArgInfo::getDirect());
41+
return (isPromotableIntegerTypeForABI(Ty)
42+
? ABIArgInfo::getExtend(Ty, CGT.ConvertType(Ty))
43+
: ABIArgInfo::getDirect());
4344
}
4445

4546
ABIArgInfo DefaultABIInfo::classifyReturnType(QualType RetTy) const {

clang/lib/CodeGen/Targets/PPC.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ ABIArgInfo AIXABIInfo::classifyArgumentType(QualType Ty) const {
217217
/*Realign*/ TyAlign > CCAlign);
218218
}
219219

220-
return (isPromotableTypeForABI(Ty) ? ABIArgInfo::getExtend(Ty)
221-
: ABIArgInfo::getDirect());
220+
return (isPromotableTypeForABI(Ty)
221+
? ABIArgInfo::getExtend(Ty, CGT.ConvertType(Ty))
222+
: ABIArgInfo::getDirect());
222223
}
223224

224225
CharUnits AIXABIInfo::getParamTypeAlignment(QualType Ty) const {
@@ -891,8 +892,9 @@ PPC64_SVR4_ABIInfo::classifyArgumentType(QualType Ty) const {
891892
/*Realign=*/TyAlign > ABIAlign);
892893
}
893894

894-
return (isPromotableTypeForABI(Ty) ? ABIArgInfo::getExtend(Ty)
895-
: ABIArgInfo::getDirect());
895+
return (isPromotableTypeForABI(Ty)
896+
? ABIArgInfo::getExtend(Ty, CGT.ConvertType(Ty))
897+
: ABIArgInfo::getDirect());
896898
}
897899

898900
ABIArgInfo
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// RUN: %clang_cc1 -triple powerpc64le-unknown-linux -O2 -target-cpu pwr7 \
2+
// RUN: -emit-llvm -fshort-enums %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-64
3+
// RUN: %clang_cc1 -triple powerpc64-unknown-linux -O2 -target-cpu pwr7 \
4+
// RUN: -emit-llvm -fshort-enums %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-64
5+
// RUN: %clang_cc1 -triple powerpc-unknown-linux -O2 -target-cpu pwr7 \
6+
// RUN: -emit-llvm -fshort-enums %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-32
7+
// RUN: %clang_cc1 -triple powerpc64-unknown-aix -O2 -target-cpu pwr7 \
8+
// RUN: -emit-llvm -fshort-enums %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-64
9+
// RUN: %clang_cc1 -triple powerpc-unknown-aix -O2 -target-cpu pwr7 \
10+
// RUN: -emit-llvm -fshort-enums %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-32
11+
12+
typedef union tu_c {
13+
signed char a;
14+
signed char b;
15+
} tu_c_t __attribute__((transparent_union));
16+
17+
typedef union tu_s {
18+
short a;
19+
} tu_s_t __attribute__((transparent_union));
20+
21+
typedef union tu_us {
22+
unsigned short a;
23+
} tu_us_t __attribute__((transparent_union));
24+
25+
typedef union tu_l {
26+
long a;
27+
} tu_l_t __attribute__((transparent_union));
28+
29+
// CHECK-LABEL: define{{.*}} void @ftest0(
30+
// CHECK-SAME: i8 noundef signext [[UC_COERCE:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
31+
// CHECK-NEXT: [[ENTRY:.*:]]
32+
// CHECK-NEXT: ret void
33+
void ftest0(tu_c_t uc) { }
34+
35+
// CHECK-LABEL: define{{.*}} void @ftest1(
36+
// CHECK-SAME: i16 noundef signext [[UC_COERCE:%.*]]) local_unnamed_addr #[[ATTR0]] {
37+
// CHECK-NEXT: [[ENTRY:.*:]]
38+
// CHECK-NEXT: ret void
39+
void ftest1(tu_s_t uc) { }
40+
41+
// CHECK-LABEL: define{{.*}} void @ftest2(
42+
// CHECK-SAME: i16 noundef zeroext [[UC_COERCE:%.*]]) local_unnamed_addr #[[ATTR0]] {
43+
// CHECK-NEXT: [[ENTRY:.*:]]
44+
// CHECK-NEXT: ret void
45+
void ftest2(tu_us_t uc) { }
46+
47+
// CHECK-64-LABEL: define{{.*}} void @ftest3(
48+
// CHECK-64-SAME: i64 [[UC_COERCE:%.*]]) local_unnamed_addr #[[ATTR0]] {
49+
// CHECK-64-NEXT: [[ENTRY:.*:]]
50+
// CHECK-64-NEXT: ret void
51+
//
52+
// CHECK-32-LABEL: define{{.*}} void @ftest3(
53+
// CHECK-32-SAME: i32 [[UC_COERCE:%.*]]) local_unnamed_addr #[[ATTR0]] {
54+
// CHECK-32-NEXT: [[ENTRY:.*:]]
55+
// CHECK-32-NEXT: ret void
56+
void ftest3(tu_l_t uc) { }
57+
58+
typedef union etest {
59+
enum flag {red, yellow, blue} fl;
60+
enum weekend {sun, sat} b;
61+
} etest_t __attribute__((transparent_union));
62+
63+
// CHECK-LABEL: define{{.*}} void @ftest4(
64+
// CHECK-SAME: i8 noundef zeroext [[A_COERCE:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
65+
// CHECK-NEXT: [[ENTRY:.*:]]
66+
// CHECK-NEXT: ret void
67+
void ftest4(etest_t a) {}

0 commit comments

Comments
 (0)