Support defining attributes at a scope level. I'd like to request implementing the feature of defining attributes at a scope level. For example, allow a syntax such as the following, possibly as a GNU extension:
if (something) __attribute__ ((section("bar"))) { /* body of if-statement */ } ...which will place the body of the if-statement in a separate memory region. The motivation behind this request is the need to place uncommonly used code in a separate memory region for better cache locality. For example, given a piece of C code such as the following: if (something) { /* body */ } ... we need to place the entire body in a separate memory region. 1 -- Attempting to use extended inline assembly to implement this is problematic since the general assumption is that outbound/inbound branches are not allowed in inline assembly. As Jim Wilson also notes, using Labels as values (e.g. &&label) confuses the CFG, effectively disabling some optimizations, which means that performance may be lost when doing this (http://lists.gnu.org/archive/html/bug-binutils/2007-04/msg00120.html). Additionally, trying to do things behind the compilers back (in inline assembly) will not work in the long-term. 2 -- Using the section attribute to place an entire function in a separate region is also unsuitable. For example a definition such as: extern void foobar (void) __attribute__ ((section ("bar"))); puts the entire function `foobar' in the `bar' section, not just the body of an if statement inside the function. Additionally, putting the body of the if-statement in a separate function and defining that function to be in a separate section is not adequate. If the body of the if-statement contains return instructions or gotos to other parts of the function, won't permit returning to the function caller or other parts of the original function (http://gcc.gnu.org/ml/gcc-help/2007-04/msg00282.html). Discussions about this topic are listed in: http://gcc.gnu.org/ml/gcc-help/2007-04/msg00250.html http://lists.gnu.org/archive/html/bug-binutils/2007-04/msg00107.html -- Summary: Support defining attributes at a scope level Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mkgnu at mkgnu dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31689