@@ -291,11 +291,11 @@ static void cast_if_not(Type *ty, Node **node) {
291291}
292292
293293static bool int_to_ptr (Node * * node ) {
294- if (!is_integer ((* node )-> ty ))
295- return false;
296- if ((* node )-> ty -> size != ty_nullptr -> size )
294+ if (is_integer ((* node )-> ty ) || (* node )-> ty -> kind == TY_BITINT ) {
297295 * node = new_cast (* node , pointer_to (ty_void ));
298- return true;
296+ return true;
297+ }
298+ return false;
299299}
300300
301301static bool match_enum_val (EnumVal * * e , int64_t val , Token * name ) {
@@ -584,6 +584,9 @@ bool is_nullptr(Node *node) {
584584 node -> ty -> kind == TY_PTR && is_compatible2 (node -> ty -> base , ty_void ))
585585 node = node -> m .lhs ;
586586
587+ if (node -> ty -> kind == TY_BITINT )
588+ return is_const_zero_bitint (node );
589+
587590 int64_t val ;
588591 return is_integer (node -> ty ) && is_const_expr (node , & val ) && val == 0 ;
589592}
@@ -643,10 +646,14 @@ static Type *cond_ptr_conv(Node **lhs, Node **rhs, Node **cond) {
643646 Type * ty1 = (* lhs )-> ty ;
644647 Type * ty2 = (* rhs )-> ty ;
645648
646- if (ty1 -> kind == TY_PTR && (int_to_ptr (rhs ) || is_nullptr (* rhs )))
649+ if (ty1 -> kind == TY_NULLPTR && ty2 -> kind == TY_NULLPTR )
650+ return ty_nullptr ;
651+
652+ if (ty1 -> kind == TY_PTR && is_ptr (ty2 ) && is_nullptr (* rhs ))
647653 return ty1 ;
648- if (ty2 -> kind == TY_PTR && ( int_to_ptr ( lhs ) || is_nullptr (* lhs ) ))
654+ if (ty2 -> kind == TY_PTR && is_ptr ( ty1 ) && is_nullptr (* lhs ))
649655 return ty2 ;
656+
650657 if (ty1 -> kind == TY_PTR && ty2 -> kind == TY_PTR ) {
651658 if (ty1 -> base -> kind == TY_VOID || ty2 -> base -> kind == TY_VOID )
652659 return pointer_to (qual_type (ty1 -> base -> qual | ty2 -> base -> qual , ty_void , NULL ));
@@ -656,10 +663,13 @@ static Type *cond_ptr_conv(Node **lhs, Node **rhs, Node **cond) {
656663
657664 return pointer_to (ty_void );
658665 }
659- if (ty1 -> kind == TY_NULLPTR && ty2 -> kind == TY_NULLPTR )
660- return ty_nullptr ;
661666
662- internal_error ();
667+ if (ty1 -> kind == TY_PTR && int_to_ptr (rhs ))
668+ return ty1 ;
669+ if (ty2 -> kind == TY_PTR && int_to_ptr (lhs ))
670+ return ty2 ;
671+
672+ error_tok ((* cond )-> tok , "invalid operand" );
663673}
664674
665675static void add_int_type (Node * node ) {
@@ -785,8 +795,9 @@ void add_type(Node *node) {
785795 node -> ty = ty_int ;
786796 ptr_convert (& node -> m .lhs );
787797 ptr_convert (& node -> m .rhs );
788- if ((is_ptr (node -> m .lhs -> ty ) && (is_ptr (node -> m .rhs -> ty ) || int_to_ptr (& node -> m .rhs ))) ||
789- (is_ptr (node -> m .rhs -> ty ) && (is_ptr (node -> m .lhs -> ty ) || int_to_ptr (& node -> m .lhs ))))
798+ if ((is_ptr (node -> m .lhs -> ty ) && is_ptr (node -> m .rhs -> ty )) ||
799+ (is_ptr (node -> m .lhs -> ty ) && int_to_ptr (& node -> m .rhs )) ||
800+ (is_ptr (node -> m .rhs -> ty ) && int_to_ptr (& node -> m .lhs )))
790801 return ;
791802 usual_arith_conv (& node -> m .lhs , & node -> m .rhs );
792803 return ;
0 commit comments