[PATCH] D55765: Fix use-after-free bug in Tooling.
Alexander Kornienko via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 8 08:59:55 PST 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL350638: Fix use-after-free bug in Tooling. (authored by alexfh, committed by ).
Herald added a subscriber: llvm-commits.
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D55765/new/
https://reviews.llvm.org/D55765
Files:
cfe/trunk/include/clang/Tooling/Tooling.h
cfe/trunk/lib/Tooling/Tooling.cpp
cfe/trunk/unittests/Analysis/ExprMutationAnalyzerTest.cpp
Index: cfe/trunk/lib/Tooling/Tooling.cpp
===================================================================
--- cfe/trunk/lib/Tooling/Tooling.cpp
+++ cfe/trunk/lib/Tooling/Tooling.cpp
@@ -574,20 +574,16 @@
namespace tooling {
std::unique_ptr<ASTUnit>
-buildASTFromCode(const Twine &Code, const Twine &FileName,
+buildASTFromCode(StringRef Code, StringRef FileName,
std::shared_ptr<PCHContainerOperations> PCHContainerOps) {
return buildASTFromCodeWithArgs(Code, std::vector<std::string>(), FileName,
"clang-tool", std::move(PCHContainerOps));
}
std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
- const Twine &Code, const std::vector<std::string> &Args,
- const Twine &FileName, const Twine &ToolName,
- std::shared_ptr<PCHContainerOperations> PCHContainerOps,
+ StringRef Code, const std::vector<std::string> &Args, StringRef FileName,
+ StringRef ToolName, std::shared_ptr<PCHContainerOperations> PCHContainerOps,
ArgumentsAdjuster Adjuster) {
- SmallString<16> FileNameStorage;
- StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage);
-
std::vector<std::unique_ptr<ASTUnit>> ASTs;
ASTBuilderAction Action(ASTs);
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem(
@@ -599,13 +595,11 @@
new FileManager(FileSystemOptions(), OverlayFileSystem));
ToolInvocation Invocation(
- getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileNameRef), FileNameRef),
+ getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileName), FileName),
&Action, Files.get(), std::move(PCHContainerOps));
- SmallString<1024> CodeStorage;
- InMemoryFileSystem->addFile(FileNameRef, 0,
- llvm::MemoryBuffer::getMemBuffer(
- Code.toNullTerminatedStringRef(CodeStorage)));
+ InMemoryFileSystem->addFile(FileName, 0,
+ llvm::MemoryBuffer::getMemBufferCopy(Code));
if (!Invocation.run())
return nullptr;
Index: cfe/trunk/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===================================================================
--- cfe/trunk/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ cfe/trunk/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -11,6 +11,7 @@
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/SmallString.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <cctype>
@@ -32,7 +33,9 @@
std::unique_ptr<ASTUnit>
buildASTFromCodeWithArgs(const Twine &Code,
const std::vector<std::string> &Args) {
- auto AST = tooling::buildASTFromCodeWithArgs(Code, Args);
+ SmallString<1024> CodeStorage;
+ auto AST =
+ tooling::buildASTFromCodeWithArgs(Code.toStringRef(CodeStorage), Args);
EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
return AST;
}
Index: cfe/trunk/include/clang/Tooling/Tooling.h
===================================================================
--- cfe/trunk/include/clang/Tooling/Tooling.h
+++ cfe/trunk/include/clang/Tooling/Tooling.h
@@ -205,7 +205,7 @@
///
/// \return The resulting AST or null if an error occurred.
std::unique_ptr<ASTUnit>
-buildASTFromCode(const Twine &Code, const Twine &FileName = "input.cc",
+buildASTFromCode(StringRef Code, StringRef FileName = "input.cc",
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
std::make_shared<PCHContainerOperations>());
@@ -223,10 +223,10 @@
///
/// \return The resulting AST or null if an error occurred.
std::unique_ptr<ASTUnit> buildASTFromCodeWithArgs(
- const Twine &Code, const std::vector<std::string> &Args,
- const Twine &FileName = "input.cc", const Twine &ToolName = "clang-tool",
+ StringRef Code, const std::vector<std::string> &Args,
+ StringRef FileName = "input.cc", StringRef ToolName = "clang-tool",
std::shared_ptr<PCHContainerOperations> PCHContainerOps =
- std::make_shared<PCHContainerOperations>(),
+ std::make_shared<PCHContainerOperations>(),
ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster());
/// Utility to run a FrontendAction in a single clang invocation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55765.180685.patch
Type: text/x-patch
Size: 4299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190108/0dbaa3e2/attachment.bin>
More information about the llvm-commits
mailing list