https://github.com/mxms0 edited https://github.com/llvm/llvm-project/pull/117370
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
@@ -463,6 +463,13 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
return true;
}
+ // Array index wasn't an integer literal, let's see if it was an enum or
+ // something similar
+ const auto IntConst =
Node.getIdx()->getIntegerConstantExpr(Finder->getAS
https://github.com/mxms0 updated
https://github.com/llvm/llvm-project/pull/117370
>From 8fed333cf4221dbf1826351da80164db5d209c21 Mon Sep 17 00:00:00 2001
From: mxms
Date: Fri, 22 Nov 2024 15:09:07 -0500
Subject: [PATCH 1/2] [Wunsafe-buffer-usage] Fix false positives in handling
enums
Do not w
@@ -39,6 +39,23 @@ void constant_idx_unsafe(unsigned idx) {
buffer[10] = 0; // expected-note{{used in buffer access here}}
}
+enum FooEnum {
+ A = 0,
+ B = 1,
+ C = 2,
+ D
+};
+
+void constant_enum_safe() {
+ int buffer[FooEnum::D] = { 0, 1, 2 };
+ buffer[C] = 0;
@@ -463,6 +463,13 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
return true;
}
+ // Array index wasn't an integer literal, let's see if it was an enum or
+ // something similar
+ const auto IntConst =
Node.getIdx()->getIntegerConstantExpr(Finder->getAS
@@ -39,6 +39,23 @@ void constant_idx_unsafe(unsigned idx) {
buffer[10] = 0; // expected-note{{used in buffer access here}}
}
+enum FooEnum {
+ A = 0,
+ B = 1,
+ C = 2,
+ D
+};
+
+void constant_enum_safe() {
+ int buffer[FooEnum::D] = { 0, 1, 2 };
+ buffer[C] = 0;
llvmbot wrote:
@llvm/pr-subscribers-clang-analysis
Author: Max (mxms0)
Changes
Do not warn if the index is an enum and we an determine statically that it's
within bounds.
---
Full diff: https://github.com/llvm/llvm-project/pull/117370.diff
2 Files Affected:
- (modified) clang/lib/Anal
github-actions[bot] wrote:
Thank you for submitting a Pull Request (PR) to the LLVM Project!
This PR will be automatically labeled and the relevant teams will be notified.
If you wish to, you can add reviewers by using the "Reviewers" section on this
page.
If this is not working for you, it
https://github.com/mxms0 created
https://github.com/llvm/llvm-project/pull/117370
Do not warn if the index is an enum and we an determine statically that it's
within bounds.
>From 8fed333cf4221dbf1826351da80164db5d209c21 Mon Sep 17 00:00:00 2001
From: mxms
Date: Fri, 22 Nov 2024 15:09:07 -050