201c4b9cc4
The rust demangler has some odd buffer handling code, which will copy the demangled string into the provided buffer, if it will fit. Otherwise it uses the allocated buffer it made. But the length of the incoming buffer will have come from a previous call, which was the length of the demangled string -- not the buffer size. And of course, we're unconditionally allocating a temporary buffer in the first place. So we don't actually get buffer reuse, and we get a memcpy in somecases. However, nothing in LLVM ever passes in a non-null pointer. Neither does anything pass in a status pointer that is then made use of. The only exercise these have is in the test suite. So let's just make the rust demangler have the same API as the dlang demangler. Reviewed By: tmiasko Differential Revision: https://reviews.llvm.org/D123420
32 lines
904 B
C++
32 lines
904 B
C++
//===------------------ RustDemangleTest.cpp ------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Demangle/Demangle.h"
|
|
#include "gmock/gmock.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
TEST(RustDemangle, Success) {
|
|
char *Demangled = llvm::rustDemangle("_RNvC1a4main");
|
|
EXPECT_STREQ(Demangled, "a::main");
|
|
std::free(Demangled);
|
|
}
|
|
|
|
TEST(RustDemangle, Invalid) {
|
|
char *Demangled = nullptr;
|
|
|
|
// Invalid prefix.
|
|
Demangled = llvm::rustDemangle("_ABCDEF");
|
|
EXPECT_EQ(Demangled, nullptr);
|
|
|
|
// Correct prefix but still invalid.
|
|
Demangled = llvm::rustDemangle("_RRR");
|
|
EXPECT_EQ(Demangled, nullptr);
|
|
}
|