[LLVMdev] Behaviour of outs()?

Jonathan Roelofs jroelofs.lists at gmail.com
Fri Jan 23 11:31:29 PST 2015



On 1/23/15 11:41 AM, mats petersson wrote:
> I'm fairly sure that whether llvm actually uses `outs` or not, it will
> be constructed and destroyed based on it's existance. I will have a
> look at this in more detail, but the general question still remains:
Not quite.

raw_ostream.cpp:
00704 raw_ostream &llvm::outs() {
00705   // Set buffer settings to model stdout behavior.
00706   // Delete the file descriptor when the program exits, forcing error
00707   // detection. If you don't want this behavior, don't use outs().
00708   static raw_fd_ostream S(STDOUT_FILENO, true);
00709   return S;
00710 }

S's constructor is called once (and only once) on the first call to 
llvm::outs(), and then the destructor will get called along with all the 
other globals' around atexit() time. If llvm::outs() doesn't get called, 
then the destructor should never be invoked.


Cheers,

Jon

> _______________________________________________
> 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