Incorrect result from pointer subtraction if result is >2Gbytes
Bug #1819743 reported by
Dominic Plunkett
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
GNU Arm Embedded Toolchain |
Invalid
|
Undecided
|
Unassigned |
Bug Description
32bit gcc 8.2 -o2
If you have an area of memory which is greater than 2Gbytes with a start and end pointers. Then if you do end -start
the compiler generates a signed shift right ASR and thus bit 31 stays set. The compiler needs to check for a carry from the subtraction and either do ASR #2 or LSR #2
See below for an example.
description: | updated |
To post a comment you must log in.
Firstly, this is undefined behaviour in as much as pointer arithmetic on 2 unrelated values. When two pointers are subtracted, both shall point to elements of the same array object, or one past the last element of the array object
What exactly is your concern ?