[Bug tree-optimization/87214] [9 Regression] r263772 miscompiled 520.omnetpp_r in SPEC CPU 2017
marxin at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jan 24 11:25:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87214
--- Comment #9 from Martin Liška <marxin at gcc dot gnu.org> ---
I guess it's not related to qsort (the files looks different and fine:
#include <cstdlib>
#include "spec_qsort.h"
static void spec_swap(void *x, void *y, size_t l) {
/* Swap elements of an array byte by byte. Note that a version specialized
to
operate on a specific data type (e.g. int) would be faster. */
char *a = (char *)x, *b = (char *)y, c;
while(l--) {
c = *a;
*a++ = *b;
*b++ = c;
}
}
static void spec_sort(char *array, size_t size, int begin, int end, int
(*cmp)(const void*,const void*)) {
/* Generic qsort algorithm */
if (end > begin) {
void *pivot = array + begin;
int l = begin + size;
int r = end;
while(l < r) {
if (cmp(array+l,pivot) <= 0) {
l += size;
} else {
r -= size;
spec_swap(array+l, array+r, size);
}
}
l -= size;
spec_swap(array+begin, array+l, size);
spec_sort(array, size, begin, l, cmp);
spec_sort(array, size, r, end, cmp);
}
}
void spec_qsort(void *array, size_t nitems, size_t size, int (*cmp)(const
void*,const void*)) {
spec_sort((char *)array, size, 0, (nitems-1)*size, cmp);
}
More information about the Gcc-bugs
mailing list