[flang-commits] [flang] 5491fdf - [flang] Add semantic check for named constant as function result
via flang-commits
flang-commits at lists.llvm.org
Tue May 31 23:39:27 PDT 2022
Author: Peixin-Qiao
Date: 2022-06-01T14:38:46+08:00
New Revision: 5491fdf559ec68039a218bab6bf41901611554f0
URL: https://github.com/llvm/llvm-project/commit/5491fdf559ec68039a218bab6bf41901611554f0
DIFF: https://github.com/llvm/llvm-project/commit/5491fdf559ec68039a218bab6bf41901611554f0.diff
LOG: [flang] Add semantic check for named constant as function result
Similar to procedure argument, the function result cannot be one
named constant.
Reviewed By: klausler
Differential Revision: https://reviews.llvm.org/D126693
Added:
flang/test/Semantics/declarations01.f90
Modified:
flang/lib/Semantics/check-declarations.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 6b559545e448f..805d89075e3f8 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -351,6 +351,10 @@ void CheckHelper::Check(const Symbol &symbol) {
"A dummy argument may not have the SAVE attribute"_err_en_US);
}
} else if (IsFunctionResult(symbol)) {
+ if (IsNamedConstant(symbol)) {
+ messages_.Say(
+ "A function result may not also be a named constant"_err_en_US);
+ }
if (!symbol.test(Symbol::Flag::InDataStmt) /*caught elsewhere*/ &&
IsSaved(symbol)) {
messages_.Say(
diff --git a/flang/test/Semantics/declarations01.f90 b/flang/test/Semantics/declarations01.f90
new file mode 100644
index 0000000000000..f3673a7ed0d19
--- /dev/null
+++ b/flang/test/Semantics/declarations01.f90
@@ -0,0 +1,8 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! test named constant declarations
+
+function f1() result(x)
+ !ERROR: A function result may not also be a named constant
+ integer, parameter :: x = 1
+end
+
More information about the flang-commits
mailing list