Skip to content

Commit

Permalink
cc: correct processing of W106 and enable it
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalak committed Apr 24, 2024
1 parent e098933 commit d4f8cf9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
44 changes: 20 additions & 24 deletions bld/cc/c/ccheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,12 @@ bool CheckZero( TREEPTR tree )
}

bool CheckAssignBits( uint64 *val, unsigned width, bool mask )
/*************************************************************
* check if value of val fit into specified width bit-size
* if mask is true then value is AND by width bit-size mask
*
* return true if val value doesn't fit into width bit-size otherwise false
*/
{
uint64 max;
bool overflow;
Expand Down Expand Up @@ -777,6 +783,11 @@ bool CheckAssignBits( uint64 *val, unsigned width, bool mask )
}

bool CheckAssignRange( TYPEPTR typ1, TREEPTR opnd2 )
/*************************************************************
* check if value of opnd2 fit into target type of typ1
*
* return true if opnd2 value doesn't fit into typ1 otherwise false
*/
{
uint64 val64;
unsigned width;
Expand All @@ -785,7 +796,7 @@ bool CheckAssignRange( TYPEPTR typ1, TREEPTR opnd2 )
typ1 = SkipTypeFluff( typ1 );
if( typ1->decl_type == TYP_LONG64
|| typ1->decl_type == TYP_ULONG64 ) {
return( true );
return( false );
}
if( opnd2->u.expr_type->decl_type == TYP_LONG64
|| opnd2->u.expr_type->decl_type == TYP_ULONG64 ) {
Expand All @@ -803,38 +814,23 @@ bool CheckAssignRange( TYPEPTR typ1, TREEPTR opnd2 )
case TYP_BOOL:
width = 1;
break;
case TYP_CHAR:
case TYP_UCHAR:
width = 1 * CHAR_BIT;
break;
#if TARGET_INT == TARGET_SHORT
case TYP_INT:
case TYP_UINT:
#endif
case TYP_SHORT:
case TYP_USHORT:
width = 2 * CHAR_BIT;
break;
#if TARGET_INT == TARGET_LONG
case TYP_INT:
case TYP_UINT:
#endif
case TYP_LONG:
case TYP_ULONG:
width = 4 * CHAR_BIT;
default:
width = TypeSize( typ1 ) * CHAR_BIT;
if( width >= 64 )
return( false );
break;
}
if( CheckAssignBits( &val64, width, false ) ) {
return( false );
return( true );
}
} else if( opnd2->op.opr == OPR_PUSHFLOAT ) {
if( typ1->decl_type == TYP_FLOAT ) {
if( atof( opnd2->op.u2.float_value->string ) > TARGET_FLT_MAX ) {
return( false );
return( true );
}
}
}
return( true );
return( false );
}

static bool IsPtrtoFunc( TYPEPTR typ )
Expand Down Expand Up @@ -973,7 +969,7 @@ void CheckParmAssign( TYPEPTR typ1, TREEPTR opnd2, int parmno, bool asgn_check )
}
case OK:
if( asgn_check ) {
if( !CheckAssignRange( typ1, opnd2 ) ) {
if( CheckAssignRange( typ1, opnd2 ) ) {
CWarnP1( parmno, ERR_CONSTANT_TOO_BIG );
}
}
Expand Down
2 changes: 1 addition & 1 deletion bld/cc/c/cmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ TREEPTR BinOp( TREEPTR op1, TOKEN opr, TREEPTR op2 )
/*
* if op2 is a constant, check to see if constant truncated
*/
if( !CheckAssignRange( typ, op2 ) ) {
if( CheckAssignRange( typ, op2 ) ) {
CWarn1( ERR_CONSTANT_TOO_BIG );
}
/* fall through */
Expand Down
6 changes: 1 addition & 5 deletions bld/cc/c/coptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*
* Open Watcom Project
*
* Copyright (c) 2002-2023 The Open Watcom Contributors. All Rights Reserved.
* Copyright (c) 2002-2024 The Open Watcom Contributors. All Rights Reserved.
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
Expand Down Expand Up @@ -956,10 +956,6 @@ void GenCOptions( char **cmdline )
{
OPT_STORAGE data;

/*
* temporary disabled
*/
WarnEnableDisable( false, ERR_CONSTANT_TOO_BIG );
/*
* Add precision warning but disabled by default
*/
Expand Down

0 comments on commit d4f8cf9

Please sign in to comment.