Skip to content

Commit 6026ae0

Browse files
ziranzhazhiweij1
andauthored
[SYCLomatic] Fix coverity issues (#2812)
Signed-off-by: Ziran Zhang <ziran.zhang@intel.com> Co-authored-by: Jiang, Zhiwei <zhiwei.jiang@intel.com>
1 parent c801703 commit 6026ae0

File tree

10 files changed

+46
-31
lines changed

10 files changed

+46
-31
lines changed

clang/lib/DPCT/AnalysisInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7526,7 +7526,7 @@ void FreeQueriesInfo::printImmediateText(llvm::raw_ostream &OS, const Node *S,
75267526
if (!DFI)
75277527
return;
75287528
auto Index = DpctGlobalInfo::getCudaKernelDimDFIIndexThenInc();
7529-
DpctGlobalInfo::insertCudaKernelDimDFIMap(Index, DFI);
7529+
DpctGlobalInfo::insertCudaKernelDimDFIMap(Index, std::move(DFI));
75307530
printFreeQueriesFunctionName<std::string>(
75317531
OS, K, "{{NEEDREPLACEG" + std::to_string(Index) + "}}");
75327532
} else {

clang/lib/DPCT/DPCT.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,9 +1029,14 @@ int runDPCT(int argc, const char **argv) {
10291029
if (SourceCode.starts_with(OptionStr)) {
10301030
QueryAPIMappingOpt += " (with the option";
10311031
while (SourceCode.consume_front(OptionStr)) {
1032-
auto Option = SourceCode.substr(0, SourceCode.find_first_of('\n'));
1033-
Option = Option.trim(' ');
1034-
SourceCode = SourceCode.substr(SourceCode.find_first_of('\n') + 1);
1032+
auto Pos = SourceCode.find('\n');
1033+
StringRef Option;
1034+
if (Pos == StringRef::npos) {
1035+
std::swap(Option, SourceCode);
1036+
} else {
1037+
Option = SourceCode.substr(0, Pos).trim(' ');
1038+
SourceCode = SourceCode.substr(Pos + 1);
1039+
}
10351040
QueryAPIMappingOpt += " ";
10361041
QueryAPIMappingOpt += Option.str();
10371042
if (Option.starts_with("--use-dpcpp-extensions")) {

clang/lib/DPCT/RuleInfra/CallExprRewriter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,8 @@ class MultiStmtsPrinter : public MultiStmtsPrinter<RestPrinter...> {
12641264

12651265
MultiStmtsPrinter(std::string Indent, std::string NL, bool IsInMacroDef,
12661266
FirstPrinter &&First, RestPrinter &&...Rest)
1267-
: Base(Indent, NL, IsInMacroDef, std::move(Rest)...),
1267+
: Base(std::move(Indent), std::move(NL), IsInMacroDef,
1268+
std::move(Rest)...),
12681269
First(std::move(First)) {}
12691270

12701271
template <class StreamT> void print(StreamT &Stream) const {

clang/lib/DPCT/RulesAsm/Parser/AsmParser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ InlineAsmStmtResult InlineAsmParser::ParseInstruction() {
385385
Types.push_back(Context.getBuiltinType(InlineAsmBuiltinType::u32));
386386
}
387387

388-
return ::new (Context) InlineAsmInstruction(Opcode, StateSpaces, Attrs, Types,
389-
Out.get(), Pred.get(), Ops);
388+
return ::new (Context) InlineAsmInstruction(
389+
Opcode, std::move(StateSpaces), Attrs, Types, Out.get(), Pred.get(), Ops);
390390
}
391391

392392
InlineAsmExprResult InlineAsmParser::ParseExpression() {

clang/lib/DPCT/RulesLang/RulesLang.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4926,10 +4926,12 @@ void KernelCallRule::runRule(
49264926
const auto *LaunchKernelCall = getNodeAsType<CallExpr>(Result, "launch");
49274927
if (!LaunchKernelCall) {
49284928
LaunchKernelCall = getNodeAsType<CallExpr>(Result, "launchUsed");
4929+
if(!LaunchKernelCall)
4930+
return;
49294931
IsAssigned = true;
49304932
}
49314933
auto FD = LaunchKernelCall->getDirectCallee();
4932-
if (!LaunchKernelCall || !FD)
4934+
if (!FD)
49334935
return;
49344936
std::string FuncName = FD->getNameAsString();
49354937
if (FuncName == "cudaLaunchHostFunc") {

clang/lib/Driver/Driver.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,11 @@ bool Driver::loadDefaultConfigFiles(llvm::cl::ExpansionContext &ExpCtx) {
18221822
llvm::Triple PrefixTriple{ClangNameParts.TargetPrefix};
18231823
if (PrefixTriple.getArch() == llvm::Triple::UnknownArch ||
18241824
PrefixTriple.isOSUnknown())
1825+
#ifdef SYCLomatic_CUSTOMIZATION
1826+
Triple = std::move(PrefixTriple);
1827+
#else
18251828
Triple = PrefixTriple;
1829+
#endif
18261830
}
18271831

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

18781882
// Try loading <triple>.cfg and return if we find a match.
1883+
#ifdef SYCLomatic_CUSTOMIZATION
1884+
if (findTripleConfigFile(ExpCtx, CfgFilePath, std::move(Triple), ".cfg"))
1885+
#else
18791886
if (findTripleConfigFile(ExpCtx, CfgFilePath, Triple, ".cfg"))
1887+
#endif
18801888
return readConfigFile(CfgFilePath, ExpCtx);
18811889

18821890
// If we were unable to find a config file deduced from executable name,

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,11 @@ static auto computeNewlines(const AnnotatedLine &Line,
16721672
if (Line.startsWith(TT_NamespaceRBrace)) {
16731673
if (Style.WrapNamespaceBodyWithEmptyLines == FormatStyle::WNBWELS_Never)
16741674
Newlines = 1;
1675+
#ifdef SYCLomatic_CUSTOMIZATION
1676+
else if (PreviousLine && !PreviousLine->startsWith(TT_NamespaceRBrace))
1677+
#else
16751678
else if (!PreviousLine->startsWith(TT_NamespaceRBrace))
1679+
#endif
16761680
Newlines = std::max(Newlines, 2u);
16771681
}
16781682
}

clang/lib/Sema/SemaDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18951,8 +18951,13 @@ void Sema::ActOnLastBitfield(SourceLocation DeclLoc,
1895118951
// All conditions are met. Add a new bitfield to the tail end of ivars.
1895218952
llvm::APInt Zero(Context.getTypeSize(Context.IntTy), 0);
1895318953
Expr * BW = IntegerLiteral::Create(Context, Zero, Context.IntTy, DeclLoc);
18954+
#ifdef SYCLomatic_CUSTOMIZATION
18955+
Expr *BitWidth =
18956+
ConstantExpr::Create(Context, BW, APValue(llvm::APSInt(std::move(Zero))));
18957+
#else
1895418958
Expr *BitWidth =
1895518959
ConstantExpr::Create(Context, BW, APValue(llvm::APSInt(Zero)));
18960+
#endif
1895618961

1895718962
Ivar = ObjCIvarDecl::Create(
1895818963
Context, cast<ObjCContainerDecl>(CurContext), DeclLoc, DeclLoc, nullptr,

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,8 +1668,11 @@ Decl *TemplateDeclInstantiator::VisitDecompositionDecl(DecompositionDecl *D) {
16681668
if (!NewDD || NewDD->isInvalidDecl())
16691669
for (auto *NewBD : NewBindings)
16701670
NewBD->setInvalidDecl();
1671-
1671+
#ifdef SYCLomatic_CUSTOMIZATION
1672+
if (NewDD && OldResolvedPack) {
1673+
#else
16721674
if (OldResolvedPack) {
1675+
#endif
16731676
// Mark the holding vars (if any) in the pack as instantiated since
16741677
// they are created implicitly.
16751678
auto Bindings = NewDD->bindings();

clang/lib/Tooling/Core/UnifiedPath.cpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,17 @@ void UnifiedPath::makeCanonical(const std::string &CWD) {
5454
llvm::SmallString<512> RealPath;
5555
// We need make sure the input `Path` for llvm::sys::fs::real_path is
5656
// exsiting, or else the behavior of real_path() is unexpected.
57-
if (llvm::sys::fs::exists(Path)) {
58-
llvm::sys::fs::real_path(Path, RealPath, true);
59-
} else {
60-
llvm::SmallString<512> Suffix;
61-
if (llvm::sys::path::has_filename(Path)) {
62-
Suffix = llvm::sys::path::filename(Path).str();
63-
llvm::sys::path::remove_filename(Path);
64-
}
65-
while (!llvm::sys::fs::exists(Path)) {
66-
if (!llvm::sys::path::has_parent_path(Path)) {
67-
assert(0 && "no real directory found");
68-
return;
69-
}
70-
llvm::sys::path::reverse_iterator RI =
71-
llvm::sys::path::rbegin(llvm::StringRef(Path));
72-
llvm::SmallString<512> SuffixTemp(*RI);
73-
llvm::sys::path::append(SuffixTemp, llvm::sys::path::Style::native,
74-
Suffix);
75-
Suffix = SuffixTemp;
76-
Path = llvm::SmallString<512>(llvm::sys::path::parent_path(Path).str());
57+
llvm::StringRef ParentPath = Path;
58+
while (!llvm::sys::fs::exists(ParentPath)) {
59+
ParentPath = llvm::sys::path::parent_path(ParentPath);
60+
if (ParentPath.empty()) {
61+
assert(0 && "no real directory found");
62+
return;
7763
}
78-
llvm::sys::fs::real_path(Path, RealPath, true);
79-
llvm::sys::path::append(RealPath, llvm::sys::path::Style::native, Suffix);
8064
}
65+
llvm::sys::fs::real_path(ParentPath, RealPath, true);
66+
if (auto Suffix = Path.substr(ParentPath.size()); !Suffix.empty())
67+
llvm::sys::path::append(RealPath, llvm::sys::path::Style::native, Suffix);
8168
_CanonicalPath = RealPath.str();
8269
#if defined(_WIN32)
8370
if (_CanonicalPath.size() >= 3 &&

0 commit comments

Comments
 (0)