Skip to content

Commit

Permalink
Fix use-after-scope introduced in 8503253
Browse files Browse the repository at this point in the history
  • Loading branch information
arichardson committed Oct 27, 2020
1 parent 0d09230 commit 75a1790
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 4 additions & 1 deletion clang/unittests/Format/MacroExpanderTest.cpp
Expand Up @@ -11,6 +11,7 @@ namespace {

class MacroExpanderTest : public ::testing::Test {
public:
MacroExpanderTest() : Lex(Allocator, Buffers) {}
std::unique_ptr<MacroExpander>
create(const std::vector<std::string> &MacroDefinitions) {
return std::make_unique<MacroExpander>(MacroDefinitions,
Expand Down Expand Up @@ -64,7 +65,9 @@ class MacroExpanderTest : public ::testing::Test {
<< Context << " in " << text(Tokens) << " at " << File << ":" << Line;
}
}

protected:
llvm::SpecificBumpPtrAllocator<FormatToken> Allocator;
std::vector<std::unique_ptr<llvm::MemoryBuffer>> Buffers;
TestLexer Lex;
};

Expand Down
18 changes: 10 additions & 8 deletions clang/unittests/Format/TestLexer.h
Expand Up @@ -59,12 +59,15 @@ inline std::string text(llvm::ArrayRef<FormatToken *> Tokens) {

class TestLexer : public UnwrappedLineConsumer {
public:
TestLexer(FormatStyle Style = getLLVMStyle())
: Style(Style), SourceMgr("test.cpp", ""),
IdentTable(getFormattingLangOpts(Style)) {}
TestLexer(llvm::SpecificBumpPtrAllocator<FormatToken> &Allocator,
std::vector<std::unique_ptr<llvm::MemoryBuffer>> &Buffers,
FormatStyle Style = getLLVMStyle())
: Allocator(Allocator), Buffers(Buffers), Style(Style),
SourceMgr("test.cpp", ""), IdentTable(getFormattingLangOpts(Style)) {}

TokenList lex(llvm::StringRef Code) {
auto Result = getNewLexer(Code).lex();
FormatTokenLexer Lex = getNewLexer(Code);
ArrayRef<FormatToken *> Result = Lex.lex();
return TokenList(Result.begin(), Result.end());
}

Expand All @@ -77,6 +80,7 @@ class TestLexer : public UnwrappedLineConsumer {
for (auto &Line : UnwrappedLines) {
AnnotatedLine Annotated(Line);
Annotator.annotate(Annotated);
Annotator.calculateFormattingInformation(Annotated);
}
UnwrappedLines.clear();
return TokenList(Tokens.begin(), Tokens.end());
Expand All @@ -99,18 +103,16 @@ class TestLexer : public UnwrappedLineConsumer {
llvm::MemoryBuffer::getMemBufferCopy(Code, "<scratch space>"));
clang::FileID FID =
SourceMgr.get().createFileID(Buffers.back()->getMemBufferRef());
FormatTokenLexer Lex(SourceMgr.get(), FID, 0, Style, Encoding, Allocator,
IdentTable);
return FormatTokenLexer(SourceMgr.get(), FID, 0, Style, Encoding, Allocator,
IdentTable);
}

public:
llvm::SpecificBumpPtrAllocator<FormatToken>& Allocator;
std::vector<std::unique_ptr<llvm::MemoryBuffer>>& Buffers;
FormatStyle Style;
encoding::Encoding Encoding = encoding::Encoding_UTF8;
std::vector<std::unique_ptr<llvm::MemoryBuffer>> Buffers;
clang::SourceManagerForFile SourceMgr;
llvm::SpecificBumpPtrAllocator<FormatToken> Allocator;
IdentifierTable IdentTable;
SmallVector<UnwrappedLine, 16> UnwrappedLines;
};
Expand Down
4 changes: 3 additions & 1 deletion clang/unittests/Format/TokenAnnotatorTest.cpp
Expand Up @@ -20,8 +20,10 @@ class TokenAnnotatorTest : public ::testing::Test {
protected:
TokenList annotate(llvm::StringRef Code,
const FormatStyle &Style = getLLVMStyle()) {
return TestLexer(Style).annotate(Code);
return TestLexer(Allocator, Buffers, Style).annotate(Code);
}
llvm::SpecificBumpPtrAllocator<FormatToken> Allocator;
std::vector<std::unique_ptr<llvm::MemoryBuffer>> Buffers;
};

#define EXPECT_TOKEN_KIND(FormatTok, Kind) \
Expand Down

0 comments on commit 75a1790

Please sign in to comment.