[llvm] r254804 - [opt] Fix sanitizer complaints about r254774
Keno Fischer via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 4 16:06:37 PST 2015
Author: kfischer
Date: Fri Dec 4 18:06:37 2015
New Revision: 254804
URL: http://llvm.org/viewvc/llvm-project?rev=254804&view=rev
Log:
[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.
Modified:
llvm/trunk/tools/opt/opt.cpp
Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=254804&r1=254803&r2=254804&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Fri Dec 4 18:06:37 2015
@@ -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
@@ -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()));
More information about the llvm-commits
mailing list