Skip to content

Commit

Permalink
Added workaround for armc assumptions on integer underflow
Browse files Browse the repository at this point in the history
With ARM Compiler 5.06u3, when the equeue_tickdiff function is
inlined, the compiler treats the unsigned integer subtraction
as undefined behaviour and assumes falsely the comparisons
could never be true.

The workaround is to an explicit cast, which politely reminds the
compiler to emit the correct comparison.
  • Loading branch information
geky committed Nov 6, 2016
1 parent b392561 commit 454cb02
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion equeue.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// calculate the relative-difference between absolute times while
// correctly handling overflow conditions
static inline int equeue_tickdiff(unsigned a, unsigned b) {
return (int)(a - b);
return (int)(unsigned)(a - b);
}

// calculate the relative-difference between absolute times, but
Expand Down

0 comments on commit 454cb02

Please sign in to comment.