Skip to content

[flang] Do not stop on mismatched DATA substring length #69336

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
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flang/include/flang/Evaluate/initial-image.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Fortran::evaluate {

class InitialImage {
public:
enum Result { Ok, NotAConstant, OutOfRange, SizeMismatch };
enum Result { Ok, NotAConstant, OutOfRange, SizeMismatch, LengthMismatch };

explicit InitialImage(std::size_t bytes) : data_(bytes) {}
InitialImage(InitialImage &&that) = default;
Expand Down Expand Up @@ -72,7 +72,7 @@ class InitialImage {
auto scalar{x.At(at)}; // this is a std string; size() in chars
auto scalarBytes{scalar.size() * KIND};
if (scalarBytes != elementBytes) {
result = SizeMismatch;
result = LengthMismatch;
}
// Blank padding when short
for (; scalarBytes < elementBytes; scalarBytes += KIND) {
Expand Down
3 changes: 2 additions & 1 deletion flang/lib/Semantics/data-to-inits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,11 @@ bool DataInitializationCompiler<DSV>::InitElement(
folded.AsFortran(), DescribeElement());
} else if (status == evaluate::InitialImage::OutOfRange) {
OutOfRangeError();
} else if (status == evaluate::InitialImage::SizeMismatch) {
} else if (status == evaluate::InitialImage::LengthMismatch) {
exprAnalyzer_.Say(
"DATA statement value '%s' for '%s' has the wrong length"_warn_en_US,
folded.AsFortran(), DescribeElement());
return true;
} else {
CHECK(exprAnalyzer_.context().AnyFatalError());
}
Expand Down
13 changes: 13 additions & 0 deletions flang/test/Semantics/data19.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
! RUN: %flang_fc1 -fdebug-dump-symbols %s 2>&1 | FileCheck %s
! Test truncation/padding in DATA statement.

character(len=3) :: c1, c2, c3(2), c4(2)
data c1(1:2), c1(3:3) /'123', '4'/
data c2(1:2), c2(3:3) /'1', '2'/
data c3(:)(1:2), c3(:)(3:3) /'123', '678', '4', '9'/
data c4(:)(1:2), c4(:)(3:3) /'1', '6', '2', '7'/
end
!CHECK: c1 (InDataStmt) size=3 offset=0: ObjectEntity type: CHARACTER(3_4,1) init:"124"
!CHECK: c2 (InDataStmt) size=3 offset=3: ObjectEntity type: CHARACTER(3_4,1) init:"1 2"
!CHECK: c3 (InDataStmt) size=6 offset=6: ObjectEntity type: CHARACTER(3_4,1) shape: 1_8:2_8 init:[CHARACTER(KIND=1,LEN=3)::"124","679"]
!CHECK: c4 (InDataStmt) size=6 offset=12: ObjectEntity type: CHARACTER(3_4,1) shape: 1_8:2_8 init:[CHARACTER(KIND=1,LEN=3)::"1 2","6 7"]