[clang-tools-extra] e4bb3e2 - [clang-tidy] Expand the list of functions in bugprone-unused-return-value
Author: Joe Ranieri Date: 2020-05-22T12:57:58-04:00 New Revision: e4bb3e25e4400151133fd3737f4842f2aeda1c1b URL: https://github.com/llvm/llvm-project/commit/e4bb3e25e4400151133fd3737f4842f2aeda1c1b DIFF: https://github.com/llvm/llvm-project/commit/e4bb3e25e4400151133fd3737f4842f2aeda1c1b.diff LOG: [clang-tidy] Expand the list of functions in bugprone-unused-return-value This change adds common C, C++, and POSIX functions to the clang-tidy unused return value checker. Differential Revision: https://reviews.llvm.org/D76083 Added: Modified: clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp Removed: diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp index c3efb08d4213..d49fd63f005d 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp @@ -43,7 +43,90 @@ UnusedReturnValueCheck::UnusedReturnValueCheck(llvm::StringRef Name, "::std::unique;" "::std::unique_ptr::release;" "::std::basic_string::empty;" - "::std::vector::empty")) {} + "::std::vector::empty;" + "::std::back_inserter;" + "::std::distance;" + "::std::find;" + "::std::find_if;" + "::std::inserter;" + "::std::lower_bound;" + "::std::make_pair;" + "::std::map::count;" + "::std::map::find;" + "::std::map::lower_bound;" + "::std::multimap::equal_range;" + "::std::multimap::upper_bound;" + "::std::set::count;" + "::std::set::find;" + "::std::setfill;" + "::std::setprecision;" + "::std::setw;" + "::std::upper_bound;" + "::std::vector::at;" + // C standard library + "::bsearch;" + "::ferror;" + "::feof;" + "::isalnum;" + "::isalpha;" + "::isblank;" + "::iscntrl;" + "::isdigit;" + "::isgraph;" + "::islower;" + "::isprint;" + "::ispunct;" + "::isspace;" + "::isupper;" + "::iswalnum;" + "::iswprint;" + "::iswspace;" + "::isxdigit;" + "::memchr;" + "::memcmp;" + "::strcmp;" + "::strcoll;" + "::strncmp;" + "::strpbrk;" + "::strrchr;" + "::strspn;" + "::strstr;" + "::wcscmp;" + // POSIX + "::access;" + "::bind;" + "::connect;" + ":: diff time;" + "::dlsym;" + "::fnmatch;" + "::getaddrinfo;" + "::getopt;" + "::htonl;" + "::htons;" + "::iconv_open;" + "::inet_addr;" + "::isascii;" + "::isatty;" + "::mmap;" + "::newlocale;" + "::openat;" + "::pathconf;" + "::pthread_equal;" + "::pthread
r370051 - Testing commit access; NFC
Author: jranieri Date: Tue Aug 27 05:36:25 2019 New Revision: 370051 URL: http://llvm.org/viewvc/llvm-project?rev=370051&view=rev Log: Testing commit access; NFC Modified: cfe/trunk/www/index.html Modified: cfe/trunk/www/index.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/index.html?rev=370051&r1=370050&r2=370051&view=diff == --- cfe/trunk/www/index.html (original) +++ cfe/trunk/www/index.html Tue Aug 27 05:36:25 2019 @@ -105,7 +105,6 @@ interested in following the development of Clang, signing up for a mailing list is a good way to learn about how the project works. - ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r370060 - Fix text range end columns in SARIF to be exclusive
Author: jranieri Date: Tue Aug 27 06:49:45 2019 New Revision: 370060 URL: http://llvm.org/viewvc/llvm-project?rev=370060&view=rev Log: Fix text range end columns in SARIF to be exclusive According to the SARIF specification, "a text region does not include the character specified by endColumn". Differential Revision: https://reviews.llvm.org/D65206 Modified: cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif Modified: cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp?rev=370060&r1=370059&r2=370060&view=diff == --- cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp Tue Aug 27 06:49:45 2019 @@ -143,11 +143,17 @@ static json::Object createFileLocation(c } static json::Object createTextRegion(SourceRange R, const SourceManager &SM) { - return json::Object{ + json::Object Region{ {"startLine", SM.getExpansionLineNumber(R.getBegin())}, - {"endLine", SM.getExpansionLineNumber(R.getEnd())}, {"startColumn", SM.getExpansionColumnNumber(R.getBegin())}, - {"endColumn", SM.getExpansionColumnNumber(R.getEnd())}}; + }; + if (R.getBegin() == R.getEnd()) { +Region["endColumn"] = SM.getExpansionColumnNumber(R.getBegin()); + } else { +Region["endLine"] = SM.getExpansionLineNumber(R.getEnd()); +Region["endColumn"] = SM.getExpansionColumnNumber(R.getEnd()) + 1; + } + return Region; } static json::Object createPhysicalLocation(SourceRange R, const FileEntry &FE, Modified: cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif?rev=370060&r1=370059&r2=370060&view=diff == --- cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif (original) +++ cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif Tue Aug 27 06:49:45 2019 @@ -44,7 +44,7 @@ "fileIndex": 0, }, "region": { -"endColumn": 5, +"endColumn": 6, "endLine": 13, "startColumn": 3, "startLine": 13 @@ -63,7 +63,7 @@ "fileIndex": 0, }, "region": { -"endColumn": 17, +"endColumn": 18, "endLine": 9, "startColumn": 11, "startLine": 9 @@ -83,7 +83,7 @@ "fileIndex": 0, }, "region": { - "endColumn": 17, + "endColumn": 18, "endLine": 9, "startColumn": 11, "startLine": 9 Modified: cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif?rev=370060&r1=370059&r2=370060&view=diff == --- cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif (original) +++ cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif Tue Aug 27 06:49:45 2019 @@ -64,7 +64,7 @@ "fileIndex": 0, }, "region": { -"endColumn": 5, +"endColumn": 6, "endLine": 24, "startColumn": 3, "startLine": 24 @@ -83,7 +83,7 @@ "fileIndex": 0, }, "region": { -"endColumn": 17, +"endColumn": 18, "endLine": 9, "startColumn": 11, "startLine": 9 @@ -103,7 +103,7 @@ "fileIndex": 0, }, "region": { - "endColumn": 17, + "endColumn": 18, "endLine":
r370061 - Fix a SARIF exporter crash with macro expansions
Author: jranieri Date: Tue Aug 27 07:20:27 2019 New Revision: 370061 URL: http://llvm.org/viewvc/llvm-project?rev=370061&view=rev Log: Fix a SARIF exporter crash with macro expansions Differential Revision: https://reviews.llvm.org/D65209 Modified: cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif cfe/trunk/test/Analysis/diagnostics/sarif-multi-diagnostic-test.c Modified: cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp?rev=370061&r1=370060&r2=370061&view=diff == --- cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp Tue Aug 27 07:20:27 2019 @@ -219,9 +219,10 @@ static json::Object createThreadFlow(con for (const auto &Piece : Pieces) { const PathDiagnosticLocation &P = Piece->getLocation(); Locations.push_back(createThreadFlowLocation( -createLocation(createPhysicalLocation(P.asRange(), - *P.asLocation().getFileEntry(), - SMgr, Files), +createLocation(createPhysicalLocation( + P.asRange(), + *P.asLocation().getExpansionLoc().getFileEntry(), + SMgr, Files), Piece->getString()), calculateImportance(*Piece))); } @@ -255,7 +256,8 @@ static json::Object createResult(const P {"locations", json::Array{createLocation(createPhysicalLocation( Diag.getLocation().asRange(), - *Diag.getLocation().asLocation().getFileEntry(), SMgr, Files))}}, + *Diag.getLocation().asLocation().getExpansionLoc().getFileEntry(), + SMgr, Files))}}, {"ruleIndex", Iter->getValue()}, {"ruleId", Diag.getCheckName()}}; } Modified: cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif?rev=370061&r1=370060&r2=370061&view=diff == --- cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif (original) +++ cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif Tue Aug 27 07:20:27 2019 @@ -6,7 +6,7 @@ { "fileLocation": { }, - "length": 686, + "length": 951, "mimeType": "text/plain", "roles": [ "resultFile" @@ -43,6 +43,16 @@ "name": { "text": "core.DivideZero" } + }, + { +"fullDescription": { + "text": "Check for memory leaks, double free, and use-after-free problems. Traces memory managed by malloc()/free()." +}, +"helpUri": "https://clang-analyzer.llvm.org/available_checks.html#unix.Malloc";, +"id": "unix.Malloc", +"name": { + "text": "unix.Malloc" +} } ] }, @@ -65,9 +75,9 @@ }, "region": { "endColumn": 6, -"endLine": 24, +"endLine": 34, "startColumn": 3, -"startLine": 24 +"startLine": 34 } } } @@ -84,9 +94,9 @@ }, "region": { "endColumn": 18, -"endLine": 9, +"endLine": 11, "startColumn": 11, -"startLine": 9 +"startLine": 11 } } } @@ -104,9 +114,9 @@ }, "region": { "endColumn": 18, - "endLine": 9, + "endLine": 11, "startColumn": 11, - "startLine": 9 + "startLine": 11 } } } @@ -135,9 +145,9 @@ }, "region": { "endColumn": 6, -"endLine": 25, +"endLine": 35, "startColumn": 3, -"startLine": 25 +"startLine": 35
r370068 - Update the SARIF exporter to SARIF 2.1
Author: jranieri Date: Tue Aug 27 07:43:54 2019 New Revision: 370068 URL: http://llvm.org/viewvc/llvm-project?rev=370068&view=rev Log: Update the SARIF exporter to SARIF 2.1 This updates the SARIF exporter to produce SARIF 2.1 output. The bulk of the diffs come from two changes to SARIF: * https://github.com/oasis-tcs/sarif-spec/issues/309 * https://github.com/oasis-tcs/sarif-spec/issues/179 Differential Revision: https://reviews.llvm.org/D65211 Modified: cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-diagnostics-taint-test.c.sarif cfe/trunk/test/Analysis/diagnostics/Inputs/expected-sarif/sarif-multi-diagnostic-test.c.sarif cfe/trunk/test/Analysis/lit.local.cfg Modified: cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp?rev=370068&r1=370067&r2=370068&view=diff == --- cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Core/SarifDiagnostics.cpp Tue Aug 27 07:43:54 2019 @@ -106,26 +106,26 @@ static std::string fileNameToURI(StringR return Ret.str().str(); } -static json::Object createFileLocation(const FileEntry &FE) { +static json::Object createArtifactLocation(const FileEntry &FE) { return json::Object{{"uri", fileNameToURI(getFileName(FE))}}; } -static json::Object createFile(const FileEntry &FE) { - return json::Object{{"fileLocation", createFileLocation(FE)}, +static json::Object createArtifact(const FileEntry &FE) { + return json::Object{{"location", createArtifactLocation(FE)}, {"roles", json::Array{"resultFile"}}, {"length", FE.getSize()}, {"mimeType", "text/plain"}}; } -static json::Object createFileLocation(const FileEntry &FE, - json::Array &Files) { +static json::Object createArtifactLocation(const FileEntry &FE, + json::Array &Artifacts) { std::string FileURI = fileNameToURI(getFileName(FE)); - // See if the Files array contains this URI already. If it does not, create - // a new file object to add to the array. - auto I = llvm::find_if(Files, [&](const json::Value &File) { + // See if the Artifacts array contains this URI already. If it does not, + // create a new artifact object to add to the array. + auto I = llvm::find_if(Artifacts, [&](const json::Value &File) { if (const json::Object *Obj = File.getAsObject()) { - if (const json::Object *FileLoc = Obj->getObject("fileLocation")) { + if (const json::Object *FileLoc = Obj->getObject("location")) { Optional URI = FileLoc->getString("uri"); return URI && URI->equals(FileURI); } @@ -133,13 +133,13 @@ static json::Object createFileLocation(c return false; }); - // Calculate the index within the file location array so it can be stored in + // Calculate the index within the artifact array so it can be stored in // the JSON object. - auto Index = static_cast(std::distance(Files.begin(), I)); - if (I == Files.end()) -Files.push_back(createFile(FE)); + auto Index = static_cast(std::distance(Artifacts.begin(), I)); + if (I == Artifacts.end()) +Artifacts.push_back(createArtifact(FE)); - return json::Object{{"uri", FileURI}, {"fileIndex", Index}}; + return json::Object{{"uri", FileURI}, {"index", Index}}; } static json::Object createTextRegion(SourceRange R, const SourceManager &SM) { @@ -158,9 +158,10 @@ static json::Object createTextRegion(Sou static json::Object createPhysicalLocation(SourceRange R, const FileEntry &FE, const SourceManager &SMgr, - json::Array &Files) { - return json::Object{{{"fileLocation", createFileLocation(FE, Files)}, - {"region", createTextRegion(R, SMgr)}}}; + json::Array &Artifacts) { + return json::Object{ + {{"artifactLocation", createArtifactLocation(FE, Artifacts)}, + {"region", createTextRegion(R, SMgr)}}}; } enum class Importance { Important, Essential, Unimportant }; @@ -213,7 +214,7 @@ static Importance calculateImportance(co } static json::Object createThreadFlow(const PathPieces &Pieces, - json::Array &Files) { + json::Array &Artifacts) { const SourceManager &SMgr = Pieces.front()->getLocation().getManager(); json::Array Locations; for (const auto &Piece : Pieces) { @@ -222,7 +223,7 @@ static json::Object createThreadFlow(con createLocation(createPhysicalLocation( P.asRange(), *P.asLocation().getExpansionLoc().getFileEntry(), -
[PATCH] Don't crash when dumping objc_bridge_related attributes
Clang's AST dumping currently crashes when dumping objc_bridge_related attributes where the class method and instance method fields are left empty. The attached patch marks the two arguments as optional and updates TableGen to understand the optional flag for identifier attribute arguments when generating the dump function. -- Joe Ranieri Index: include/clang/Basic/Attr.td === --- include/clang/Basic/Attr.td (revision 254076) +++ include/clang/Basic/Attr.td (working copy) @@ -1071,8 +1071,8 @@ let Spellings = [GNU<"objc_bridge_related">]; let Subjects = SubjectList<[Record], ErrorDiag>; let Args = [IdentifierArgument<"RelatedClass">, - IdentifierArgument<"ClassMethod">, - IdentifierArgument<"InstanceMethod">]; + IdentifierArgument<"ClassMethod", 1>, + IdentifierArgument<"InstanceMethod", 1>]; let HasCustomParsing = 1; let Documentation = [Undocumented]; } Index: test/Misc/ast-dump-attr.cpp === --- test/Misc/ast-dump-attr.cpp (revision 254076) +++ test/Misc/ast-dump-attr.cpp (working copy) @@ -150,3 +150,7 @@ // CHECK: DeprecatedAttr } } + +struct __attribute__((objc_bridge_related(NSParagraphStyle,,))) TestBridgedRef; +// CHECK: CXXRecordDecl{{.*}} struct TestBridgedRef +// CHECK-NEXT: ObjCBridgeRelatedAttr{{.*}} NSParagraphStyle Index: utils/TableGen/ClangAttrEmitter.cpp === --- utils/TableGen/ClangAttrEmitter.cpp (revision 254076) +++ utils/TableGen/ClangAttrEmitter.cpp (working copy) @@ -279,6 +279,8 @@ OS << "OS << \" \";\n"; OS << "dumpBareDeclRef(SA->get" << getUpperName() << "());\n"; } else if (type == "IdentifierInfo *") { +if (isOptional()) + OS << "if (SA->get" << getUpperName() << "())\n "; OS << "OS << \" \" << SA->get" << getUpperName() << "()->getName();\n"; } else if (type == "TypeSourceInfo *") { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] Don't crash when dumping objc_bridge_related attributes
On Thu, Nov 26, 2015 at 11:29 AM, Aaron Ballman wrote: > On Wed, Nov 25, 2015 at 6:13 PM, Joe Ranieri wrote: >> Clang's AST dumping currently crashes when dumping objc_bridge_related >> attributes where the class method and instance method fields are left >> empty. The attached patch marks the two arguments as optional and >> updates TableGen to understand the optional flag for identifier >> attribute arguments when generating the dump function. > > LGTM, thank you! Do you have commit privileges, or would you like me > to commit on your behalf? > > ~Aaron Please commit on my behalf. -- Joe Ranieri ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits