Skip to content

Commit 2276733

Browse files
committed
[X86] Always check the size of SourceTy before getting the next type
D109607 results in a regression in llvm-test-suite. The reason is we didn't check the size of SourceTy, so that we will return wrong SSE type when SourceTy is overlapped. Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D110037
1 parent 5b47256 commit 2276733

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,17 +3438,21 @@ llvm::Type *X86_64ABIInfo::
34383438
GetSSETypeAtOffset(llvm::Type *IRType, unsigned IROffset,
34393439
QualType SourceTy, unsigned SourceOffset) const {
34403440
const llvm::DataLayout &TD = getDataLayout();
3441+
unsigned SourceSize =
3442+
(unsigned)getContext().getTypeSize(SourceTy) / 8 - SourceOffset;
34413443
llvm::Type *T0 = getFPTypeAtOffset(IRType, IROffset, TD);
34423444
if (!T0 || T0->isDoubleTy())
34433445
return llvm::Type::getDoubleTy(getVMContext());
34443446

34453447
// Get the adjacent FP type.
3446-
llvm::Type *T1 =
3447-
getFPTypeAtOffset(IRType, IROffset + TD.getTypeAllocSize(T0), TD);
3448+
llvm::Type *T1 = nullptr;
3449+
unsigned T0Size = TD.getTypeAllocSize(T0);
3450+
if (SourceSize > T0Size)
3451+
T1 = getFPTypeAtOffset(IRType, IROffset + T0Size, TD);
34483452
if (T1 == nullptr) {
34493453
// Check if IRType is a half + float. float type will be in IROffset+4 due
34503454
// to its alignment.
3451-
if (T0->isHalfTy())
3455+
if (T0->isHalfTy() && SourceSize > 4)
34523456
T1 = getFPTypeAtOffset(IRType, IROffset + 4, TD);
34533457
// If we can't get a second FP type, return a simple half or float.
34543458
// avx512fp16-abi.c:pr51813_2 shows it works to return float for
@@ -3461,7 +3465,9 @@ GetSSETypeAtOffset(llvm::Type *IRType, unsigned IROffset,
34613465
return llvm::FixedVectorType::get(T0, 2);
34623466

34633467
if (T0->isHalfTy() && T1->isHalfTy()) {
3464-
llvm::Type *T2 = getFPTypeAtOffset(IRType, IROffset + 4, TD);
3468+
llvm::Type *T2 = nullptr;
3469+
if (SourceSize > 4)
3470+
T2 = getFPTypeAtOffset(IRType, IROffset + 4, TD);
34653471
if (T2 == nullptr)
34663472
return llvm::FixedVectorType::get(T0, 2);
34673473
return llvm::FixedVectorType::get(T0, 4);

clang/test/CodeGen/X86/va-arg-sse.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ struct S a[5];
3434
// CHECK-NEXT: [[REG_SAVE_AREA:%.*]] = load i8*, i8** [[TMP0]], align 16
3535
// CHECK-NEXT: [[TMP1:%.*]] = getelementptr i8, i8* [[REG_SAVE_AREA]], i32 [[FP_OFFSET]]
3636
// CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds i8, i8* [[TMP1]], i64 16
37-
// CHECK-NEXT: [[TMP3:%.*]] = bitcast %struct.S* [[TMP]] to { <2 x float>, <2 x float> }*
37+
// CHECK-NEXT: [[TMP3:%.*]] = bitcast %struct.S* [[TMP]] to { <2 x float>, float }*
3838
// CHECK-NEXT: [[TMP4:%.*]] = bitcast i8* [[TMP1]] to <2 x float>*
3939
// CHECK-NEXT: [[TMP5:%.*]] = load <2 x float>, <2 x float>* [[TMP4]], align 16
40-
// CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds { <2 x float>, <2 x float> }, { <2 x float>, <2 x float> }* [[TMP3]], i32 0, i32 0
40+
// CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds { <2 x float>, float }, { <2 x float>, float }* [[TMP3]], i32 0, i32 0
4141
// CHECK-NEXT: store <2 x float> [[TMP5]], <2 x float>* [[TMP6]], align 4
42-
// CHECK-NEXT: [[TMP7:%.*]] = bitcast i8* [[TMP2]] to <2 x float>*
43-
// CHECK-NEXT: [[TMP8:%.*]] = load <2 x float>, <2 x float>* [[TMP7]], align 16
44-
// CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds { <2 x float>, <2 x float> }, { <2 x float>, <2 x float> }* [[TMP3]], i32 0, i32 1
45-
// CHECK-NEXT: store <2 x float> [[TMP8]], <2 x float>* [[TMP9]], align 4
46-
// CHECK-NEXT: [[TMP10:%.*]] = bitcast { <2 x float>, <2 x float> }* [[TMP3]] to %struct.S*
42+
// CHECK-NEXT: [[TMP7:%.*]] = bitcast i8* [[TMP2]] to float*
43+
// CHECK-NEXT: [[TMP8:%.*]] = load float, float* [[TMP7]], align 16
44+
// CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds { <2 x float>, float }, { <2 x float>, float }* [[TMP3]], i32 0, i32 1
45+
// CHECK-NEXT: store float [[TMP8]], float* [[TMP9]], align 4
46+
// CHECK-NEXT: [[TMP10:%.*]] = bitcast { <2 x float>, float }* [[TMP3]] to %struct.S*
4747
// CHECK-NEXT: [[TMP11:%.*]] = add i32 [[FP_OFFSET]], 32
4848
// CHECK-NEXT: store i32 [[TMP11]], i32* [[FP_OFFSET_P]], align 4
4949
// CHECK-NEXT: br label [[VAARG_END:%.*]]

0 commit comments

Comments
 (0)