62 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2 3struct param_num {4 void* Foo(int a) __attribute__((alloc_align(1))); // expected-error {{'alloc_align' attribute is invalid for the implicit this argument}}5};6 7 8template <typename T>9struct dependent_ret {10 T *Foo(unsigned long long a) __attribute__((alloc_align(2))); // no-warning, ends up being int**.11 T Foo2(unsigned long long a) __attribute__((alloc_align(2))); // expected-warning {{'alloc_align' attribute only applies to return values that are pointers or references}}12};13 14// Following 2 errors associated only with the 'float' versions below.15template <typename T>16struct dependent_param_struct {17 void* Foo(T param) __attribute__((alloc_align(2))); // expected-error {{'alloc_align' attribute argument may only refer to a function parameter of integer type}}18};19 20template <typename T>21void* dependent_param_func(T param) __attribute__((alloc_align(1)));// expected-error {{'alloc_align' attribute argument may only refer to a function parameter of integer type}}22 23template <int T>24void* illegal_align_param(int p) __attribute__((alloc_align(T))); // expected-error {{'alloc_align' attribute requires parameter 1 to be an integer constant}}25 26template <typename T>27T dependent_return_type(int p) __attribute__((alloc_align(1)));28 29void dependent_impl(int align) {30 dependent_ret<int> a; // expected-note {{in instantiation of template class 'dependent_ret<int>' requested here}}31 a.Foo(1);32 a.Foo2(1);33 dependent_ret<int *> b;34 b.Foo(1);35 b.Foo2(1);36 b.Foo(3); // expected-warning {{requested alignment is not a power of 2}}37 b.Foo2(3); // expected-warning {{requested alignment is not a power of 2}}38 b.Foo(8589934592ull); // expected-warning {{requested alignment must be 4294967296 bytes or smaller; maximum alignment assumed}}39 b.Foo2(8589934592ull); // expected-warning {{requested alignment must be 4294967296 bytes or smaller; maximum alignment assumed}}40 b.Foo(align);41 b.Foo2(align);42 43 dependent_param_struct<int> c;44 c.Foo(1);45 dependent_param_struct<float> d; // expected-note {{in instantiation of template class 'dependent_param_struct<float>' requested here}}46 d.Foo(1.0);47 dependent_param_func<int>(1);48 dependent_param_func<float>(1); // expected-note {{in instantiation of function template specialization 'dependent_param_func<float>' requested here}}49}50 51namespace GH26612 {52// This issue was about the align_value attribute, but alloc_align has the53// same problematic code pattern, so is being fixed at the same time despite54// not having the same crashing behavior.55template <class T>56__attribute__((alloc_align(1))) T f(T x); // expected-warning {{'alloc_align' attribute only applies to return values that are pointers or references}}57 58void foo() {59 f<int>(0); // expected-note {{in instantiation of function template specialization 'GH26612::f<int>' requested here}}60}61} // namespace GH2661262