[flang][OpenMP] Fix copyprivate crash with unlimited polymorphic pointer#199768
Open
ceseo wants to merge 1 commit into
Open
[flang][OpenMP] Fix copyprivate crash with unlimited polymorphic pointer#199768ceseo wants to merge 1 commit into
ceseo wants to merge 1 commit into
Conversation
Lowering a copyprivate clause whose list item is an unlimited polymorphic pointer (class(*), pointer) crashed in TypeInfo::typeScan. The scan descends through the fir.class box and the fir.ptr, reaching a `none` element type, which the terminal assertion did not allow. Fixes llvm#198770
|
@llvm/pr-subscribers-flang-openmp @llvm/pr-subscribers-flang-fir-hlfir Author: Carlos Seo (ceseo) ChangesLowering a copyprivate clause whose list item is an unlimited polymorphic pointer (class(*), pointer) crashed in TypeInfo::typeScan. The scan descends through the fir.class box and the fir.ptr, reaching a Fixes #198770 Full diff: https://github.com/llvm/llvm-project/pull/199768.diff 2 Files Affected:
diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
index 213b5f783430e..aa6d2e6753941 100644
--- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp
@@ -1179,9 +1179,13 @@ void TypeInfo::typeScan(mlir::Type ty) {
typeScan(pty.getEleTy());
} else {
// The scan ends when reaching any built-in, record or boxproc type.
+ // A `none` element type is reached for unlimited polymorphic entities
+ // (e.g. `class(*)`), which are always inside a box; the copy is then
+ // performed through the descriptor, so no scalar type info is needed.
assert(ty.isIntOrIndexOrFloat() || mlir::isa<mlir::ComplexType>(ty) ||
mlir::isa<fir::LogicalType>(ty) || mlir::isa<fir::RecordType>(ty) ||
- mlir::isa<fir::BoxProcType>(ty));
+ mlir::isa<fir::BoxProcType>(ty) ||
+ (inBox && mlir::isa<mlir::NoneType>(ty)));
}
}
diff --git a/flang/test/Lower/OpenMP/copyprivate6.f90 b/flang/test/Lower/OpenMP/copyprivate6.f90
new file mode 100644
index 0000000000000..39b33946b2cee
--- /dev/null
+++ b/flang/test/Lower/OpenMP/copyprivate6.f90
@@ -0,0 +1,26 @@
+! Test lowering of COPYPRIVATE with an unlimited polymorphic pointer.
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
+
+! Testcase from: https://github.com/llvm/llvm-project/issues/198770
+
+! CHECK-LABEL: func.func private @_copy_ref_class_ptr_none(
+! CHECK-SAME: %arg0: [[TYPE:!fir.ref<!fir.class<!fir.ptr<none>>>]],
+! CHECK-SAME: %arg1: [[TYPE]]) attributes {llvm.linkage = #llvm.linkage<internal>} {
+! CHECK: %[[DST:.*]]:2 = hlfir.declare %arg0 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_copy_ref_class_ptr_none_dst"}
+! CHECK: %[[SRC:.*]]:2 = hlfir.declare %arg1 {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_copy_ref_class_ptr_none_src"}
+! CHECK: %[[LD:.*]] = fir.load %[[SRC]]#0 : [[TYPE]]
+! CHECK: fir.store %[[LD]] to %[[DST]]#0 : [[TYPE]]
+! CHECK: return
+! CHECK: }
+
+! CHECK-LABEL: func.func @_QQmain()
+! CHECK: omp.single copyprivate(%{{.*}} -> @_copy_ref_class_ptr_none : !fir.ref<!fir.class<!fir.ptr<none>>>) {
+! CHECK: omp.terminator
+! CHECK: }
+
+class(*), pointer, save :: aa
+!$omp threadprivate(aa)
+!$omp single
+!$omp end single copyprivate(aa)
+end
+
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lowering a copyprivate clause whose list item is an unlimited polymorphic pointer (class(*), pointer) crashed in TypeInfo::typeScan. The scan descends through the fir.class box and the fir.ptr, reaching a
noneelement type, which the terminal assertion did not allow.Fixes #198770