[clang] [-Wunsafe-buffer-usage] Ignore constant safe indices in array subscripts (PR #80504)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 14 18:08:35 PST 2024


================
@@ -598,16 +623,16 @@ class ArraySubscriptGadget : public WarningGadget {
   }
 
   static Matcher matcher() {
-    // FIXME: What if the index is integer literal 0? Should this be
-    // a safe gadget in this case?
-      // clang-format off
+    // clang-format off
       return stmt(arraySubscriptExpr(
             hasBase(ignoringParenImpCasts(
               anyOf(hasPointerType(), hasArrayType()))),
-            unless(hasIndex(
-                anyOf(integerLiteral(equals(0)), arrayInitIndexExpr())
-             )))
-            .bind(ArraySubscrTag));
+            unless(anyOf(
+              isSafeArraySubscript(),
+              hasIndex(
+                  anyOf(integerLiteral(equals(0)), arrayInitIndexExpr())
----------------
haoNoQ wrote:

So you want to suppress the warning here right? In this case yeah makes sense.

It's also somewhat covered by
```
warning: zero size arrays are an extension [-Wzero-length-array]
```

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


More information about the cfe-commits mailing list