mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +00:00
Avoided referencing string literals with sizeof so that they are not output if unused elsewhere.
This commit is contained in:
parent
903e84c24c
commit
e2f950b15e
@ -923,7 +923,11 @@ static void Primary (ExprDesc* E)
|
||||
case TOK_SCONST:
|
||||
case TOK_WCSCONST:
|
||||
/* String literal */
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user