[clang] [clang][lex] Fix lexing malformed pragma within include directive (PR #138165)
https://github.com/sweiglbosker updated https://github.com/llvm/llvm-project/pull/138165 Rate limit · GitHub body { background-color: #f6f8fa; color: #24292e; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol; font-size: 14px; line-height: 1.5; margin: 0; } .container { margin: 50px auto; max-width: 600px; text-align: center; padding: 0 24px; } a { color: #0366d6; text-decoration: none; } a:hover { text-decoration: underline; } h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; text-shadow: 0 1px 0 #fff; } p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; } ul { list-style: none; margin: 25px 0; padding: 0; } li { display: table-cell; font-weight: bold; width: 1%; } .logo { display: inline-block; margin-top: 35px; } .logo-img-2x { display: none; } @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and ( min--moz-device-pixel-ratio: 2), only screen and ( -o-min-device-pixel-ratio: 2/1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) { .logo-img-1x { display: none; } .logo-img-2x { display: inline-block; } } #suggestions { margin-top: 35px; color: #ccc; } #suggestions a { color: #66; font-weight: 200; font-size: 14px; margin: 0 10px; } Whoa there! You have exceeded a secondary rate limit. Please wait a few minutes before you try again; in some cases this may take up to an hour. https://support.github.com/contact";>Contact Support — https://githubstatus.com";>GitHub Status — https://twitter.com/githubstatus";>@githubstatus ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][lex] Fix lexing malformed pragma within include directive (PR #138165)
sweiglbosker wrote: Done https://github.com/llvm/llvm-project/pull/138165 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][lex] Fix lexing malformed pragma within include directive (PR #138165)
https://github.com/sweiglbosker updated https://github.com/llvm/llvm-project/pull/138165 >From 08f13cc755539516c2a5606ed0a7dfa20b99bbd3 Mon Sep 17 00:00:00 2001 From: Stefan Weigl-Bosker Date: Thu, 1 May 2025 12:24:17 -0400 Subject: [PATCH] [Lex] fix lexing malformed pragma within include directive --- clang/docs/ReleaseNotes.rst | 4 +++- clang/lib/Lex/Pragma.cpp | 4 ++-- clang/test/Preprocessor/_Pragma-in-include.c | 4 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 clang/test/Preprocessor/_Pragma-in-include.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1dd97bcc67364..943aff772b08b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -535,7 +535,9 @@ Bug Fixes in This Version - Fixed visibility calculation for template functions. (#GH103477) - Fixed a bug where an attribute before a ``pragma clang attribute`` or ``pragma clang __debug`` would cause an assertion. Instead, this now diagnoses - the invalid attribute location appropriately. (#GH137861) + the invalid attribute location appropriately. (#GH137861) +- Fixed a crash when a malformed ``_Pragma`` directive appears as part of an + ``#include`` directive. (#GH138094) Bug Fixes to Compiler Builtins ^^ diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 5b6a29bdad910..01c85e6ad95d5 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -220,11 +220,11 @@ void Preprocessor::Handle_Pragma(Token &Tok) { if (!tok::isStringLiteral(Tok.getKind())) { Diag(PragmaLoc, diag::err__Pragma_malformed); // Skip bad tokens, and the ')', if present. -if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof)) +if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof) && Tok.isNot(tok::eod)) Lex(Tok); while (Tok.isNot(tok::r_paren) && !Tok.isAtStartOfLine() && - Tok.isNot(tok::eof)) + Tok.isNot(tok::eof) && Tok.isNot(tok::eod)) Lex(Tok); if (Tok.is(tok::r_paren)) Lex(Tok); diff --git a/clang/test/Preprocessor/_Pragma-in-include.c b/clang/test/Preprocessor/_Pragma-in-include.c new file mode 100644 index 0..6a121946bf0ce --- /dev/null +++ b/clang/test/Preprocessor/_Pragma-in-include.c @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -E %s -verify + +// Don't crash, verify that diagnostics are preserved +#include _Pragma( // expected-error {{_Pragma takes a parenthesized string literal}} expected-error {{expected "FILENAME"}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][lex] Fix lexing malformed pragma within include directive (PR #138165)
https://github.com/sweiglbosker updated https://github.com/llvm/llvm-project/pull/138165 Rate limit · GitHub body { background-color: #f6f8fa; color: #24292e; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol; font-size: 14px; line-height: 1.5; margin: 0; } .container { margin: 50px auto; max-width: 600px; text-align: center; padding: 0 24px; } a { color: #0366d6; text-decoration: none; } a:hover { text-decoration: underline; } h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; text-shadow: 0 1px 0 #fff; } p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; } ul { list-style: none; margin: 25px 0; padding: 0; } li { display: table-cell; font-weight: bold; width: 1%; } .logo { display: inline-block; margin-top: 35px; } .logo-img-2x { display: none; } @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and ( min--moz-device-pixel-ratio: 2), only screen and ( -o-min-device-pixel-ratio: 2/1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) { .logo-img-1x { display: none; } .logo-img-2x { display: inline-block; } } #suggestions { margin-top: 35px; color: #ccc; } #suggestions a { color: #66; font-weight: 200; font-size: 14px; margin: 0 10px; } Whoa there! You have exceeded a secondary rate limit. Please wait a few minutes before you try again; in some cases this may take up to an hour. https://support.github.com/contact";>Contact Support — https://githubstatus.com";>GitHub Status — https://twitter.com/githubstatus";>@githubstatus ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][lex] Fix lexing malformed pragma within include directive (PR #138165)
https://github.com/sweiglbosker updated https://github.com/llvm/llvm-project/pull/138165 Rate limit · GitHub body { background-color: #f6f8fa; color: #24292e; font-family: -apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol; font-size: 14px; line-height: 1.5; margin: 0; } .container { margin: 50px auto; max-width: 600px; text-align: center; padding: 0 24px; } a { color: #0366d6; text-decoration: none; } a:hover { text-decoration: underline; } h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; text-shadow: 0 1px 0 #fff; } p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; } ul { list-style: none; margin: 25px 0; padding: 0; } li { display: table-cell; font-weight: bold; width: 1%; } .logo { display: inline-block; margin-top: 35px; } .logo-img-2x { display: none; } @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and ( min--moz-device-pixel-ratio: 2), only screen and ( -o-min-device-pixel-ratio: 2/1), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) { .logo-img-1x { display: none; } .logo-img-2x { display: inline-block; } } #suggestions { margin-top: 35px; color: #ccc; } #suggestions a { color: #66; font-weight: 200; font-size: 14px; margin: 0 10px; } Whoa there! You have exceeded a secondary rate limit. Please wait a few minutes before you try again; in some cases this may take up to an hour. https://support.github.com/contact";>Contact Support — https://githubstatus.com";>GitHub Status — https://twitter.com/githubstatus";>@githubstatus ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][lex] Fix lexing malformed pragma within include directive (PR #138165)
https://github.com/sweiglbosker updated https://github.com/llvm/llvm-project/pull/138165 >From 429b48c245c4f41ad13b59603aefc5d374c2a52c Mon Sep 17 00:00:00 2001 From: Stefan Weigl-Bosker Date: Thu, 1 May 2025 12:24:17 -0400 Subject: [PATCH] [Lex] fix lexing malformed pragma within include directive --- clang/docs/ReleaseNotes.rst | 3 ++- clang/lib/Lex/Pragma.cpp | 4 ++-- clang/test/Preprocessor/_Pragma-in-include.c | 8 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 clang/test/Preprocessor/_Pragma-in-include.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1dd97bcc67364..c0e6889090468 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -535,7 +535,8 @@ Bug Fixes in This Version - Fixed visibility calculation for template functions. (#GH103477) - Fixed a bug where an attribute before a ``pragma clang attribute`` or ``pragma clang __debug`` would cause an assertion. Instead, this now diagnoses - the invalid attribute location appropriately. (#GH137861) + the invalid attribute location appropriately. (#GH137861) +- Fixed a crash when a malformed ``_Pragma`` directive appears as part of an ``#include`` directive. (#GH138094) Bug Fixes to Compiler Builtins ^^ diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 5b6a29bdad910..01c85e6ad95d5 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -220,11 +220,11 @@ void Preprocessor::Handle_Pragma(Token &Tok) { if (!tok::isStringLiteral(Tok.getKind())) { Diag(PragmaLoc, diag::err__Pragma_malformed); // Skip bad tokens, and the ')', if present. -if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof)) +if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof) && Tok.isNot(tok::eod)) Lex(Tok); while (Tok.isNot(tok::r_paren) && !Tok.isAtStartOfLine() && - Tok.isNot(tok::eof)) + Tok.isNot(tok::eof) && Tok.isNot(tok::eod)) Lex(Tok); if (Tok.is(tok::r_paren)) Lex(Tok); diff --git a/clang/test/Preprocessor/_Pragma-in-include.c b/clang/test/Preprocessor/_Pragma-in-include.c new file mode 100644 index 0..b32764dece52b --- /dev/null +++ b/clang/test/Preprocessor/_Pragma-in-include.c @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -verify + +// Don't crash, verify that diagnostics are preserved +#include _Pragma( // expected-error {{_Pragma takes a parenthesized string literal}} \ + expected-error {{expected "FILENAME"}} + + + ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][lex] Fix lexing malformed pragma within include directive (PR #138165)
https://github.com/sweiglbosker updated https://github.com/llvm/llvm-project/pull/138165 >From 2865b67e6014698e4f5c374aa448020b47b84ca5 Mon Sep 17 00:00:00 2001 From: Stefan Weigl-Bosker Date: Thu, 1 May 2025 12:24:17 -0400 Subject: [PATCH] [Lex] fix lexing malformed pragma within include directive --- clang/docs/ReleaseNotes.rst | 3 ++- clang/lib/Lex/Pragma.cpp | 4 ++-- clang/test/Preprocessor/_Pragma-in-include.c | 5 + 3 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 clang/test/Preprocessor/_Pragma-in-include.c diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1dd97bcc67364..c0e6889090468 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -535,7 +535,8 @@ Bug Fixes in This Version - Fixed visibility calculation for template functions. (#GH103477) - Fixed a bug where an attribute before a ``pragma clang attribute`` or ``pragma clang __debug`` would cause an assertion. Instead, this now diagnoses - the invalid attribute location appropriately. (#GH137861) + the invalid attribute location appropriately. (#GH137861) +- Fixed a crash when a malformed ``_Pragma`` directive appears as part of an ``#include`` directive. (#GH138094) Bug Fixes to Compiler Builtins ^^ diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 5b6a29bdad910..01c85e6ad95d5 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -220,11 +220,11 @@ void Preprocessor::Handle_Pragma(Token &Tok) { if (!tok::isStringLiteral(Tok.getKind())) { Diag(PragmaLoc, diag::err__Pragma_malformed); // Skip bad tokens, and the ')', if present. -if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof)) +if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof) && Tok.isNot(tok::eod)) Lex(Tok); while (Tok.isNot(tok::r_paren) && !Tok.isAtStartOfLine() && - Tok.isNot(tok::eof)) + Tok.isNot(tok::eof) && Tok.isNot(tok::eod)) Lex(Tok); if (Tok.is(tok::r_paren)) Lex(Tok); diff --git a/clang/test/Preprocessor/_Pragma-in-include.c b/clang/test/Preprocessor/_Pragma-in-include.c new file mode 100644 index 0..c31011609e244 --- /dev/null +++ b/clang/test/Preprocessor/_Pragma-in-include.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 %s -verify + +// Don't crash, verify that diagnostics are preserved +#include _Pragma( // expected-error {{_Pragma takes a parenthesized string literal}} \ + expected-error {{expected "FILENAME"}} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][lex] Fix lexing malformed pragma within include directive (PR #138165)
sweiglbosker wrote: > Thanks for the fix! Given the nature of the issue, I would probably introduce > a new test file rather than modify an existing one. But I think it should > live in `clang/test/Preprocessor`. Just added a small test. Looks good to you? https://github.com/llvm/llvm-project/pull/138165 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits