annotate clang/test/SemaCXX/builtin-assume-aligned-tmpl.cpp @ 222:81f6424ef0e3 llvm-original

LLVM original branch
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 18 Jul 2021 22:10:01 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2
anatofuz
parents:
diff changeset
3 template<int z>
anatofuz
parents:
diff changeset
4 int test9(int *a) {
anatofuz
parents:
diff changeset
5 a = (int *) __builtin_assume_aligned(a, z + 1); // expected-error {{requested alignment is not a power of 2}}
anatofuz
parents:
diff changeset
6 return a[0];
anatofuz
parents:
diff changeset
7 }
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 void test9i(int *a) {
anatofuz
parents:
diff changeset
10 test9<42>(a); // expected-note {{in instantiation of function template specialization 'test9<42>' requested here}}
anatofuz
parents:
diff changeset
11 }
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 template<typename T>
anatofuz
parents:
diff changeset
14 int test10(int *a, T z) {
anatofuz
parents:
diff changeset
15 a = (int *) __builtin_assume_aligned(a, z + 1); // expected-error {{must be a constant integer}}
anatofuz
parents:
diff changeset
16 return a[0];
anatofuz
parents:
diff changeset
17 }
anatofuz
parents:
diff changeset
18
anatofuz
parents:
diff changeset
19 int test10i(int *a) {
anatofuz
parents:
diff changeset
20 return test10(a, 42); // expected-note {{in instantiation of function template specialization 'test10<int>' requested here}}
anatofuz
parents:
diff changeset
21 }
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 template <int q>
anatofuz
parents:
diff changeset
24 void *atest() __attribute__((assume_aligned(q))); // expected-error {{requested alignment is not a power of 2}}
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 template <int q, int o>
anatofuz
parents:
diff changeset
27 void *atest2() __attribute__((assume_aligned(q, o))); // expected-error {{requested alignment is not a power of 2}}
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 void test20() {
anatofuz
parents:
diff changeset
30 atest<31>(); // expected-note {{in instantiation of function template specialization 'atest<31>' requested here}}
anatofuz
parents:
diff changeset
31 atest<32>();
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 atest2<31, 5>(); // expected-note {{in instantiation of function template specialization 'atest2<31, 5>' requested here}}
anatofuz
parents:
diff changeset
34 atest2<32, 4>();
anatofuz
parents:
diff changeset
35 }
anatofuz
parents:
diff changeset
36
anatofuz
parents:
diff changeset
37 // expected-error@+1 {{invalid application of 'sizeof' to a function type}}
anatofuz
parents:
diff changeset
38 template<typename T> __attribute__((assume_aligned(sizeof(int(T()))))) T *f();
anatofuz
parents:
diff changeset
39 void test21() {
anatofuz
parents:
diff changeset
40 void *p = f<void>(); // expected-note {{in instantiation of function template specialization 'f<void>' requested here}}
anatofuz
parents:
diff changeset
41 }
anatofuz
parents:
diff changeset
42
anatofuz
parents:
diff changeset
43 // expected-error@+1 {{functional-style cast from 'void' to 'int' is not allowed}}
anatofuz
parents:
diff changeset
44 template<typename T> __attribute__((assume_aligned(sizeof((int(T())))))) T *g();
anatofuz
parents:
diff changeset
45 void test23() {
anatofuz
parents:
diff changeset
46 void *p = g<void>(); // expected-note {{in instantiation of function template specialization 'g<void>' requested here}}
anatofuz
parents:
diff changeset
47 }
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 template <typename T, int o>
anatofuz
parents:
diff changeset
50 T *atest3() __attribute__((assume_aligned(31, o))); // expected-error {{requested alignment is not a power of 2}}
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 template <typename T, int o>
anatofuz
parents:
diff changeset
53 T *atest4() __attribute__((assume_aligned(32, o)));
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 void test22() {
anatofuz
parents:
diff changeset
56 atest3<int, 5>();
anatofuz
parents:
diff changeset
57 atest4<int, 5>();
anatofuz
parents:
diff changeset
58 }
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 // expected-warning@+1 {{'assume_aligned' attribute only applies to Objective-C methods and functions}}
anatofuz
parents:
diff changeset
61 class __attribute__((assume_aligned(32))) x {
anatofuz
parents:
diff changeset
62 int y;
anatofuz
parents:
diff changeset
63 };
anatofuz
parents:
diff changeset
64
anatofuz
parents:
diff changeset
65 // expected-warning@+1 {{'assume_aligned' attribute only applies to return values that are pointers or references}}
anatofuz
parents:
diff changeset
66 x foo() __attribute__((assume_aligned(32)));
anatofuz
parents:
diff changeset
67
anatofuz
parents:
diff changeset
68 struct s1 {
anatofuz
parents:
diff changeset
69 static const int x = 32;
anatofuz
parents:
diff changeset
70 };
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 struct s2 {
anatofuz
parents:
diff changeset
73 static const int x = 64;
anatofuz
parents:
diff changeset
74 };
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 struct s3 {
anatofuz
parents:
diff changeset
77 static const int x = 63;
anatofuz
parents:
diff changeset
78 };
anatofuz
parents:
diff changeset
79
anatofuz
parents:
diff changeset
80 template <typename X>
anatofuz
parents:
diff changeset
81 void *atest5() __attribute__((assume_aligned(X::x))); // expected-error {{requested alignment is not a power of 2}}
anatofuz
parents:
diff changeset
82 void test24() {
anatofuz
parents:
diff changeset
83 atest5<s1>();
anatofuz
parents:
diff changeset
84 atest5<s2>();
anatofuz
parents:
diff changeset
85 atest5<s3>(); // expected-note {{in instantiation of function template specialization 'atest5<s3>' requested here}}
anatofuz
parents:
diff changeset
86 }
anatofuz
parents:
diff changeset
87