Skip to content

Commit 9840208

Browse files
committed
[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
1 parent c332a98 commit 9840208

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,11 @@ OpenMPClauseKind Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level,
22442244
[](OpenMPDirectiveKind K) { return isOpenMPTaskingDirective(K); },
22452245
Level)) {
22462246
bool IsTriviallyCopyable =
2247-
D->getType().getNonReferenceType().isTriviallyCopyableType(Context);
2247+
D->getType().getNonReferenceType().isTriviallyCopyableType(Context) &&
2248+
!D->getType()
2249+
.getNonReferenceType()
2250+
.getCanonicalType()
2251+
->getAsCXXRecordDecl();
22482252
OpenMPDirectiveKind DKind = DSAStack->getDirective(Level);
22492253
SmallVector<OpenMPDirectiveKind, 4> CaptureRegions;
22502254
getOpenMPCaptureRegions(CaptureRegions, DKind);

clang/test/OpenMP/taskloop_codegen.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,20 @@ struct S {
229229
// CHECK: br label %
230230
// CHECK: ret i32 0
231231

232+
class St {
233+
public:
234+
operator int();
235+
St &operator+=(int);
236+
};
237+
238+
// CHECK-LABEL: taskloop_with_class
239+
void taskloop_with_class() {
240+
St s1;
241+
// 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*)*))
242+
// 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*))
243+
#pragma omp taskloop
244+
for (St s = St(); s < s1; s += 1) {
245+
}
246+
}
247+
232248
#endif

0 commit comments

Comments
 (0)