mirror of
https://github.com/cc65/cc65.git
synced 2025-01-10 19:29:45 +00:00
Merge pull request #1807 from acqn/CharmapFix
[cc65] Fixed #pragma charmap for string literals
This commit is contained in:
commit
a41b76795a
@ -1263,6 +1263,8 @@ static void Primary (ExprDesc* E)
|
||||
/* String literal */
|
||||
if ((Flags & E_EVAL_UNEVAL) != E_EVAL_UNEVAL) {
|
||||
E->V.LVal = UseLiteral (CurTok.SVal);
|
||||
/* Translate into target charset */
|
||||
TranslateLiteral (E->V.LVal);
|
||||
} else {
|
||||
E->V.LVal = CurTok.SVal;
|
||||
}
|
||||
|
@ -126,9 +126,6 @@ static void FreeLiteral (Literal* L)
|
||||
static void OutputLiteral (Literal* L)
|
||||
/* Output one literal to the currently active data segment */
|
||||
{
|
||||
/* Translate the literal into the target charset */
|
||||
TranslateLiteral (L);
|
||||
|
||||
/* Define the label for the literal */
|
||||
g_defliterallabel (L->Label);
|
||||
|
||||
@ -387,9 +384,6 @@ static void OutputReadOnlyLiterals (Collection* Literals)
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Translate the literal into the target charset */
|
||||
TranslateLiteral (L);
|
||||
|
||||
/* Check if this literal is part of another one. Since the literals
|
||||
** are sorted by size (larger ones first), it can only be part of a
|
||||
** literal with a smaller index.
|
||||
|
54
test/val/bug1373.c
Normal file
54
test/val/bug1373.c
Normal file
@ -0,0 +1,54 @@
|
||||
|
||||
/* #1373 - #pragma charmap works in unexpected ways */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
char res0[10];
|
||||
char res1[10];
|
||||
char res2[10];
|
||||
char res3[10];
|
||||
char res4[10];
|
||||
|
||||
int err = 0;
|
||||
|
||||
#pragma charmap(0x61, 0x44)
|
||||
#define STRING_A "abABa"
|
||||
|
||||
extern char mappedA[10];
|
||||
|
||||
#pragma charmap(0x61, 0x61)
|
||||
char notmappedA[10] = "abABa";
|
||||
|
||||
void test(void);
|
||||
|
||||
#pragma charmap(0x61, 0x42)
|
||||
int main(void)
|
||||
{
|
||||
char mappedB[10] = STRING_A;
|
||||
sprintf(res0, "abABa"); /* expected: BbABB */
|
||||
|
||||
#pragma charmap(0x61, 0x61)
|
||||
sprintf(res1, mappedA); /* expected: CbABC */
|
||||
sprintf(res2, STRING_A); /* expected: abABa */
|
||||
sprintf(res3, mappedB); /* expected: BbABB */
|
||||
|
||||
#pragma charmap(0x61, 0x43)
|
||||
sprintf(res4, notmappedA); /* expected: abABa */
|
||||
|
||||
test();
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
char mappedA[10] = "abABa";
|
||||
|
||||
#pragma charmap(0x61, 0x61)
|
||||
void test(void)
|
||||
{
|
||||
puts(res0); if (strcmp(res0, "BbABB") != 0) { puts("expected: BbABB"); err++; }
|
||||
puts(res1); if (strcmp(res1, "CbABC") != 0) { puts("expected: CbABC"); err++; }
|
||||
puts(res2); if (strcmp(res2, "abABa") != 0) { puts("expected: abABa"); err++; }
|
||||
puts(res3); if (strcmp(res3, "BbABB") != 0) { puts("expected: BbABB"); err++; }
|
||||
puts(res4); if (strcmp(res4, "abABa") != 0) { puts("expected: abABa"); err++; }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user