Skip to content

Commit

Permalink
[opt] Fix sanitizer complaints about r254774
Browse files Browse the repository at this point in the history
`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.

llvm-svn: 254804
  • Loading branch information
Keno committed Dec 5, 2015
1 parent 000f77d commit 38707c4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions llvm/tools/opt/opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,14 +595,16 @@ int main(int argc, char **argv) {
SmallVector<char, 0> Buffer;
SmallVector<char, 0> CompileTwiceBuffer;
std::unique_ptr<raw_svector_ostream> BOS;
raw_ostream *OS = &Out->os();
if (RunTwice) {
BOS = make_unique<raw_svector_ostream>(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<raw_svector_ostream>(Buffer);
OS = BOS.get();
}
if (OutputAssembly)
Passes.add(createPrintModulePass(*OS, "", PreserveAssemblyUseListOrder));
else
Expand All @@ -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<Module> M2(CloneModule(M.get()));
Expand Down

0 comments on commit 38707c4

Please sign in to comment.