Skip to content

Commit 2865b67

Browse files
committed
[Lex] fix lexing malformed pragma within include directive
1 parent 4768173 commit 2865b67

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ Bug Fixes in This Version
535535
- Fixed visibility calculation for template functions. (#GH103477)
536536
- Fixed a bug where an attribute before a ``pragma clang attribute`` or
537537
``pragma clang __debug`` would cause an assertion. Instead, this now diagnoses
538-
the invalid attribute location appropriately. (#GH137861)
538+
the invalid attribute location appropriately. (#GH137861)
539+
- Fixed a crash when a malformed ``_Pragma`` directive appears as part of an ``#include`` directive. (#GH138094)
539540

540541
Bug Fixes to Compiler Builtins
541542
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Lex/Pragma.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ void Preprocessor::Handle_Pragma(Token &Tok) {
220220
if (!tok::isStringLiteral(Tok.getKind())) {
221221
Diag(PragmaLoc, diag::err__Pragma_malformed);
222222
// Skip bad tokens, and the ')', if present.
223-
if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof))
223+
if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof) && Tok.isNot(tok::eod))
224224
Lex(Tok);
225225
while (Tok.isNot(tok::r_paren) &&
226226
!Tok.isAtStartOfLine() &&
227-
Tok.isNot(tok::eof))
227+
Tok.isNot(tok::eof) && Tok.isNot(tok::eod))
228228
Lex(Tok);
229229
if (Tok.is(tok::r_paren))
230230
Lex(Tok);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %clang_cc1 %s -verify
2+
3+
// Don't crash, verify that diagnostics are preserved
4+
#include _Pragma( // expected-error {{_Pragma takes a parenthesized string literal}} \
5+
expected-error {{expected "FILENAME"}}

0 commit comments

Comments
 (0)