From 307cbbfbcbcf5e5296262ad1eb5dbc299bcac58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 22 Aug 2026 18:03:04 +0000 Subject: [PATCH] Preprocessor: Fix missing NL at EOF. (#3918) --- tools/shaderc/pp.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tools/shaderc/pp.cpp b/tools/shaderc/pp.cpp index 07d6ed1f1..496cf84d2 100644 --- a/tools/shaderc/pp.cpp +++ b/tools/shaderc/pp.cpp @@ -863,16 +863,35 @@ namespace shaderc void pushFrame(const bx::StringView& _name, const bx::StringView& _source, bool _isInclude) { const uint32_t max = _source.getLength() + 16; - Token* tokens = m_arena.allocate(max); + Token* tokens = m_arena.allocate(max + 1 /* space for token if NL at EOF is missing */); Lexer lexer(m_arena, _source, tokens, max); + uint32_t num = lexer.run(); + + if (0 < num) + { + const Token& lastToken = tokens[num-1]; + + if (Kind::Newline != lastToken.kind) + { + tokens[num++] = + { + .lexeme = "\n", + .location = lastToken.location, + .hide = NULL, + .kind = Kind::Newline, + .spaceBefore = false, + }; + } + } + const Frame frame = { .name = _name, .presumedName = bx::StringView(), .tokens = tokens, - .num = lexer.run(), + .num = num, .pos = 0, .lineDelta = 0, .isInclude = _isInclude,