Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn test_afl_seed_{}() {{
// Ratcheting number that is increased as more libiberty tests start
// passing. Once they are all passing, this can be removed and we can enable all
// of them by default.
const LIBIBERTY_TEST_THRESHOLD: usize = 14;
const LIBIBERTY_TEST_THRESHOLD: usize = 20;

/// Read `tests/libiberty-demangle-expected`, parse its input mangled symbols,
/// and expected output demangled symbols, and generate test cases for them.
Expand Down
27 changes: 23 additions & 4 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,7 @@ impl Demangle for Encoding {

// To maintain compatibility with libiberty, print `()` instead
// of `(void)` for functions that take no arguments.
let void =
Type::Builtin(BuiltinType::Standard(StandardBuiltinType::Void));
if function_args.len() == 1 &&
ctx.subs.get_type(&function_args[0]) == Some(&void) {
if function_args.len() == 1 && function_args[0].is_void(ctx.subs) {
try!(write!(ctx, ")"));
return Ok(());
}
Expand Down Expand Up @@ -1573,11 +1570,26 @@ pub enum Type {
PackExpansion(TypeHandle),
}

impl Type {
fn is_void(&self) -> bool {
match *self {
Type::Builtin(BuiltinType::Standard(StandardBuiltinType::Void)) => true,
_ => false,
}
}
}

define_handle! {
/// A reference to a parsed `Type` production.
pub enum TypeHandle
}

impl TypeHandle {
fn is_void(&self, subs: &SubstitutionTable) -> bool {
subs.get_type(self).map_or(false, |ty| ty.is_void())
}
}

impl Parse for TypeHandle {
fn parse<'a, 'b>(subs: &'a mut SubstitutionTable,
input: IndexStr<'b>)
Expand Down Expand Up @@ -2101,6 +2113,13 @@ impl Demangle for BareFunctionType {
{
try!(self.ret().demangle(ctx, stack));
try!(write!(ctx, " ("));

// For libiberty compatibility, print `()` instead of `(void)`.
if self.args().len() == 1 && self.args()[0].is_void(ctx.subs) {
try!(write!(ctx, ")"));
return Ok(());
}

let mut need_comma = false;
for arg in self.args() {
if need_comma {
Expand Down