Skip to content

Commit d1ea479

Browse files
authored
[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
1 parent 07b4396 commit d1ea479

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ C23 Feature Support
170170
scope.
171171
- Fixed a bug where you could not cast a null pointer constant to type
172172
``nullptr_t``. Fixes #GH133644.
173+
- Fixed a failed assertion with an invalid parameter to the ``#embed``
174+
directive. Fixes #GH126940.
173175

174176
C11 Feature Support
175177
^^^^^^^^^^^^^^^^^^^

clang/lib/Lex/PPDirectives.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3897,7 +3897,9 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool ForHasEmbed) {
38973897
return std::nullopt;
38983898
}
38993899
if (!ForHasEmbed) {
3900-
Diag(CurTok, diag::err_pp_unknown_parameter) << 1 << Parameter;
3900+
Diag(ParamStartLoc, diag::err_pp_unknown_parameter) << 1 << Parameter;
3901+
if (CurTok.isNot(tok::eod))
3902+
DiscardUntilEndOfDirective(CurTok);
39013903
return std::nullopt;
39023904
}
39033905
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
// RUN: %clang_cc1 %s -std=c23 -E -verify
2-
// okay-no-diagnostics
32

43
#embed __FILE__ unrecognized
54
// expected-error@-1 {{unknown embed preprocessor parameter 'unrecognized'}}
65
#embed __FILE__ unrecognized::param
76
// expected-error@-1 {{unknown embed preprocessor parameter 'unrecognized::param'}}
87
#embed __FILE__ unrecognized::param(with, args)
98
// expected-error@-1 {{unknown embed preprocessor parameter 'unrecognized::param'}}
9+
10+
// The first of these two cases was causing a failed assertion due to not being
11+
// at the end of the directive when we finished skipping past `bla`.
12+
#embed __FILE__ bla(2) limit(2) // expected-error {{unknown embed preprocessor parameter 'bla'}}
13+
#embed __FILE__ limit(2) bla(2) // expected-error {{unknown embed preprocessor parameter 'bla'}}
14+
15+
// We intentionally only tell you about one invalid parameter at a time so that
16+
// we can skip over invalid token soup.
17+
#embed __FILE__ bla(2) limit(2) bork // expected-error {{unknown embed preprocessor parameter 'bla'}}

0 commit comments

Comments
 (0)