[LLVMbugs] [Bug 7961] New: Need to recognize when switch cases cover all possible enum values

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Aug 21 19:00:10 PDT 2010


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

           Summary: Need to recognize when switch cases cover all possible
                    enum values
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: dkcat8p2ay at snkmail.com
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=5399)
 --> (http://llvm.org/bugs/attachment.cgi?id=5399)
Simplified test case demonstrating reported issue

When cases in a switch statement over an enum condition cover all possible enum
values, the analyzer may still incorrectly conclude "'Default' branch taken."
within the switch statement.  This was tested against current trunk (r111702).

When built with "scan-build gcc -Wall -o clang_1 clang_1.c", the attached test
case is found to have an "Undefined or garbage value returned to caller" bug. 
As the switch cases cover all possible enum values, the variable ret is always
assigned a value before func() returns.

Although my C++-foo is definitely showing its age, I have found the section in
Sema::ActOnFinishSwitchStmt() that claims to "Check to see if switch is over an
Enum and handles all of its values."  Is it possible to extend that analysis to
avoid the bug found in the attached program?

-- 
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