<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/131440>131440</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
code deduplication in case of throw
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
fekir
</td>
</tr>
</table>
<pre>
Consider following snippet
~~~~
struct myclass{
myclass(int i);
};
#ifdef THROWIT
[[noreturn]] __attribute__((noinline)) void throwit(int i){
throw myclass(i);
}
#define THROW(p) throwit(p);
#else
#define THROW(p) throw myclass(p);
#endif
void foo(){
THROW(41);
}
void bar(int j){
THROW(j);
}
~~~~
https://godbolt.org/z/oeqoqqhh1
When writing `throw` directly, "a lot" of code is generated in the body of `bar` and `foo` which is identical, which in turn generates a bigger binary.
When wrapping the `throw` in a non-`inline` function, this duplication does not happen, and since throwing is not cheap (`__cxa_allocate_exception` allocates), the cost of having a non-inline function should be negligible.
Does clang have any option (or chance) for avoiding to wrap all "throw" in functions to reduce the size of the binary?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyElMFu4zgMhp9GuRBTyHLiJAcf0hbB7mmBxQBzDGSJttlVJVeSm8kc-uwLKp42LRZYIEASifz5kfxtnRINHrEVm3uxeVzpOY8htj3-Q3HVBXtpH4JPZDFCH5wLZ_IDJE_ThFnIg5CHt7e3NyEPKcfZZHi-GKdTEtt7IQ8A8H6gduQzkFB7UfOd2D4uP-RBqJp6iz18_-Pvv378-Z2PGOfeh4h5jl5sHsXmEU4nnXOkbs54Ogm1E2rnA3lHHllX7eE1kIU8xnCmfFvyHafc3UJ9AiooFnvyeGURajex7ofk9JGganQJ_yfpptbnVG-pX9qXh8Ldh1CausH9rbeuvnJ-pHU6Lq0-_Wfu05fUZWHXz5jzlER9EOoo1HEItgsu34U4CHX8JdQx4Et4eRnH6hr-Y0QP50iZbSAaWVoUjQRLEU12F6EeQCilwYUslILQgwkWgRIM6DHqjBbIQx4R2F4cIBrJPTQStLf8jwfRSDiPZEbOJIs-k9GO1ZdTD2yMd9EEGjoaBozQkdfxcvcJWE8TE3PVW2ryoMEH_000cvFRI6GfvckUPFfLIyWw8-TIaD4DGzCBDxlGPU1YYpg6kTe42MQPDM0xZkQ9AS-1kaeT-alP2rlgdMYT_jQ4lSrc93Kaio0fCqcJKfN0Rv3KilfOK-Q7IaQxzM5Ch-BxcDRQ53Dp_JFBjdN-YAkE7S8QSkUGChHMqL3hBwf6EEGzl8qMQpkXM_Emr7NSimf1u2zioIh2Li0jJPqFjFqWWqYv6uPKtrXd13u9wrbarpVUzWa7X41tVdnO2L6vUK_tdqfXttYbo2xdo1FWdytqlVQbWVcbuauaan-H0ta7qq522-1GdpURa4nPmtydc6_PbNYVpTRjW9XVei1XTnfoUnmjKeXxDOVWKMUvuNhy0rduHpJYS0cppw-ZTNlhWwxr8Xbr5MHotDQZw3k1R9d-eXYoj3N3Z8KzUEdWXL6-TTE8oclCHQtHEuq4gL626t8AAAD__5igvrs">