Fix __int64 bitnot bug.

This commit is contained in:
Shpoike 2023-04-17 03:40:43 +01:00
parent 0a565b1186
commit 7b3096bbf5
3 changed files with 83 additions and 17 deletions

View file

@ -944,6 +944,7 @@ enum {
ERR_BADPLUSPLUSOPERATOR, ERR_BADPLUSPLUSOPERATOR,
ERR_BADNOTTYPE, ERR_BADNOTTYPE,
ERR_BADTYPECAST, ERR_BADTYPECAST,
ERR_BADMEMBER,
ERR_MULTIPLEDEFAULTS, ERR_MULTIPLEDEFAULTS,
ERR_CASENOTIMMEDIATE, ERR_CASENOTIMMEDIATE,
ERR_BADSWITCHTYPE, ERR_BADSWITCHTYPE,

View file

@ -4600,6 +4600,12 @@ QCC_sref_t QCC_PR_StatementFlags ( QCC_opcode_t *op, QCC_sref_t var_a, QCC_sref_
return var_c; return var_c;
} }
break; break;
case OP_BITNOT_I64:
op = &pr_opcodes[OP_SUB_I64];
var_b = var_a;
var_a = QCC_MakeInt64Const(~(longlong)0);
var_a.sym->referenced = true;
break;
case OP_BITNOT_F: case OP_BITNOT_F:
op = &pr_opcodes[OP_SUB_F]; op = &pr_opcodes[OP_SUB_F];
var_b = var_a; var_b = var_a;
@ -5905,7 +5911,7 @@ static void QCC_PrecacheFile (const char *n, int ch)
static void QCC_VerifyFormatString (const char *funcname, QCC_ref_t **arglist, unsigned int argcount) static void QCC_VerifyFormatString (const char *funcname, QCC_ref_t **arglist, unsigned int argcount)
{ {
const char *s = "%s"; const char *s = "%s", *reqtype;
int firstarg = 1; int firstarg = 1;
const char *s0; const char *s0;
char *err; char *err;
@ -6072,6 +6078,7 @@ noflags:
//case 'll': //long long //case 'll': //long long
case 'l': isfloat = 0; break; //long case 'l': isfloat = 0; break; //long
case 'L': isfloat = 0; break; //long double case 'L': isfloat = 0; break; //long double
//case 'q': break; //long long in c
case 'j': //[u]intmax_t case 'j': //[u]intmax_t
case 'z': //size_t case 'z': //size_t
case 't': //ptrdiff_t case 't': //ptrdiff_t
@ -6109,6 +6116,7 @@ nolength:
memcpy(formatbuf, s0, s+1-s0); memcpy(formatbuf, s0, s+1-s0);
formatbuf[s+1-s0] = 0; formatbuf[s+1-s0] = 0;
reqtype = NULL;
switch(*s) switch(*s)
{ {
//fixme: should we validate char ranges? //fixme: should we validate char ranges?
@ -6123,9 +6131,7 @@ nolength:
case ev_variant: case ev_variant:
break; break;
default: default:
{ reqtype = "float";
QCC_PR_ParseWarning(WARN_FORMATSTRING, "%s: %s%s%s requires float at arg %i (got %s%s%s)", funcname, col_name, formatbuf, col_none, thisarg+1, col_type, TypeName(ARGCTYPE(thisarg), temp, sizeof(temp)), col_none);
}
break; break;
} }
} }
@ -6139,7 +6145,7 @@ nolength:
case ev_variant: case ev_variant:
break; break;
default: default:
QCC_PR_ParseWarning(WARN_FORMATSTRING, "%s: %s%s%s requires pointer at arg %i (got %s%s%s)", funcname, col_name, formatbuf, col_none, thisarg+1, col_type, TypeName(ARGCTYPE(thisarg), temp, sizeof(temp)), col_none); reqtype = "pointer";
break; break;
} }
} }
@ -6156,6 +6162,7 @@ nolength:
break; break;
//fallthrough //fallthrough
default: default:
reqtype = "int";
QCC_PR_ParseWarning(WARN_FORMATSTRING, "%s: %s%s%s requires int at arg %i (got %s%s%s)", funcname, col_name, formatbuf, col_none, thisarg+1, col_type, TypeName(ARGCTYPE(thisarg), temp, sizeof(temp)), col_none); QCC_PR_ParseWarning(WARN_FORMATSTRING, "%s: %s%s%s requires int at arg %i (got %s%s%s)", funcname, col_name, formatbuf, col_none, thisarg+1, col_type, TypeName(ARGCTYPE(thisarg), temp, sizeof(temp)), col_none);
break; break;
} }
@ -6171,12 +6178,12 @@ nolength:
case ev_variant: case ev_variant:
break; break;
default: default:
QCC_PR_ParseWarning(WARN_FORMATSTRING, "%s: %s%s%s requires vector at arg %i (got %s%s%s)", funcname, col_name, formatbuf, col_none, thisarg+1, col_type, TypeName(ARGCTYPE(thisarg), temp, sizeof(temp)), col_none); reqtype = "vector";
break; break;
} }
} }
else else
QCC_PR_ParseWarning(WARN_FORMATSTRING, "%s: %s%s%s requires intvector at arg %i (got %s%s%s)", funcname, col_name, formatbuf, col_none, thisarg+1, col_type, TypeName(ARGCTYPE(thisarg), temp, sizeof(temp)), col_none); reqtype = "intvector";
break; break;
case 's': case 's':
case 'S': case 'S':
@ -6186,7 +6193,7 @@ nolength:
case ev_variant: case ev_variant:
break; break;
default: default:
QCC_PR_ParseWarning(WARN_FORMATSTRING, "%s: %s%s%s requires string at arg %i (got %s%s%s)", funcname, col_name, formatbuf, col_none, thisarg+1, col_type, TypeName(ARGCTYPE(thisarg), temp, sizeof(temp)), col_none); reqtype = "string";
break; break;
} }
break; break;
@ -6194,6 +6201,52 @@ nolength:
QCC_PR_ParseWarning(WARN_FORMATSTRING, "%s: invalid format string: %s%s%s", funcname, col_name, s0, col_none); QCC_PR_ParseWarning(WARN_FORMATSTRING, "%s: invalid format string: %s%s%s", funcname, col_name, s0, col_none);
return; return;
} }
if (reqtype)
{
QCC_PR_ParseWarning(WARN_FORMATSTRING, "%s: %s%s%s requires %s at arg %i (got %s%s%s)", funcname, col_name, formatbuf, col_none, reqtype, thisarg+1, col_type, TypeName(ARGCTYPE(thisarg), temp, sizeof(temp)), col_none);
switch(ARGCTYPE(thisarg)->type)
{
case ev_string:
QCC_PR_Note(WARN_FORMATSTRING, s_filen, pr_source_line, "%s", "use %s or %S for strings");
break;
case ev_float:
QCC_PR_Note(WARN_FORMATSTRING, s_filen, pr_source_line, "%s", "use %g or %f or %hx for floats");
break;
case ev_vector:
QCC_PR_Note(WARN_FORMATSTRING, s_filen, pr_source_line, "%s", "use %v for vectors");
break;
case ev_entity:
QCC_PR_Note(WARN_FORMATSTRING, s_filen, pr_source_line, "%s", "use %i for entities");
break;
case ev_pointer:
QCC_PR_Note(WARN_FORMATSTRING, s_filen, pr_source_line, "%s", "use %p for pointer types");
break;
case ev_integer:
QCC_PR_Note(WARN_FORMATSTRING, s_filen, pr_source_line, "%s", "use %i or %lx for 32bit ints");
break;
case ev_uint:
QCC_PR_Note(WARN_FORMATSTRING, s_filen, pr_source_line, "%s", "use %lu or or %lx for 32bit ints");
break;
case ev_void: //coder's problem
case ev_field: //cast to int
case ev_function: //cast to int
case ev_variant: //should be accepted by anything...
case ev_int64: //specification problem
case ev_uint64: //specification problem
case ev_double: //specification problem
case ev_struct: //coder's problem
case ev_union: //coder's problem
case ev_accessor: //should be unreachable
case ev_enum: //should be unreachable
case ev_typedef: //should be unreachable
case ev_boolean: //should be unreachable
QCC_PR_Note(WARN_FORMATSTRING, s_filen, pr_source_line, "%s", "cast to something else");
break;
}
}
s++; s++;
break; break;
default: default:
@ -8963,9 +9016,9 @@ static QCC_ref_t *QCC_PR_ParseField(QCC_ref_t *refbuf, QCC_ref_t *lhs)
return refbuf; return refbuf;
} }
if (t->parentclass) if (t->parentclass)
QCC_PR_ParseError(ERR_INTERNAL, "%s is not a field of class %s", QCC_GetSRefName(QCC_RefToDef(field, false)), t->name); QCC_PR_ParseError(ERR_BADMEMBER, "%s is not a field of class %s", QCC_GetSRefName(QCC_RefToDef(field, false)), t->name);
else else
QCC_PR_ParseError(ERR_INTERNAL, "%s is not a field", QCC_GetSRefName(QCC_RefToDef(field, false))); QCC_PR_ParseError(ERR_BADMEMBER, "%s is not a field", QCC_GetSRefName(QCC_RefToDef(field, false)));
} }
lhs = QCC_PR_ParseField(refbuf, lhs); lhs = QCC_PR_ParseField(refbuf, lhs);
@ -8973,7 +9026,12 @@ static QCC_ref_t *QCC_PR_ParseField(QCC_ref_t *refbuf, QCC_ref_t *lhs)
lhs = QCC_PR_ParseRefArrayPointer (refbuf, lhs, false, false); lhs = QCC_PR_ParseRefArrayPointer (refbuf, lhs, false, false);
} }
else else
QCC_PR_ParseError(ERR_INTERNAL, "%s is not a member of %s", QCC_PR_ParseName(), t->name); {
QCC_PR_ParseWarning(ERR_BADMEMBER, "%s is not a member of %s", QCC_PR_ParseName(), t->name);
if (t->filen)
QCC_PR_Note(ERR_BADMEMBER, t->filen, t->line, "%s is defined here", t->name);
return QCC_PR_BuildRef(refbuf, REF_GLOBAL, QCC_MakeIntConst(0), nullsref, type_void, false);
}
} }
else if (flag_qccx && t->type == ev_entity && QCC_PR_CheckToken("[")) else if (flag_qccx && t->type == ev_entity && QCC_PR_CheckToken("["))
{ //p[%0] gives a regular array reference. except that p is probably a float, and we're expecting OP_LOAD_F { //p[%0] gives a regular array reference. except that p is probably a float, and we're expecting OP_LOAD_F
@ -9383,7 +9441,11 @@ fieldarrayindex:
return QCC_PR_ParseRefArrayPointer(retbuf, r, allowarrayassign, makearraypointers); return QCC_PR_ParseRefArrayPointer(retbuf, r, allowarrayassign, makearraypointers);
} }
} }
QCC_PR_ParseError(0, "%s is not a member of %s", mname, tname);
QCC_PR_ParseWarning(ERR_BADMEMBER, "%s is not a member of %s", mname, t->name);
if (t->filen)
QCC_PR_Note(ERR_BADMEMBER, t->filen, t->line, "%s is defined here", t->name);
QCC_PR_ParseError(ERR_BADMEMBER, NULL);
} }
if (!ofs && idx.cast) if (!ofs && idx.cast)
; ;

View file

@ -4074,11 +4074,14 @@ NORETURN void VARGS QCC_PR_ParseError (int errortype, const char *error, ...)
editbadfile(s_filen, pr_source_line); editbadfile(s_filen, pr_source_line);
#endif #endif
if (error)
{
QCC_PR_PrintScope(); QCC_PR_PrintScope();
if (flag_msvcstyle) if (flag_msvcstyle)
externs->Printf ("%s%s(%i) : %serror%s: %s\n", col_location, s_filen, pr_source_line, col_error, col_none, string); externs->Printf ("%s%s(%i) : %serror%s: %s\n", col_location, s_filen, pr_source_line, col_error, col_none, string);
else else
externs->Printf ("%s%s:%i: %serror%s: %s\n", col_location, s_filen, pr_source_line, col_error, col_none, string); externs->Printf ("%s%s:%i: %serror%s: %s\n", col_location, s_filen, pr_source_line, col_error, col_none, string);
}
longjmp (pr_parse_abort, 1); longjmp (pr_parse_abort, 1);
} }