From: Keno Fischer Date: Sat, 5 Dec 2015 00:06:37 +0000 (+0000) Subject: [opt] Fix sanitizer complaints about r254774 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=357108cbea3d64a0f31b931121d4a381ee6c1a3b;p=oota-llvm.git [opt] Fix sanitizer complaints about r254774 `Out` can be null if no output is requested, so move any access to it inside the conditional. Thanks to Justin Bogner for finding this. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254804 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index c1510a7fb25..fc31beb4815 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -595,14 +595,16 @@ int main(int argc, char **argv) { SmallVector Buffer; SmallVector CompileTwiceBuffer; std::unique_ptr BOS; - raw_ostream *OS = &Out->os(); - if (RunTwice) { - BOS = make_unique(Buffer); - OS = BOS.get(); - } + raw_ostream *OS = nullptr; // Write bitcode or assembly to the output as the last step... if (!NoOutput && !AnalyzeOnly) { + assert(Out); + OS = &Out->os(); + if (RunTwice) { + BOS = make_unique(Buffer); + OS = BOS.get(); + } if (OutputAssembly) Passes.add(createPrintModulePass(*OS, "", PreserveAssemblyUseListOrder)); else @@ -618,6 +620,7 @@ int main(int argc, char **argv) { // If requested, run all passes again with the same pass manager to catch // bugs caused by persistent state in the passes if (RunTwice) { + assert(Out); CompileTwiceBuffer = Buffer; Buffer.clear(); std::unique_ptr M2(CloneModule(M.get()));