mirror of
https://github.com/intel/llvm.git
synced 2026-01-15 12:25:46 +08:00
[clang] Fix static analyzer concerns in #embed code (#99331)
1. Dead code in `LookupEmbedFile`. The loop always exited on the first iteration. This was also causing a bug of not checking all directories provided by `--embed-dir`. 2. Use of uninitialized variable `CurTok` in `LexEmbedParameters`. It was used to initialize the field which seems to be unused. Removed unused field, this way `CurTok` should be initialized by Lex method.
This commit is contained in:
committed by
GitHub
parent
c248d05c68
commit
c813667095
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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))
|
||||
@@ -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);
|
||||
@@ -3872,7 +3871,6 @@ Preprocessor::LexEmbedParameters(Token &CurTok, bool ForHasEmbed) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Result.ParamRange.setEnd(CurTok.getLocation());
|
||||
return Result;
|
||||
}
|
||||
|
||||
|
||||
4
clang/test/Preprocessor/embed_search_paths.c
Normal file
4
clang/test/Preprocessor/embed_search_paths.c
Normal file
@@ -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>
|
||||
Reference in New Issue
Block a user