Author: Aaron Ballman Date: 2025-04-11T10:44:37-04:00 New Revision: d1ea4799d9a3e2757772a47e9dce5f2e24bb982f
URL: https://github.com/llvm/llvm-project/commit/d1ea4799d9a3e2757772a47e9dce5f2e24bb982f DIFF: https://github.com/llvm/llvm-project/commit/d1ea4799d9a3e2757772a47e9dce5f2e24bb982f.diff LOG: [C23] Fix failed assertions with invalid #embed parameters (#135368) If the invalid parameter was not the last parameter given, we would fail to skip to the end of the directive and trip a failed assertion. Fixes #126940 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Lex/PPDirectives.cpp clang/test/Preprocessor/embed_parameter_unrecognized.c Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index db8dad268a8a7..9c45965dc4d82 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -170,6 +170,8 @@ C23 Feature Support scope. - Fixed a bug where you could not cast a null pointer constant to type ``nullptr_t``. Fixes #GH133644. +- Fixed a failed assertion with an invalid parameter to the ``#embed`` + directive. Fixes #GH126940. C11 Feature Support ^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index d97a6e8d64f9c..dfdba6bd09fd8 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -3897,7 +3897,9 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool ForHasEmbed) { return std::nullopt; } if (!ForHasEmbed) { - Diag(CurTok, diag::err_pp_unknown_parameter) << 1 << Parameter; + Diag(ParamStartLoc, diag::err_pp_unknown_parameter) << 1 << Parameter; + if (CurTok.isNot(tok::eod)) + DiscardUntilEndOfDirective(CurTok); return std::nullopt; } } diff --git a/clang/test/Preprocessor/embed_parameter_unrecognized.c b/clang/test/Preprocessor/embed_parameter_unrecognized.c index b03384341a00a..c6fef941b7b88 100644 --- a/clang/test/Preprocessor/embed_parameter_unrecognized.c +++ b/clang/test/Preprocessor/embed_parameter_unrecognized.c @@ -1,5 +1,4 @@ // RUN: %clang_cc1 %s -std=c23 -E -verify -// okay-no-diagnostics #embed __FILE__ unrecognized // expected-error@-1 {{unknown embed preprocessor parameter 'unrecognized'}} @@ -7,3 +6,12 @@ // expected-error@-1 {{unknown embed preprocessor parameter 'unrecognized::param'}} #embed __FILE__ unrecognized::param(with, args) // expected-error@-1 {{unknown embed preprocessor parameter 'unrecognized::param'}} + +// The first of these two cases was causing a failed assertion due to not being +// at the end of the directive when we finished skipping past `bla`. +#embed __FILE__ bla(2) limit(2) // expected-error {{unknown embed preprocessor parameter 'bla'}} +#embed __FILE__ limit(2) bla(2) // expected-error {{unknown embed preprocessor parameter 'bla'}} + +// We intentionally only tell you about one invalid parameter at a time so that +// we can skip over invalid token soup. +#embed __FILE__ bla(2) limit(2) bork // expected-error {{unknown embed preprocessor parameter 'bla'}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits