Skip to content

Commit 98f1ae0

Browse files
authored
[clang] Fix assertion with invalid embed limit parameter value (#157896)
If a negative value was given we would fail to skip till the end of the directive and trip a failed assertion. Fixes #157842
1 parent f56309a commit 98f1ae0

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ Bug Fixes in This Version
308308
- Builtin elementwise operators now accept vector arguments that have different
309309
qualifiers on their elements. For example, vector of 4 ``const float`` values
310310
and vector of 4 ``float`` values. (#GH155405)
311+
- Fixed a failed assertion with a negative limit parameter value inside of
312+
``__has_embed``. (#GH157842)
311313

312314
Bug Fixes to Compiler Builtins
313315
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Lex/PPDirectives.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3746,6 +3746,8 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool ForHasEmbed) {
37463746
if (Result.isNegative()) {
37473747
Diag(CurTok, diag::err_requires_positive_value)
37483748
<< toString(Result, 10) << /*positive*/ 0;
3749+
if (CurTok.isNot(tok::eod))
3750+
DiscardUntilEndOfDirective(CurTok);
37493751
return std::nullopt;
37503752
}
37513753
return Result.getLimitedValue();

clang/test/Preprocessor/embed___has_embed_parsing_errors.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,12 @@
238238
#if __has_embed("media/art.txt" if_empty))
239239
#endif
240240

241+
// expected-error@+2 {{invalid value '-1'; must be positive}} \
242+
expected-error@+2 {{expected value in expression}}
243+
#if __has_embed (__FILE__ limit(-1))
244+
#endif
245+
246+
// expected-error@+2 {{invalid value '-100000000000000000'; must be positive}}\
247+
expected-error@+2 {{expected value in expression}}
248+
#if __has_embed (__FILE__ limit(-100000000000000000)) != __STDC_EMBED_NOT_FOUND__
249+
#endif

0 commit comments

Comments
 (0)