Skip to content

Commit

Permalink
[analyzer][NFC] Use switch statement in MallocChecker::performKernelM…
Browse files Browse the repository at this point in the history
…alloc

Reviewed By: steakhal

Differential Revision: https://reviews.llvm.org/D159397
  • Loading branch information
brad0 committed Sep 5, 2023
1 parent 1362206 commit 0a73e1e
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0a73e1e

Please sign in to comment.