[clang] 0a73e1e - [analyzer][NFC] Use switch statement in MallocChecker::performKernelMalloc

Brad Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 4 22:08:25 PDT 2023


Author: Brad Smith
Date: 2023-09-05T01:06:43-04:00
New Revision: 0a73e1eb47ddc87fad51c390b4a8e20019614a08

URL: https://github.com/llvm/llvm-project/commit/0a73e1eb47ddc87fad51c390b4a8e20019614a08
DIFF: https://github.com/llvm/llvm-project/commit/0a73e1eb47ddc87fad51c390b4a8e20019614a08.diff

LOG: [analyzer][NFC] Use switch statement in MallocChecker::performKernelMalloc

Reviewed By: steakhal

Differential Revision: https://reviews.llvm.org/D159397

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index d2b564d022b5d39..18c7f3e4f6e6b92 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -1141,22 +1141,28 @@ MallocChecker::performKernelMalloc(const CallEvent &Call, CheckerContext &C,
   llvm::Triple::OSType OS = Ctx.getTargetInfo().getTriple().getOS();
 
   if (!KernelZeroFlagVal) {
-    if (OS == llvm::Triple::FreeBSD)
+    switch (OS) {
+    case llvm::Triple::FreeBSD:
       KernelZeroFlagVal = 0x0100;
-    else if (OS == llvm::Triple::NetBSD)
+      break;
+    case llvm::Triple::NetBSD:
       KernelZeroFlagVal = 0x0002;
-    else if (OS == llvm::Triple::OpenBSD)
+      break;
+    case llvm::Triple::OpenBSD:
       KernelZeroFlagVal = 0x0008;
-    else if (OS == llvm::Triple::Linux)
+      break;
+    case llvm::Triple::Linux:
       // __GFP_ZERO
       KernelZeroFlagVal = 0x8000;
-    else
+      break;
+    default:
       // FIXME: We need a more general way of getting the M_ZERO value.
       // See also: O_CREAT in UnixAPIChecker.cpp.
 
       // Fall back to normal malloc behavior on platforms where we don't
       // know M_ZERO.
       return std::nullopt;
+    }
   }
 
   // We treat the last argument as the flags argument, and callers fall-back to


        


More information about the cfe-commits mailing list