Skip to content

Commit 0047f6a

Browse files
committed
[flang] Add name match checks for interface procedures
We had neglected to check for name mismatches for procedure definitions that appear in interfaces. I also changed label11.f90 to an error test since I think they're better than "FileCheck" tests. Differential Revision: https://reviews.llvm.org/D89611
1 parent cf814fc commit 0047f6a

File tree

2 files changed

+54
-13
lines changed

2 files changed

+54
-13
lines changed

flang/lib/Semantics/resolve-labels.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,20 @@ class ParseTreeAnalyzer {
355355
std::get<parser::Statement<parser::EndBlockDataStmt>>(blockData.t));
356356
}
357357

358+
// C1564
359+
void Post(const parser::InterfaceBody::Function &func) {
360+
CheckOptionalName<parser::FunctionStmt>("FUNCTION", func,
361+
std::get<parser::Statement<parser::EndFunctionStmt>>(func.t));
362+
}
363+
358364
// C1564
359365
void Post(const parser::FunctionSubprogram &functionSubprogram) {
360366
CheckOptionalName<parser::FunctionStmt>("FUNCTION", functionSubprogram,
361367
std::get<parser::Statement<parser::EndFunctionStmt>>(
362368
functionSubprogram.t));
363369
}
370+
371+
// C1502
364372
void Post(const parser::InterfaceBlock &interfaceBlock) {
365373
auto &interfaceStmt{
366374
std::get<parser::Statement<parser::InterfaceStmt>>(interfaceBlock.t)};
@@ -381,7 +389,7 @@ class ParseTreeAnalyzer {
381389
context_
382390
.Say(currentPosition_,
383391
parser::MessageFormattedText{
384-
"INTERFACE generic-name (%s) mismatch"_en_US,
392+
"INTERFACE generic-name (%s) mismatch"_err_en_US,
385393
namePointer->source})
386394
.Attach(interfaceStmt.source, "mismatched INTERFACE"_en_US);
387395
}
@@ -432,6 +440,12 @@ class ParseTreeAnalyzer {
432440
std::get<parser::Statement<parser::EndSubmoduleStmt>>(submodule.t));
433441
}
434442

443+
// C1567
444+
void Post(const parser::InterfaceBody::Subroutine &sub) {
445+
CheckOptionalName<parser::SubroutineStmt>("SUBROUTINE", sub,
446+
std::get<parser::Statement<parser::EndSubroutineStmt>>(sub.t));
447+
}
448+
435449
// C1567
436450
void Post(const parser::SubroutineSubprogram &subroutineSubprogram) {
437451
CheckOptionalName<parser::SubroutineStmt>("SUBROUTINE",

flang/test/Semantics/label11.f90

+39-12
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,66 @@
1-
! RUN: not %f18 -funparse-with-symbols %s 2>&1 | FileCheck %s
2-
! CHECK: BLOCK DATA subprogram name mismatch
3-
! CHECK: should be
4-
! CHECK: FUNCTION name mismatch
5-
! CHECK: SUBROUTINE name mismatch
6-
! CHECK: PROGRAM name mismatch
7-
! CHECK: SUBMODULE name mismatch
8-
! CHECK: INTERFACE generic-name (t7) mismatch
9-
! CHECK: mismatched INTERFACE
10-
! CHECK: derived type definition name mismatch
11-
! CHECK: MODULE PROCEDURE name mismatch
12-
! CHECK: MODULE name mismatch
1+
! RUN: %S/test_errors.sh %s %t %f18
132
! C739 If END TYPE is followed by a type-name, the type-name shall be the
143
! same as that in the corresponding derived-type-stmt.
4+
! C1401 The program-name shall not be included in the end-program-stmt unless
5+
! the optional program-stmt is used. If included, it shall be identical to the
6+
! program-name specified in the program-stmt.
7+
! C1402 If the module-name is specified in the end-module-stmt, it shall be
8+
! identical to the module-name specified in the module-stmt.
9+
! C1413 If a submodule-name appears in the end-submodule-stmt, it shall be
10+
! identical to the one in the submodule-stmt.
11+
! C1414 If a function-name appears in the end-function-stmt, it shall be
12+
! identical to the function-name specified in the function-stmt.
13+
! C1502 If the end-interface-stmt includes a generic-spec, the interface-stmt
14+
! shall specify the same generic-spec
15+
! C1564 If a function-name appears in the end-function-stmt, it shall be
16+
! identical to the function-name specified in the function-stmt.
17+
! C1567 If a submodule-name appears in the end-submodule-stmt, it shall be
18+
! identical to the one in the submodule-stmt.
19+
! C1569 If the module-name is specified in the end-module-stmt, it shall be
20+
! identical to the module-name specified in the module-stmt
1521

1622
block data t1
23+
!ERROR: BLOCK DATA subprogram name mismatch
1724
end block data t2
1825

1926
function t3
27+
!ERROR: FUNCTION name mismatch
2028
end function t4
2129

2230
subroutine t9
31+
!ERROR: SUBROUTINE name mismatch
2332
end subroutine t10
2433

2534
program t13
35+
!ERROR: END PROGRAM name mismatch
2636
end program t14
2737

2838
submodule (mod) t15
39+
!ERROR: SUBMODULE name mismatch
2940
end submodule t16
3041

3142
module t5
3243
interface t7
44+
!ERROR: INTERFACE generic-name (t7) mismatch
3345
end interface t8
3446
type t17
47+
!ERROR: derived type definition name mismatch
3548
end type t18
49+
50+
abstract interface
51+
subroutine subrFront()
52+
!ERROR: SUBROUTINE name mismatch
53+
end subroutine subrBack
54+
function funcFront(x)
55+
real, intent(in) :: x
56+
real funcFront
57+
!ERROR: FUNCTION name mismatch
58+
end function funcBack
59+
end interface
60+
3661
contains
3762
module procedure t11
63+
!ERROR: MODULE PROCEDURE name mismatch
3864
end procedure t12
65+
!ERROR: MODULE name mismatch
3966
end module mox

0 commit comments

Comments
 (0)