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

via flang-commits flang-commits at lists.llvm.org
Wed Sep 13 09:02:40 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics
            
<details>
<summary>Changes</summary>
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.)
--
Full diff: https://github.com/llvm/llvm-project/pull/66224.diff

2 Files Affected:

- (modified) flang/lib/Semantics/runtime-type-info.cpp (+5-2) 
- (modified) flang/test/Driver/dump-all-bad.f90 (+4-2) 


<pre>
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
</pre>
</details>


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


More information about the flang-commits mailing list