[clang] [-Wunsafe-buffer-usage] Fix false positives for constant cases (PR #92432)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Mon May 20 12:43:00 PDT 2024


================
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-everything -Wunsafe-buffer-usage \
+// RUN:            -fsafe-buffer-usage-suggestions \
+// RUN:            -verify %s
+
+void char_literal() {
+  if ("abc"[2] == 'c')
+    return;
+  if ("def"[3] == '0')
+    return;
+}
+
+void const_size_buffer_arithmetic() {
+  char kBuf[64] = {};
+  const char* p = kBuf + 1;
+}
+
+// expected-no-diagnostics
----------------
haoNoQ wrote:

Extreme nitpicking: I usually put those on top of the file because otherwise I'd be super confused where all those expected warnings are at. We also really don't want it to end up in the middle of the file if folks add more code at the bottom without reading the comment.

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


More information about the cfe-commits mailing list