]> granicus.if.org Git - clang/commitdiff
Fix crash on invalid in microsoft anonymous struct extension.
authorNico Weber <nicolasweber@gmx.de>
Wed, 1 Feb 2012 00:41:00 +0000 (00:41 +0000)
committerNico Weber <nicolasweber@gmx.de>
Wed, 1 Feb 2012 00:41:00 +0000 (00:41 +0000)
Fixes PR11847. Patch from Jason Haslam!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149460 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/MicrosoftExtensions.c

index d545d03ac5228d7985fd4657b56b13ed46f54154..87bcfe9127d4935ac810458c143aa07a450f4d11 100644 (file)
@@ -2952,9 +2952,10 @@ Decl *Sema::BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS,
   SmallVector<NamedDecl*, 2> Chain;
   Chain.push_back(Anon);
 
-  if (InjectAnonymousStructOrUnionMembers(*this, S, CurContext,
-                                          Record->getDefinition(),
-                                          AS_none, Chain, true))
+  RecordDecl *RecordDef = Record->getDefinition();
+  if (!RecordDef || InjectAnonymousStructOrUnionMembers(*this, S, CurContext,
+                                                        RecordDef, AS_none,
+                                                        Chain, true))
     Anon->setInvalidDecl();
 
   return Anon;
index 7438f7f5de4e27392af077f0d899108a3fe3d36e..a08aeab99b881e4ec4795f049e2daa51692504d5 100644 (file)
@@ -86,4 +86,13 @@ void pointer_to_integral_type_conv(char* ptr) {
    short sh = (short)ptr;
    ch = (char)ptr;
    sh = (short)ptr;
-} 
+}
+
+
+typedef struct {
+  UNKNOWN u; // expected-error {{unknown type name 'UNKNOWN'}}
+} AA;
+
+typedef struct {
+  AA; // expected-warning {{anonymous structs are a Microsoft extension}}
+} BB;