Clang error: matrix ... index is outside the allowed range [0, B) (err_matrix_index_outside_range)
Jump to navigation
Jump to search
Text |
(since 11.0) | ||||||
---|---|---|---|---|---|---|---|
Type | Error | ||||||
Category | None (since 11.0) | ||||||
Internal Id | err_matrix_index_outside_range (since 11.0) | ||||||
Internal Message | matrix %select{row|column}0 index is outside the allowed range [0, %1) (since 11.0)
| ||||||
Regular Expression | (?:error|fatal error)\: matrix (?:row|column) index is outside the allowed range \[0, (.*?)\)
| ||||||
First Commit | 2019-12-21 931fcd3ba011 [WebAssembly] Improve clang diagnostics for wasm attributes |
Description
Example
Flags | -xc -fclang-abi-compat=17.0 -fenable-matrix
|
|
---|---|---|
Source |
int main() {
float m __attribute__((matrix_type(2, 2)));
m[2][0] = 1.0; // Invalid row index
}
| |
Compiler Output |
<source>:2:26: error: 'matrix_type' attribute only applies to typedefs <source>:3:5: error: matrix row index is outside the allowed range [0, 2) |
Clang Internals (17.0.6)
Git Commit Message
[WebAssembly] Improve clang diagnostics for wasm attributes This patch addresses the review comments on r352930: - Removes redundant diagnostic checking code - Removes errnoneous use of diag::err_alias_is_definition, which turned out to be ineffective anyway since functions can be defined later in the translation unit and avoid detection. - Adds a test for various invalid cases for import_name and import_module. Differential Revision: https://reviews.llvm.org/D59520
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaExpr.cpp (line 5302)
ExprResult Sema::CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBLoc) {
// ...
// Check that IndexExpr is an integer expression. If it is a constant
// expression, check that it is less than Dim (= the number of elements in the
// corresponding dimension).
auto IsIndexValid = [&](Expr *IndexExpr, unsigned Dim, bool IsColumnIdx) -> Expr * {
// ...
if (std::optional<llvm::APSInt> Idx = IndexExpr->getIntegerConstantExpr(Context)) {
if ((*Idx < 0 || *Idx >= Dim)) {
Diag(IndexExpr->getBeginLoc(), diag::err_matrix_index_outside_range) << IsColumnIdx << Dim;
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/Sema/matrix-type-operators.c
- clang/test/Sema/matrix-type-operators.c:154:5: error: matrix row index is outside the allowed range [0, 5)
- clang/test/Sema/matrix-type-operators.c:156:8: error: matrix column index is outside the allowed range [0, 10)
- clang/test/Sema/matrix-type-operators.c:158:8: error: matrix column index is outside the allowed range [0, 10)
- clang/test/Sema/matrix-type-operators.c:160:5: error: matrix row index is outside the allowed range [0, 5)
- clang/test/Sema/matrix-type-operators.c:162:5: error: matrix row index is outside the allowed range [0, 5)
- clang/test/Sema/matrix-type-operators.c:164:8: error: matrix column index is outside the allowed range [0, 10)
- clang/test/Sema/matrix-type-operators.c:166:5: error: matrix row index is outside the allowed range [0, 5)
- clang/test/Sema/matrix-type-operators.c:179:16: error: matrix row index is outside the allowed range [0, 5)
- clang/test/Sema/matrix-type-operators.c:210:16: error: matrix row index is outside the allowed range [0, 5)
- clang/test/Sema/matrix-type-operators.c:212:19: error: matrix column index is outside the allowed range [0, 10)
- clang/test/Sema/matrix-type-operators.c:214:16: error: matrix row index is outside the allowed range [0, 5)
- clang/test/Sema/matrix-type-operators.c:216:16: error: matrix row index is outside the allowed range [0, 5)
- clang/test/Sema/matrix-type-operators.c:218:20: error: matrix column index is outside the allowed range [0, 10)
- clang/test/Sema/matrix-type-operators.c:220:17: error: matrix row index is outside the allowed range [0, 5)