summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2013-10-08 00:19:09 +0000
committerJustin Bogner <mail@justinbogner.com>2013-10-08 00:19:09 +0000
commit84ff5ee44810adfbe948e473c8bd1da085c8186e (patch)
tree3e02ecea34cc06fe22a75cd3497a313ea54fbbd8 /clang
parent4f755deaf659f2b07ed4f83eb5b73a68c9b2eade (diff)
downloadbcm5719-llvm-84ff5ee44810adfbe948e473c8bd1da085c8186e.tar.gz
bcm5719-llvm-84ff5ee44810adfbe948e473c8bd1da085c8186e.zip
Sema: Only merge typedef attributes if the previous decl is a typedef
In r186373, we started merging attributes on typedefs, but this causes us to try to merge attributes even if the previous declaration was not a typedef. Only merge the attributes if the previous decl was also a typedef. Fixes rdar://problem/15044218 llvm-svn: 192146
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp10
-rw-r--r--clang/test/SemaCXX/attr-aligned.cpp16
-rw-r--r--clang/test/SemaCXX/attr-deprecated.cpp6
3 files changed, 27 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 4d5d559ed53..f2f203531fa 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1712,12 +1712,12 @@ void Sema::MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls) {
if (isIncompatibleTypedef(Old, New))
return;
- // The types match. Link up the redeclaration chain if the old
- // declaration was a typedef.
- if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Old))
+ // The types match. Link up the redeclaration chain and merge attributes if
+ // the old declaration was a typedef.
+ if (TypedefNameDecl *Typedef = dyn_cast<TypedefNameDecl>(Old)) {
New->setPreviousDeclaration(Typedef);
-
- mergeDeclAttributes(New, Old);
+ mergeDeclAttributes(New, Old);
+ }
if (getLangOpts().MicrosoftExt)
return;
diff --git a/clang/test/SemaCXX/attr-aligned.cpp b/clang/test/SemaCXX/attr-aligned.cpp
new file mode 100644
index 00000000000..4b9c55f4c7d
--- /dev/null
+++ b/clang/test/SemaCXX/attr-aligned.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+typedef struct S1 { char c; } S1 __attribute__((aligned(8)));
+static_assert(alignof(S1) == 8, "attribute ignored");
+static_assert(alignof(struct S1) == 1, "attribute applied to original type");
+
+typedef struct __attribute__((aligned(8))) S2 { char c; } AS;
+static_assert(alignof(S2) == 8, "attribute not propagated");
+static_assert(alignof(struct S2) == 8, "attribute ignored");
+
+typedef struct __attribute__((aligned(4))) S3 {
+ char c;
+} S3 __attribute__((aligned(8)));
+static_assert(alignof(S3) == 8, "attribute ignored");
+static_assert(alignof(struct S3) == 4, "attribute clobbered");
diff --git a/clang/test/SemaCXX/attr-deprecated.cpp b/clang/test/SemaCXX/attr-deprecated.cpp
index d09faf34d7a..b3223f39979 100644
--- a/clang/test/SemaCXX/attr-deprecated.cpp
+++ b/clang/test/SemaCXX/attr-deprecated.cpp
@@ -244,3 +244,9 @@ namespace test7 {
X *x = new X; // expected-warning{{'operator new' is deprecated}} expected-warning{{'operator delete' is deprecated}}
}
}
+
+// rdar://problem/15044218
+typedef struct TDS {
+} TDS __attribute__((deprecated)); // expected-note {{'TDS' declared here}}
+TDS tds; // expected-warning {{'TDS' is deprecated}}
+struct TDS tds2; // no warning, attribute only applies to the typedef.
OpenPOWER on IntegriCloud