1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 23:29:39 +00:00

Avoided referencing string literals with sizeof so that they are not output if unused elsewhere.

This commit is contained in:
acqn 2020-08-31 17:45:36 +08:00 committed by Oliver Schmidt
parent 903e84c24c
commit e2f950b15e

View File

@ -923,7 +923,11 @@ static void Primary (ExprDesc* E)
case TOK_SCONST:
case TOK_WCSCONST:
/* String literal */
E->LVal = UseLiteral (CurTok.SVal);
if ((Flags & E_EVAL_UNEVAL) != E_EVAL_UNEVAL) {
E->LVal = UseLiteral (CurTok.SVal);
} else {
E->LVal = CurTok.SVal;
}
E->Type = GetCharArrayType (GetLiteralSize (CurTok.SVal));
E->Flags = E_LOC_LITERAL | E_RTYPE_RVAL | E_ADDRESS_OF;
E->IVal = 0;
@ -1996,19 +2000,18 @@ void hie10 (ExprDesc* Expr)
/* Remember the output queue pointer */
CodeMark Mark;
GetCodePos (&Mark);
hie10 (Expr);
if (ED_IsBitField (Expr)) {
/* The expression shall be unevaluated */
ExprDesc Uneval;
ED_Init (&Uneval);
ED_MarkForUneval (&Uneval);
hie10 (&Uneval);
if (ED_IsBitField (&Uneval)) {
Error ("Cannot apply 'sizeof' to bit-field");
Size = 0;
} else {
/* If the expression is a literal string, release it, so it
** won't be output as data if not used elsewhere.
*/
if (ED_IsLocLiteral (Expr)) {
ReleaseLiteral (Expr->LVal);
}
/* Calculate the size */
Size = ExprCheckedSizeOf (Expr->Type);
Size = ExprCheckedSizeOf (Uneval.Type);
}
/* Remove any generated code */
RemoveCode (&Mark);