diff options
Diffstat (limited to 'chromium/tools/clang')
22 files changed, 326 insertions, 239 deletions
diff --git a/chromium/tools/clang/OWNERS b/chromium/tools/clang/OWNERS index d0e3cf46145..4c7cbe4ffaa 100644 --- a/chromium/tools/clang/OWNERS +++ b/chromium/tools/clang/OWNERS @@ -3,3 +3,5 @@ thakis@chromium.org # Only for clang tooling. dcheng@chromium.org + +# COMPONENT: Tools diff --git a/chromium/tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp b/chromium/tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp index d263a8cc5ee..43b064ccdcf 100644 --- a/chromium/tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp +++ b/chromium/tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp @@ -33,6 +33,10 @@ class BlinkGCPluginAction : public PluginASTAction { for (const auto& arg : args) { if (arg == "dump-graph") { options_.dump_graph = true; + } else if (arg == "warn-stack-allocated-trace-method") { + // TODO(sof): after next roll, remove this option to round out + // crbug.com/689874 + continue; } else if (arg == "warn-unneeded-finalizer") { options_.warn_unneeded_finalizer = true; } else if (arg == "use-chromium-style-naming") { diff --git a/chromium/tools/clang/blink_gc_plugin/BlinkGCPluginConsumer.cpp b/chromium/tools/clang/blink_gc_plugin/BlinkGCPluginConsumer.cpp index c3e277a7ae1..771d3f86acb 100644 --- a/chromium/tools/clang/blink_gc_plugin/BlinkGCPluginConsumer.cpp +++ b/chromium/tools/clang/blink_gc_plugin/BlinkGCPluginConsumer.cpp @@ -181,6 +181,8 @@ void BlinkGCPluginConsumer::CheckClass(RecordInfo* info) { return; if (CXXMethodDecl* trace = info->GetTraceMethod()) { + if (info->IsStackAllocated()) + reporter_.TraceMethodForStackAllocatedClass(info, trace); if (trace->isPure()) reporter_.ClassDeclaresPureVirtualTrace(info, trace); } else if (info->RequiresTraceMethod()) { @@ -528,7 +530,6 @@ void BlinkGCPluginConsumer::CheckTraceOrDispatchMethod( CXXMethodDecl* method) { Config::TraceMethodType trace_type = Config::GetTraceMethodType(method); if (trace_type == Config::TRACE_AFTER_DISPATCH_METHOD || - trace_type == Config::TRACE_AFTER_DISPATCH_IMPL_METHOD || !parent->GetTraceDispatchMethod()) { CheckTraceMethod(parent, method, trace_type); } @@ -549,12 +550,6 @@ void BlinkGCPluginConsumer::CheckTraceMethod( CheckTraceVisitor visitor(trace, parent, &cache_); visitor.TraverseCXXMethodDecl(trace); - // Skip reporting if this trace method is a just delegate to - // traceImpl (or traceAfterDispatchImpl) method. We will report on - // CheckTraceMethod on traceImpl method. - if (visitor.delegates_to_traceimpl()) - return; - for (auto& base : parent->GetBases()) if (!base.second.IsProperlyTraced()) reporter_.BaseRequiresTracing(parent, trace, base.first); diff --git a/chromium/tools/clang/blink_gc_plugin/BlinkGCPluginOptions.h b/chromium/tools/clang/blink_gc_plugin/BlinkGCPluginOptions.h index baaa2fff6f1..fee044b7b1a 100644 --- a/chromium/tools/clang/blink_gc_plugin/BlinkGCPluginOptions.h +++ b/chromium/tools/clang/blink_gc_plugin/BlinkGCPluginOptions.h @@ -11,9 +11,14 @@ struct BlinkGCPluginOptions { bool dump_graph = false; + + // If |true|, emit warning for class types which derive from from + // GarbageCollectedFinalized<> when just GarbageCollected<> will do. bool warn_unneeded_finalizer = false; + // TODO(https://crbug.com/675879): Clean up after the Blink rename. bool use_chromium_style_naming = false; + std::set<std::string> ignored_classes; std::set<std::string> checked_namespaces; std::vector<std::string> ignored_directories; diff --git a/chromium/tools/clang/blink_gc_plugin/CheckTraceVisitor.cpp b/chromium/tools/clang/blink_gc_plugin/CheckTraceVisitor.cpp index c996ca7dd14..8f6639eae41 100644 --- a/chromium/tools/clang/blink_gc_plugin/CheckTraceVisitor.cpp +++ b/chromium/tools/clang/blink_gc_plugin/CheckTraceVisitor.cpp @@ -13,15 +13,7 @@ using namespace clang; CheckTraceVisitor::CheckTraceVisitor(CXXMethodDecl* trace, RecordInfo* info, RecordCache* cache) - : trace_(trace), - info_(info), - cache_(cache), - delegates_to_traceimpl_(false) { -} - -bool CheckTraceVisitor::delegates_to_traceimpl() const { - return delegates_to_traceimpl_; -} + : trace_(trace), info_(info), cache_(cache) {} bool CheckTraceVisitor::VisitMemberExpr(MemberExpr* member) { // In weak callbacks, consider any occurrence as a correct usage. @@ -72,8 +64,6 @@ bool CheckTraceVisitor::VisitCallExpr(CallExpr* call) { CXXRecordDecl* decl = base->getPointeeType()->getAsCXXRecordDecl(); if (decl) CheckTraceFieldCall(expr->getMemberName().getAsString(), decl, arg); - if (Config::IsTraceImplName(expr->getMemberName().getAsString())) - delegates_to_traceimpl_ = true; return true; } @@ -81,10 +71,6 @@ bool CheckTraceVisitor::VisitCallExpr(CallExpr* call) { if (CheckTraceFieldMemberCall(expr) || CheckRegisterWeakMembers(expr)) return true; - if (Config::IsTraceImplName(expr->getMethodDecl()->getNameAsString())) { - delegates_to_traceimpl_ = true; - return true; - } } CheckTraceBaseCall(call); @@ -92,10 +78,6 @@ bool CheckTraceVisitor::VisitCallExpr(CallExpr* call) { } bool CheckTraceVisitor::IsTraceCallName(const std::string& name) { - if (trace_->getName() == kTraceImplName) - return name == kTraceName; - if (trace_->getName() == kTraceAfterDispatchImplName) - return name == kTraceAfterDispatchName; // Currently, a manually dispatched class cannot have mixin bases (having // one would add a vtable which we explicitly check against). This means // that we can only make calls to a trace method of the same name. Revisit @@ -232,8 +214,7 @@ bool CheckTraceVisitor::CheckTraceBaseCall(CallExpr* call) { dyn_cast<UnresolvedMemberExpr>(call->getCallee())) { // Callee part may become unresolved if the type of the argument // ("visitor") is a template parameter and the called function is - // overloaded (i.e. trace(Visitor*) and - // trace(InlinedGlobalMarkingVisitor)). + // overloaded. // // Here, we try to find a function that looks like trace() from the // candidate overloaded functions, and if we find one, we assume it is @@ -351,6 +332,8 @@ bool CheckTraceVisitor::CheckRegisterWeakMembers(CXXMemberCallExpr* call) { nested_visitor.TraverseStmt(callback->getBody()); } } + // TODO: mark all WeakMember<>s as traced even if + // the body isn't available? } } return true; diff --git a/chromium/tools/clang/blink_gc_plugin/CheckTraceVisitor.h b/chromium/tools/clang/blink_gc_plugin/CheckTraceVisitor.h index 580a6fba99b..e1afd9b602e 100644 --- a/chromium/tools/clang/blink_gc_plugin/CheckTraceVisitor.h +++ b/chromium/tools/clang/blink_gc_plugin/CheckTraceVisitor.h @@ -23,8 +23,6 @@ class CheckTraceVisitor : public clang::RecursiveASTVisitor<CheckTraceVisitor> { RecordInfo* info, RecordCache* cache); - bool delegates_to_traceimpl() const; - bool VisitMemberExpr(clang::MemberExpr* member); bool VisitCallExpr(clang::CallExpr* call); @@ -53,7 +51,6 @@ class CheckTraceVisitor : public clang::RecursiveASTVisitor<CheckTraceVisitor> { clang::CXXMethodDecl* trace_; RecordInfo* info_; RecordCache* cache_; - bool delegates_to_traceimpl_; }; #endif // TOOLS_BLINK_GC_PLUGIN_CHECK_TRACE_VISITOR_H_ diff --git a/chromium/tools/clang/blink_gc_plugin/Config.cpp b/chromium/tools/clang/blink_gc_plugin/Config.cpp index bb32ad449d3..fa00782cc6b 100644 --- a/chromium/tools/clang/blink_gc_plugin/Config.cpp +++ b/chromium/tools/clang/blink_gc_plugin/Config.cpp @@ -14,10 +14,8 @@ using namespace clang; namespace legacy { const char kCreateName[] = "create"; const char kTraceName[] = "trace"; -const char kTraceImplName[] = "traceImpl"; const char kFinalizeName[] = "finalizeGarbageCollectedObject"; const char kTraceAfterDispatchName[] = "traceAfterDispatch"; -const char kTraceAfterDispatchImplName[] = "traceAfterDispatchImpl"; const char kRegisterWeakMembersName[] = "registerWeakMembers"; const char kAdjustAndMarkName[] = "adjustAndMark"; const char kIsHeapObjectAliveName[] = "isHeapObjectAlive"; @@ -26,10 +24,8 @@ const char kIsHeapObjectAliveName[] = "isHeapObjectAlive"; const char kNewOperatorName[] = "operator new"; const char* kCreateName = "Create"; const char* kTraceName = "Trace"; -const char* kTraceImplName = "TraceImpl"; const char* kFinalizeName = "FinalizeGarbageCollectedObject"; const char* kTraceAfterDispatchName = "TraceAfterDispatch"; -const char* kTraceAfterDispatchImplName = "TraceAfterDispatchImpl"; const char* kRegisterWeakMembersName = "RegisterWeakMembers"; const char kHeapAllocatorName[] = "HeapAllocator"; const char kTraceIfNeededName[] = "TraceIfNeeded"; @@ -46,10 +42,8 @@ const char kReverseIteratorName[] = "reverse_iterator"; void Config::UseLegacyNames() { kCreateName = legacy::kCreateName; kTraceName = legacy::kTraceName; - kTraceImplName = legacy::kTraceImplName; kFinalizeName = legacy::kFinalizeName; kTraceAfterDispatchName = legacy::kTraceAfterDispatchName; - kTraceAfterDispatchImplName = legacy::kTraceAfterDispatchImplName; kRegisterWeakMembersName = legacy::kRegisterWeakMembersName; kAdjustAndMarkName = legacy::kAdjustAndMarkName; kIsHeapObjectAliveName = legacy::kIsHeapObjectAliveName; diff --git a/chromium/tools/clang/blink_gc_plugin/Config.h b/chromium/tools/clang/blink_gc_plugin/Config.h index 2ab933f382d..f0c4aeca33b 100644 --- a/chromium/tools/clang/blink_gc_plugin/Config.h +++ b/chromium/tools/clang/blink_gc_plugin/Config.h @@ -20,10 +20,8 @@ extern const char kNewOperatorName[]; extern const char* kCreateName; extern const char* kTraceName; -extern const char* kTraceImplName; extern const char* kFinalizeName; extern const char* kTraceAfterDispatchName; -extern const char* kTraceAfterDispatchImplName; extern const char* kRegisterWeakMembersName; extern const char kHeapAllocatorName[]; extern const char kTraceIfNeededName[]; @@ -219,8 +217,6 @@ class Config { NOT_TRACE_METHOD, TRACE_METHOD, TRACE_AFTER_DISPATCH_METHOD, - TRACE_IMPL_METHOD, - TRACE_AFTER_DISPATCH_IMPL_METHOD }; static TraceMethodType GetTraceMethodType(const clang::FunctionDecl* method) { @@ -228,15 +224,11 @@ class Config { return NOT_TRACE_METHOD; const std::string& name = method->getNameAsString(); - if (name != kTraceName && name != kTraceAfterDispatchName && - name != kTraceImplName && name != kTraceAfterDispatchImplName) + if (name != kTraceName && name != kTraceAfterDispatchName) return NOT_TRACE_METHOD; const clang::QualType& formal_type = method->getParamDecl(0)->getType(); - if (name == kTraceImplName || name == kTraceAfterDispatchImplName) { - if (!IsVisitorDispatcherType(formal_type)) - return NOT_TRACE_METHOD; - } else if (!IsVisitorPtrType(formal_type)) { + if (!IsVisitorPtrType(formal_type)) { return NOT_TRACE_METHOD; } @@ -244,10 +236,6 @@ class Config { return TRACE_METHOD; if (name == kTraceAfterDispatchName) return TRACE_AFTER_DISPATCH_METHOD; - if (name == kTraceImplName) - return TRACE_IMPL_METHOD; - if (name == kTraceAfterDispatchImplName) - return TRACE_AFTER_DISPATCH_IMPL_METHOD; assert(false && "Should not reach here"); return NOT_TRACE_METHOD; @@ -257,10 +245,6 @@ class Config { return GetTraceMethodType(method) != NOT_TRACE_METHOD; } - static bool IsTraceImplName(const std::string& name) { - return name == kTraceImplName || name == kTraceAfterDispatchImplName; - } - static bool StartsWith(const std::string& str, const std::string& prefix) { if (prefix.size() > str.size()) return false; diff --git a/chromium/tools/clang/blink_gc_plugin/DiagnosticsReporter.cpp b/chromium/tools/clang/blink_gc_plugin/DiagnosticsReporter.cpp index 1ae842573ff..95d5595beb5 100644 --- a/chromium/tools/clang/blink_gc_plugin/DiagnosticsReporter.cpp +++ b/chromium/tools/clang/blink_gc_plugin/DiagnosticsReporter.cpp @@ -150,6 +150,10 @@ const char kBaseClassMustDeclareVirtualTrace[] = const char kIteratorToGCManagedCollectionNote[] = "[blink-gc] Iterator field %0 to a GC managed collection declared here:"; +const char kTraceMethodOfStackAllocatedParentNote[] = + "[blink-gc] The stack allocated class %0 provides an unnecessary " + "trace method:"; + } // namespace DiagnosticBuilder DiagnosticsReporter::ReportDiagnostic( @@ -210,6 +214,10 @@ DiagnosticsReporter::DiagnosticsReporter( getErrorLevel(), kLeftMostBaseMustBePolymorphic); diag_base_class_must_declare_virtual_trace_ = diagnostic_.getCustomDiagID( getErrorLevel(), kBaseClassMustDeclareVirtualTrace); + diag_iterator_to_gc_managed_collection_note_ = diagnostic_.getCustomDiagID( + getErrorLevel(), kIteratorToGCManagedCollectionNote); + diag_trace_method_of_stack_allocated_parent_ = diagnostic_.getCustomDiagID( + getErrorLevel(), kTraceMethodOfStackAllocatedParentNote); // Register note messages. diag_base_requires_tracing_note_ = diagnostic_.getCustomDiagID( @@ -256,8 +264,6 @@ DiagnosticsReporter::DiagnosticsReporter( DiagnosticsEngine::Note, kOverriddenNonVirtualTraceNote); diag_manual_dispatch_method_note_ = diagnostic_.getCustomDiagID( DiagnosticsEngine::Note, kManualDispatchMethodNote); - diag_iterator_to_gc_managed_collection_note_ = diagnostic_.getCustomDiagID( - DiagnosticsEngine::Note, kIteratorToGCManagedCollectionNote); } bool DiagnosticsReporter::hasErrorOccurred() const @@ -499,6 +505,14 @@ void DiagnosticsReporter::BaseClassMustDeclareVirtualTrace( << base << derived->record(); } +void DiagnosticsReporter::TraceMethodForStackAllocatedClass( + RecordInfo* info, + CXXMethodDecl* trace) { + ReportDiagnostic(trace->getLocStart(), + diag_trace_method_of_stack_allocated_parent_) + << info->record(); +} + void DiagnosticsReporter::NoteManualDispatchMethod(CXXMethodDecl* dispatch) { ReportDiagnostic(dispatch->getLocStart(), diag_manual_dispatch_method_note_) diff --git a/chromium/tools/clang/blink_gc_plugin/DiagnosticsReporter.h b/chromium/tools/clang/blink_gc_plugin/DiagnosticsReporter.h index ddcfbfd7c8d..6a32f70ec6f 100644 --- a/chromium/tools/clang/blink_gc_plugin/DiagnosticsReporter.h +++ b/chromium/tools/clang/blink_gc_plugin/DiagnosticsReporter.h @@ -62,6 +62,8 @@ class DiagnosticsReporter { clang::CXXRecordDecl* base); void BaseClassMustDeclareVirtualTrace(RecordInfo* derived, clang::CXXRecordDecl* base); + void TraceMethodForStackAllocatedClass(RecordInfo* parent, + clang::CXXMethodDecl* trace); void NoteManualDispatchMethod(clang::CXXMethodDecl* dispatch); void NoteBaseRequiresTracing(BasePoint* base); @@ -136,6 +138,7 @@ class DiagnosticsReporter { unsigned diag_overridden_non_virtual_trace_note_; unsigned diag_manual_dispatch_method_note_; unsigned diag_iterator_to_gc_managed_collection_note_; + unsigned diag_trace_method_of_stack_allocated_parent_; }; #endif // TOOLS_BLINK_GC_PLUGIN_DIAGNOSTICS_REPORTER_H_ diff --git a/chromium/tools/clang/blink_gc_plugin/Edge.h b/chromium/tools/clang/blink_gc_plugin/Edge.h index d7af335dc63..164112ffdb3 100644 --- a/chromium/tools/clang/blink_gc_plugin/Edge.h +++ b/chromium/tools/clang/blink_gc_plugin/Edge.h @@ -143,13 +143,13 @@ class RawPtr : public PtrEdge { { } - bool IsRawPtr() { return true; } - LivenessKind Kind() { return kWeak; } - bool NeedsFinalization() { return false; } - TracingStatus NeedsTracing(NeedsTracingOption) { + bool IsRawPtr() override { return true; } + LivenessKind Kind() override { return kWeak; } + bool NeedsFinalization() override { return false; } + TracingStatus NeedsTracing(NeedsTracingOption) override { return TracingStatus::Illegal(); } - void Accept(EdgeVisitor* visitor) { visitor->VisitRawPtr(this); } + void Accept(EdgeVisitor* visitor) override { visitor->VisitRawPtr(this); } bool HasReferenceType() { return is_ref_type_; } private: @@ -159,83 +159,83 @@ class RawPtr : public PtrEdge { class RefPtr : public PtrEdge { public: explicit RefPtr(Edge* ptr) : PtrEdge(ptr) { } - bool IsRefPtr() { return true; } - LivenessKind Kind() { return kStrong; } - bool NeedsFinalization() { return true; } - TracingStatus NeedsTracing(NeedsTracingOption) { + bool IsRefPtr() override { return true; } + LivenessKind Kind() override { return kStrong; } + bool NeedsFinalization() override { return true; } + TracingStatus NeedsTracing(NeedsTracingOption) override { return TracingStatus::Illegal(); } - void Accept(EdgeVisitor* visitor) { visitor->VisitRefPtr(this); } + void Accept(EdgeVisitor* visitor) override { visitor->VisitRefPtr(this); } }; class OwnPtr : public PtrEdge { public: explicit OwnPtr(Edge* ptr) : PtrEdge(ptr) { } - bool IsOwnPtr() { return true; } - LivenessKind Kind() { return kStrong; } - bool NeedsFinalization() { return true; } - TracingStatus NeedsTracing(NeedsTracingOption) { + bool IsOwnPtr() override { return true; } + LivenessKind Kind() override { return kStrong; } + bool NeedsFinalization() override { return true; } + TracingStatus NeedsTracing(NeedsTracingOption) override { return TracingStatus::Illegal(); } - void Accept(EdgeVisitor* visitor) { visitor->VisitOwnPtr(this); } + void Accept(EdgeVisitor* visitor) override { visitor->VisitOwnPtr(this); } }; class UniquePtr : public PtrEdge { public: explicit UniquePtr(Edge* ptr) : PtrEdge(ptr) { } - bool IsUniquePtr() { return true; } - LivenessKind Kind() { return kStrong; } - bool NeedsFinalization() { return true; } - TracingStatus NeedsTracing(NeedsTracingOption) { + bool IsUniquePtr() override { return true; } + LivenessKind Kind() override { return kStrong; } + bool NeedsFinalization() override { return true; } + TracingStatus NeedsTracing(NeedsTracingOption) override { return TracingStatus::Illegal(); } - void Accept(EdgeVisitor* visitor) { visitor->VisitUniquePtr(this); } + void Accept(EdgeVisitor* visitor) override { visitor->VisitUniquePtr(this); } }; class Member : public PtrEdge { public: explicit Member(Edge* ptr) : PtrEdge(ptr) { } - bool IsMember() { return true; } - LivenessKind Kind() { return kStrong; } - bool NeedsFinalization() { return false; } - TracingStatus NeedsTracing(NeedsTracingOption) { + bool IsMember() override { return true; } + LivenessKind Kind() override { return kStrong; } + bool NeedsFinalization() override { return false; } + TracingStatus NeedsTracing(NeedsTracingOption) override { return TracingStatus::Needed(); } - void Accept(EdgeVisitor* visitor) { visitor->VisitMember(this); } + void Accept(EdgeVisitor* visitor) override { visitor->VisitMember(this); } }; class WeakMember : public PtrEdge { public: explicit WeakMember(Edge* ptr) : PtrEdge(ptr) { } - bool IsWeakMember() { return true; } - LivenessKind Kind() { return kWeak; } - bool NeedsFinalization() { return false; } - TracingStatus NeedsTracing(NeedsTracingOption) { + bool IsWeakMember() override { return true; } + LivenessKind Kind() override { return kWeak; } + bool NeedsFinalization() override { return false; } + TracingStatus NeedsTracing(NeedsTracingOption) override { return TracingStatus::Needed(); } - void Accept(EdgeVisitor* visitor) { visitor->VisitWeakMember(this); } + void Accept(EdgeVisitor* visitor) override { visitor->VisitWeakMember(this); } }; class Persistent : public PtrEdge { public: explicit Persistent(Edge* ptr) : PtrEdge(ptr) { } - LivenessKind Kind() { return kRoot; } - bool NeedsFinalization() { return true; } - TracingStatus NeedsTracing(NeedsTracingOption) { + LivenessKind Kind() override { return kRoot; } + bool NeedsFinalization() override { return true; } + TracingStatus NeedsTracing(NeedsTracingOption) override { return TracingStatus::Unneeded(); } - void Accept(EdgeVisitor* visitor) { visitor->VisitPersistent(this); } + void Accept(EdgeVisitor* visitor) override { visitor->VisitPersistent(this); } }; class CrossThreadPersistent : public PtrEdge { public: explicit CrossThreadPersistent(Edge* ptr) : PtrEdge(ptr) { } - LivenessKind Kind() { return kRoot; } - bool NeedsFinalization() { return true; } - TracingStatus NeedsTracing(NeedsTracingOption) { + LivenessKind Kind() override { return kRoot; } + bool NeedsFinalization() override { return true; } + TracingStatus NeedsTracing(NeedsTracingOption) override { return TracingStatus::Illegal(); } - void Accept(EdgeVisitor* visitor) { + void Accept(EdgeVisitor* visitor) override { visitor->VisitCrossThreadPersistent(this); } }; @@ -253,18 +253,18 @@ class Collection : public Edge { delete *it; } } - bool IsCollection() { return true; } - LivenessKind Kind() { return is_root_ ? kRoot : kStrong; } + bool IsCollection() override { return true; } + LivenessKind Kind() override { return is_root_ ? kRoot : kStrong; } bool on_heap() { return on_heap_; } bool is_root() { return is_root_; } Members& members() { return members_; } - void Accept(EdgeVisitor* visitor) { visitor->VisitCollection(this); } + void Accept(EdgeVisitor* visitor) override { visitor->VisitCollection(this); } void AcceptMembers(EdgeVisitor* visitor) { for (Members::iterator it = members_.begin(); it != members_.end(); ++it) (*it)->Accept(visitor); } - bool NeedsFinalization(); - TracingStatus NeedsTracing(NeedsTracingOption) { + bool NeedsFinalization() override; + TracingStatus NeedsTracing(NeedsTracingOption) override { if (is_root_) return TracingStatus::Unneeded(); if (on_heap_) @@ -292,10 +292,10 @@ class Iterator : public Edge { : info_(info), on_heap_(on_heap), is_unsafe_(is_unsafe) {} ~Iterator() {} - void Accept(EdgeVisitor* visitor) { visitor->VisitIterator(this); } + void Accept(EdgeVisitor* visitor) override { visitor->VisitIterator(this); } LivenessKind Kind() override { return kStrong; } - bool NeedsFinalization() { return false; } - TracingStatus NeedsTracing(NeedsTracingOption) { + bool NeedsFinalization() override { return false; } + TracingStatus NeedsTracing(NeedsTracingOption) override { if (on_heap_) return TracingStatus::Needed(); return TracingStatus::Unneeded(); diff --git a/chromium/tools/clang/blink_gc_plugin/RecordInfo.cpp b/chromium/tools/clang/blink_gc_plugin/RecordInfo.cpp index fe211ac8b9c..419ed7ae764 100644 --- a/chromium/tools/clang/blink_gc_plugin/RecordInfo.cpp +++ b/chromium/tools/clang/blink_gc_plugin/RecordInfo.cpp @@ -438,7 +438,6 @@ void RecordInfo::DetermineTracingMethods() { if (Config::IsGCBase(name_)) return; CXXMethodDecl* trace = nullptr; - CXXMethodDecl* trace_impl = nullptr; CXXMethodDecl* trace_after_dispatch = nullptr; bool has_adjust_and_mark = false; bool has_is_heap_object_alive = false; @@ -459,11 +458,6 @@ void RecordInfo::DetermineTracingMethods() { case Config::TRACE_AFTER_DISPATCH_METHOD: trace_after_dispatch = method; break; - case Config::TRACE_IMPL_METHOD: - trace_impl = method; - break; - case Config::TRACE_AFTER_DISPATCH_IMPL_METHOD: - break; case Config::NOT_TRACE_METHOD: if (method->getNameAsString() == kFinalizeName) { finalize_dispatch_method_ = method; @@ -481,7 +475,7 @@ void RecordInfo::DetermineTracingMethods() { has_adjust_and_mark && has_is_heap_object_alive ? kTrue : kFalse; if (trace_after_dispatch) { trace_method_ = trace_after_dispatch; - trace_dispatch_method_ = trace_impl ? trace_impl : trace; + trace_dispatch_method_ = trace; } else { // TODO: Can we never have a dispatch method called trace without the same // class defining a traceAfterDispatch method? diff --git a/chromium/tools/clang/plugins/FindBadConstructsConsumer.cpp b/chromium/tools/clang/plugins/FindBadConstructsConsumer.cpp index 636261b3db3..427fa472a9e 100644 --- a/chromium/tools/clang/plugins/FindBadConstructsConsumer.cpp +++ b/chromium/tools/clang/plugins/FindBadConstructsConsumer.cpp @@ -112,13 +112,14 @@ std::set<FunctionDecl*> GetLateParsedFunctionDecls(TranslationUnitDecl* decl) { return v.late_parsed_decls; } -std::string GetAutoReplacementTypeAsString(QualType type) { +std::string GetAutoReplacementTypeAsString(QualType type, + StorageClass storage_class) { QualType non_reference_type = type.getNonReferenceType(); if (!non_reference_type->isPointerType()) - return "auto"; + return storage_class == SC_Static ? "static auto" : "auto"; - std::string result = - GetAutoReplacementTypeAsString(non_reference_type->getPointeeType()); + std::string result = GetAutoReplacementTypeAsString( + non_reference_type->getPointeeType(), storage_class); result += "*"; if (non_reference_type.isLocalConstQualified()) result += " const"; @@ -1016,7 +1017,8 @@ void FindBadConstructsConsumer::CheckVarDecl(clang::VarDecl* var_decl) { diag_auto_deduced_to_a_pointer_type_) << FixItHint::CreateReplacement( range, - GetAutoReplacementTypeAsString(var_decl->getType())); + GetAutoReplacementTypeAsString( + var_decl->getType(), var_decl->getStorageClass())); } } } diff --git a/chromium/tools/clang/rewrite_to_chrome_style/EditTracker.cpp b/chromium/tools/clang/rewrite_to_chrome_style/EditTracker.cpp index cd8228ebdf5..600fb02470e 100644 --- a/chromium/tools/clang/rewrite_to_chrome_style/EditTracker.cpp +++ b/chromium/tools/clang/rewrite_to_chrome_style/EditTracker.cpp @@ -9,6 +9,27 @@ #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +namespace { + +const char* GetTag(RenameCategory category) { + switch (category) { + case RenameCategory::kEnumValue: + return "enum"; + case RenameCategory::kField: + return "var"; + case RenameCategory::kFunction: + return "func"; + case RenameCategory::kUnresolved: + return "unresolved"; + case RenameCategory::kVariable: + return "var"; + } +} + +} // namespace + +EditTracker::EditTracker(RenameCategory category) : category_(category) {} + void EditTracker::Add(const clang::SourceManager& source_manager, clang::SourceLocation location, llvm::StringRef original_text, @@ -30,8 +51,8 @@ void EditTracker::Add(const clang::SourceManager& source_manager, result.first->getValue().filenames.try_emplace(filename); } -void EditTracker::SerializeTo(llvm::StringRef tag, - llvm::raw_ostream& output) const { +void EditTracker::SerializeTo(llvm::raw_ostream& output) const { + const char* tag = GetTag(category_); for (const auto& edit : tracked_edits_) { for (const auto& filename : edit.getValue().filenames) { output << filename.getKey() << ":" << tag << ":" << edit.getKey() << ":" diff --git a/chromium/tools/clang/rewrite_to_chrome_style/EditTracker.h b/chromium/tools/clang/rewrite_to_chrome_style/EditTracker.h index ef5e30145ad..0d8bf0c115e 100644 --- a/chromium/tools/clang/rewrite_to_chrome_style/EditTracker.h +++ b/chromium/tools/clang/rewrite_to_chrome_style/EditTracker.h @@ -22,11 +22,19 @@ struct EditInfo { llvm::StringSet<> filenames; }; +enum class RenameCategory { + kEnumValue, + kField, + kFunction, + kUnresolved, + kVariable, +}; + // Simple class that tracks the edits made by path. Used to dump the databaes // used by the Blink rebase helper. class EditTracker { public: - EditTracker() = default; + explicit EditTracker(RenameCategory category); void Add(const clang::SourceManager& source_manager, clang::SourceLocation location, @@ -36,7 +44,7 @@ class EditTracker { // Serializes the tracked edits to |output|. Emits: // <filename>:<tag>:<original text>:<new text> // for each distinct filename for each tracked edit. - void SerializeTo(llvm::StringRef tag, llvm::raw_ostream& output) const; + void SerializeTo(llvm::raw_ostream& output) const; private: EditTracker(const EditTracker&) = delete; @@ -44,6 +52,8 @@ class EditTracker { // The string key is the original text. llvm::StringMap<EditInfo> tracked_edits_; + + RenameCategory category_; }; #endif // #define TOOLS_CLANG_REWRITE_TO_CHROME_STYLE_EDIT_TRACKER_H_ diff --git a/chromium/tools/clang/rewrite_to_chrome_style/OWNERS b/chromium/tools/clang/rewrite_to_chrome_style/OWNERS index cc9ab9fe0e2..b2ca4271d78 100644 --- a/chromium/tools/clang/rewrite_to_chrome_style/OWNERS +++ b/chromium/tools/clang/rewrite_to_chrome_style/OWNERS @@ -1,3 +1,5 @@ danakj@chromium.org dcheng@chromium.org lukasza@chromium.org + +# COMPONENT: Tools diff --git a/chromium/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp b/chromium/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp index 5a0d6442044..9f94e9b6a51 100644 --- a/chromium/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp +++ b/chromium/tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp @@ -51,6 +51,8 @@ namespace { const char kBlinkFieldPrefix[] = "m_"; const char kBlinkStaticMemberPrefix[] = "s_"; const char kGeneratedFileRegex[] = "^gen/|/gen/"; +const char kGeneratedFileExclusionRegex[] = + "(^gen/|/gen/).*/ComputedStyleBase\\.h$"; const char kGMockMethodNamePrefix[] = "gmock_"; const char kMethodBlocklistParamName[] = "method-blocklist"; @@ -88,6 +90,13 @@ AST_MATCHER_P(clang::FunctionTemplateDecl, return InnerMatcher.matches(*Node.getTemplatedDecl(), Finder, Builder); } +AST_MATCHER_P(clang::Decl, + hasCanonicalDecl, + clang::ast_matchers::internal::Matcher<clang::Decl>, + InnerMatcher) { + return InnerMatcher.matches(*Node.getCanonicalDecl(), Finder, Builder); +} + // Matches a CXXMethodDecl of a method declared via MOCK_METHODx macro if such // method mocks a method matched by the InnerMatcher. For example if "foo" // matcher matches "interfaceMethod", then mocksMethod(foo()) will match @@ -106,9 +115,6 @@ AST_MATCHER_P(clang::CXXMethodDecl, llvm::StringRef mocked_method_name = method_name.substr(strlen(kGMockMethodNamePrefix)); for (const auto& potentially_mocked_method : Node.getParent()->methods()) { - if (!potentially_mocked_method->isVirtual()) - continue; - clang::DeclarationName decl_name = potentially_mocked_method->getDeclName(); if (!decl_name.isIdentifier() || potentially_mocked_method->getName() != mocked_method_name) @@ -131,6 +137,9 @@ class MethodBlocklist { } bool Contains(const clang::FunctionDecl& method) const { + if (!method.getDeclName().isIdentifier()) + return false; + auto it = method_to_class_to_args_.find(method.getName()); if (it == method_to_class_to_args_.end()) return false; @@ -142,6 +151,8 @@ class MethodBlocklist { clang::dyn_cast<clang::NamedDecl>(method.getDeclContext()); if (!method_context) return false; + if (!method_context->getDeclName().isIdentifier()) + return false; const llvm::StringMap<std::set<unsigned>>& class_to_args = it->second; auto it2 = class_to_args.find(method_context->getName()); @@ -435,7 +446,7 @@ bool IsBlacklistedInstanceMethodName(llvm::StringRef name) { // https://crbug.com/672902: Should not rewrite names that mimick methods // from std library. - "back", "empty", "erase", "front", "insert", + "back", "empty", "erase", "front", "insert", "length", "size", }; for (const auto& b : kBlacklistedNames) { if (name == b) @@ -450,11 +461,17 @@ bool IsBlacklistedMethodName(llvm::StringRef name) { } bool IsBlacklistedFunction(const clang::FunctionDecl& decl) { + if (!decl.getDeclName().isIdentifier()) + return false; + clang::StringRef name = decl.getName(); return IsBlacklistedFunctionName(name) || IsBlacklistedFreeFunctionName(name); } bool IsBlacklistedMethod(const clang::CXXMethodDecl& decl) { + if (!decl.getDeclName().isIdentifier()) + return false; + clang::StringRef name = decl.getName(); if (IsBlacklistedFunctionName(name)) return true; @@ -484,6 +501,50 @@ AST_MATCHER(clang::CXXMethodDecl, isBlacklistedMethod) { return IsBlacklistedMethod(Node); } +bool IsKnownTraitName(clang::StringRef name) { + // This set of names is globally a type trait throughout chromium. + return name == "safeToCompareToEmptyOrDeleted"; +} + +AST_MATCHER(clang::VarDecl, isKnownTraitName) { + return Node.getDeclName().isIdentifier() && IsKnownTraitName(Node.getName()); +} + +AST_MATCHER(clang::Decl, isDeclInGeneratedFile) { + // This matcher mimics the built-in isExpansionInFileMatching matcher from + // llvm/tools/clang/include/clang/ASTMatchers/ASTMatchers.h, except: + // - It special cases some files (e.g. doesn't skip renaming of identifiers + // from gen/blink/core/ComputedStyleBase.h) + + const clang::SourceManager& source_manager = + Node.getASTContext().getSourceManager(); + + // TODO(lukasza): Consider using getSpellingLoc below. + // The built-in isExpansionInFileMatching matcher uses getExpansionLoc below. + // We could consider using getSpellingLoc (which properly handles things like + // SETTINGS_GETTERS_AND_SETTERS macro which is defined in generated code + // (gen/blink/core/SettingsMacros.h), but expanded in non-generated code + // (third_party/WebKit/Source/core/frame/Settings.h). + clang::SourceLocation loc = + source_manager.getExpansionLoc(Node.getLocStart()); + + // TODO(lukasza): jump out of scratch space if token concatenation was used. + if (loc.isInvalid()) + return false; + + const clang::FileEntry* file_entry = + source_manager.getFileEntryForID(source_manager.getFileID(loc)); + if (!file_entry) + return false; + + static llvm::Regex exclusion_regex(kGeneratedFileExclusionRegex); + if (exclusion_regex.match(file_entry->getName())) + return false; + + static llvm::Regex generated_file_regex(kGeneratedFileRegex); + return generated_file_regex.match(file_entry->getName()); +} + // Helper to convert from a camelCaseName to camel_case_name. It uses some // heuristics to try to handle acronyms in camel case names correctly. std::string CamelCaseToUnderscoreCase(StringRef input) { @@ -638,17 +699,18 @@ bool ShouldPrefixFunctionName(const std::string& old_method_name) { "frame", "frameBlameContext", "frontend", + "gridCell", "hash", "heapObjectHeader", "iconURL", "image", "inputMethodController", "inputType", + "interpolationTypes", "layout", "layoutBlock", "layoutObject", "layoutSize", - "length", "lineCap", "lineEndings", "lineJoin", @@ -660,15 +722,20 @@ bool ShouldPrefixFunctionName(const std::string& old_method_name) { "name", "navigationType", "node", + "notificationManager", "outcome", "pagePopup", "paintWorklet", "path", + "position", "processingInstruction", "readyState", "relList", + "referrer", + "referrerPolicy", "resource", "response", + "restrictedKeyMap", "sandboxSupport", "screenInfo", "screenOrientationController", @@ -676,6 +743,7 @@ bool ShouldPrefixFunctionName(const std::string& old_method_name) { "selectionInFlatTree", "settings", "signalingState", + "snapshotById", "state", "string", "styleSheet", @@ -687,8 +755,10 @@ bool ShouldPrefixFunctionName(const std::string& old_method_name) { "thread", "timing", "topLevelBlameContext", + "type", "vector", "visibleSelection", + "visibleSelectionInFlatTree", "webFrame", "widget", "wordBoundaries", @@ -703,7 +773,8 @@ bool ShouldPrefixFunctionName(const std::string& old_method_name) { } AST_MATCHER(clang::FunctionDecl, shouldPrefixFunctionName) { - return ShouldPrefixFunctionName(Node.getName().str()); + return Node.getDeclName().isIdentifier() && + ShouldPrefixFunctionName(Node.getName().str()); } bool GetNameForDecl(const clang::FunctionDecl& decl, @@ -828,6 +899,13 @@ bool GetNameForDecl(const clang::VarDecl& decl, return false; } + // This is a type trait that appears in consumers of WTF as well as inside + // WTF. We want it to be named in this_style_of_case accordingly. + if (IsKnownTraitName(original_name)) { + name = CamelCaseToUnderscoreCase(original_name); + return true; + } + // static class members match against VarDecls. Blink style dictates that // these should be prefixed with `s_`, so strip that off. Also check for `m_` // and strip that off too, for code that accidentally uses the wrong prefix. @@ -998,8 +1076,9 @@ struct TargetNodeTraits<clang::UnresolvedUsingValueDecl> { template <typename TargetNode> class RewriterBase : public MatchFinder::MatchCallback { public: - explicit RewriterBase(std::set<Replacement>* replacements) - : replacements_(replacements) {} + explicit RewriterBase(std::set<Replacement>* replacements, + RenameCategory category) + : replacements_(replacements), edit_tracker_(category) {} const TargetNode& GetTargetNode(const MatchFinder::MatchResult& result) { const TargetNode* target_node = result.Nodes.getNodeAs<TargetNode>( @@ -1085,23 +1164,57 @@ class RewriterBase : public MatchFinder::MatchCallback { edit_tracker_.Add(*result.SourceManager, loc, old_name, new_name); } - const EditTracker& edit_tracker() const { return edit_tracker_; } + const EditTracker* edit_tracker() const { return &edit_tracker_; } private: std::set<Replacement>* const replacements_; EditTracker edit_tracker_; }; +template <typename DeclNode> +RenameCategory GetCategory(); +template <> +RenameCategory GetCategory<clang::FieldDecl>() { + return RenameCategory::kField; +} +template <> +RenameCategory GetCategory<clang::VarDecl>() { + return RenameCategory::kVariable; +} +template <> +RenameCategory GetCategory<clang::FunctionDecl>() { + return RenameCategory::kFunction; +} +template <> +RenameCategory GetCategory<clang::CXXMethodDecl>() { + return RenameCategory::kFunction; +} +template <> +RenameCategory GetCategory<clang::EnumConstantDecl>() { + return RenameCategory::kEnumValue; +} +template <> +RenameCategory GetCategory<clang::NamedDecl>() { + return RenameCategory::kUnresolved; +} +template <> +RenameCategory GetCategory<clang::UsingDecl>() { + return RenameCategory::kUnresolved; +} + template <typename DeclNode, typename TargetNode> class DeclRewriterBase : public RewriterBase<TargetNode> { public: using Base = RewriterBase<TargetNode>; explicit DeclRewriterBase(std::set<Replacement>* replacements) - : Base(replacements) {} + : Base(replacements, GetCategory<DeclNode>()) {} void run(const MatchFinder::MatchResult& result) override { const DeclNode* decl = result.Nodes.getNodeAs<DeclNode>("decl"); + if (!decl->getDeclName().isIdentifier()) + return; + assert(decl); llvm::StringRef old_name = decl->getName(); @@ -1175,28 +1288,29 @@ class GMockMemberRewriter // Find location of the gmock_##MockedMethod identifier. clang::SourceLocation target_loc = Base::GetTargetLoc(result); - // Find location of EXPECT_CALL macro invocation. + // Find location of EXPECT_CALL or ON_CALL macro invocation. clang::SourceLocation macro_call_loc = result.SourceManager->getExpansionLoc(target_loc); // Map |macro_call_loc| to argument location (location of the method name // that needs renaming). - auto it = expect_call_to_2nd_arg.find(macro_call_loc); - if (it == expect_call_to_2nd_arg.end()) + auto it = gmock_macro_call_to_2nd_arg.find(macro_call_loc); + if (it == gmock_macro_call_to_2nd_arg.end()) return clang::SourceLocation(); return it->second; } private: - std::map<clang::SourceLocation, clang::SourceLocation> expect_call_to_2nd_arg; + std::map<clang::SourceLocation, clang::SourceLocation> + gmock_macro_call_to_2nd_arg; - // Called from PPCallbacks with the locations of EXPECT_CALL macro invocation: - // Example: + // Called from PPCallbacks with the locations of EXPECT_CALL and ON_CALL macro + // invocation. Example: // EXPECT_CALL(my_mock, myMethod(123, 456)); // ^- expansion_loc ^- actual_arg_loc - void RecordExpectCallMacroInvocation(clang::SourceLocation expansion_loc, - clang::SourceLocation second_arg_loc) { - expect_call_to_2nd_arg[expansion_loc] = second_arg_loc; + void RecordGMockMacroInvocation(clang::SourceLocation expansion_loc, + clang::SourceLocation second_arg_loc) { + gmock_macro_call_to_2nd_arg[expansion_loc] = second_arg_loc; } class PPCallbacks : public clang::PPCallbacks { @@ -1211,7 +1325,7 @@ class GMockMemberRewriter if (!id) return; - if (id->getName() != "EXPECT_CALL") + if (id->getName() != "EXPECT_CALL" && id->getName() != "ON_CALL") return; if (def.getMacroInfo()->getNumArgs() != 2) @@ -1221,7 +1335,7 @@ class GMockMemberRewriter // is in testing/gmock/include/gmock/gmock-spec-builders.h but I don't // know how to get clang::SourceManager to call getFileName. - rewriter_->RecordExpectCallMacroInvocation( + rewriter_->RecordGMockMacroInvocation( name.getLocation(), args->getUnexpArgument(1)->getLocation()); } @@ -1281,7 +1395,7 @@ class UnresolvedRewriterBase : public RewriterBase<TargetNode> { using Base = RewriterBase<TargetNode>; explicit UnresolvedRewriterBase(std::set<Replacement>* replacements) - : RewriterBase<TargetNode>(replacements) {} + : RewriterBase<TargetNode>(replacements, RenameCategory::kUnresolved) {} void run(const MatchFinder::MatchResult& result) override { const TargetNode& node = Base::GetTargetNode(result); @@ -1439,7 +1553,7 @@ int main(int argc, const char* argv[]) { auto in_blink_namespace = decl( anyOf(decl_under_blink_namespace, decl_has_qualifier_to_blink_namespace, hasAncestor(decl_has_qualifier_to_blink_namespace)), - unless(isExpansionInFileMatching(kGeneratedFileRegex))); + unless(hasCanonicalDecl(isDeclInGeneratedFile()))); // Field, variable, and enum declarations ======== // Given @@ -1458,6 +1572,8 @@ int main(int argc, const char* argv[]) { has(cxxMethodDecl(isUserProvided(), isInstanceMethod())))))); auto var_decl_matcher = id("decl", varDecl(in_blink_namespace, unless(is_type_trait_value))); + // For known trait names, rename every instance anywhere in the codebase. + auto type_trait_decl_matcher = id("decl", varDecl(isKnownTraitName())); auto enum_member_decl_matcher = id("decl", enumConstantDecl(in_blink_namespace)); @@ -1466,6 +1582,7 @@ int main(int argc, const char* argv[]) { VarDeclRewriter var_decl_rewriter(&replacements); match_finder.addMatcher(var_decl_matcher, &var_decl_rewriter); + match_finder.addMatcher(type_trait_decl_matcher, &var_decl_rewriter); EnumConstantDeclRewriter enum_member_decl_rewriter(&replacements); match_finder.addMatcher(enum_member_decl_matcher, &enum_member_decl_rewriter); @@ -1488,6 +1605,8 @@ int main(int argc, const char* argv[]) { // there's nothing interesting to rewrite in those either. unless(hasAncestor(functionDecl(isDefaulted()))))); auto decl_ref_matcher = id("expr", declRefExpr(to(var_decl_matcher))); + auto type_trait_ref_matcher = + id("expr", declRefExpr(to(type_trait_decl_matcher))); auto enum_member_ref_matcher = id("expr", declRefExpr(to(enum_member_decl_matcher))); @@ -1496,6 +1615,7 @@ int main(int argc, const char* argv[]) { DeclRefRewriter decl_ref_rewriter(&replacements); match_finder.addMatcher(decl_ref_matcher, &decl_ref_rewriter); + match_finder.addMatcher(type_trait_ref_matcher, &decl_ref_rewriter); EnumConstantDeclRefRewriter enum_member_ref_rewriter(&replacements); match_finder.addMatcher(enum_member_ref_matcher, &enum_member_ref_rewriter); @@ -1773,7 +1893,9 @@ int main(int argc, const char* argv[]) { // GMock calls lookup ======== // Given // EXPECT_CALL(obj, myMethod(...)) - // will match obj.gmock_myMethod(...) call generated by the macro + // or + // ON_CALL(obj, myMethod(...)) + // will match obj.gmock_myMethod(...) call generated by the macros // (but only if it mocks a Blink method). auto gmock_member_matcher = id("expr", memberExpr(hasDeclaration( @@ -1791,13 +1913,32 @@ int main(int argc, const char* argv[]) { return result; // Supplemental data for the Blink rename rebase helper. - // TODO(dcheng): There's a lot of match rewriters missing from this list. + std::vector<const EditTracker*> all_edit_trackers{ + field_decl_rewriter.edit_tracker(), + var_decl_rewriter.edit_tracker(), + enum_member_decl_rewriter.edit_tracker(), + member_rewriter.edit_tracker(), + decl_ref_rewriter.edit_tracker(), + enum_member_ref_rewriter.edit_tracker(), + member_ref_rewriter.edit_tracker(), + function_decl_rewriter.edit_tracker(), + function_ref_rewriter.edit_tracker(), + method_decl_rewriter.edit_tracker(), + method_ref_rewriter.edit_tracker(), + method_member_rewriter.edit_tracker(), + constructor_initializer_rewriter.edit_tracker(), + unresolved_lookup_rewriter.edit_tracker(), + unresolved_member_rewriter.edit_tracker(), + unresolved_dependent_member_rewriter.edit_tracker(), + unresolved_using_value_decl_rewriter.edit_tracker(), + using_decl_rewriter.edit_tracker(), + dependent_scope_decl_ref_expr_rewriter.edit_tracker(), + cxx_dependent_scope_member_expr_rewriter.edit_tracker(), + gmock_member_rewriter.edit_tracker(), + }; llvm::outs() << "==== BEGIN TRACKED EDITS ====\n"; - field_decl_rewriter.edit_tracker().SerializeTo("var", llvm::outs()); - var_decl_rewriter.edit_tracker().SerializeTo("var", llvm::outs()); - enum_member_decl_rewriter.edit_tracker().SerializeTo("enu", llvm::outs()); - function_decl_rewriter.edit_tracker().SerializeTo("fun", llvm::outs()); - method_decl_rewriter.edit_tracker().SerializeTo("fun", llvm::outs()); + for (const EditTracker* edit_tracker : all_edit_trackers) + edit_tracker->SerializeTo(llvm::outs()); llvm::outs() << "==== END TRACKED EDITS ====\n"; // Serialization format is documented in tools/clang/scripts/run_tool.py diff --git a/chromium/tools/clang/scripts/blink_gc_plugin_flags.py b/chromium/tools/clang/scripts/blink_gc_plugin_flags.py deleted file mode 100755 index 0fce3b3558b..00000000000 --- a/chromium/tools/clang/scripts/blink_gc_plugin_flags.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python -# Copyright 2015 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# This script returns the flags that should be passed to clang. - -# TODO(sof): the script can be removed when/once gyp support is retired; -# unused with gn. - -import os -import sys - -THIS_DIR = os.path.abspath(os.path.dirname(__file__)) -SRC_DIR = os.path.join(THIS_DIR, '..', '..', '..') -CLANG_LIB_PATH = os.path.normpath(os.path.join( - SRC_DIR, 'third_party', 'llvm-build', 'Release+Asserts', 'lib')) - -FLAGS = '-Xclang -add-plugin -Xclang blink-gc-plugin' -PREFIX= ' -Xclang -plugin-arg-blink-gc-plugin -Xclang ' - -for arg in sys.argv[1:]: - if arg == 'dump-graph=1': - FLAGS += PREFIX + 'dump-graph' - elif arg == 'warn-unneeded-finalizer=1': - FLAGS += PREFIX + 'warn-unneeded-finalizer' - elif arg.startswith('custom_clang_lib_path='): - CLANG_LIB_PATH = arg[len('custom_clang_lib_path='):] - elif arg == 'target_os=ios': - sys.stderr.write('error: blink is unsupported on iOS\n') - sys.exit(1) - -if not sys.platform in ['win32', 'cygwin']: - LIBSUFFIX = 'dylib' if sys.platform == 'darwin' else 'so' - FLAGS = ('-Xclang -load -Xclang "%s/libBlinkGCPlugin.%s" ' + FLAGS) % \ - (CLANG_LIB_PATH, LIBSUFFIX) - -print FLAGS diff --git a/chromium/tools/clang/scripts/generate_win_compdb.py b/chromium/tools/clang/scripts/generate_win_compdb.py index a7a7ba647d8..6edd5938cb3 100755 --- a/chromium/tools/clang/scripts/generate_win_compdb.py +++ b/chromium/tools/clang/scripts/generate_win_compdb.py @@ -48,15 +48,6 @@ def _ProcessEntry(e): except IOError: pass - # TODO(dcheng): This should be implemented in Clang tooling. - # http://llvm.org/bugs/show_bug.cgi?id=19687 - # Finally, use slashes instead of backslashes to avoid bad escaping by the - # tooling. This should really only matter for command, but we do it for all - # keys for consistency. - e['directory'] = e['directory'].replace('\\', '/') - e['command'] = e['command'].replace('\\', '/') - e['file'] = e['file'].replace('\\', '/') - return e diff --git a/chromium/tools/clang/scripts/package.py b/chromium/tools/clang/scripts/package.py index 17181098f97..780bf5f1dab 100755 --- a/chromium/tools/clang/scripts/package.py +++ b/chromium/tools/clang/scripts/package.py @@ -87,7 +87,7 @@ def RunGsutil(args): def GsutilArchiveExists(archive_name, platform): gsutil_args = ['-q', 'stat', - 'gs://chromium-browser-clang/%s/%s.tgz' % + 'gs://chromium-browser-clang-staging/%s/%s.tgz' % (platform, archive_name)] return RunGsutil(gsutil_args) == 0 @@ -97,7 +97,7 @@ def MaybeUpload(args, archive_name, platform): # so -n option to gsutil is used. It will warn, if the upload was aborted. gsutil_args = ['cp', '-n', '-a', 'public-read', '%s.tgz' % archive_name, - 'gs://chromium-browser-clang/%s/%s.tgz' % + 'gs://chromium-browser-clang-staging/%s/%s.tgz' % (platform, archive_name)] if args.upload: print 'Uploading %s to Google Cloud Storage...' % archive_name @@ -141,9 +141,10 @@ def main(): GsutilArchiveExists(golddir, platform)): print ('Desired toolchain revision %s is already available ' 'in Google Cloud Storage:') % expected_stamp - print 'gs://chromium-browser-clang/%s/%s.tgz' % (platform, pdir) + print 'gs://chromium-browser-clang-staging/%s/%s.tgz' % (platform, pdir) if sys.platform.startswith('linux'): - print 'gs://chromium-browser-clang/%s/%s.tgz' % (platform, golddir) + print 'gs://chromium-browser-clang-staging/%s/%s.tgz' % (platform, + golddir) return 0 with open('buildlog.txt', 'w') as log: diff --git a/chromium/tools/clang/scripts/update.py b/chromium/tools/clang/scripts/update.py index dc7a439b298..2dfef6f4efd 100755 --- a/chromium/tools/clang/scripts/update.py +++ b/chromium/tools/clang/scripts/update.py @@ -27,14 +27,14 @@ import zipfile # Do NOT CHANGE this if you don't know what you're doing -- see # https://chromium.googlesource.com/chromium/src/+/master/docs/updating_clang.md # Reverting problematic clang rolls is safe, though. -CLANG_REVISION = '289944' +CLANG_REVISION = '296320' use_head_revision = 'LLVM_FORCE_HEAD_REVISION' in os.environ if use_head_revision: CLANG_REVISION = 'HEAD' # This is incremented when pushing a new build of Clang at the same revision. -CLANG_SUB_REVISION=2 +CLANG_SUB_REVISION=1 PACKAGE_VERSION = "%s-%s" % (CLANG_REVISION, CLANG_SUB_REVISION) @@ -71,7 +71,7 @@ BINUTILS_BIN_DIR = os.path.join(BINUTILS_DIR, BINUTILS_DIR, 'Linux_x64', 'Release', 'bin') BFD_PLUGINS_DIR = os.path.join(BINUTILS_DIR, 'Linux_x64', 'Release', 'lib', 'bfd-plugins') -VERSION = '4.0.0' +VERSION = '5.0.0' ANDROID_NDK_DIR = os.path.join( CHROMIUM_DIR, 'third_party', 'android_tools', 'ndk') @@ -336,7 +336,7 @@ def AddGnuWinToPath(): return gnuwin_dir = os.path.join(LLVM_BUILD_TOOLS_DIR, 'gnuwin') - GNUWIN_VERSION = '5' + GNUWIN_VERSION = '6' GNUWIN_STAMP = os.path.join(gnuwin_dir, 'stamp') if ReadStampFile(GNUWIN_STAMP) == GNUWIN_VERSION: print 'GNU Win tools already up to date.' @@ -862,29 +862,11 @@ def main(): args.lto_gold_plugin = False if args.if_needed: - is_clang_required = False - # clang is always used on Mac and Linux. - if sys.platform == 'darwin' or sys.platform.startswith('linux'): - is_clang_required = True - # clang requested via $GYP_DEFINES. - if re.search(r'\b(clang|asan|lsan|msan|tsan)=1', - os.environ.get('GYP_DEFINES', '')): - is_clang_required = True - # clang previously downloaded, keep it up to date. - # If you don't want this, delete third_party/llvm-build on your machine. - if os.path.isdir(LLVM_BUILD_DIR): - is_clang_required = True - if not is_clang_required: - return 0 + # TODO(thakis): Can probably remove this and --if-needed altogether. if re.search(r'\b(make_clang_dir)=', os.environ.get('GYP_DEFINES', '')): print 'Skipping Clang update (make_clang_dir= was set in GYP_DEFINES).' return 0 - if use_head_revision: - # TODO(hans): Trunk was updated; remove after the next roll. - global VERSION - VERSION = '5.0.0' - global CLANG_REVISION, PACKAGE_VERSION if args.print_revision: if use_head_revision or args.llvm_force_head_revision: diff --git a/chromium/tools/clang/value_cleanup/ListValueRewriter.cpp b/chromium/tools/clang/value_cleanup/ListValueRewriter.cpp index f32f818d85c..85b1d28b8e0 100644 --- a/chromium/tools/clang/value_cleanup/ListValueRewriter.cpp +++ b/chromium/tools/clang/value_cleanup/ListValueRewriter.cpp @@ -351,25 +351,25 @@ void ListValueRewriter::RegisterMatchers(MatchFinder* match_finder) { callee(cxxMethodDecl(hasName("::base::ListValue::Append"))), argumentCountIs(1)); - // base::ListValue::Append(new base::FundamentalValue(bool)) + // base::ListValue::Append(new base::Value(bool)) // => base::ListValue::AppendBoolean() match_finder->addMatcher( id("callExpr", cxxMemberCallExpr( is_list_append, hasArgument( - 0, ignoringParenImpCasts(id( - "newExpr", - cxxNewExpr(has(cxxConstructExpr( - hasDeclaration(cxxMethodDecl(hasName( - "::base::FundamentalValue::FundamentalValue"))), - argumentCountIs(1), - hasArgument( - 0, id("argExpr", - expr(hasType(booleanType())))))))))))), + 0, ignoringParenImpCasts( + id("newExpr", + cxxNewExpr(has(cxxConstructExpr( + hasDeclaration(cxxMethodDecl( + hasName("::base::Value::FundamentalValue"))), + argumentCountIs(1), + hasArgument( + 0, id("argExpr", + expr(hasType(booleanType())))))))))))), &append_boolean_callback_); - // base::ListValue::Append(new base::FundamentalValue(int)) + // base::ListValue::Append(new base::Value(int)) // => base::ListValue::AppendInteger() match_finder->addMatcher( id("callExpr", @@ -380,8 +380,8 @@ void ListValueRewriter::RegisterMatchers(MatchFinder* match_finder) { ignoringParenImpCasts(id( "newExpr", cxxNewExpr(has(cxxConstructExpr( - hasDeclaration(cxxMethodDecl(hasName( - "::base::FundamentalValue::FundamentalValue"))), + hasDeclaration(cxxMethodDecl( + hasName("::base::Value::FundamentalValue"))), argumentCountIs(1), hasArgument(0, id("argExpr", expr(hasType(isInteger()), @@ -389,7 +389,7 @@ void ListValueRewriter::RegisterMatchers(MatchFinder* match_finder) { booleanType()))))))))))))), &append_integer_callback_); - // base::ListValue::Append(new base::FundamentalValue(double)) + // base::ListValue::Append(new base::Value(double)) // => base::ListValue::AppendDouble() match_finder->addMatcher( id("callExpr", @@ -399,8 +399,8 @@ void ListValueRewriter::RegisterMatchers(MatchFinder* match_finder) { 0, ignoringParenImpCasts(id( "newExpr", cxxNewExpr(has(cxxConstructExpr( - hasDeclaration(cxxMethodDecl(hasName( - "::base::FundamentalValue::FundamentalValue"))), + hasDeclaration(cxxMethodDecl( + hasName("::base::Value::FundamentalValue"))), argumentCountIs(1), hasArgument( 0, id("argExpr", |