[flang-commits] [flang] c0c3caf - [flang] Fix assert on bad character kind

Tim Keith via flang-commits flang-commits at lists.llvm.org
Sat Aug 22 10:11:49 PDT 2020


Author: Tim Keith
Date: 2020-08-22T10:11:38-07:00
New Revision: c0c3cafa2bdaaf878a6b544837073d3d92fbb797

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

LOG: [flang] Fix assert on bad character kind

When we report an error for a bad character kind, don't keep it in the
`DeclTypeSpec`. Otherwise there could be further problems. In this case,
`ComputeOffsets()` got an assertion error because we didn't recognize
`CHARACTER(*,8)` as needing a descriptor because of the bad kind.

Fixes https://bugs.llvm.org/show_bug.cgi?id=47173

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

Added: 
    

Modified: 
    flang/lib/Semantics/resolve-names.cpp
    flang/test/Semantics/kinds02.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 299b180df957..7feca5b00a8f 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -3461,6 +3461,7 @@ void DeclarationVisitor::Post(const parser::CharSelector::LengthAndKind &x) {
           TypeCategory::Character, *intKind)) { // C715, C719
     Say(currStmtSource().value(),
         "KIND value (%jd) not valid for CHARACTER"_err_en_US, *intKind);
+    charInfo_.kind = std::nullopt; // prevent further errors
   }
   if (x.length) {
     charInfo_.length = GetParamValue(*x.length, common::TypeParamAttr::Len);

diff  --git a/flang/test/Semantics/kinds02.f90 b/flang/test/Semantics/kinds02.f90
index 9743fb646ac8..cf22056c1c20 100644
--- a/flang/test/Semantics/kinds02.f90
+++ b/flang/test/Semantics/kinds02.f90
@@ -83,3 +83,9 @@
 !ERROR: CHARACTER(KIND=8) is not a supported type
 character(len=*), parameter :: cvar11 = 8_"abcd"
 end program
+
+subroutine s(a, b)
+  character(*,2) :: a
+  !ERROR: KIND value (8) not valid for CHARACTER
+  character(*,8) :: b
+end


        


More information about the flang-commits mailing list