Skip to content

Bounds context [1/n] #807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Apr 2, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions clang/lib/Sema/SemaBounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,9 @@ namespace {
if (Bounds)
ParamsState.UC[Param] = Bounds;
}

// Store a checking state for each CFG block in order to track
// the variables with bounds declarations that are in scope.
llvm::DenseMap<unsigned int, CheckingState> BlockStates;
BlockStates[Cfg->getEntry().getBlockID()] = ParamsState;

Expand Down Expand Up @@ -2958,8 +2961,9 @@ namespace {
BoundsExpr *B = nullptr;
InteropTypeExpr *IT = nullptr;
if (VD) {
if (State.UC[VD])
B = State.UC[VD];
auto Declared = State.UC.find(VD);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do it this way:

if (State.UC.count(VD))
  B = State.UC[VD];

if (Declared != State.UC.end())
B = (*Declared).second;
else
B = VD->getBoundsExpr();
IT = VD->getInteropTypeExpr();
Expand Down Expand Up @@ -3412,6 +3416,11 @@ namespace {
// GetIncomingBlockState returns the checking state that is true at
// the beginning of the block by taking the intersection of the UC
// contexts that were true after each of the block's predecessors.
//
// BlockStates stores the checking state including the bounds context
// for each CFG block in order to track the variables with bounds
// declarations that are in scope. This preserves lexically scoped
// information that is otherwise lost during CFG traversal.
CheckingState GetIncomingBlockState(const CFGBlock *Block,
llvm::DenseMap<unsigned int, CheckingState> BlockStates) {
CheckingState BlockState;
Expand Down