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

via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 6 21:38:59 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 7f19b1e49c172772390a3c2e71631115da80af4b e1eadf464509ab74ff4f097f92e7140f43c61262 --extensions cpp -- clang/lib/Analysis/UnsafeBufferUsage.cpp clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-unsupported.cpp clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index c3f580ec42..f91c220bdc 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -433,27 +433,27 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   //    already duplicated
   //  - call both from Sema and from here
 
-    uint64_t limit;
-    if (const auto *CATy =
-            dyn_cast<ConstantArrayType>(Node.getBase()
-                                            ->IgnoreParenImpCasts()
-                                            ->getType()
-                                            ->getUnqualifiedDesugaredType())) {
-      limit = CATy->getLimitedSize();
-    } else if (const auto *SLiteral = dyn_cast<StringLiteral>(
-                   Node.getBase()->IgnoreParenImpCasts())) {
-      limit = SLiteral->getLength() + 1;
-    } else {
-      return false;
-    }
-
-    if (const auto *IdxLit = dyn_cast<IntegerLiteral>(Node.getIdx())) {
-      const APInt ArrIdx = IdxLit->getValue();
-      if (!ArrIdx.isNonNegative() || ArrIdx.getLimitedValue() >= limit)
-        return false;
-      return true;
-    }
+  uint64_t limit;
+  if (const auto *CATy =
+          dyn_cast<ConstantArrayType>(Node.getBase()
+                                          ->IgnoreParenImpCasts()
+                                          ->getType()
+                                          ->getUnqualifiedDesugaredType())) {
+    limit = CATy->getLimitedSize();
+  } else if (const auto *SLiteral = dyn_cast<StringLiteral>(
+                 Node.getBase()->IgnoreParenImpCasts())) {
+    limit = SLiteral->getLength() + 1;
+  } else {
     return false;
+  }
+
+  if (const auto *IdxLit = dyn_cast<IntegerLiteral>(Node.getIdx())) {
+    const APInt ArrIdx = IdxLit->getValue();
+    if (!ArrIdx.isNonNegative() || ArrIdx.getLimitedValue() >= limit)
+      return false;
+    return true;
+  }
+  return false;
 }
 
 AST_MATCHER_P(CallExpr, hasNumArgs, unsigned, Num) {

``````````

</details>


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


More information about the cfe-commits mailing list