ltcmelo / psychec

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

Cannot use `cnip` to complete the missing code, and `cnip test.c` produces no output. #155

Open guye opened 1 month ago

guye commented 1 month ago

Description Using cnip test.c produces no output. The content of test.c is as follows: int main() { T a = 0; T->value = 3.14; T->next = a; return 0; }

Version (https://github.com/ltcmelo/psychec/commit/e0e6e05fe65c3c60b2557ab42663e220f1dd72a2)

Expected behavior Output the completed code.

pronesto commented 1 month ago

Hi!

Using psyche-c's online interface I get:

#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__ {double value; int /*<<< orphan*/  next; } ;
typedef  int /*<<< orphan*/  T ;

/* Variables and functions */
 TYPE_1__* T ; 

//-------------------------
int main()
{
T a = 0;
T->value = 3.14;
T->next = a;
return 0;
}

Is cnip working at all in your environment? Do you see any error message?

ltcmelo commented 1 month ago

@guye for type inference you should use the reconstruct.py script from the original branch (as in this screenshot from the README).

guye commented 3 weeks ago

Sorry, it was my mistake. Previously, I was compiling in the Cygwin environment on Windows, and I could compile cnip on the master branch, but I couldn't use reconstruct.py. After switching to the original branch, the compilation failed in the Cygwin environment. Therefore, I switched to the Ubuntu 22.04 environment, and encountered some minor issues during compilation, as follows:

/usr/include/x86_64-linux-gnu/c++/11/bits/c++config.h:280:33: note: ‘std::size_t’ declared here
  280 |   typedef __SIZE_TYPE__         size_t;
      |                                 ^~~~~~
/home/zenkoo/opensource/psychec/frontend/Symbols.cpp:594:24: error: ‘i’ was not declared in this scope
  594 |     for (size_t i = 0; i < original->_baseClasses.size(); ++i)
      |                        ^
At global scope:

After simply handling the errors, the compilation was successful, but when calling ./reconstruct.py test.c, another issue occurred, as shown below:

Traceback (most recent call last):
  File "./reconstruct.py", line 70, in <module>
    analyser.analyse()
  File "./reconstruct.py", line 60, in analyse
    self.solve_constraints()
  File "./reconstruct.py", line 41, in solve_constraints
    "-o", "../%s" % self.gen_file_name])
  File "/usr/lib/python2.7/subprocess.py", line 172, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

ENV: Python 2.7.18 gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 original branch commit 4322192336d

ltcmelo commented 3 weeks ago

I suspect that either the generator or solver might have not been build. You could check whether files psychecgen and psychecsolver-exe are present in your directory; if they aren't, then there's still an issue in your environment. For the solver, you'd need to setup Haskell in your system (keep in mind that Psyche's environment is older than that for Ubuntu 22.04).