[llvm-commits] [llvm] r79065 - /llvm/trunk/lib/Support/FormattedStream.cpp
Dan Gohman
gohman at apple.com
Mon Aug 17 09:30:54 PDT 2009
On Aug 17, 2009, at 2:42 AM, Artur Pietrek <pietreka at gmail.com> wrote:
>
>
> On Sat, Aug 15, 2009 at 4:02 AM, Dan Gohman <gohman at apple.com> wrote:
>
> -/// ComputeColumn - Examine the current output and figure out which
> +/// CountColumns - Examine the given char sequence and figure out
> which
> /// column we end up in after output.
> ///
> -void formatted_raw_ostream::ComputeColumn() {
> +static unsigned CountColumns(unsigned Column, const char *Ptr,
> size_t Size) {
> // Keep track of the current column by scanning the string for
> // special characters
>
> - // The buffer may have been allocated underneath us.
> - if (Scanned == 0 && GetNumBytesInBuffer() != 0) {
> - Scanned = begin();
> - }
> -
> - while (Scanned != end()) {
> - ++ColumnScanned;
> - if (*Scanned == '\n' || *Scanned == '\r')
> - ColumnScanned = 0;
> - else if (*Scanned == '\t')
> + for (const char *End = Ptr + Size; Ptr != End; ++Ptr) {
> + ++Column;
> + if (*Ptr == '\n' || *Ptr == '\r')
> + Column = 0;
> + else if (*Ptr == '\t')
> // Assumes tab stop = 8 characters.
> - ColumnScanned += (8 - (ColumnScanned & 0x7)) & 0x7;
> - ++Scanned;
> + Column += (8 - (Column & 0x7)) & 0x7;
> }
> +
> + return Column;
> +}
>
> Hi all,
>
> Is it legal to output Instruction or any Value using formatted
> stream like this:
> Out << *Instr;
Yes, that's fine. Fairly common, in fact.
>
> I was using it to print commented LLVM instructions to my assembly
> to check if I'm translating instructions correctly, but since the
> change above I get segfault after running my backend.
>
> Changing line:
> for (const char *End = Ptr + Size; Ptr != End; ++Ptr) {
>
> to:
> + for (const char *End = Ptr + Size; Ptr < End; ++Ptr) {
>
> helps. Is it bug or I just should not use it that way?
The change shouldn't be necessary. It sounds like there's a bug. Is
Ptr pointing to a valid string when this happens?
Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090817/76ab0a70/attachment.html>
More information about the llvm-commits
mailing list