1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -O1 -emit-llvm -o - | FileCheck %s 2*f4a2713aSLionel Sambuc // rdar://8315199 3*f4a2713aSLionel Sambuc 4*f4a2713aSLionel Sambuc /* Test for builtin conj, creal, cimag. */ 5*f4a2713aSLionel Sambuc /* Origin: Joseph Myers <jsm28@cam.ac.uk> */ 6*f4a2713aSLionel Sambuc 7*f4a2713aSLionel Sambuc extern float _Complex conjf (float _Complex); 8*f4a2713aSLionel Sambuc extern double _Complex conj (double _Complex); 9*f4a2713aSLionel Sambuc extern long double _Complex conjl (long double _Complex); 10*f4a2713aSLionel Sambuc 11*f4a2713aSLionel Sambuc extern float crealf (float _Complex); 12*f4a2713aSLionel Sambuc extern double creal (double _Complex); 13*f4a2713aSLionel Sambuc extern long double creall (long double _Complex); 14*f4a2713aSLionel Sambuc 15*f4a2713aSLionel Sambuc extern float cimagf (float _Complex); 16*f4a2713aSLionel Sambuc extern double cimag (double _Complex); 17*f4a2713aSLionel Sambuc extern long double cimagl (long double _Complex); 18*f4a2713aSLionel Sambuc 19*f4a2713aSLionel Sambuc extern void abort (void); 20*f4a2713aSLionel Sambuc extern void link_error (void); 21*f4a2713aSLionel Sambuc 22*f4a2713aSLionel Sambuc int main()23*f4a2713aSLionel Sambucmain () 24*f4a2713aSLionel Sambuc { 25*f4a2713aSLionel Sambuc /* For each type, test both runtime and compile time (constant folding) 26*f4a2713aSLionel Sambuc optimization. */ 27*f4a2713aSLionel Sambuc volatile float _Complex fc = 1.0F + 2.0iF; 28*f4a2713aSLionel Sambuc volatile double _Complex dc = 1.0 + 2.0i; 29*f4a2713aSLionel Sambuc volatile long double _Complex ldc = 1.0L + 2.0iL; 30*f4a2713aSLionel Sambuc /* Test floats. */ 31*f4a2713aSLionel Sambuc if (__builtin_conjf (fc) != 1.0F - 2.0iF) 32*f4a2713aSLionel Sambuc abort (); 33*f4a2713aSLionel Sambuc if (__builtin_conjf (1.0F + 2.0iF) != 1.0F - 2.0iF) 34*f4a2713aSLionel Sambuc link_error (); 35*f4a2713aSLionel Sambuc if (__builtin_crealf (fc) != 1.0F) 36*f4a2713aSLionel Sambuc abort (); 37*f4a2713aSLionel Sambuc if (__builtin_crealf (1.0F + 2.0iF) != 1.0F) 38*f4a2713aSLionel Sambuc link_error (); 39*f4a2713aSLionel Sambuc if (__builtin_cimagf (fc) != 2.0F) 40*f4a2713aSLionel Sambuc abort (); 41*f4a2713aSLionel Sambuc if (__builtin_cimagf (1.0F + 2.0iF) != 2.0F) 42*f4a2713aSLionel Sambuc link_error (); 43*f4a2713aSLionel Sambuc /* Test doubles. */ 44*f4a2713aSLionel Sambuc if (__builtin_conj (dc) != 1.0 - 2.0i) 45*f4a2713aSLionel Sambuc abort (); 46*f4a2713aSLionel Sambuc if (__builtin_conj (1.0 + 2.0i) != 1.0 - 2.0i) 47*f4a2713aSLionel Sambuc link_error (); 48*f4a2713aSLionel Sambuc if (__builtin_creal (dc) != 1.0) 49*f4a2713aSLionel Sambuc abort (); 50*f4a2713aSLionel Sambuc if (__builtin_creal (1.0 + 2.0i) != 1.0) 51*f4a2713aSLionel Sambuc link_error (); 52*f4a2713aSLionel Sambuc if (__builtin_cimag (dc) != 2.0) 53*f4a2713aSLionel Sambuc abort (); 54*f4a2713aSLionel Sambuc if (__builtin_cimag (1.0 + 2.0i) != 2.0) 55*f4a2713aSLionel Sambuc link_error (); 56*f4a2713aSLionel Sambuc /* Test long doubles. */ 57*f4a2713aSLionel Sambuc if (__builtin_conjl (ldc) != 1.0L - 2.0iL) 58*f4a2713aSLionel Sambuc abort (); 59*f4a2713aSLionel Sambuc if (__builtin_conjl (1.0L + 2.0iL) != 1.0L - 2.0iL) 60*f4a2713aSLionel Sambuc link_error (); 61*f4a2713aSLionel Sambuc if (__builtin_creall (ldc) != 1.0L) 62*f4a2713aSLionel Sambuc abort (); 63*f4a2713aSLionel Sambuc if (__builtin_creall (1.0L + 2.0iL) != 1.0L) 64*f4a2713aSLionel Sambuc link_error (); 65*f4a2713aSLionel Sambuc if (__builtin_cimagl (ldc) != 2.0L) 66*f4a2713aSLionel Sambuc abort (); 67*f4a2713aSLionel Sambuc if (__builtin_cimagl (1.0L + 2.0iL) != 2.0L) 68*f4a2713aSLionel Sambuc link_error (); 69*f4a2713aSLionel Sambuc } 70*f4a2713aSLionel Sambuc 71*f4a2713aSLionel Sambuc // CHECK-NOT: link_error 72