Skip to content

[llvm] annotate interfaces in Demangle for DLL export #147564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion libcxxabi/src/demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "DemangleConfig.h"
#include "StringViewExtras.h"
#include "Utility.h"
#include "Visibility.h"
#include <algorithm>
#include <cctype>
#include <cstdint>
Expand Down Expand Up @@ -3049,7 +3050,8 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
Node *parse(bool ParseParams = true);
};

const char* parse_discriminator(const char* first, const char* last);
DEMANGLE_ABI const char *parse_discriminator(const char *first,
const char *last);

// <name> ::= <nested-name> // N
// ::= <local-name> # See Scope Encoding below // Z
Expand Down
18 changes: 18 additions & 0 deletions libcxxabi/src/demangle/Visibility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===--- Visibility.h -------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// This file is contains noop definitions of the DEMANGLE_ABI macro defined in
// llvm/include/llvm/Demangle/Visibility.h.
//===----------------------------------------------------------------------===//

#ifndef LIBCXXABI_DEMANGLE_VISIBILITY_H
#define LIBCXXABI_DEMANGLE_VISIBILITY_H

// The DEMANGLE_ABI macro resovles to nothing when building libcxxabi. Only
// the llvm copy defines DEMANGLE_ABI as a visibility attribute.
#define DEMANGLE_ABI

#endif
5 changes: 3 additions & 2 deletions libcxxabi/src/demangle/cp-to-llvm.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

# Copies the 'demangle' library, excluding 'DemangleConfig.h', to llvm. If no
# llvm directory is specified, then assume a monorepo layout.
# Copies the 'demangle' library, excluding 'DemangleConfig.h' and
# 'Visibility.h', to llvm. If no llvm directory is specified, then assume a
# monorepo layout.

set -e

Expand Down
59 changes: 32 additions & 27 deletions llvm/include/llvm/Demangle/Demangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#ifndef LLVM_DEMANGLE_DEMANGLE_H
#define LLVM_DEMANGLE_DEMANGLE_H

#include "Visibility.h"
#include <cstddef>
#include <optional>
#include <string>
Expand All @@ -33,7 +34,8 @@ enum : int {
/// Returns a non-NULL pointer to a NUL-terminated C style string
/// that should be explicitly freed, if successful. Otherwise, may return
/// nullptr if mangled_name is not a valid mangling or is nullptr.
char *itaniumDemangle(std::string_view mangled_name, bool ParseParams = true);
DEMANGLE_ABI char *itaniumDemangle(std::string_view mangled_name,
bool ParseParams = true);

enum MSDemangleFlags {
MSDF_None = 0,
Expand All @@ -52,87 +54,90 @@ enum MSDemangleFlags {
/// bytes of the input string were consumed.
/// status receives one of the demangle_ enum entries above if it's not nullptr.
/// Flags controls various details of the demangled representation.
char *microsoftDemangle(std::string_view mangled_name, size_t *n_read,
int *status, MSDemangleFlags Flags = MSDF_None);
DEMANGLE_ABI char *microsoftDemangle(std::string_view mangled_name,
size_t *n_read, int *status,
MSDemangleFlags Flags = MSDF_None);

std::optional<size_t>
DEMANGLE_ABI std::optional<size_t>
getArm64ECInsertionPointInMangledName(std::string_view MangledName);

// Demangles a Rust v0 mangled symbol.
char *rustDemangle(std::string_view MangledName);
DEMANGLE_ABI char *rustDemangle(std::string_view MangledName);

// Demangles a D mangled symbol.
char *dlangDemangle(std::string_view MangledName);
DEMANGLE_ABI char *dlangDemangle(std::string_view MangledName);

/// Attempt to demangle a string using different demangling schemes.
/// The function uses heuristics to determine which demangling scheme to use.
/// \param MangledName - reference to string to demangle.
/// \returns - the demangled string, or a copy of the input string if no
/// demangling occurred.
std::string demangle(std::string_view MangledName);
DEMANGLE_ABI std::string demangle(std::string_view MangledName);

bool nonMicrosoftDemangle(std::string_view MangledName, std::string &Result,
bool CanHaveLeadingDot = true,
bool ParseParams = true);
DEMANGLE_ABI bool nonMicrosoftDemangle(std::string_view MangledName,
std::string &Result,
bool CanHaveLeadingDot = true,
bool ParseParams = true);

/// "Partial" demangler. This supports demangling a string into an AST
/// (typically an intermediate stage in itaniumDemangle) and querying certain
/// properties or partially printing the demangled name.
struct ItaniumPartialDemangler {
ItaniumPartialDemangler();
DEMANGLE_ABI ItaniumPartialDemangler();

ItaniumPartialDemangler(ItaniumPartialDemangler &&Other);
ItaniumPartialDemangler &operator=(ItaniumPartialDemangler &&Other);
DEMANGLE_ABI ItaniumPartialDemangler(ItaniumPartialDemangler &&Other);
DEMANGLE_ABI ItaniumPartialDemangler &
operator=(ItaniumPartialDemangler &&Other);

/// Demangle into an AST. Subsequent calls to the rest of the member functions
/// implicitly operate on the AST this produces.
/// \return true on error, false otherwise
bool partialDemangle(const char *MangledName);
DEMANGLE_ABI bool partialDemangle(const char *MangledName);

/// Just print the entire mangled name into Buf. Buf and N behave like the
/// second and third parameters to __cxa_demangle.
char *finishDemangle(char *Buf, size_t *N) const;
DEMANGLE_ABI char *finishDemangle(char *Buf, size_t *N) const;

/// See \ref finishDemangle
///
/// \param[in] OB A llvm::itanium_demangle::OutputBuffer that the demangled
/// name will be printed into.
///
char *finishDemangle(void *OB) const;
DEMANGLE_ABI char *finishDemangle(void *OB) const;

/// Get the base name of a function. This doesn't include trailing template
/// arguments, ie for "a::b<int>" this function returns "b".
char *getFunctionBaseName(char *Buf, size_t *N) const;
DEMANGLE_ABI char *getFunctionBaseName(char *Buf, size_t *N) const;

/// Get the context name for a function. For "a::b::c", this function returns
/// "a::b".
char *getFunctionDeclContextName(char *Buf, size_t *N) const;
DEMANGLE_ABI char *getFunctionDeclContextName(char *Buf, size_t *N) const;

/// Get the entire name of this function.
char *getFunctionName(char *Buf, size_t *N) const;
DEMANGLE_ABI char *getFunctionName(char *Buf, size_t *N) const;

/// Get the parameters for this function.
char *getFunctionParameters(char *Buf, size_t *N) const;
char *getFunctionReturnType(char *Buf, size_t *N) const;
DEMANGLE_ABI char *getFunctionParameters(char *Buf, size_t *N) const;
DEMANGLE_ABI char *getFunctionReturnType(char *Buf, size_t *N) const;

/// If this function has any cv or reference qualifiers. These imply that
/// the function is a non-static member function.
bool hasFunctionQualifiers() const;
DEMANGLE_ABI bool hasFunctionQualifiers() const;

/// If this symbol describes a constructor or destructor.
bool isCtorOrDtor() const;
DEMANGLE_ABI bool isCtorOrDtor() const;

/// If this symbol describes a function.
bool isFunction() const;
DEMANGLE_ABI bool isFunction() const;

/// If this symbol describes a variable.
bool isData() const;
DEMANGLE_ABI bool isData() const;

/// If this symbol is a <special-name>. These are generally implicitly
/// generated by the implementation, such as vtables and typeinfo names.
bool isSpecialName() const;
DEMANGLE_ABI bool isSpecialName() const;

~ItaniumPartialDemangler();
DEMANGLE_ABI ~ItaniumPartialDemangler();

private:
void *RootNode;
Expand Down
4 changes: 3 additions & 1 deletion llvm/include/llvm/Demangle/ItaniumDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "DemangleConfig.h"
#include "StringViewExtras.h"
#include "Utility.h"
#include "Visibility.h"
#include <algorithm>
#include <cctype>
#include <cstdint>
Expand Down Expand Up @@ -3049,7 +3050,8 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
Node *parse(bool ParseParams = true);
};

const char* parse_discriminator(const char* first, const char* last);
DEMANGLE_ABI const char *parse_discriminator(const char *first,
const char *last);

// <name> ::= <nested-name> // N
// ::= <local-name> # See Scope Encoding below // Z
Expand Down
7 changes: 4 additions & 3 deletions llvm/include/llvm/Demangle/MicrosoftDemangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "llvm/Demangle/Demangle.h"
#include "llvm/Demangle/MicrosoftDemangleNodes.h"
#include "llvm/Demangle/Visibility.h"

#include <cassert>
#include <string_view>
Expand Down Expand Up @@ -151,14 +152,14 @@ class Demangler {

// You are supposed to call parse() first and then check if error is true. If
// it is false, call output() to write the formatted name to the given stream.
SymbolNode *parse(std::string_view &MangledName);
DEMANGLE_ABI SymbolNode *parse(std::string_view &MangledName);

TagTypeNode *parseTagUniqueName(std::string_view &MangledName);
DEMANGLE_ABI TagTypeNode *parseTagUniqueName(std::string_view &MangledName);

// True if an error occurred.
bool Error = false;

void dumpBackReferences();
DEMANGLE_ABI void dumpBackReferences();

private:
SymbolNode *demangleEncodedSymbol(std::string_view &MangledName,
Expand Down
Loading