xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/conditional.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
2*f4a2713aSLionel Sambuc 
test1(int cond,float a,float b)3*f4a2713aSLionel Sambuc float test1(int cond, float a, float b) {
4*f4a2713aSLionel Sambuc   return cond ? a : b;
5*f4a2713aSLionel Sambuc }
6*f4a2713aSLionel Sambuc 
test2(int cond,float a,double b)7*f4a2713aSLionel Sambuc double test2(int cond, float a, double b) {
8*f4a2713aSLionel Sambuc   return cond ? a : b;
9*f4a2713aSLionel Sambuc }
10*f4a2713aSLionel Sambuc 
11*f4a2713aSLionel Sambuc void f();
12*f4a2713aSLionel Sambuc 
test3()13*f4a2713aSLionel Sambuc void test3(){
14*f4a2713aSLionel Sambuc    1 ? f() : (void)0;
15*f4a2713aSLionel Sambuc }
16*f4a2713aSLionel Sambuc 
test4()17*f4a2713aSLionel Sambuc void test4() {
18*f4a2713aSLionel Sambuc   int i; short j;
19*f4a2713aSLionel Sambuc   float* k = 1 ? &i : &j;
20*f4a2713aSLionel Sambuc }
21*f4a2713aSLionel Sambuc 
test5()22*f4a2713aSLionel Sambuc void test5() {
23*f4a2713aSLionel Sambuc   const int* cip;
24*f4a2713aSLionel Sambuc   void* vp;
25*f4a2713aSLionel Sambuc   cip = 0 ? vp : cip;
26*f4a2713aSLionel Sambuc }
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc void test6();
29*f4a2713aSLionel Sambuc void test7(int);
test8()30*f4a2713aSLionel Sambuc void* test8() {return 1 ? test6 : test7;}
31*f4a2713aSLionel Sambuc 
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc void _efree(void *ptr);
34*f4a2713aSLionel Sambuc 
_php_stream_free3()35*f4a2713aSLionel Sambuc void _php_stream_free3() {
36*f4a2713aSLionel Sambuc   (1 ? free(0) : _efree(0));
37*f4a2713aSLionel Sambuc }
38*f4a2713aSLionel Sambuc 
_php_stream_free4()39*f4a2713aSLionel Sambuc void _php_stream_free4() {
40*f4a2713aSLionel Sambuc   1 ? _efree(0) : free(0);
41*f4a2713aSLionel Sambuc }
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc // PR5526
44*f4a2713aSLionel Sambuc struct test9 { int a; };
45*f4a2713aSLionel Sambuc void* test9spare();
test9(struct test9 * p)46*f4a2713aSLionel Sambuc void test9(struct test9 *p) {
47*f4a2713aSLionel Sambuc   p ? p : test9spare();
48*f4a2713aSLionel Sambuc }
49*f4a2713aSLionel Sambuc 
50*f4a2713aSLionel Sambuc // CHECK: @test10
51*f4a2713aSLionel Sambuc // CHECK: select i1 {{.*}}, i32 4, i32 5
test10(int c)52*f4a2713aSLionel Sambuc int test10(int c) {
53*f4a2713aSLionel Sambuc   return c ? 4 : 5;
54*f4a2713aSLionel Sambuc }
55*f4a2713aSLionel Sambuc enum { Gronk = 5 };
56*f4a2713aSLionel Sambuc 
57*f4a2713aSLionel Sambuc // rdar://9289603
58*f4a2713aSLionel Sambuc // CHECK: @test11
59*f4a2713aSLionel Sambuc // CHECK: select i1 {{.*}}, i32 4, i32 5
test11(int c)60*f4a2713aSLionel Sambuc int test11(int c) {
61*f4a2713aSLionel Sambuc   return c ? 4 : Gronk;
62*f4a2713aSLionel Sambuc }
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc // CHECK: @test12
65*f4a2713aSLionel Sambuc // CHECK: select i1 {{.*}}, double 4.0{{.*}}, double 2.0
test12(int c)66*f4a2713aSLionel Sambuc double test12(int c) {
67*f4a2713aSLionel Sambuc   return c ? 4.0 : 2.0;
68*f4a2713aSLionel Sambuc }
69*f4a2713aSLionel Sambuc // CHECK: @test13
70*f4a2713aSLionel Sambuc // CHECK: call {{.*}} @f2(
71*f4a2713aSLionel Sambuc int f2(void);
test13()72*f4a2713aSLionel Sambuc void test13() {
73*f4a2713aSLionel Sambuc   f2() ? (void)0 : (void)0;
74*f4a2713aSLionel Sambuc }
75