r253909 - Make clang_Cursor_getMangling not mangle if the declaration isn't mangled

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Tue May 31 07:18:48 PDT 2016


Burt Wesarg points out on cfe-dev that this commit message doesn't match
the patch (nor the description provided in the code review thread that lead
to this commit) - this one might be worth reverting and recommitting with a
more accurate commit message (I don't usually suggest this for most commits
that are missing a commit message, but this one is actively misleading so
might be trickier when people are doing archaeology)?

On Mon, Nov 23, 2015 at 11:56 AM, Ehsan Akhgari via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Author: ehsan
> Date: Mon Nov 23 13:56:46 2015
> New Revision: 253909
>
> URL: http://llvm.org/viewvc/llvm-project?rev=253909&view=rev
> Log:
> Make clang_Cursor_getMangling not mangle if the declaration isn't mangled
>
> Right now clang_Cursor_getMangling will attempt to mangle any
> declaration, even if the declaration isn't mangled (extern C).  This
> results in a partially mangled name which isn't useful for much. This
> patch makes clang_Cursor_getMangling return an empty string if the
> declaration isn't mangled.
>
> Patch by Michael Wu <mwu at mozilla.com>.
>
> Added:
>     cfe/trunk/test/Index/symbol-visibility.c
> 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=253909&r1=253908&r2=253909&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang-c/Index.h (original)
> +++ cfe/trunk/include/clang-c/Index.h Mon Nov 23 13:56:46 2015
> @@ -2461,6 +2461,32 @@ enum CXLinkageKind {
>  CINDEX_LINKAGE enum CXLinkageKind clang_getCursorLinkage(CXCursor cursor);
>
>  /**
> + * \brief Describe the visibility of the entity referred to by a cursor.
> + *
> + * This returns the default visibility if not explicitly specified by
> + * a visibility attribute. The default visibility may be changed by
> + * commandline arguments.
> + *
> + * \param cursor The cursor to query.
> + *
> + * \returns The visibility of the cursor.
> + */
> +enum CXVisibilityKind {
> +  /** \brief This value indicates that no visibility information is
> available
> +   * for a provided CXCursor. */
> +  CXVisibility_Invalid,
> +
> +  /** \brief Symbol not seen by the linker. */
> +  CXVisibility_Hidden,
> +  /** \brief Symbol seen by the linker but resolves to a symbol inside
> this object. */
> +  CXVisibility_Protected,
> +  /** \brief Symbol seen by the linker and acts like a normal symbol. */
> +  CXVisibility_Default,
> +};
> +
> +CINDEX_LINKAGE enum CXVisibilityKind clang_getCursorVisibility(CXCursor
> cursor);
> +
> +/**
>   * \brief Determine the availability of the entity that this cursor
> refers to,
>   * taking the current target platform into account.
>   *
>
> Added: cfe/trunk/test/Index/symbol-visibility.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/symbol-visibility.c?rev=253909&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Index/symbol-visibility.c (added)
> +++ cfe/trunk/test/Index/symbol-visibility.c Mon Nov 23 13:56:46 2015
> @@ -0,0 +1,7 @@
> +// RUN: c-index-test -test-print-visibility %s | FileCheck %s
> +
> +__attribute__ ((visibility ("default"))) void foo1();
> +__attribute__ ((visibility ("hidden"))) void foo2();
> +
> +// CHECK: FunctionDecl=foo1:3:47visibility=Default
> +// CHECK: FunctionDecl=foo2:4:46visibility=Hidden
>
> 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=253909&r1=253908&r2=253909&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/c-index-test/c-index-test.c (original)
> +++ cfe/trunk/tools/c-index-test/c-index-test.c Mon Nov 23 13:56:46 2015
> @@ -1248,6 +1248,32 @@ static enum CXChildVisitResult PrintLink
>  }
>
>
>  /******************************************************************************/
> +/* Visibility testing.
>     */
>
> +/******************************************************************************/
> +
> +static enum CXChildVisitResult PrintVisibility(CXCursor cursor, CXCursor
> p,
> +                                               CXClientData d) {
> +  const char *visibility = 0;
> +
> +  if (clang_isInvalid(clang_getCursorKind(cursor)))
> +    return CXChildVisit_Recurse;
> +
> +  switch (clang_getCursorVisibility(cursor)) {
> +    case CXVisibility_Invalid: break;
> +    case CXVisibility_Hidden: visibility = "Hidden"; break;
> +    case CXVisibility_Protected: visibility = "Protected"; break;
> +    case CXVisibility_Default: visibility = "Default"; break;
> +  }
> +
> +  if (visibility) {
> +    PrintCursor(cursor, NULL);
> +    printf("visibility=%s\n", visibility);
> +  }
> +
> +  return CXChildVisit_Recurse;
> +}
> +
>
> +/******************************************************************************/
>  /* Typekind testing.
>     */
>
>  /******************************************************************************/
>
> @@ -4084,6 +4110,7 @@ static void print_usage(void) {
>      "       c-index-test -test-inclusion-stack-tu <AST file>\n");
>    fprintf(stderr,
>      "       c-index-test -test-print-linkage-source {<args>}*\n"
> +    "       c-index-test -test-print-visibility {<args>}*\n"
>      "       c-index-test -test-print-type {<args>}*\n"
>      "       c-index-test -test-print-type-size {<args>}*\n"
>      "       c-index-test -test-print-bitwidth {<args>}*\n"
> @@ -4171,6 +4198,9 @@ int cindextest_main(int argc, const char
>    else if (argc > 2 && strcmp(argv[1], "-test-print-linkage-source") == 0)
>      return perform_test_load_source(argc - 2, argv + 2, "all",
> PrintLinkage,
>                                      NULL);
> +  else if (argc > 2 && strcmp(argv[1], "-test-print-visibility") == 0)
> +    return perform_test_load_source(argc - 2, argv + 2, "all",
> PrintVisibility,
> +                                    NULL);
>    else if (argc > 2 && strcmp(argv[1], "-test-print-type") == 0)
>      return perform_test_load_source(argc - 2, argv + 2, "all",
>                                      PrintType, 0);
>
> Modified: cfe/trunk/tools/libclang/CIndex.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=253909&r1=253908&r2=253909&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/libclang/CIndex.cpp (original)
> +++ cfe/trunk/tools/libclang/CIndex.cpp Mon Nov 23 13:56:46 2015
> @@ -6451,6 +6451,27 @@ CXLinkageKind clang_getCursorLinkage(CXC
>  } // end: extern "C"
>
>
>  //===----------------------------------------------------------------------===//
> +// Operations for querying visibility of a cursor.
>
> +//===----------------------------------------------------------------------===//
> +
> +extern "C" {
> +CXVisibilityKind clang_getCursorVisibility(CXCursor cursor) {
> +  if (!clang_isDeclaration(cursor.kind))
> +    return CXVisibility_Invalid;
> +
> +  const Decl *D = cxcursor::getCursorDecl(cursor);
> +  if (const NamedDecl *ND = dyn_cast_or_null<NamedDecl>(D))
> +    switch (ND->getVisibility()) {
> +      case HiddenVisibility: return CXVisibility_Hidden;
> +      case ProtectedVisibility: return CXVisibility_Protected;
> +      case DefaultVisibility: return CXVisibility_Default;
> +    };
> +
> +  return CXVisibility_Invalid;
> +}
> +} // end: extern "C"
> +
>
> +//===----------------------------------------------------------------------===//
>  // Operations for querying language of a cursor.
>
>  //===----------------------------------------------------------------------===//
>
>
> Modified: cfe/trunk/tools/libclang/libclang.exports
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=253909&r1=253908&r2=253909&view=diff
>
> ==============================================================================
> --- cfe/trunk/tools/libclang/libclang.exports (original)
> +++ cfe/trunk/tools/libclang/libclang.exports Mon Nov 23 13:56:46 2015
> @@ -176,6 +176,7 @@ clang_getCursorSemanticParent
>  clang_getCursorSpelling
>  clang_getCursorType
>  clang_getCursorUSR
> +clang_getCursorVisibility
>  clang_getDeclObjCTypeEncoding
>  clang_getDefinitionSpellingAndExtent
>  clang_getDiagnostic
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160531/dfe7ad93/attachment-0001.html>


More information about the cfe-commits mailing list