1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-14 14:26:27 +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_SCONST:
case TOK_WCSCONST: case TOK_WCSCONST:
/* String literal */ /* String literal */
if ((Flags & E_EVAL_UNEVAL) != E_EVAL_UNEVAL) {
E->LVal = UseLiteral (CurTok.SVal); E->LVal = UseLiteral (CurTok.SVal);
} else {
E->LVal = CurTok.SVal;
}
E->Type = GetCharArrayType (GetLiteralSize (CurTok.SVal)); E->Type = GetCharArrayType (GetLiteralSize (CurTok.SVal));
E->Flags = E_LOC_LITERAL | E_RTYPE_RVAL | E_ADDRESS_OF; E->Flags = E_LOC_LITERAL | E_RTYPE_RVAL | E_ADDRESS_OF;
E->IVal = 0; E->IVal = 0;
@@ -1996,19 +2000,18 @@ void hie10 (ExprDesc* Expr)
/* Remember the output queue pointer */ /* Remember the output queue pointer */
CodeMark Mark; CodeMark Mark;
GetCodePos (&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"); Error ("Cannot apply 'sizeof' to bit-field");
Size = 0; Size = 0;
} else { } 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 */ /* Calculate the size */
Size = ExprCheckedSizeOf (Expr->Type); Size = ExprCheckedSizeOf (Uneval.Type);
} }
/* Remove any generated code */ /* Remove any generated code */
RemoveCode (&Mark); RemoveCode (&Mark);