Bruce-Lee-LY/cuda_hook

[Bug] code_generate has bug when parse parameter with *array type* like "int x[]"

chenzhuofu opened this issue · 1 comments

Description

I found that code_generate has bug when parse parameter with array type like "int x[]".

Reproduction

You can reproduce the bug using header file below:

void test_with_brackets_1(int x[]);

void test_with_brackets_2(int x[][5]);

The output of code_generate.py would be"

// auto generate 2 apis

#include "test_subset.h"
#include "hook.h"
#include "macro_common.h"
#include "trace_profile.h"

HOOK_C_API HOOK_DECL_EXPORT void test_with_brackets_1(int x) {
    HOOK_TRACE_PROFILE("test_with_brackets_1");
    using func_ptr = void (*)(int);
    static auto func_entry = reinterpret_cast<func_ptr>(HOOK_TEST_SYMBOL("test_with_brackets_1"));
    HOOK_CHECK(func_entry);
    return func_entry(x);
}

HOOK_C_API HOOK_DECL_EXPORT void test_with_brackets_2(int x) {
    HOOK_TRACE_PROFILE("test_with_brackets_2");
    using func_ptr = void (*)(int);
    static auto func_entry = reinterpret_cast<func_ptr>(HOOK_TEST_SYMBOL("test_with_brackets_2"));
    HOOK_CHECK(func_entry);
    return func_entry(x);
}

I fixed it in pr #10.

Just identify type [] by cppHeaderParser.CppVariable["array"], and then convert it into type *.

It works in my situation.