This is an archive of the discontinued LLVM Phabricator instance.

[NFC][CLANG] Fix static analyzer tool remarks about unchecked return values
AbandonedPublic

Authored by Manna on Apr 7 2023, 9:12 AM.

Details

Summary

Reported by Coverity:

Unchecked return value
If the function returns an error value, the error value may be mistaken for a normal value.

  1. Inside "Parser.cpp" file, in clang::Parser::ParseKNRParamDeclarations(clang::Declarator &): Value returned from a function is not checked for errors before being used.

check_return: Calling TryConsumeToken without checking return value (as is done elsewhere 75 out of 86 times).

  1. Inside "CallGraph.h" file, in clang::CallGraph::addToCallGraph(clang::Decl *): Value returned from a function is not checked for errors before being used.

check_return: Calling TraverseDecl without checking return value (as is done elsewhere 22 out of 23 times).

  1. Inside "TokenAnnotator.cpp" file ,in clang::​format::​<unnamed>::​AnnotatingParser::​consumeToken(): Value returned from a function is not checked for errors before being used.

    check_return: Calling consumeToken without checking return value (as is done elsewhere 6 out of 7 times).
  1. Inside "UnsafeBufferUsage.cpp" file, In clang::​ast_matchers::​MatchDescendantVisitor::​findMatch(clang::​DynTypedNode const &): Value returned from a function is not checked for errors before being used.

check_return: Calling TraverseStmt without checking return value (as is done elsewhere 485 out of 489 times)

  1. Inside "ItaniumDemangle.h" file, in llvm::​itanium_demangle::​AbstractManglingParser<llvm::​itanium_demangle::​ManglingParser<<unnamed>::​CanonicalizerAllocator>, <unnamed>::​CanonicalizerAllocator>::​parseFunctionType(): Value returned from a function is not checked for errors before being used.

    check_return: Calling consumeIf without checking return value (as is done elsewhere 47 out of 50 times).
  1. Inside "ItaniumDemangle.h" file, in llvm::​itanium_demangle::​AbstractManglingParser<llvm::​itanium_demangle::​ManglingParser<<unnamed>::​CanonicalizerAllocator>, <unnamed>::​CanonicalizerAllocator>::​parseBaseUnresolvedName(): Value returned from a function is not checked for errors before being used.

check_return: Calling consumeIf without checking return value (as is done elsewhere 47 out of 50 times).

  1. Inside "ItaniumDemangle.h" file, in llvm::​itanium_demangle::​AbstractManglingParser<llvm::​itanium_demangle::​ManglingParser<llvm::​esimd::​SimpleAllocator>, llvm::​esimd::​SimpleAllocator>::​parseNumber(bool): Value returned from a function is not checked for errors before being used.

check_return: Calling consumeIf without checking return value (as is done elsewhere 95 out of 102 times).

  1. Inside "ExprConstant.cpp" file, in clang::​Expr::​isPotentialConstantExprUnevaluated(clang::​Expr *, clang::​FunctionDecl const *, llvm::​SmallVectorImpl<std::​pair<clang::​SourceLocation, clang::​PartialDiagnostic>> &): Value returned from a function is not checked for errors before being used.

check_return: Calling Evaluate without checking return value (as is done elsewhere 23 out of 27 times).

  1. Inside "ASTMatchFinder.cpp" file, in clang::​ast_matchers::​internal::​<unnamed>::​MatchASTVisitor::​dataTraverseNode(clang::​Stmt *, llvm::​SmallVectorImpl<llvm::​PointerIntPair<clang::​Stmt *, 1u, bool, llvm::​PointerLikeTypeTraits<clang::​Stmt *>, llvm::​PointerIntPairInfo<clang::​Stmt *, 1u, llvm::​PointerLikeTypeTraits<clang::​Stmt *>>>> *): Value returned from a function is not checked for errors before being used.

check_return: Calling TraverseDecl without checking return value (as is done elsewhere 29 out of 33 times).

  1. Inside "ParseObjc.cpp" file, in clang::​Parser::​isStartOfObjCClassMessageMissingOpenBracket(): Value returned from a function is not checked for errors before being used.

check_return: Calling TryAnnotateTypeOrScopeToken without checking return value (as is done elsewhere 19 out of 21 times).

Diff Detail

Event Timeline

Manna created this revision.Apr 7 2023, 9:12 AM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald Transcript
Manna requested review of this revision.Apr 7 2023, 9:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 7 2023, 9:12 AM

I don't see much value in these changes. In the cases I know anything about, the change in state (or out params) is the error checking that we need. The casts add nothing but noise, so I don't think these are good changes.

Manna added a comment.EditedApr 7 2023, 9:59 AM

I don't see much value in these changes. In the cases I know anything about, the change in state (or out params) is the error checking that we need. The casts add nothing but noise, so I don't think these are good changes.

Thanks @erichkeane for reviews and feedback. I agree with you that all changes will silence the static analyzer tool but will not make any big impact. I will close them as a False positive.

That sounds appropriate to me.

Manna abandoned this revision.Apr 7 2023, 10:04 AM