aboutsummaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/vector.cpp
blob: 808bdb679b09cdbd73ed9f04cf75917f82e6a5eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify %s
// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++98 %s
// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++11 %s
// RUN: %clang_cc1 -flax-vector-conversions=all -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c++20 %s
// RUN: %clang_cc1 -flax-vector-conversions=integer -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -DNO_LAX_FLOAT
// RUN: %clang_cc1 -flax-vector-conversions=none -triple x86_64-apple-darwin10 -fsyntax-only -verify %s -DNO_LAX_FLOAT -DNO_LAX_INT

typedef char char16 __attribute__ ((__vector_size__ (16)));
typedef long long longlong16 __attribute__ ((__vector_size__ (16)));
typedef char char16_e __attribute__ ((__ext_vector_type__ (16)));
typedef long long longlong16_e __attribute__ ((__ext_vector_type__ (2)));

// Test overloading and function calls with vector types.
void f0(char16); // expected-note 0+{{candidate}}

void f0_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) {
  f0(c16);
  f0(ll16);
#ifdef NO_LAX_INT
  // expected-error@-2 {{no matching function}}
#endif
  f0(c16e);
  f0(ll16e);
#ifdef NO_LAX_INT
  // expected-error@-2 {{no matching function}}
#endif
}

int &f1(char16);
float &f1(longlong16);

void f1_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) {
  int &ir1 = f1(c16);
  float &fr1 = f1(ll16);
  int &ir2 = f1(c16e);
  float &fr2 = f1(ll16e);
}

void f2(char16_e); // expected-note 0+{{candidate}}

void f2_test(char16 c16, longlong16 ll16, char16_e c16e, longlong16_e ll16e) {
  f2(c16);
  f2(ll16);
#ifdef NO_LAX_INT
  // expected-error@-2 {{no matching function}}
#endif
  f2(c16e);
  f2(ll16e); // expected-error{{no matching function}}
  f2('a');
  f2(17);
}

// Test the conditional operator with vector types.
void conditional(bool Cond, char16 c16, longlong16 ll16, char16_e c16e,
                 longlong16_e ll16e) {
  // Conditional operators with the same type.
  __typeof__(Cond? c16 : c16) *c16p1 = &c16;
  __typeof__(Cond? ll16 : ll16) *ll16p1 = &ll16;
  __typeof__(Cond? c16e : c16e) *c16ep1 = &c16e;
  __typeof__(Cond? ll16e : ll16e) *ll16ep1 = &ll16e;

  // Conditional operators with similar types.
  __typeof__(Cond? c16 : c16e) *c16ep2 = &c16e;
  __typeof__(Cond? c16e : c16) *c16ep3 = &c16e;
  __typeof__(Cond? ll16 : ll16e) *ll16ep2 = &ll16e;
  __typeof__(Cond? ll16e : ll16) *ll16ep3 = &ll16e;

  // Conditional operators with compatible types under -flax-vector-conversions (default)
  (void)(Cond? c16 : ll16);
  (void)(Cond? ll16e : c16e);
  (void)(Cond? ll16e : c16);
#ifdef NO_LAX_INT
  // expected-error@-4 {{cannot convert}}
  // expected-error@-4 {{cannot convert}}
  // expected-error@-4 {{cannot convert}}
#endif
}

// Test C++ cast'ing of vector types.
void casts(longlong16 ll16, longlong16_e ll16e) {
  // C-style casts.
  (void)(char16)ll16;
  (void)(char16_e)ll16;
  (void)(longlong16)ll16;
  (void)(longlong16_e)ll16;
  (void)(char16)ll16e;
  (void)(char16_e)ll16e;
  (void)(longlong16)ll16e;
  (void)(longlong16_e)ll16e;

  // Function-style casts.
  (void)char16(ll16);
  (void)char16_e(ll16);
  (void)longlong16(ll16);
  (void)longlong16_e(ll16);
  (void)char16(ll16e);
  (void)char16_e(ll16e);
  (void)longlong16(ll16e);
  (void)longlong16_e(ll16e);

  // static_cast
  (void)static_cast<char16>(ll16);
  (void)static_cast<char16_e>(ll16);
#ifdef NO_LAX_INT
  // expected-error@-3 {{not allowed}}
  // expected-error@-3 {{not allowed}}
#endif
  (void)static_cast<longlong16>(ll16);
  (void)static_cast<longlong16_e>(ll16);
  (void)static_cast<char16>(ll16e);
#ifdef NO_LAX_INT
  // expected-error@-2 {{not allowed}}
#endif
  (void)static_cast<char16_e>(ll16e); // expected-error{{static_cast from 'longlong16_e' (vector of 2 'long long' values) to 'char16_e' (vector of 16 'char' values) is not allowed}}
  (void)static_cast<longlong16>(ll16e);
  (void)static_cast<longlong16_e>(ll16e);

  // reinterpret_cast
  (void)reinterpret_cast<char16>(ll16);
  (void)reinterpret_cast<char16_e>(ll16);
  (void)reinterpret_cast<longlong16>(ll16);
  (void)reinterpret_cast<longlong16_e>(ll16);
  (void)reinterpret_cast<char16>(ll16e);
  (void)reinterpret_cast<char16_e>(ll16e);
  (void)reinterpret_cast<longlong16>(ll16e);
  (void)reinterpret_cast<longlong16_e>(ll16e);
}

template<typename T>
struct convertible_to { // expected-note 3 {{candidate function (the implicit copy assignment operator) not viable}}
#if __cplusplus >= 201103L // C++11 or later
// expected-note@-2 3 {{candidate function (the implicit move assignment operator) not viable}}
#endif
  operator T() const;
};

void test_implicit_conversions(bool Cond, char16 c16, longlong16 ll16,
                               char16_e c16e, longlong16_e ll16e,
                               convertible_to<char16> to_c16,
                               convertible_to<longlong16> to_ll16,
                               convertible_to<char16_e> to_c16e,
                               convertible_to<longlong16_e> to_ll16e,
                               convertible_to<char16&> rto_c16,
                               convertible_to<char16_e&> rto_c16e) {
  f0(to_c16);
  f0(to_ll16);
#ifdef NO_LAX_INT
  // expected-error@-2 {{no matching function}}
#endif
  f0(to_c16e);
  f0(to_ll16e);
#ifdef NO_LAX_INT
  // expected-error@-2 {{no matching function}}
#endif
  f2(to_c16);
  f2(to_ll16);
#ifdef NO_LAX_INT
  // expected-error@-2 {{no matching function}}
#endif
  f2(to_c16e);
  f2(to_ll16e); // expected-error{{no matching function}}

  (void)(c16 == c16e);
  (void)(c16 == to_c16);
  (void)+to_c16;
  (void)-to_c16;
  (void)~to_c16;
  (void)(to_c16 == to_c16e);
  (void)(to_c16 != to_c16e);
  (void)(to_c16 <  to_c16e);
  (void)(to_c16 <= to_c16e);
  (void)(to_c16 >  to_c16e);
  (void)(to_c16 >= to_c16e);
  (void)(to_c16 + to_c16);
  (void)(to_c16 - to_c16);
  (void)(to_c16 * to_c16);
  (void)(to_c16 / to_c16);
  (void)(rto_c16 = to_c16); // expected-error{{no viable overloaded '='}}
  (void)(rto_c16 += to_c16);
  (void)(rto_c16 -= to_c16);
  (void)(rto_c16 *= to_c16);
  (void)(rto_c16 /= to_c16);

  (void)+to_c16e;
  (void)-to_c16e;
  (void)~to_c16e;
  (void)(to_c16e == to_c16e);
  (void)(to_c16e != to_c16e);
  (void)(to_c16e <  to_c16e);
  (void)(to_c16e <= to_c16e);
  (void)(to_c16e >  to_c16e);
  (void)(to_c16e >= to_c16e);
  (void)(to_c16e + to_c16);
  (void)(to_c16e - to_c16);
  (void)(to_c16e * to_c16);
  (void)(to_c16e / to_c16);
  (void)(rto_c16e = to_c16); // expected-error{{no viable overloaded '='}}
  (void)(rto_c16e += to_c16);
  (void)(rto_c16e -= to_c16);
  (void)(rto_c16e *= to_c16);
  (void)(rto_c16e /= to_c16);

  (void)+to_c16;
  (void)-to_c16;
  (void)~to_c16;
  (void)(to_c16 == to_c16e);
  (void)(to_c16 != to_c16e);
  (void)(to_c16 <  to_c16e);
  (void)(to_c16 <= to_c16e);
  (void)(to_c16 >  to_c16e);
  (void)(to_c16 >= to_c16e);
  (void)(to_c16 + to_c16e);
  (void)(to_c16 - to_c16e);
  (void)(to_c16 * to_c16e);
  (void)(to_c16 / to_c16e);
  (void)(rto_c16 = c16e); // expected-error{{no viable overloaded '='}}
  (void)(rto_c16 += to_c16e);
  (void)(rto_c16 -= to_c16e);
  (void)(rto_c16 *= to_c16e);
  (void)(rto_c16 /= to_c16e);

  (void)(Cond? to_c16 : to_c16e);
  (void)(Cond? to_ll16e : to_ll16);

  // These 2 are convertible with -flax-vector-conversions (default)
  (void)(Cond? to_c16 : to_ll16);
  (void)(Cond? to_c16e : to_ll16e);
#ifdef NO_LAX_INT
  // expected-error@-3 {{cannot convert}}
  // expected-error@-3 {{cannot convert}}
#endif
}

typedef float fltx2 __attribute__((__vector_size__(8)));
typedef float fltx4 __attribute__((__vector_size__(16)));
typedef double dblx2 __attribute__((__vector_size__(16)));
typedef double dblx4 __attribute__((__vector_size__(32)));

void accept_fltx2(fltx2); // expected-note{{candidate function not viable: no known conversion from 'double' to 'fltx2' (vector of 2 'float' values) for 1st argument}}
void accept_fltx4(fltx4);
void accept_dblx2(dblx2);
#ifdef NO_LAX_FLOAT
// expected-note@-3 {{no known conversion}}
// expected-note@-3 {{no known conversion}}
#endif
void accept_dblx4(dblx4);
void accept_bool(bool); // expected-note{{candidate function not viable: no known conversion from 'fltx2' (vector of 2 'float' values) to 'bool' for 1st argument}}

void test(fltx2 fltx2_val, fltx4 fltx4_val, dblx2 dblx2_val, dblx4 dblx4_val) {
  // Exact matches
  accept_fltx2(fltx2_val);
  accept_fltx4(fltx4_val);
  accept_dblx2(dblx2_val);
  accept_dblx4(dblx4_val);

  // Same-size conversions
  accept_fltx4(dblx2_val);
  accept_dblx2(fltx4_val);
#ifdef NO_LAX_FLOAT
  // expected-error@-3 {{no matching function}}
  // expected-error@-3 {{no matching function}}
#endif

  // Conversion to bool.
  accept_bool(fltx2_val); // expected-error{{no matching function for call to 'accept_bool'}}

  // Scalar-to-vector conversions.
  accept_fltx2(1.0); // expected-error{{no matching function for call to 'accept_fltx2'}}
}

typedef int intx4 __attribute__((__vector_size__(16)));
typedef int inte4 __attribute__((__ext_vector_type__(4)));
typedef float flte4 __attribute__((__ext_vector_type__(4)));

void test_mixed_vector_types(fltx4 f, intx4 n, flte4 g, inte4 m) {
  (void)(f == g);
  (void)(g != f);
  (void)(f <= g);
  (void)(g >= f);
  (void)(f < g);
  (void)(g > f);

  (void)(+g);
  (void)(-g);

  (void)(f + g);
  (void)(f - g);
  (void)(f * g);
  (void)(f / g);
  (void)(f = g);
  (void)(f += g);
  (void)(f -= g);
  (void)(f *= g);
  (void)(f /= g);


  (void)(n == m);
  (void)(m != n);
  (void)(n <= m);
  (void)(m >= n);
  (void)(n < m);
  (void)(m > n);

  (void)(+m);
  (void)(-m);
  (void)(~m);

  (void)(n + m);
  (void)(n - m);
  (void)(n * m);
  (void)(n / m);
  (void)(n % m);
  (void)(n = m);
  (void)(n += m);
  (void)(n -= m);
  (void)(n *= m);
  (void)(n /= m);
}

template<typename T> void test_pseudo_dtor_tmpl(T *ptr) {
  ptr->~T();
  (*ptr).~T();
}

void test_pseudo_dtor(fltx4 *f) {
  f->~fltx4();
  (*f).~fltx4();
  test_pseudo_dtor_tmpl(f);
}

// PR16204
typedef __attribute__((ext_vector_type(4))) int vi4;
const int &reference_to_vec_element = vi4(1).x;

// PR12649
typedef bool bad __attribute__((__vector_size__(16)));  // expected-error {{invalid vector element type 'bool'}}

namespace Templates {
template <typename Elt, unsigned long long Size>
struct TemplateVectorType {
  typedef Elt __attribute__((__vector_size__(Size))) type; // #1
};

template <int N, typename T>
struct PR15730 {
  typedef T __attribute__((vector_size(N * sizeof(T)))) type;
  typedef T __attribute__((vector_size(0x1000000000))) type2; // #2
  typedef T __attribute__((vector_size(3))) type3; // #3
};

void Init() {
  const TemplateVectorType<float, 32>::type Works = {};
  const TemplateVectorType<int, 32>::type Works2 = {};
  // expected-error@#1 {{invalid vector element type 'bool'}}
  // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<bool, 32>' requested here}}
  const TemplateVectorType<bool, 32>::type NoBool = {};
  // expected-error@#1 {{invalid vector element type 'int __attribute__((ext_vector_type(4)))' (vector of 4 'int' values)}}
  // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int __attribute__((ext_vector_type(4))), 32>' requested here}}
  const TemplateVectorType<vi4, 32>::type NoComplex = {};
  // expected-error@#1 {{vector size not an integral multiple of component size}}
  // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 33>' requested here}}
  const TemplateVectorType<int, 33>::type BadSize = {};
  const TemplateVectorType<int, 3200>::type Large = {};
  // expected-error@#1 {{vector size too large}}
  // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 68719476736>' requested here}}
  const TemplateVectorType<int, 0x1000000000>::type TooLarge = {};
  // expected-error@#1 {{zero vector size}}
  // expected-note@+1 {{in instantiation of template class 'Templates::TemplateVectorType<int, 0>' requested here}}
  const TemplateVectorType<int, 0>::type Zero = {};

  // expected-error@#2 {{vector size too large}}
  // expected-error@#3 {{vector size not an integral multiple of component size}}
  // expected-note@+1 {{in instantiation of template class 'Templates::PR15730<8, int>' requested here}}
  const PR15730<8, int>::type PR15730_1 = {};
  // expected-error@#2 {{vector size too large}}
  // expected-note@+1 {{in instantiation of template class 'Templates::PR15730<8, char>' requested here}}
  const PR15730<8, char>::type2 PR15730_2 = {};
}

} // namespace Templates

typedef int inte2 __attribute__((__ext_vector_type__(2)));

void test_vector_literal(inte4 res) {
  inte2 a = (inte2)(1, 2); //expected-warning{{left operand of comma operator has no effect}}
  inte4 b = (inte4)(a, a); //expected-error{{C-style cast from vector 'inte2' (vector of 2 'int' values) to vector 'inte4' (vector of 4 'int' values) of different size}} //expected-warning{{left operand of comma operator has no effect}}
}

typedef __attribute__((__ext_vector_type__(4))) float vector_float4;
typedef __attribute__((__ext_vector_type__(4))) int vector_int4;

namespace swizzle_template_confusion {
  template<typename T> struct xyzw {};
  vector_int4 foo123(vector_float4 &A, vector_float4 &B) {
    return A.xyzw < B.x && B.y > A.y; // OK, not a template-id
  }
}

namespace swizzle_typo_correction {
  template<typename T> struct xyzv {};
  vector_int4 foo123(vector_float4 &A, vector_float4 &B) {
    return A.xyzw < B.x && B.y > A.y; // OK, not a typo for 'xyzv'
  }
}

namespace PR45299 {
typedef float float4 __attribute__((vector_size(16)));

// In this example, 'k' is value dependent. PR45299 reported that this asserted
// because of that, since the truncation check attempted to constant evaluate k,
// which it could not do because it is dependent.
template <typename T>
struct NormalMember {
  float4 f(float4 x) {
    return k * x;
  }
  float k;
};

#if __cplusplus >= 201103L
// This should not diagnose, since the constant evaluator (during instantiation)
// can tell that this isn't a truncation.
template <typename T>
struct ConstantValueNoDiag {
  float4 f(float4 x) {
    return k * x;
  }
  static constexpr double k = 1;
};
template <typename T, int N>
struct ConstantValueNoDiagDependentValue {
  float4 f(float4 x) {
    return k * x;
  }
  static constexpr double k = N;
};

// The following two both diagnose because they cause a truncation.  Test both
// the dependent type and non-dependent type versions.
template <typename T>
struct DiagTrunc {
  float4 f(float4 x) {
    // expected-error@+1{{as implicit conversion would cause truncation}}
    return k * x;
  }
  static constexpr double k = 1340282346638528859811704183484516925443.000000;
};
template <typename T, int N>
struct DiagTruncDependentValue {
  float4 f(float4 x) {
    // expected-error@+1{{as implicit conversion would cause truncation}}
    return k * x;
  }
  static constexpr double k = N + 1340282346638528859811704183484516925443.000000;
};
template <typename T>
struct DiagTruncDependentType {
  float4 f(float4 x) {
    // expected-error@+1{{as implicit conversion would cause truncation}}
    return k * x;
  }
  static constexpr T k = 1340282346638528859811704183484516925443.000000;
};

template <typename T>
struct PR45298 {
    T k1 = T(0);
};

// Ensure this no longer asserts.
template <typename T>
struct PR45298Consumer {
  float4 f(float4 x) {
    return (float)s.k1 * x;
  }

  PR45298<T> s;
};
#endif // __cplusplus >= 201103L

void use() {
  float4 theFloat4;
  NormalMember<double>().f(theFloat4);
#if __cplusplus >= 201103L
  ConstantValueNoDiag<double>().f(theFloat4);
  ConstantValueNoDiagDependentValue<double, 1>().f(theFloat4);
  DiagTrunc<double>().f(theFloat4);
  // expected-note@+1{{in instantiation of member function}}
  DiagTruncDependentValue<double, 0>().f(theFloat4);
  // expected-note@+1{{in instantiation of member function}}
  DiagTruncDependentType<double>().f(theFloat4);
  PR45298Consumer<double>().f(theFloat4);
#endif // __cplusplus >= 201103L
}
}

namespace rdar60092165 {
template <class T> void f() {
  typedef T first_type __attribute__((vector_size(sizeof(T) * 4)));
  typedef T second_type __attribute__((vector_size(sizeof(T) * 4)));

  second_type st;
}
}

namespace PR45780 {
enum E { Value = 15 };
void use(char16 c) {
  E e;
  c &Value;   // expected-error{{cannot convert between scalar type 'PR45780::E' and vector type 'char16'}}
  c == Value; // expected-error{{cannot convert between scalar type 'PR45780::E' and vector type 'char16'}}
  e | c;      // expected-error{{cannot convert between scalar type 'E' and vector type 'char16'}}
  e != c;     // expected-error{{cannot convert between scalar type 'E' and vector type 'char16'}}
}

} // namespace PR45780

namespace PR48540 {
// The below used to cause an OOM error, or an assert, make sure it is still
//  valid.
int (__attribute__((vector_size(16))) a);

template <typename T, int I>
struct S {
  T (__attribute__((vector_size(16))) a);
  int (__attribute__((vector_size(I))) b);
  T (__attribute__((vector_size(I))) c);
};

void use() {
  S<int, 16> s;
}
} // namespace PR48540

#if __cplusplus >= 202002L // C++20 or later
// Don't crash due to missing integer ranks.
char8_t v1 __attribute__((vector_size(16)));
char16_t v2 __attribute__((vector_size(16)));
char32_t v3 __attribute__((vector_size(16)));
wchar_t v4 __attribute__((vector_size(16)));
void triggerIntegerRankCheck() {
  auto b1 = (v1 >= 0x12);
  auto b2 = (v2 >= 0x12);
  auto b3 = (v3 >= 0x12);
  auto b4 = (v4 >= 0x12);
}
#endif

namespace all_operators {
typedef unsigned int v2u __attribute__((ext_vector_type(2)));
typedef float v2f __attribute__((ext_vector_type(2)));

void test_int_vector_scalar(unsigned int ua, v2u v2ua) {
  // Operators with one integer vector and one integer scalar operand. The scalar will splat.
  (void)(v2ua + ua);
  (void)(ua + v2ua);
  (void)(v2ua - ua);
  (void)(ua - v2ua);
  (void)(v2ua * ua);
  (void)(ua * v2ua);
  (void)(v2ua / ua);
  (void)(ua / v2ua);
  (void)(v2ua % ua);
  (void)(ua % v2ua);

  (void)(v2ua == ua);
  (void)(ua == v2ua);
  (void)(v2ua != ua);
  (void)(ua != v2ua);
  (void)(v2ua <= ua);
  (void)(ua <= v2ua);
  (void)(v2ua >= ua);
  (void)(ua >= v2ua);
  (void)(v2ua < ua);
  (void)(ua < v2ua);
  (void)(v2ua > ua);
  (void)(ua > v2ua);
  (void)(v2ua && ua);
  (void)(ua && v2ua);
  (void)(v2ua || ua);
  (void)(ua || v2ua);

  (void)(v2ua & ua);
  (void)(ua & v2ua);
  (void)(v2ua | ua);
  (void)(ua | v2ua);
  (void)(v2ua ^ ua);
  (void)(ua ^ v2ua);
  (void)(v2ua << ua);
  (void)(ua << v2ua);
  (void)(v2ua >> ua);
  (void)(ua >> v2ua);

  v2ua += ua;
  v2ua -= ua;
  v2ua *= ua;
  v2ua /= ua;
  v2ua %= ua;
  v2ua &= ua;
  v2ua |= ua;
  v2ua ^= ua;
  v2ua >>= ua;
  v2ua <<= ua;

  ua += v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
  ua -= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
  ua *= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
  ua /= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
  ua %= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
  ua &= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
  ua |= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
  ua ^= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
  ua >>= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
  ua <<= v2ua; // expected-error{{assigning to 'unsigned int' from incompatible type 'v2u'}}
}

void test_float_vector_scalar(float fa, unsigned int ua, v2f v2fa) {
  // Operators with one float vector and one float scalar operand. The scalar will splat.
  (void)(v2fa + fa);
  (void)(fa + v2fa);
  (void)(v2fa - fa);
  (void)(fa - v2fa);
  (void)(v2fa * fa);
  (void)(fa * v2fa);
  (void)(v2fa / fa);
  (void)(fa / v2fa);
  (void)(v2fa % fa); // expected-error{{invalid operands to binary expression}}
  (void)(fa % v2fa); // expected-error{{invalid operands to binary expression}}

  (void)(v2fa == fa);
  (void)(fa == v2fa);
  (void)(v2fa != fa);
  (void)(fa != v2fa);
  (void)(v2fa <= fa);
  (void)(fa <= v2fa);
  (void)(v2fa >= fa);
  (void)(fa >= v2fa);
  (void)(v2fa < fa);
  (void)(fa < v2fa);
  (void)(v2fa > fa);
  (void)(fa > v2fa);
  (void)(v2fa && fa);
  (void)(fa && v2fa);
  (void)(v2fa || fa);
  (void)(fa || v2fa);

  (void)(v2fa & fa); // expected-error{{invalid operands to binary expression}}
  (void)(fa & v2fa); // expected-error{{invalid operands to binary expression}}
  (void)(v2fa | fa); // expected-error{{invalid operands to binary expression}}
  (void)(fa | v2fa); // expected-error{{invalid operands to binary expression}}
  (void)(v2fa ^ fa); // expected-error{{invalid operands to binary expression}}
  (void)(fa ^ v2fa); // expected-error{{invalid operands to binary expression}}
  (void)(v2fa << fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
  (void)(v2fa << ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
  (void)(fa << v2fa); // expected-error{{used type 'float' where integer is required}}
  (void)(ua << v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
  (void)(v2fa >> fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
  (void)(v2fa >> ua); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
  (void)(fa >> v2fa); // expected-error{{used type 'float' where integer is required}}
  (void)(ua >> v2fa); // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}

  v2fa += fa;
  v2fa -= fa;
  v2fa *= fa;
  v2fa /= fa;
  v2fa %= fa; // expected-error{{invalid operands to binary expression}}
  v2fa &= fa; // expected-error{{invalid operands to binary expression}}
  v2fa |= fa; // expected-error{{invalid operands to binary expression}}
  v2fa ^= fa; // expected-error{{invalid operands to binary expression}}
  v2fa >>= fa; // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}
  v2fa <<= fa; // expected-error{{used type 'v2f' (vector of 2 'float' values) where integer is required}}

  fa += v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}
  fa -= v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}
  fa *= v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}
  fa /= v2fa; // expected-error{{assigning to 'float' from incompatible type 'v2f'}}
  fa %= v2fa; // expected-error{{invalid operands to binary expression}}
  fa &= v2fa; // expected-error{{invalid operands to binary expression}}
  fa |= v2fa; // expected-error{{invalid operands to binary expression}}
  fa ^= v2fa; // expected-error{{invalid operands to binary expression}}
  fa >>= v2fa; // expected-error{{used type 'float' where integer is required}}
  fa <<= v2fa; // expected-error{{used type 'float' where integer is required}}
}

enum Enum { ENUM };

void test_enum_vector_scalar(Enum ea, v2u v2ua) {
  // Operators with one integer vector and one enum scalar operand.
  // The scalar will have an implicit conversion to an integral type and then splat.
  // FIXME: These should behave the same as in C, they should be accepted via
  // the enum converting to an integer then splatting to the vector width.
  // https://github.com/llvm/llvm-project/issues/62869
  (void)(v2ua + ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea + v2ua); // expected-error{{cannot convert between vector values of different size}}
  (void)(v2ua - ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea - v2ua); // expected-error{{cannot convert between vector values of different size}}
  (void)(v2ua * ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea * v2ua); // expected-error{{cannot convert between vector values of different size}}
  (void)(v2ua / ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea / v2ua); // expected-error{{cannot convert between vector values of different size}}
  (void)(v2ua % ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea % v2ua); // expected-error{{cannot convert between vector values of different size}}

  (void)(v2ua == ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea == v2ua); // expected-error{{cannot convert between vector values of different size}}
  (void)(v2ua != ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea != v2ua); // expected-error{{cannot convert between vector values of different size}}
  (void)(v2ua <= ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea <= v2ua); // expected-error{{cannot convert between vector values of different size}}
  (void)(v2ua >= ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea >= v2ua); // expected-error{{cannot convert between vector values of different size}}
  (void)(v2ua < ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea < v2ua); // expected-error{{cannot convert between vector values of different size}}
  (void)(v2ua > ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea > v2ua); // expected-error{{cannot convert between vector values of different size}}
  (void)(v2ua && ea); // expected-error{{cannot convert between vector values of different size}}
  // expected-error@-1{{invalid operands to binary expression}}
  (void)(ea && v2ua); // expected-error{{cannot convert between vector values of different size}}
  // expected-error@-1{{invalid operands to binary expression}}
  (void)(v2ua || ea); // expected-error{{cannot convert between vector values of different size}}
  // expected-error@-1{{invalid operands to binary expression}}
  (void)(ea || v2ua); // expected-error{{cannot convert between vector values of different size}}
  // expected-error@-1{{invalid operands to binary expression}}

  (void)(v2ua & ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea & v2ua); // expected-error{{cannot convert between vector values of different size}}
  (void)(v2ua | ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea | v2ua); // expected-error{{cannot convert between vector values of different size}}
  (void)(v2ua ^ ea); // expected-error{{cannot convert between vector values of different size}}
  (void)(ea ^ v2ua); // expected-error{{cannot convert between vector values of different size}}
  // FIXME: Vector/scalar shifts cause an assertion failure
  // https://github.com/llvm/llvm-project/issues/62870
  // (void)(v2ua << ea);
  // (void)(ea << v2ua);
  // (void)(v2ua >> ea);
  // (void)(ea >> v2ua);

  v2ua += ea; // expected-error{{cannot convert between vector values of different size}}
  v2ua -= ea; // expected-error{{cannot convert between vector values of different size}}
  v2ua *= ea; // expected-error{{cannot convert between vector values of different size}}
  v2ua /= ea; // expected-error{{cannot convert between vector values of different size}}
  v2ua %= ea; // expected-error{{cannot convert between vector values of different size}}
  v2ua &= ea; // expected-error{{cannot convert between vector values of different size}}
  v2ua |= ea; // expected-error{{cannot convert between vector values of different size}}
  v2ua ^= ea; // expected-error{{cannot convert between vector values of different size}}
  // FIXME: Vector/scalar shifts cause an assertion failure
  // https://github.com/llvm/llvm-project/issues/62870
  // v2ua >>= ea;
  // v2ua <<= ea;

  ea += v2ua; // expected-error{{cannot convert between vector values of different size}}
  ea -= v2ua; // expected-error{{cannot convert between vector values of different size}}
  ea *= v2ua; // expected-error{{cannot convert between vector values of different size}}
  ea /= v2ua; // expected-error{{cannot convert between vector values of different size}}
  ea %= v2ua; // expected-error{{cannot convert between vector values of different size}}
  ea &= v2ua; // expected-error{{cannot convert between vector values of different size}}
  ea |= v2ua; // expected-error{{cannot convert between vector values of different size}}
  ea ^= v2ua; // expected-error{{cannot convert between vector values of different size}}
  // FIXME: Vector/scalar shifts cause an assertion failure
  // https://github.com/llvm/llvm-project/issues/62870
  // ea >>= v2ua; // not-expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
  // ea <<= v2ua; // not-expected-error{{assigning to 'enum Enum' from incompatible type 'v2u'}}
}

#if __cplusplus >= 201103L // C++11 or later
enum class EnumClass { ENUM };

void test_scoped_enum_vector(EnumClass ea, v2u v2ua) {
  // Scoped enumerations are only compatible with exactly matching types. They shouldn't integral promote.
  (void)(v2ua + ea); // expected-error{{cannot convert between vector and non-scalar values}}
  (void)(ea + v2ua); // expected-error{{cannot convert between vector and non-scalar values}}
}
#endif
}

namespace GH105486 {
__attribute__((__vector_size__(sizeof(double)))) double a;
double b = a - (long)(*0); // expected-error {{indirection requires pointer operand ('int' invalid)}} \
                           // expected-error {{cannot initialize a variable of type 'double' with an rvalue of type '__attribute__((__vector_size__(1 * sizeof(double)))) double' (vector of 1 'double' value)}}

__attribute__((__vector_size__(sizeof(long)))) long c;
long d = c - (long)(*0); // expected-error {{indirection requires pointer operand ('int' invalid)}} \
                         // expected-error {{cannot initialize a variable of type 'long' with an rvalue of type '__attribute__((__vector_size__(1 * sizeof(long)))) long' (vector of 1 'long' value)}}

const long long e = *0; // expected-error {{indirection requires pointer operand ('int' invalid)}}
double f = a - e;       // expected-error {{cannot initialize a variable of type 'double' with an rvalue of type '__attribute__((__vector_size__(1 * sizeof(double)))) double' (vector of 1 'double' value)}}
int h = c - e;          // expected-error {{cannot initialize a variable of type 'int' with an rvalue of type '__attribute__((__vector_size__(1 * sizeof(long)))) long' (vector of 1 'long' value)}}
}