gamesh411 created this revision. gamesh411 added reviewers: steakhal, martong, whisperity. gamesh411 added a project: clang-tools-extra. Herald added subscribers: carlosgalvezp, Szelethus, dkrupp, rnkovacs, xazax.hun. Herald added a project: All. gamesh411 requested review of this revision. Herald added a subscriber: cfe-commits.
Clang Tidy check cert-oop57-cpp now checks for arbitrary-valued integer literals in memset expressions containing non-trivially default-constructible instances. Previously it only checked 0 values. Note that the first non-compliant example of https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP57-CPP.+Prefer+special+member+functions+and+overloaded+operators+to+C+Standard+Library+functions requires this. A comparative analysis of OS projects is currently running to see the impact of this change. https://reviews.llvm.org/D126186 Files: clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp Index: clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp +++ clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp @@ -88,3 +88,10 @@ mymemcmp(&Data, &Other, sizeof(Data)); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'mymemcmp' } + +void nonNullSetValue() { + NonTrivial Data; + // Check non-null-valued second argument. + std::memset(&Data, 1, sizeof(Data)); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'memset' on a non-trivially default constructible class is undefined +} Index: clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp +++ clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp @@ -90,7 +90,7 @@ callExpr(callee(namedDecl(hasAnyName( utils::options::parseListPair(BuiltinMemSet, MemSetNames)))), ArgChecker(unless(isTriviallyDefaultConstructible()), - expr(integerLiteral(equals(0))))) + expr(integerLiteral()))) .bind("lazyConstruct"), this); Finder->addMatcher(
Index: clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp =================================================================== --- clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp +++ clang-tools-extra/test/clang-tidy/checkers/cert-oop57-cpp.cpp @@ -88,3 +88,10 @@ mymemcmp(&Data, &Other, sizeof(Data)); // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: consider using comparison operators instead of calling 'mymemcmp' } + +void nonNullSetValue() { + NonTrivial Data; + // Check non-null-valued second argument. + std::memset(&Data, 1, sizeof(Data)); + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling 'memset' on a non-trivially default constructible class is undefined +} Index: clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp =================================================================== --- clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp +++ clang-tools-extra/clang-tidy/cert/NonTrivialTypesLibcMemoryCallsCheck.cpp @@ -90,7 +90,7 @@ callExpr(callee(namedDecl(hasAnyName( utils::options::parseListPair(BuiltinMemSet, MemSetNames)))), ArgChecker(unless(isTriviallyDefaultConstructible()), - expr(integerLiteral(equals(0))))) + expr(integerLiteral()))) .bind("lazyConstruct"), this); Finder->addMatcher(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits