[LLVMbugs] [Bug 14440] New: Implement __builtin_fallthrough() to suppress false positives from -Wimplicit-fallthrough

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Nov 26 15:00:49 PST 2012


http://llvm.org/bugs/show_bug.cgi?id=14440

             Bug #: 14440
           Summary: Implement __builtin_fallthrough() to suppress false
                    positives from -Wimplicit-fallthrough
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: arthur.j.odwyer at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


See the corresponding GCC bug (filed long ago, my recent comment near the
bottom):
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652

Per this clang-dev mailing-list discussion (which I just unearthed; I didn't
participate):
http://clang-developers.42468.n3.nabble.com/should-Wimplicit-fallthrough-require-C-11-td4028144.html

I think it would be a great idea to implement the builtin function
__builtin_fallthrough(). (It should have exactly that spelling, so that GCC and
Clang receive compatible builtins instead of mutually misspelled ones.)  Then,
either the C++11 attribute [[clang::fallthrough]] should be retired, or else it
should be implemented as a simple call to the builtin.

A call to __builtin_fallthrough() should suppress the warning that would
ordinarily be emitted for the immediately following case label:

    case 1:
        foo();
        __builtin_fallthrough();
    case 2:  /* no warning here, hooray! */

Programmers who don't want to see ugly double-underscores in their code can
"#define FALLS_THROUGH_TO __builtin_fallthrough();" and write

    case 1:
        foo();
    FALLS_THROUGH_TO case 2:  /* hooray! */

Unfortunately I don't have the time or expertise to actually submit a patch for
this, but I've filed the suggestion both here and on GCC's Bugzilla, and I'm
very hopeful that both compilers will eventually implement compatible versions
of this feature. Warning about unintended fallthrough is *VERY* good at
catching bugs, and having a mechanism to eliminate false-positive warnings is
*VERY* important.

(As I said above, I'm aware of [[clang::fallthrough]], but it doesn't work
outside of C++11 mode, and besides that it's not portable to any non-Clang
compiler because it's got the word "clang" hard-coded into it.)

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list