Skip to content

Commit

Permalink
[SYCLomatic][Coverity] Fix coverity issues (#2577)
Browse files Browse the repository at this point in the history
Signed-off-by: Ziran Zhang <[email protected]>
  • Loading branch information
ziranzha authored Dec 24, 2024
1 parent c0852a0 commit bf9df04
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion clang/lib/DPCT/AnalysisInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7044,7 +7044,7 @@ void deduceTemplateArgumentFromType(std::vector<TemplateArgumentInfo> &TAIList,
case Type::ConstantArray: {
auto ArgConstArray = ARG_TYPE_CAST(ConstantArrayType);
auto ParmConstArray = PARM_TYPE_CAST(ConstantArrayType);
if (ArgConstArray &&
if (ArgConstArray && ParmConstArray &&
ArgConstArray->getSize() == ParmConstArray->getSize()) {
deduceTemplateArgumentFromArrayElement(TAIList, ParmType, ArgType, TL);
}
Expand Down
1 change: 0 additions & 1 deletion clang/lib/DPCT/CodePin/GenCodePinHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ void GenCodePinHeaderRule::processCodePinTypeMemberOrBase(
}
}

PrintPolicy.SuppressScope = true;
PrintPolicy.SuppressScope = false;
MemberOrBaseInfo.UserDefinedTypeFlag =
isTypeInAnalysisScope(NextMT.getTypePtrOrNull());
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/DPCT/DPCT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ int migratePythonScript(const clang::tooling::UnifiedPath &InRoot,
}

// print APIMapping of Query
int showAPIMapping(std::string SrcAPI, std::string Option,
RefactoringTool &Tool, ReplTy &ReplSYCL) {
int showAPIMapping(StringRef SrcAPI, StringRef Option, RefactoringTool &Tool,
ReplTy &ReplSYCL) {
llvm::outs() << "CUDA API:" << llvm::raw_ostream::GREEN << SrcAPI
<< llvm::raw_ostream::RESET;
DiagnosticsEngine Diagnostics(
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/DPCT/RuleInfra/TypeLocRewriters.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ class TypeLocEmitWarningRewriterFactory : public TypeLocRewriterFactoryBase {
TypeLocEmitWarningRewriterFactory(
std::shared_ptr<TypeLocRewriterFactoryBase> InnerFactory, Diagnostics ID,
MsgArgsT... Args)
: Inner(InnerFactory), MsgID(ID), MsgArgs(std::make_tuple(Args...)) {}
: Inner(std::move(InnerFactory)), MsgID(ID),
MsgArgs(std::make_tuple(Args...)) {}
std::shared_ptr<TypeLocRewriter> create(const TypeLoc TL) const override {
std::apply(
[&](auto... Args) {
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/DPCT/RulesLang/CallExprRewriterTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ class TextureReadRewriterFactory : public CallExprRewriterFactoryBase {

public:
TextureReadRewriterFactory(std::string Name, int Tex, std::string TargetName)
: Source(std::move(Name)), TexType(Tex), TargetName(TargetName) {}
: Source(std::move(Name)), TexType(Tex),
TargetName(std::move(TargetName)) {}
std::shared_ptr<CallExprRewriter>
create(const CallExpr *Call) const override {
const Expr *SourceExpr = Call->getArg(0);
Expand Down
9 changes: 4 additions & 5 deletions clang/lib/DPCT/RulesLang/Math/CallExprRewriterMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ static inline bool isTargetMathFunction(const FunctionDecl *FD) {
if (!FD)
return false;
auto FilePath = DpctGlobalInfo::getLocInfo(FD).first;
if (auto S = DpctGlobalInfo::getAnalysisScope();
std::any_of(S.begin(), S.end(),
[FP = FilePath](const clang::tooling::UnifiedPath &P) {
return isChildOrSamePath(P, FP);
}))
if (auto S = DpctGlobalInfo::getAnalysisScope(); std::any_of(
S.begin(), S.end(), [&](const clang::tooling::UnifiedPath &P) {
return isChildOrSamePath(P, FilePath);
}))
return false;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/DPCT/RulesMathLib/MapNamesSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class MapNamesSolver {
repl.MissedArgumentIsBuffer = std::move(mab);
repl.MissedArgumentType = std::move(mat);
repl.MissedArgumentName = std::move(man);
repl.ReplName = s;
repl.ReplName = std::move(s);
return repl;
};

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 @@ -2913,7 +2913,11 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
// FIXME: For some more esoteric targets the default toolchain is not the
// correct one.
C.getArgsForToolChain(&TC, Triple.getArchName(), Action::OFK_None);
#ifdef SYCLomatic_CUSTOMIZATION
RegisterEffectiveTriple TripleRAII(TC, std::move(Triple));
#else
RegisterEffectiveTriple TripleRAII(TC, Triple);
#endif
switch (RLT) {
case ToolChain::RLT_CompilerRT:
llvm::outs() << TC.getCompilerRT(C.getArgs(), "builtins") << "\n";
Expand Down Expand Up @@ -6115,7 +6119,11 @@ class OffloadingActionBuilder final {
auto ProvidedPath =
Args.getLastArgValue(options::OPT_fsycl_libspirv_path_EQ).str();
if (llvm::sys::fs::exists(ProvidedPath))
#ifdef SYCLomatic_CUSTOMIZATION
LibSpirvFile = std::move(ProvidedPath);
#else
LibSpirvFile = ProvidedPath;
#endif
} else {
SmallVector<StringRef, 2> LibraryPaths;

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,11 @@ static std::string getDeviceArg(const ArgStringList &CmdArgs) {
return DeviceArg;
}

#ifdef SYCLomatic_CUSTOMIZATION
static bool checkPVCDevice(const std::string &SingleArg, std::string &DevArg) {
#else
static bool checkPVCDevice(std::string SingleArg, std::string &DevArg) {
#endif
// Handle shortened versions.
bool CheckShortVersion = true;
for (auto Char : SingleArg) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/ProfileData/InstrProfReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class RawInstrProfReader : public InstrProfReader {
const InstrProfCorrelator *Correlator,
const object::BuildIDFetcher *BIDFetcher,
const InstrProfCorrelator::ProfCorrelatorKind BIDFetcherCorrelatorKind,
std::function<void(Error)> Warn)
const std::function<void(Error)> &Warn)
: DataBuffer(std::move(DataBuffer)),
Correlator(dyn_cast_or_null<const InstrProfCorrelatorImpl<IntPtrT>>(
Correlator)),
Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/ProfileData/InstrProfReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ Expected<std::unique_ptr<InstrProfReader>> InstrProfReader::create(
if (Error E = BufferOrError.takeError())
return std::move(E);
return InstrProfReader::create(std::move(BufferOrError.get()), Correlator,
#ifdef SYCLomatic_CUSTOMIZATION
BIDFetcher, BIDFetcherCorrelatorKind,
std::move(Warn));
#else
BIDFetcher, BIDFetcherCorrelatorKind, Warn);
#endif
}

Expected<std::unique_ptr<InstrProfReader>> InstrProfReader::create(
Expand Down

0 comments on commit bf9df04

Please sign in to comment.