Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run InvokeWrappingPass before AllocaLoweringPass #240

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

DutChen18
Copy link
Member

When rewriting calls to variadic functions, AllocaLowering only handles call instructions, not invoke instructions. By moving InvokeWrapping before AllocaLowering, the problematic invokes are converted to calls before AllocaLowering is run.

This fixes an issue with exceptions and variadic arguments:

extern "C" {
        int printf(const char *__restrict, ...);
}
struct Struct
{
        static void func();
};

class ArgParse {
public:
        ~ArgParse ();
        int options (const char *intro, ...) /*noexcept*/;
};

int ArgParse::options (const char *intro, ...) /*noexcept*/
{
        __builtin_va_list ap;
        __builtin_va_start(ap, intro);
        const char *cur = __builtin_va_arg(ap, char *);
        printf("Variadic %s\n", cur);
        Struct::func();
        return 0;
}

void webMain()
{
        ArgParse ap;
        ap.options ("", "__GOOD__");
}
/opt/cheerp/bin/clang++ --target=cheerp-wasm -O2 -o test.js test.cpp -cheerp-pretty-code -fexceptions && nodejs test.js

Before: Variadic (null)
After: Variadic __GOOD__

When rewriting calls to variadic functions, AllocaLowering only handles
call instructions, not invoke instructions. By moving InvokeWrapping
before AllocaLowering, the problematic invokes are converted to calls
before AllocaLowering is run.
@DutChen18 DutChen18 requested a review from yuri91 June 24, 2024 16:07
@yuri91 yuri91 merged commit bd1858b into master Jun 25, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants