Skip to content

Commit aab187c

Browse files
Rename "BasePointer" -> "LowerBound"
1 parent 533e1ca commit aab187c

File tree

6 files changed

+41
-41
lines changed

6 files changed

+41
-41
lines changed
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//=--PointerArithmeticAssignment.h--------------------------------*- C++-*-===//
1+
//=--LowerBoundAssignment.h---------------------------------------*- C++-*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -8,14 +8,14 @@
88
// Contains classes for detection and rewriting of assignment expression that
99
// would invalidate the bounds of pointers rewritten to use range bounds.
1010
// 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
1212
// bounds, so that the new bounds of `p` are `bounds(q, q + n)`
1313
// (assuming `q` has the same size as `p`). For this to not invalidate the
1414
// bound, `__3c_tmp_p` must also be updated to be equal to `q`.
1515
//===----------------------------------------------------------------------===//
1616

17-
#ifndef LLVM_BASEPOINTERASSIGNMENT_H
18-
#define LLVM_BASEPOINTERASSIGNMENT_H
17+
#ifndef LLVM_LOWERBOUNDASSIGNMENT_H
18+
#define LLVM_LOWERBOUNDASSIGNMENT_H
1919

2020
#include "clang/AST/Decl.h"
2121
#include "clang/AST/Stmt.h"
@@ -24,59 +24,59 @@
2424
// Return true if an assignment LHS=RHS is the value of RHS is not derived form
2525
// LHS. For example, an assignment `p = q` will return true (we assume `q`
2626
// 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);
2828

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> {
3434
public:
35-
explicit BasePointerAssignmentVisitor() {}
35+
explicit LowerBoundAssignmentVisitor() {}
3636

3737
bool VisitBinaryOperator(BinaryOperator *O);
3838

3939
// Override this method to define the operation that should be performed on
4040
// each assignment. The LHS and RHS of the assignment expression are passed
4141
// through.
42-
virtual void visitBasePointerAssignment(Expr *LHS, Expr *RHS) = 0;
42+
virtual void visitLowerBoundAssignment(Expr *LHS, Expr *RHS) = 0;
4343
};
4444

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
4646
// variable that was rewritten to use range bounds, rewrite the assignment so
4747
// that it doesn't not invalidate the bounds. e.g.:
4848
// q = p;
4949
// becomes
5050
// __3c_tmp_q = p, q = __3c_tmp_q;
51-
class BasePointerAssignmentUpdater : public BasePointerAssignmentVisitor {
51+
class LowerBoundAssignmentUpdater : public LowerBoundAssignmentVisitor {
5252
public:
53-
explicit BasePointerAssignmentUpdater(ASTContext *C, ProgramInfo &I,
54-
Rewriter &R) : ABInfo(
53+
explicit LowerBoundAssignmentUpdater(ASTContext *C, ProgramInfo &I,
54+
Rewriter &R) : ABInfo(
5555
I.getABoundsInfo()), CR(I, C), R(R) {}
5656

57-
void visitBasePointerAssignment(Expr *LHS, Expr *RHS) override;
57+
void visitLowerBoundAssignment(Expr *LHS, Expr *RHS) override;
5858

5959
private:
6060
AVarBoundsInfo &ABInfo;
6161
ConstraintResolver CR;
6262
Rewriter &R;
6363
};
6464

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,
6666
// mark the LHS pointer as ineligible for range bounds. This is required
6767
// because, if the pointer is given range bounds, then the assignment expression
6868
// would need to be rewritten. The expression is a macro, so it cannot be
6969
// rewritten.
70-
class BasePointerAssignmentFinder : public BasePointerAssignmentVisitor {
70+
class LowerBoundAssignmentFinder : public LowerBoundAssignmentVisitor {
7171
public:
72-
explicit BasePointerAssignmentFinder(ASTContext *C, ProgramInfo &I) : ABInfo(
72+
explicit LowerBoundAssignmentFinder(ASTContext *C, ProgramInfo &I) : ABInfo(
7373
I.getABoundsInfo()), CR(I, C), C(C) {}
7474

75-
void visitBasePointerAssignment(Expr *LHS, Expr *RHS) override;
75+
void visitLowerBoundAssignment(Expr *LHS, Expr *RHS) override;
7676

7777
private:
7878
AVarBoundsInfo &ABInfo;
7979
ConstraintResolver CR;
8080
ASTContext *C;
8181
};
82-
#endif //LLVM_BASEPOINTERASSIGNMENT_H
82+
#endif //LLVM_LOWERBOUNDASSIGNMENT_H

clang/lib/3C/AVarBoundsInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "clang/3C/ProgramInfo.h"
1616
#include "clang/3C/3CGlobalOptions.h"
1717
#include <sstream>
18-
#include <clang/3C/BasePointerAssignment.h>
18+
#include <clang/3C/LowerBoundAssignment.h>
1919

2020
std::vector<BoundsPriority> AVarBoundsInfo::PrioList{Declared, Allocator,
2121
FlowInferred, Heuristics};
@@ -1197,7 +1197,7 @@ bool AVarBoundsInfo::addAssignment(BoundsKey L, BoundsKey R) {
11971197
bool AVarBoundsInfo::handlePointerAssignment(clang::Expr *L, clang::Expr *R,
11981198
ASTContext *C,
11991199
ConstraintResolver *CR) {
1200-
if (!isBasePointerAssignment(L, R))
1200+
if (!isLowerBoundAssignment(L, R))
12011201
recordArithmeticOperation(L, CR);
12021202
return true;
12031203
}

clang/lib/3C/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ add_clang_library(clang3C
3030
AVarBoundsInfo.cpp
3131
AVarGraph.cpp
3232
ArrayBoundsInferenceConsumer.cpp
33-
BasePointerAssignment.cpp
33+
LowerBoundAssignment.cpp
3434
CastPlacement.cpp
3535
3C.cpp
3636
3CInteractiveData.cpp

clang/lib/3C/ConstraintBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//===----------------------------------------------------------------------===//
1111

1212
#include "clang/3C/ConstraintBuilder.h"
13-
#include "clang/3C/BasePointerAssignment.h"
13+
#include "clang/3C/LowerBoundAssignment.h"
1414
#include "clang/3C/3CGlobalOptions.h"
1515
#include "clang/3C/3CStats.h"
1616
#include "clang/3C/ArrayBoundsInferenceConsumer.h"
@@ -472,7 +472,7 @@ void VariableAdderConsumer::HandleTranslationUnit(ASTContext &C) {
472472
}
473473

474474
VariableAdderVisitor VAV = VariableAdderVisitor(&C, Info);
475-
BasePointerAssignmentFinder BPF = BasePointerAssignmentFinder(&C, Info);
475+
LowerBoundAssignmentFinder BPF = LowerBoundAssignmentFinder(&C, Info);
476476
TranslationUnitDecl *TUD = C.getTranslationUnitDecl();
477477
// Collect Variables.
478478
for (const auto &D : TUD->decls()) {

clang/lib/3C/BasePointerAssignment.cpp renamed to clang/lib/3C/LowerBoundAssignment.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
//=--PointerArithmeticAssignment.cpp------------------------------*- C++-*-===//
1+
//=--LowerBoundAssignment.cpp-------------------------------------*- C++-*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8-
// Implementation of methods in PointerArithmeticAssignment.h
8+
// Implementation of methods in LowerBoundAssignment.h
99
//===----------------------------------------------------------------------===//
1010

1111
#include "clang/3C/ProgramInfo.h"
1212
#include "clang/AST/ASTContext.h"
1313

1414
#include "clang/Rewrite/Core/Rewriter.h"
15-
#include "clang/3C/BasePointerAssignment.h"
15+
#include "clang/3C/LowerBoundAssignment.h"
1616
#include "clang/3C/RewriteUtils.h"
1717

1818
using namespace llvm;
@@ -78,7 +78,7 @@ class CollectDeclsVisitor : public RecursiveASTVisitor<CollectDeclsVisitor> {
7878
std::set<StructAccess> ObservedStructAccesses;
7979
};
8080

81-
bool isBasePointerAssignment(Expr *LHS, Expr *RHS) {
81+
bool isLowerBoundAssignment(Expr *LHS, Expr *RHS) {
8282
CollectDeclsVisitor LVarVis;
8383
LVarVis.TraverseStmt(LHS);
8484

@@ -93,21 +93,21 @@ bool isBasePointerAssignment(Expr *LHS, Expr *RHS) {
9393
RVarVis.getObservedStructAccesses(), CommonStVars);
9494

9595
// If CommonVars is empty, then the same pointer does not appears on the LHS
96-
// and RHS of the assignment. We say that the assignment is a base pointer
96+
// and RHS of the assignment. We say that the assignment is a lower bound
9797
// update.
9898
return CommonVars.empty() && CommonStVars.empty();
9999
}
100100

101101
bool
102-
BasePointerAssignmentVisitor::VisitBinaryOperator(BinaryOperator *O) {
102+
LowerBoundAssignmentVisitor::VisitBinaryOperator(BinaryOperator *O) {
103103
if (O->getOpcode() == clang::BO_Assign &&
104-
isBasePointerAssignment(O->getLHS(), O->getRHS()))
105-
visitBasePointerAssignment(O->getLHS(), O->getRHS());
104+
isLowerBoundAssignment(O->getLHS(), O->getRHS()))
105+
visitLowerBoundAssignment(O->getLHS(), O->getRHS());
106106
return true;
107107
}
108108

109-
void BasePointerAssignmentUpdater::visitBasePointerAssignment(Expr *LHS,
110-
Expr *RHS) {
109+
void LowerBoundAssignmentUpdater::visitLowerBoundAssignment(Expr *LHS,
110+
Expr *RHS) {
111111
CVarSet LHSCVs = CR.getExprConstraintVarsSet(LHS);
112112
// It is possible for multiple ConstraintVariables to exist on the LHS
113113
// of an assignment expression; e.g., `*(0 ? a : b) = 0`. If this
@@ -134,8 +134,8 @@ void BasePointerAssignmentUpdater::visitBasePointerAssignment(Expr *LHS,
134134
}
135135
}
136136

137-
void BasePointerAssignmentFinder::visitBasePointerAssignment(Expr *LHS,
138-
Expr *RHS) {
137+
void LowerBoundAssignmentFinder::visitLowerBoundAssignment(Expr *LHS,
138+
Expr *RHS) {
139139
SourceLocation RHSEnd =
140140
getLocationAfter(RHS->getEndLoc(), C->getSourceManager(), C->getLangOpts());
141141
SourceLocation LHSLoc = LHS->getExprLoc();

clang/lib/3C/RewriteUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "clang/3C/CastPlacement.h"
1515
#include "clang/3C/CheckedRegions.h"
1616
#include "clang/3C/DeclRewriter.h"
17-
#include "clang/3C/BasePointerAssignment.h"
17+
#include "clang/3C/LowerBoundAssignment.h"
1818
#include "clang/3C/TypeVariableAnalysis.h"
1919
#include "clang/AST/RecursiveASTVisitor.h"
2020
#include "clang/Tooling/Transformer/SourceCode.h"
@@ -700,7 +700,7 @@ void RewriteConsumer::HandleTranslationUnit(ASTContext &Context) {
700700
CastPlacementVisitor ECPV(&Context, Info, R, CLV.getExprsWithCast());
701701
TypeExprRewriter TER(&Context, Info, R);
702702
TypeArgumentAdder TPA(&Context, Info, R);
703-
BasePointerAssignmentUpdater AU(&Context, Info, R);
703+
LowerBoundAssignmentUpdater AU(&Context, Info, R);
704704
TranslationUnitDecl *TUD = Context.getTranslationUnitDecl();
705705
for (const auto &D : TUD->decls()) {
706706
if (_3COpts.AddCheckedRegions) {

0 commit comments

Comments
 (0)