Skip to content

Commit ba641b7

Browse files
committed
Merging r315464:
------------------------------------------------------------------------ r315464 | abataev | 2017-10-11 08:29:40 -0700 (Wed, 11 Oct 2017) | 5 lines [OPENMP] Fix PR34916: Crash on mixing taskloop|tasks directives. If both taskloop and task directives are used at the same time in one program, we may ran into the situation when the particular type for task directive is reused for taskloop directives. Patch fixes this problem. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_50@318233 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 4ab9ad7 commit ba641b7

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4249,9 +4249,20 @@ CGOpenMPRuntime::emitTaskInit(CodeGenFunction &CGF, SourceLocation Loc,
42494249
// Build type kmp_routine_entry_t (if not built yet).
42504250
emitKmpRoutineEntryT(KmpInt32Ty);
42514251
// Build type kmp_task_t (if not built yet).
4252-
if (KmpTaskTQTy.isNull()) {
4253-
KmpTaskTQTy = C.getRecordType(createKmpTaskTRecordDecl(
4254-
CGM, D.getDirectiveKind(), KmpInt32Ty, KmpRoutineEntryPtrQTy));
4252+
if (isOpenMPTaskLoopDirective(D.getDirectiveKind())) {
4253+
if (SavedKmpTaskloopTQTy.isNull()) {
4254+
SavedKmpTaskloopTQTy = C.getRecordType(createKmpTaskTRecordDecl(
4255+
CGM, D.getDirectiveKind(), KmpInt32Ty, KmpRoutineEntryPtrQTy));
4256+
}
4257+
KmpTaskTQTy = SavedKmpTaskloopTQTy;
4258+
} else if (D.getDirectiveKind() == OMPD_task) {
4259+
assert(D.getDirectiveKind() == OMPD_task &&
4260+
"Expected taskloop or task directive");
4261+
if (SavedKmpTaskTQTy.isNull()) {
4262+
SavedKmpTaskTQTy = C.getRecordType(createKmpTaskTRecordDecl(
4263+
CGM, D.getDirectiveKind(), KmpInt32Ty, KmpRoutineEntryPtrQTy));
4264+
}
4265+
KmpTaskTQTy = SavedKmpTaskTQTy;
42554266
}
42564267
auto *KmpTaskTQTyRD = cast<RecordDecl>(KmpTaskTQTy->getAsTagDecl());
42574268
// Build particular struct kmp_task_t for the given task.

lib/CodeGen/CGOpenMPRuntime.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ class CGOpenMPRuntime {
313313
/// deconstructors of firstprivate C++ objects */
314314
/// } kmp_task_t;
315315
QualType KmpTaskTQTy;
316+
/// Saved kmp_task_t for task directive.
317+
QualType SavedKmpTaskTQTy;
318+
/// Saved kmp_task_t for taskloop-based directive.
319+
QualType SavedKmpTaskloopTQTy;
316320
/// \brief Type typedef struct kmp_depend_info {
317321
/// kmp_intptr_t base_addr;
318322
/// size_t len;

test/OpenMP/taskloop_codegen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
// CHECK-LABEL: @main
99
int main(int argc, char **argv) {
1010
// CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(%ident_t* [[DEFLOC:@.+]])
11+
// CHECK: call i8* @__kmpc_omp_task_alloc(%ident_t* [[DEFLOC]], i32 [[GTID]],
12+
// CHECK: call i32 @__kmpc_omp_task(%ident_t* [[DEFLOC]], i32 [[GTID]],
13+
#pragma omp task
14+
;
1115
// CHECK: call void @__kmpc_taskgroup(%ident_t* [[DEFLOC]], i32 [[GTID]])
1216
// CHECK: [[TASKV:%.+]] = call i8* @__kmpc_omp_task_alloc(%ident_t* [[DEFLOC]], i32 [[GTID]], i32 33, i64 80, i64 1, i32 (i32, i8*)* bitcast (i32 (i32, [[TDP_TY:%.+]]*)* [[TASK1:@.+]] to i32 (i32, i8*)*))
1317
// CHECK: [[TASK:%.+]] = bitcast i8* [[TASKV]] to [[TDP_TY]]*

0 commit comments

Comments
 (0)