• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- DynamicSize.h - 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 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICSIZE_H
14 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICSIZE_H
15 
16 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
17 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
18 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
19 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h"
20 #include "clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h"
21 
22 namespace clang {
23 namespace ento {
24 
25 /// Get the stored dynamic size for the region \p MR.
26 DefinedOrUnknownSVal getDynamicSize(ProgramStateRef State, const MemRegion *MR,
27                                     SValBuilder &SVB);
28 
29 /// Get the stored element count of the region \p MR.
30 DefinedOrUnknownSVal getDynamicElementCount(ProgramStateRef State,
31                                             const MemRegion *MR,
32                                             SValBuilder &SVB,
33                                             QualType ElementTy);
34 
35 /// Get the dynamic size for a symbolic value that represents a buffer. If
36 /// there is an offsetting to the underlying buffer we consider that too.
37 /// Returns with an SVal that represents the size, this is Unknown if the
38 /// engine cannot deduce the size.
39 /// E.g.
40 ///   char buf[3];
41 ///   (buf); // size is 3
42 ///   (buf + 1); // size is 2
43 ///   (buf + 3); // size is 0
44 ///   (buf + 4); // size is -1
45 ///
46 ///   char *bufptr;
47 ///   (bufptr) // size is unknown
48 SVal getDynamicSizeWithOffset(ProgramStateRef State, const SVal &BufV);
49 
50 } // namespace ento
51 } // namespace clang
52 
53 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICSIZE_H
54