[Bug c++/119292] New: code deduplication in case of throw (improvement)
federico at kircheis dot it
gcc-bugzilla@gcc.gnu.org
Fri Mar 14 14:05:33 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119292
Bug ID: 119292
Summary: code deduplication in case of throw (improvement)
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: federico at kircheis dot it
Target Milestone: ---
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/ja1azahe4
When writing "throw" directly, "a lot" of code is generated in the body of bar
and foo which is identical, which in turn generate 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 small.
Does GCC have any option (or chance) for avoiding to wrap all "throw" in
functions to reduce the size of the binary?
More information about the Gcc-bugs
mailing list