appleseedlab / superc

The SuperC Parsing Framework
24 stars 4 forks source link

conditional static def leads to wrong number of arguments #134

Open pattersonz opened 3 years ago

pattersonz commented 3 years ago

the following code:

int wdb_stmt_cache(int wdb, int index);

#ifdef WAZUH_UNIT_TESTING
#define static
#endif

static void wdbi_update_completion(int wdb) {
    if (wdb_stmt_cache(wdb, 1) == -1) {
        return;
    }
}

produces this output:

#include <stdbool.h>

extern void __static_type_error(char *msg);
extern void __static_renaming(char *renaming, char *original);
extern void __static_condition_renaming(char *expression, char *renaming);

TODO: record original presence condition strings in file as well once raw strings are collected
void __static_initializer_default();

extern const bool __static_condition_default_7;
extern const bool __static_condition_default_8;
extern const bool __static_condition_default_9;
void __static_initializer_default() {
__static_renaming("__wdb_stmt_cache_2", "wdb_stmt_cache");
__static_renaming("__wdbi_update_completion_5", "wdbi_update_completion");
__static_renaming("__wdbi_update_completion_6", "wdbi_update_completion");

__static_condition_renaming("__static_condition_default_7", "(declare-fun |(defined WAZUH_UNIT_TESTING)| () Bool)(assert |(defined WAZUH_UNIT_TESTING)|)");
__static_condition_renaming("__static_condition_default_8", "(declare-fun |(defined WAZUH_UNIT_TESTING)| () Bool)(assert (not |(defined WAZUH_UNIT_TESTING)|))");
__static_condition_renaming("__static_condition_default_9", "(declare-fun |(defined WAZUH_UNIT_TESTING)| () Bool)(assert (not |(defined WAZUH_UNIT_TESTING)|))");

};
TODO: account for bitfield sizes in forward refs

int  __wdb_stmt_cache_2 (int  __wdb_0, int  __index_1);
void  __wdbi_update_completion_5 (int  __wdb_3) {

if (__static_condition_default_7) {
{

{
if (__static_condition_default_7) {
if (  __wdb_stmt_cache_2  (  __wdb_3 , 1 ) == - 1 ) {
return  ;

}

}

if (__static_condition_default_8) {
if (  __wdb_stmt_cache_2  ( 1 ) == - 1 ) {
return  ;

}

}

}}

}

}
static void  __wdbi_update_completion_6 (int  __wdb_4) {

if (__static_condition_default_9) {
{

{
if (__static_condition_default_7) {
if (  __wdb_stmt_cache_2  (  __wdb_3 , 1 ) == - 1 ) {
return  ;

}

}

if (__static_condition_default_8) {
if (  __wdb_stmt_cache_2  ( 1 ) == - 1 ) {
return  ;

}

}

}}

}

}

This results in two definitions of wdb_update_completion. The function calls exist in in static_condition_default_7/8. In 8, the wrong number of arguments are used.

Also, in wdb_update_completion_6, wdb_3 is used in the call to wdb_stmt_cache_2, but wdb_4 is what is defined in the arg list.