[flang-commits] [flang] [flang] Fix crash under -fdebug-dump-all (PR #66224)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Sep 13 09:13:29 PDT 2023


https://github.com/klausler updated https://github.com/llvm/llvm-project/pull/66224:

>From 1e7b5e029e5e5d383178def2a3cb364cb9eadcce Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 29 Aug 2023 14:46:10 -0700
Subject: [PATCH] [flang] Fix crash under -fdebug-dump-all

The -fdebug-dump-all flag invokes runtime type information
generation even for a program with fatal semantic errors.
This could cause a crash on a failed CHECK(), since the
type information table generator assumes a correct program.
Make it more resilient for a known fatal case.  (But if
we hit many more of these, we should look into not generating
the runtime type information tables under this flag.)

Pull request: https://github.com/llvm/llvm-project/pull/66224
---
 flang/lib/Semantics/runtime-type-info.cpp | 7 +++++--
 flang/test/Driver/dump-all-bad.f90        | 6 ++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Semantics/runtime-type-info.cpp b/flang/lib/Semantics/runtime-type-info.cpp
index c46b12d6b30e86e..aa470ecdc771941 100644
--- a/flang/lib/Semantics/runtime-type-info.cpp
+++ b/flang/lib/Semantics/runtime-type-info.cpp
@@ -310,8 +310,11 @@ static SomeExpr StructureExpr(evaluate::StructureConstructor &&x) {
 
 static int GetIntegerKind(const Symbol &symbol) {
   auto dyType{evaluate::DynamicType::From(symbol)};
-  CHECK(dyType && dyType->category() == TypeCategory::Integer);
-  return dyType->kind();
+  CHECK((dyType && dyType->category() == TypeCategory::Integer) ||
+      symbol.owner().context().HasError(symbol));
+  return dyType && dyType->category() == TypeCategory::Integer
+      ? dyType->kind()
+      : symbol.owner().context().GetDefaultKind(TypeCategory::Integer);
 }
 
 // Save a rank-1 array constant of some numeric type as an
diff --git a/flang/test/Driver/dump-all-bad.f90 b/flang/test/Driver/dump-all-bad.f90
index 2d6f71a526af5b5..58f0d02c497469d 100644
--- a/flang/test/Driver/dump-all-bad.f90
+++ b/flang/test/Driver/dump-all-bad.f90
@@ -10,6 +10,8 @@
 ! CHECK: Flang: symbols dump
 
 program bad
-  real,pointer :: x
-  x = null()      ! Error - must be pointer assignment
+  type dt(k)
+    integer(kind=16) :: k
+    integer(kind=16) :: comp
+  end type dt
 end



More information about the flang-commits mailing list