Skip to content
Snippets Groups Projects
Commit aa3ac3d4 authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

Merge branch 'Sorting_fix' into 'master'

Removed an unecessary condition that GCC optimizes out and produces a warning blocking compilation.

GCC 5.x.y returns a lethal warning when compiling the code:

`space.c: In function 'parts_sort':
space.c:595:12: error: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Werror=strict-overflow]
         if (jj + 1 < j && pivot + 1 < max) {
            ^
space.c: In function 'gparts_sort':
space.c:735:12: error: assuming signed overflow does not occur when assuming that (X + c) < X is always false [-Werror=strict-overflow]
         if (jj + 1 < j && pivot + 1 < max) {`

After some research it turns out that the compiler notices that the condition "jj + 1<j" is always true and attempts to optimize it out. But it is only true if j and jj don't overflow (which is what we want anyway). So since it is an "unsafe" optimisation, the compiler returns a warning and we die on warnings... 

In this patch I completely remove that condition. Do you agree with that fix ? 

Note that the parallel_sort branch suffers from the same issue.

See merge request !55
parents 23b341b9 54db70bf
No related branches found
No related tags found
No related merge requests found
......@@ -592,7 +592,7 @@ void parts_sort(struct part *parts, struct xpart *xparts, int *ind, int N,
} else {
/* Recurse on the right? */
if (jj + 1 < j && pivot + 1 < max) {
if (pivot + 1 < max) {
qid = (last++) % qstack_size;
qstack[qid].i = jj + 1;
qstack[qid].j = j;
......@@ -732,7 +732,7 @@ void gparts_sort(struct gpart *gparts, int *ind, int N, int min, int max) {
} else {
/* Recurse on the right? */
if (jj + 1 < j && pivot + 1 < max) {
if (pivot + 1 < max) {
qid = (last++) % qstack_size;
qstack[qid].i = jj + 1;
qstack[qid].j = j;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment