Skip to content

Commit

Permalink
Fix static initialization order fiasco in MCTests
Browse files Browse the repository at this point in the history
Reported by Kostya on llvm-dev, uncovered by an ASAN bot

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286647 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
joker-eph committed Nov 11, 2016
1 parent 823ac75 commit aa2b11d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions unittests/MC/DwarfLineTables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,25 @@ struct Context {
operator MCContext &() { return *Ctx; };
};

Context Ctxt;
Context &getContext() {
static Context Ctxt;
return Ctxt;
}
}

void verifyEncoding(MCDwarfLineTableParams Params, int LineDelta, int AddrDelta,
ArrayRef<uint8_t> ExpectedEncoding) {
SmallString<16> Buffer;
raw_svector_ostream EncodingOS(Buffer);
MCDwarfLineAddr::Encode(Ctxt, Params, LineDelta, AddrDelta, EncodingOS);
MCDwarfLineAddr::Encode(getContext(), Params, LineDelta, AddrDelta,
EncodingOS);
ArrayRef<uint8_t> Encoding(reinterpret_cast<uint8_t *>(Buffer.data()),
Buffer.size());
EXPECT_EQ(ExpectedEncoding, Encoding);
}

TEST(DwarfLineTables, TestDefaultParams) {
if (!Ctxt)
if (!getContext())
return;

MCDwarfLineTableParams Params;
Expand Down Expand Up @@ -110,7 +114,7 @@ TEST(DwarfLineTables, TestDefaultParams) {
}

TEST(DwarfLineTables, TestCustomParams) {
if (!Ctxt)
if (!getContext())
return;

// Some tests against the example values given in the standard.
Expand Down Expand Up @@ -164,7 +168,7 @@ TEST(DwarfLineTables, TestCustomParams) {
}

TEST(DwarfLineTables, TestCustomParams2) {
if (!Ctxt)
if (!getContext())
return;

// Corner case param values.
Expand Down

0 comments on commit aa2b11d

Please sign in to comment.