-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang][openacc] Avoid crash when variable is not declared in reduction #114603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
@llvm/pr-subscribers-openacc @llvm/pr-subscribers-flang-semantics Author: Valentin Clement (バレンタイン クレメン) (clementval) ChangesDo not check redutction type when the variable has not been declared. Correct error is then emitted. Full diff: https://github.com/llvm/llvm-project/pull/114603.diff 2 Files Affected:
diff --git a/flang/lib/Semantics/check-acc-structure.cpp b/flang/lib/Semantics/check-acc-structure.cpp
index 623e31341a7c20..7afc285e7b9ae3 100644
--- a/flang/lib/Semantics/check-acc-structure.cpp
+++ b/flang/lib/Semantics/check-acc-structure.cpp
@@ -674,26 +674,28 @@ void AccStructureChecker::Enter(const parser::AccClause::Reduction &reduction) {
common::visitors{
[&](const parser::Designator &designator) {
if (const auto *name = getDesignatorNameIfDataRef(designator)) {
- const auto *type{name->symbol->GetType()};
- if (type->IsNumeric(TypeCategory::Integer) &&
- !reductionIntegerSet.test(op.v)) {
- context_.Say(GetContext().clauseSource,
- "reduction operator not supported for integer type"_err_en_US);
- } else if (type->IsNumeric(TypeCategory::Real) &&
- !reductionRealSet.test(op.v)) {
- context_.Say(GetContext().clauseSource,
- "reduction operator not supported for real type"_err_en_US);
- } else if (type->IsNumeric(TypeCategory::Complex) &&
- !reductionComplexSet.test(op.v)) {
- context_.Say(GetContext().clauseSource,
- "reduction operator not supported for complex type"_err_en_US);
- } else if (type->category() ==
- Fortran::semantics::DeclTypeSpec::Category::Logical &&
- !reductionLogicalSet.test(op.v)) {
- context_.Say(GetContext().clauseSource,
- "reduction operator not supported for logical type"_err_en_US);
+ if (name->symbol) {
+ const auto *type{name->symbol->GetType()};
+ if (type->IsNumeric(TypeCategory::Integer) &&
+ !reductionIntegerSet.test(op.v)) {
+ context_.Say(GetContext().clauseSource,
+ "reduction operator not supported for integer type"_err_en_US);
+ } else if (type->IsNumeric(TypeCategory::Real) &&
+ !reductionRealSet.test(op.v)) {
+ context_.Say(GetContext().clauseSource,
+ "reduction operator not supported for real type"_err_en_US);
+ } else if (type->IsNumeric(TypeCategory::Complex) &&
+ !reductionComplexSet.test(op.v)) {
+ context_.Say(GetContext().clauseSource,
+ "reduction operator not supported for complex type"_err_en_US);
+ } else if (type->category() ==
+ Fortran::semantics::DeclTypeSpec::Category::Logical &&
+ !reductionLogicalSet.test(op.v)) {
+ context_.Say(GetContext().clauseSource,
+ "reduction operator not supported for logical type"_err_en_US);
+ }
+ // TODO: check composite type.
}
- // TODO: check composite type.
}
},
[&](const Fortran::parser::Name &name) {
diff --git a/flang/test/Semantics/OpenACC/acc-reduction-validity.f90 b/flang/test/Semantics/OpenACC/acc-reduction-validity.f90
index ccd009bffa2e24..cecc7e0f507b25 100644
--- a/flang/test/Semantics/OpenACC/acc-reduction-validity.f90
+++ b/flang/test/Semantics/OpenACC/acc-reduction-validity.f90
@@ -3,6 +3,7 @@
! Check OpenACC reduction validity.
program openacc_reduction_validity
+ implicit none
integer :: i
real :: r
@@ -168,5 +169,9 @@ program openacc_reduction_validity
!$acc parallel reduction(ieor:l)
!$acc end parallel
+ !ERROR: No explicit type declared for 'xyz'
+ !$acc parallel reduction(+:xyz)
+ !$acc end parallel
+
end program
|
The commit message misspells the word "redutction". Otherwise, looks great. |
razvanlupusoru
approved these changes
Nov 3, 2024
PhilippRados
pushed a commit
to PhilippRados/llvm-project
that referenced
this pull request
Nov 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
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.
Do not check reduction type when the variable has not been declared. Correct error is then emitted.