3016 Commits

Author SHA1 Message Date
Pietro Fezzardi 33a8aeb64c MonotoneFramework: drop greaterThan from Lattices
All the definitions of `greaterThan` were `!lowerThanOrEqual`, and all
the uses were implicitly assuming this semantic.
However, this was confusing because in a Lattice the ordering is not
total, hence `!lowerThanOrEqual` is not equivalent to `greaterThan`.

This commit drops the `greaterThan` method altogether to avoid
confusion.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi db2e4b5bdb Improve interface types for MonotoneSet 2019-03-06 09:04:58 +01:00
Alessandro Di Federico 773b33e5f5 Add InterruptCreator in MonotoneFramework
This commit introduces the helper templated struct InterruptCreator,
that is used to provide defaults for the methods
MonotoneFramework::createSummaryInterrupt() and
MonotoneFramework::createNoReturnInterrupt() whenever the Interrupt
template parameter for Monotoneframework is of type
DefaultInterrupt<LatticeElement>.
This frees the implementor of a new MonotoneFramework from the need
to implement those methods in the most common cases.

Whenever Interrupt is DefaultInterrupt<LatticeElement>,
MonotoneFramework::createSummaryInterrupt() aborts, since a summary
should never be generated for those kind of analyses.
Instead, MonotoneFramework::createNoReturnInterrupt() generates a
default Interrupt, since it will never be used.
2019-03-06 09:04:58 +01:00
Alessandro Di Federico 8c49f47f26 Use DefaultInterrupt<LatticeElement> as default
In most cases, a user of MonotoneFramework does not need a
interprocedural analysis, nor an analysis whose results on
terminal labels have to be aggregated in a FinalResults.
DefaultInterrupt<LatticeElement> is designed exactly for those
cases, and is hence used as default template parameter for
MonotoneFramework.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi d16e02a4c4 Add DefaultInterrupt template class
This class provides the simplest possible implementation for an Interrupt
for a Monotone Framework.

In particular this interrupt is suitable for MonotoneFrameworks that are NOT
interprocedural, and that DO NOT need to combine all the results on the
terminal labels at the end of the analysis in a single FinalResult.

With these assumption, the resulting Interrupt is pretty simple and it just
forwards the results of the transfer function.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi 186b2d9a07 Rename isReturn method to isPartOfFinalResults 2019-03-06 09:04:58 +01:00
Pietro Fezzardi 08d0722bef MonotoneFramework: remove public typedef LabelRange 2019-03-06 09:04:58 +01:00
Pietro Fezzardi 4996a06517 MonotoneFramework: remove method extremalLabels
This method was unused.
2019-03-06 09:04:58 +01:00
Pietro Fezzardi a0cd9664ee Add IntersectionMonotoneSet and UnionMonotoneSet
The MonotoneFrameworkSet class had two sets of methods, one for handling
set operations on it, the other handling lattice ordering.
It also silently assumed that the lattice combine operation was the set
union, which is not true in general.

This commit decouples the set operations from the lattice operations.
This allows to provide two separate implementations of
IntersectionMonotoneSet (for which the compbine operation is the set
intersection) and UnionMonotoneSet (for which the combine operation is
the set union).
2019-03-06 09:04:58 +01:00
Pietro Fezzardi 10d3cfe4b6 Add writeToLog specialization for llvm::StringRef 2019-03-06 09:04:58 +01:00
Pietro Fezzardi f4603dc10c Add operator[] and at() members to SmallMap 2019-03-06 09:04:58 +01:00
Alessandro Di Federico e6928e34c1 Minor changes 2019-03-06 09:04:58 +01:00
Pietro Fezzardi a5ae26a7a9 EnforceCFGCombingPass depends on RemoveDbgMetadata
Before this change, `EnforceCFGCombingPass` was occasionally failing on
`verifyModule` if called from Caliban, with mismatches in the
`llvm.dbg.cu` debug metadata.
This metadata is a list of `DICompileUnit`, and `verifyModule` was
failing inside `verifyCompileUnits` because some of the visited compile
unit during the verify were not listed in `llvm.dbg.cu`.

One of the reasons of this problem might be that during
the enforcing we clone many things in the enforced function, and this
may cause the cloned stuff not to update the metadata accordingly.
I couldn't track down if this was caused by my misuse of LLVM's API for
cloning, of to some actual bug in LLVM.

In the end I couldn't find out the exact cause and fix it, so this
commit is a workaround. It adds a dependency on `RemoveDbgMetadata`, so
that the debug metadata causing `verifyModule` to fail are removed
before the enforcing, hence preventing things going astray during the
enforcing, and fixing the failure.

This workaround should be fine, because this is one of the last steps
before generating C code, and debug info are note serialized to C
anyway.
2019-03-01 15:55:04 +01:00
Pietro Fezzardi 3b2dac4e85 Enforce clang-format 2019-02-25 12:29:15 +01:00
Pietro Fezzardi b44c0dd71d Fix emission of negated if conditions 2019-02-25 11:58:19 +01:00
Alessandro Di Federico a75c75c305 Make install_pattern available in CMake package 2019-02-22 11:33:28 +01:00
Pietro Fezzardi 49da34f6a6 Fix print of function arguments 2019-02-13 15:27:59 +01:00
Andrea Gussoni af258c6e66 Fix double inserting for check nodes
Avoid double insertion of a predecessor for a check node when also using
`insertBulkNodes`.

Also added assertions to better detect this situation.
2019-02-13 14:44:52 +01:00
Andrea Gussoni 4319ba4e59 HACK: avoid a double insertion of predecessor
Hack to circumvent a probable problem of `setFalse` during
`insertBulkNodes` which causes a `set` node to have a repeated
predecessor.
2019-02-13 10:14:16 +01:00
Andrea Gussoni 6e2f087583 Track IfNode condition negation
Added a method to check if the `then` and `else` branches of an `IfNode`
have been inverted.
2019-02-13 10:06:38 +01:00
Andrea Gussoni 9b5607ab29 Fix check node false reassignment 2019-02-12 23:28:59 +01:00
Pietro Fezzardi cb08b4ac31 tmp 2019-02-12 20:55:28 +01:00
Alessandro Di Federico 4b9123fce8 Induction variable name used in range 2019-02-12 18:40:30 +01:00
Alessandro Di Federico 53db84f7d6 s/revamb/revng/g 2019-02-11 16:09:23 +01:00
Pietro Fezzardi 188d8fbdbb Make DecompilationPass an llvm::FunctionPass 2019-02-11 15:10:27 +01:00
Andrea Gussoni f790e308e1 Add ID for AST nodes
Added a unique ID to AST nodes, which is useful for serialization
purposes after flattening.
2019-02-11 14:15:07 +01:00
Pietro Fezzardi c5df55dedc Expose DecompilationPass.h header for public use 2019-02-11 14:01:40 +01:00
Pietro Fezzardi f4d5fec5bc First fully functional EnforceCFGComingPass 2019-02-11 12:18:44 +01:00
Pietro Fezzardi 463c40a9cf Add ASTNode children BreakNode and ContinueNode 2019-02-11 12:18:44 +01:00
Pietro Fezzardi 2b1843d898 Fix AST in EnforceCFGCombingPass 2019-02-11 12:18:44 +01:00
Andrea Gussoni 02e1b94daa Added RemoveSwitchPass
Added a new `FunctionPass` which converts `switch` instructions in a
nested chain of `if` checks.
2019-02-11 12:18:44 +01:00
Andrea Gussoni 929c0c4cdf Flattening for AST
Implemented the flattening also for the AST trees, taking also care of
adjusting the pointers to the new BBNode in the `root` `RegionCFG`.
2019-02-11 12:18:44 +01:00
Andrea Gussoni dbffa54124 Handle check BBNode in inflate
Considering the `check` BBNode during the `inflate` procedure, and
fixing the functions handling edges and nodes successors accordingly.
2019-02-11 12:18:44 +01:00
Alessandro Di Federico d00bf31bca Reorganize the build system 2019-02-10 16:20:24 +01:00
Alain Carlucci b2629efd05 Avoid useless computations when decompiling a single function 2019-02-08 11:44:17 +01:00
Alain Carlucci 2cda9be797 Decompile one function + write on raw_ostream 2019-02-08 11:44:17 +01:00
Andrea Gussoni eba245d35e RemoveBadPC pass
Added a pass that removes the `bad_return_pc` check, which is useful
only when we want to preserve semantics, but it is useless and harmful
for decompilation.
2019-02-07 19:27:08 +01:00
Pietro Fezzardi 7fc7ac4c7b Finish EnforceCFGCombingPass 2019-02-07 19:26:37 +01:00
Pietro Fezzardi c455b516d2 Add Liveness again 2019-02-07 14:44:32 +01:00
Pietro Fezzardi de19c3fd26 Fix BasicBlockNode::isBasicBlock() 2019-02-06 19:24:44 +01:00
Andrea Gussoni 2e9ff8449f Improved debugging messages 2019-02-05 10:17:47 +01:00
Andrea Gussoni 6231ba7bed Comb ignores useless conditional nodes
When the `then` and `else` branches of a conditional node reach two
disjoint sets of exit nodes do not consider that nodes in the `inflate`
procedure.
2019-02-05 09:54:23 +01:00
Andrea Gussoni 414aba5f66 Dot serialize function now const 2019-02-05 09:54:14 +01:00
Andrea Gussoni 54880d3a38 Fix dispatcher edge creation
Add the correct predecessor when setting the `true` or `false` branches
of the dispatcher check nodes.
2019-02-05 09:32:09 +01:00
Pietro Fezzardi 10fcd9bbdc Fix getters for Check BasicBlockNodes 2019-02-02 01:40:19 +01:00
Pietro Fezzardi 2afd5053e6 Rework exit and entry dispatcher trees 2019-02-01 19:24:56 +01:00
Pietro Fezzardi 7399590079 BasicBlockNode: remove usesless setter methods
Removing this methods also guarantees that the NodeType of a
BasicBlockNode is never changed after construction.
2019-02-01 17:59:23 +01:00
Pietro Fezzardi 2c93512f90 Rework BasicBlockNode class 2019-02-01 15:08:53 +01:00
Andrea Gussoni 0cdb63630e Restructure ASTTree anatomy
Added a pointer to the `RootNode` in the ASTTree, and added a
`dumpOnFile` method for easier serialization.
2019-01-30 18:35:24 +01:00
Pietro Fezzardi 099ae4d479 First stub of flattening 2019-01-30 09:22:20 +01:00