[cfe-commits] r80859 - in /cfe/trunk: include/clang-c/Index.h include/clang/Frontend/ASTUnit.h lib/Frontend/ASTUnit.cpp tools/CIndex/CIndex.cpp tools/CIndex/CIndex.exports tools/c-index-test/c-index-test.c

Daniel Dunbar daniel at zuster.org
Wed Sep 2 23:02:56 PDT 2009


Hi Steve,

Sorry, I had to revert this (and the next commit, which depended on
it), it was breaking all the index tests in a number of places.

I tried to look into but I don't really understand what's going on...
the problem is some kind of spurious free / double free:
--
(gdb) r
Starting program:
/Volumes/Data/Users/ddunbar/llvm.obj.64/Debug/bin/index-test
/Volumes/Data/Users/ddunbar/llvm.obj.64/tools/clang/test/Output/Index/find-decls.c.tmp1.ast
/Volumes/Data/Users/ddunbar/llvm.obj.64/tools/clang/test/Output/Index/find-decls.c.tmp2.ast
-point-at /Volumes/Data/Users/ddunbar/llvm/tools/clang/test/Index/t1.c:8:7
-print-decls
Reading symbols for shared libraries +++. done
[Decl: Function bar_func]
</Volumes/Data/Users/ddunbar/llvm/tools/clang/test/Index/foo.h:4:6,
/Volumes/Data/Users/ddunbar/llvm/tools/clang/test/Index/foo.h:4:19>
[Decl: Function bar_func]
</Volumes/Data/Users/ddunbar/llvm/tools/clang/test/Index/t2.c:5:6,
/Volumes/Data/Users/ddunbar/llvm/tools/clang/test/Index/t2.c:11:1>
[Decl: Function bar_func]
</Volumes/Data/Users/ddunbar/llvm/tools/clang/test/Index/foo.h:4:6,
/Volumes/Data/Users/ddunbar/llvm/tools/clang/test/Index/foo.h:4:19>
index-test(56219) malloc: *** error for object 0x101009000: pointer
being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

Program received signal SIGABRT, Aborted.
0x00007fff87250096 in __kill ()
(gdb) bt
#0  0x00007fff87250096 in __kill ()
#1  0x00007fff872f10c2 in abort ()
#2  0x00007fff87208215 in free ()
#3  0x00000001000692dc in clang::ExternalASTSource::~ExternalASTSource
(this=0x101009000) at
/Volumes/Data/Users/ddunbar/llvm/tools/clang/lib/AST/ASTContext.cpp:4040
#4  0x000000010007db20 in
llvm::OwningPtr<clang::ExternalASTSource>::~OwningPtr
(this=0x101012288) at OwningPtr.h:35
#5  0x000000010007ab9d in clang::ASTContext::~ASTContext
(this=0x101011e00) at
/Volumes/Data/Users/ddunbar/llvm/tools/clang/lib/AST/ASTContext.cpp:91
#6  0x000000010002ac3f in
llvm::OwningPtr<clang::ASTContext>::~OwningPtr (this=0x1008002a0) at
OwningPtr.h:35
#7  0x00000001000298ca in clang::ASTUnit::~ASTUnit (this=0x100800270)
at /Volumes/Data/Users/ddunbar/llvm/tools/clang/lib/Frontend/ASTUnit.cpp:29
#8  0x000000010000acbb in llvm::OwningPtr<clang::ASTUnit>::~OwningPtr
(this=0x1008068a8) at OwningPtr.h:35
#9  0x000000010000ae00 in TUnit::~TUnit (this=0x1008068a0) at
/Volumes/Data/Users/ddunbar/llvm/tools/clang/tools/index-test/index-test.cpp:59
#10 0x0000000100005bb1 in main (argc=6, argv=0x7fff5fbff180) at
/Volumes/Data/Users/ddunbar/llvm/tools/clang/tools/index-test/index-test.cpp:301
--

Can you take a look?

 - Daniel

On Wed, Sep 2, 2009 at 5:32 PM, Steve Naroff<snaroff at apple.com> wrote:
> Author: snaroff
> Date: Wed Sep  2 19:32:06 2009
> New Revision: 80859
>
> URL: http://llvm.org/viewvc/llvm-project?rev=80859&view=rev
> Log:
> Visit function/method bodies and issue callback for parameters and local variables.
> Add clang_getTranslationUnitSpelling().
>
>
> Modified:
>    cfe/trunk/include/clang-c/Index.h
>    cfe/trunk/include/clang/Frontend/ASTUnit.h
>    cfe/trunk/lib/Frontend/ASTUnit.cpp
>    cfe/trunk/tools/CIndex/CIndex.cpp
>    cfe/trunk/tools/CIndex/CIndex.exports
>    cfe/trunk/tools/c-index-test/c-index-test.c
>
> Modified: cfe/trunk/include/clang-c/Index.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=80859&r1=80858&r2=80859&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang-c/Index.h (original)
> +++ cfe/trunk/include/clang-c/Index.h Wed Sep  2 19:32:06 2009
> @@ -95,6 +95,8 @@
>   CXIndex, const char *ast_filename
>  );
>
> +const char *clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit);
> +
>  /*
>    Usage: clang_loadTranslationUnit(). Will load the toplevel declarations
>    within a translation unit, issuing a 'callback' for each one.
>
> Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=80859&r1=80858&r2=80859&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
> +++ cfe/trunk/include/clang/Frontend/ASTUnit.h Wed Sep  2 19:32:06 2009
> @@ -28,6 +28,7 @@
>   class Preprocessor;
>   class ASTContext;
>   class Decl;
> +  class PCHReader;
>
>  /// \brief Utility class for loading a ASTContext from a PCH file.
>  ///
> @@ -39,6 +40,7 @@
>   llvm::OwningPtr<TargetInfo>       Target;
>   llvm::OwningPtr<Preprocessor>     PP;
>   llvm::OwningPtr<ASTContext>       Ctx;
> +  llvm::OwningPtr<PCHReader>        Reader;
>
>   ASTUnit(const ASTUnit&); // do not implement
>   ASTUnit &operator=(const ASTUnit &); // do not implement
> @@ -59,6 +61,8 @@
>   const Diagnostic &getDiagnostic() const { return *Diags.get(); }
>         Diagnostic &getDiagnostic()       { return *Diags.get(); }
>
> +  const std::string &getOriginalSourceFileName();
> +
>   /// \brief Create a ASTUnit from a PCH file.
>   ///
>   /// \param Filename PCH filename
>
> Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=80859&r1=80858&r2=80859&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original)
> +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Wed Sep  2 19:32:06 2009
> @@ -77,6 +77,9 @@
>
>  } // anonymous namespace
>
> +const std::string &ASTUnit::getOriginalSourceFileName() {
> +  return Reader->getOriginalSourceFile();
> +}
>
>  ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
>                                   FileManager &FileMgr,
> @@ -101,10 +104,11 @@
>   std::string Predefines;
>   unsigned Counter;
>
> -  llvm::OwningPtr<PCHReader> Reader;
> +  llvm::OwningPtr<PCHReader>        Reader;
>   llvm::OwningPtr<ExternalASTSource> Source;
>
>   Reader.reset(new PCHReader(SourceMgr, FileMgr, Diags));
> +  AST->Reader.reset(Reader.get());
>   Reader->setListener(new PCHInfoCollector(LangInfo, HeaderInfo, TargetTriple,
>                                            Predefines, Counter));
>
>
> Modified: cfe/trunk/tools/CIndex/CIndex.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.cpp?rev=80859&r1=80858&r2=80859&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/CIndex/CIndex.cpp (original)
> +++ cfe/trunk/tools/CIndex/CIndex.cpp Wed Sep  2 19:32:06 2009
> @@ -67,6 +67,9 @@
>         break;
>     }
>   }
> +  void VisitVarDecl(VarDecl *ND) {
> +    Call(CXCursor_VarDecl, ND);
> +  }
>   void VisitFunctionDecl(FunctionDecl *ND) {
>     Call(ND->isThisDeclarationADefinition() ? CXCursor_FunctionDefn
>                                             : CXCursor_FunctionDecl, ND);
> @@ -95,6 +98,9 @@
>   CXClientData CData;
>
>   void Call(enum CXCursorKind CK, NamedDecl *ND) {
> +    // Disable the callback when the context is equal to the visiting decl.
> +    if (CDecl == ND)
> +      return;
>     CXCursor C = { CK, ND };
>     Callback(CDecl, C, CData);
>   }
> @@ -129,17 +135,28 @@
>   void VisitFieldDecl(FieldDecl *ND) {
>     Call(CXCursor_FieldDecl, ND);
>   }
> +  void VisitVarDecl(VarDecl *ND) {
> +    Call(CXCursor_VarDecl, ND);
> +  }
> +  void VisitParmVarDecl(ParmVarDecl *ND) {
> +    Call(CXCursor_ParmDecl, ND);
> +  }
>   void VisitObjCPropertyDecl(ObjCPropertyDecl *ND) {
>     Call(CXCursor_ObjCPropertyDecl, ND);
>   }
>   void VisitObjCIvarDecl(ObjCIvarDecl *ND) {
>     Call(CXCursor_ObjCIvarDecl, ND);
>   }
> +  void VisitFunctionDecl(FunctionDecl *ND) {
> +    if (ND->isThisDeclarationADefinition()) {
> +      VisitDeclContext(dyn_cast<DeclContext>(ND));
> +    }
> +  }
>   void VisitObjCMethodDecl(ObjCMethodDecl *ND) {
>     if (ND->getBody()) {
>       Call(ND->isInstanceMethod() ? CXCursor_ObjCInstanceMethodDefn
>                                   : CXCursor_ObjCClassMethodDefn, ND);
> -      // FIXME: load body.
> +      VisitDeclContext(dyn_cast<DeclContext>(ND));
>     } else
>       Call(ND->isInstanceMethod() ? CXCursor_ObjCInstanceMethodDecl
>                                   : CXCursor_ObjCClassMethodDecl, ND);
> @@ -167,6 +184,12 @@
>   return ASTUnit::LoadFromPCHFile(astName, CXXIdx->getFileManager(), &ErrMsg);
>  }
>
> +const char *clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit)
> +{
> +  assert(CTUnit && "Passed null CXTranslationUnit");
> +  ASTUnit *CXXUnit = static_cast<ASTUnit *>(CTUnit);
> +  return CXXUnit->getOriginalSourceFileName().c_str();
> +}
>
>  void clang_loadTranslationUnit(CXTranslationUnit CTUnit,
>                                CXTranslationUnitIterator callback,
>
> Modified: cfe/trunk/tools/CIndex/CIndex.exports
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/CIndex/CIndex.exports?rev=80859&r1=80858&r2=80859&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/CIndex/CIndex.exports (original)
> +++ cfe/trunk/tools/CIndex/CIndex.exports Wed Sep  2 19:32:06 2009
> @@ -19,3 +19,4 @@
>  _clang_isDefinition
>  _clang_getCursorSpelling
>  _clang_getCursorKindSpelling
> +_clang_getTranslationUnitSpelling
>
> Modified: cfe/trunk/tools/c-index-test/c-index-test.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=80859&r1=80858&r2=80859&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/c-index-test/c-index-test.c (original)
> +++ cfe/trunk/tools/c-index-test/c-index-test.c Wed Sep  2 19:32:06 2009
> @@ -3,25 +3,27 @@
>  #include "clang-c/Index.h"
>  #include <stdio.h>
>
> +static void PrintCursor(CXCursor Cursor) {
> +  printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
> +                     clang_getCursorSpelling(Cursor));
> +  printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
> +                          clang_getCursorLine(Cursor),
> +                          clang_getCursorColumn(Cursor));
> +}
> +
>  static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter)
>  {
> -  if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
> -    printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
> -                       clang_getCursorSpelling(Cursor));
> -    printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
> -                            clang_getCursorLine(Cursor),
> -                            clang_getCursorColumn(Cursor));
> -  }
> +  printf("%s: ", clang_getDeclSpelling(Dcl));
> +  if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter))
> +    PrintCursor(Cursor);
>  }
> +
>  static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
>                                    CXClientData Filter)
>  {
> +  printf("%s: ", clang_getTranslationUnitSpelling(Unit));
>   if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
> -    printf("%s => %s", clang_getCursorKindSpelling(Cursor.kind),
> -                       clang_getCursorSpelling(Cursor));
> -    printf(" (%s,%d:%d)\n", clang_getCursorSource(Cursor),
> -                            clang_getCursorLine(Cursor),
> -                            clang_getCursorColumn(Cursor));
> +    PrintCursor(Cursor);
>
>     clang_loadDeclaration(Cursor.decl, DeclVisitor, 0);
>   }
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list