summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2013-05-02 23:25:32 +0000
committerDouglas Gregor <dgregor@apple.com>2013-05-02 23:25:32 +0000
commitd2472d4cdbee3c5ab5e5edfd080406a9f3a41a6e (patch)
tree6b18c9d8fcb70e5eb80a9703b447f2c969514e1e /clang/test
parent33ebfe36e59dbc75a5f7ae28d59381ad478f460b (diff)
downloadbcm5719-llvm-d2472d4cdbee3c5ab5e5edfd080406a9f3a41a6e.tar.gz
bcm5719-llvm-d2472d4cdbee3c5ab5e5edfd080406a9f3a41a6e.zip
Use attribute argument information to determine when to parse attribute arguments as expressions.
This change partly addresses a heinous problem we have with the parsing of attribute arguments that are a lone identifier. Previously, we would end up parsing the 'align' attribute of this as an expression "(Align)": template<unsigned Size, unsigned Align> class my_aligned_storage { __attribute__((align((Align)))) char storage[Size]; }; while this would parse as a "parameter name" 'Align': template<unsigned Size, unsigned Align> class my_aligned_storage { __attribute__((align(Align))) char storage[Size]; }; The code that handles the alignment attribute would completely ignore the parameter name, so the while the first of these would do what's expected, the second would silently be equivalent to template<unsigned Size, unsigned Align> class my_aligned_storage { __attribute__((align)) char storage[Size]; }; i.e., use the maximal alignment rather than the specified alignment. Address this by sniffing the "Args" provided in the TableGen description of attributes. If the first argument is "obviously" something that should be treated as an expression (rather than an identifier to be matched later), parse it as an expression. Fixes <rdar://problem/13700933>. llvm-svn: 180973
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/SemaObjC/format-arg-attribute.m2
-rw-r--r--clang/test/SemaTemplate/attributes.cpp22
2 files changed, 22 insertions, 2 deletions
diff --git a/clang/test/SemaObjC/format-arg-attribute.m b/clang/test/SemaObjC/format-arg-attribute.m
index 6edb8fd99b3..dede433f37a 100644
--- a/clang/test/SemaObjC/format-arg-attribute.m
+++ b/clang/test/SemaObjC/format-arg-attribute.m
@@ -14,7 +14,7 @@ union u1 { int i; } __attribute__((format_arg(1))); // expected-warning {{'form
enum e1 { E1V0 } __attribute__((format_arg(1))); // expected-warning {{'format_arg' attribute only applies to functions}}
extern NSString *ff3 (const NSString *) __attribute__((format_arg(3-2)));
-extern NSString *ff4 (const NSString *) __attribute__((format_arg(foo))); // expected-error {{attribute takes one argument}}
+extern NSString *ff4 (const NSString *) __attribute__((format_arg(foo))); // expected-error {{use of undeclared identifier 'foo'}}
/* format_arg formats must take and return a string. */
extern NSString *fi0 (int) __attribute__((format_arg(1))); // expected-error {{format argument not a string type}}
diff --git a/clang/test/SemaTemplate/attributes.cpp b/clang/test/SemaTemplate/attributes.cpp
index 495f4a7ad38..5a06a706aa8 100644
--- a/clang/test/SemaTemplate/attributes.cpp
+++ b/clang/test/SemaTemplate/attributes.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=gnu++11 -fsyntax-only -verify %s
namespace attribute_aligned {
template<int N>
@@ -18,6 +18,26 @@ namespace attribute_aligned {
check_alignment<2>::t c2;
check_alignment<3>::t c3; // expected-note 2 {{in instantiation}}
check_alignment<4>::t c4;
+
+ template<unsigned Size, unsigned Align>
+ class my_aligned_storage
+ {
+ __attribute__((align(Align))) char storage[Size];
+ };
+
+ template<typename T>
+ class C {
+ public:
+ C() {
+ static_assert(sizeof(t) == sizeof(T), "my_aligned_storage size wrong");
+ static_assert(alignof(t) == alignof(T), "my_aligned_storage align wrong"); // expected-warning{{'alignof' applied to an expression is a GNU extension}}
+ }
+
+ private:
+ my_aligned_storage<sizeof(T), alignof(T)> t;
+ };
+
+ C<double> cd;
}
namespace PR9049 {
OpenPOWER on IntegriCloud