Commit Graph

3168 Commits

Author SHA1 Message Date
Alvise de Faveri 92712396ee DLA: Fix multi-edge children in DedupUnionFields
When deduplicating unions, for each union we compare each successor
with all other successors. However, the same successor node might be
reachable by more than one edge from the parent.

This can cause problems when a node gets merged while the comparison is
still ongoing. In particular, since the comparison is done using a copy
of the successor list, to avoid iterator invalidation, the links in
the worklist are not updated when a node gets merged, causing links to
the merged node to have an invalid destination.

The fix here is to keep a list of **nodes** to visit, and a list of
**edges** that have already been visited, so that, if a node is merged
through one of its links, we are not visiting other links connected to
the same node after the merge.
2021-11-16 17:00:34 +01:00
Andrea Gussoni 46cb2be99c generateAst: Add parent switch in SwitchBreak 2021-11-15 12:39:17 +01:00
Pietro Fezzardi 067f2fffe1 Add ModelToHeader 2021-11-15 11:47:17 +01:00
Pietro Fezzardi 432cf351d7 AddSCEVBarrierPass.h: declare function extern 2021-11-12 18:36:19 +01:00
Pietro Fezzardi 15cc5d2a42 libRestructureCFGPass: link revngModel 2021-11-04 10:00:11 +01:00
Pietro Fezzardi c050dcb621 Handle missing model in SerializeModelPass
Before this commit, SerializeModelPass and SerializeModelWrapperPass had
hard dependencies on the passes that load the model from LLVM-IR.

This commit makes this dependency optional. When the passes for model
serialization are executed, if they see that nobody requested to load
the model, they will not try to serialize it.

This prevents them from crashing when running in pipelines that only
contain passes that ignore the model.

This is particularly beneficial because `revng opt` automatically adds
`-serialize-model` at the end of each pipeline and, before this commit,
this meant that `revng opt` could not be used for unit-testing simple
llvm passes that do not use the model.

With this commit, `revng opt` can be used for unit-tests, even on LLVM IR
with missing model.
2021-10-21 15:02:01 +02:00
Alessandro Di Federico 83f420abda Introduce dump method for model structs 2021-10-21 15:02:00 +02:00
Alessandro Di Federico eb2c3df925 Tag with MetaAddress functions and call sites 2021-10-21 15:02:00 +02:00
Alessandro Di Federico 8546a0c786 CallEdge: only indirect calls have a prototype 2021-10-21 15:01:59 +02:00
Alessandro Di Federico 89532890ed Introduce support for importing DWARF information 2021-10-21 15:01:20 +02:00
Alessandro Di Federico 3a3eea0cf5 Introduce support for dynamic functions 2021-10-21 15:01:19 +02:00
Alessandro Di Federico a023bfa7f5 Introduce ABI handling 2021-10-18 20:44:58 +02:00
Alessandro Di Federico 0dfc81da41 Minor model improvements
* Introduce some documentation for the model.
* Improve the way enums are serialized/deserialized.
* Mark certain fields of model data structures as optional.
* introduces some error messages during model validation.
2021-10-18 20:44:58 +02:00
Alessandro Di Federico 34ae75c800 model: handle 80 bits floats (12 bytes) 2021-10-18 20:44:58 +02:00
Alessandro Di Federico 06043b92c6 PromoteCSV: do not promote the stack pointer 2021-10-18 20:44:58 +02:00
Alessandro Di Federico 2fec214959 Fix QualifiedType::isScalar 2021-10-18 20:44:58 +02:00
Alessandro Di Federico e29c36cd51 Drop --disable-enforce-abi-safety-checks 2021-10-18 20:44:58 +02:00
Alessandro Di Federico 18cfbdbfe0 Whitespace and other minor changes 2021-10-18 12:39:21 +02:00
Pietro Fezzardi 032463c539 Fix handling of calls with unnamed callees 2021-10-12 09:57:30 +02:00
Alvise de Faveri e90020b94c Don't visit the same union twice during dedup
Optimization to avoid checking the same union node multiple times.
2021-10-11 18:28:03 +02:00
Alvise de Faveri a6d0d52107 Remove leftover call from debugging session
RemoveConflicts should not be needed here, as it runs before in a
separate step and is also ran during deduplication.
2021-10-11 18:25:18 +02:00
Alvise de Faveri e2dd34e08e Avoid comparing a node with itself in union dedup 2021-10-11 18:21:53 +02:00
Alvise de Faveri 43ae7a91cb DLA: Add DeduplicateUnionFields Step
Add a step that recognizes if two subtrees of a union node are
topologically equivalent and merges them. This corresponds to removing
duplicate fields in unions.

This deduplication was prevously done while emitting layouts.

A check is inserted into DLAMakeLayouts to assert that, after
constructing unions, no union has only one child, which could be the
case if we didn't deduplicate union fields in the graph.
2021-10-06 16:37:37 +02:00
Alvise de Faveri 637bf70ff3 DLA: Make CollapseSingleChild a function
Since the reasoning behind single child collapsing can be reused in
other points of the DLA pipeline, move the logic that acts on a single
node in a static function out of the CollapseSingleChild step.
2021-10-05 18:16:21 +02:00
Alvise de Faveri 7e72fc4be1 DLA: Add RemoveConflictingEdges step
Add a DLA step that removes all instance-at-offset-0 edges between nodes
that already have an inheritance edge between them.
2021-10-05 18:16:21 +02:00
Pietro Fezzardi fda2b0042f Drop Beautify dependency on MarkForSerialization 2021-09-22 19:01:44 +02:00
Pietro Fezzardi 7ceb6d2f16 Extract BeautifyGHAST in a separate library 2021-09-22 19:00:09 +02:00
Pietro Fezzardi ce0083a7ff Extract MarkForSerialization in separate library 2021-09-22 15:03:12 +02:00
Pietro Fezzardi eea93438cc Alphabetically sort lib/CMakeLists.txt 2021-09-22 14:57:32 +02:00
Pietro Fezzardi a0dbea19e5 Prevent model::Type CustomNames from colliding
This commit reserves the "unnamed_" prefix for revng.
The first use of this reserved prefix is in `model::Type`s
`CustomName`s and `model::Identifier`s.
This commit also makes the `verify()` method stricter for
`model::Identifier` so that an `Identifier` whose name starts with the
reserved prefix does fails verification.
2021-09-02 14:55:47 +02:00
Pietro Fezzardi 3d38451abd Enable error checking on Model deserialization
This commit changes the `TupleTree::deserialize` method to return an
`llvm::ErrorOr<TupleTree>`, enabling users to choose their policies on
error reporting.
2021-09-02 14:42:51 +02:00
Pietro Fezzardi bae9214652 Stricten verification for model::Identifier
Now only `Identifier`s that are valid C identifiers are guaranteed to
verify.
The `fromString` factory is updated accordingly.
2021-09-02 14:42:47 +02:00
Pietro Fezzardi aa46b03050 Add name() members to various Model types 2021-09-02 14:39:23 +02:00
Pietro Fezzardi 44b348db6a Provide efficient getName for model::Type enums 2021-09-02 14:39:23 +02:00
Pietro Fezzardi b31f6beb1a Make ManagedStatic IDGenerator static 2021-09-02 14:28:58 +02:00
Alessandro Di Federico 6e4cd06095 Add LLVM libs for --no-undefined compliance 2021-09-01 16:40:56 +02:00
Pietro Fezzardi a2a29c7942 Fix missing linking with revng and LLVM libraries 2021-08-31 12:30:04 +02:00
Pietro Fezzardi f057441ce8 Fix linking 2021-08-20 11:21:04 +02:00
Andrea Gussoni 55c620ab31 RegionCFGTree: refactor connectContinueNode
THe creation and connection of continue nodes is now down in the
population of the collapsed region, avoiding external methods.
2021-08-19 18:51:24 +02:00
Andrea Gussoni 7323cecec1 RestructureCFG: improve break node creation
Break node creation is now improved to avoid edge index swapping that
can cause inversion of conditions later on in the decompilation
pipeline.

To do this, the creation and connection of the break nodes is done
during the bulk insertion of nodes in a collapsed region.
2021-08-19 18:51:14 +02:00
Andrea Gussoni 866ab7cbed CDecompilerAction: fix expression negation
The `negateExpr` function incorrectly changed the `OpCode` of a binary
comparison, resulting in not intended side effects.
2021-08-19 18:50:39 +02:00
Alvise de Faveri a0f95e0370 Modify CollapseSingleChild to allow single members
* Inheritance straight lines are now collapsed by CollapseSingleChild
* Don't collapse if parent has more than one parent or if the child has
more than one parent
* Allow the possibility to construct single-member struct: if this
struct is inherited by many other structs, "flattening" the struct is not
the most sensible thing to do, since inheritance information is something
we want to preserve in these cases.
2021-07-27 11:59:48 +02:00
Alessandro Di Federico fd30d3de42 Import the model's type system
This commit introduces the type system of the model along with several
various other improvements to the model and its users.

* Introduce the type system.
* Introduce possibility to tag certain fields in the model as to be
  optional during YAML serialization.
* All the `Name` fields have been replaced in favor of `CustomName` plus
  a `name` method that will use `CustomName` if available, or an
  automatically generated name otherwise.
* Make TupleTreeReferences behavior more robust: now you either need to
  have a valid pointer to `Root` and a `Path` or be default constructed
  (`nullptr` for `Root` and an empty `Path`). Any other configuration is
  invalid.
* The type system introduces `RawFunctionType`: this superseds the
  previous way in which we were specifying arguments and return
  values. Users of such information have been updated accordingly.
2021-07-21 18:22:58 +02:00
Pietro Fezzardi 10d1eab7f4 Decompiler: update to new model APIs 2021-07-21 11:09:28 +02:00
Pietro Fezzardi e1ab2ff553 ASTBuildAnalysis.cpp: disable array accesses 2021-07-21 10:48:06 +02:00
Pietro Fezzardi 88ade5e105 Handle non-decreasing nested AddRecs
These may happen in nasty functions like memchr, where you have a loop
pre-header iterating over single bytes, a loop iterating over 4 bytes,
and finally the loop exit iterating over single bytes again.

Now we stop at the first non-decreasing nested AddRec.
2021-07-21 10:48:06 +02:00
Pietro Fezzardi f2dd2d89de ASTBuildAnalysis: improve logging 2021-07-21 10:48:06 +02:00
Pietro Fezzardi c994dc0b44 ASTBuildAnalysis: drop assertion for handled case 2021-07-21 10:48:06 +02:00
Pietro Fezzardi 81cb8422ad ASTBuildAnalysis: build member access expressions 2021-07-21 10:48:06 +02:00
Pietro Fezzardi ae0095e90a DLA: handle Values with unknown Layouts 2021-07-20 15:20:53 +02:00