LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 10771 - -Warray-bounds false positive when a cast is involved
Summary: -Warray-bounds false positive when a cast is involved
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: trunk
Hardware: Macintosh All
: P normal
Assignee: Kaelyn Takata
URL:
Keywords:
: 10937 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-08-26 09:08 PDT by Sean McBride
Modified: 2011-09-22 09:50 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sean McBride 2011-08-26 09:08:37 PDT
Consider this C++:

int main (void)
{
	double foo[4096];
	((char *)(foo))[(sizeof(foo)-1)] = '\0';
	
	return 0;
}

It outputs:

test.cp:4:12: warning: array index of '32767' indexes past the end of an array (that contains 4096 elements) [-Warray-bounds]
        ((char *)(foo))[(sizeof(foo)-1)] = '\0';
                  ^      ~~~~~~~~~~~~~

It's a false positive.  Note the cast to char*.

This is with clang version 3.0 (trunk 138577).
Comment 1 Eli Friedman 2011-09-15 17:14:40 PDT
*** Bug 10937 has been marked as a duplicate of this bug. ***
Comment 2 Nico Weber 2011-09-15 17:41:19 PDT
This happens e.g. in ICU
Comment 3 Sean McBride 2011-09-15 17:45:37 PDT
In my case, the original code in question is from the open source ITK project. The warning can be seen on its nightly dashboard:

http://www.cdash.org/CDash/viewBuildError.php?type=1&buildid=1533029
Comment 4 Nico Weber 2011-09-17 17:59:52 PDT
r139990
Comment 5 Sean McBride 2011-09-22 09:50:01 PDT
Confirmed fixed.