@@ -107,12 +107,21 @@ void *simplify_env_emit_primitive_box_bool(SimplifyEnv *env, void *src) {
107107 return simplify_env_emit (env , instr );
108108}
109109
110- /* Helper: create HirType for CBool(val) with int specialization */
110+ /* Helper: create HirType with int specialization */
111+ static HirType make_int_spec_type (HirType base , intptr_t val ) {
112+ base .bits_and_flags |= ((uint64_t )HIR_SPEC_INT << HIR_TYPE_SPEC_SHIFT );
113+ base .int_val = val ;
114+ return base ;
115+ }
116+
111117static HirType make_cbool_type (intptr_t val ) {
112- HirType t = HIR_TYPE_CBOOL ;
113- t .bits_and_flags |= ((uint64_t )HIR_SPEC_INT << HIR_TYPE_SPEC_SHIFT );
114- t .int_val = val != 0 ? 1 : 0 ;
115- return t ;
118+ return make_int_spec_type (((HirType )HIR_TYPE_CBOOL ), val != 0 ? 1 : 0 );
119+ }
120+
121+ static HirType make_cint_type (HirType target_type , intptr_t val ) {
122+ uint64_t bits = target_type .bits_and_flags & HIR_TYPE_BITS_MASK ;
123+ HirType t = HIR_TYPE_SIMPLE (bits , HIR_TYPE_LIFETIME_BOTTOM );
124+ return make_int_spec_type (t , val );
116125}
117126
118127/* ---- simplifyCIntToCBool ----
@@ -194,6 +203,19 @@ void *simplify_int_convert_c(SimplifyEnv *env, const void *instr) {
194203 return NULL ;
195204}
196205
206+ /* ---- simplifyIsNegativeAndErrOccurred ----
207+ * If input is a LoadConst, we know no exception is active → result is 0. */
208+ void * simplify_is_neg_and_err_c (SimplifyEnv * env , const void * instr ) {
209+ void * input = hir_c_get_operand (instr , 0 );
210+ extern void * hir_reg_instr (void * reg );
211+ void * def = hir_reg_instr (input );
212+ if (def == NULL || hir_c_opcode (def ) != HIR_OP_LoadConst ) {
213+ return NULL ;
214+ }
215+ HirType output_type = hir_register_type (hir_c_output (instr ));
216+ return simplify_env_emit_load_const (env , make_cint_type (output_type , 0 ));
217+ }
218+
197219/* ---- simplifyCondBranch (partial — constant condition folding) ----
198220 * If condition is a known int constant, fold to unconditional Branch. */
199221void * simplify_cond_branch_const_c (SimplifyEnv * env , const void * instr ) {
0 commit comments