https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86840
Bug ID: 86840 Summary: __attribute__((optimize("exceptions"))) is silently ignored Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: vries at gcc dot gnu.org Target Milestone: --- Consider test.c: ... void a (void); void do_cleanup (void *p); void #ifdef E __attribute__((optimize("exceptions"))) #endif b (void) { int c __attribute__((cleanup(do_cleanup))); a(); } ... When enabling exceptions, an exception table is generated: ... $ gcc test.c -o- -S -O2 -fexceptions | grep -c "\.gcc_except_table" 2 ... And when disabling exceptions, it's not: ... $ gcc test.c -o- -S -O2 -fno-exceptions | grep -c "\.gcc_except_table" 0 ... When enabling exceptions using the attribute on function b, no exception table is generated: ... $ gcc test.c -o- -S -O2 -fno-exceptions -DE | grep -c "\.gcc_except_table" 0 ... This should have a warning "attribute ignored", and/or document this more clearly in the documentation of fexceptions and/or the optimize attribute.