diff --git a/libs/vkd3d-shader/preproc.l b/libs/vkd3d-shader/preproc.l index 60cd662e..5e8ed2eb 100644 --- a/libs/vkd3d-shader/preproc.l +++ b/libs/vkd3d-shader/preproc.l @@ -664,6 +664,21 @@ int yylex(YYSTYPE *lval, YYLTYPE *lloc, yyscan_t scanner) break; } + /* Stringification is another special case. Unsurprisingly, + * we need to stringify if this is an argument. More + * surprisingly, we need to stringify even if it's not. */ + case T_HASHSTRING: + { + struct vkd3d_string_buffer buffer; + + vkd3d_string_buffer_init(&buffer); + preproc_stringify(ctx, &buffer, text); + if (current_arg) + preproc_text_add(current_arg, buffer.buffer); + vkd3d_string_buffer_cleanup(&buffer); + break; + } + case T_NEWLINE: if (current_arg) preproc_text_add(current_arg, " "); diff --git a/tests/hlsl_d3d12.c b/tests/hlsl_d3d12.c index 85a1548f..ef41235e 100644 --- a/tests/hlsl_d3d12.c +++ b/tests/hlsl_d3d12.c @@ -236,6 +236,27 @@ static void test_preprocess(void) "#", }, + { + "#define KEY2(x) x\n" + "#define KEY(a) KEY2(#a)\n" + "KEY(apple)", + + "\"apple\"", + }, + { + "#define KEY2(x) #x\n" + "#define KEY(a) KEY2(#a)\n" + "KEY(apple)", + + "\"\\\"apple\\\"\"", + }, + { + "#define KEY2(x) #x\n" + "#define KEY(a) KEY2(#x)\n" + "KEY(apple)", + + "\"\\\"x\\\"\"", + }, /* #pragma is preserved. */ {