Skip to content

[SYCLomatic] Fix coverity issues #2812

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

Open
wants to merge 1 commit into
base: SYCLomatic
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion clang/lib/DPCT/AnalysisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7525,7 +7525,7 @@ void FreeQueriesInfo::printImmediateText(llvm::raw_ostream &OS, const Node *S,
if (!DFI)
return;
auto Index = DpctGlobalInfo::getCudaKernelDimDFIIndexThenInc();
DpctGlobalInfo::insertCudaKernelDimDFIMap(Index, DFI);
DpctGlobalInfo::insertCudaKernelDimDFIMap(Index, std::move(DFI));
printFreeQueriesFunctionName<std::string>(
OS, K, "{{NEEDREPLACEG" + std::to_string(Index) + "}}");
} else {
Expand Down
11 changes: 8 additions & 3 deletions clang/lib/DPCT/DPCT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,9 +1029,14 @@ int runDPCT(int argc, const char **argv) {
if (SourceCode.starts_with(OptionStr)) {
QueryAPIMappingOpt += " (with the option";
while (SourceCode.consume_front(OptionStr)) {
auto Option = SourceCode.substr(0, SourceCode.find_first_of('\n'));
Option = Option.trim(' ');
SourceCode = SourceCode.substr(SourceCode.find_first_of('\n') + 1);
auto Pos = SourceCode.find('\n');
StringRef Option;
if (Pos == StringRef::npos) {
std::swap(Option, SourceCode);
} else {
Option = SourceCode.substr(0, Pos).trim(' ');
SourceCode = SourceCode.substr(Pos + 1);
}
QueryAPIMappingOpt += " ";
QueryAPIMappingOpt += Option.str();
if (Option.starts_with("--use-dpcpp-extensions")) {
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/DPCT/RuleInfra/CallExprRewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,8 @@ class MultiStmtsPrinter : public MultiStmtsPrinter<RestPrinter...> {

MultiStmtsPrinter(std::string Indent, std::string NL, bool IsInMacroDef,
FirstPrinter &&First, RestPrinter &&...Rest)
: Base(Indent, NL, IsInMacroDef, std::move(Rest)...),
: Base(std::move(Indent), std::move(NL), IsInMacroDef,
std::move(Rest)...),
First(std::move(First)) {}

template <class StreamT> void print(StreamT &Stream) const {
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/DPCT/RulesAsm/Parser/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ InlineAsmStmtResult InlineAsmParser::ParseInstruction() {
Types.push_back(Context.getBuiltinType(InlineAsmBuiltinType::u32));
}

return ::new (Context) InlineAsmInstruction(Opcode, StateSpaces, Attrs, Types,
Out.get(), Pred.get(), Ops);
return ::new (Context) InlineAsmInstruction(
Opcode, std::move(StateSpaces), Attrs, Types, Out.get(), Pred.get(), Ops);
}

InlineAsmExprResult InlineAsmParser::ParseExpression() {
Expand Down
4 changes: 3 additions & 1 deletion clang/lib/DPCT/RulesLang/RulesLang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4910,10 +4910,12 @@ void KernelCallRule::runRule(
const auto *LaunchKernelCall = getNodeAsType<CallExpr>(Result, "launch");
if (!LaunchKernelCall) {
LaunchKernelCall = getNodeAsType<CallExpr>(Result, "launchUsed");
if(!LaunchKernelCall)
return;
IsAssigned = true;
}
auto FD = LaunchKernelCall->getDirectCallee();
if (!LaunchKernelCall || !FD)
if (!FD)
return;
std::string FuncName = FD->getNameAsString();
if (FuncName == "cudaLaunchHostFunc") {
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,11 @@ bool Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
llvm::Triple PrefixTriple{ClangNameParts.TargetPrefix};
if (PrefixTriple.getArch() == llvm::Triple::UnknownArch ||
PrefixTriple.isOSUnknown())
#ifdef SYCLomatic_CUSTOMIZATION
Triple = std::move(PrefixTriple);
#else
Triple = PrefixTriple;
#endif
}

// Otherwise, use the real triple as used by the driver.
Expand Down Expand Up @@ -1876,7 +1880,11 @@ bool Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
}

// Try loading <triple>.cfg and return if we find a match.
#ifdef SYCLomatic_CUSTOMIZATION
if (findTripleConfigFile(ExpCtx, CfgFilePath, std::move(Triple), ".cfg"))
#else
if (findTripleConfigFile(ExpCtx, CfgFilePath, Triple, ".cfg"))
#endif
return readConfigFile(CfgFilePath, ExpCtx);

// If we were unable to find a config file deduced from executable name,
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Format/UnwrappedLineFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,11 @@ static auto computeNewlines(const AnnotatedLine &Line,
if (Line.startsWith(TT_NamespaceRBrace)) {
if (Style.WrapNamespaceBodyWithEmptyLines == FormatStyle::WNBWELS_Never)
Newlines = 1;
#ifdef SYCLomatic_CUSTOMIZATION
else if (PreviousLine && PreviousLine->startsWith(TT_NamespaceRBrace))
#else
else if (!PreviousLine->startsWith(TT_NamespaceRBrace))
#endif
Newlines = std::max(Newlines, 2u);
}
}
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18951,8 +18951,13 @@ void Sema::ActOnLastBitfield(SourceLocation DeclLoc,
// All conditions are met. Add a new bitfield to the tail end of ivars.
llvm::APInt Zero(Context.getTypeSize(Context.IntTy), 0);
Expr * BW = IntegerLiteral::Create(Context, Zero, Context.IntTy, DeclLoc);
#ifdef SYCLomatic_CUSTOMIZATION
Expr *BitWidth =
ConstantExpr::Create(Context, BW, APValue(llvm::APSInt(std::move(Zero))));
#else
Expr *BitWidth =
ConstantExpr::Create(Context, BW, APValue(llvm::APSInt(Zero)));
#endif

Ivar = ObjCIvarDecl::Create(
Context, cast<ObjCContainerDecl>(CurContext), DeclLoc, DeclLoc, nullptr,
Expand Down
5 changes: 4 additions & 1 deletion clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1668,8 +1668,11 @@ Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) {
if (!NewDD || NewDD->isInvalidDecl())
for (auto *NewBD : NewBindings)
NewBD->setInvalidDecl();

#ifdef SYCLomatic_CUSTOMIZATION
if (NewDD && OldResolvedPack) {
#else
if (OldResolvedPack) {
#endif
// Mark the holding vars (if any) in the pack as instantiated since
// they are created implicitly.
auto Bindings = NewDD->bindings();
Expand Down
31 changes: 9 additions & 22 deletions clang/lib/Tooling/Core/UnifiedPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,17 @@ void UnifiedPath::makeCanonical(const std::string &CWD) {
llvm::SmallString<512> RealPath;
// We need make sure the input `Path` for llvm::sys::fs::real_path is
// exsiting, or else the behavior of real_path() is unexpected.
if (llvm::sys::fs::exists(Path)) {
llvm::sys::fs::real_path(Path, RealPath, true);
} else {
llvm::SmallString<512> Suffix;
if (llvm::sys::path::has_filename(Path)) {
Suffix = llvm::sys::path::filename(Path).str();
llvm::sys::path::remove_filename(Path);
}
while (!llvm::sys::fs::exists(Path)) {
if (!llvm::sys::path::has_parent_path(Path)) {
assert(0 && "no real directory found");
return;
}
llvm::sys::path::reverse_iterator RI =
llvm::sys::path::rbegin(llvm::StringRef(Path));
llvm::SmallString<512> SuffixTemp(*RI);
llvm::sys::path::append(SuffixTemp, llvm::sys::path::Style::native,
Suffix);
Suffix = SuffixTemp;
Path = llvm::SmallString<512>(llvm::sys::path::parent_path(Path).str());
llvm::StringRef ParentPath = Path;
while (!llvm::sys::fs::exists(ParentPath)) {
ParentPath = llvm::sys::path::parent_path(ParentPath);
if (ParentPath.empty()) {
assert(0 && "no real directory found");
return;
}
llvm::sys::fs::real_path(Path, RealPath, true);
llvm::sys::path::append(RealPath, llvm::sys::path::Style::native, Suffix);
}
llvm::sys::fs::real_path(ParentPath, RealPath, true);
if (auto Suffix = Path.substr(ParentPath.size()); !Suffix.empty())
llvm::sys::path::append(RealPath, llvm::sys::path::Style::native, Suffix);
_CanonicalPath = RealPath.str();
#if defined(_WIN32)
if (_CanonicalPath.size() >= 3 &&
Expand Down
Loading