Skip to content

Commit

Permalink
c++: add More GNU v2/v3 Tests (#68)
Browse files Browse the repository at this point in the history
* Add more GNU v3 Tests
* Add GNU v2 Tests
* Add tests from libiberty
* Split to RZ_DEMANGLE_OPT_BASIC & RZ_DEMANGLE_OPT_ENABLE_ALL tests

Some tests were failing because of regex replacement performed after
demangling, to simplify the demangled output. Thec c++ tests are now
split into two parts : test_cxx.c and test_cxx_base.c

Full discussion can be viewed in the thread here :
https://im.rizin.re/rizinorg/pl/prasfjqxc3fgb8uxxoh565ku4w
  • Loading branch information
brightprogrammer authored Dec 23, 2024
1 parent b15c0f6 commit d3083c1
Show file tree
Hide file tree
Showing 7 changed files with 30,337 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build*/
build*/
.cache/
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ if get_option('use_gpl')
libdemangle_src += 'src' / 'gnu_v2' / 'cplus-dem.c'
common_c_args += '-DWITH_GPL=1'
tests += 'cxx'
tests += 'cxx_base'
tests += 'cxx_gnu_v2'
endif

Expand Down Expand Up @@ -100,4 +101,4 @@ if get_option('enable_tests') and not meson.is_subproject()
)
test(test, exe)
endforeach
endif
endif
4 changes: 2 additions & 2 deletions src/cxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// ansidecl.h makes a mess with the definition of
// const. thus we directly avoid to import the
// demangle.h header and instead define the data here.
#define DMGL_PARAMS (1 << 0) /* Include function args */
#define DMGL_PARAMS (1 << 0) | (1 << 1) /* Include function args and ANSI qualifiers */

char *cplus_demangle_v3(const char *mangled, int options);
char *cplus_demangle_v2(const char *mangled, int options);
Expand Down Expand Up @@ -69,7 +69,7 @@ typedef struct cxx_replace_pair_t {
{ "std::regex_search<" t ">", "std::regex_search<" t ", std::allocator<std::" p "csub_match >, std::regex_traits<" t "> >" }, \
{ "std::regex_search<" t ">", "std::regex_search<" t " const*, std::allocator<std::" p "csub_match >, " t ", std::regex_traits<" t "> >" }, \
{ "std::regex_search<" t ">", "std::regex_search<iterator<" t ">, std::allocator<std::" p "csub_match >, " t ", std::regex_traits<" t "> >" }, \
{ "std::regex_search<std::" p "string>", "std::regex_search<std::char_traits<" t ">, std::allocator<" t ">, std::allocator<std::" p "csub_match >, " t ", std::regex_traits<" t "> >" }
{ "std::regex_search<std::" p "string>", "std::regex_search<std::char_traits<" t ">, std::allocator<" t ">, std::allocator<std::" p "csub_match >, " t ", std::regex_traits<" t "> >" }

static const CxxReplacePair cplus_typedefs[] = {
STD_BASIC_WITH_ALLOC_CHAR("string", "string"),
Expand Down
18 changes: 13 additions & 5 deletions src/gnu_v2/cplus-dem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,8 +1075,9 @@ demangle_template_template_parm(struct work_stuff *work, const char **mangled, s
need_comma = 1;
}
}
if (tname->p[-1] == '>')
string_append(tname, " ");
// test cases failing because of this space
// if (tname->p[-1] == '>')
// string_append(tname, " ");
string_append(tname, "> class");
return (success);
}
Expand Down Expand Up @@ -1422,8 +1423,9 @@ demangle_template(struct work_stuff *work, const char **mangled, string *tname,
if (is_java_array) {
string_append(tname, "[]");
} else {
if (tname->p[-1] == '>')
string_append(tname, " ");
// Test cases failing because of this extra space
// if (tname->p[-1] == '>')
// string_append(tname, " ");
string_append(tname, ">");
}

Expand Down Expand Up @@ -2498,8 +2500,14 @@ do_type(struct work_stuff *work, const char **mangled, string *result)
(*mangled)++;
break;

case 'M':
case 'O': {
(*mangled)++;
string_prepend(&decl, "&&");
if (tk == tk_none)
tk = tk_reference;
break;
}
case 'M': {
type_quals = TYPE_UNQUALIFIED;

member = **mangled == 'M';
Expand Down
25,988 changes: 25,969 additions & 19 deletions test/test_cxx.c

Large diffs are not rendered by default.

3,999 changes: 3,999 additions & 0 deletions test/test_cxx_base.c

Large diffs are not rendered by default.

352 changes: 350 additions & 2 deletions test/test_cxx_gnu_v2.c

Large diffs are not rendered by default.

0 comments on commit d3083c1

Please sign in to comment.