[clang] [-Wunsafe-buffer-usage] Suppress warning for multi-dimensional constant arrays (PR #118249)

Jan Korous via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 4 11:44:23 PST 2024


================
@@ -52,3 +52,37 @@ void constant_id_string(unsigned idx) {
   unsafe_char = ""[1]; //expected-warning{{unsafe buffer access}} 
   unsafe_char = ""[idx]; //expected-warning{{unsafe buffer access}}
 }
+
+typedef float Float4x4[4][4];
+
+// expected-warning at +1 {{'matrix' is an unsafe buffer that does not perform bounds checks}}
+float two_dimension_array(Float4x4& matrix) {
+  // expected-note at +1{{used in buffer access here}}
+  float a = matrix[0][4];
----------------
jkorous-apple wrote:

In the future we should just immediately emit an error for this case.
Can we change the test to use a variable instead of out-of-bounds constant?

https://github.com/llvm/llvm-project/pull/118249


More information about the cfe-commits mailing list