r214410 - Exposes a C API to name mangling for a given cursor.

Kostya Serebryany kcc at google.com
Fri Aug 1 06:08:58 PDT 2014


Confirmed, thanks!


On Fri, Aug 1, 2014 at 5:05 PM, Eli Bendersky <eliben at google.com> wrote:

>
>
>
> On Fri, Aug 1, 2014 at 5:36 AM, Eli Bendersky <eliben at google.com> wrote:
>
>> Kostya, thanks for pointing my attention to this. I will fix it shortly.
>>
>> The leak is only in the test (c-index-test.c) here - the library API is
>> OK.
>>
>
> Fixed in r214506.
>
> [I checked with Valgrind - looks clean now]
>
>
>
>
>>
>> Eli
>>
>>
>>
>> On Fri, Aug 1, 2014 at 5:05 AM, Kostya Serebryany <kcc at google.com> wrote:
>>
>>> And valgrind agrees:
>>>
>>> valgrind  --leak-check=full c-index-test -test-print-mangle
>>> tools/clang/test/Index/Output/print-mangled-name.cpp.tmp_linux.ast
>>> ==1055== 30 bytes in 3 blocks are definitely lost in loss record 16 of 29
>>> ==1055==    at 0x4C2CF27: malloc (vg_replace_malloc.c:291)
>>> ==1055==    by 0x4F668A4: clang::cxstring::createDup(llvm::StringRef)
>>> (in lib/libclang.so.3.5)
>>> ==1055==    by 0x4F2C894: clang_Cursor_getMangling (in
>>> lib/libclang.so.3.5)
>>> ==1055==    by 0x40B86B: PrintMangledName (in bin/c-index-test)
>>> ==1055==    by 0x4F39AA8:
>>> clang::cxcursor::CursorVisitor::Visit(CXCursor, bool) (in
>>> lib/libclang.so.3.5)
>>> ==1055==    by 0x4F3ACAF:
>>> clang::cxcursor::CursorVisitor::VisitDeclContext(clang::DeclContext*) (in
>>> lib/libclang.so.3.5)
>>> ==1055==    by 0x4F39810:
>>> clang::cxcursor::CursorVisitor::VisitChildren(CXCursor) (in
>>> lib/libclang.so.3.5)
>>> ==1055==    by 0x4F42DF2: clang_visitChildren (in lib/libclang.so.3.5)
>>> ==1055==    by 0x40FFB9: perform_test_load.isra.7 (in bin/c-index-test)
>>> ==1055==    by 0x41020C: perform_test_load_tu (in bin/c-index-test)
>>> ==1055==    by 0x414BF6: cindextest_main (in bin/c-index-test)
>>> ==1055==    by 0x4158AE: thread_runner (in bin/c-index-test)
>>>
>>> ~
>>>
>>>
>>>
>>> On Fri, Aug 1, 2014 at 3:51 PM, Kostya Serebryany <kcc at google.com>
>>> wrote:
>>>
>>>> We observe a new leak on the sanitizer bot:
>>>>
>>>> http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/4103/steps/check-clang%20asan/logs/stdio
>>>> It seems to be caused by this change.
>>>>
>>>> Direct leak of 30 byte(s) in 3 object(s) allocated from:
>>>>     #0 0x49a509 in malloc /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:40
>>>>     #1 0x7f9b1b401cd8 in clang::cxstring::createDup(llvm::StringRef) /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CXString.cpp:100:40
>>>>     #2 0x7f9b1b3a323d in clang_Cursor_getMangling /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:3693:10
>>>>     #3 0x4c5233 in PrintMangledName /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/c-index-test/c-index-test.c:1373:17
>>>>     #4 0x7f9b1b36ff52 in clang::cxcursor::CursorVisitor::Visit(CXCursor, bool) /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:207:11
>>>>     #5 0x7f9b1b376da2 in clang::cxcursor::CursorVisitor::VisitDeclContext(clang::DeclContext*) /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:654:9
>>>>     #6 0x7f9b1b3710ed in clang::cxcursor::CursorVisitor::VisitChildren(CXCursor) /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:529:20
>>>>     #7 0x7f9b1b39ca2e in clang_visitChildren /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/libclang/CIndex.cpp:3364:10
>>>>     #8 0x4ba911 in perform_test_load /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/c-index-test/c-index-test.c:1437:5
>>>>     #9 0x4ba3d0 in perform_test_load_tu /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/c-index-test/c-index-test.c:1468:12
>>>>     #10 0x4c2c1a in cindextest_main /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/c-index-test/c-index-test.c:4052:14
>>>>     #11 0x4c52a7 in thread_runner /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/tools/clang/tools/c-index-test/c-index-test.c:4133:25
>>>>     #12 0x7f9b1cef555f in ExecuteOnThread_Dispatch(void*) /home/dtoolsbot/build/sanitizer-x86_64-linux-bootstrap/build/llvm/lib/Support/Threading.cpp:40:3
>>>>     #13 0x7f9b1a537181 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x8181)
>>>>
>>>> SUMMARY: AddressSanitizer: 30 byte(s) leaked in 3 allocation(s).
>>>>
>>>>
>>>>
>>>>
>>>> On Thu, Jul 31, 2014 at 10:04 PM, Eli Bendersky <eliben at google.com>
>>>> wrote:
>>>>
>>>>> Author: eliben
>>>>> Date: Thu Jul 31 13:04:56 2014
>>>>> New Revision: 214410
>>>>>
>>>>> URL: http://llvm.org/viewvc/llvm-project?rev=214410&view=rev
>>>>> Log:
>>>>> Exposes a C API to name mangling for a given cursor.
>>>>>
>>>>> Inspired by https://gist.github.com/tritao/2766291, and was
>>>>> previously discussed
>>>>> on cfe-dev:
>>>>> http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-June/037577.html
>>>>>
>>>>> Adding testing capability via c-index-test.
>>>>>
>>>>>
>>>>>
>>>>> Added:
>>>>>     cfe/trunk/test/Index/print-mangled-name.cpp
>>>>> Modified:
>>>>>     cfe/trunk/include/clang-c/Index.h
>>>>>     cfe/trunk/tools/c-index-test/c-index-test.c
>>>>>     cfe/trunk/tools/libclang/CIndex.cpp
>>>>>     cfe/trunk/tools/libclang/libclang.exports
>>>>>
>>>>> Modified: cfe/trunk/include/clang-c/Index.h
>>>>> URL:
>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=214410&r1=214409&r2=214410&view=diff
>>>>>
>>>>> ==============================================================================
>>>>> --- cfe/trunk/include/clang-c/Index.h (original)
>>>>> +++ cfe/trunk/include/clang-c/Index.h Thu Jul 31 13:04:56 2014
>>>>> @@ -3639,6 +3639,20 @@ CINDEX_LINKAGE CXString clang_Cursor_get
>>>>>   * @}
>>>>>   */
>>>>>
>>>>> +/** \defgroup CINDEX_MANGLE Name Mangling API Functions
>>>>> + *
>>>>> + * @{
>>>>> + */
>>>>> +
>>>>> +/**
>>>>> + * \brief Retrieve the CXString representing the mangled name of the
>>>>> cursor.
>>>>> + */
>>>>> +CINDEX_LINKAGE CXString clang_Cursor_getMangling(CXCursor);
>>>>> +
>>>>> +/**
>>>>> + * @}
>>>>> + */
>>>>> +
>>>>>  /**
>>>>>   * \defgroup CINDEX_MODULE Module introspection
>>>>>   *
>>>>>
>>>>> Added: cfe/trunk/test/Index/print-mangled-name.cpp
>>>>> URL:
>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-mangled-name.cpp?rev=214410&view=auto
>>>>>
>>>>> ==============================================================================
>>>>> --- cfe/trunk/test/Index/print-mangled-name.cpp (added)
>>>>> +++ cfe/trunk/test/Index/print-mangled-name.cpp Thu Jul 31 13:04:56
>>>>> 2014
>>>>> @@ -0,0 +1,23 @@
>>>>> +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -emit-pch %s -o
>>>>> %t_linux.ast
>>>>> +// RUN: c-index-test -test-print-mangle %t_linux.ast | FileCheck %s
>>>>> --check-prefix=ITANIUM
>>>>> +
>>>>> +// RUN: %clang_cc1 -triple i686-pc-win32 -emit-pch %s -o %t_msft.ast
>>>>> +// RUN: c-index-test -test-print-mangle %t_msft.ast | FileCheck %s
>>>>> --check-prefix=MICROSOFT
>>>>> +
>>>>> +int foo(int, int);
>>>>> +// ITANIUM: mangled=_Z3fooii
>>>>> +// MICROSOFT: mangled=?foo@@YAHHH
>>>>> +
>>>>> +int foo(float, int);
>>>>> +// ITANIUM: mangled=_Z3foofi
>>>>> +// MICROSOFT: mangled=?foo@@YAHMH
>>>>> +
>>>>> +struct S {
>>>>> +  int x, y;
>>>>> +};
>>>>> +// ITANIUM: StructDecl{{.*}}mangled=]
>>>>> +// MICROSOFT: StructDecl{{.*}}mangled=]
>>>>> +
>>>>> +int foo(S, S&);
>>>>> +// ITANIUM: mangled=_Z3foo1SRS
>>>>> +// MICROSOFT: mangled=?foo@@YAHUS
>>>>>
>>>>> 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=214410&r1=214409&r2=214410&view=diff
>>>>>
>>>>> ==============================================================================
>>>>> --- cfe/trunk/tools/c-index-test/c-index-test.c (original)
>>>>> +++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Jul 31 13:04:56
>>>>> 2014
>>>>> @@ -1363,6 +1363,19 @@ static enum CXChildVisitResult PrintType
>>>>>  }
>>>>>
>>>>>
>>>>>  /******************************************************************************/
>>>>> +/* Mangling testing.
>>>>>          */
>>>>>
>>>>> +/******************************************************************************/
>>>>> +
>>>>> +static enum CXChildVisitResult PrintMangledName(CXCursor cursor,
>>>>> CXCursor p,
>>>>> +                                                CXClientData d) {
>>>>> +  CXString MangledName;
>>>>> +  PrintCursor(cursor, NULL);
>>>>> +  MangledName = clang_Cursor_getMangling(cursor);
>>>>> +  printf(" [mangled=%s]\n", clang_getCString(MangledName));
>>>>> +  return CXChildVisit_Continue;
>>>>> +}
>>>>> +
>>>>>
>>>>> +/******************************************************************************/
>>>>>  /* Bitwidth testing.
>>>>>          */
>>>>>
>>>>>  /******************************************************************************/
>>>>>
>>>>> @@ -4081,6 +4094,8 @@ int cindextest_main(int argc, const char
>>>>>    else if (argc > 2 && strcmp(argv[1], "-test-print-bitwidth") == 0)
>>>>>      return perform_test_load_source(argc - 2, argv + 2, "all",
>>>>>                                      PrintBitWidth, 0);
>>>>> +  else if (argc > 2 && strcmp(argv[1], "-test-print-mangle") == 0)
>>>>> +    return perform_test_load_tu(argv[2], "all", NULL,
>>>>> PrintMangledName, NULL);
>>>>>    else if (argc > 1 && strcmp(argv[1], "-print-usr") == 0) {
>>>>>      if (argc > 2)
>>>>>        return print_usrs(argv + 2, argv + argc);
>>>>>
>>>>> Modified: cfe/trunk/tools/libclang/CIndex.cpp
>>>>> URL:
>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=214410&r1=214409&r2=214410&view=diff
>>>>>
>>>>> ==============================================================================
>>>>> --- cfe/trunk/tools/libclang/CIndex.cpp (original)
>>>>> +++ cfe/trunk/tools/libclang/CIndex.cpp Thu Jul 31 13:04:56 2014
>>>>> @@ -22,6 +22,7 @@
>>>>>  #include "CXType.h"
>>>>>  #include "CursorVisitor.h"
>>>>>  #include "clang/AST/Attr.h"
>>>>> +#include "clang/AST/Mangle.h"
>>>>>  #include "clang/AST/StmtVisitor.h"
>>>>>  #include "clang/Basic/Diagnostic.h"
>>>>>  #include "clang/Basic/DiagnosticCategories.h"
>>>>> @@ -3667,6 +3668,31 @@ CXSourceRange clang_Cursor_getSpellingNa
>>>>>    return cxloc::translateSourceRange(Ctx, Loc);
>>>>>  }
>>>>>
>>>>> +CXString clang_Cursor_getMangling(CXCursor C) {
>>>>> +  if (clang_isInvalid(C.kind) || !clang_isDeclaration(C.kind))
>>>>> +    return cxstring::createEmpty();
>>>>> +
>>>>> +  const Decl *D = getCursorDecl(C);
>>>>> +  // Mangling only works for functions and variables.
>>>>> +  if (!D || !(isa<FunctionDecl>(D) || isa<VarDecl>(D)))
>>>>> +    return cxstring::createEmpty();
>>>>> +
>>>>> +  const NamedDecl *ND = cast<NamedDecl>(D);
>>>>> +  std::unique_ptr<MangleContext>
>>>>> MC(ND->getASTContext().createMangleContext());
>>>>> +
>>>>> +  std::string Buf;
>>>>> +  llvm::raw_string_ostream OS(Buf);
>>>>> +  MC->mangleName(ND, OS);
>>>>> +  OS.flush();
>>>>> +
>>>>> +  // The Microsoft mangler may insert a special character in the
>>>>> beginning to
>>>>> +  // prevent further mangling. We can strip that for display purposes.
>>>>> +  if (Buf[0] == '\x01') {
>>>>> +    Buf.erase(0, 1);
>>>>> +  }
>>>>> +  return cxstring::createDup(Buf);
>>>>> +}
>>>>> +
>>>>>  CXString clang_getCursorDisplayName(CXCursor C) {
>>>>>    if (!clang_isDeclaration(C.kind))
>>>>>      return clang_getCursorSpelling(C);
>>>>>
>>>>> Modified: cfe/trunk/tools/libclang/libclang.exports
>>>>> URL:
>>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=214410&r1=214409&r2=214410&view=diff
>>>>>
>>>>> ==============================================================================
>>>>> --- cfe/trunk/tools/libclang/libclang.exports (original)
>>>>> +++ cfe/trunk/tools/libclang/libclang.exports Thu Jul 31 13:04:56 2014
>>>>> @@ -9,6 +9,7 @@ clang_CXXMethod_isVirtual
>>>>>  clang_Cursor_getArgument
>>>>>  clang_Cursor_getBriefCommentText
>>>>>  clang_Cursor_getCommentRange
>>>>> +clang_Cursor_getMangling
>>>>>  clang_Cursor_getParsedComment
>>>>>  clang_Cursor_getRawCommentText
>>>>>  clang_Cursor_getNumArguments
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> cfe-commits mailing list
>>>>> cfe-commits at cs.uiuc.edu
>>>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>>>
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140801/9b5a8466/attachment.html>


More information about the cfe-commits mailing list