Skip to content

Commit 2468a85

Browse files
committed
[OpenCL] Fix an infinite loop in builidng AddrSpaceQualType
In building AddrSpaceQualType (llvm#90048), there is a bug in removeAddrSpaceQualType() for arrays. Arrays are weird because qualifiers on the element type also count as qualifiers on the type, so getSingleStepDesugaredType() can't remove the sugar on arrays. This results in an infinite loop in removeAddrSpaceQualType. To fix the issue, we use ASTContext::getUnqualifiedArrayType, which strips the qualifier off the element type, then reconstruct the array type.
1 parent e2db08f commit 2468a85

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
537537
elementType.isTriviallyCopyableType(CGF.getContext())) {
538538
CodeGen::CodeGenModule &CGM = CGF.CGM;
539539
ConstantEmitter Emitter(CGF);
540+
Qualifiers Quals;
540541
QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType(
541-
CGM.getContext().removeAddrSpaceQualType(ArrayQTy),
542+
CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals),
542543
CGM.GetGlobalConstantAddressSpace());
543544
LangAS AS = GVArrayQTy.getAddressSpace();
544545
if (llvm::Constant *C =
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4
2+
//RUN: %clang_cc1 %s -emit-llvm -O1 -o - | FileCheck %s
3+
4+
// CHECK-LABEL: define dso_local spir_kernel void @test(
5+
// CHECK-SAME: ptr nocapture noundef readonly align 8 [[IN:%.*]], ptr nocapture noundef writeonly align 8 [[OUT:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] !kernel_arg_addr_space [[META3:![0-9]+]] !kernel_arg_access_qual [[META4:![0-9]+]] !kernel_arg_type [[META5:![0-9]+]] !kernel_arg_base_type [[META5]] !kernel_arg_type_qual [[META6:![0-9]+]] {
6+
// CHECK-NEXT: entry:
7+
// CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[IN]], i64 8
8+
// CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr [[ARRAYIDX1]], align 8, !tbaa [[TBAA7:![0-9]+]]
9+
// CHECK-NEXT: store i64 [[TMP0]], ptr [[OUT]], align 8, !tbaa [[TBAA7]]
10+
// CHECK-NEXT: ret void
11+
//
12+
__kernel void test(__global long *In, __global long *Out) {
13+
long m[4] = { In[0], In[1], 0, 0 };
14+
*Out = m[1];
15+
}
16+
//.
17+
// CHECK: [[META3]] = !{i32 1, i32 1}
18+
// CHECK: [[META4]] = !{!"none", !"none"}
19+
// CHECK: [[META5]] = !{!"long*", !"long*"}
20+
// CHECK: [[META6]] = !{!"", !""}
21+
// CHECK: [[TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0}
22+
// CHECK: [[META8]] = !{!"long", [[META9:![0-9]+]], i64 0}
23+
// CHECK: [[META9]] = !{!"omnipotent char", [[META10:![0-9]+]], i64 0}
24+
// CHECK: [[META10]] = !{!"Simple C++ TBAA"}
25+
//.

0 commit comments

Comments
 (0)