[LLVMdev] how to resolve llvm exception IR?

Duncan Sands baldrick at free.fr
Mon Apr 27 23:16:16 PDT 2009


Hi zhangzw,

...
>     59          %3 = invoke
> %"struct.std::basic_ostream<char,std::char_traits<char> >"*
> @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(%"struct.std::basic_ostream<char,std::char_traits<char>
> >"* @_ZSt4cout, i8* getelementptr ([10 x i8]* @.str, i32 0, i32 0))
>     60                          to label %bb6 unwind label %lpad10
...
> my  question is at line 59  can throw an exception?

I don't know if it can really throw an exception or not.  Presumably it
could run out of memory?  But it's not marked as not throwing any exceptions
("nounwind") so LLVM has to assume that it might.  If LLVM had access to
the definition of @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
then it might be able to prove that it doesn't throw any exceptions, at which
point the invoke would be turned into an ordinary call.  If you know that
this routine cannot throw exceptions, then it can be marked as nothrow in
some the C++ header somewhere (and you should send a patch to the libstdc++
people).  By the way, the reason an invoke is needed here is to ensure that
@__cxa_end_catch() will be called on the original exception before the new
exception is propagated out.

...
>     48          %0 = invoke
> %"struct.std::basic_ostream<char,std::char_traits<char> >"*
> @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(%"struct.std::basic_ostream<char,std::char_traits<char>
> >"* @_ZSt4cout, i8* getelementptr ([14 x i8]* @.str, i32 0, i32 0))
...
> here at line 48 can throw an exception?

Same basic answer.

> my another problem :  are there any different of above two  llmv-ir
> on  handle c++ exception  ?

They should result in the same output when the program is run, assuming
that the exception throwing routine doesn't run out of memory and abort,
in which case you might see a message for the second version but not for
the first.

Ciao,

Duncan.



More information about the llvm-dev mailing list