Jan Hubicka <hubi...@ucw.cz> writes:

> Hi,
> this patch lets us to remove
>   void *mem = __builtin_malloc (s);
>   if (!mem)
>     __builtin_abort ();
>   __builtin_free (mem);
>
> Where we previously stopped on "if (!mem)" marking __builtin_malloc necessary.
> This is done by matching such conditional in tree-ssa-dce.cc and playing same 
> game
> as we do for free functions.  We consider if itself necessary (since it does
> control flow) but we do not propagate necessity over the SSA name.
>
> In removal stage we check whether SSA name is needed and if not, we replace
> it by constant 1, which makes the conditonal to be folded as constant in
> cfgccleanup.
>
> While working on this, I refactored the code a bit to avoid duplicate matching
> of allocation functions which made me notice that we handled strdup/strndup 
> just
> half way and this prevented us from removing it, which is also fixed and 
> tested
> in the testcase.
>
> Note that testcase pr68078.f90 checks that failed allocation is reported
> when memory limits are set.  We no longer report it since the memory is
> unused and that is why I needed to disable DCE.
>
> I alos tested that with Jakub's patch we now eliminate new operator with
> std::nothrow_t.
>
> Bootstrapped/regtested x86_64-linux, OK?

Very excited to see this and the other work -- thank you!

I seem to get this when testing it out:
+Running gcc:/gcc/testsuite/gcc.dg/analyzer/analyzer.exp ...
+FAIL: gcc.dg/analyzer/pr101837.c (test for warnings, line 10)
+FAIL: gcc.dg/analyzer/pr101837.c (test for warnings, line 5)
+FAIL: gcc.dg/analyzer/pr101837.c (test for warnings, line 9)

I can reproduce it with gcc -c -fanalyzer
gcc/testsuite/gcc.dg/analyzer/pr101837.c -O2. Works with trunk, fails
with patch applied on trunk. On the one hand, it's good, but it's not so
good for the analyzer.

I'll keep testing the patch.

thanks,
sam

Reply via email to