Skip to content

Commit

Permalink
Fix integral->pointer casting
Browse files Browse the repository at this point in the history
  • Loading branch information
bobrippling committed Feb 16, 2024
1 parent ae03e35 commit 03f60e3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/cc1/ops/expr_cast.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>

#include "ops.h"
#include "../../util/alloc.h"
Expand Down Expand Up @@ -165,9 +166,14 @@ static integral_t convert_integral_to_integral_warn(
const int signed_in = type_is_signed(tin);
const int signed_out = type_is_signed(tout);
sintegral_t to_iv_sign_ext;
integral_t to_iv = integral_truncate(in, sz_out, &to_iv_sign_ext);
integral_t to_iv;
integral_t ret;

assert(type_is_integral(tin));
assert(type_is_integral(tout));

to_iv = integral_truncate(in, sz_out, &to_iv_sign_ext);

if(!signed_out && signed_in){
const unsigned sz_in_bits = CHAR_BIT * sz_in;
const unsigned sz_out_bits = CHAR_BIT * sz_out;
Expand Down Expand Up @@ -349,7 +355,8 @@ static void fold_const_expr_cast(expr *e, consty *k)
break;

case CONST_NUM:
fold_cast_num(e, &k->bits.num);
if(type_is_integral(e->tree_type))
fold_cast_num(e, &k->bits.num);
break;

case CONST_NEED_ADDR:
Expand Down

0 comments on commit 03f60e3

Please sign in to comment.