diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -1304,6 +1304,9 @@ def ProfileInstrUnprofiled : DiagGroup<"profile-instr-unprofiled">; def MisExpect : DiagGroup<"misexpect">; +// Array bounds remarks. +def ArrayBoundsRemarks : DiagGroup<"array-bounds">; + // AddressSanitizer frontend instrumentation remarks. def SanitizeAddressRemarks : DiagGroup<"sanitize-address">; diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -9450,6 +9450,10 @@ def note_array_declared_here : Note< "array %0 declared here">; +def remark_array_access : Remark< + "accessing %select{fixed|dynamic}0 sized array %1 by %2">, + InGroup; + def warn_inconsistent_array_form : Warning< "argument %0 of type %1 with mismatched bound">, InGroup, DefaultIgnore; diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -16323,6 +16323,10 @@ else if (size.getBitWidth() < index.getBitWidth()) size = size.zext(index.getBitWidth()); + Context.getDiagnostics().Report( + BaseExpr->getBeginLoc(), diag::remark_array_access) + << 0 << ArrayTy->desugar() << toString(index, 10, true); + // For array subscripting the index must be less than size, but for pointer // arithmetic also allow the index (offset) to be equal to size since // computing the next address after the end of the array is legal and