[flang-commits] [flang] 7ede0b2 - [flang] Complex constructors are scalar only
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Sun Oct 30 11:10:37 PDT 2022
Author: Peter Klausler
Date: 2022-10-30T11:03:42-07:00
New Revision: 7ede0b2cc520da59e8459563cbd1a36cc8492f86
URL: https://github.com/llvm/llvm-project/commit/7ede0b2cc520da59e8459563cbd1a36cc8492f86
DIFF: https://github.com/llvm/llvm-project/commit/7ede0b2cc520da59e8459563cbd1a36cc8492f86.diff
LOG: [flang] Complex constructors are scalar only
The common language extension that allows arbitary expressions
to be used as components in a complex constructor (x,y) -- not both
constant, since that would make it a complex literal constant --
still have to be scalar; it's not an elemental operation like the
CMPLX() intrinsic function is.
Differential Revision: https://reviews.llvm.org/D136978
Added:
flang/test/Semantics/expr-errors05.f90
Modified:
flang/lib/Semantics/expression.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 47421efc560c6..2fad785a62272 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -2851,6 +2851,14 @@ MaybeExpr ExpressionAnalyzer::Analyze(
const parser::Expr::ComplexConstructor &x) {
auto re{Analyze(std::get<0>(x.t).value())};
auto im{Analyze(std::get<1>(x.t).value())};
+ if (re && re->Rank() > 0) {
+ context().Say(std::get<0>(x.t).value().source,
+ "Real part of complex constructor must be scalar"_err_en_US);
+ }
+ if (im && im->Rank() > 0) {
+ context().Say(std::get<1>(x.t).value().source,
+ "Imaginary part of complex constructor must be scalar"_err_en_US);
+ }
if (re && im) {
ConformabilityCheck(GetContextualMessages(), *re, *im);
}
diff --git a/flang/test/Semantics/expr-errors05.f90 b/flang/test/Semantics/expr-errors05.f90
new file mode 100644
index 0000000000000..1f1a7c51813b5
--- /dev/null
+++ b/flang/test/Semantics/expr-errors05.f90
@@ -0,0 +1,7 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! The components of a complex constructor (extension) must be scalar
+!ERROR: Real part of complex constructor must be scalar
+complex, parameter :: z1(*) = ([1.,2.], 3.)
+!ERROR: Imaginary part of complex constructor must be scalar
+complex, parameter :: z2(*) = (4., [5.,6.])
+end
More information about the flang-commits
mailing list