Skip to content

Conversation

@eugeneepshteyn
Copy link
Contributor

Fixed a crash in the following example:

subroutine sub()
  implicit none
  print *, (i, i = 1, 2)  ! Problem: using undefined var in implied-do loop
end subroutine sub

The error message was already generated, but the compiler crashed before it could display it.

When REAL types are constant folded, the underneath implementation uses
arrays of integers. Ensure that these arrays are properly aligned.

This matters when building flang with clang. In some cases, the
resulting code for flang compiler ended up using SSE2 aligned load
instructions for REAL(16) constant folding on x86_64, and these
instructions require that the values are loaded from the aligned
addresses.
First change: missing variable name in the error message.
@eugeneepshteyn eugeneepshteyn marked this pull request as ready for review July 18, 2025 13:45
@eugeneepshteyn eugeneepshteyn requested a review from klausler July 18, 2025 13:45
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Jul 18, 2025
@eugeneepshteyn eugeneepshteyn requested a review from akuhlens July 18, 2025 13:45
@llvmbot
Copy link
Member

llvmbot commented Jul 18, 2025

@llvm/pr-subscribers-flang-semantics

Author: Eugene Epshteyn (eugeneepshteyn)

Changes

Fixed a crash in the following example:

subroutine sub()
  implicit none
  print *, (i, i = 1, 2)  ! Problem: using undefined var in implied-do loop
end subroutine sub

The error message was already generated, but the compiler crashed before it could display it.


Full diff: https://github.com/llvm/llvm-project/pull/149513.diff

3 Files Affected:

  • (modified) flang/lib/Semantics/check-do-forall.cpp (+3-1)
  • (modified) flang/lib/Semantics/resolve-names.cpp (+1-1)
  • (modified) flang/test/Semantics/resolve40.f90 (+7)
diff --git a/flang/lib/Semantics/check-do-forall.cpp b/flang/lib/Semantics/check-do-forall.cpp
index cc1d4bf58745a..e258df86a4b1c 100644
--- a/flang/lib/Semantics/check-do-forall.cpp
+++ b/flang/lib/Semantics/check-do-forall.cpp
@@ -1180,7 +1180,9 @@ void DoForallChecker::Leave(const parser::IoControlSpec &ioControlSpec) {
 void DoForallChecker::Leave(const parser::OutputImpliedDo &outputImpliedDo) {
   const auto &control{std::get<parser::IoImpliedDoControl>(outputImpliedDo.t)};
   const parser::Name &name{control.name.thing.thing};
-  context_.CheckIndexVarRedefine(name.source, *name.symbol);
+  if (name.symbol) {
+    context_.CheckIndexVarRedefine(name.source, *name.symbol);
+  }
 }
 
 void DoForallChecker::Leave(const parser::StatVariable &statVariable) {
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index b3268605e7c0c..deafdbd269c78 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -8700,7 +8700,7 @@ const parser::Name *DeclarationVisitor::ResolveName(const parser::Name &name) {
     return &name;
   }
   if (isImplicitNoneType() && !deferImplicitTyping_) {
-    Say(name, "No explicit type declared for '%s'"_err_en_US);
+    Say(name, "No explicit type declared for '%s'"_err_en_US, name.source);
     return nullptr;
   }
   // Create the symbol, then ensure that it is accessible
diff --git a/flang/test/Semantics/resolve40.f90 b/flang/test/Semantics/resolve40.f90
index a91507aa62282..81bb5f989ec48 100644
--- a/flang/test/Semantics/resolve40.f90
+++ b/flang/test/Semantics/resolve40.f90
@@ -96,3 +96,10 @@ subroutine s12(x)
   !BECAUSE: 'x' is an INTENT(IN) dummy argument
   read(*,nml=nl)
 end
+
+subroutine s13()
+  implicit none
+  !ERROR: No explicit type declared for 'i'
+  !ERROR: No explicit type declared for 'i'
+  print *, (i, i = 1, 2)
+end

@eugeneepshteyn eugeneepshteyn merged commit 2c2567d into llvm:main Jul 18, 2025
9 checks passed
@eugeneepshteyn eugeneepshteyn deleted the implicit-do-crash branch July 18, 2025 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flang:semantics flang Flang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants