[PATCH] D52854: Use is.constant intrinsic for __builtin_constant_p
void added a comment. @rsmith I've been implementing your suggestion, but it's quickly becoming ridiculous. Just to implement a `ConstExpr` wrapper class, I need to touch ~23 files, virtually all changes being boilerplate code to forward the action to the wrapped expression. And this is before I add the code in this patch that implements the feature. While it would be nice to use LLVM's type system to determine if an expression is expected to be constant, it appears that doing that is much worse than adding the information to the bits field you mentioned. Repository: rC Clang https://reviews.llvm.org/D52854 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52219: [analyzer] (1/n) Support pointee mutation analysis in ExprMutationAnalyzer.
JonasToth added a comment. I think you can commit, there was enough opportunity to respond and we pinged directly as well. Repository: rC Clang https://reviews.llvm.org/D52219 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52390: [analyzer] Add StackSizeChecker to StaticAnalyzer
Szelethus added a comment. It'd also be good to have an entry in `www/analyzer/alpha_checks.html`. We've been neglecting it for long enough :/. Repository: rC Clang https://reviews.llvm.org/D52390 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52969: [analyzer][www] Added the missing alpha.cplusplus checkers to the webpage
Szelethus created this revision. Szelethus added reviewers: NoQ, george.karpenkov, baloghadamsoftware, rnkovacs. Herald added subscribers: cfe-commits, mikhail.ramalho, a.sidorin, szepet, xazax.hun, whisperity. Repository: rC Clang https://reviews.llvm.org/D52969 Files: www/analyzer/alpha_checks.html www/analyzer/available_checks.html Index: www/analyzer/available_checks.html === --- www/analyzer/available_checks.html +++ www/analyzer/available_checks.html @@ -543,7 +543,34 @@ Name, DescriptionExample + + +optin.cplusplus.VirtualCall +(C++) +Check virtual member function calls during construction or +destruction. + + +class A { +public: + A() { +f(); // warn + } + virtual void f(); +}; + + +class A { +public: + ~A() { +this->f(); // warn + } + virtual void f(); +}; + + + optin.mpi.MPI-Checker (C) Index: www/analyzer/alpha_checks.html === --- www/analyzer/alpha_checks.html +++ www/analyzer/alpha_checks.html @@ -275,93 +275,192 @@ + +alpha.core.StackAddressAsyncEscape +(C) +Check that addresses to stack memory do not escape the function that involves +dispatch_after or dispatch_async. This checker is +a part of core.StackAddressEscape, but is +https://reviews.llvm.org/D41042>temporarily disabled until some +false positives are fixed. + + +dispatch_block_t test_block_inside_block_async_leak() { + int x = 123; + void (^inner)(void) = ^void(void) { +int y = x; +++y; + }; + void (^outer)(void) = ^void(void) { +int z = x; +++z; +inner(); + }; + return outer; // warn: address of stack-allocated block is captured by a +// returned block +} + + + + + + alpha.core.TestAfterDivZero -(C, C++, ObjC) +(C++) Check for division by variable that is later compared against 0. Either the comparison is useless or there is division by zero. -void test(int x) { - var = 77 / x; - if (x == 0) { } // warn +void err_eq(int x) { + var = 77 / x; // note: Division with compared value made here + if (x == 0) { } // warn: value being compared against zero has already been + // used for division } - - C++ Alpha Checkers Name, DescriptionExample - + + -alpha.cplusplus.VirtualCall +alpha.cplusplus.DeleteWithNonVirtualDtor (C++) -Check virtual member function calls during construction or -destruction. +Reports destructions of polymorphic objects with a non-virtual destructor in +their base class + -class A { -public: - A() { -f(); // warn - } - virtual void f(); -}; - +NonVirtual *create() { + NonVirtual *x = new NVDerived(); // note: conversion from derived to base + // happened here + return x; +} + +void sink(NonVirtual *x) { + delete x; // warn: destruction of a polymorphic object with no virtual +// destructor +} + + + + +alpha.cplusplus.InvalidatedIterator +(C++) +Check for use of invalidated iterators. + + -class A { -public: - ~A() { -this->f(); // warn - } - virtual void f(); +void bad_copy_assign_operator_list1(std::list &L1, +const std::list &L2) { + auto i0 = L1.cbegin(); + L1 = L2; + *i0; // warn: invalidated iterator accessed +} + + + + +alpha.cplusplus.IteratorRange +(C++) +Check for iterators used outside their valid ranges. + + + +void simple_bad_end(const std::vector &v) { + auto i = v.end(); + *i; // warn: iterator accessed outside of its range +} + + + + +alpha.cplusplus.MismatchedIterator +(C++) +Check for use of iterators of different containers where iterators of the same +container are expected. + + + +void bad_insert3(std::vector &v1, std::vector &v2) { + v2.insert(v1.cbegin(), v2.cbegin(), v2.cend()); // warn: container accessed + // using foreign + // iterator argument + v1.insert(v1.cbegin(), v1.cbegin(), v2.cend()); // warn: iterators of + // different containers + // used where the same + // container is + // expected + v1.insert(v1.cbegin(), v2.cbegin(), v1.cend()); // warn: iterators of + // different containers + // used where the same + // container is + // expected +} + + + + +alpha.cplusplus.MisusedMovedObject +(C++) +Method calls on a moved-from object and copying a moved-from object will be +reported. + + + +struct A { + void foo() {} }; + +void f() { + A a; + A
[PATCH] D52650: [clangd] NFC: Migrate to LLVM STLExtras API where possible
kbobyrev updated this revision to Diff 168589. kbobyrev added a comment. Rebase on top of HEAD. https://reviews.llvm.org/D52650 Files: clang-tools-extra/clangd/ClangdLSPServer.cpp clang-tools-extra/clangd/ClangdServer.cpp clang-tools-extra/clangd/CodeComplete.cpp clang-tools-extra/clangd/TUScheduler.cpp clang-tools-extra/clangd/XRefs.cpp clang-tools-extra/clangd/index/CanonicalIncludes.cpp clang-tools-extra/clangd/index/FileIndex.cpp clang-tools-extra/clangd/index/Index.cpp clang-tools-extra/clangd/index/Serialization.cpp clang-tools-extra/clangd/index/SymbolCollector.cpp clang-tools-extra/clangd/index/dex/Dex.cpp clang-tools-extra/clangd/index/dex/Iterator.cpp llvm/include/llvm/ADT/STLExtras.h Index: llvm/include/llvm/ADT/STLExtras.h === --- llvm/include/llvm/ADT/STLExtras.h +++ llvm/include/llvm/ADT/STLExtras.h @@ -1139,6 +1139,12 @@ return std::lower_bound(adl_begin(Range), adl_end(Range), I); } +template +auto lower_bound(R &&Range, ForwardIt I, Compare C) +-> decltype(adl_begin(Range)) { + return std::lower_bound(adl_begin(Range), adl_end(Range), I, C); +} + /// Provide wrappers to std::upper_bound which take ranges instead of having to /// pass begin/end explicitly. template Index: clang-tools-extra/clangd/index/dex/Iterator.cpp === --- clang-tools-extra/clangd/index/dex/Iterator.cpp +++ clang-tools-extra/clangd/index/dex/Iterator.cpp @@ -40,11 +40,10 @@ // highest element starting from the front. When child iterators in the // beginning have smaller estimated size, the sync() will have less restarts // and become more effective. -std::sort(begin(Children), end(Children), - [](const std::unique_ptr &LHS, - const std::unique_ptr &RHS) { -return LHS->estimateSize() < RHS->estimateSize(); - }); +llvm::sort(Children, [](const std::unique_ptr &LHS, +const std::unique_ptr &RHS) { + return LHS->estimateSize() < RHS->estimateSize(); +}); } bool reachedEnd() const override { return ReachedEnd; } Index: clang-tools-extra/clangd/index/dex/Dex.cpp === --- clang-tools-extra/clangd/index/dex/Dex.cpp +++ clang-tools-extra/clangd/index/dex/Dex.cpp @@ -123,8 +123,7 @@ // Symbols are sorted by symbol qualities so that items in the posting lists // are stored in the descending order of symbol quality. - std::sort(begin(ScoredSymbols), end(ScoredSymbols), -std::greater>()); + llvm::sort(ScoredSymbols, std::greater>()); // SymbolQuality was empty up until now. SymbolQuality.resize(Symbols.size()); Index: clang-tools-extra/clangd/index/SymbolCollector.cpp === --- clang-tools-extra/clangd/index/SymbolCollector.cpp +++ clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -129,8 +129,7 @@ // will include OUTER_INNER and exclude some_enum_constant. // FIXME: the heuristic relies on naming style (i.e. no underscore in // user-defined names) and can be improved. - return (ND.getKind() != Decl::EnumConstant) || - std::any_of(Name.begin(), Name.end(), islower); + return (ND.getKind() != Decl::EnumConstant) || llvm::any_of(Name, islower); } // We only collect #include paths for symbols that are suitable for global code Index: clang-tools-extra/clangd/index/Serialization.cpp === --- clang-tools-extra/clangd/index/Serialization.cpp +++ clang-tools-extra/clangd/index/Serialization.cpp @@ -158,7 +158,7 @@ // Finalize the table and write it to OS. No more strings may be added. void finalize(raw_ostream &OS) { Sorted = {Unique.begin(), Unique.end()}; -std::sort(Sorted.begin(), Sorted.end()); +llvm::sort(Sorted); for (unsigned I = 0; I < Sorted.size(); ++I) Index.try_emplace({Sorted[I].data(), Sorted[I].size()}, I); Index: clang-tools-extra/clangd/index/Index.cpp === --- clang-tools-extra/clangd/index/Index.cpp +++ clang-tools-extra/clangd/index/Index.cpp @@ -84,10 +84,8 @@ } SymbolSlab::const_iterator SymbolSlab::find(const SymbolID &ID) const { - auto It = std::lower_bound(Symbols.begin(), Symbols.end(), ID, - [](const Symbol &S, const SymbolID &I) { - return S.ID < I; - }); + auto It = llvm::lower_bound( + Symbols, ID, [](const Symbol &S, const SymbolID &I) { return S.ID < I; }); if (It != Symbols.end() && It->ID == ID) return It; return Symbols.end(); @@ -112,8 +110,8 @@ SymbolSlab SymbolSlab::Builder::build() && { Symbols = {Symbols.begin(), Symbols.end()}; // Force shrink-to-fit. // Sort
[clang-tools-extra] r343937 - [clangd] NFC: Migrate to LLVM STLExtras API where possible
Author: omtcyfz Date: Sun Oct 7 07:49:41 2018 New Revision: 343937 URL: http://llvm.org/viewvc/llvm-project?rev=343937&view=rev Log: [clangd] NFC: Migrate to LLVM STLExtras API where possible This patch improves readability by migrating `std::function(ForwardIt start, ForwardIt end, ...)` to LLVM's STLExtras range-based equivalent `llvm::function(RangeT &&Range, ...)`. Similar change in Clang: D52576. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D52650 Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/TUScheduler.cpp clang-tools-extra/trunk/clangd/XRefs.cpp clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp clang-tools-extra/trunk/clangd/index/FileIndex.cpp clang-tools-extra/trunk/clangd/index/Index.cpp clang-tools-extra/trunk/clangd/index/Serialization.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/clangd/index/dex/Dex.cpp clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp Modified: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp?rev=343937&r1=343936&r2=343937&view=diff == --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp Sun Oct 7 07:49:41 2018 @@ -549,8 +549,7 @@ void ClangdLSPServer::onDiagnosticsReady DiagnosticsJSON.push_back(std::move(LSPDiag)); auto &FixItsForDiagnostic = LocalFixIts[Diag]; - std::copy(Fixes.begin(), Fixes.end(), -std::back_inserter(FixItsForDiagnostic)); + llvm::copy(Fixes, std::back_inserter(FixItsForDiagnostic)); }); } Modified: clang-tools-extra/trunk/clangd/ClangdServer.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdServer.cpp?rev=343937&r1=343936&r2=343937&view=diff == --- clang-tools-extra/trunk/clangd/ClangdServer.cpp (original) +++ clang-tools-extra/trunk/clangd/ClangdServer.cpp Sun Oct 7 07:49:41 2018 @@ -361,17 +361,15 @@ llvm::Optional ClangdServer::switc // Lookup in a list of known extensions. auto SourceIter = - std::find_if(std::begin(SourceExtensions), std::end(SourceExtensions), - [&PathExt](PathRef SourceExt) { - return SourceExt.equals_lower(PathExt); - }); + llvm::find_if(SourceExtensions, [&PathExt](PathRef SourceExt) { +return SourceExt.equals_lower(PathExt); + }); bool IsSource = SourceIter != std::end(SourceExtensions); auto HeaderIter = - std::find_if(std::begin(HeaderExtensions), std::end(HeaderExtensions), - [&PathExt](PathRef HeaderExt) { - return HeaderExt.equals_lower(PathExt); - }); + llvm::find_if(HeaderExtensions, [&PathExt](PathRef HeaderExt) { +return HeaderExt.equals_lower(PathExt); + }); bool IsHeader = HeaderIter != std::end(HeaderExtensions); Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=343937&r1=343936&r2=343937&view=diff == --- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original) +++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Sun Oct 7 07:49:41 2018 @@ -306,11 +306,10 @@ struct CodeCompletionBuilder { Completion.FixIts.push_back( toTextEdit(FixIt, ASTCtx.getSourceManager(), ASTCtx.getLangOpts())); } - std::sort(Completion.FixIts.begin(), Completion.FixIts.end(), -[](const TextEdit &X, const TextEdit &Y) { - return std::tie(X.range.start.line, X.range.start.character) < - std::tie(Y.range.start.line, Y.range.start.character); -}); + llvm::sort(Completion.FixIts, [](const TextEdit &X, const TextEdit &Y) { +return std::tie(X.range.start.line, X.range.start.character) < + std::tie(Y.range.start.line, Y.range.start.character); + }); Completion.Deprecated |= (C.SemaResult->Availability == CXAvailability_Deprecated); } @@ -861,8 +860,8 @@ public: IndexRequest.IDs.size(), FetchedDocs.size()); } -std::sort( -ScoredSignatures.begin(), ScoredSignatures.end(), +llvm::sort( +ScoredSignatures, [](const ScoredSignature &L, const ScoredSignature &R) { // Ordering follows: // - Less number of parameters is better. @@ -1164,13 +1163,12 @@ llvm::SmallVector getRankedIncludes(const Symbol &S
[PATCH] D52650: [clangd] NFC: Migrate to LLVM STLExtras API where possible
This revision was automatically updated to reflect the committed changes. Closed by commit rL343937: [clangd] NFC: Migrate to LLVM STLExtras API where possible (authored by omtcyfz, committed by ). Herald added subscribers: llvm-commits, kristina. Changed prior to commit: https://reviews.llvm.org/D52650?vs=168589&id=168590#toc Repository: rL LLVM https://reviews.llvm.org/D52650 Files: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp clang-tools-extra/trunk/clangd/ClangdServer.cpp clang-tools-extra/trunk/clangd/CodeComplete.cpp clang-tools-extra/trunk/clangd/TUScheduler.cpp clang-tools-extra/trunk/clangd/XRefs.cpp clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp clang-tools-extra/trunk/clangd/index/FileIndex.cpp clang-tools-extra/trunk/clangd/index/Index.cpp clang-tools-extra/trunk/clangd/index/Serialization.cpp clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp clang-tools-extra/trunk/clangd/index/dex/Dex.cpp clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp llvm/trunk/include/llvm/ADT/STLExtras.h Index: llvm/trunk/include/llvm/ADT/STLExtras.h === --- llvm/trunk/include/llvm/ADT/STLExtras.h +++ llvm/trunk/include/llvm/ADT/STLExtras.h @@ -1139,6 +1139,12 @@ return std::lower_bound(adl_begin(Range), adl_end(Range), I); } +template +auto lower_bound(R &&Range, ForwardIt I, Compare C) +-> decltype(adl_begin(Range)) { + return std::lower_bound(adl_begin(Range), adl_end(Range), I, C); +} + /// Provide wrappers to std::upper_bound which take ranges instead of having to /// pass begin/end explicitly. template Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp === --- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp +++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp @@ -549,8 +549,7 @@ DiagnosticsJSON.push_back(std::move(LSPDiag)); auto &FixItsForDiagnostic = LocalFixIts[Diag]; - std::copy(Fixes.begin(), Fixes.end(), -std::back_inserter(FixItsForDiagnostic)); + llvm::copy(Fixes, std::back_inserter(FixItsForDiagnostic)); }); } Index: clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp === --- clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp +++ clang-tools-extra/trunk/clangd/index/CanonicalIncludes.cpp @@ -46,12 +46,11 @@ return SE->second; // Find the first header such that the extension is not '.inc', and isn't a // recognized non-header file - auto I = - std::find_if(Headers.begin(), Headers.end(), [](llvm::StringRef Include) { -// Skip .inc file whose including header file should -// be #included instead. -return !Include.endswith(".inc"); - }); + auto I = llvm::find_if(Headers, [](llvm::StringRef Include) { +// Skip .inc file whose including header file should +// be #included instead. +return !Include.endswith(".inc"); + }); if (I == Headers.end()) return Headers[0]; // Fallback to the declaring header. StringRef Header = *I; Index: clang-tools-extra/trunk/clangd/index/Serialization.cpp === --- clang-tools-extra/trunk/clangd/index/Serialization.cpp +++ clang-tools-extra/trunk/clangd/index/Serialization.cpp @@ -158,7 +158,7 @@ // Finalize the table and write it to OS. No more strings may be added. void finalize(raw_ostream &OS) { Sorted = {Unique.begin(), Unique.end()}; -std::sort(Sorted.begin(), Sorted.end()); +llvm::sort(Sorted); for (unsigned I = 0; I < Sorted.size(); ++I) Index.try_emplace({Sorted[I].data(), Sorted[I].size()}, I); Index: clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp === --- clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp +++ clang-tools-extra/trunk/clangd/index/SymbolCollector.cpp @@ -129,8 +129,7 @@ // will include OUTER_INNER and exclude some_enum_constant. // FIXME: the heuristic relies on naming style (i.e. no underscore in // user-defined names) and can be improved. - return (ND.getKind() != Decl::EnumConstant) || - std::any_of(Name.begin(), Name.end(), islower); + return (ND.getKind() != Decl::EnumConstant) || llvm::any_of(Name, islower); } // We only collect #include paths for symbols that are suitable for global code Index: clang-tools-extra/trunk/clangd/index/Index.cpp === --- clang-tools-extra/trunk/clangd/index/Index.cpp +++ clang-tools-extra/trunk/clangd/index/Index.cpp @@ -84,10 +84,8 @@ } SymbolSlab::const_iterator SymbolSlab::find(const SymbolID &ID) const { - auto It = std::lower_bound(Symbols.begin(), Symbols.end(), ID, - [](const Symbol &S, const SymbolID &I) { -
[PATCH] D51949: [clang-tidy] new check 'readability-isolate-declaration'
kbobyrev added inline comments. Comment at: clang-tidy/readability/IsolateDeclarationCheck.cpp:24 +AST_MATCHER(DeclStmt, onlyDeclaresVariables) { + return std::all_of(Node.decl_begin(), Node.decl_end(), + [](Decl *D) { return isa(D); }); It would be shorter to use `llvm::all_of(Node.decls(), ...);` Comment at: clang-tidy/readability/IsolateDeclarationCheck.cpp:30 + InnerMatcher) { + const Stmt *InitStmt = Node.getInit(); + return InitStmt ? InnerMatcher.matches(*InitStmt, Finder, Builder) : false; Maybe inline this variable? Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51949 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51866: [analyzer][UninitializedObjectChecker][WIP] New flag to ignore guarded uninitialized fields
Szelethus updated this revision to Diff 168592. Szelethus added a comment. Reimplemented with AST matchers. @george.karpenkov I know you wanted to test this feature for a while, but sadly I've been busy with the macro expansion related projects, I hope it's still relevant. https://reviews.llvm.org/D51866 Files: lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObject.h lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp test/Analysis/cxx-uninitialized-object-unguarded-access.cpp Index: test/Analysis/cxx-uninitialized-object-unguarded-access.cpp === --- /dev/null +++ test/Analysis/cxx-uninitialized-object-unguarded-access.cpp @@ -0,0 +1,257 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.cplusplus.UninitializedObject \ +// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:Pedantic=true -DPEDANTIC \ +// RUN: -analyzer-config alpha.cplusplus.UninitializedObject:IgnoreGuardedFields=true \ +// RUN: -std=c++11 -verify %s + +//===--===// +// Helper functions for tests. +//===--===// +void halt() __attribute__((__noreturn__)); +void assert(int b) { + if (!b) +halt(); +} + +int rand(); + +//===--===// +// Tests for fields properly guarded by asserts. +//===--===// + +class NoUnguardedFieldsTest { +public: + enum Kind { +V, +A + }; + +private: + int Volume, Area; + Kind K; + +public: + NoUnguardedFieldsTest(Kind K) : K(K) { +switch (K) { +case V: + Volume = 0; + break; +case A: + Area = 0; + break; +} + } + + void operator-() { +assert(K == Kind::A); +(void)Area; + } + + void operator+() { +assert(K == Kind::V); +(void)Volume; + } +}; + +void fNoUnguardedFieldsTest() { + NoUnguardedFieldsTest T1(NoUnguardedFieldsTest::Kind::A); + NoUnguardedFieldsTest T2(NoUnguardedFieldsTest::Kind::V); +} + +class NoUnguardedFieldsWithUndefMethodTest { +public: + enum Kind { +V, +A + }; + +private: + int Volume, Area; + Kind K; + +public: + NoUnguardedFieldsWithUndefMethodTest(Kind K) : K(K) { +switch (K) { +case V: + Volume = 0; + break; +case A: + Area = 0; + break; +} + } + + void operator-() { +assert(K == Kind::A); +(void)Area; + } + + void operator+() { +assert(K == Kind::V); +(void)Volume; + } + + void methodWithoutDefinition(); +}; + +void fNoUnguardedFieldsWithUndefMethodTest() { + NoUnguardedFieldsWithUndefMethodTest + T1(NoUnguardedFieldsWithUndefMethodTest::Kind::A); + NoUnguardedFieldsWithUndefMethodTest + T2(NoUnguardedFieldsWithUndefMethodTest::Kind::V); +} + +class UnguardedFieldThroughMethodTest { +public: + enum Kind { +V, +A + }; + +private: + int Volume, Area; // expected-note {{uninitialized field 'this->Volume'}} + Kind K; + +public: + UnguardedFieldThroughMethodTest(Kind K) : K(K) { +switch (K) { +case V: + Volume = 0; + break; +case A: + Area = 0; // expected-warning {{1 uninitialized field}} + break; +} + } + + void operator-() { +assert(K == Kind::A); +(void)Area; + } + + void operator+() { +(void)Volume; + } +}; + +void fUnguardedFieldThroughMethodTest() { + UnguardedFieldThroughMethodTest T1(UnguardedFieldThroughMethodTest::Kind::A); +} + +class UnguardedPublicFieldsTest { +public: + enum Kind { +V, +A + }; + + int Volume, Area; // expected-note {{uninitialized field 'this->Volume'}} + Kind K; + +public: + UnguardedPublicFieldsTest(Kind K) : K(K) { +switch (K) { +case V: + Volume = 0; + break; +case A: + Area = 0; // expected-warning {{1 uninitialized field}} + break; +} + } + + void operator-() { +assert(K == Kind::A); +(void)Area; + } + + void operator+() { +assert(K == Kind::V); +(void)Volume; + } +}; + +void fUnguardedPublicFieldsTest() { + UnguardedPublicFieldsTest T1(UnguardedPublicFieldsTest::Kind::A); +} + +//===--===// +// Highlights of some false negatives due to syntactic checking. +//===--===// + +class UnguardedFalseNegativeTest1 { +public: + enum Kind { +V, +A + }; + +private: + int Volume, Area; + Kind K; + +public: + UnguardedFalseNegativeTest1(Kind K) : K(K) { +switch (K) { +case V: + Volume = 0; + break; +case A: + Area = 0; + break; +} + } + + void operator-() { +if (rand()) + assert(K == Kind::A); +(void)Area; + } + + void operator+() { +if (rand()) + assert(K == Kind::V); +(
[PATCH] D51531: [analyzer][UninitializedObjectChecker] Uninit regions are only reported once
Szelethus added a comment. Another possibility could be to gather `CXXConstructorDecl`, and emit one warning per ctor, but it would be waaay to drastic. Wouldn't a global set be too? https://reviews.llvm.org/D51531 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52969: [analyzer][www] Added the missing alpha.cplusplus checkers to the webpage
Szelethus updated this revision to Diff 168595. Szelethus edited the summary of this revision. https://reviews.llvm.org/D52969 Files: www/analyzer/alpha_checks.html www/analyzer/available_checks.html Index: www/analyzer/available_checks.html === --- www/analyzer/available_checks.html +++ www/analyzer/available_checks.html @@ -543,7 +543,34 @@ Name, DescriptionExample + + +optin.cplusplus.VirtualCall +(C++) +Check virtual member function calls during construction or +destruction. + + +class A { +public: + A() { +f(); // warn + } + virtual void f(); +}; + + +class A { +public: + ~A() { +this->f(); // warn + } + virtual void f(); +}; + + + optin.mpi.MPI-Checker (C) Index: www/analyzer/alpha_checks.html === --- www/analyzer/alpha_checks.html +++ www/analyzer/alpha_checks.html @@ -275,6 +275,33 @@ + +alpha.core.StackAddressAsyncEscape +(C) +Check that addresses to stack memory do not escape the function that involves +dispatch_after or dispatch_async. This checker is +a part of core.StackAddressEscape, but is +https://reviews.llvm.org/D41042>temporarily disabled until some +false positives are fixed. + + +dispatch_block_t test_block_inside_block_async_leak() { + int x = 123; + void (^inner)(void) = ^void(void) { +int y = x; +++y; + }; + void (^outer)(void) = ^void(void) { +int z = x; +++z; +inner(); + }; + return outer; // warn: address of stack-allocated block is captured by a +// returned block +} + + + alpha.core.TestAfterDivZero (C, C++, ObjC) @@ -289,79 +316,150 @@ } + C++ Alpha Checkers Name, DescriptionExample - + + -alpha.cplusplus.VirtualCall +alpha.cplusplus.DeleteWithNonVirtualDtor (C++) -Check virtual member function calls during construction or -destruction. +Reports destructions of polymorphic objects with a non-virtual destructor in +their base class + -class A { -public: - A() { -f(); // warn - } - virtual void f(); -}; - +NonVirtual *create() { + NonVirtual *x = new NVDerived(); // note: conversion from derived to base + // happened here + return x; +} + +void sink(NonVirtual *x) { + delete x; // warn: destruction of a polymorphic object with no virtual +// destructor +} + + + + +alpha.cplusplus.InvalidatedIterator +(C++) +Check for use of invalidated iterators. + + -class A { -public: - ~A() { -this->f(); // warn - } - virtual void f(); +void bad_copy_assign_operator_list1(std::list &L1, +const std::list &L2) { + auto i0 = L1.cbegin(); + L1 = L2; + *i0; // warn: invalidated iterator accessed +} + + + + +alpha.cplusplus.IteratorRange +(C++) +Check for iterators used outside their valid ranges. + + + +void simple_bad_end(const std::vector &v) { + auto i = v.end(); + *i; // warn: iterator accessed outside of its range +} + + + + +alpha.cplusplus.MismatchedIterator +(C++) +Check for use of iterators of different containers where iterators of the same +container are expected. + + + +void bad_insert3(std::vector &v1, std::vector &v2) { + v2.insert(v1.cbegin(), v2.cbegin(), v2.cend()); // warn: container accessed + // using foreign + // iterator argument + v1.insert(v1.cbegin(), v1.cbegin(), v2.cend()); // warn: iterators of + // different containers + // used where the same + // container is + // expected + v1.insert(v1.cbegin(), v2.cbegin(), v1.cend()); // warn: iterators of + // different containers + // used where the same + // container is + // expected +} + + + + +alpha.cplusplus.MisusedMovedObject +(C++) +Method calls on a moved-from object and copying a moved-from object will be +reported. + + + +struct A { + void foo() {} }; + +void f() { + A a; + A b = std::move(a); // note: 'a' became 'moved-from' here + a.foo();// warn: method call on a 'moved-from' object 'a' +} - + alpha.cplusplus.UninitializedObject (C++) -This checker reports uninitialized fields in objects created -after a constructor call. It doesn't only find direct uninitialized -fields, but rather makes a deep inspection of the object, -analyzing all of it's fields subfields. -The checker regards inherited fields as direct fields, so one -will recieve warnings for uninitialized inherited data members
[PATCH] D42242: Make libc++abi work with gcc's ARM unwind library
mgorny added a comment. @mclow.lists , ping. Any chance to get a proper version upstream? I'd rather not pull patches from Fedora when we can have something official. https://reviews.llvm.org/D42242 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r343946 - [clangd] Migrate to LLVM STLExtras range API
Author: maskray Date: Sun Oct 7 10:21:08 2018 New Revision: 343946 URL: http://llvm.org/viewvc/llvm-project?rev=343946&view=rev Log: [clangd] Migrate to LLVM STLExtras range API Modified: clang-tools-extra/trunk/clangd/FileDistance.cpp clang-tools-extra/trunk/clangd/XRefs.cpp Modified: clang-tools-extra/trunk/clangd/FileDistance.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/FileDistance.cpp?rev=343946&r1=343945&r2=343946&view=diff == --- clang-tools-extra/trunk/clangd/FileDistance.cpp (original) +++ clang-tools-extra/trunk/clangd/FileDistance.cpp Sun Oct 7 10:21:08 2018 @@ -72,8 +72,8 @@ FileDistance::FileDistance(StringMap S.getValue().MaxUpTraversals) { if (Cache.find(Hash) != Cache.end()) Modified: clang-tools-extra/trunk/clangd/XRefs.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=343946&r1=343945&r2=343946&view=diff == --- clang-tools-extra/trunk/clangd/XRefs.cpp (original) +++ clang-tools-extra/trunk/clangd/XRefs.cpp Sun Oct 7 10:21:08 2018 @@ -372,11 +372,10 @@ public: } std::vector take() && { -std::sort(References.begin(), References.end(), - [](const Reference &L, const Reference &R) { -return std::tie(L.Loc, L.CanonicalTarget, L.Role) < - std::tie(R.Loc, R.CanonicalTarget, R.Role); - }); +llvm::sort(References, [](const Reference &L, const Reference &R) { + return std::tie(L.Loc, L.CanonicalTarget, L.Role) < + std::tie(R.Loc, R.CanonicalTarget, R.Role); +}); // We sometimes see duplicates when parts of the AST get traversed twice. References.erase( std::unique(References.begin(), References.end(), ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51949: [clang-tidy] new check 'readability-isolate-declaration'
JonasToth marked 2 inline comments as done. JonasToth added a comment. @kbobyrev is it ok for you if I stick with the `Optional<>` style in the check? Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51949 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52969: [analyzer][www] Update alpha_checks.html
Szelethus updated this revision to Diff 168597. Szelethus retitled this revision from "[analyzer][www] Added the missing alpha.cplusplus checkers to the webpage" to "[analyzer][www] Update alpha_checks.html". Herald added a subscriber: jfb. https://reviews.llvm.org/D52969 Files: www/analyzer/alpha_checks.html www/analyzer/available_checks.html Index: www/analyzer/available_checks.html === --- www/analyzer/available_checks.html +++ www/analyzer/available_checks.html @@ -543,7 +543,34 @@ Name, DescriptionExample + + +optin.cplusplus.VirtualCall +(C++) +Check virtual member function calls during construction or +destruction. + + +class A { +public: + A() { +f(); // warn + } + virtual void f(); +}; + + +class A { +public: + ~A() { +this->f(); // warn + } + virtual void f(); +}; + + + optin.mpi.MPI-Checker (C) Index: www/analyzer/alpha_checks.html === --- www/analyzer/alpha_checks.html +++ www/analyzer/alpha_checks.html @@ -107,6 +107,7 @@ } + alpha.core.CastSize (C) @@ -275,6 +276,33 @@ + +alpha.core.StackAddressAsyncEscape +(C) +Check that addresses to stack memory do not escape the function that involves +dispatch_after or dispatch_async. This checker is +a part of core.StackAddressEscape, but is +https://reviews.llvm.org/D41042>temporarily disabled until some +false positives are fixed. + + +dispatch_block_t test_block_inside_block_async_leak() { + int x = 123; + void (^inner)(void) = ^void(void) { +int y = x; +++y; + }; + void (^outer)(void) = ^void(void) { +int z = x; +++z; +inner(); + }; + return outer; // warn: address of stack-allocated block is captured by a +// returned block +} + + + alpha.core.TestAfterDivZero (C, C++, ObjC) @@ -289,79 +317,150 @@ } + C++ Alpha Checkers Name, DescriptionExample - + + -alpha.cplusplus.VirtualCall +alpha.cplusplus.DeleteWithNonVirtualDtor (C++) -Check virtual member function calls during construction or -destruction. +Reports destructions of polymorphic objects with a non-virtual destructor in +their base class + -class A { -public: - A() { -f(); // warn - } - virtual void f(); -}; - +NonVirtual *create() { + NonVirtual *x = new NVDerived(); // note: conversion from derived to base + // happened here + return x; +} + +void sink(NonVirtual *x) { + delete x; // warn: destruction of a polymorphic object with no virtual +// destructor +} + + + + +alpha.cplusplus.InvalidatedIterator +(C++) +Check for use of invalidated iterators. + + -class A { -public: - ~A() { -this->f(); // warn - } - virtual void f(); +void bad_copy_assign_operator_list1(std::list &L1, +const std::list &L2) { + auto i0 = L1.cbegin(); + L1 = L2; + *i0; // warn: invalidated iterator accessed +} + + + + +alpha.cplusplus.IteratorRange +(C++) +Check for iterators used outside their valid ranges. + + + +void simple_bad_end(const std::vector &v) { + auto i = v.end(); + *i; // warn: iterator accessed outside of its range +} + + + + +alpha.cplusplus.MismatchedIterator +(C++) +Check for use of iterators of different containers where iterators of the same +container are expected. + + + +void bad_insert3(std::vector &v1, std::vector &v2) { + v2.insert(v1.cbegin(), v2.cbegin(), v2.cend()); // warn: container accessed + // using foreign + // iterator argument + v1.insert(v1.cbegin(), v1.cbegin(), v2.cend()); // warn: iterators of + // different containers + // used where the same + // container is + // expected + v1.insert(v1.cbegin(), v2.cbegin(), v1.cend()); // warn: iterators of + // different containers + // used where the same + // container is + // expected +} + + + + +alpha.cplusplus.MisusedMovedObject +(C++) +Method calls on a moved-from object and copying a moved-from object will be +reported. + + + +struct A { + void foo() {} }; + +void f() { + A a; + A b = std::move(a); // note: 'a' became 'moved-from' here + a.foo();// warn: method call on a 'moved-from' object 'a' +} - + alpha.cplusplus.UninitializedObject (C++) -This checker reports uninitialized fields in objects created -after a constructor call. It doesn't only find direct uninitialized -fields, but rather ma
[PATCH] D51949: [clang-tidy] new check 'readability-isolate-declaration'
JonasToth updated this revision to Diff 168598. JonasToth added a comment. - address review comments, simplifying code Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D51949 Files: clang-tidy/readability/CMakeLists.txt clang-tidy/readability/IsolateDeclarationCheck.cpp clang-tidy/readability/IsolateDeclarationCheck.h clang-tidy/readability/ReadabilityTidyModule.cpp clang-tidy/utils/LexerUtils.cpp clang-tidy/utils/LexerUtils.h docs/ReleaseNotes.rst docs/clang-tidy/checks/list.rst docs/clang-tidy/checks/readability-isolate-declaration.rst test/clang-tidy/readability-isolate-declaration-cxx17.cpp test/clang-tidy/readability-isolate-declaration-fixing.cpp test/clang-tidy/readability-isolate-declaration.c test/clang-tidy/readability-isolate-declaration.cpp Index: test/clang-tidy/readability-isolate-declaration.cpp === --- /dev/null +++ test/clang-tidy/readability-isolate-declaration.cpp @@ -0,0 +1,412 @@ +// RUN: %check_clang_tidy %s readability-isolate-declaration %t + +void f() { + int i; +} + +void f2() { + int i, j, *k, lala = 42; + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: int i; + // CHECK-FIXES: {{^ }}int j; + // CHECK-FIXES: {{^ }}int *k; + // CHECK-FIXES: {{^ }}int lala = 42; + + int normal, weird = /* comment */ 42; + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: int normal; + // CHECK-FIXES: {{^ }}int weird = /* comment */ 42; + + int /* here is a comment */ v1, + // another comment + v2 = 42 // Ok, more comments + ; + // CHECK-MESSAGES: [[@LINE-4]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: int /* here is a comment */ v1; + // CHECK-FIXES: {{^ }}int /* here is a comment */ // another comment + // CHECK-FIXES: {{^ }}v2 = 42 // Ok, more comments + // CHECK-FIXES: {{^ }}; + + auto int1 = 42, int2 = 0, int3 = 43; + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: auto int1 = 42; + // CHECK-FIXES: {{^ }}auto int2 = 0; + // CHECK-FIXES: {{^ }}auto int3 = 43; + + decltype(auto) ptr1 = &int1, ptr2 = &int1; + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: decltype(auto) ptr1 = &int1; + // CHECK-FIXES: {{^ }}decltype(auto) ptr2 = &int1; + + decltype(k) ptr3 = &int1, ptr4 = &int1; + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: decltype(k) ptr3 = &int1; + // CHECK-FIXES: {{^ }}decltype(k) ptr4 = &int1; +} + +void f3() { + int i, *pointer1; + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: int i; + // CHECK-FIXES: {{^ }}int *pointer1; + // + int *pointer2 = nullptr, *pointer3 = &i; + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: int *pointer2 = nullptr; + // CHECK-FIXES: {{^ }}int *pointer3 = &i; + + int *(i_ptr) = nullptr, *((i_ptr2)); + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: int *(i_ptr) = nullptr; + // CHECK-FIXES: {{^ }}int *((i_ptr2)); + + float(*f_ptr)[42], (((f_value))) = 42; + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: float (*f_ptr)[42]; + // CHECK-FIXES: {{^ }}float (((f_value))) = 42; + + float(((*f_ptr2)))[42], ((*f_ptr3)), f_value2 = 42.f; + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: float (((*f_ptr2)))[42]; + // CHECK-FIXES: {{^ }}float ((*f_ptr3)); + // CHECK-FIXES: {{^ }}float f_value2 = 42.f; + + float(((*f_ptr4)))[42], *f_ptr5, ((f_value3)); + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: float (((*f_ptr4)))[42]; + // CHECK-FIXES: {{^ }}float *f_ptr5; + // CHECK-FIXES: {{^ }}float ((f_value3)); + + void(((*f2))(int)), (*g2)(int, float); + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: void (((*f2))(int)); + // CHECK-FIXES: {{^ }}void (*g2)(int, float); + + float(*(*(*f_ptr6)))[42], (*f_ptr7); + // CHECK-MESSAGES: [[@LINE-1]]:3: warning: multiple declarations in a single statement reduces readability + // CHECK-FIXES: float (*(*(*f_ptr6)))[42]; + // CHECK-FIXES: {{^ }}float (*f_ptr7); +} + +void f4() { + double d = 42. /* foo */, z = 43., /* hi */ y, c /* */ /* */, l = 2.; + // CHECK-MES
[PATCH] D52971: [clang-tidy] Customize FileCheck prefix in check_clang-tidy.py to support multiple prefixes
zinovy.nis created this revision. zinovy.nis added reviewers: lebedev.ri, alexfh. zinovy.nis added a project: clang-tools-extra. Herald added subscribers: cfe-commits, xazax.hun. The patch extends the existing command line option `-check_suffix` to accept multiple comma-separated prefixes. // RUN: %check_clang_tidy -check-suffix=USING-C,USING-D %s misc-unused-using-decls %t -- -- ... Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52971 Files: test/clang-tidy/check_clang_tidy.cpp test/clang-tidy/check_clang_tidy.py Index: test/clang-tidy/check_clang_tidy.py === --- test/clang-tidy/check_clang_tidy.py +++ test/clang-tidy/check_clang_tidy.py @@ -18,7 +18,7 @@ Usage: check_clang_tidy.py [-resource-dir=] \ [-assume-filename=] \ -[-check-suffix=] \ +[-check-suffix=] \ \ -- [optional clang-tidy arguments] @@ -38,15 +38,18 @@ f.write(text) f.truncate() +def csv(string): + return string.split(',') + def main(): parser = argparse.ArgumentParser() parser.add_argument('-expect-clang-tidy-error', action='store_true') parser.add_argument('-resource-dir') parser.add_argument('-assume-filename') - parser.add_argument('-check-suffix', default='') parser.add_argument('input_file_name') parser.add_argument('check_name') parser.add_argument('temp_file_name') + parser.add_argument('-check-suffix', default=[], type=csv, help="comma-separated list of FileCheck suffixes") args, extra_args = parser.parse_known_args() @@ -72,14 +75,6 @@ clang_tidy_extra_args.extend( ['-fobjc-abi-version=2', '-fobjc-arc']) - if args.check_suffix and not re.match('^[A-Z0-9\-]+$', args.check_suffix): -sys.exit('Only A..Z, 0..9 and "-" are allowed in check suffix, but "%s" was given' % (args.check_suffix)) - - file_check_suffix = ('-' + args.check_suffix) if args.check_suffix else '' - check_fixes_prefix = 'CHECK-FIXES' + file_check_suffix - check_messages_prefix = 'CHECK-MESSAGES' + file_check_suffix - check_notes_prefix = 'CHECK-NOTES' + file_check_suffix - # Tests should not rely on STL being available, and instead provide mock # implementations of relevant APIs. clang_tidy_extra_args.append('-nostdinc++') @@ -90,15 +85,33 @@ with open(input_file_name, 'r') as input_file: input_text = input_file.read() - has_check_fixes = check_fixes_prefix in input_text - has_check_messages = check_messages_prefix in input_text - has_check_notes = check_notes_prefix in input_text + check_fixes_prefixes = [] + check_messages_prefixes = [] + check_notes_prefixes = [] + + if any(args.check_suffix): +for check in args.check_suffix: + if not re.match('^[A-Z0-9\-,]+$', check): +sys.exit('Only A..Z, 0..9, "," and "-" are ' + + 'allowed in check suffixes list, but "%s" was given' % (check)) + file_check_suffix = '-' + check + check_fixes_prefixes.append('CHECK-FIXES' + file_check_suffix) + check_messages_prefixes.append('CHECK-MESSAGES' + file_check_suffix) + check_notes_prefixes.append('CHECK-NOTES' + file_check_suffix) + else: +check_fixes_prefixes = ['CHECK-FIXES'] +check_messages_prefixes = ['CHECK-MESSAGES'] +check_notes_prefixes = ['CHECK-NOTES'] + + has_check_fixes = any(prefix in input_text for prefix in check_fixes_prefixes) + has_check_messages = any(prefix in input_text for prefix in check_messages_prefixes) + has_check_notes = any(prefix in input_text for prefix in check_notes_prefixes) if not has_check_fixes and not has_check_messages and not has_check_notes: -sys.exit('%s, %s or %s not found in the input' % (check_fixes_prefix, - check_messages_prefix, check_notes_prefix) ) +sys.exit('%s, %s or %s not found in the input' % + (check_fixes_prefixes, check_messages_prefixes, check_notes_prefixes)) - if has_check_notes and has_check_messages: + if any(set(check_notes_prefixes) & set(check_messages_prefixes)): sys.exit('Please use either CHECK-NOTES or CHECK-MESSAGES but not both') # Remove the contents of the CHECK lines to avoid CHECKs matching on @@ -143,7 +156,8 @@ try: subprocess.check_output( ['FileCheck', '-input-file=' + temp_file_name, input_file_name, - '-check-prefix=' + check_fixes_prefix, '-strict-whitespace'], + '-check-prefixes=' + ','.join(check_fixes_prefixes), + '-strict-whitespace'], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: print('FileCheck failed:\n' + e.output.decode()) @@ -155,7 +169,7 @@ try: subprocess.check_output( ['FileCheck', '-input-file=' + messages_file, input_file_name, - '-check-prefix=' + check_messages_prefix, + '-check-prefixes=' + ','.join(check_messages_prefixes), '-implicit-check-not={{warning|error}}:'], stderr=subprocess.STDOUT)
[PATCH] D45776: [clang-tidy] Customize FileCheck prefix in check_clang-tidy.py
zinovy.nis added a comment. In https://reviews.llvm.org/D45776#1253944, @lebedev.ri wrote: > >> Did this intentionally omit the possibility to pass a group of prefixes, > >> like `FileCheck` supports? > >> Usefulness of this feature is somewhat penalized by this. Done. Please review this https://reviews.llvm.org/D52971 Repository: rL LLVM https://reviews.llvm.org/D45776 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52971: [clang-tidy] Customize FileCheck prefix in check_clang-tidy.py to support multiple prefixes
lebedev.ri added a comment. Thank you! Comment at: test/clang-tidy/check_clang_tidy.py:94-95 +for check in args.check_suffix: + if not re.match('^[A-Z0-9\-,]+$', check): +sys.exit('Only A..Z, 0..9, "," and "-" are ' + + 'allowed in check suffixes list, but "%s" was given' % (check)) How `,` can be allowed if that is the suffix separator? Also, i think `_` can be supported. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52835: [Diagnostics] Check integer to floating point number implicit conversions
xbolva00 added a comment. Ping :) https://reviews.llvm.org/D52835 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52973: Add type_info predefined decl
mwasplund created this revision. Herald added a subscriber: cfe-commits. Bug 39052 - [Modules TS] MSVC std library produces ambiguous type_info reference when including module with ms-compatibility When compiling a modules-ts project with MSVC compatibility turned on the type_info class was getting defined multiple times. With this change I am adding the type_info class as a predefined decl to allow the reader/writer to resolve the duplicated declarations. On top of this I am adding an extra check to ignore redeclaration checks on implicit types. This could be up for discussion since the spec does not specify if the implicit types should be in the global unit or if they can be overridden by the same type inside a module purview. Repository: rC Clang https://reviews.llvm.org/D52973 Files: lib/Sema/SemaDecl.cpp Index: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -5235,7 +5235,7 @@ DeclarationName Name, SourceLocation Loc, bool IsTemplateId) { DeclContext *Cur = CurContext; - while (Cur->isTransparentContext() || isa(Cur)) + while (isa(Cur) || isa(Cur)) Cur = Cur->getParent(); // If the user provided a superfluous scope specifier that refers back to the Index: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -5235,7 +5235,7 @@ DeclarationName Name, SourceLocation Loc, bool IsTemplateId) { DeclContext *Cur = CurContext; - while (Cur->isTransparentContext() || isa(Cur)) + while (isa(Cur) || isa(Cur)) Cur = Cur->getParent(); // If the user provided a superfluous scope specifier that refers back to the ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52891: [AMDGPU] Add -fvisibility-amdgpu-non-kernel-functions
arsenm added a comment. Use of the word kernel might confuse general people. Maybe it needs to specify OpenCL, but it also applies to HIP/CUDA https://reviews.llvm.org/D52891 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r343949 - [coro]Pass rvalue reference for named local variable to return_value
Author: modocache Date: Sun Oct 7 20:08:39 2018 New Revision: 343949 URL: http://llvm.org/viewvc/llvm-project?rev=343949&view=rev Log: [coro]Pass rvalue reference for named local variable to return_value Summary: Addressing https://bugs.llvm.org/show_bug.cgi?id=37265. Implements [class.copy]/33 of coroutines TS. When the criteria for elision of a copy/move operation are met, but not for an exception-declaration, and the object to be copied is designated by an lvalue, or when the expression in a return or co_return statement is a (possibly parenthesized) id-expression that names an object with automatic storage duration declared in the body or parameter-declaration-clause of the innermost enclosing function or lambda-expression, overload resolution to select the constructor for the copy or the return_value overload to call is first performed as if the object were designated by an rvalue. Patch by Tanoy Sinha! Reviewers: modocache, GorNishanov Reviewed By: modocache, GorNishanov Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D51741 Added: cfe/trunk/test/SemaCXX/coroutine-rvo.cpp Modified: cfe/trunk/lib/Sema/SemaCoroutine.cpp Modified: cfe/trunk/lib/Sema/SemaCoroutine.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCoroutine.cpp?rev=343949&r1=343948&r2=343949&view=diff == --- cfe/trunk/lib/Sema/SemaCoroutine.cpp (original) +++ cfe/trunk/lib/Sema/SemaCoroutine.cpp Sun Oct 7 20:08:39 2018 @@ -841,6 +841,19 @@ StmtResult Sema::BuildCoreturnStmt(Sourc E = R.get(); } + // Move the return value if we can + if (E) { +auto NRVOCandidate = this->getCopyElisionCandidate(E->getType(), E, CES_AsIfByStdMove); +if (NRVOCandidate) { + InitializedEntity Entity = + InitializedEntity::InitializeResult(Loc, E->getType(), NRVOCandidate); + ExprResult MoveResult = this->PerformMoveOrCopyInitialization( + Entity, NRVOCandidate, E->getType(), E); + if (MoveResult.get()) +E = MoveResult.get(); +} + } + // FIXME: If the operand is a reference to a variable that's about to go out // of scope, we should treat the operand as an xvalue for this overload // resolution. Added: cfe/trunk/test/SemaCXX/coroutine-rvo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/coroutine-rvo.cpp?rev=343949&view=auto == --- cfe/trunk/test/SemaCXX/coroutine-rvo.cpp (added) +++ cfe/trunk/test/SemaCXX/coroutine-rvo.cpp Sun Oct 7 20:08:39 2018 @@ -0,0 +1,69 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z -fcoroutines-ts -fsyntax-only + +namespace std::experimental { +template struct coroutine_handle { + coroutine_handle() = default; + static coroutine_handle from_address(void *) noexcept; +}; + +template <> struct coroutine_handle { + static coroutine_handle from_address(void *) noexcept; + coroutine_handle() = default; + template + coroutine_handle(coroutine_handle) noexcept; +}; + +template +struct void_t_imp { + using type = void; +}; +template +using void_t = typename void_t_imp::type; + +template +struct traits_sfinae_base {}; + +template +struct traits_sfinae_base> { + using promise_type = typename T::promise_type; +}; + +template +struct coroutine_traits : public traits_sfinae_base {}; +} + +struct suspend_never { + bool await_ready() noexcept; + void await_suspend(std::experimental::coroutine_handle<>) noexcept; + void await_resume() noexcept; +}; + +struct MoveOnly { + MoveOnly() {}; + MoveOnly(const MoveOnly&) = delete; + MoveOnly(MoveOnly&&) noexcept {}; + ~MoveOnly() {}; +}; + +template +struct task { + struct promise_type { +auto initial_suspend() { return suspend_never{}; } +auto final_suspend() { return suspend_never{}; } +auto get_return_object() { return task{}; } +static void unhandled_exception() {} +void return_value(T&& value) {} + }; +}; + +task f() { + MoveOnly value; + co_return value; +} + +int main() { + f(); + return 0; +} + +// expected-no-diagnostics ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D51741: [coro]Pass rvalue reference for named local variable to return_value
This revision was automatically updated to reflect the committed changes. Closed by commit rL343949: [coro]Pass rvalue reference for named local variable to return_value (authored by modocache, committed by ). Herald added a subscriber: llvm-commits. Repository: rL LLVM https://reviews.llvm.org/D51741 Files: cfe/trunk/lib/Sema/SemaCoroutine.cpp cfe/trunk/test/SemaCXX/coroutine-rvo.cpp Index: cfe/trunk/lib/Sema/SemaCoroutine.cpp === --- cfe/trunk/lib/Sema/SemaCoroutine.cpp +++ cfe/trunk/lib/Sema/SemaCoroutine.cpp @@ -841,6 +841,19 @@ E = R.get(); } + // Move the return value if we can + if (E) { +auto NRVOCandidate = this->getCopyElisionCandidate(E->getType(), E, CES_AsIfByStdMove); +if (NRVOCandidate) { + InitializedEntity Entity = + InitializedEntity::InitializeResult(Loc, E->getType(), NRVOCandidate); + ExprResult MoveResult = this->PerformMoveOrCopyInitialization( + Entity, NRVOCandidate, E->getType(), E); + if (MoveResult.get()) +E = MoveResult.get(); +} + } + // FIXME: If the operand is a reference to a variable that's about to go out // of scope, we should treat the operand as an xvalue for this overload // resolution. Index: cfe/trunk/test/SemaCXX/coroutine-rvo.cpp === --- cfe/trunk/test/SemaCXX/coroutine-rvo.cpp +++ cfe/trunk/test/SemaCXX/coroutine-rvo.cpp @@ -0,0 +1,69 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z -fcoroutines-ts -fsyntax-only + +namespace std::experimental { +template struct coroutine_handle { + coroutine_handle() = default; + static coroutine_handle from_address(void *) noexcept; +}; + +template <> struct coroutine_handle { + static coroutine_handle from_address(void *) noexcept; + coroutine_handle() = default; + template + coroutine_handle(coroutine_handle) noexcept; +}; + +template +struct void_t_imp { + using type = void; +}; +template +using void_t = typename void_t_imp::type; + +template +struct traits_sfinae_base {}; + +template +struct traits_sfinae_base> { + using promise_type = typename T::promise_type; +}; + +template +struct coroutine_traits : public traits_sfinae_base {}; +} + +struct suspend_never { + bool await_ready() noexcept; + void await_suspend(std::experimental::coroutine_handle<>) noexcept; + void await_resume() noexcept; +}; + +struct MoveOnly { + MoveOnly() {}; + MoveOnly(const MoveOnly&) = delete; + MoveOnly(MoveOnly&&) noexcept {}; + ~MoveOnly() {}; +}; + +template +struct task { + struct promise_type { +auto initial_suspend() { return suspend_never{}; } +auto final_suspend() { return suspend_never{}; } +auto get_return_object() { return task{}; } +static void unhandled_exception() {} +void return_value(T&& value) {} + }; +}; + +task f() { + MoveOnly value; + co_return value; +} + +int main() { + f(); + return 0; +} + +// expected-no-diagnostics Index: cfe/trunk/lib/Sema/SemaCoroutine.cpp === --- cfe/trunk/lib/Sema/SemaCoroutine.cpp +++ cfe/trunk/lib/Sema/SemaCoroutine.cpp @@ -841,6 +841,19 @@ E = R.get(); } + // Move the return value if we can + if (E) { +auto NRVOCandidate = this->getCopyElisionCandidate(E->getType(), E, CES_AsIfByStdMove); +if (NRVOCandidate) { + InitializedEntity Entity = + InitializedEntity::InitializeResult(Loc, E->getType(), NRVOCandidate); + ExprResult MoveResult = this->PerformMoveOrCopyInitialization( + Entity, NRVOCandidate, E->getType(), E); + if (MoveResult.get()) +E = MoveResult.get(); +} + } + // FIXME: If the operand is a reference to a variable that's about to go out // of scope, we should treat the operand as an xvalue for this overload // resolution. Index: cfe/trunk/test/SemaCXX/coroutine-rvo.cpp === --- cfe/trunk/test/SemaCXX/coroutine-rvo.cpp +++ cfe/trunk/test/SemaCXX/coroutine-rvo.cpp @@ -0,0 +1,69 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin9 %s -stdlib=libc++ -std=c++1z -fcoroutines-ts -fsyntax-only + +namespace std::experimental { +template struct coroutine_handle { + coroutine_handle() = default; + static coroutine_handle from_address(void *) noexcept; +}; + +template <> struct coroutine_handle { + static coroutine_handle from_address(void *) noexcept; + coroutine_handle() = default; + template + coroutine_handle(coroutine_handle) noexcept; +}; + +template +struct void_t_imp { + using type = void; +}; +template +using void_t = typename void_t_imp::type; + +template +struct traits_sfinae_base {}; + +template +struct traits_sfinae_base> { + using promise_type = typename T::promise_type; +}; + +template +struct coroutine_traits : public traits_sfinae_base {}; +} + +struct suspend_never { + bool
[PATCH] D52891: [AMDGPU] Add -fvisibility-amdgpu-non-kernel-functions
t-tye added a comment. Another word commonly used across languages is "offload". https://reviews.llvm.org/D52891 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52973: Add type_info predefined decl
mwasplund updated this revision to Diff 168606. Repository: rC Clang https://reviews.llvm.org/D52973 Files: lib/Sema/SemaDecl.cpp Index: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -5235,7 +5235,7 @@ DeclarationName Name, SourceLocation Loc, bool IsTemplateId) { DeclContext *Cur = CurContext; - while (Cur->isTransparentContext() || isa(Cur)) + while (isa(Cur) || isa(Cur)) Cur = Cur->getParent(); // If the user provided a superfluous scope specifier that refers back to the Index: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -5235,7 +5235,7 @@ DeclarationName Name, SourceLocation Loc, bool IsTemplateId) { DeclContext *Cur = CurContext; - while (Cur->isTransparentContext() || isa(Cur)) + while (isa(Cur) || isa(Cur)) Cur = Cur->getParent(); // If the user provided a superfluous scope specifier that refers back to the ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52973: Add type_info predefined decl
mwasplund updated this revision to Diff 168607. Repository: rC Clang https://reviews.llvm.org/D52973 Files: include/clang/AST/ASTContext.h include/clang/Serialization/ASTBitCodes.h lib/AST/ASTContext.cpp lib/Sema/Sema.cpp lib/Sema/SemaDecl.cpp lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp Index: lib/Serialization/ASTWriter.cpp === --- lib/Serialization/ASTWriter.cpp +++ lib/Serialization/ASTWriter.cpp @@ -4682,7 +4682,9 @@ RegisterPredefDecl(Context.CFConstantStringTagDecl, PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID); RegisterPredefDecl(Context.TypePackElementDecl, - PREDEF_DECL_TYPE_PACK_ELEMENT_ID); + PREDEF_DECL_TYPE_PACK_ELEMENT_ID); + RegisterPredefDecl(Context.TypeInfoClassDecl, + PREDEF_DECL_TYPE_INFO_CLASS_ID); // Build a record containing all of the tentative definitions in this file, in // TentativeDefinitions order. Generally, this record will be empty for Index: lib/Serialization/ASTReader.cpp === --- lib/Serialization/ASTReader.cpp +++ lib/Serialization/ASTReader.cpp @@ -7306,6 +7306,9 @@ case PREDEF_DECL_TYPE_PACK_ELEMENT_ID: return Context.getTypePackElementDecl(); + + case PREDEF_DECL_TYPE_INFO_CLASS_ID: +return Context.getTypeInfoClassDecl(); } llvm_unreachable("PredefinedDeclIDs unknown enum value"); } Index: lib/Sema/SemaDecl.cpp === --- lib/Sema/SemaDecl.cpp +++ lib/Sema/SemaDecl.cpp @@ -1464,6 +1464,11 @@ if (NewM == OldM) return false; + // FIXME: The Modules TS does not specify how to handle inplicit types + // For now we will simply ignore the implicit global types + if (Old->isImplicit()) +return false; + // FIXME: Check proclaimed-ownership-declarations here too. bool NewIsModuleInterface = NewM && NewM->Kind == Module::ModuleInterfaceUnit; bool OldIsModuleInterface = OldM && OldM->Kind == Module::ModuleInterfaceUnit; Index: lib/Sema/Sema.cpp === --- lib/Sema/Sema.cpp +++ lib/Sema/Sema.cpp @@ -247,8 +247,7 @@ if (getLangOpts().MSVCCompat) { if (getLangOpts().CPlusPlus && IdResolver.begin(&Context.Idents.get("type_info")) == IdResolver.end()) - PushOnScopeChains(Context.buildImplicitRecord("type_info", TTK_Class), -TUScope); + PushOnScopeChains(Context.getTypeInfoClassDecl(), TUScope); addImplicitTypedef("size_t", Context.getSizeType()); } Index: lib/AST/ASTContext.cpp === --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -1080,6 +1080,12 @@ return UInt128Decl; } +RecordDecl *ASTContext::getTypeInfoClassDecl() const { + if (!TypeInfoClassDecl) +TypeInfoClassDecl = buildImplicitRecord("type_info", TTK_Class); + return TypeInfoClassDecl; +} + void ASTContext::InitBuiltinType(CanQualType &R, BuiltinType::Kind K) { auto *Ty = new (*this, TypeAlignment) BuiltinType(K); R = CanQualType::CreateUnsafe(QualType(Ty, 0)); Index: include/clang/Serialization/ASTBitCodes.h === --- include/clang/Serialization/ASTBitCodes.h +++ include/clang/Serialization/ASTBitCodes.h @@ -1264,13 +1264,16 @@ /// The internal '__type_pack_element' template. PREDEF_DECL_TYPE_PACK_ELEMENT_ID = 16, + + /// The internal 'type_info' class. + PREDEF_DECL_TYPE_INFO_CLASS_ID = 17, }; /// The number of declaration IDs that are predefined. /// /// For more information about predefined declarations, see the /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants. -const unsigned int NUM_PREDEF_DECL_IDS = 17; +const unsigned int NUM_PREDEF_DECL_IDS = 18; /// Record of updates for a declaration that was modified after /// being deserialized. This can occur within DECLTYPES_BLOCK_ID. Index: include/clang/AST/ASTContext.h === --- include/clang/AST/ASTContext.h +++ include/clang/AST/ASTContext.h @@ -326,6 +326,9 @@ /// The typedef for the predefined 'BOOL' type. mutable TypedefDecl *BOOLDecl = nullptr; + /// The class for the predifined 'type_info' type. + mutable RecordDecl *TypeInfoClassDecl = nullptr; + // Typedefs which may be provided defining the structure of Objective-C // pseudo-builtins QualType ObjCIdRedefinitionType; @@ -1123,6 +1126,9 @@ /// Retrieve the declaration for the 128-bit unsigned integer type. TypedefDecl *getUInt128Decl() const; + /// Retrieve the declaration for the type_info class type. + RecordDecl *getTypeInfoClassDecl() const; + //===
[PATCH] D46441: [clang][CodeGenCXX] Noalias attr for 'this' parameter
rjmccall added inline comments. Comment at: lib/CodeGen/CGCall.cpp:1893 + +IsCtor = isa(TargetDecl); } AntonBikineev wrote: > rjmccall wrote: > > I feel like you should just use `TargetDecl && > > isa(TargetDecl)` below; it's more obvious. > > > > Is there not an analogous rule for destructors? > There appears to be no similar rule for destructors, maybe because at the > point of calling a destructor the value of the object/subobjects is > well-determined. That's a good point, although there's certainly a point during the destructor's execution that that's no longer true. Comment at: lib/CodeGen/CGCall.cpp:2049 +// from the constructor’s this pointer, the value of the object or +// subobject thus obtained is unspecified. +unsigned ThisIRArg, NumIRArgs; You probably ought to add here that we're treating this as undefined behavior and have recommended the standard be changed. https://reviews.llvm.org/D46441 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D52971: [clang-tidy] Customize FileCheck prefix in check_clang-tidy.py to support multiple prefixes
zinovy.nis updated this revision to Diff 168609. zinovy.nis added a comment. Removed "," from the list of allowed suffix characters. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52971 Files: test/clang-tidy/check_clang_tidy.cpp test/clang-tidy/check_clang_tidy.py Index: test/clang-tidy/check_clang_tidy.py === --- test/clang-tidy/check_clang_tidy.py +++ test/clang-tidy/check_clang_tidy.py @@ -18,7 +18,7 @@ Usage: check_clang_tidy.py [-resource-dir=] \ [-assume-filename=] \ -[-check-suffix=] \ +[-check-suffix=] \ \ -- [optional clang-tidy arguments] @@ -38,15 +38,18 @@ f.write(text) f.truncate() +def csv(string): + return string.split(',') + def main(): parser = argparse.ArgumentParser() parser.add_argument('-expect-clang-tidy-error', action='store_true') parser.add_argument('-resource-dir') parser.add_argument('-assume-filename') - parser.add_argument('-check-suffix', default='') parser.add_argument('input_file_name') parser.add_argument('check_name') parser.add_argument('temp_file_name') + parser.add_argument('-check-suffix', default=[], type=csv, help="comma-separated list of FileCheck suffixes") args, extra_args = parser.parse_known_args() @@ -72,14 +75,6 @@ clang_tidy_extra_args.extend( ['-fobjc-abi-version=2', '-fobjc-arc']) - if args.check_suffix and not re.match('^[A-Z0-9\-]+$', args.check_suffix): -sys.exit('Only A..Z, 0..9 and "-" are allowed in check suffix, but "%s" was given' % (args.check_suffix)) - - file_check_suffix = ('-' + args.check_suffix) if args.check_suffix else '' - check_fixes_prefix = 'CHECK-FIXES' + file_check_suffix - check_messages_prefix = 'CHECK-MESSAGES' + file_check_suffix - check_notes_prefix = 'CHECK-NOTES' + file_check_suffix - # Tests should not rely on STL being available, and instead provide mock # implementations of relevant APIs. clang_tidy_extra_args.append('-nostdinc++') @@ -90,15 +85,33 @@ with open(input_file_name, 'r') as input_file: input_text = input_file.read() - has_check_fixes = check_fixes_prefix in input_text - has_check_messages = check_messages_prefix in input_text - has_check_notes = check_notes_prefix in input_text + check_fixes_prefixes = [] + check_messages_prefixes = [] + check_notes_prefixes = [] + + if any(args.check_suffix): +for check in args.check_suffix: + if not re.match('^[A-Z0-9\-]+$', check): +sys.exit('Only A..Z, 0..9 and "-" are ' + + 'allowed in check suffixes list, but "%s" was given' % (check)) + file_check_suffix = '-' + check + check_fixes_prefixes.append('CHECK-FIXES' + file_check_suffix) + check_messages_prefixes.append('CHECK-MESSAGES' + file_check_suffix) + check_notes_prefixes.append('CHECK-NOTES' + file_check_suffix) + else: +check_fixes_prefixes = ['CHECK-FIXES'] +check_messages_prefixes = ['CHECK-MESSAGES'] +check_notes_prefixes = ['CHECK-NOTES'] + + has_check_fixes = any(prefix in input_text for prefix in check_fixes_prefixes) + has_check_messages = any(prefix in input_text for prefix in check_messages_prefixes) + has_check_notes = any(prefix in input_text for prefix in check_notes_prefixes) if not has_check_fixes and not has_check_messages and not has_check_notes: -sys.exit('%s, %s or %s not found in the input' % (check_fixes_prefix, - check_messages_prefix, check_notes_prefix) ) +sys.exit('%s, %s or %s not found in the input' % + (check_fixes_prefixes, check_messages_prefixes, check_notes_prefixes)) - if has_check_notes and has_check_messages: + if any(set(check_notes_prefixes) & set(check_messages_prefixes)): sys.exit('Please use either CHECK-NOTES or CHECK-MESSAGES but not both') # Remove the contents of the CHECK lines to avoid CHECKs matching on @@ -143,7 +156,8 @@ try: subprocess.check_output( ['FileCheck', '-input-file=' + temp_file_name, input_file_name, - '-check-prefix=' + check_fixes_prefix, '-strict-whitespace'], + '-check-prefixes=' + ','.join(check_fixes_prefixes), + '-strict-whitespace'], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: print('FileCheck failed:\n' + e.output.decode()) @@ -155,7 +169,7 @@ try: subprocess.check_output( ['FileCheck', '-input-file=' + messages_file, input_file_name, - '-check-prefix=' + check_messages_prefix, + '-check-prefixes=' + ','.join(check_messages_prefixes), '-implicit-check-not={{warning|error}}:'], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: @@ -170,7 +184,7 @@ try: subprocess.check_output( ['FileCheck', '-input-file=' + notes_file, input_file_name, - '-check-prefix=' + check_notes_prefix, + '-check-prefixes=' +
[PATCH] D52971: [clang-tidy] Customize FileCheck prefix in check_clang-tidy.py to support multiple prefixes
zinovy.nis marked an inline comment as done. zinovy.nis added inline comments. Comment at: test/clang-tidy/check_clang_tidy.py:94-95 +for check in args.check_suffix: + if not re.match('^[A-Z0-9\-,]+$', check): +sys.exit('Only A..Z, 0..9, "," and "-" are ' + + 'allowed in check suffixes list, but "%s" was given' % (check)) lebedev.ri wrote: > How `,` can be allowed if that is the suffix separator? > Also, i think `_` can be supported. When discussing the previous patch Alex said on underscores: > I don't know whether it makes sense to endorse (or even allow) the use of > underscore in the check suffix. The mix of underscores and dashes looks ugly > and is prone to errors. So it was intentionally. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D52971 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [clang-tools-extra] r343848 - [clang-tidy] Replace deprecated std::ios_base aliases
Hi Jonas, I get the follwing warning/error when compiling this commit with clang 3.6: ../tools/clang/tools/extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp:21:5: error: suggest braces around initialization of subobject [-Werror,-Wmissing-braces] "::std::ios_base::io_state", "::std::ios_base::open_mode", ^~~ 1 error generated. It looks like r343916 tried to fix it (but failed? and was reverted) so I suppose I'm not alone seeing it. Regards, Mikael On 10/05/2018 03:36 PM, Jonas Toth via cfe-commits wrote: > Author: jonastoth > Date: Fri Oct 5 06:36:00 2018 > New Revision: 343848 > > URL: http://llvm.org/viewvc/llvm-project?rev=343848&view=rev > Log: > [clang-tidy] Replace deprecated std::ios_base aliases > > This check warns the uses of the deprecated member types of std::ios_base > and replaces those that have a non-deprecated equivalent. > > Patch by andobence! > > Reviewd by: alexfh > > Revision ID: https://reviews.llvm.org/D51332 > > Added: > > clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp > > clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.h > > clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-deprecated-ios-base-aliases.rst > > clang-tools-extra/trunk/test/clang-tidy/modernize-deprecated-ios-base-aliases.cpp > Modified: > clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt > clang-tools-extra/trunk/clang-tidy/modernize/ModernizeTidyModule.cpp > clang-tools-extra/trunk/docs/ReleaseNotes.rst > clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst > > Modified: clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt > URL: > http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt?rev=343848&r1=343847&r2=343848&view=diff > == > --- clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt (original) > +++ clang-tools-extra/trunk/clang-tidy/modernize/CMakeLists.txt Fri Oct 5 > 06:36:00 2018 > @@ -4,6 +4,7 @@ add_clang_library(clangTidyModernizeModu > AvoidBindCheck.cpp > ConcatNestedNamespacesCheck.cpp > DeprecatedHeadersCheck.cpp > + DeprecatedIosBaseAliasesCheck.cpp > LoopConvertCheck.cpp > LoopConvertUtils.cpp > MakeSharedCheck.cpp > > Added: > clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp > URL: > http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp?rev=343848&view=auto > == > --- > clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp > (added) > +++ > clang-tools-extra/trunk/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp > Fri Oct 5 06:36:00 2018 > @@ -0,0 +1,80 @@ > +//===--- DeprecatedIosBaseAliasesCheck.cpp - > clang-tidy===// > +// > +// The LLVM Compiler Infrastructure > +// > +// This file is distributed under the University of Illinois Open Source > +// License. See LICENSE.TXT for details. > +// > +//===--===// > + > +#include "DeprecatedIosBaseAliasesCheck.h" > +#include "clang/AST/ASTContext.h" > +#include "clang/ASTMatchers/ASTMatchFinder.h" > + > +using namespace clang::ast_matchers; > + > +namespace clang { > +namespace tidy { > +namespace modernize { > + > +static const std::array DeprecatedTypes = { > +"::std::ios_base::io_state", "::std::ios_base::open_mode", > +"::std::ios_base::seek_dir", "::std::ios_base::streamoff", > +"::std::ios_base::streampos", > +}; > + > +static const llvm::StringMap ReplacementTypes = { > +{"io_state", "iostate"}, > +{"open_mode", "openmode"}, > +{"seek_dir", "seekdir"}}; > + > +void DeprecatedIosBaseAliasesCheck::registerMatchers(MatchFinder *Finder) { > + // Only register the matchers for C++; the functionality currently does not > + // provide any benefit to other languages, despite being benign. > + if (!getLangOpts().CPlusPlus) > +return; > + > + auto IoStateDecl = > typedefDecl(hasAnyName(DeprecatedTypes)).bind("TypeDecl"); > + auto IoStateType = > + qualType(hasDeclaration(IoStateDecl), unless(elaboratedType())); > + > + Finder->addMatcher(typeLoc(loc(IoStateType)).bind("TypeLoc"), this); > +} > + > +void DeprecatedIosBaseAliasesCheck::check( > +const MatchFinder::MatchResult &Result) { > + SourceManager &SM = *Result.SourceManager; > + > + const auto *Typedef = Result.Nodes.getNodeAs("TypeDecl"); > + StringRef TypeName = Typedef->getName(); > + bool HasReplacement = ReplacementTypes.count(TypeName); > + > + const auto *TL = Result.Nodes.getNodeAs("TypeLoc"); > + SourceLocation IoStateLoc = TL->getBeginLoc(); > + > + // Do
[PATCH] D50250: [clang][ubsan] Implicit Conversion Sanitizer - integer sign change - clang part
lebedev.ri added a comment. Ping. Repository: rC Clang https://reviews.llvm.org/D50250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D50901: [clang][ubsan] Split Implicit Integer Truncation Sanitizer into unsigned and signed checks
lebedev.ri added a comment. Ping! It seemed we were so close here :) Repository: rC Clang https://reviews.llvm.org/D50901 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits