Bug 66021 - GCC miscompiles Z3
Summary: GCC miscompiles Z3
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.9.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2015-05-05 17:11 UTC by Nuno Lopes
Modified: 2015-05-10 21:44 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
test case (149.86 KB, application/x-zip-compressed)
2015-05-05 17:16 UTC, Nuno Lopes
Details
reduced test case (987 bytes, text/plain)
2015-05-05 18:15 UTC, Nuno Lopes
Details
Reduced test case (1.86 KB, text/plain)
2015-05-10 15:44 UTC, Nuno Lopes
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nuno Lopes 2015-05-05 17:11:09 UTC
GCC 4.92 miscompiles Z3. I've tried Cygwin and Linux, 32 and 64 bits, and all miscompile.
Comment 1 Nuno Lopes 2015-05-05 17:14:07 UTC
Sorry, a bit more information the problem:

On function void reduce_args_tactic::imp::populate_decl2args_proc::operator()(app * n), when compiled with -O0 no call to memory::deallocate(void* p) is made, while with -O2 memory::deallocate is called with p == 0, which cannot happen (since it's called through dealloc_svect, which bails out if the pointer is null).

Apologies for not being able to reduce the test case; I don't have much experience with the gcc internals.
Comment 2 Nuno Lopes 2015-05-05 17:16:12 UTC
Created attachment 35465 [details]
test case
Comment 3 Nuno Lopes 2015-05-05 18:15:48 UTC
Created attachment 35467 [details]
reduced test case
Comment 4 Andrew Pinski 2015-05-05 23:46:09 UTC
(In reply to Nuno Lopes from comment #3)
> Created attachment 35467 [details]
> reduced test case

The reduced testcase is compiled correctly in that the deallocate is called unconditional with zero argument:
  bit_vector() : m_num_bits(0), m_capacity(0), m_data(0) {
    memory::deallocate(m_data);
  }

m_data will be NULL always when deallocate is called.
Comment 5 Nuno Lopes 2015-05-10 15:44:56 UTC
Created attachment 35514 [details]
Reduced test case

Previous reduced test case was bogus. This one should be ok.
Comment 6 Andrew Pinski 2015-05-10 21:40:18 UTC
Note even though the length that is passed to memcpy is zero, the arguments have to be non-null.  So adding the check around the call to memcpy should fix the issue.
Comment 7 Andrew Pinski 2015-05-10 21:44:56 UTC
Basically GCC understands that memcpy takes non-null arguments and optimizes based on that.