[PATCH] D100648: [flang][f18] Add an additional check for semantic errors

Andrzej Warzynski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 16 07:22:06 PDT 2021


awarzynski created this revision.
awarzynski requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

`Semantics::AnyFatalError` may return `true` after
`Fortran::semantics::BuildRuntimeDerivedTypeTables` is run. That's
despite `Semantics::perform` having been run earlier and not reporting
any issues. This is demonstrated below:

  semantics.perform()
  // No errors here, i.e. `semantics.AnyFatalError()` returns `false`
  BuildRuntimeDerivedTypeTables()
  // New semantic errors are found, i.e. `semantics.AnyFatalError()` returns `false`

This patch udpates the "throwaway" driver so that the semantic errors
identified after `BuildRuntimeDerivedTypeTables` are correctly reported.

This change affects some tests - the corresponding input leads to
semantic errors that are only identified after
`BuildRuntimeDerivedTypeTables` is run. The generated output (which is
fed into FileCheck) still matches the expected output, but `f18` returns
a non-zero code. As a temporary solution workaround for this, `%f18` is
replaced with `not %f18`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100648

Files:
  flang/test/Semantics/data05.f90
  flang/test/Semantics/offsets01.f90
  flang/test/Semantics/offsets02.f90
  flang/test/Semantics/typeinfo01.f90
  flang/tools/f18/f18.cpp


Index: flang/tools/f18/f18.cpp
===================================================================
--- flang/tools/f18/f18.cpp
+++ flang/tools/f18/f18.cpp
@@ -277,6 +277,12 @@
     if (driver.dumpSymbols) {
       semantics.DumpSymbols(llvm::outs());
     }
+    if (semantics.AnyFatalError()) {
+      llvm::errs() << driver.prefix << "Semantic errors in " << path << '\n';
+      semantics.EmitMessages(llvm::errs());
+      exitStatus = EXIT_FAILURE;
+      return {};
+    }
     if (driver.dumpUnparseWithSymbols) {
       Fortran::semantics::UnparseWithSymbols(
           llvm::outs(), parseTree, driver.encoding);
Index: flang/test/Semantics/typeinfo01.f90
===================================================================
--- flang/test/Semantics/typeinfo01.f90
+++ flang/test/Semantics/typeinfo01.f90
@@ -1,4 +1,4 @@
-!RUN: %f18 -fdebug-dump-symbols %s | FileCheck %s
+!RUN: not %f18 -fdebug-dump-symbols %s | FileCheck %s
 ! Tests for derived type runtime descriptions
 
 module m01
Index: flang/test/Semantics/offsets02.f90
===================================================================
--- flang/test/Semantics/offsets02.f90
+++ flang/test/Semantics/offsets02.f90
@@ -1,4 +1,4 @@
-!RUN: %flang_fc1 -fdebug-dump-symbols %s | FileCheck %s
+!RUN: not %f18 -fdebug-dump-symbols %s | FileCheck %s
 
 ! Size and alignment of derived types
 
Index: flang/test/Semantics/offsets01.f90
===================================================================
--- flang/test/Semantics/offsets01.f90
+++ flang/test/Semantics/offsets01.f90
@@ -1,4 +1,4 @@
-!RUN: %flang_fc1 -fdebug-dump-symbols %s | FileCheck %s
+!RUN: not %f18 -fdebug-dump-symbols %s | FileCheck %s
 
 ! Size and alignment of intrinsic types
 subroutine s1
Index: flang/test/Semantics/data05.f90
===================================================================
--- flang/test/Semantics/data05.f90
+++ flang/test/Semantics/data05.f90
@@ -1,4 +1,4 @@
-!RUN: %flang_fc1 -fdebug-dump-symbols %s | FileCheck %s
+!RUN: not %f18 -fdebug-dump-symbols %s | FileCheck %s
 module m
   interface
     integer function ifunc(n)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100648.338104.patch
Type: text/x-patch
Size: 2090 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210416/9d750724/attachment.bin>


More information about the llvm-commits mailing list