]> granicus.if.org Git - clang/commitdiff
fix a valgrind problem I noticed while developing another patch,
authorChris Lattner <sabre@nondot.org>
Sun, 12 Apr 2009 20:51:10 +0000 (20:51 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 12 Apr 2009 20:51:10 +0000 (20:51 +0000)
if a decl is invalid, it isn't added to the Decls array, so we
need to pass in Decls.size() to avoid reading uninit memory.

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

lib/Sema/SemaDecl.cpp
test/Sema/decl-invalid.c

index 72611ef08b03f90b24210d3394fe359383f60694..603b8b31a261691300097d4393098e1719572f8e 100644 (file)
@@ -2620,7 +2620,7 @@ Sema::DeclGroupPtrTy Sema::FinalizeDeclaratorGroup(Scope *S, DeclPtrTy *Group,
     }
   }
   return DeclGroupPtrTy::make(DeclGroupRef::Create(Context,
-                                                   &Decls[0], NumDecls));
+                                                   &Decls[0], Decls.size()));
 }
 
 
index 0e10bdd8c122f26577537008f50d9cc5752dd19a..e14bc9891a455840ed83e0e5ebaf59bc81a6a18a 100644 (file)
@@ -8,6 +8,10 @@ typedef union <anonymous> __mbstate_t;  // expected-error {{declaration of anony
 void x(); 
 int a() {
   int r[x()];  // expected-error {{size of array has non-integer type 'void'}}
+
+  static y ?; // expected-error{{unknown type name 'y'}} \
+                 expected-error{{expected identifier or '('}} \
+                 expected-error{{expected ';' at end of declaration}}
 }
 
 int; // expected-error {{declaration does not declare anything}}