On Mon, 2016-07-11 at 22:20 +0200, Marek Polacek wrote: > On Mon, Jul 11, 2016 at 10:11:52PM +0200, Jakub Jelinek wrote: > > On Mon, Jul 11, 2016 at 10:08:02PM +0200, Eric Botcazou wrote: > > > > After I'd completed the warning, I kicked off a bootstrap so as > > > > to add > > > > various gcc_fallthrough calls. There were a good amount of > > > > them, as > > > > expected. I also grepped various FALLTHRU/Falls > > > > through/...fall > > > > thru.../... comments in config/ and added gcc_fallthroughs to > > > > make it > > > > easier for people. Wherever I wasn't sure that the > > > > gcc_fallthrough was > > > > appropriate, I added an 'XXX' comment. This must not be relied > > > > upon as I > > > > don't know most of the compiler code. The same goes for > > > > relevant libraries > > > > where I introduced various gomp_fallthrough macros conditional > > > > on __GNUC__ > > > > (I'd tried to use a configure check but then decided I won't > > > > put up with > > > > all the vagaries of autoconf). > > > > > > Do we really want to clutter up the entire tree like that? The > > > result is > > > particularly ugly IMO. Just add -Wno-switch-fallthrough > > > somewhere I'd say. > > I think that if *we* refuse to use __builtin_fallthrough, then we > can't > expect users to use it. > > > Well, we already have the /* FALLTHRU */ etc. comments in most of > > the > > places. Perhaps if we replace those comments just with > > GCC_FALLTHRU, > > a macro that expands to __builtin_fallthrough (); for GCC >= 7, or > > to [[fallthrough]] for C++17, or nothing? > > IMHO it doesn't make sense to keep both the gomp_fallthrough (); > > macro and > > /* FALLTHROUGH */ etc. comments in the source. > > Yea, that's a possibility, though sometimes the comment explains why > the > fall through is desirable.
Is there no way to use the comment itself, somehow? Looking over the patches you had to do, it looks like using the comments themselves would make it significantly easier for users to use this warning without having to patch their code. Of course this adds the philosophical risk of making the content of the comment be significant, for some meaning of "significant". Brainstorming... how about looking for comments containing the substrings "fall" and either "through" or "thru", case-insensitively? This could be only done if we're about to emit a warning: maybe look through the pertinent lines via the input.c interface? Or maybe have the preprocessor detect such comments during lexing (perhaps if the warning is enabled), and store them somewhere... (maybe a bitmap of source_location values within the line_table, or somesuch, giving the locations of "fallthrough" comments). I appreciate that my suggestions above are kludges, but maybe someone else can think of a cleaner way to do it. Dave