[LLVMdev] Different behavoir when writing to stdout with 2 raw_fd_ostreams with or w/o redirection

Sean Silva silvas at purdue.edu
Thu Nov 29 03:02:46 PST 2012


My guess is that in the second case the timing of the global
destructor of S is messing things up. Just a guess though.

-- Sean Silva

On Thu, Nov 29, 2012 at 1:54 AM, Dmitry N. Mikushin <maemarcus at gmail.com> wrote:
> Dear all,
>
> Consider there is a program that writes to stdout using two different
> raw_fd_ostream-s:
>
> #include "llvm/LLVMContext.h"
> #include "llvm/Module.h"
> #include "llvm/Support/raw_ostream.h"
>
> using namespace llvm;
>
> int main()
> {
>         raw_fd_ostream S(STDOUT_FILENO, false);
>
>         outs() << "Hello";
>         S << ", world!";
>
>         return 0;
> }
>
> With this layout everything is fine, it prints ", world!Hello"
>
> Now, make S definition global:
>
> #include "llvm/LLVMContext.h"
> #include "llvm/Module.h"
> #include "llvm/Support/raw_ostream.h"
>
> using namespace llvm;
>
> raw_fd_ostream S(STDOUT_FILENO, false);
>
> int main()
> {
>         outs() << "Hello";
>         S << ", world!";
>
>         return 0;
> }
>
> And... surprisingly:
>
> $ ./outs
> Hello, world!$ ./outs &>result
> $ cat result
> HelloLLVM ERROR: IO failure on output stream.
>
> So, no error with screen output and error when redirected to file. Why so?
>
> Thanks,
> - D.
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>



More information about the llvm-dev mailing list