Skip to content

Commit

Permalink
Merge branch 'master' into master-post-microsoft
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmccutchen-cci committed Dec 4, 2020
2 parents b6146c3 + 9494e6a commit f2e3d1c
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 145 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

9 changes: 5 additions & 4 deletions clang/docs/checkedc/3C/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ here. You must grant the same license on your contribution as the
existing codebase. We do not have a formal contributor license
agreement (CLA) process at this time, but we may set one up and
require you to complete it before we accept your contribution. Also be
aware that we need to keep 5C working, so you may have to wait for us
to address 5C-specific problems arising from your 3C pull request
and/or we may ask you to make specific changes to your pull request to
accommodate 5C's code.
aware that we need to keep 5C ([our proprietary extension of
3C](README.md#what-3c-users-should-know-about-the-development-process))
working, so you may have to wait for us to address 5C-specific
problems arising from your 3C pull request and/or we may ask you to
make specific changes to your pull request to accommodate 5C's code.

## Testing

Expand Down
4 changes: 1 addition & 3 deletions clang/include/clang/3C/AVarBoundsInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,7 @@ class AVarBoundsInfo {
class ContextSensitiveBoundsKeyVisitor
: public RecursiveASTVisitor<ContextSensitiveBoundsKeyVisitor> {
public:
explicit ContextSensitiveBoundsKeyVisitor(ASTContext *C, ProgramInfo &I,
ConstraintResolver *CResolver);
explicit ContextSensitiveBoundsKeyVisitor(ASTContext *C, ProgramInfo &I);

virtual ~ContextSensitiveBoundsKeyVisitor();

Expand All @@ -372,7 +371,6 @@ class ContextSensitiveBoundsKeyVisitor
private:
ASTContext *Context;
ProgramInfo &Info;
ConstraintResolver *CR;
};

#endif // LLVM_CLANG_3C_AVARBOUNDSINFO_H
3 changes: 1 addition & 2 deletions clang/include/clang/3C/RewriteUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,13 @@ class GlobalVariableGroups {
// detected array variables.
class ArrayBoundsRewriter {
public:
ArrayBoundsRewriter(ASTContext *C, ProgramInfo &I) : Context(C), Info(I) {}
ArrayBoundsRewriter(ProgramInfo &I) : Info(I) {}
// Get the string representation of the bounds for the given variable.
std::string getBoundsString(PVConstraint *PV, Decl *D, bool Isitype = false);
// Check if the constraint variable has newly created bounds string.
bool hasNewBoundsString(PVConstraint *PV, Decl *D, bool Isitype = false);

private:
ASTContext *Context;
ProgramInfo &Info;
};

Expand Down
42 changes: 25 additions & 17 deletions clang/include/clang/AST/PreorderAST.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,32 @@

namespace clang {
using Result = Lexicographic::Result;
class OperatorNode;

class Node {
public:
enum class NodeKind { BinaryNode, LeafExprNode };
enum class NodeKind { OperatorNode, LeafExprNode };

NodeKind Kind;
Node *Parent;
OperatorNode *Parent;

Node(NodeKind Kind, Node *Parent) :
Node(NodeKind Kind, OperatorNode *Parent) :
Kind(Kind), Parent(Parent) {}
};

class BinaryNode : public Node {
class OperatorNode : public Node {
public:
BinaryOperator::Opcode Opc;
// Note: An OperatorNode has a list of children because the preorder AST is
// an n-ary tree.
llvm::SmallVector<Node *, 2> Children;

BinaryNode(BinaryOperator::Opcode Opc, Node *Parent) :
Node(NodeKind::BinaryNode, Parent),
OperatorNode(BinaryOperator::Opcode Opc, OperatorNode *Parent) :
Node(NodeKind::OperatorNode, Parent),
Opc(Opc) {}

static bool classof(const Node *N) {
return N->Kind == NodeKind::BinaryNode;
return N->Kind == NodeKind::OperatorNode;
}

// Is the operator commutative and associative?
Expand All @@ -58,7 +61,7 @@ namespace clang {
public:
Expr *E;

LeafExprNode(Expr *E, Node *Parent) :
LeafExprNode(Expr *E, OperatorNode *Parent) :
Node(NodeKind::LeafExprNode, Parent),
E(E) {}

Expand All @@ -81,27 +84,32 @@ namespace clang {
// Create a PreorderAST for the expression E.
// @param[in] E is the sub expression to be added to a new node.
// @param[in] Parent is the parent of the new node.
void Create(Expr *E, Node *Parent = nullptr);
void Create(Expr *E, OperatorNode *Parent = nullptr);

// Add a new node to the AST.
// @param[in] Node is the current node to be added.
// @param[in] Parent is the parent of the node to be added.
void AddNode(Node *N, Node *Parent);
void AddNode(Node *N, OperatorNode *Parent);

// Move the children (if any) of node N to its parent and then remove N.
// @param[in] N is the current node.
// @param[in] P is the parent of the node to be removed. P should be a
// BinaryNode.
void RemoveNode(Node *N, Node *P);
// Coalesce the OperatorNode O with its parent. This involves moving the
// children (if any) of node O to its parent and then removing O.
// @param[in] O is the current node. O should be a OperatorNode.
void CoalesceNode(OperatorNode *O);

// Recursively coalesce binary nodes having the same commutative and
// Determines if a OperatorNode could be coalesced into its parent.
// @param[in] O is the current node. O should be a OperatorNode.
// @return Return true if O can be coalesced into its parent, false
// otherwise.
bool CanCoalesceNode(OperatorNode *O);

// Recursively coalesce OperatoreNodes having the same commutative and
// associative operator.
// @param[in] N is current node of the AST. Initial value is Root.
// @param[in] Changed indicates whether a node was coalesced. We need this
// to control when to stop recursive coalescing.
void Coalesce(Node *N, bool &Changed);

// Sort the children expressions in a binary node of the AST.
// Sort the children expressions in a OperatorNode of the AST.
// @param[in] N is current node of the AST. Initial value is Root.
void Sort(Node *N);

Expand Down
5 changes: 2 additions & 3 deletions clang/lib/3C/AVarBoundsInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,6 @@ bool AvarBoundsInference::inferBounds(BoundsKey K, AVarGraph &BKGraph,
std::set<BoundsKey> PotentialB;
PotentialB.clear();
for (auto TK : PotBDs[K]) {
ProgramVar *TKVar = BI->getProgramVar(TK);
getReachableBoundKeys(Kvar->getScope(), TK, PotentialB, BKGraph,
true);
}
Expand Down Expand Up @@ -1333,8 +1332,8 @@ bool AVarBoundsInfo::areSameProgramVar(BoundsKey B1, BoundsKey B2) {
}

ContextSensitiveBoundsKeyVisitor::ContextSensitiveBoundsKeyVisitor(
ASTContext *C, ProgramInfo &I, ConstraintResolver *CResolver)
: Context(C), Info(I), CR(CResolver) {
ASTContext *C, ProgramInfo &I)
: Context(C), Info(I) {
Info.getABoundsInfo().resetContextSensitiveBoundsKey();
}

Expand Down
1 change: 0 additions & 1 deletion clang/lib/3C/ArrayBoundsInferenceConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,6 @@ bool LocalVarABVisitor::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {

bool LocalVarABVisitor::VisitDeclStmt(DeclStmt *S) {
// Build rules based on initializers.
auto &ABoundsInfo = Info.getABoundsInfo();
for (const auto &D : S->decls())
if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
Expr *InitE = VD->getInit();
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/3C/ConstraintBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void ConstraintBuilderConsumer::HandleTranslationUnit(ASTContext &C) {
TypeVarVisitor TV = TypeVarVisitor(&C, Info);
ConstraintResolver CSResolver(Info, &C);
ContextSensitiveBoundsKeyVisitor CSBV =
ContextSensitiveBoundsKeyVisitor(&C, Info, &CSResolver);
ContextSensitiveBoundsKeyVisitor(&C, Info);
ConstraintGenVisitor GV = ConstraintGenVisitor(&C, Info, TV);
TranslationUnitDecl *TUD = C.getTranslationUnitDecl();
// Generate constraints.
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/3C/DeclRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using namespace clang;
void DeclRewriter::rewriteDecls(ASTContext &Context, ProgramInfo &Info,
Rewriter &R) {
// Compute the bounds information for all the array variables.
ArrayBoundsRewriter ABRewriter(&Context, Info);
ArrayBoundsRewriter ABRewriter(Info);

// Collect function and record declarations that need to be rewritten in a set
// as well as their rewriten types in a map.
Expand Down
Loading

0 comments on commit f2e3d1c

Please sign in to comment.