1 //===- DynamicExtent.h - Dynamic extent 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 extent information.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICEXTENT_H
14 #define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICEXTENT_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 /// \returns The stored dynamic extent for the region \p MR.
26 DefinedOrUnknownSVal getDynamicExtent(ProgramStateRef State,
27                                       const MemRegion *MR, SValBuilder &SVB);
28 
29 /// \returns The element extent of the type \p Ty.
30 DefinedOrUnknownSVal getElementExtent(QualType Ty, SValBuilder &SVB);
31 
32 /// \returns The stored element count of the region \p MR.
33 DefinedOrUnknownSVal getDynamicElementCount(ProgramStateRef State,
34                                             const MemRegion *MR,
35                                             SValBuilder &SVB, QualType Ty);
36 
37 /// Set the dynamic extent \p Extent of the region \p MR.
38 ProgramStateRef setDynamicExtent(ProgramStateRef State, const MemRegion *MR,
39                                  DefinedOrUnknownSVal Extent, SValBuilder &SVB);
40 
41 /// Get the dynamic extent for a symbolic value that represents a buffer. If
42 /// there is an offsetting to the underlying buffer we consider that too.
43 /// Returns with an SVal that represents the extent, this is Unknown if the
44 /// engine cannot deduce the extent.
45 /// E.g.
46 ///   char buf[3];
47 ///   (buf); // extent is 3
48 ///   (buf + 1); // extent is 2
49 ///   (buf + 3); // extent is 0
50 ///   (buf + 4); // extent is -1
51 ///
52 ///   char *bufptr;
53 ///   (bufptr) // extent is unknown
54 SVal getDynamicExtentWithOffset(ProgramStateRef State, SVal BufV);
55 
56 /// \returns The stored element count of the region represented by a symbolic
57 /// value \p BufV.
58 DefinedOrUnknownSVal getDynamicElementCountWithOffset(ProgramStateRef State,
59                                                       SVal BufV, QualType Ty);
60 
61 } // namespace ento
62 } // namespace clang
63 
64 #endif // LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_DYNAMICEXTENT_H
65