Skip to content

Unsigned overflow checked for 0U - x but not for -x #6114

@SaswatPadhi

Description

@SaswatPadhi

CBMC version: 5.29.0
Operating system: 10.15.7

Test case:

#include <assert.h>
#include <stdint.h>

int main()
{
    uint32_t x;
    __CPROVER_assume(x & 0x80000000); // set the MSB

    uint32_t y = 0u - x;    // CBMC unhappy
    uint32_t z = -x;        // CBMC unchecked
    uint32_t w = 1u + ~x;   // CBMC happy

    assert(w == y);         // passes
    assert(w == z);         // passes
}

Exact command line resulting in the issue:

$ cbmc --unsigned-overflow-check --signed-overflow-check --bounds-check --conversion-check ~/test.c | tail
** Results:
/Users/saspadhi/test.c function main
[main.overflow.1] line 9 arithmetic overflow on unsigned - in 0u - x: FAILURE
[main.overflow.2] line 11 arithmetic overflow on unsigned + in 1u + ~x: SUCCESS
[main.assertion.1] line 13 assertion w == y: SUCCESS
[main.assertion.2] line 14 assertion w == z: SUCCESS

** 1 of 4 failed (2 iterations)
VERIFICATION FAILED

What behaviour did you expect:
CBMC would report overflow consistently on -x and 0u - x.

What happened instead:
CBMC does not report an overflow on unary negation -x but does so on 0u - x.

Metadata

Metadata

Labels

awsBugs or features of importance to AWS CBMC usersaws-highbug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions