Commit Graph

6113 Commits

Author SHA1 Message Date
Lauri Vasama 888d529d93 Fix Clift return type verification 2025-03-19 12:57:20 +02:00
Lauri Vasama df2003efb8 Add clift::removeConst in CliftTypes.h 2025-03-19 12:57:20 +02:00
Lauri Vasama da9df369fc Loosen Clift logical op type constraints 2025-03-19 12:57:20 +02:00
Lauri Vasama 4a334bef7b Move Clift type helpers to CliftTypes.h 2025-03-19 12:57:19 +02:00
Lauri Vasama c472dd3cae Move ScopedExchange to revng/ADT/ 2025-03-19 12:57:19 +02:00
Lauri Vasama eec882dac1 Add clift::GlobalOpInterface 2025-03-19 12:57:19 +02:00
Lauri Vasama 44c9388930 Rename Clift comparison operations 2025-03-19 12:57:18 +02:00
Lauri Vasama 08c2c0a477 Remove ScalarTupleType
After converting type IDs to unique handles it was decided to remove
scalar tuple types in favour of generated structs with non-model unique
handles.
2025-03-19 12:57:18 +02:00
Lauri Vasama 386efffb2f Convert TypeDefinitionAttr ID to UniqueHandle 2025-03-19 12:57:17 +02:00
Lauri Vasama 86126db366 Fix Clift composite type verify on parsing 2025-03-19 12:57:17 +02:00
Lauri Vasama 4648fe672f Allow commit message ending with backticks 2025-03-19 12:57:14 +02:00
Alessandro Di Federico 8cd571335b Merge branch 'feature/fix-32-bit-pointer-masks' 2025-03-17 08:51:55 +01:00
Alessandro Di Federico c5b9728289 LocalVariableBuilder: add pointer size assumption
This commit further centralizes the creation of allocas + ptrtoint.  The
creation of these pair of instructions is problematic when the size of a
pointer in the input and target architecture differ.

In fact, in such cases, LLVM turns trunc into masking the integer to
suppresse the high bits. This results in problematic code.

This commit introduces an assumption that ensures LLVM does not do that.
2025-03-17 08:51:29 +01:00
Alessandro Di Federico 86f3dcf1ae Minor changes 2025-03-14 17:25:05 +01:00
Alessandro Di Federico 6465a7523d Merge branch 'feature/ui-qa-2025-03-04' 2025-03-14 15:18:43 +01:00
Giacomo Vercesi a9a0fdc236 ELFImport: fix input file missing
When using revng through `revng daemon` the variable `InputPath` is not
populated, leading to `lddtree` failing silently. Fall back to the input
binary in the resume directory in case the the `InputPath` variable is
empty.
2025-03-14 13:05:39 +01:00
Giacomo Vercesi 6cdf6b9eda DebugInfo: do --verbose if logger is enabled
Enable running `fetch-debuginfo` in verbose mode if the logger is
enabled.
2025-03-13 18:03:50 +01:00
Giacomo Vercesi d9e928dce9 fetch debuginfo: provide alternative urls via env
Allow the `fetch debuginfo` command to have the upstream server urls be
provided via environment variables rather than the command-line.
2025-03-13 18:03:50 +01:00
Giacomo Vercesi f6b9e509a3 fetch debuginfo: actually check for PE/COFF
Add the code needed to check if the input file is actually a PE/COFF
file.
2025-03-13 18:03:50 +01:00
Giacomo Vercesi fa44c4cf2f fetch debuginfo: drop self.verbose
The `FetchDebugInfoCommand` contained assignment to `self.verbose` which
was unused. Drop it.
2025-03-13 18:03:50 +01:00
Giacomo Vercesi 87872f9fc5 PipelineManager: add save-after-every-analysis
Add a command-line option to pipeline that saves after every analysis is
run.
2025-03-13 18:03:50 +01:00
Giacomo Vercesi 74eba2954f revng trace run: log commands before execution
Log the commands that are going to be executed by `revng trace run` on
the `trace-runner` logger.
2025-03-13 16:23:21 +01:00
Giacomo Vercesi 41e2e0f73d RunTraceOptions: use doxygen comments
Change the struct field comments on the
`revng::tracing::RunTraceOptions` struct to doxygen comments.
2025-03-13 16:23:21 +01:00
Giacomo Vercesi 6eae722d5b tracing::Argument: make ArgumentState enum private
Move the `ArgumentState` enum to be a private member of the `Argument`
class, since no external users require using the enum.
2025-03-13 16:23:21 +01:00
Giacomo Vercesi 042108bc44 ProgramRunner: cleanup
Clean up the `ProgramRunner` class:
* use llvm-provided wrappers and system-agnostic variables to compute
  the `Paths` variable
* pre-compute the list of path variables so it's not re-computed on
  every invocation of `run` or `isProgramAvailable`
* Wrap the logging code so that it's not triggered if the logger is
  disabled
2025-03-13 16:23:21 +01:00
Giacomo Vercesi 442020bf22 ProgramRunner: print exit code to logger
Print the exit code of the invoked program to the `program-runner`
logger.
2025-03-13 15:16:17 +01:00
Giacomo Vercesi 51687a2f4f Runner.cpp: remove extra ; 2025-03-13 15:16:17 +01:00
Giacomo Vercesi 5b00a93660 revng trace run: skip setting credentials
The `rp_manager_set_storage_credentials` is now skipped when running a
trace in `revng trace run`. This is needed because the storage backend
when running a trace is replaced with a local one and calling the
function does not make sense.
2025-03-13 15:09:15 +01:00
Giacomo Vercesi 72d9b46e4b Error.h: improve joinErrors
Change the `joinError` functions to have stronger guarantees when used:
* Change the template signature to `RangeOf` to ensure that the
  container has `llvm::Error`s.
* Check that the size of the passed container is actually positive
  before deferencing `.begin()`.
2025-03-13 15:07:25 +01:00
Giacomo Vercesi 140735a913 tuple-tree-generate-typescript: drop --prettier
The `prettier` binary is now assumed to be installed as part of the
system. No need to manually install it and use the `--prettier`
command-line option.
2025-03-13 14:06:02 +01:00
Giacomo Vercesi 6c31138374 Drop unused files in scripts/
Some files under `scripts/` were unused. Delete them as they are no
longer needed.
2025-03-13 14:06:02 +01:00
Pietro Fezzardi 29278d7e3a Merge branch 'feature/dagify' 2025-03-11 17:59:50 +01:00
Andrea Gussoni 93f4a620dd DAGify: implement the DAGify pass
Implement the DAGify pass. This pass, using the results exposed by the
`GenericRegionInfo` analysis, transforms all the retreating edges of
each identified `GenericRegion`, processed in a bottom-up fashion, into
a `goto` edge on the `ScopeGraph`.
2025-03-11 12:26:36 +01:00
Andrea Gussoni d5b26a9346 GenericRegion: add support for ScopeGraph
Add the needed support for running `GenericRegionInfo` on the
`ScopeGraph`.

This needs a new ad-hoc `getGenericCycleInfo` helper in order to unwrap
the `Graph` object (pointing to the underlying `Function *`) from the
`Scope` wrapper object.
2025-03-11 12:25:24 +01:00
Andrea Gussoni 3499d10154 GenericRegion: remove retreatings edges
Remove retreating edges from the `GenericRegion` class, and the
collection of them in `GenericRegionInfo`.
2025-03-11 12:25:24 +01:00
Andrea Gussoni fe127200be GraphAlgorithms: improve comments 2025-03-11 12:25:24 +01:00
Andrea Gussoni 7c8d581271 ESE: fix unit test 2025-03-11 12:25:24 +01:00
Andrea Gussoni f5b3feb738 ESE: fix comment 2025-03-11 12:25:24 +01:00
Andrea Gussoni ec8972cbed ScopeGraph: require pointer type for ScopeGraph 2025-03-11 12:25:23 +01:00
Andrea Gussoni ce6f9ddb69 ScopeGraph: do not assert when marker not present
Do not assert if the marker function is not present in the input IR, the
`Builder` instantiation takes care of its on-the-fly declaration
instantiation.
2025-03-11 09:28:04 +01:00
Pietro Fezzardi 86edda9caf Merge branch 'feature/fix-broken-bitcasts' 2025-03-05 15:27:51 +01:00
Pietro Fezzardi 405001d628 CCodeGenerator::getModelGEPToken: relax assumption
This commit relaxes the assumption of the
CCodeGenerator::getModelGEPToken method, that previously crashed if the
BaseType and CurType were different.
Now this condition is only checked after skipping all typedefs, that
are transparent to ModelGEPs.
2025-03-05 15:25:59 +01:00
Pietro Fezzardi e87a229b1c DecompileFunction: use __builtin_bit_cast
This commit ensures that, when the LLVM-based C code generation emits a
bitcast that would not compile in C if printed as a regular cast, it
uses __builtin_bit_cast instead.

This is necessary because the LLVM-based C backend is deprecated in
favor of the clift-based decompilation pipeline, so we're not actively
fixing bugs anymore, and it currently cannot guarantee that such invalid
casts are never emitted.
2025-03-05 15:25:59 +01:00
Pietro Fezzardi f13e919678 MakeModelCastPass: allow casting non-scalars
Before this commit, MakeModelCastPass was assuming that it would never
try to emit casts involving non-scalars, which don't compile in C.

From now on, the semantic of ModelCast in understood to be bitcast, and
it's valid also when involving non-scalar types.
This may cause the emission of ModelCast that are then emitted in C as
casts that don't compile.
Since the LLVM-based decompilation pipeline is deprecated in favor of
the clift-based decompilation pipeline, this is now considered
acceptable, as long as the C backend prints a warning and a comment on
the broken cast.
2025-03-05 14:47:46 +01:00
Pietro Fezzardi 7f7c38fa35 MakeModelCastPass: postpone arguments computation
This commits reworks MakeModelCastPass so that the computation the of
arguments for the invocation of a ModelCast are now computed later: not
when we decided that a cast must be emitted, but right before we emit
the call.

This simplifies the code and lays the groundwork for relaxing some
assertions later.
2025-03-05 14:47:46 +01:00
Pietro Fezzardi bd1f2f3422 MakeModelCastsPass: add model::Binary * member
This field is initialized at the entry of the `runOnFunction` method, to
avoid passing it throughout a bunch of methods as explicit argument.
2025-03-05 14:47:46 +01:00
Pietro Fezzardi 556e14dfb1 MakeModelCastsPass: drop unused member 2025-03-05 14:47:46 +01:00
Pietro Fezzardi f5b1622a0b RemoveLoadStore: handle not areMemOpCompatible
This commit adds support in RemoveLoadStore for load/store instructions
such that the pointee of their pointer operand on LLVM is does not match
the pointee type on the Model (i.e. not areMemOpCompatible).

These cases are handled by emitting a Copy/Assign whose address operand
is a ModelGEP with a type matching the LLVM pointee, so that when these
are emitted as expressions in C the dereference operation is guaranteed
to access memory at a size that is compatible with LLVM, which represent
the semantic of what happens in the binary.
2025-03-05 14:47:46 +01:00
Pietro Fezzardi 95d44d254b SwitchToStatement: emit copies on each use
Before this commit, SwitchToStatement, in Legacy mode, was evaluating
the injection of Copy instruction an all uses at the same time, while
it's perfectly feasible, depending on how the surrounding IR is shaped,
that calls to Copy are only necessary on some of the uses.

This commit fixes, that evaluating the emission of a call to Copy on
each Use separately.
2025-03-05 14:47:46 +01:00
Pietro Fezzardi 6a4ce00ce9 InitModelTypes: improve types of void * variables
This commit adds a post-processing step to initModelTypes, to enable it
to better discover types of void * variables, by looking at their uses.

This is useful in scenarios like e.g.:

```c
struct s {
  int32_t x;
  int32_t y;
};

struct s* init() {
  void *result = calloc(SIZE, 1);
  *((int32_t *)(result)) = SOME_INIT_VALUE;
  *((int32_t *)( (uin64_t)(result) + 4) = OTHER_INIT_VALUE;
  return result;
```

This patch enables initModelTypes to look at uses of `result`, and to
enable other transformations that depend on initModelTypes (such as
MakeModelGEP, SwitchToStatements) to turn the above code into:

```c
struct s {
  int32_t x;
  int32_t y;
};

struct s* init() {
  struct s *result = calloc(SIZE, 1);
  result->x = SOME_INIT_VALUE;
  result->y = OTHER_INIT_VALUE;
  return result;
```
2025-03-05 12:22:30 +01:00