|
1 |
| -//=--PointerArithmeticAssignment.h--------------------------------*- C++-*-===// |
| 1 | +//=--LowerBoundAssignment.h---------------------------------------*- C++-*-===// |
2 | 2 | //
|
3 | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
4 | 4 | // See https://llvm.org/LICENSE.txt for license information.
|
|
8 | 8 | // Contains classes for detection and rewriting of assignment expression that
|
9 | 9 | // would invalidate the bounds of pointers rewritten to use range bounds.
|
10 | 10 | // For pointers using a range bound `bounds(__3c_tmp_p, __3c_tmp_p + n)`, an
|
11 |
| -// assignment `p = q` effectively changes the "base pointer" of the range |
| 11 | +// assignment `p = q` effectively changes the lower bound of the range |
12 | 12 | // bounds, so that the new bounds of `p` are `bounds(q, q + n)`
|
13 | 13 | // (assuming `q` has the same size as `p`). For this to not invalidate the
|
14 | 14 | // bound, `__3c_tmp_p` must also be updated to be equal to `q`.
|
15 | 15 | //===----------------------------------------------------------------------===//
|
16 | 16 |
|
17 |
| -#ifndef LLVM_BASEPOINTERASSIGNMENT_H |
18 |
| -#define LLVM_BASEPOINTERASSIGNMENT_H |
| 17 | +#ifndef LLVM_LOWERBOUNDASSIGNMENT_H |
| 18 | +#define LLVM_LOWERBOUNDASSIGNMENT_H |
19 | 19 |
|
20 | 20 | #include "clang/AST/Decl.h"
|
21 | 21 | #include "clang/AST/Stmt.h"
|
|
24 | 24 | // Return true if an assignment LHS=RHS is the value of RHS is not derived form
|
25 | 25 | // LHS. For example, an assignment `p = q` will return true (we assume `q`
|
26 | 26 | // doesn't alias `p`), while `p = p + 1` will return false.
|
27 |
| -bool isBasePointerAssignment(clang::Expr *LHS, clang::Expr *RHS); |
| 27 | +bool isLowerBoundAssignment(clang::Expr *LHS, clang::Expr *RHS); |
28 | 28 |
|
29 |
| -// A class to visit all base pointer assignment expression as detected by |
30 |
| -// isBasePointerAssignment. This class should be extended with |
31 |
| -// visitBasePointerAssignment overridden. |
32 |
| -class BasePointerAssignmentVisitor |
33 |
| - : public RecursiveASTVisitor<BasePointerAssignmentVisitor> { |
| 29 | +// A class to visit all lower bound assignment expression as detected by |
| 30 | +// isLowerBoundAssignment. This class should be extended with |
| 31 | +// visitLowerBoundAssignment overridden. |
| 32 | +class LowerBoundAssignmentVisitor |
| 33 | + : public RecursiveASTVisitor<LowerBoundAssignmentVisitor> { |
34 | 34 | public:
|
35 |
| - explicit BasePointerAssignmentVisitor() {} |
| 35 | + explicit LowerBoundAssignmentVisitor() {} |
36 | 36 |
|
37 | 37 | bool VisitBinaryOperator(BinaryOperator *O);
|
38 | 38 |
|
39 | 39 | // Override this method to define the operation that should be performed on
|
40 | 40 | // each assignment. The LHS and RHS of the assignment expression are passed
|
41 | 41 | // through.
|
42 |
| - virtual void visitBasePointerAssignment(Expr *LHS, Expr *RHS) = 0; |
| 42 | + virtual void visitLowerBoundAssignment(Expr *LHS, Expr *RHS) = 0; |
43 | 43 | };
|
44 | 44 |
|
45 |
| -// Visit each base pointer assignment expression and, if the LHS is a pointer |
| 45 | +// Visit each lower bound pointer expression and, if the LHS is a pointer |
46 | 46 | // variable that was rewritten to use range bounds, rewrite the assignment so
|
47 | 47 | // that it doesn't not invalidate the bounds. e.g.:
|
48 | 48 | // q = p;
|
49 | 49 | // becomes
|
50 | 50 | // __3c_tmp_q = p, q = __3c_tmp_q;
|
51 |
| -class BasePointerAssignmentUpdater : public BasePointerAssignmentVisitor { |
| 51 | +class LowerBoundAssignmentUpdater : public LowerBoundAssignmentVisitor { |
52 | 52 | public:
|
53 |
| - explicit BasePointerAssignmentUpdater(ASTContext *C, ProgramInfo &I, |
54 |
| - Rewriter &R) : ABInfo( |
| 53 | + explicit LowerBoundAssignmentUpdater(ASTContext *C, ProgramInfo &I, |
| 54 | + Rewriter &R) : ABInfo( |
55 | 55 | I.getABoundsInfo()), CR(I, C), R(R) {}
|
56 | 56 |
|
57 |
| - void visitBasePointerAssignment(Expr *LHS, Expr *RHS) override; |
| 57 | + void visitLowerBoundAssignment(Expr *LHS, Expr *RHS) override; |
58 | 58 |
|
59 | 59 | private:
|
60 | 60 | AVarBoundsInfo &ABInfo;
|
61 | 61 | ConstraintResolver CR;
|
62 | 62 | Rewriter &R;
|
63 | 63 | };
|
64 | 64 |
|
65 |
| -// Visit each base pointer assignment expression and, if it is inside a macro, |
| 65 | +// Visit each lower bound assignment expression and, if it is inside a macro, |
66 | 66 | // mark the LHS pointer as ineligible for range bounds. This is required
|
67 | 67 | // because, if the pointer is given range bounds, then the assignment expression
|
68 | 68 | // would need to be rewritten. The expression is a macro, so it cannot be
|
69 | 69 | // rewritten.
|
70 |
| -class BasePointerAssignmentFinder : public BasePointerAssignmentVisitor { |
| 70 | +class LowerBoundAssignmentFinder : public LowerBoundAssignmentVisitor { |
71 | 71 | public:
|
72 |
| - explicit BasePointerAssignmentFinder(ASTContext *C, ProgramInfo &I) : ABInfo( |
| 72 | + explicit LowerBoundAssignmentFinder(ASTContext *C, ProgramInfo &I) : ABInfo( |
73 | 73 | I.getABoundsInfo()), CR(I, C), C(C) {}
|
74 | 74 |
|
75 |
| - void visitBasePointerAssignment(Expr *LHS, Expr *RHS) override; |
| 75 | + void visitLowerBoundAssignment(Expr *LHS, Expr *RHS) override; |
76 | 76 |
|
77 | 77 | private:
|
78 | 78 | AVarBoundsInfo &ABInfo;
|
79 | 79 | ConstraintResolver CR;
|
80 | 80 | ASTContext *C;
|
81 | 81 | };
|
82 |
| -#endif //LLVM_BASEPOINTERASSIGNMENT_H |
| 82 | +#endif //LLVM_LOWERBOUNDASSIGNMENT_H |
0 commit comments