Incorrect result from pointer subtraction if result is >2Gbytes

Bug #1819743 reported by Dominic Plunkett on 2019-03-12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain

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.

Dominic Plunkett (dp111) on 2019-03-12
description: updated
Ramana Radhakrishnan (ramana) wrote :

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 ?

Changed in gcc-arm-embedded:
status: New → Invalid
Dominic Plunkett (dp111) wrote :

I'm sorry I over simplified the example. I think the compiler should be using LSR instead of ASR as pointers are unsigned.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers