BasicAA currently tries to support addrspacecasts that change the index width by performing the decomposition in the maximum of all index widths and then trying to fix this up with in-place sign extends to get correct overflow behavior if the actual index width is smaller. However, even in the case where we don't mix different index widths and just have an index width that is smaller than the maximum, the behavior is incorrect (see test), because we only perform the index width adjustment during decomposition and not any of the later logic -- and we don't do anything at all for variable offsets. I'm sure that the case where we actually mix different index widths is even more broken than that. Fix this by not allowing decomposition through index width changes. If the pointers have different index widths, fall back to a base object comparison, ignoring the offsets.
85 lines
1.3 KiB
C
85 lines
1.3 KiB
C
// RUN: %clang_cc1 -triple s390x-ibm-zos -O2 -emit-llvm %s -o - | FileCheck %s --check-prefix=X64
|
|
#include <stddef.h>
|
|
void *__malloc31(size_t);
|
|
|
|
int test_1() {
|
|
// X64-LABEL: define {{.*}} i32 @test_1()
|
|
// X64: ret i32 %add20
|
|
int *__ptr32 a;
|
|
int *b;
|
|
int i;
|
|
int sum1, sum2, sum3;
|
|
|
|
a = (int *__ptr32)__malloc31(sizeof(int) * 10);
|
|
|
|
b = a;
|
|
sum1 = 0;
|
|
for (i = 0; i < 10; ++i) {
|
|
a[i] = i;
|
|
sum1 += i;
|
|
}
|
|
|
|
sum2 = 0;
|
|
for (i = 0; i < 10; ++i) {
|
|
sum2 += a[i];
|
|
}
|
|
sum3 = 0;
|
|
for (i = 0; i < 10; ++i) {
|
|
sum3 += b[i];
|
|
}
|
|
|
|
return (sum1 + sum2 + sum3);
|
|
}
|
|
|
|
int test_2() {
|
|
// X64-LABEL: define {{.*}} i32 @test_2()
|
|
// X64: ret i32 4
|
|
int *a = (int *)__malloc31(sizeof(int));
|
|
int *__ptr32 b;
|
|
|
|
*a = 99;
|
|
b = a;
|
|
*b = 44;
|
|
|
|
// Test should return 4
|
|
return (*b - 40);
|
|
}
|
|
|
|
int test_3() {
|
|
// X64-LABEL: define {{.*}} i32 @test_3()
|
|
// X64: ret i32 4
|
|
int *a = (int *)__malloc31(sizeof(int));
|
|
int *__ptr32 b;
|
|
|
|
*a = 99;
|
|
b = a;
|
|
|
|
// Test should return 4
|
|
return (*b - 95);
|
|
}
|
|
|
|
int test_4() {
|
|
// X64-LABEL: define {{.*}} i32 @test_4()
|
|
// X64: ret i32 1
|
|
int *a = (int *)__malloc31(sizeof(int));
|
|
float *d = (float *)__malloc31(sizeof(float));
|
|
|
|
int *__ptr32 b;
|
|
int *c;
|
|
|
|
float *__ptr32 e;
|
|
float *f;
|
|
|
|
*a = 0;
|
|
*d = 0.0;
|
|
|
|
b = a;
|
|
c = a;
|
|
e = d;
|
|
f = d;
|
|
|
|
// Test should return 1
|
|
return (b == c && e == f);
|
|
}
|
|
|