Don't a.k.a. through the primary typedef of an anonymous tag decl.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93362 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index fefe924..171101b 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -110,6 +110,12 @@
     if (isa<VectorType>(Underlying))
       break;
 
+    // Don't desugar through the primary typedef of an anonymous type.
+    if (isa<TagType>(Underlying) && isa<TypedefType>(QT))
+      if (cast<TagType>(Underlying)->getDecl()->getTypedefForAnonDecl() ==
+          cast<TypedefType>(QT)->getDecl())
+        break;
+
     // Otherwise, we're tearing through something opaque; note that
     // we'll eventually need an a.k.a. clause and keep going.
     AKA = true;
diff --git a/test/Sema/anonymous-struct-union.c b/test/Sema/anonymous-struct-union.c
index 47fb2b6..78995a9 100644
--- a/test/Sema/anonymous-struct-union.c
+++ b/test/Sema/anonymous-struct-union.c
@@ -96,3 +96,9 @@
     int a;
   }
 }; // expected-error{{expected member name or ';' after declaration specifiers}}
+
+// Make sure we don't a.k.a. anonymous structs.
+typedef struct {
+  int x;
+} a_struct;
+int tmp = (a_struct) { .x = 0 }; // expected-error {{incompatible type initializing 'a_struct', expected 'int'}}
diff --git a/test/Sema/enum.c b/test/Sema/enum.c
index 262cab5..916de41 100644
--- a/test/Sema/enum.c
+++ b/test/Sema/enum.c
@@ -84,3 +84,11 @@
 static enum e1 badfunc(struct s1 *q) {
   return q->bar();
 }
+
+
+// Make sure we don't a.k.a. anonymous enums.
+typedef enum {
+  an_enumerator = 20
+} an_enum;
+// FIXME: why is this only a warning?
+char * s = (an_enum) an_enumerator; // expected-warning {{incompatible integer to pointer conversion initializing 'an_enum', expected 'char *'}}