From 4cd46a298c6611dd169eeae3ef7412f0c3af3289 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 1 Jan 2017 15:16:22 +0800 Subject: Codegen C - Handle function pointers cast to raw pointers in literals --- src/trans/codegen_c.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/trans/codegen_c.cpp') diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 3bd8d475..82b78dd8 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -584,9 +584,25 @@ namespace { m_of << e; ), (BorrowOf, - // TODO: Get the pointed-to item type - if( ! ty.m_data.is_Function() ) + TU_MATCHA( (e.m_data), (pe), + (Generic, + if( ! m_crate.get_valitem_by_path(sp, pe.m_path).is_Function() ) + m_of << "&"; + else if( !ty.m_data.is_Function() ) // TODO: Ensure that the type is `*const ()` or similar. + m_of << "(void*)"; + else + ; + ), + (UfcsUnknown, + MIR_BUG(*m_mir_res, "UfcsUnknown in trans " << e); + ), + (UfcsInherent, m_of << "&"; + ), + (UfcsKnown, + m_of << "&"; + ) + ) m_of << Trans_Mangle( params.monomorph(m_resolve, e)); ), (String, -- cgit v1.2.3