Commit Graph

6113 Commits

Author SHA1 Message Date
Pietro Fezzardi 3886b882da MarkAssignments: drop check on many uses
This commit changes MarkAssignments (and related tests) so that now
instruction with more than one use are not assigned to a new variable
by default.

In some cases it might still be good to serialize them for readability,
but for those cases we will implementa a standalone pass that only
implements heuristics based on readability.

MarkAssignments now only takes decisions based on semantics of
side-effects.
2023-04-20 17:51:16 +02:00
Alessandro Di Federico 89fd543cc8 Merge branch 'feature/c-api-tracing' 2023-04-20 15:31:54 +02:00
Giacomo Vercesi a2b7d0e0bf PipelineC: add tracing
Add support for tracing onto the PipelineC. This is done by:
1. Creating wrapper functions for each PipelineC function with the
   script in `scripts/PipelineC_add_tracing.py`. These will call a
   special function called `wrap` which will ultimately call a method
   with a `_` prepended to the name
2. Conversion of all PipelineC methods in `PipelineC.cpp` to `static`
   and their rename with a `_` in front, in order for them to work with
   the wrapper function in (1)
3. Generation of 2 additional include files, one for types and one for
   functions, to be used by users of tracing files in order to have
   introspection.

These steps allow the creation of a trace file with the use of the
`REVNG_C_API_TRACE_PATH` environment variable. The traces can then be
used in conjunction with the `revng trace run` and `revng trace
inspect` commands.
2023-04-20 14:43:13 +02:00
Giacomo Vercesi 19bb38d32b PipelineC: fix UAF on rp_targets_list
The underlying rp_target pointer was not stable, switch to returning a
copy of the target instead.
2023-04-20 14:43:13 +02:00
Giacomo Vercesi 566cb6310b PipelineC: make indexed object stably sorted
Many Pipeline objects (Globals, Ranks, Kinds, Targets in a TargetList)
were ordered by load order, this makes the playback of traces difficult.
Moreover the order of loading of pipeline files also influences the
ordering of other elements (Step, Analys{is,esLists}). These are also
ordered to prevent incosistent ordering.
2023-04-20 14:43:13 +02:00
Giacomo Vercesi 8d89c6a318 PipelineC: rp_initialize: only use argc and argv
Switch from specifying `libraries` and `pipelines` in `rp_initialize`
and `rp_manager_create` to the use of command-line options that are to
be passed via `argc` and `argv` in `rp_initialize`.
2023-04-20 14:43:12 +02:00
Giacomo Vercesi 9a972009d1 PipelineC: size and const-correctness
Fix the return type (often mismatched from uint64_t to int) and the
const-correctness of many functions in PipelineC
2023-04-20 14:43:12 +02:00
Giacomo Vercesi 3bfdb95d92 revng.api: Improve Manager.run_analyses_list
Fix the case where the return of `rp_manager_run_analyses_list` returns
nullptr.
2023-04-20 14:43:12 +02:00
Giacomo Vercesi 07be2c1cae Allow the use of valgrind with python
This commit does 2 main things:
* Adds PYTHONMALLOC=1 environment variable when `--valgrind` is used
  to force python to use normal malloc instead of the custom allocator
  python normally uses that's not friendly with valgrind
* Add a suppression file to remove a couple of false-positives that
  happen consistently and generate useless noise
2023-04-20 14:43:12 +02:00
Giacomo Vercesi 4400924312 revng.cli: allow non-ELFs to be run with gdb
If needed, wrap the execution of scripts in `exec` to allow running
them with gdb. This is especially useful for running python scripts
that use cffi and being able to inspect the C/C++ side.
2023-04-20 14:43:11 +02:00
Giacomo Vercesi 59175e9925 daemon-self-test: do not fail() twice
There was a codepath in `revng-check-conventions` that would cause
`fail(e)` to be called twice. This would cause an exception on the
second invocation due to the undelying process being already terminated.
2023-04-20 14:43:11 +02:00
Giacomo Vercesi cf0921ab31 revng-check-conventions: allow ignoring InitRevng
Add an additional `rcc-ignore` rule to ignore the absence of `InitRevng`
in a `Main.cpp` file
2023-04-20 14:43:11 +02:00
Giacomo Vercesi 87543f835a revng.cli._commands: drop shebangs
Remove leftover shebangs from python files in `revng.cli._commands` as
those files are no longer executable on their own
2023-04-20 14:43:11 +02:00
Giacomo Vercesi a06df16b73 rcc: handle empty files gracefully
Fix two corner cases in `revng-check-conventions` where it would error
out when processing an empty file
2023-04-20 14:43:10 +02:00
Andrea Gussoni 659aff1bbf Fix loop promotion criterion
A bug introduced no loop promotion by mistake, we now correctly exit the
loop promotion routine if the loop has been already promoted to `while`
or `do-while` loop.
2023-04-19 16:07:46 +02:00
Pietro Fezzardi ee911b633b Merge branch '/feature/llvm-16' into develop 2023-04-19 15:13:32 +02:00
Alessandro Di Federico 7ef337d825 Merge branch 'feature/llvm-16' 2023-04-19 14:44:01 +02:00
Pietro Fezzardi 8413e6e872 InitModelType: fix type of cstringLiterals 2023-04-14 14:54:14 +02:00
Pietro Fezzardi 56db9e6660 Make getExpectedModelType more strict on integers
This commit teaches getExpectedModelType about the fact that various
bitwise operations are only allowed to have integer operands.

It also updates VMA, which uses getExpectedModelType, to take this
into account.
2023-04-14 14:54:14 +02:00
Pietro Fezzardi 118929b8fd InitModelTypes: don't run VMA if PointerOnly 2023-04-14 14:54:14 +02:00
Alessandro Di Federico f7a3fa8f07 SegregateStackAccesses: fix returning structs
In SegregateStackAccesses sometimes we have to replace a call whose call
type does not match the callee type. Specifically when the return type
is a `StructType`, sometimes the call returns an identical `StructType`,
but with a different identity.

This commit adapts the return type of new calls on the fly.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 35d2323fa0 SegregateStackAccesses: assert(findAssociatedCall) 2023-04-14 14:54:14 +02:00
Alessandro Di Federico be79842827 Enable DCE of revng_init_local_sp 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 2bacc7ab68 DecompileFunction: fix handling of {and,or} i1
We used to emit bitwise `&` and `|` but, given that we emit `i1` as
`bool`, it's more appropriate to use `&&` and `||`.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico b09526a5b4 DecompileFunction: drop redundant handling of IntToPtr
They were already handle above since `isa<IntToPtr>` implies
`isa<CastInst>`. Same for `PtrToInt`.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico a9eae1c96b Purge remaining traces of InsertValueInst
InsertValue has long been superseded by `struct_initialier`, so we don't
expect it in the IR we work on.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 79c2ca38f6 Introduce SplitOverflowIntrinsicsPass
This pass splits calls `*.with.overflow*` intrinsics into the a pair of
instructions: the underlying operation and a call to an `Helper`-tagged
function that computes whether such operation overflowed.

For instance, we go from:

    %2 = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %0, i32 %1)
    %3 = extractvalue { i32, i1 } %2, 1
    br i1 %3, label %..., label %...

To:

    %2 = mul i32 %0, %1
    %3 = call i1 @mul_overflow_u32(i32 %0, i32 %1)
    br i1 %3, label %..., label %...

This saves from handling `struct` in the backend.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 43a0be786f helpers-to-header tests: start from canonicalized 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 82fcf858ba getStrongModelInfo: handle call_stack_arguments 2023-04-14 14:54:14 +02:00
Alessandro Di Federico c8a955813d getStrongModelInfo: fix prototype lookup in model
Limit lookup of function prototypes in the model to isolated functions
only.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico b206957e5f DetectStackSizeAnalysis: fail if no Architecture 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 8860ea16e2 Introduce HoistStructPhis
This pass turns phis of invocations of pure functions into an invocation
of the pure functions with one phis per argument of the original
invocations.

This makes handling phis easier in the backend and is necessary after
the introduction of simplify-cfg with sinking enabled.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico b73bb90d0c Handle the freeze instruction 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 2deb057364 DecompileFunction: introduce buildInvalid
Factor code to emit poison and undef values.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico ffee4c22f0 Adapt tests to LLVM 16 2023-04-14 14:54:14 +02:00
Alessandro Di Federico ccb660646e Introduce SimplifyCFGWithHoistAndSinkPass
This is a simple pass that enables running simplify-cfg with the legacy
pass manager enabling instruction hoisting and sinking.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico fda84a701f Decompilation: suppress more warnings 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 859a9ec2cf SegregateStackAccesses: do not iterate and modify
SegregateStackAccesses creates new functions. Iterating over existing
functions while creating new ones is problematic, so we now first
collect all the functions we want to inspect and then process them.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 886e1696a2 llvmIntToModelType: adapt to opaque pointers
This commit introduces modelType, which supersedes `llvmIntToModelType`
in order to better handle translation of LLVM types into model types
after introduction of opaque pointer types.  The main differences is
that `modelType` accepts the `Value` (instead of just the `Type`), so it
can better handle `AllocaInst` and `GlobalVariable`, which provide
information about the pointee.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 5cfeb0fc36 InjectStackSizeProbesAtCallSitesPass: use nomerge
The `nomerge` attribute prevents this type of problematic deduplication
(specifically by simplify-cfg with sinking enabled) of calls to markers.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico f87a86677d MakeModelGEP: handle multiple identical incoming
Since MakeModelGEP works Use-wise, if a `Value` was used multiple times
in a phi, we used to replace them with distinct model GEPs. This led to
generate illegal IR.

This commit fixes this situation by detecting the situation and reusing
the same model GEP.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico c32f7cd8f3 LoopRewriteWithCanonicalIV: NewVal == Op 2023-04-14 14:54:14 +02:00
Alessandro Di Federico ba05ddfaaf DLA: handle ConstantPointerNull 2023-04-14 14:54:14 +02:00
Alessandro Di Federico 6610213da4 DLA: drop support for InsertValue
They shouldn't appear in the IR at this stage of the pipeline.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 03bbf22a48 DLA: improve handling of phis
DLA used to support phis in return values, but didn't handle phis
referring to other phis.
This commit fixes that.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 237aefcc9a DLA: drop LoopInfoWrapperPass
It was not being used.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 82512ef81f CreateIntToPtr: adopt opaque pointer type 2023-04-14 14:54:14 +02:00
Alessandro Di Federico ef6ec4ed0f Minor changes 2023-04-14 14:54:14 +02:00
Alessandro Di Federico d33f339ec9 Adapt to revng.callerblock.start dismission
We no longer attach non-dbg metadata to instructions, it's not robust.
2023-04-14 14:54:14 +02:00
Alessandro Di Federico 3d5e0d3106 DecompileFunction: update handling of strings
Simplify the emission of string literas after the introduction of opaque
pointers, which basically take out of the equation GEP ConstantExpr.
2023-04-14 14:54:14 +02:00