`CFGStmtMap::Build` accepts pointers and returns a pointer to
dynamically allocated memory. In the one location where the type is
actually constructed, the pointers are guaranteed to be non-null. By
accepting references to statically enforce this, we can remove the only
way for the construction to fail.
By making this change, we also allow our user to decide how they want to
own the memory (either directly or indirectly). The user does not
actually need dynamic allocation here, so we replace the
`std::unique_ptr` with `std::optional`.
This simplifies the code by requiring fewer checks, makes comments on
what happens redundant because the code can obviously do only one thing,
avoids potential bugs, and improves performance by allocating less.
There is no reason to dynamically allocate `llvm::DenseMap` and try to
hide the type. A header we include anyway already includes `DenseMap.h`
so we save almost no compilation time. This change improves performance
by avoiding the dynamic allocation, and simplifies the code
considerably.
Now that we just have a regular data member, there is also no need for a
manual destructor, and the copy / move operations will do the right
thing.
In `getBlock`, we have some code that a comment claims is implementing
memoization, but in reality it does nothing. The relevant expression is
a conditional `(*SM)[X] = B`, but `B` is equal to `SM->find(X)->second`.
In `Accumulate`, we have a bunch of code to add things to the map for
the initial set-up. However, the original code would either find or
default construct an element, and then if the found element is equal to
the default constructed element it would set it to `B`. Rather than
doing this in two steps, we can simply use `try_emplace` to insert if
it's not already present. This change is sound only if the new element
we are inserting cannot be equal to the default constructed element, but
the element type is a pointer and this entire section of code assumes
`B` is not null.
The mutable version of the overload is not used. The way we implemented
code sharing in the const vs. mutable overloads had a const-correctness
violation, anyway.
Turn it into a variant class instead. This conversion does indeed save some code
but there's a plan to add support for more kinds of terminators that aren't
necessarily based on statements, and with those in mind it becomes more and more
confusing to have CFGTerminators implicitly convertible to a Stmt *.
Differential Revision: https://reviews.llvm.org/D61814
llvm-svn: 361586
to reflect the new license.
We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.
Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.
llvm-svn: 351636
Use Optional<CFG*> where invalid states were needed previously. In the one case
where that's not possible (beginAutomaticObjDtorsInsert) just use a dummy
CFGAutomaticObjDtor.
Thanks for the help from Jordan Rose & discussion/feedback from Ted Kremenek
and Doug Gregor.
Post commit code review feedback on r175796 by Ted Kremenek.
llvm-svn: 175938