[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
This commit is contained in:
Tim Keith 2020-08-22 10:11:36 -07:00
parent bb894b9782
commit c0c3cafa2b
2 changed files with 7 additions and 0 deletions

View File

@ -3461,6 +3461,7 @@ void DeclarationVisitor::Post(const parser::CharSelector::LengthAndKind &x) {
TypeCategory::Character, *intKind)) { // C715, C719 TypeCategory::Character, *intKind)) { // C715, C719
Say(currStmtSource().value(), Say(currStmtSource().value(),
"KIND value (%jd) not valid for CHARACTER"_err_en_US, *intKind); "KIND value (%jd) not valid for CHARACTER"_err_en_US, *intKind);
charInfo_.kind = std::nullopt; // prevent further errors
} }
if (x.length) { if (x.length) {
charInfo_.length = GetParamValue(*x.length, common::TypeParamAttr::Len); charInfo_.length = GetParamValue(*x.length, common::TypeParamAttr::Len);

View File

@ -83,3 +83,9 @@ character(len=*), parameter :: cvar10 = 4_"abcd"
!ERROR: CHARACTER(KIND=8) is not a supported type !ERROR: CHARACTER(KIND=8) is not a supported type
character(len=*), parameter :: cvar11 = 8_"abcd" character(len=*), parameter :: cvar11 = 8_"abcd"
end program end program
subroutine s(a, b)
character(*,2) :: a
!ERROR: KIND value (8) not valid for CHARACTER
character(*,8) :: b
end