Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] Fix static analyzer concerns in #embed code #99331

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion clang/include/clang/Lex/PPEmbedParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ struct LexEmbedParametersResult {
std::optional<PPEmbedParameterIfEmpty> MaybeIfEmptyParam;
std::optional<PPEmbedParameterPrefix> MaybePrefixParam;
std::optional<PPEmbedParameterSuffix> MaybeSuffixParam;
SourceRange ParamRange;
int UnrecognizedParams;

size_t PrefixTokenCount() const {
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/Lex/PPDirectives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,9 @@ Preprocessor::LookupEmbedFile(StringRef Filename, bool isAngled, bool OpenFile,
SeparateComponents(LookupPath, Entry, Filename, false);
llvm::Expected<FileEntryRef> ShouldBeEntry =
FM.getFileRef(LookupPath, OpenFile);
return llvm::expectedToOptional(std::move(ShouldBeEntry));
if (ShouldBeEntry)
return llvm::expectedToOptional(std::move(ShouldBeEntry));
llvm::consumeError(ShouldBeEntry.takeError());
}
return std::nullopt;
}
Expand Down Expand Up @@ -3624,12 +3626,10 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool ForHasEmbed) {
LexEmbedParametersResult Result{};
SmallVector<Token, 2> ParameterTokens;
tok::TokenKind EndTokenKind = ForHasEmbed ? tok::r_paren : tok::eod;
Result.ParamRange = {CurTok.getLocation(), CurTok.getLocation()};

auto DiagMismatchedBracesAndSkipToEOD =
[&](tok::TokenKind Expected,
std::pair<tok::TokenKind, SourceLocation> Matches) {
Result.ParamRange.setEnd(CurTok.getEndLoc());
Diag(CurTok, diag::err_expected) << Expected;
Diag(Matches.second, diag::note_matching) << Matches.first;
if (CurTok.isNot(tok::eod))
Expand All @@ -3638,7 +3638,6 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool ForHasEmbed) {

auto ExpectOrDiagAndSkipToEOD = [&](tok::TokenKind Kind) {
if (CurTok.isNot(Kind)) {
Result.ParamRange.setEnd(CurTok.getEndLoc());
Diag(CurTok, diag::err_expected) << Kind;
if (CurTok.isNot(tok::eod))
DiscardUntilEndOfDirective(CurTok);
Expand Down Expand Up @@ -3872,7 +3871,6 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool ForHasEmbed) {
}
}
}
Result.ParamRange.setEnd(CurTok.getLocation());
return Result;
}

Expand Down
4 changes: 4 additions & 0 deletions clang/test/Preprocessor/embed_search_paths.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// RUN: %clang_cc1 -std=c23 %s -E -verify --embed-dir=%S --embed-dir=%S/Inputs
// expected-no-diagnostics

#embed <jk.txt>
Loading