diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2020-07-15 17:32:02 -0400 |
---|---|---|
committer | Hans Wennborg <hans@chromium.org> | 2020-07-27 16:15:20 +0200 |
commit | d3600f84c4a7a6826f33d45b2545b4e915ab3a5c (patch) | |
tree | 793cdfb9d712cb3b99f987cf15561b9c447e8478 | |
parent | 405d10e4ad134a5eb573d6d1fdd7ad99f3f8c5ea (diff) | |
download | llvm-d3600f84c4a7a6826f33d45b2545b4e915ab3a5c.zip llvm-d3600f84c4a7a6826f33d45b2545b4e915ab3a5c.tar.gz llvm-d3600f84c4a7a6826f33d45b2545b4e915ab3a5c.tar.bz2 |
[OPENMP] Fix PR46730: Fix compiler crash on taskloop over constructible loop counters.
Summary:
If the variable is constrcutible, its copy is created by calling a
constructor. Such variables are duplicated and thus, must be captured.
Reviewers: jdoerfert
Subscribers: yaxunl, guansong, cfe-commits, sstefan1, caomhin
Tags: #clang
Differential Revision: https://reviews.llvm.org/D83909
(cherry picked from commit 9840208db6980f690d09b209e6ad6d57133ec5e5)
-rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 6 | ||||
-rw-r--r-- | clang/test/OpenMP/taskloop_codegen.cpp | 16 |
2 files changed, 21 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 8bf605e..533c5b1 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -2244,7 +2244,11 @@ OpenMPClauseKind Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level, [](OpenMPDirectiveKind K) { return isOpenMPTaskingDirective(K); }, Level)) { bool IsTriviallyCopyable = - D->getType().getNonReferenceType().isTriviallyCopyableType(Context); + D->getType().getNonReferenceType().isTriviallyCopyableType(Context) && + !D->getType() + .getNonReferenceType() + .getCanonicalType() + ->getAsCXXRecordDecl(); OpenMPDirectiveKind DKind = DSAStack->getDirective(Level); SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; getOpenMPCaptureRegions(CaptureRegions, DKind); diff --git a/clang/test/OpenMP/taskloop_codegen.cpp b/clang/test/OpenMP/taskloop_codegen.cpp index 55e43ff..7402c2a 100644 --- a/clang/test/OpenMP/taskloop_codegen.cpp +++ b/clang/test/OpenMP/taskloop_codegen.cpp @@ -229,4 +229,20 @@ struct S { // CHECK: br label % // CHECK: ret i32 0 +class St { +public: + operator int(); + St &operator+=(int); +}; + +// CHECK-LABEL: taskloop_with_class +void taskloop_with_class() { + St s1; + // CHECK: [[TD:%.+]] = call i8* @__kmpc_omp_task_alloc(%struct.ident_t* @{{.+}}, i32 [[GTID:%.+]], i32 1, i64 88, i64 8, i32 (i32, i8*)* bitcast (i32 (i32, [[TD_TYPE:%.+]]*)* @{{.+}} to i32 (i32, i8*)*)) + // CHECK: call void @__kmpc_taskloop(%struct.ident_t* @{{.+}}, i32 [[GTID]], i8* [[TD]], i32 1, i64* %{{.+}}, i64* %{{.+}}, i64 %{{.+}}, i32 1, i32 0, i64 0, i8* bitcast (void ([[TD_TYPE]]*, [[TD_TYPE]]*, i32)* @{{.+}} to i8*)) +#pragma omp taskloop + for (St s = St(); s < s1; s += 1) { + } +} + #endif |