This repository was archived by the owner on Jul 1, 2025. It is now read-only.
Replace std::to_string with operator<<(llvm::raw_ostream&)#208
Merged
goldsborough merged 3 commits intopytorch:masterfrom Jan 2, 2018
Merged
Replace std::to_string with operator<<(llvm::raw_ostream&)#208goldsborough merged 3 commits intopytorch:masterfrom
goldsborough merged 3 commits intopytorch:masterfrom
Conversation
Contributor
|
The changes look good to me. Please run M.dumpDAG() and G.dumpDAG() and M.dump() and G.dump() and make sure that things work. |
nadavrot
approved these changes
Jan 2, 2018
5a48270 to
90b53e1
Compare
Contributor
Author
|
Tested the graph and IR dump and found a bug which I fixed. Generated dot graphs are now identical again so the patch is safe (hopefully). |
Contributor
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes #180 by replacing our overloads of
std::to_string, which is UB, with correspondingllvm::raw_ostream& operator<<(llvm::raw_ostream&, <thing>)overloads.This was less trivial than thought, because we were using a mix of
std::ostream,std::stringstreamandllvm::raw_ostreamin the codebase. Furthermore,raw_ostreamcannot output to files, whilestd::ostreamcan, so the replacement wasn't a simple find+replace. I think the best way forward is:operator<<(raw_ostream&),llvm::outs()andllvm::errs()as the stream source,llvm::raw_string_ostreamorllvm::raw_svector_streamand then call its.str()method,raw_ostreamcan't do), do (3) and to output it to astd::ofstream.I think this PR also fixes a bug where we were calling
std::to_stringon a string literal (inexamples/ptb.cpp), which was actually creating a string with the textual representation of the literal's memory address (because of thevoid*overload we had forstd::to_string), rather than constructing a string.I also recommend using one of my favorite LLVM data structures ever, llvm::Twine, for simple string concatenation instead of
std::string::operator+.It's a lot of code, so please do look at it carefully. Also, please tell me what would be a good test to make sure the dotty output for the IR looks good (@artemrakhov)?