r192146 - Sema: Only merge typedef attributes if the previous decl is a typedef

Justin Bogner mail at justinbogner.com
Mon Oct 7 17:19:09 PDT 2013


Author: bogner
Date: Mon Oct  7 19:19:09 2013
New Revision: 192146

URL: http://llvm.org/viewvc/llvm-project?rev=192146&view=rev
Log:
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

Added:
    cfe/trunk/test/SemaCXX/attr-aligned.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/attr-deprecated.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=192146&r1=192145&r2=192146&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Oct  7 19:19:09 2013
@@ -1712,12 +1712,12 @@ void Sema::MergeTypedefNameDecl(TypedefN
   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;

Added: cfe/trunk/test/SemaCXX/attr-aligned.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-aligned.cpp?rev=192146&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-aligned.cpp (added)
+++ cfe/trunk/test/SemaCXX/attr-aligned.cpp Mon Oct  7 19:19:09 2013
@@ -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");

Modified: cfe/trunk/test/SemaCXX/attr-deprecated.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-deprecated.cpp?rev=192146&r1=192145&r2=192146&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/attr-deprecated.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-deprecated.cpp Mon Oct  7 19:19:09 2013
@@ -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.





More information about the cfe-commits mailing list