================ @@ -6018,9 +6018,15 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, << IndexExpr->getSourceRange()); if ((IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_S) || - IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_U)) - && !IndexExpr->isTypeDependent()) - Diag(LLoc, diag::warn_subscript_is_char) << IndexExpr->getSourceRange(); + IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_U)) && + !IndexExpr->isTypeDependent()) { + std::optional<llvm::APSInt> IntegerContantExpr = + IndexExpr->getIntegerConstantExpr(getASTContext()); + if (!(IntegerContantExpr.has_value() && + IntegerContantExpr.value().isNonNegative())) { + Diag(LLoc, diag::warn_subscript_is_char) << IndexExpr->getSourceRange(); + } ---------------- AaronBallman wrote:
```suggestion std::optional<llvm::APSInt> IntegerContantExpr = IndexExpr->getIntegerConstantExpr(getASTContext()); if (!IntegerContantExpr.has_value() || IntegerContantExpr.value().isNegative()) Diag(LLoc, diag::warn_subscript_is_char) << IndexExpr->getSourceRange(); ``` This performs extra work for each array subscript in the TU, but because it's limited to only array subscripts with a character type, I don't think the compile-time performance hit should be too bad, so this seems reasonable to me. https://github.com/llvm/llvm-project/pull/69061 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits