avast / avast/retdec-regression-tests-framework

Nondeterministic C source code parsing between platforms

Open
#8 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
24
Forks
13
PR merge metrics
No merged PRs in 30d

Description

The C sources that are being tested are parsed using clang. The problem is that the result of this parsing (AST) is not always the same on all the supported platforms (Linux, Windows, macOS). Difference can probably occur even between machines using the same platform. Even if the same version of clang is used, there can be differences. It looks like system includes play a role here. The problem is most prominent in call expression parsing, but probably can occur in other situations as well.

Example:
```c
#include

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

int main()
{
int32_t set;
sigaddset((struct _TYPEDEF_sigset_t *)&set, SIGINT):
}
```
* Linux parses it ok and recognizes `sigaddset` call.
* macOS does not parse the call at all - it completely ignores it.
* macOS without the long list of includes parses it ok and recognizes `sigaddset` call.
* macOS without the type cast (i.e. `sigaddset(&set, SIGINT)`) parses the call as `__sigbits`.

Another example is parsing of `strlcpy()` call (without proper type signature). Linux parses it ok, but macOS does not. It parses it only if the function (and its calls) have the full signature of
```c
size_t strlcpy(char * restrict dst, const char * restrict src, size_t dstsize);
```

Solutions:
* Can we force clang to use some custom set of includes that would be the same everywhere?
* Can we remove the `#include` statements from C sources before parsing it? (=> I don't think so, without them, some other function calls may not get parsed.)
* Are includes the only problem?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the framework's clang-based parsing setup and compare the included C examples across Linux, Windows, and macOS. Determine whether controlled includes or another parsing setup can produce consistent AST results, then verify that calls such as sigaddset and strlcpy are parsed consistently on the supported platforms.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers, testing-qa
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.