Skip to content

Commit

Permalink
[flang] Warn for the limit on name length
Browse files Browse the repository at this point in the history
As fortran 2018 C601, the maximum length of a name is 63 characters.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D125371
  • Loading branch information
PeixinQiao committed May 13, 2022
1 parent 0c00dbb commit a2ac0bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions flang/include/flang/Common/Fortran.h
Expand Up @@ -72,5 +72,8 @@ using Label = std::uint64_t;

// Fortran arrays may have up to 15 dimensions (See Fortran 2018 section 5.4.6).
static constexpr int maxRank{15};

// Fortran names may have up to 63 characters (See Fortran 2018 C601).
static constexpr int maxNameLen{63};
} // namespace Fortran::common
#endif // FORTRAN_COMMON_FORTRAN_H_
6 changes: 6 additions & 0 deletions flang/lib/Semantics/check-declarations.cpp
Expand Up @@ -198,6 +198,12 @@ void CheckHelper::Check(
}

void CheckHelper::Check(const Symbol &symbol) {
if (symbol.name().size() > common::maxNameLen) {
messages_.Say(symbol.name(),
"%s has length %d, which is greater than the maximum name length "
"%d"_port_en_US,
symbol.name(), symbol.name().size(), common::maxNameLen);
}
if (context_.HasError(symbol)) {
return;
}
Expand Down

0 comments on commit a2ac0bb

Please sign in to comment.