-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
[flang] Fix crash from fuzzy test. #122364
Open
klausler
wants to merge
1
commit into
llvm:main
Choose a base branch
from
klausler:bug122002
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+63
−21
Conversation
This file contains 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
llvmbot
added
flang
Flang issues not falling into any other category
flang:semantics
labels
Jan 9, 2025
@llvm/pr-subscribers-flang-semantics Author: Peter Klausler (klausler) ChangesFixes #122002. Full diff: https://github.com/llvm/llvm-project/pull/122364.diff 2 Files Affected:
diff --git a/flang/lib/Evaluate/shape.cpp b/flang/lib/Evaluate/shape.cpp
index c7b2156a3de17a..a078d753ba5ee0 100644
--- a/flang/lib/Evaluate/shape.cpp
+++ b/flang/lib/Evaluate/shape.cpp
@@ -254,7 +254,8 @@ class GetLowerBoundHelper
if (dimension_ < rank) {
const semantics::ShapeSpec &shapeSpec{object->shape()[dimension_]};
if (shapeSpec.lbound().isExplicit()) {
- if (const auto &lbound{shapeSpec.lbound().GetExplicit()}) {
+ if (const auto &lbound{shapeSpec.lbound().GetExplicit()};
+ lbound && lbound->Rank() == 0) {
if constexpr (LBOUND_SEMANTICS) {
bool ok{false};
auto lbValue{ToInt64(*lbound)};
@@ -266,7 +267,8 @@ class GetLowerBoundHelper
} else if (lbValue.value_or(0) == 1) {
// Lower bound is 1, regardless of extent
ok = true;
- } else if (const auto &ubound{shapeSpec.ubound().GetExplicit()}) {
+ } else if (const auto &ubound{shapeSpec.ubound().GetExplicit()};
+ ubound && ubound->Rank() == 0) {
// If we can't prove that the dimension is nonempty,
// we must be conservative.
// TODO: simple symbolic math in expression rewriting to
@@ -459,7 +461,7 @@ static MaybeExtentExpr GetNonNegativeExtent(
} else {
return ExtentExpr{*uval - *lval + 1};
}
- } else if (lbound && ubound &&
+ } else if (lbound && ubound && lbound->Rank() == 0 && ubound->Rank() == 0 &&
(!invariantOnly ||
(IsScopeInvariantExpr(*lbound) && IsScopeInvariantExpr(*ubound)))) {
// Apply effective IDIM (MAX calculation with 0) so thet the
@@ -608,7 +610,8 @@ MaybeExtentExpr GetRawUpperBound(
int rank{details->shape().Rank()};
if (dimension < rank) {
const auto &bound{details->shape()[dimension].ubound().GetExplicit()};
- if (bound && (!invariantOnly || IsScopeInvariantExpr(*bound))) {
+ if (bound && bound->Rank() == 0 &&
+ (!invariantOnly || IsScopeInvariantExpr(*bound))) {
return *bound;
} else if (semantics::IsAssumedSizeArray(symbol) &&
dimension + 1 == symbol.Rank()) {
@@ -640,7 +643,8 @@ MaybeExtentExpr GetRawUpperBound(FoldingContext &context,
static MaybeExtentExpr GetExplicitUBOUND(FoldingContext *context,
const semantics::ShapeSpec &shapeSpec, bool invariantOnly) {
const auto &ubound{shapeSpec.ubound().GetExplicit()};
- if (ubound && (!invariantOnly || IsScopeInvariantExpr(*ubound))) {
+ if (ubound && ubound->Rank() == 0 &&
+ (!invariantOnly || IsScopeInvariantExpr(*ubound))) {
if (auto extent{GetNonNegativeExtent(shapeSpec, invariantOnly)}) {
if (auto cstExtent{ToInt64(
context ? Fold(*context, std::move(*extent)) : *extent)}) {
@@ -731,7 +735,8 @@ MaybeExtentExpr GetLCOBOUND(
if (dimension < corank) {
const semantics::ShapeSpec &shapeSpec{object->coshape()[dimension]};
if (const auto &lcobound{shapeSpec.lbound().GetExplicit()}) {
- if (!invariantOnly || IsScopeInvariantExpr(*lcobound)) {
+ if (lcobound->Rank() == 0 &&
+ (!invariantOnly || IsScopeInvariantExpr(*lcobound))) {
return *lcobound;
}
}
@@ -748,7 +753,8 @@ MaybeExtentExpr GetUCOBOUND(
if (dimension < corank - 1) {
const semantics::ShapeSpec &shapeSpec{object->coshape()[dimension]};
if (const auto ucobound{shapeSpec.ubound().GetExplicit()}) {
- if (!invariantOnly || IsScopeInvariantExpr(*ucobound)) {
+ if (ucobound->Rank() == 0 &&
+ (!invariantOnly || IsScopeInvariantExpr(*ucobound))) {
return *ucobound;
}
}
diff --git a/flang/test/Semantics/bug122002.f90 b/flang/test/Semantics/bug122002.f90
new file mode 100644
index 00000000000000..18fbed92a05f50
--- /dev/null
+++ b/flang/test/Semantics/bug122002.f90
@@ -0,0 +1,5 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! ERROR: Missing initialization for parameter 'n'
+! ERROR: Must be a scalar value, but is a rank-1 array
+integer, parameter :: n(n)
+end
|
eugeneepshteyn
approved these changes
Jan 9, 2025
Fixes llvm#122002. The compiler now survives both of the test cases in that bug report.
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.
Fixes #122002.