warn about ptrdiff_t passed as long on 2-4 machines

This commit is contained in:
eck 1990-04-25 15:09:51 +00:00
parent f2b4713c24
commit dc12b2fa3d
8 changed files with 40 additions and 5 deletions

View file

@ -327,7 +327,7 @@ garbage:
if (ch != EOI)
UnGetChar();
*tg++ = '\0'; /* mark the end of the identifier */
idef = ptok->tk_idf = idf_hashed(buf, tg - buf, hash);
idef = ptok->tk_idf = idf_hashed(buf, (int) (tg - buf), hash);
idef->id_file = ptok->tk_file;
idef->id_line = ptok->tk_line;
#ifndef NOPP

View file

@ -38,13 +38,33 @@ arithbalance(e1p, oper, e2p) /* 3.1.2.5 */
{
/* The expressions *e1p and *e2p are balanced to be operands
of the arithmetic operator oper.
We check here if the EX_PTRDIFF flag should be retained.
They are set to zero in because one of the opreands might
have a floating type, in which case the flags shouldn't
travel upward in the expression tree.
*/
register int t1, t2, u1, u2;
int shifting = (oper == LEFT || oper == RIGHT
|| oper == LEFTAB || oper == RIGHTAB);
int ptrdiff = 0;
t1 = any2arith(e1p, oper);
t2 = any2arith(e2p, oper);
if (int_size != pointer_size) {
if (ptrdiff = ((*e1p)->ex_flags & EX_PTRDIFF)
|| ((*e2p)->ex_flags & EX_PTRDIFF)) {
if (!((*e1p)->ex_flags & EX_PTRDIFF) && t1 == LONG)
ptrdiff = 0;
if (!((*e2p)->ex_flags & EX_PTRDIFF) && t2 == LONG
&& !shifting)
ptrdiff = 0;
}
/* Now turn off ptrdiff flags */
(*e1p)->ex_flags &= ~EX_PTRDIFF;
(*e2p)->ex_flags &= ~EX_PTRDIFF;
}
/* Now t1 and t2 are either INT, LONG, FLOAT, DOUBLE, or LNGDBL */
/* If any operand has the type long double, the other operand
@ -132,6 +152,13 @@ arithbalance(e1p, oper, e2p) /* 3.1.2.5 */
else
if (!u1 && u2 && !shifting)
t1 = int2int(e1p, (t2 == LONG) ? ulong_type : uint_type);
if (int_size != pointer_size) {
if (ptrdiff) {
(*e1p)->ex_flags |= EX_PTRDIFF;
(*e2p)->ex_flags |= EX_PTRDIFF;
}
}
}
relbalance(e1p, oper, e2p)
@ -549,6 +576,9 @@ any2parameter(expp)
/* To handle default argument promotions
*/
any2opnd(expp, '(');
if (int_size != pointer_size)
if ((*expp)->ex_flags & EX_PTRDIFF)
expr_warning(*expp, "pointer difference caused long expression");
if ((*expp)->ex_type->tp_fund == FLOAT)
float2float(expp, double_type);
}

View file

@ -17,6 +17,7 @@
#include "label.h"
#include "expr.h"
#include "Lpars.h"
#include "sizes.h"
extern char options[];
extern char *symbol2str();
@ -297,6 +298,7 @@ pntminuspnt(expp, oper, expr)
, pa_type->tp_fund));
ch3cast(expp, CAST, pa_type); /* result will be an integral expr */
/* cast necessary ??? */
if (int_size != pointer_size) (*expp)->ex_flags |= EX_PTRDIFF;
}
mk_binop(expp, oper, expr, commutative)

View file

@ -682,7 +682,7 @@ get_text(formals, length)
blank = 0;
}
*length = repl->r_ptr - repl->r_text;
return Realloc(repl->r_text, repl->r_ptr - repl->r_text + 1);
return Realloc(repl->r_text, (unsigned)(repl->r_ptr - repl->r_text +1));
}
/* macroeq() decides whether two macro replacement texts are

View file

@ -95,6 +95,7 @@ struct expr {
#define EX_VOLATILE 0x080 /* volatile variabele */
#define EX_ILVALUE 0x100 /* an illegal lvalue e.g. f().x */
#define EX_ERROR 0x200 /* the expression is wrong */
#define EX_PTRDIFF 0x400 /* subtracting 2 pointers in expr. */
#define NILEXPR ((struct expr *)0)

View file

@ -127,6 +127,8 @@ unary(register struct expr **expp;)
cast(&tp) unary(expp)
{ ch3cast(expp, CAST, tp);
(*expp)->ex_flags |= EX_CAST;
if (int_size != pointer_size)
(*expp)->ex_flags &= ~EX_PTRDIFF;
}
|
postfix_expression(expp)

View file

@ -141,7 +141,7 @@ str2idf(tg)
}
hash = STOPHASH(hash);
*ncp++ = '\0';
return idf_hashed(ntg, ncp - ntg, hash);
return idf_hashed(ntg, (int) (ncp - ntg), hash);
}
struct idf *

View file

@ -51,7 +51,7 @@ replace(idf)
if (!expand_macro(repl, idf))
return 0;
InputLevel++;
InsertText(repl->r_text, repl->r_ptr - repl->r_text);
InsertText(repl->r_text, (int)(repl->r_ptr - repl->r_text));
idf->id_macro->mc_flag |= NOREPLACE;
repl->r_level = InputLevel;
repl->next = ReplaceList;
@ -347,7 +347,7 @@ actual(repl)
/* When the identifier has an associated macro
replacement list, it's expanded.
*/
idef = idf_hashed(buf, p - buf, hash);
idef = idf_hashed(buf, (int) (p - buf), hash);
if (NoExpandMacro || !replace(idef)) {
if ((idef->id_macro
&& (idef->id_macro->mc_flag & NOREPLACE))