Skip to content

Commit 344612e

Browse files
nawalcoptyurnathan
authored andcommitted
Fix for build fail in LibclcRemangler.cpp because of undeclared identifier initializeOutputBuffer
* [demangler] Simplify OutputBuffer initialization Every non-testcase use of OutputBuffer contains code to allocate an initial buffer (using either 128 or 1024 as initial guesses). There's now no need to do that, given recent changes to the buffer extension heuristics -- it allocates a 1k(ish) buffer on first need. Just pass in a buffer (if any) to the constructor. Thus the OutputBuffer's ownership of the buffer starts at its own lifetime start. We can reduce the lifetime of this object in several cases. That new constructor takes a 'size_t *' for the size argument, as all uses with a non-null buffer are passing through a malloc'd buffer from their own caller in this manner. The buffer reset member function is never used, and is deleted. Some adjustment to a couple of uses is needed, due to the lazy buffer creation of this patch. a) the Microsoft demangler can demangle empty strings to nothing, which it then memoizes. We need to avoid the UB of passing nullptr to memcpy. b) a unit test checks insertion of no characters into an empty buffer. We need to avoid UB when converting that to std::string. The original buffer initialization code would return a failure code if that first malloc failed. Existing code either ignored that, called std::terminate with a FIXME, or returned an error code. But that's not foolproof anyway, as a subsequent buffer extension failure ends up calling std::terminate. I am working on addressing that unfortunate failure mode in a manner more consistent with the C++ ABI design. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D122604 Co-authored-by: Nathan Sidwell <[email protected]>
1 parent 43c51e8 commit 344612e

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

libclc/utils/libclc-remangler/LibclcRemangler.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ class Remangler {
175175
bool Failed = false;
176176

177177
void printNode(const Node *node, OutputBuffer &nodeOutBuffer) {
178-
initializeOutputBuffer(nullptr, nullptr, nodeOutBuffer, 1024);
179178
node->print(nodeOutBuffer);
180179
}
181180

@@ -258,7 +257,6 @@ class Remangler {
258257
}
259258
default: {
260259
OutputBuffer errorTypeOut;
261-
initializeOutputBuffer(nullptr, nullptr, errorTypeOut, 1024);
262260
errorTypeOut << "Unhandled name : ";
263261
nameNode->print(errorTypeOut);
264262
errorTypeOut << "\n";
@@ -429,7 +427,6 @@ class Remangler {
429427
}
430428
default: {
431429
OutputBuffer errorTypeOut;
432-
initializeOutputBuffer(nullptr, nullptr, errorTypeOut, 1024);
433430
errorTypeOut << "Unhandled type : ";
434431
typeNode->print(errorTypeOut);
435432
errorTypeOut << "\n";
@@ -469,7 +466,6 @@ class Remangler {
469466
std::string remangle() {
470467
Subs.clear();
471468
OutputBuffer remanglingStream;
472-
initializeOutputBuffer(nullptr, nullptr, remanglingStream, 1024);
473469
remangleOpenCLCFunction(Root, remanglingStream);
474470
std::string remangled = std::string(remanglingStream.getBuffer(),
475471
remanglingStream.getCurrentPosition());

0 commit comments

Comments
 (0)