From f96e83c486210495dca27580b20abf476627c291 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 4 Feb 2018 14:33:34 -0500 Subject: [PATCH] fuzz_with_unicorn: Move instruction generator vector into GenRandomInst Keeps scope localized and prevents potential static initialization issues. --- tests/A64/fuzz_with_unicorn.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/A64/fuzz_with_unicorn.cpp b/tests/A64/fuzz_with_unicorn.cpp index 5ed54109..15157351 100644 --- a/tests/A64/fuzz_with_unicorn.cpp +++ b/tests/A64/fuzz_with_unicorn.cpp @@ -31,31 +31,31 @@ static Vector RandomVector() { return {RandInt(0, ~u64(0)), RandInt(0, ~u64(0))}; } -static std::vector instruction_generators = []{ - const std::vector> list { +static u32 GenRandomInst(u64 pc, bool is_last_inst) { + static const std::vector instruction_generators = []{ + const std::vector> list { #define INST(fn, name, bitstring) {#fn, bitstring}, #include "frontend/A64/decoder/a64.inc" #undef INST - }; + }; - std::vector result; + std::vector result; - for (const auto& [fn, bitstring] : list) { - if (std::strcmp(fn, "UnallocatedEncoding") == 0) { - InstructionGenerator::AddInvalidInstruction(bitstring); - continue; + for (const auto& [fn, bitstring] : list) { + if (std::strcmp(fn, "UnallocatedEncoding") == 0) { + InstructionGenerator::AddInvalidInstruction(bitstring); + continue; + } + result.emplace_back(InstructionGenerator{bitstring}); } - result.emplace_back(InstructionGenerator{bitstring}); - } - // Manually added exceptions: - // FMOV_float_imm for half-precision floats (QEMU doesn't have half-precision support yet). - InstructionGenerator::AddInvalidInstruction("00011110111iiiiiiii10000000ddddd"); + // Manually added exceptions: + // FMOV_float_imm for half-precision floats (QEMU doesn't have half-precision support yet). + InstructionGenerator::AddInvalidInstruction("00011110111iiiiiiii10000000ddddd"); - return result; -}(); + return result; + }(); -static u32 GenRandomInst(u64 pc, bool is_last_inst) { const A64::LocationDescriptor location{pc, {}}; restart: