[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
https://github.com/changpeng closed https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
https://github.com/efriedma-quic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
@@ -0,0 +1,25 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +//RUN: %clang_cc1 %s -emit-llvm -O1 -o - | FileCheck %s changpeng wrote: add "triple spir", same as other tests in the same directory https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
https://github.com/changpeng updated https://github.com/llvm/llvm-project/pull/92612 >From 2468a85a47499d90a99610846c632332eb7307b8 Mon Sep 17 00:00:00 2001 From: Changpeng Fang Date: Fri, 17 May 2024 15:13:07 -0700 Subject: [PATCH 1/3] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType In building AddrSpaceQualType (https://github.com/llvm/llvm-project/pull/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. --- clang/lib/CodeGen/CGExprAgg.cpp | 3 ++- .../array-type-infinite-loop.clcpp| 25 +++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 6172eb9cdc1bb..53ce133e8cbc6 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), CGM.GetGlobalConstantAddressSpace()); LangAS AS = GVArrayQTy.getAddressSpace(); if (llvm::Constant *C = diff --git a/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp new file mode 100644 index 0..5a5b104e892f7 --- /dev/null +++ b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp @@ -0,0 +1,25 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +//RUN: %clang_cc1 %s -emit-llvm -O1 -o - | FileCheck %s + +// CHECK-LABEL: define dso_local spir_kernel void @test( +// 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]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[IN]], i64 8 +// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr [[ARRAYIDX1]], align 8, !tbaa [[TBAA7:![0-9]+]] +// CHECK-NEXT:store i64 [[TMP0]], ptr [[OUT]], align 8, !tbaa [[TBAA7]] +// CHECK-NEXT:ret void +// +__kernel void test(__global long *In, __global long *Out) { + long m[4] = { In[0], In[1], 0, 0 }; + *Out = m[1]; +} +//. +// CHECK: [[META3]] = !{i32 1, i32 1} +// CHECK: [[META4]] = !{!"none", !"none"} +// CHECK: [[META5]] = !{!"long*", !"long*"} +// CHECK: [[META6]] = !{!"", !""} +// CHECK: [[TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0} +// CHECK: [[META8]] = !{!"long", [[META9:![0-9]+]], i64 0} +// CHECK: [[META9]] = !{!"omnipotent char", [[META10:![0-9]+]], i64 0} +// CHECK: [[META10]] = !{!"Simple C++ TBAA"} +//. >From 17ac766cdcbf22af685b89b9a054a22afb42f46e Mon Sep 17 00:00:00 2001 From: Changpeng Fang Date: Fri, 17 May 2024 18:20:06 -0700 Subject: [PATCH 2/3] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType Fix ASTContext::removeAddrSpaceQualType() --- clang/include/clang/AST/ASTContext.h | 2 +- clang/lib/AST/ASTContext.cpp | 9 - clang/lib/CodeGen/CGExprAgg.cpp | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index e03b112194786..2ce2b810d3636 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -2611,7 +2611,7 @@ class ASTContext : public RefCountedBase { /// /// \returns if this is an array type, the completely unqualified array type /// that corresponds to it. Otherwise, returns T.getUnqualifiedType(). - QualType getUnqualifiedArrayType(QualType T, Qualifiers ); + QualType getUnqualifiedArrayType(QualType T, Qualifiers ) const; /// Determine whether the given types are equivalent after /// cvr-qualifiers have been removed. diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 8fc2bb8c401c2..388233c554d46 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -3054,6 +3054,13 @@ QualType ASTContext::removeAddrSpaceQualType(QualType T) const { if (!T.hasAddressSpace())
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
https://github.com/changpeng edited https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
@@ -3054,6 +3054,13 @@ QualType ASTContext::removeAddrSpaceQualType(QualType T) const { if (!T.hasAddressSpace()) return T; + // For arrays, strip the qualifier off the element type, then reconstruct the + // array type + if (T.getTypePtr()->isArrayType()) { +Qualifiers Qualfs; +return getUnqualifiedArrayType(T, Qualfs); changpeng wrote: Thanks. Can I do as the following? Note that I am passing QualifierCollector to getUnqualifiedArrayType, which has Qualifiers as the second argument. Also, TypeNode = T.getTypePtr(); after I is unqualified. QualifierCollector Quals; const Type *TypeNode; if (T.getTypePtr()->isArrayType()) { T = getUnqualifiedArrayType(T, Quals); TypeNode = T.getTypePtr(); } else { while (T.hasAddressSpace()) { https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
@@ -3054,6 +3054,13 @@ QualType ASTContext::removeAddrSpaceQualType(QualType T) const { if (!T.hasAddressSpace()) return T; + // For arrays, strip the qualifier off the element type, then reconstruct the + // array type + if (T.getTypePtr()->isArrayType()) { +Qualifiers Qualfs; +return getUnqualifiedArrayType(T, Qualfs); efriedma-quic wrote: You need to preserve the non-address-space qualifiers, the same way the code after the loop does. Actually, I'd just recommend restructuring to use the existing code, something like: ``` if (T.getTypePtr()->isArrayType()) { getUnqualifiedArrayType() } else { while (T.hasAddressSpace()) { [...] } } ``` https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
@@ -0,0 +1,25 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +//RUN: %clang_cc1 %s -emit-llvm -O1 -o - | FileCheck %s arsenm wrote: codegen tests need an explicit target https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
@@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), changpeng wrote: > Something like that, yes. Thanks. Updated. Should be closer! https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
https://github.com/changpeng updated https://github.com/llvm/llvm-project/pull/92612 >From 2468a85a47499d90a99610846c632332eb7307b8 Mon Sep 17 00:00:00 2001 From: Changpeng Fang Date: Fri, 17 May 2024 15:13:07 -0700 Subject: [PATCH 1/2] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType In building AddrSpaceQualType (https://github.com/llvm/llvm-project/pull/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. --- clang/lib/CodeGen/CGExprAgg.cpp | 3 ++- .../array-type-infinite-loop.clcpp| 25 +++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 6172eb9cdc1bb..53ce133e8cbc6 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), CGM.GetGlobalConstantAddressSpace()); LangAS AS = GVArrayQTy.getAddressSpace(); if (llvm::Constant *C = diff --git a/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp new file mode 100644 index 0..5a5b104e892f7 --- /dev/null +++ b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp @@ -0,0 +1,25 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +//RUN: %clang_cc1 %s -emit-llvm -O1 -o - | FileCheck %s + +// CHECK-LABEL: define dso_local spir_kernel void @test( +// 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]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[IN]], i64 8 +// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr [[ARRAYIDX1]], align 8, !tbaa [[TBAA7:![0-9]+]] +// CHECK-NEXT:store i64 [[TMP0]], ptr [[OUT]], align 8, !tbaa [[TBAA7]] +// CHECK-NEXT:ret void +// +__kernel void test(__global long *In, __global long *Out) { + long m[4] = { In[0], In[1], 0, 0 }; + *Out = m[1]; +} +//. +// CHECK: [[META3]] = !{i32 1, i32 1} +// CHECK: [[META4]] = !{!"none", !"none"} +// CHECK: [[META5]] = !{!"long*", !"long*"} +// CHECK: [[META6]] = !{!"", !""} +// CHECK: [[TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0} +// CHECK: [[META8]] = !{!"long", [[META9:![0-9]+]], i64 0} +// CHECK: [[META9]] = !{!"omnipotent char", [[META10:![0-9]+]], i64 0} +// CHECK: [[META10]] = !{!"Simple C++ TBAA"} +//. >From 17ac766cdcbf22af685b89b9a054a22afb42f46e Mon Sep 17 00:00:00 2001 From: Changpeng Fang Date: Fri, 17 May 2024 18:20:06 -0700 Subject: [PATCH 2/2] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType Fix ASTContext::removeAddrSpaceQualType() --- clang/include/clang/AST/ASTContext.h | 2 +- clang/lib/AST/ASTContext.cpp | 9 - clang/lib/CodeGen/CGExprAgg.cpp | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index e03b112194786..2ce2b810d3636 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -2611,7 +2611,7 @@ class ASTContext : public RefCountedBase { /// /// \returns if this is an array type, the completely unqualified array type /// that corresponds to it. Otherwise, returns T.getUnqualifiedType(). - QualType getUnqualifiedArrayType(QualType T, Qualifiers ); + QualType getUnqualifiedArrayType(QualType T, Qualifiers ) const; /// Determine whether the given types are equivalent after /// cvr-qualifiers have been removed. diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 8fc2bb8c401c2..388233c554d46 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -3054,6 +3054,13 @@ QualType ASTContext::removeAddrSpaceQualType(QualType T) const { if (!T.hasAddressSpace())
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
@@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), efriedma-quic wrote: Something like that, yes. https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
@@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), changpeng wrote: Do you mean we should actually fix removeAddrSpaceQualType? Somewhere inside removeAddrSpaceQualType, we should use getUnqualifiedArrayType if it is an arrayType, and getSingleStepDesugaredType othereise? I have to admit that I have no experience in this field, so I am relying on you and @svenvh to move on for a reasonable fix. Thanks. https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
@@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), efriedma-quic wrote: I see two issues with this fix: 1. It leaves removeAddrSpaceQualType broken for anyone else who tries to use it. Ideally, removeAddrSpaceQualType should do what it says. 2. This drops other qualifiers on the floor; they might be relevant in some cases. https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Changpeng Fang (changpeng) Changes In building AddrSpaceQualType (https://github.com/llvm/llvm-project/pull/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 instead, which strips the qualifier off the element type, then reconstruct the array type. --- Full diff: https://github.com/llvm/llvm-project/pull/92612.diff 2 Files Affected: - (modified) clang/lib/CodeGen/CGExprAgg.cpp (+2-1) - (added) clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp (+25) ``diff diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 6172eb9cdc1bb..53ce133e8cbc6 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), CGM.GetGlobalConstantAddressSpace()); LangAS AS = GVArrayQTy.getAddressSpace(); if (llvm::Constant *C = diff --git a/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp new file mode 100644 index 0..5a5b104e892f7 --- /dev/null +++ b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp @@ -0,0 +1,25 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +//RUN: %clang_cc1 %s -emit-llvm -O1 -o - | FileCheck %s + +// CHECK-LABEL: define dso_local spir_kernel void @test( +// 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]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[IN]], i64 8 +// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr [[ARRAYIDX1]], align 8, !tbaa [[TBAA7:![0-9]+]] +// CHECK-NEXT:store i64 [[TMP0]], ptr [[OUT]], align 8, !tbaa [[TBAA7]] +// CHECK-NEXT:ret void +// +__kernel void test(__global long *In, __global long *Out) { + long m[4] = { In[0], In[1], 0, 0 }; + *Out = m[1]; +} +//. +// CHECK: [[META3]] = !{i32 1, i32 1} +// CHECK: [[META4]] = !{!"none", !"none"} +// CHECK: [[META5]] = !{!"long*", !"long*"} +// CHECK: [[META6]] = !{!"", !""} +// CHECK: [[TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0} +// CHECK: [[META8]] = !{!"long", [[META9:![0-9]+]], i64 0} +// CHECK: [[META9]] = !{!"omnipotent char", [[META10:![0-9]+]], i64 0} +// CHECK: [[META10]] = !{!"Simple C++ TBAA"} +//. `` https://github.com/llvm/llvm-project/pull/92612 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType (PR #92612)
https://github.com/changpeng created https://github.com/llvm/llvm-project/pull/92612 In building AddrSpaceQualType (https://github.com/llvm/llvm-project/pull/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 instead, which strips the qualifier off the element type, then reconstruct the array type. >From 2468a85a47499d90a99610846c632332eb7307b8 Mon Sep 17 00:00:00 2001 From: Changpeng Fang Date: Fri, 17 May 2024 15:13:07 -0700 Subject: [PATCH] [OpenCL] Fix an infinite loop in builidng AddrSpaceQualType In building AddrSpaceQualType (https://github.com/llvm/llvm-project/pull/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. --- clang/lib/CodeGen/CGExprAgg.cpp | 3 ++- .../array-type-infinite-loop.clcpp| 25 +++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 6172eb9cdc1bb..53ce133e8cbc6 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -537,8 +537,9 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType, elementType.isTriviallyCopyableType(CGF.getContext())) { CodeGen::CodeGenModule = CGF.CGM; ConstantEmitter Emitter(CGF); +Qualifiers Quals; QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType( -CGM.getContext().removeAddrSpaceQualType(ArrayQTy), +CGM.getContext().getUnqualifiedArrayType(ArrayQTy, Quals), CGM.GetGlobalConstantAddressSpace()); LangAS AS = GVArrayQTy.getAddressSpace(); if (llvm::Constant *C = diff --git a/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp new file mode 100644 index 0..5a5b104e892f7 --- /dev/null +++ b/clang/test/CodeGenOpenCLCXX/array-type-infinite-loop.clcpp @@ -0,0 +1,25 @@ +// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 4 +//RUN: %clang_cc1 %s -emit-llvm -O1 -o - | FileCheck %s + +// CHECK-LABEL: define dso_local spir_kernel void @test( +// 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]+]] { +// CHECK-NEXT: entry: +// CHECK-NEXT:[[ARRAYIDX1:%.*]] = getelementptr inbounds i8, ptr [[IN]], i64 8 +// CHECK-NEXT:[[TMP0:%.*]] = load i64, ptr [[ARRAYIDX1]], align 8, !tbaa [[TBAA7:![0-9]+]] +// CHECK-NEXT:store i64 [[TMP0]], ptr [[OUT]], align 8, !tbaa [[TBAA7]] +// CHECK-NEXT:ret void +// +__kernel void test(__global long *In, __global long *Out) { + long m[4] = { In[0], In[1], 0, 0 }; + *Out = m[1]; +} +//. +// CHECK: [[META3]] = !{i32 1, i32 1} +// CHECK: [[META4]] = !{!"none", !"none"} +// CHECK: [[META5]] = !{!"long*", !"long*"} +// CHECK: [[META6]] = !{!"", !""} +// CHECK: [[TBAA7]] = !{[[META8:![0-9]+]], [[META8]], i64 0} +// CHECK: [[META8]] = !{!"long", [[META9:![0-9]+]], i64 0} +// CHECK: [[META9]] = !{!"omnipotent char", [[META10:![0-9]+]], i64 0} +// CHECK: [[META10]] = !{!"Simple C++ TBAA"} +//. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits