[flang-commits] [flang] 3bc334b - [flang] Fix crash in semantics in error recovery

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Sep 23 17:45:53 PDT 2022


Author: Peter Klausler
Date: 2022-09-23T17:45:35-07:00
New Revision: 3bc334b31a224f85a68ba7dfa5b4bd5fe57f1b3d

URL: https://github.com/llvm/llvm-project/commit/3bc334b31a224f85a68ba7dfa5b4bd5fe57f1b3d
DIFF: https://github.com/llvm/llvm-project/commit/3bc334b31a224f85a68ba7dfa5b4bd5fe57f1b3d.diff

LOG: [flang] Fix crash in semantics in error recovery

When a FUNCTION statement has both an explicit type in its prefix
and a RESULT clause in its suffix, semantics crashes due to the
redundant type; emit a nice error message instead.

Differential Revision: https://reviews.llvm.org/D134504

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index a339f868b1e0..df3632616a22 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -2060,12 +2060,19 @@ void FuncResultStack::CompleteFunctionResultType() {
   // If the function has a type in the prefix, process it now.
   FuncInfo *info{Top()};
   if (info && &info->scope == &scopeHandler_.currScope()) {
-    if (info->parsedType) {
+    if (info->parsedType && info->resultSymbol) {
       scopeHandler_.messageHandler().set_currStmtSource(info->source);
       if (const auto *type{
               scopeHandler_.ProcessTypeSpec(*info->parsedType, true)}) {
-        if (!scopeHandler_.context().HasError(info->resultSymbol)) {
-          info->resultSymbol->SetType(*type);
+        Symbol &symbol{*info->resultSymbol};
+        if (!scopeHandler_.context().HasError(symbol)) {
+          if (symbol.GetType()) {
+            scopeHandler_.Say(symbol.name(),
+                "Function cannot have both an explicit type prefix and a RESULT suffix"_err_en_US);
+            scopeHandler_.context().SetError(symbol);
+          } else {
+            symbol.SetType(*type);
+          }
         }
       }
       info->parsedType = nullptr;


        


More information about the flang-commits mailing list