[cfe-commits] r139990 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/SemaCXX/array-bounds.cpp
Nico Weber
thakis at chromium.org
Sat Sep 17 16:04:16 PDT 2011
rikka, please take a look if this makes sense.
On Sat, Sep 17, 2011 at 3:59 PM, Nico Weber <nicolasweber at gmx.de> wrote:
> Author: nico
> Date: Sat Sep 17 17:59:41 2011
> New Revision: 139990
>
> URL: http://llvm.org/viewvc/llvm-project?rev=139990&view=rev
> Log:
> Let -Warray-bounds handle casted array types without false positives.
>
> Fixes PR10771.
>
>
> Modified:
> cfe/trunk/lib/Sema/SemaChecking.cpp
> cfe/trunk/test/SemaCXX/array-bounds.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=139990&r1=139989&r2=139990&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaChecking.cpp Sat Sep 17 17:59:41 2011
> @@ -3709,7 +3709,7 @@
> return;
>
> const Type* BaseType = getElementType(BaseExpr);
> - if (!isSubscript && BaseType != EffectiveType) {
> + if (BaseType != EffectiveType) {
> // Make sure we're comparing apples to apples when comparing index to size
> uint64_t ptrarith_typesize = Context.getTypeSize(EffectiveType);
> uint64_t array_typesize = Context.getTypeSize(BaseType);
>
> Modified: cfe/trunk/test/SemaCXX/array-bounds.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/array-bounds.cpp?rev=139990&r1=139989&r2=139990&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/array-bounds.cpp (original)
> +++ cfe/trunk/test/SemaCXX/array-bounds.cpp Sat Sep 17 17:59:41 2011
> @@ -214,3 +214,15 @@
> else
> return foo[5]; // expected-warning {{array index of '5' indexes past the end of an array (that contains 5 elements)}}
> }
> +
> +void test_pr10771() {
> + double foo[4096]; // expected-note {{array 'foo' declared here}}
> +
> + ((char*)foo)[sizeof(foo) - 1] = '\0'; // no-warning
> + *(((char*)foo) + sizeof(foo) - 1) = '\0'; // no-warning
> +
> + ((char*)foo)[sizeof(foo)] = '\0'; // expected-warning {{array index of '32768' indexes past the end of an array (that contains 32768 elements)}}
> +
> + // TODO: This should probably warn, too.
> + *(((char*)foo) + sizeof(foo)) = '\0'; // no-warning
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
More information about the cfe-commits
mailing list