[clang] [Wunsafe-buffer-usage] Fix false positives in handling enums (PR #117370)

2024-11-22 Thread via cfe-commits
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

[clang] [Wunsafe-buffer-usage] Fix false positives in handling enums (PR #117370)

2024-11-22 Thread via 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

[clang] [Wunsafe-buffer-usage] Fix false positives in handling enums (PR #117370)

2024-11-22 Thread via cfe-commits
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

[clang] [Wunsafe-buffer-usage] Fix false positives in handling enums (PR #117370)

2024-11-22 Thread via cfe-commits
@@ -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;

[clang] [Wunsafe-buffer-usage] Fix false positives in handling enums (PR #117370)

2024-11-22 Thread Reid Kleckner via 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

[clang] [Wunsafe-buffer-usage] Fix false positives in handling enums (PR #117370)

2024-11-22 Thread Reid Kleckner via cfe-commits
@@ -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;

[clang] [Wunsafe-buffer-usage] Fix false positives in handling enums (PR #117370)

2024-11-22 Thread via cfe-commits
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

[clang] [Wunsafe-buffer-usage] Fix false positives in handling enums (PR #117370)

2024-11-22 Thread via cfe-commits
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

[clang] [Wunsafe-buffer-usage] Fix false positives in handling enums (PR #117370)

2024-11-22 Thread via cfe-commits
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