ltcmelo / psychec

A compiler frontend for the C programming language
BSD 3-Clause "New" or "Revised" License
529 stars 39 forks source link

Issue Compiling Separate C File in FFmpeg Using Psyche-C (Error: "Expected a Declaration") #143

Open CoffeeGeeker opened 3 days ago

CoffeeGeeker commented 3 days ago

Hello,

I am attempting to compile a separate C file in a project like FFmpeg in order to test a function modified by a submitted commit. I have exported all the C files using the tool available at [Angha's Export Tool](http://cuda.dcc.ufmg.br/angha/home).

I understand that Psyche-C can optionally infer and synthesize missing types during compilation. For example, Psyche-C can automatically generate a declaration for T as shown below:

void f() {
    T v = 0;
    v->value = 42;
    v->next = v;
}

So far, I have successfully compiled psychecgen and psychecsolver-exe from the original branch. However, when I run these tools on the extracted functions, I encounter the following error for most of the functions:

/root/data/collect_c/extracted_functions/libavcodec/extr_rootdatacollect_ccompilefileFFmpeg-05507348afa1c3ec53ecc1ba9061213a5154baddlibavcodecdnxhdenc.c_dnxhd_8bit_get_pixels_8x4_sym.c:15:2: error: expected a declaration

I would like to inquire whether this issue stems from my setup or if there are any known limitations or problems within Psyche-C that might be causing these errors.

Additionally, I am specifically focused on the read_header function within the libavcodec/ffv1dec.c file. The extracted file is located at:

extracted_functions/libavcodec/extr_rootdatacollect_ccompilefileFFmpeg-05507348afa1c3ec53ecc1ba9061213a5154baddlibavcodecffv1dec.c_read_header.c

For further reference, I have uploaded the relevant files. You can access them here: [Google Drive Link](https://drive.google.com/file/d/1sq6ykb-QgssbEfOliH06nQ2oea3MsvL-/view?usp=sharing).

If you have any time, I would greatly appreciate your assistance in checking this issue. Thank you in advance for your help.

Best regards

pronesto commented 2 days ago

Hi, CoffeeGeeker,

I understand that Psyche-C can optionally infer and synthesize missing types during compilation. For example, Psyche-C can automatically generate a declaration for T as shown below:

void f() {
    T v = 0;
    v->value = 42;
    v->next = v;
}

Yes. When I input your example into psyche-c, I get the following program:

#define NULL ((void*)0)
typedef unsigned long size_t;  // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__;  // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef  struct TYPE_2__   TYPE_1__ ;

/* Type definitions */
struct TYPE_2__ {int value; struct TYPE_2__* next; } ;
typedef  TYPE_1__* T ;

/* Variables and functions */

//-------------------------
void f() {
    T v = 0;
    v->value = 42;
    v->next = v;
}

I would like to inquire whether this issue stems from my setup or if there are any known limitations or problems within Psyche-C that might be causing these errors.

For that, I am not sure. Perhaps Leandro could take a look, in case he finds the time to get back into psyche-c.

CoffeeGeeker commented 2 days ago

Hi, pronesto, Thank you very much for your kind response. The example I mentioned earlier is from the one provided on the GitHub homepage. What I would like to discuss is an issue I encountered myself. Psyche-C can optionally (currently only available in the original branch) infer the missing types of a C snippet, and I was following this idea. The original repository indeed supplements missing types based on existing function information, and it seems that others have successfully done this. However, my attempts have failed, and I would like to understand why.

Additionally, I have an example from a single function (dlibavcodecffv1dec.c_read_header.c). Here is the link for reference: Google Drive link.

Thank you again for your assistance!

ltcmelo commented 2 days ago

Hi @CoffeeGeeker, I was able to infer and synthesize the missing types of the snippet that you provided with psychec; I'm pasting it below:

#define NULL ((void*)0)
typedef unsigned long size_t;  // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__;  // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef  struct TYPE_13__   TYPE_8__ ;
typedef  struct TYPE_12__   TYPE_3__ ;
typedef  struct TYPE_11__   TYPE_2__ ;
typedef  struct TYPE_10__   TYPE_1__ ;

/* Type definitions */
typedef  int /*<<< orphan*/  uint8_t ;
typedef  unsigned int uint64_t ;
typedef  int /*<<< orphan*/  state ;
struct TYPE_13__ {int coder_type; int bits_per_raw_sample; int /*<<< orphan*/  pix_fmt; } ;
struct TYPE_10__ {int /*<<< orphan*/  const* bytestream_start; int /*<<< orphan*/ * bytestream_end; scalar_t__* one_state; } ;
struct TYPE_12__ {int version; int ac; int colorspace; int plane_count; int chroma_planes; int chroma_h_shift; int chroma_v_shift; int transparency; int packed_at_lsb; int slice_count; int slice_x; int width; int slice_y; int height; int slice_width; int slice_height; int num_h_slices; int num_v_slices; int* context_count; int /*<<< orphan*/  quant_table; int /*<<< orphan*/ * quant_tables; TYPE_8__* avctx; scalar_t__ quant_table_count; TYPE_2__* plane; scalar_t__ slice_damaged; struct TYPE_12__** slice_context; int /*<<< orphan*/  ec; scalar_t__* state_transition; TYPE_1__ c; } ;
struct TYPE_11__ {int quant_table_index; int context_count; int /*<<< orphan*/  vlc_state; int /*<<< orphan*/  state; int /*<<< orphan*/  quant_table; } ;
typedef  TYPE_1__ RangeCoder ;
typedef  TYPE_2__ PlaneContext ;
typedef  TYPE_3__ FFV1Context ;

/* Variables and functions */
 int AVERROR (int /*<<< orphan*/ ) ; 
 int AVERROR_INVALIDDATA ; 
 int /*<<< orphan*/  AV_LOG_ERROR ; 
 int /*<<< orphan*/  AV_PIX_FMT_0RGB32 ; 
 int /*<<< orphan*/  AV_PIX_FMT_GBRP10 ; 
 int /*<<< orphan*/  AV_PIX_FMT_GBRP12 ; 
 int /*<<< orphan*/  AV_PIX_FMT_GBRP14 ; 
 int /*<<< orphan*/  AV_PIX_FMT_GBRP9 ; 
 int /*<<< orphan*/  AV_PIX_FMT_GRAY16 ; 
 int /*<<< orphan*/  AV_PIX_FMT_GRAY8 ; 
 int /*<<< orphan*/  AV_PIX_FMT_RGB32 ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV410P ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV411P ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV420P ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV420P10 ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV420P16 ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV420P9 ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV422P ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV422P10 ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV422P16 ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV422P9 ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV440P ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV444P ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV444P10 ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV444P16 ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUV444P9 ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUVA420P ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUVA422P ; 
 int /*<<< orphan*/  AV_PIX_FMT_YUVA444P ; 
 int AV_RB24 (int /*<<< orphan*/  const*) ; 
 int CONTEXT_SIZE ; 
 int /*<<< orphan*/  ENOSYS ; 
 scalar_t__ MAX_SLICES ; 
 int /*<<< orphan*/  av_assert0 (int) ; 
 int /*<<< orphan*/  av_dlog (TYPE_8__*,char*,int,int,int /*<<< orphan*/ ) ; 
 int /*<<< orphan*/  av_freep (int /*<<< orphan*/ *) ; 
 int /*<<< orphan*/  av_log (TYPE_8__*,int /*<<< orphan*/ ,char*,...) ; 
 int get_rac (TYPE_1__* const,int /*<<< orphan*/ *) ; 
 int get_symbol (TYPE_1__* const,int /*<<< orphan*/ *,int) ; 
 int /*<<< orphan*/  memcpy (int /*<<< orphan*/ ,int /*<<< orphan*/ ,int) ; 
 int /*<<< orphan*/  memset (int /*<<< orphan*/ *,int,int) ; 
 int read_quant_tables (TYPE_1__* const,int /*<<< orphan*/ ) ; 

If you paste this content into a header file.h, #include "file.h" from your snippet's file, and compile it (e.g. with gcc -c …), the compilation should succeed.

How you did you invoke psychec? You should do so through the reconstruct.py script, i.e. ./reconstruct snippet.c (files snippet_gen.h and snippet_fixed.c will be produced).

Also, are you able to make psychec work with its README's example (the one refer to in your first post)?

CoffeeGeeker commented 2 days ago

hello,ltcmelo, Thank you very much for your help earlier! After testing with the latest version, I can confirm that your solution is indeed useful. I would like to generate symbol information during compilation for debugging purposes. For example, when using gcc, I want to compile with symbol information using the -g flag, but I'm encountering errors such as those shown when using -g.

Previously, I had tested with the original repository and compiled it using this script: Google Drive Link to Script.

In my earlier attempts, I used a reference from this link for extracting functions. Despite those efforts, the script and compiled files, which are included in the link, did not work as expected.

I apologize for not testing the latest version sooner and for any confusion caused. Your assistance on this would be greatly appreciated.

Thank you once again for your continued support!

Best regards, CoffeeGeeker

CoffeeGeeker commented 1 day ago

hello,ltcmelo, I realize I misunderstood the original post. I have now completed the code supplement and compilation from the original branch, and it's working fine. Thank you! I've exported many functions, but they are not independent. Is it possible to call existing functions within the folder to supplement additional functions?

Thanks again!