C syntax error: redefinition of 'XXX' structure
- Dominant language
- C++
- Stars
- 8.6k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
When syntax checks are run on C files generated by RetDec, there are a lot of errors. One of them is `redefinition of 'XXX'`. E.g.
```
redefinition of 'struct _IO_FILE'
redefinition of 'struct _IO_marker'
redefinition of 'struct passwd'
redefinition of 'struct stat'
```
The problem is that for example `_IO_FILE` is defined in `stdio.h`, which we include, but we also define it in LLVM IR and C. We have to fully define it in LLVM IR in order to be able to work with it.
What needs to be done to solve it:
- Better implementation of data types in JSON config. If possible, use _ctypes_ library. We need to store member names, and header names from which structures come from.
- Fill this information as types are generated to LLVM IR in _bin2llvmir_.
- Use this info in _llvmir2hll_ - name structure members, etc. This can not be done sooner since LLVM IR does not have member names.
- _llvmir2hll_ should not generate declarations of those structures, which are in headers that will be included in C. It knows what headers it generates, and can cross-check them with header information in JSON config.
Some things might turn out to be tricky. E.g. structure definitions might differ based on compilers.
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue points to JSON config, bin2llvmir, and llvmir2hll; start by tracing how structure types and included headers are represented and generated. Done means member and header metadata survives into LLVM IR and llvmir2hll avoids redeclaring structures supplied by included C headers, including compiler-dependent cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100