[cfe-commits] r93362 - in /cfe/trunk: lib/Sema/Sema.cpp test/Sema/anonymous-struct-union.c test/Sema/enum.c

John McCall rjmccall at apple.com
Wed Jan 13 14:07:45 PST 2010


Author: rjmccall
Date: Wed Jan 13 16:07:44 2010
New Revision: 93362

URL: http://llvm.org/viewvc/llvm-project?rev=93362&view=rev
Log:
Don't a.k.a. through the primary typedef of an anonymous tag decl.


Modified:
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/test/Sema/anonymous-struct-union.c
    cfe/trunk/test/Sema/enum.c

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=93362&r1=93361&r2=93362&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Wed Jan 13 16:07:44 2010
@@ -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;

Modified: cfe/trunk/test/Sema/anonymous-struct-union.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/anonymous-struct-union.c?rev=93362&r1=93361&r2=93362&view=diff

==============================================================================
--- cfe/trunk/test/Sema/anonymous-struct-union.c (original)
+++ cfe/trunk/test/Sema/anonymous-struct-union.c Wed Jan 13 16:07:44 2010
@@ -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'}}

Modified: cfe/trunk/test/Sema/enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enum.c?rev=93362&r1=93361&r2=93362&view=diff

==============================================================================
--- cfe/trunk/test/Sema/enum.c (original)
+++ cfe/trunk/test/Sema/enum.c Wed Jan 13 16:07:44 2010
@@ -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 *'}}





More information about the cfe-commits mailing list