Coverage Report

Created: 2020-02-25 14:32

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/StaticAnalyzer/Core/DynamicSize.cpp
Line
Count
Source
1
//===- DynamicSize.cpp - Dynamic size related APIs --------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
//  This file defines APIs that track and query dynamic size information.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "clang/StaticAnalyzer/Core/PathSensitive/DynamicSize.h"
14
#include "clang/AST/Expr.h"
15
#include "clang/Basic/LLVM.h"
16
#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
17
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
18
#include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
19
#include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
20
#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
21
22
namespace clang {
23
namespace ento {
24
25
DefinedOrUnknownSVal getDynamicSize(ProgramStateRef State, const MemRegion *MR,
26
4.19k
                                    SValBuilder &SVB) {
27
4.19k
  return MR->getMemRegionManager().getStaticSize(MR, SVB);
28
4.19k
}
29
30
DefinedOrUnknownSVal getDynamicElementCount(ProgramStateRef State,
31
                                            const MemRegion *MR,
32
                                            SValBuilder &SVB,
33
427
                                            QualType ElementTy) {
34
427
  MemRegionManager &MemMgr = MR->getMemRegionManager();
35
427
  ASTContext &Ctx = MemMgr.getContext();
36
427
37
427
  DefinedOrUnknownSVal Size = getDynamicSize(State, MR, SVB);
38
427
  SVal ElementSizeV = SVB.makeIntVal(
39
427
      Ctx.getTypeSizeInChars(ElementTy).getQuantity(), SVB.getArrayIndexType());
40
427
41
427
  SVal DivisionV =
42
427
      SVB.evalBinOp(State, BO_Div, Size, ElementSizeV, SVB.getArrayIndexType());
43
427
44
427
  return DivisionV.castAs<DefinedOrUnknownSVal>();
45
427
}
46
47
} // namespace ento
48
} // namespace clang