Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang] Fix crash under -fdebug-dump-all #66224

Merged
merged 1 commit into from
Sep 13, 2023
Merged

Conversation

klausler
Copy link
Contributor

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.)

@klausler klausler requested review from a team as code owners September 13, 2023 16:01
@llvmbot llvmbot added flang:driver flang Flang issues not falling into any other category flang:semantics labels Sep 13, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Sep 13, 2023

@llvm/pr-subscribers-flang-driver

@llvm/pr-subscribers-flang-semantics

Changes 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//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)
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

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: llvm#66224
Copy link
Contributor

@psteinfeld psteinfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

Copy link
Contributor

@banach-space banach-space left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@klausler klausler merged commit d5cc372 into llvm:main Sep 13, 2023
2 checks passed
@klausler klausler deleted the bug1341 branch September 13, 2023 21:05
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
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.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:driver flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants