Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Warray-bounds false negative when casting an out-of-bounds array item #43688

Closed
llvmbot opened this issue Dec 19, 2019 · 2 comments
Closed

-Warray-bounds false negative when casting an out-of-bounds array item #43688

llvmbot opened this issue Dec 19, 2019 · 2 comments
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 19, 2019

Bugzilla Link 44343
Resolution FIXED
Resolved on Feb 03, 2021 05:57
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @zygoloid,@vabridgers

Extended Description

For the following code in array-bounds.cpp

unsigned int arr[2] = {0, 1};
int i1 = arr[4];
int i2 = (int)(arr[4]);
int i3 = static_cast(arr[4]);

Clang warns only for i1's assignment. When the array item is casted, no out of bounds warning is presented.

$ clang -cc1 -Warray-bounds array-bounds.cpp
array-bounds.cpp:2:10: warning: array index 4 is past the end of the array
(which contains 2 elements)
int i1 = arr[4];
^ ~
array-bounds.cpp:1:1: note: array 'arr' declared here
unsigned int arr[2] = {0, 1};
^
1 warning generated.

This is not a duplicate of #11143 , as in the latter the subscript operator is applied on the casted array, whereas in this case, the subscript operator is applied first and then casting applied on the result.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Dec 19, 2019

A fix is up for review: https://reviews.llvm.org/D71714

@vabridgers
Copy link
Contributor

Landed the following commit

commit e48f444
Author: Ilya Mirsky ilya.mirsky@ericsson.com
Date: Sun Jan 17 18:02:44 2021 -0600
[Sema] Fix -Warray-bounds false negative when casting an out-of-bounds array item
Patch by Ilya Mirsky!
Fixes: #43688
Reviewed By: rsmith
Differential Revision: https://reviews.llvm.org/D71714

rsmith requested to carefully watch this change, and be prepared to revert if necessary. Closing this ticket for now.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

2 participants