[flang-commits] [flang] 0386490 - [flang] Prevent segfault in DynamicType::IsTkCompatibleWith

Tim Keith via flang-commits flang-commits at lists.llvm.org
Thu Apr 9 08:15:17 PDT 2020


Author: Tim Keith
Date: 2019-07-03T15:47:37-07:00
New Revision: 03864907513dd71c084bc234ee00ae495847f278

URL: https://github.com/llvm/llvm-project/commit/03864907513dd71c084bc234ee00ae495847f278
DIFF: https://github.com/llvm/llvm-project/commit/03864907513dd71c084bc234ee00ae495847f278.diff

LOG: [flang] Prevent segfault in DynamicType::IsTkCompatibleWith

Make sure `derived_` is not null before dereferencing it.

This might only happen when there is a previous error. I saw it
compiling a test program where a USEd module was not found.

Original-commit: flang-compiler/f18 at 2db516556b1509a8519ce91013f49431b6d43d22
Reviewed-on: https://github.com/flang-compiler/f18/pull/550

Added: 
    

Modified: 
    flang/lib/evaluate/type.cc

Removed: 
    


################################################################################
diff  --git a/flang/lib/evaluate/type.cc b/flang/lib/evaluate/type.cc
index 48299eb62593..047e3b72f178 100644
--- a/flang/lib/evaluate/type.cc
+++ b/flang/lib/evaluate/type.cc
@@ -171,7 +171,8 @@ bool DynamicType::IsTkCompatibleWith(const DynamicType &that) const {
     return true;
   } else if (that.IsUnlimitedPolymorphic()) {
     return false;
-  } else if (!IsKindCompatible(*derived_, *that.derived_)) {
+  } else if (!derived_ || !that.derived_ ||
+      !IsKindCompatible(*derived_, *that.derived_)) {
     return false;  // kind params don't match
   } else if (!IsPolymorphic()) {
     return derived_->typeSymbol() == that.derived_->typeSymbol();


        


More information about the flang-commits mailing list