[flang-commits] [PATCH] D135215: [flang] Add missing source location to a semantic error message
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Tue Oct 4 15:10:09 PDT 2022
klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
Ensure that the semantic error "An allocatable or pointer component
reference must be applied to a scalar base" is emitted with a source
code location.
https://reviews.llvm.org/D135215
Files:
flang/lib/Semantics/expression.cpp
flang/test/Semantics/expr-errors04.f90
Index: flang/test/Semantics/expr-errors04.f90
===================================================================
--- flang/test/Semantics/expr-errors04.f90
+++ flang/test/Semantics/expr-errors04.f90
@@ -14,6 +14,8 @@
complex :: c, c2(2)
integer :: x, x2(2)
character(10) :: s, s2(2)
+ real, pointer :: p
+ real, allocatable :: a
contains
procedure, nopass :: info1 => real_info1
procedure, nopass :: info2 => real_info2
@@ -108,4 +110,17 @@
!ERROR: Reference to rank-2 object 't1' has 1 subscripts
call t%t3%t2%t1(1:)%g1
+ !ERROR: An allocatable or pointer component reference must be applied to a scalar base
+ print *, t(1)%t3(1)%t2(1)%t1%p
+ !ERROR: An allocatable or pointer component reference must be applied to a scalar base
+ print *, t%t3(1)%t2(1)%t1(1,1)%p
+ !ERROR: An allocatable or pointer component reference must be applied to a scalar base
+ print *, t(1)%t3(1)%t2(1)%t1%a
+ !ERROR: An allocatable or pointer component reference must be applied to a scalar base
+ print *, t%t3(1)%t2(1)%t1(1,1)%a
+ !ERROR: An allocatable or pointer component reference must be applied to a scalar base
+ t(1)%t3(1)%t2(1)%t1%p => null()
+ !ERROR: An allocatable or pointer component reference must be applied to a scalar base
+ t%t3(1)%t2(1)%t1(1,1)%p => null()
+
end
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -1145,6 +1145,7 @@
return std::nullopt;
} else if (std::optional<DataRef> dataRef{
ExtractDataRef(std::move(*dtExpr))}) {
+ auto restorer{GetContextualMessages().SetLocation(name)};
if (auto component{
CreateComponent(std::move(*dataRef), *sym, *dtSpec->scope())}) {
return Designate(DataRef{std::move(*component)});
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135215.465192.patch
Type: text/x-patch
Size: 1900 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221004/bc8d0a15/attachment.bin>
More information about the flang-commits
mailing list