diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -1141,22 +1141,28 @@ 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