Skip to content

Commit

Permalink
Make initializeOutputStream() return false on error and true on success.
Browse files Browse the repository at this point in the history
As discussed in https://reviews.llvm.org/D52104

Differential Revision: https://reviews.llvm.org/D52143

llvm-svn: 346606
  • Loading branch information
nico committed Nov 11, 2018
1 parent 2eab39f commit 6808bc0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions llvm/include/llvm/Demangle/Utility.h
Expand Up @@ -175,13 +175,13 @@ inline bool initializeOutputStream(char *Buf, size_t *N, OutputStream &S,
if (Buf == nullptr) {
Buf = static_cast<char *>(std::malloc(InitSize));
if (Buf == nullptr)
return true;
return false;
BufferSize = InitSize;
} else
BufferSize = *N;

S.reset(Buf, BufferSize);
return false;
return true;
}

#endif
10 changes: 5 additions & 5 deletions llvm/lib/Demangle/ItaniumDemangle.cpp
Expand Up @@ -340,7 +340,7 @@ char *llvm::itaniumDemangle(const char *MangledName, char *Buf,

if (AST == nullptr)
InternalStatus = demangle_invalid_mangled_name;
else if (initializeOutputStream(Buf, N, S, 1024))
else if (!initializeOutputStream(Buf, N, S, 1024))
InternalStatus = demangle_memory_alloc_failure;
else {
assert(Parser.ForwardTemplateRefs.empty());
Expand Down Expand Up @@ -396,7 +396,7 @@ bool ItaniumPartialDemangler::partialDemangle(const char *MangledName) {

static char *printNode(const Node *RootNode, char *Buf, size_t *N) {
OutputStream S;
if (initializeOutputStream(Buf, N, S, 128))
if (!initializeOutputStream(Buf, N, S, 128))
return nullptr;
RootNode->print(S);
S += '\0';
Expand Down Expand Up @@ -441,7 +441,7 @@ char *ItaniumPartialDemangler::getFunctionDeclContextName(char *Buf,
const Node *Name = static_cast<const FunctionEncoding *>(RootNode)->getName();

OutputStream S;
if (initializeOutputStream(Buf, N, S, 128))
if (!initializeOutputStream(Buf, N, S, 128))
return nullptr;

KeepGoingLocalFunction:
Expand Down Expand Up @@ -494,7 +494,7 @@ char *ItaniumPartialDemangler::getFunctionParameters(char *Buf,
NodeArray Params = static_cast<FunctionEncoding *>(RootNode)->getParams();

OutputStream S;
if (initializeOutputStream(Buf, N, S, 128))
if (!initializeOutputStream(Buf, N, S, 128))
return nullptr;

S += '(';
Expand All @@ -512,7 +512,7 @@ char *ItaniumPartialDemangler::getFunctionReturnType(
return nullptr;

OutputStream S;
if (initializeOutputStream(Buf, N, S, 128))
if (!initializeOutputStream(Buf, N, S, 128))
return nullptr;

if (const Node *Ret =
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Demangle/MicrosoftDemangle.cpp
Expand Up @@ -874,7 +874,7 @@ void Demangler::memorizeIdentifier(IdentifierNode *Identifier) {
// Render this class template name into a string buffer so that we can
// memorize it for the purpose of back-referencing.
OutputStream OS;
if (initializeOutputStream(nullptr, nullptr, OS, 1024))
if (!initializeOutputStream(nullptr, nullptr, OS, 1024))
// FIXME: Propagate out-of-memory as an error?
std::terminate();
Identifier->output(OS, OF_Default);
Expand Down Expand Up @@ -1207,7 +1207,7 @@ Demangler::demangleStringLiteral(StringView &MangledName) {
if (MangledName.empty())
goto StringLiteralError;

if (initializeOutputStream(nullptr, nullptr, OS, 1024))
if (!initializeOutputStream(nullptr, nullptr, OS, 1024))
// FIXME: Propagate out-of-memory as an error?
std::terminate();
if (IsWcharT) {
Expand Down Expand Up @@ -1330,7 +1330,7 @@ Demangler::demangleLocallyScopedNamePiece(StringView &MangledName) {

// Render the parent symbol's name into a buffer.
OutputStream OS;
if (initializeOutputStream(nullptr, nullptr, OS, 1024))
if (!initializeOutputStream(nullptr, nullptr, OS, 1024))
// FIXME: Propagate out-of-memory as an error?
std::terminate();
OS << '`';
Expand Down Expand Up @@ -2156,7 +2156,7 @@ void Demangler::dumpBackReferences() {

// Create an output stream so we can render each type.
OutputStream OS;
if (initializeOutputStream(nullptr, nullptr, OS, 1024))
if (!initializeOutputStream(nullptr, nullptr, OS, 1024))
std::terminate();
for (size_t I = 0; I < Backrefs.FunctionParamCount; ++I) {
OS.setCurrentPosition(0);
Expand Down Expand Up @@ -2194,7 +2194,7 @@ char *llvm::microsoftDemangle(const char *MangledName, char *Buf, size_t *N,

if (D.Error)
InternalStatus = demangle_invalid_mangled_name;
else if (initializeOutputStream(Buf, N, S, 1024))
else if (!initializeOutputStream(Buf, N, S, 1024))
InternalStatus = demangle_memory_alloc_failure;
else {
AST->output(S, OF_Default);
Expand Down

0 comments on commit 6808bc0

Please sign in to comment.