From 2e83ec9d31b25bdd34e39003038cc0b67c87ae2a Mon Sep 17 00:00:00 2001 From: Chris Smowton Date: Thu, 7 Jun 2018 14:06:46 +0100 Subject: [PATCH] Zero-initialize Class literals before calling initializer function This (a) sets the class-identifier to "java.lang.Class," which wasn't being done before, and allows the class initializer to assume fields are nulled before entry, as for a normal constructor. --- .../regression/jbmc/class-literals/Test.class | Bin 1263 -> 1646 bytes jbmc/regression/jbmc/class-literals/Test.java | 17 ++++++++++++++ jbmc/src/java_bytecode/java_entry_point.cpp | 21 ++++++++++++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/jbmc/regression/jbmc/class-literals/Test.class b/jbmc/regression/jbmc/class-literals/Test.class index ef7d26bc773c3f56d66c6ea0686d47653139b1ed..c6ca2351f0ddd9e81137e371e1bf82e94187ca4d 100644 GIT binary patch literal 1646 zcmZ{lOHUI~6vzMfws5EI0PPe?kvF39eu+;Ic`FFGC^0GsegdK! z6XVuLQj8`VH!fWG30(RKT)Hrxi$xlGoyC7Tzd1dxdrs!-@An@83}Y#bW^{+ph#rAn zfj)u$Fv`#^Fd#4}FeGqRU|8Usza>3Npx+d0RZwmow-W34f;yA0){wqyHa41tc$TMWUe+?vHuwO~8e z(pGlWa+jqsy~vuj!%&g(&Gf@XbF+Z8(R8NZAe_o=xoKl%k%p-%xzOg8&2wI zK`TRS=8>7*%vckSlk-iP4TX|M{Tb6)@1M$0mJG=wGI5yojO*rHhG@aToa0;WeKSpw zA_X+#Y-NuOQag_S!1C=h17Devl9DnfWnRjx6zU9Lp(eyv7LH=xT-~tJ{s=?$iURAH z!K{vJQm#vxlQJ*m1{SDKvTz-Xpa9Y1P8oFDD=wazPT?cAS5#2B?ftEVa8Vh8{^`2r z4ue>?{3SC>wO4m^7A2nYUE5iw#1m_lXS>$gzwXhY`CA@ZY37<~23a&I&x3viz~u3e zw$oE1-5K4>y7s|dOGBI@EkA%9A)G!m4Wz*74fwM+;CqN0fzJr;A@TubclJ^KsX&F2 zYDyYX(y)?7lvG#J3MH*n(kdm5Drrnf4J8fa5m$64kLpsY}Xo!0d#v~%R4IK_Du!~CUp$e}M#TUfz9R_|P&NNiBCM4J}YS}!J>>ldaHtN|E zG_dDrWbe?#zM+}@KnweYRvtwgrv>4o=;h1k;~DhxT@3K27{VFKqyBomUL7!*Y%phOh$0&-6j1YCr&R8~XM#KB}j%}gxW`xMz* zZoO26Dy`C;3tzyEPvHYto*olIk(tFg-Cv*XKIi;BKmUID24Du8VWg1>VF=?K6JcD# zb&km}g2-@W<@^T6l=L?_Zb?7Qaa;NsjyoK8Iqq@X=a}V~<9NU^FBcaSOen}InBrKJ zV2NXyAwH_xwy+$dX4K+6|2ZG49ehaMK{aYrFO14%c@xn(bl##(-GF5UKA?wa!aJeb7sA& z;-N(C(88hVycCX6RPji1-wxfg_J356(=}<wfNvHib +#include #include #include +#include #include #include @@ -117,7 +119,8 @@ static void java_static_lifetime_init( bool assume_init_pointers_not_null, const object_factory_parameterst &object_factory_parameters, const select_pointer_typet &pointer_type_selector, - bool string_refinement_enabled) + bool string_refinement_enabled, + message_handlert &message_handler) { symbolt &initialize_symbol=*symbol_table.get_writeable(INITIALIZE_FUNCTION); code_blockt &code_block=to_code_block(to_code(initialize_symbol.value)); @@ -188,6 +191,19 @@ static void java_static_lifetime_init( args.push_back( constant_bool(class_symbol.type.get_bool(ID_enumeration))); + // First initialize the object as prior to a constructor: + namespacet ns(symbol_table); + + exprt zero_object = + zero_initializer( + sym.type, source_locationt(), ns, message_handler); + set_class_identifier( + to_struct_expr(zero_object), ns, to_symbol_type(sym.type)); + + code_block.copy_to_operands( + code_assignt(sym.symbol_expr(), zero_object)); + + // Then call the init function: code_block.move_to_operands(initializer_call); } else if(sym.value.is_nil() && sym.type!=empty_typet()) @@ -530,7 +546,8 @@ bool java_entry_point( assume_init_pointers_not_null, object_factory_parameters, pointer_type_selector, - string_refinement_enabled); + string_refinement_enabled, + message_handler); return generate_java_start_function( symbol,