2010-06-30 02:34:40 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -o - | FileCheck %s
|
2008-01-03 05:54:09 +08:00
|
|
|
|
|
|
|
// PR1895
|
|
|
|
// sizeof function
|
|
|
|
int zxcv(void);
|
|
|
|
int x=sizeof(zxcv);
|
|
|
|
int y=__alignof__(zxcv);
|
|
|
|
|
2008-01-03 14:36:51 +08:00
|
|
|
|
|
|
|
void *test(int *i) {
|
|
|
|
short a = 1;
|
|
|
|
i += a;
|
|
|
|
i + a;
|
|
|
|
a + i;
|
|
|
|
}
|
|
|
|
|
2008-01-30 15:01:17 +08:00
|
|
|
_Bool test2b;
|
2009-07-22 04:52:43 +08:00
|
|
|
int test2() { if (test2b); return 0; }
|
2008-01-30 15:01:17 +08:00
|
|
|
|
2008-01-31 12:12:50 +08:00
|
|
|
// PR1921
|
|
|
|
int test3() {
|
|
|
|
const unsigned char *bp;
|
|
|
|
bp -= (short)1;
|
|
|
|
}
|
|
|
|
|
2008-02-21 13:45:29 +08:00
|
|
|
// PR2080 - sizeof void
|
|
|
|
int t1 = sizeof(void);
|
|
|
|
int t2 = __alignof__(void);
|
|
|
|
void test4() {
|
|
|
|
t1 = sizeof(void);
|
|
|
|
t2 = __alignof__(void);
|
|
|
|
|
|
|
|
t1 = sizeof(test4());
|
|
|
|
t2 = __alignof__(test4());
|
|
|
|
}
|
|
|
|
|
2008-06-28 06:48:56 +08:00
|
|
|
// 'const float' promotes to double in varargs.
|
|
|
|
int test5(const float x, float float_number) {
|
|
|
|
return __builtin_isless(x, float_number);
|
|
|
|
}
|
|
|
|
|
2008-11-17 04:09:07 +08:00
|
|
|
// this one shouldn't fold
|
|
|
|
int ola() {
|
|
|
|
int a=2;
|
|
|
|
if ((0, (int)a) & 2) { return 1; }
|
|
|
|
return 2;
|
|
|
|
}
|
2008-11-20 01:44:31 +08:00
|
|
|
|
|
|
|
// this one shouldn't fold as well
|
|
|
|
void eMaisUma() {
|
2009-09-09 23:08:12 +08:00
|
|
|
double t[1];
|
|
|
|
if (*t)
|
|
|
|
return;
|
2008-11-20 01:44:31 +08:00
|
|
|
}
|
2009-02-11 15:21:43 +08:00
|
|
|
|
|
|
|
// rdar://6520707
|
|
|
|
void f0(void (*fp)(void), void (*fp2)(void)) {
|
|
|
|
int x = fp - fp2;
|
|
|
|
}
|
|
|
|
|
2009-03-18 12:02:57 +08:00
|
|
|
// noop casts as lvalues.
|
|
|
|
struct X {
|
|
|
|
int Y;
|
|
|
|
};
|
|
|
|
struct X foo();
|
|
|
|
int bar() {
|
|
|
|
return ((struct X)foo()).Y + 1;
|
|
|
|
}
|
2009-02-11 15:21:43 +08:00
|
|
|
|
2009-03-18 12:25:13 +08:00
|
|
|
// PR3809: INC/DEC of function pointers.
|
|
|
|
void f2(void);
|
|
|
|
unsigned f1(void) {
|
|
|
|
void (*fp)(void) = f2;
|
|
|
|
|
|
|
|
++fp;
|
|
|
|
fp++;
|
|
|
|
--fp;
|
|
|
|
fp--;
|
|
|
|
return (unsigned) fp;
|
|
|
|
}
|
|
|
|
|
2009-03-19 02:28:57 +08:00
|
|
|
union f3_x {int x; float y;};
|
|
|
|
int f3() {return ((union f3_x)2).x;}
|
|
|
|
|
2009-03-19 02:30:44 +08:00
|
|
|
union f4_y {int x; _Complex float y;};
|
|
|
|
_Complex float f4() {return ((union f4_y)(_Complex float)2.0).y;}
|
|
|
|
|
|
|
|
struct f5_a { int a; } f5_a;
|
|
|
|
union f5_z {int x; struct f5_a y;};
|
|
|
|
struct f5_a f5() {return ((union f5_z)f5_a).y;}
|
2009-03-24 10:38:23 +08:00
|
|
|
|
|
|
|
// ?: in "lvalue"
|
|
|
|
struct s6 { int f0; };
|
|
|
|
int f6(int a0, struct s6 a1, struct s6 a2) {
|
|
|
|
return (a0 ? a1 : a2).f0;
|
|
|
|
}
|
2009-04-22 07:00:09 +08:00
|
|
|
|
|
|
|
// PR4026
|
|
|
|
void f7() {
|
|
|
|
__func__;
|
|
|
|
}
|
2009-04-26 03:35:26 +08:00
|
|
|
|
|
|
|
// PR4067
|
|
|
|
int f8() {
|
|
|
|
return ({ foo(); }).Y;
|
|
|
|
}
|
2009-05-13 05:28:12 +08:00
|
|
|
|
|
|
|
// rdar://6880558
|
|
|
|
struct S;
|
|
|
|
struct C {
|
|
|
|
int i;
|
|
|
|
struct S *tab[];
|
|
|
|
};
|
|
|
|
struct S { struct C c; };
|
|
|
|
void f9(struct S *x) {
|
|
|
|
foo(((void)1, x->c).tab[0]);
|
|
|
|
}
|
|
|
|
|
2009-12-07 10:09:14 +08:00
|
|
|
void f10() {
|
|
|
|
__builtin_sin(0);
|
|
|
|
}
|
2010-06-27 07:03:20 +08:00
|
|
|
|
|
|
|
// rdar://7530813
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define i32 @f11
|
2010-06-27 07:03:20 +08:00
|
|
|
int f11(long X) {
|
|
|
|
int A[100];
|
|
|
|
return A[X];
|
|
|
|
|
2010-06-30 02:34:40 +08:00
|
|
|
// CHECK: [[Xaddr:%[^ ]+]] = alloca i64, align 8
|
Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment. Introduce APIs on CGBuilderTy to work with Address
values. Change core APIs on CGF/CGM to traffic in Address where
appropriate. Require alignments to be non-zero. Update a ton
of code to compute and propagate alignment information.
As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.
The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned. Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay. I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.
Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.
We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment. In particular,
field access now uses alignmentAtOffset instead of min.
Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs. For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint. That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.
ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments. In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments. That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.
I partially punted on applying this work to CGBuiltin. Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.
llvm-svn: 246985
2015-09-08 16:05:57 +08:00
|
|
|
// CHECK: [[A:%.*]] = alloca [100 x i32], align
|
|
|
|
// CHECK: [[X:%.*]] = load {{.*}}, {{.*}}* [[Xaddr]]
|
|
|
|
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [100 x i32], [100 x i32]* [[A]], i64 0, i64 [[X]]
|
|
|
|
// CHECK-NEXT: load i32, i32* [[T0]], align 4
|
2010-06-27 07:03:20 +08:00
|
|
|
}
|
|
|
|
|
2010-06-27 09:08:03 +08:00
|
|
|
int f12() {
|
|
|
|
// PR3150
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define i32 @f12
|
2010-06-27 09:08:03 +08:00
|
|
|
// CHECK: ret i32 1
|
|
|
|
return 1||1;
|
|
|
|
}
|
2010-06-29 01:12:37 +08:00
|
|
|
|
|
|
|
// Make sure negate of fp uses -0.0 for proper -0 handling.
|
|
|
|
double f13(double X) {
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define double @f13
|
2010-06-29 02:29:14 +08:00
|
|
|
// CHECK: fsub double -0.0
|
2010-06-29 01:12:37 +08:00
|
|
|
return -X;
|
|
|
|
}
|
2010-08-21 10:46:28 +08:00
|
|
|
|
|
|
|
// Check operations on incomplete types.
|
2010-12-04 20:29:11 +08:00
|
|
|
void f14(struct s14 *a) {
|
2010-08-21 10:46:28 +08:00
|
|
|
(void) &*a;
|
|
|
|
}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @f15
|
2010-12-04 20:43:24 +08:00
|
|
|
void f15() {
|
|
|
|
extern void f15_start(void);
|
|
|
|
f15_start();
|
|
|
|
// CHECK: call void @f15_start()
|
|
|
|
|
|
|
|
extern void *f15_v(void);
|
|
|
|
extern const void *f15_cv(void);
|
|
|
|
extern volatile void *f15_vv(void);
|
|
|
|
*f15_v(); *f15_v(), *f15_v(); f15_v() ? *f15_v() : *f15_v();
|
|
|
|
*f15_cv(); *f15_cv(), *f15_cv(); f15_cv() ? *f15_cv() : *f15_cv();
|
|
|
|
*f15_vv(); *f15_vv(), *f15_vv(); f15_vv() ? *f15_vv() : *f15_vv();
|
|
|
|
// CHECK-NOT: load
|
2010-12-04 20:29:11 +08:00
|
|
|
// CHECK: ret void
|
|
|
|
}
|
2011-01-13 10:03:06 +08:00
|
|
|
|
|
|
|
// PR8967: this was crashing
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @f16()
|
2011-01-13 10:03:06 +08:00
|
|
|
void f16() {
|
|
|
|
__extension__({ goto lbl; });
|
|
|
|
lbl:
|
|
|
|
;
|
|
|
|
}
|
2012-08-29 01:46:11 +08:00
|
|
|
|
|
|
|
// PR13704: negative increment in i128 is not preserved.
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @f17()
|
2012-08-29 01:46:11 +08:00
|
|
|
void f17() {
|
|
|
|
extern void extfunc(__int128);
|
|
|
|
__int128 x = 2;
|
|
|
|
x--;
|
|
|
|
extfunc(x);
|
2012-08-29 02:11:31 +08:00
|
|
|
// CHECK: add nsw i128 %{{.}}, -1
|
2012-08-29 01:46:11 +08:00
|
|
|
}
|
2015-05-21 05:59:25 +08:00
|
|
|
|
|
|
|
// PR23597: We should evaluate union cast operands even if the cast is unused.
|
|
|
|
typedef union u {
|
|
|
|
int i;
|
|
|
|
} strct;
|
|
|
|
int returns_int(void);
|
|
|
|
void f18() {
|
|
|
|
(strct)returns_int();
|
|
|
|
}
|
|
|
|
// CHECK-LABEL: define void @f18()
|
|
|
|
// CHECK: call i32 @returns_int()
|