https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59856
--- Comment #9 from Josh Triplett <josh at joshtriplett dot org> --- (In reply to Tom Tromey from comment #6) > (In reply to Josh Triplett from comment #4) > > Unfortunate, and I'd love to see GCC handle trailing attributes (does a bug > > already exist for that somewhere?), but not something that should block > > *this* > > feature. > > Offhand I don't know if there is a bug covering this. Filed as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68524 . > > Sparse actually tracks context as a property of basic blocks. > > I was thinking this might be doable but I don't really know how > gcc handles basic block coalescing -- if two blocks are merged > we'd want to ensure that the resulting block ends up with the > correct context property. Right; this would need specific handling when manipulating basic blocks. > It might help to see exactly where __context__ is used in real code. A few patterns: First, you can use __context__(some_lock, 1, 1) to assert that you hold some_lock. Second, you can use __context__(some_lock, 0, 1) to note that you have acquired some_lock; that may make sense within the definition of a lock acquisition function, since the function's declaration will have a context attribute saying it returns with the lock held, and the body needs to match that. It also makes sense in the body of a lock acquisition macro. Third, ditto for __context__(some_lock, 1, 0) and lock release functions. And fourth, see the definition of __cond_lock: # define __acquire(x) __context__(x,1) # define __release(x) __context__(x,-1) # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0) You can then define a wrapper for a trylock function: #define trylock(l) __cond_lock(l, trylock(l)) If you then use this in an if, the compiler can know that one path has a different context than the other: /* l has context 0 */ if (trylock(l)) { /* l has context 1 */ } else { /* l still has context 0 */ } > > (if > > they ship it at all; AFAICT Debian only ships gcc-python3-plugin). > > The version of python doesn't matter much. > > For people whose distro doesn't package gcc-python-plugin, it is simple > to build; just git clone + make. Sparse requires exactly the same, but even that level of difficulty means a tiny fraction of people building kernels actually use it. Integrating it with GCC means it could work automatically for everyone.