Fixed timing of #pragma charmap.

Now it is immediately applied and affects almost all characters and string literals after it.
Exceptions:
- String literals as the message of a static assertion or inline assembler code (only the required one, not any optional formatted arguments) in an asm() expression are not translated with either #pragma charmap or target presets.
- String literals used for preprocessor directives or as the result of stringized macro arguments are never translated.
This commit is contained in:
acqn
2023-10-13 16:32:06 +08:00
parent c6ead99b00
commit 25832ef5fc
8 changed files with 94 additions and 17 deletions

View File

@@ -1,9 +1,39 @@
/* Bug #2151 - #pragma causes errors when used within functions */
#include <stdio.h>
#include <string.h>
#pragma charmap(0x61, 0x61)
_Static_assert('A'==
#pragma charmap(0x61, 0x41)
'a'
#pragma charmap(0x61, 0x42)
,
#pragma charmap(0x61, 0x61)
"charmap failed");
char str[] =
"a"
#pragma charmap(0x61, 0x42)
"a"
#pragma charmap(0x61, 0x43)
"a"
#pragma charmap(0x61, 0x61)
;
unsigned failures;
#pragma bss-name("BSS1")
int
#pragma code-name("CODE_WUT")
main _Pragma("message(\"_Pragma note\")")
main _Pragma
#pragma charmap(0x61, 0x32)
(
"message(\"_Pragma string"
/* Concatenated string literals in _Pragma is a cc65 extension */
" unaffected by charmap\")"
)
#pragma charmap(0x61, 0x61)
(
void
_Pragma _Pragma (
@@ -20,9 +50,27 @@ _Pragma _Pragma (
#pragma bss-name("BSS2")
static
#pragma zpsym ("y")
int x; // TODO: currently in "BSS", but supposed to be in "BSS2"?
int x; // TODO: currently in "BSS", but supposed to be in "BSS2"?
x = 0;
return x + y;
if (memcmp(str, "aBC", 3))
{
++failures;
printf("%3s\n", str);
}
if (x + y != 0)
{
++failures;
printf("%d\n", x + y);
}
if (failures != 0)
{
printf("faiures: %d\n", failures);
}
return failures;
#pragma bss-name("BSS")
}