[cfe-commits] r75597 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/PCH/cxx-method.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Mon Jul 13 20:18:53 PDT 2009


Author: akirtzidis
Date: Mon Jul 13 22:18:53 2009
New Revision: 75597

URL: http://llvm.org/viewvc/llvm-project?rev=75597&view=rev
Log:
Fixes for a couple of things:

- Declaration context of ParmVarDecls (that we got from the Declarator) was not their containing function.
- C++ out-of-line method definitions didn't get an access specifier.

Both were exposed by a crash when emitting a C++ method to a PCH file (assert at Decl::CheckAccessDeclContext()).

Added:
    cfe/trunk/test/PCH/cxx-method.cpp
Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon Jul 13 22:18:53 2009
@@ -2298,8 +2298,12 @@
         Diag(Param->getLocation(), diag::err_param_typedef_of_void);
       // FIXME: Leaks decl?
     } else if (FTI.NumArgs > 0 && FTI.ArgInfo[0].Param != 0) {
-      for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i)
-        Params.push_back(FTI.ArgInfo[i].Param.getAs<ParmVarDecl>());
+      for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {
+        ParmVarDecl *Param = FTI.ArgInfo[i].Param.getAs<ParmVarDecl>();
+        assert(Param->getDeclContext() != NewFD && "Was set before ?");
+        Param->setDeclContext(NewFD);
+        Params.push_back(Param);
+      }
     }
   
   } else if (const FunctionProtoType *FT = R->getAsFunctionProtoType()) {
@@ -2546,8 +2550,11 @@
       if (FunctionTemplateDecl *OldTemplateDecl
             = dyn_cast<FunctionTemplateDecl>(OldDecl))
         NewFD->setPreviousDeclaration(OldTemplateDecl->getTemplatedDecl());
-      else
+      else {
+        if (isa<CXXMethodDecl>(NewFD)) // Set access for out-of-line definitions
+          NewFD->setAccess(OldDecl->getAccess());
         NewFD->setPreviousDeclaration(cast<FunctionDecl>(OldDecl));
+      }
     }
   }
 

Added: cfe/trunk/test/PCH/cxx-method.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/cxx-method.cpp?rev=75597&view=auto

==============================================================================
--- cfe/trunk/test/PCH/cxx-method.cpp (added)
+++ cfe/trunk/test/PCH/cxx-method.cpp Mon Jul 13 22:18:53 2009
@@ -0,0 +1,7 @@
+// RUN: clang-cc -emit-pch %s -o %t
+
+struct S {
+  void m(int x);
+};
+
+void S::m(int x) { }





More information about the cfe-commits mailing list