llvm-project/clang/test/SemaCXX/matrix-index-operator-sign-conversion.cpp
Florian Hahn 96509bb98f
[Matrix] Preserve signedness when extending matrix index expression. (#103044)
As per [1] the indices for a matrix element access operator shall have
integral or unscoped enumeration types and be non-negative. At the
moment, the index expression is converted to SizeType irrespective of
the signedness of the index expression. This causes implicit sign
conversion warnings if any of the indices is signed.

As per the spec, using signed types as indices is allowed and should not
cause any warnings. If the index expression is signed, extend to
SignedSizeType to avoid the warning.

[1]
https://clang.llvm.org/docs/MatrixTypes.html#matrix-type-element-access-operator

PR: https://github.com/llvm/llvm-project/pull/103044
2024-08-23 10:11:52 +01:00

18 lines
616 B
C++

// RUN: %clang_cc1 -triple arm64-apple-macosx -std=c++11 -fenable-matrix -fsyntax-only -verify -Wsign-conversion %s
template <typename T, int R, int C> using m __attribute__((__matrix_type__(R,C))) = T;
double index1(m<double,3,1> X, int i) { return X[i][0]; }
double index2(m<double,3,1> X, unsigned i) { return X[i][0]; }
double index3(m<double,3,1> X, char i) { return X[i][0]; }
double index4(m<double,3,1> X, int i) { return X[0][i]; }
double index5(m<double,3,1> X, unsigned i) { return X[0][i]; }
double index6(m<double,3,1> X, char i) { return X[0][i]; }
// expected-no-diagnostics