Now that we support C string literals, by the rules of the language they
have type `const char [N]` where `N` is a compile time constant.
They also decay to `const char *`.
This causes the `-Wpointer-sign` warning to trigger when recompiling
decompiled C code, since we assign the string literals (with type `const
char *` in C) to variables with other pointer types, some of which are
e.g. `const uint8_t * but possibly also `const generic8_t *`.
Given that we emit C code from assembly this warning is too strict to be
always enforced.
In fact, we had already disabled a similar warnings, such as
`-Wincompatible-pointer-types`, and others.
So we disable `-Wpointer-sign` as well in recompilation tests.
For segmentRef type of the segment and type returned by segmentRef
function are the same.
For cstringLiteral every call returns pointer to 1-byte type. Pointer is
offsetted by value of strlen+1. strlen is fetched from metadata.
Additionally, all uses of cstringLiteral function has same type as the
type of cstringLiteral (pointer to 1-byte).
This commit changes MakeSegmentRefPass so that it's now a ModulePass and
it uses the binary to detect integer constants that represent the
address of strings.
When it detects address of constant strings, instead of injecting calls
to SegmentRef, we now inject calls to cstringLiteral, so that we can
later emit them as inline string literals in C.
In segmentRef we use integer type meaning address in memory, so we
generate segmentRef function with non-pointer type. For cstringLiteral
function we need real pointer type of operand.
Save MetaAddress, size, offset and original type for every
cstringLiteral call in metadata as we do for segmentRef calls.
For cstringLiteral "revng.cstring_literal" metadata name is used.
StringLiteralPool needs tuple of address, size, offset and type to
keep distinct string decorator functions for each string. This tuple is
represented by StringLiteralPoolKey struct.
Pipe for MakeSegmentRefPass needs to be defined explicitly, because
additional wrapper passes are required in MakeSegmentRef:
1. LoadModelWrapperPass
2. LoadBinaryWrapperPass
MakeSegmentRefPass requires access to RawBinaryView to detect cstring
literals in binary.
Fix printed command in MakeSegmentRefPipe
This printed command might not work. @ale commented it will be replaced
with `revng pipe run-pipe` once we will have it.
Update IRHelpers to new revng API
Switch String and Namespace arguments in getUniqueString
This commit works around a quirk of
`llvm::ConstantDataArray::getString`, which returns a
`llvm::ConstantAggregateZero` for empty strings.
This quirk caused assertions in the previous implementation when passing
an empty `String` to `getUniqueString`.
Using an empty namespace causes the creation of a named metadata with an
empty string as name.
`llvm::verifyModule` does not check for that, so the `Module` still
verifies, but the on-disk serialization generated by `AsmPrinter.cpp`
prints `"empty name"` instead of the metadata name, and if the
serialized `Module` is then reparsed it parses succesfully but it does
not verify anymore.
This method is similar to `getByAddress`, but it returns an
`llvm::StringRef`.
It is intended for those users that need to manipulate the bytes as
strings. In those cases, the `llvm::ArrayRef<uint8_t>` returned by
`getByAddress` is not suitable, because it triggers warnings due to
`uint8_t` not being the same as `char`.
In the previous implementation of Model.verify an llvm::Error was
returned. Some call sites retained the logic associated with it. Fix
these with the correct logic.
Also fix an instance of `verify` that was missing an assert.
Drop the use of unique_ptr within the rp_error data type and instead use
std::monostate. Also fix the functions to allow the use of `nullptr` as
the error parameter
The primitives were imported before the importing of the binary, which
is not valid anymore since it leads to duplicate types in cases where
the binary contains any primitive types, since one of the revng-side
commit now asserts on an attempt to insert multiples of the same type.
Also, this removes a duplicated type from the `SegregateStackAccesses`
test's `override` model.