[clang] [CFG] Add a BuildOption to consider default branch of switch on covered enumerations. (PR #161345)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 2 00:40:16 PDT 2025


================
@@ -1251,6 +1251,7 @@ class CFG {
     bool MarkElidedCXXConstructors = false;
     bool AddVirtualBaseBranches = false;
     bool OmitImplicitValueInitializers = false;
+    bool SwitchKeepDefaultCoveredEnum = false;
----------------
steakhal wrote:

I know we don't really have a good track record of documentation but I think the wording of this new flag opens op the door for ambiguity. For example, reading `Switch` might come across as a verb, (like it did for me when I read this first).

A comment would resolve this ambiguity. By judging the previous flags, it seems like similar options end with the word `Branch`.

BTW would the new behavior make the `default:` branches reachable regardless if the enum is `covered` or not?
1) If the switch wasnt fully covered then the `default` case would be trivially reachable.
2) If the switch was fully covered then this option would make the default branch artificially reachable.

Consequently, the behavior is the same, regardless if the switch fully covers the enum of not: the default branch is considered reachable. I suppose, this bogged me a bit when I read the name of this option. Maybe something like `AssumeReachableDefaultCaseInSwitchStatements`.

https://github.com/llvm/llvm-project/pull/161345


More information about the cfe-commits mailing list