From 01181948363149ee36a5381b9d5f597e1b85c125 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Sun, 19 Apr 2020 21:32:33 -0700 Subject: [PATCH] llvm-dwarfdump: Fix UB (unsequenced writes) introduced in e0fd87cc64d5 Unsequenced write due to "x &= f()" where 'f()' modifies 'x'. Detected by the llvm-clang-x86_64-expensive-checks-win buildbot. Investigated/identified by Galina - thanks! --- tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 31de753e7a1..9cae4dc3d5b 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -506,7 +506,8 @@ static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer, if (filterArch(*Obj)) { std::unique_ptr DICtx = DWARFContext::create(*Obj, nullptr, "", RecoverableErrorHandler); - Result &= HandleObj(*Obj, *DICtx, Filename, OS); + if (!HandleObj(*Obj, *DICtx, Filename, OS)) + Result = false; } } else if (auto *Fat = dyn_cast(BinOrErr->get())) @@ -518,14 +519,16 @@ static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer, if (filterArch(Obj)) { std::unique_ptr DICtx = DWARFContext::create(Obj, nullptr, "", RecoverableErrorHandler); - Result &= HandleObj(Obj, *DICtx, ObjName, OS); + if (!HandleObj(Obj, *DICtx, ObjName, OS)) + Result = false; } continue; } else consumeError(MachOOrErr.takeError()); if (auto ArchiveOrErr = ObjForArch.getAsArchive()) { error(ObjName, errorToErrorCode(ArchiveOrErr.takeError())); - Result &= handleArchive(ObjName, *ArchiveOrErr.get(), HandleObj, OS); + if (!handleArchive(ObjName, *ArchiveOrErr.get(), HandleObj, OS)) + Result = false; continue; } else consumeError(ArchiveOrErr.takeError());