Issue 131440
Summary code deduplication in case of throw
Labels new issue
Assignees
Reporter fekir
    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?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to