[cfe-commits] r170000 - in /cfe/trunk: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp test/Analysis/dtor.cpp

Eric Christopher echristo at gmail.com
Wed Dec 12 11:18:35 PST 2012


Woo. r170000!

-eric


On Wed, Dec 12, 2012 at 11:13 AM, Jordan Rose <jordan_rose at apple.com> wrote:

> Author: jrose
> Date: Wed Dec 12 13:13:44 2012
> New Revision: 170000
>
> URL: http://llvm.org/viewvc/llvm-project?rev=170000&view=rev
> Log:
> [analyzer] Don't crash running destructors for multidimensional arrays.
>
> We don't handle array destructors correctly yet, but we now apply the same
> hack (explicitly destroy the first element, implicitly invalidate the rest)
> for multidimensional arrays that we already use for linear arrays.
>
> <rdar://problem/12858542>
>
> Modified:
>     cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
>     cfe/trunk/test/Analysis/dtor.cpp
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp?rev=170000&r1=169999&r2=170000&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp Wed Dec 12
> 13:13:44 2012
> @@ -172,7 +172,8 @@
>    // FIXME: We need to run the same destructor on every element of the
> array.
>    // This workaround will just run the first destructor (which will still
>    // invalidate the entire array).
> -  if (const ArrayType *AT = getContext().getAsArrayType(ObjectType)) {
> +  // This is a loop because of multidimensional arrays.
> +  while (const ArrayType *AT = getContext().getAsArrayType(ObjectType)) {
>      ObjectType = AT->getElementType();
>      Dest = State->getLValue(ObjectType,
> getSValBuilder().makeZeroArrayIndex(),
>                              loc::MemRegionVal(Dest)).getAsRegion();
>
> Modified: cfe/trunk/test/Analysis/dtor.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dtor.cpp?rev=170000&r1=169999&r2=170000&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Analysis/dtor.cpp (original)
> +++ cfe/trunk/test/Analysis/dtor.cpp Wed Dec 12 13:13:44 2012
> @@ -301,3 +301,30 @@
>      obj->VirtualDtor::~VirtualDtor();
>    }
>  }
> +
> +
> +namespace MultidimensionalArrays {
> +  void testArrayInvalidation() {
> +    int i = 42;
> +    int j = 42;
> +
> +    {
> +      IntWrapper arr[2][2];
> +
> +      // There should be no undefined value warnings here.
> +      // Eventually these should be TRUE as well, but right now
> +      // we can't handle array constructors.
> +      clang_analyzer_eval(arr[0][0].x == 0); //
> expected-warning{{UNKNOWN}}
> +      clang_analyzer_eval(arr[1][1].x == 0); //
> expected-warning{{UNKNOWN}}
> +
> +      arr[0][0].x = &i;
> +      arr[1][1].x = &j;
> +      clang_analyzer_eval(*arr[0][0].x == 42); // expected-warning{{TRUE}}
> +      clang_analyzer_eval(*arr[1][1].x == 42); // expected-warning{{TRUE}}
> +    }
> +
> +    // The destructors should have invalidated i and j.
> +    clang_analyzer_eval(i == 42); // expected-warning{{UNKNOWN}}
> +    clang_analyzer_eval(j == 42); // expected-warning{{UNKNOWN}}
> +  }
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121212/07503d9e/attachment.html>


More information about the cfe-commits mailing list