You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Function dependencies not respected with --disable-main #1727
$ clang x.c
x.c:41:9: error: implicit declaration of function 'f' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
a = f();
^
1 error generated.
The issue is that main1 depends on f, but f gets generated below the function. It only happens when --disable-main is used, but we need to use it.
I am not sure how to best test this in integration tests, due to the --disable-main. The @ccallback is needed, otherwise the function gets treated as unused.
Its a problem with pass_wrap_global_stmts_into_program. It only shifts user defined functions into _global_symbols (generated module) only when they are called. In your case main1 is never called so it stays in the global scope. Now C backend first visits all the functions in global scope and since main1 lies in global scope so C code of it is generated first. Then f is generated when the modules are visited. If main1 is shifted to _global_symbols then it depends on import_order_01 and hence f will always be generated before main1 (which is correct).
End moral - So, IMO global scope should only contain intrinsic functions generated by libasr in intrinsic_function_registry.h. All user defined functions should be shifted to _global_symbols modules irrespective of the fact whether they are called by the user or not.
Activity
certik commentedon Apr 21, 2023
I am not sure how to best test this in integration tests, due to the
--disable-main. The@ccallbackis needed, otherwise the function gets treated as unused.czgdp1807 commentedon Apr 21, 2023
The
--disable-maindoesn't matter. Even without it,f()goes belowmain1,czgdp1807 commentedon Apr 21, 2023
Its a problem with
pass_wrap_global_stmts_into_program. It only shifts user defined functions into_global_symbols(generated module) only when they are called. In your casemain1is never called so it stays in the global scope. Now C backend first visits all the functions in global scope and sincemain1lies in global scope so C code of it is generated first. Thenfis generated when the modules are visited. Ifmain1is shifted to_global_symbolsthen it depends onimport_order_01and hencefwill always be generated beforemain1(which is correct).End moral - So, IMO global scope should only contain intrinsic functions generated by
libasrinintrinsic_function_registry.h. All user defined functions should be shifted to_global_symbolsmodules irrespective of the fact whether they are called by the user or not.