From 30897929fc012602dc540a87fa1cb9b5e7db368d Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Mon, 21 Sep 2020 22:02:32 +0000 Subject: [PATCH] [vm] Fix warnings in GCC 9.3.0 and XCode 12.0. Bug: https://github.com/flutter/flutter/issues/66203 Change-Id: Ifff0c211e2ecdcb56d62c273a471fc05bbae9c37 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161602 Reviewed-by: Chinmay Garde Reviewed-by: Alexander Aprelev Commit-Queue: Ryan Macnak --- runtime/bin/main_options.cc | 5 +++-- runtime/bin/main_options.h | 6 +++--- runtime/include/dart_api_dl.c | 2 +- runtime/vm/clustered_snapshot.cc | 6 +++--- .../frontend/kernel_translation_helper.cc | 14 ++++++------- runtime/vm/compiler/frontend/scope_builder.cc | 4 ++-- runtime/vm/dart_api_impl_test.cc | 20 +++++-------------- runtime/vm/heap/scavenger.cc | 3 ++- runtime/vm/image_snapshot.cc | 2 +- runtime/vm/kernel_isolate.cc | 6 ------ runtime/vm/object.h | 4 ++-- 11 files changed, 29 insertions(+), 43 deletions(-) diff --git a/runtime/bin/main_options.cc b/runtime/bin/main_options.cc index 7c54268b919..1d2f619dcb1 100644 --- a/runtime/bin/main_options.cc +++ b/runtime/bin/main_options.cc @@ -487,7 +487,6 @@ int Options::ParseArguments(int argc, bool implicitly_use_dart_dev = false; bool run_script = false; - int script_or_cmd_index = -1; // Get the script name. if (i < argc) { @@ -500,7 +499,6 @@ int Options::ParseArguments(int argc, #else bool is_potential_file_path = true; #endif // !defined(DART_PRECOMPILED_RUNTIME) - script_or_cmd_index = i; if (Options::disable_dart_dev() || (is_potential_file_path && !enable_vm_service_)) { *script_name = Utils::StrDup(argv[i]); @@ -549,6 +547,9 @@ int Options::ParseArguments(int argc, else { // NOLINT return -1; } + USE(enable_dartdev_analytics); + USE(disable_dartdev_analytics); + const char** vm_argv = temp_vm_options.arguments(); int vm_argc = temp_vm_options.count(); diff --git a/runtime/bin/main_options.h b/runtime/bin/main_options.h index 48553df129c..6f612fd46ae 100644 --- a/runtime/bin/main_options.h +++ b/runtime/bin/main_options.h @@ -79,9 +79,9 @@ enum SnapshotKind { kAppJIT, }; -static const char* DEFAULT_VM_SERVICE_SERVER_IP = "localhost"; -static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; -static const int INVALID_VM_SERVICE_SERVER_PORT = -1; +static constexpr const char* DEFAULT_VM_SERVICE_SERVER_IP = "localhost"; +static constexpr int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; +static constexpr int INVALID_VM_SERVICE_SERVER_PORT = -1; class Options { public: diff --git a/runtime/include/dart_api_dl.c b/runtime/include/dart_api_dl.c index 7709a0253b1..1a49c9c3b3a 100644 --- a/runtime/include/dart_api_dl.c +++ b/runtime/include/dart_api_dl.c @@ -16,7 +16,7 @@ DART_API_ALL_DL_SYMBOLS(DART_API_DL_DEFINITIONS) #undef DART_API_DL_DEFINITIONS -typedef void (*DartApiEntry_function)(); +typedef void* DartApiEntry_function; DartApiEntry_function FindFunctionPointer(const DartApiEntry* entries, const char* name) { diff --git a/runtime/vm/clustered_snapshot.cc b/runtime/vm/clustered_snapshot.cc index 72c121023cc..1918244efa9 100644 --- a/runtime/vm/clustered_snapshot.cc +++ b/runtime/vm/clustered_snapshot.cc @@ -2206,14 +2206,14 @@ class WeakSerializationReferenceSerializationCluster s->WriteUnsigned(WrittenCount()); // Set up references for those objects that will be written. - for (auto const ref : canonical_wsrs_) { + for (auto const& ref : canonical_wsrs_) { s->AssignRef(ref); } // In precompiled mode, set the object ID of each non-canonical WSR to // its canonical counterpart's object ID. This ensures that any reference to // it is serialized as a reference to the canonicalized one. - for (auto const ref : objects_) { + for (auto const& ref : objects_) { ASSERT(IsReachableReference(heap_->GetObjectId(ref))); if (ShouldDrop(ref)) { // For dropped references, reset their ID to be the unreachable @@ -2238,7 +2238,7 @@ class WeakSerializationReferenceSerializationCluster void WriteFill(Serializer* s) { ASSERT(s->kind() == Snapshot::kFullAOT); - for (auto const ref : canonical_wsrs_) { + for (auto const& ref : canonical_wsrs_) { AutoTraceObject(ref); // In precompiled mode, we drop the reference to the target and only diff --git a/runtime/vm/compiler/frontend/kernel_translation_helper.cc b/runtime/vm/compiler/frontend/kernel_translation_helper.cc index 3c2b977d05a..da6287320ef 100644 --- a/runtime/vm/compiler/frontend/kernel_translation_helper.cc +++ b/runtime/vm/compiler/frontend/kernel_translation_helper.cc @@ -1826,13 +1826,13 @@ void LoadingUnitsMetadataHelper::ReadMetadata(intptr_t node_offset) { AlternativeReadingScopeWithNewData alt(&helper_->reader_, &H.metadata_payloads(), md_offset); - Thread* T = Thread::Current(); - Zone* Z = T->zone(); + Thread* thread = Thread::Current(); + Zone* zone = thread->zone(); intptr_t unit_count = helper_->ReadUInt(); - Array& loading_units = Array::Handle(Z, Array::New(unit_count + 1)); - LoadingUnit& unit = LoadingUnit::Handle(Z); - LoadingUnit& parent = LoadingUnit::Handle(Z); - Library& lib = Library::Handle(Z); + Array& loading_units = Array::Handle(zone, Array::New(unit_count + 1)); + LoadingUnit& unit = LoadingUnit::Handle(zone); + LoadingUnit& parent = LoadingUnit::Handle(zone); + Library& lib = Library::Handle(zone); for (int i = 0; i < unit_count; i++) { intptr_t id = helper_->ReadUInt(); @@ -1849,7 +1849,7 @@ void LoadingUnitsMetadataHelper::ReadMetadata(intptr_t node_offset) { for (intptr_t j = 0; j < library_count; j++) { const String& uri = translation_helper_.DartSymbolPlain(helper_->ReadStringReference()); - lib = Library::LookupLibrary(T, uri); + lib = Library::LookupLibrary(thread, uri); if (lib.IsNull()) { FATAL1("Missing library: %s\n", uri.ToCString()); } diff --git a/runtime/vm/compiler/frontend/scope_builder.cc b/runtime/vm/compiler/frontend/scope_builder.cc index f28890bfb85..bb55bba4ef0 100644 --- a/runtime/vm/compiler/frontend/scope_builder.cc +++ b/runtime/vm/compiler/frontend/scope_builder.cc @@ -148,8 +148,8 @@ ScopeBuildingResult* ScopeBuilder::BuildScopes() { (parent.num_fixed_parameters() != target.num_fixed_parameters())) { needs_expr_temp_ = true; } - FALL_THROUGH; } + FALL_THROUGH; case FunctionLayout::kClosureFunction: case FunctionLayout::kRegularFunction: case FunctionLayout::kGetterFunction: @@ -442,8 +442,8 @@ ScopeBuildingResult* ScopeBuilder::BuildScopes() { FOR_EACH_DYNAMIC_CLOSURE_CALL_VARIABLE(ADD_VAR); #undef ADD_VAR } - FALL_THROUGH; } + FALL_THROUGH; case FunctionLayout::kNoSuchMethodDispatcher: { for (intptr_t i = 0; i < function.NumParameters(); ++i) { LocalVariable* variable = MakeVariable( diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index 8c96d22f428..0046562f330 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -3528,14 +3528,12 @@ static void FinalizableHandlePeerFinalizer(void* isolate_callback_data, } TEST_CASE(DartAPI_FinalizableHandleCallback) { - Dart_FinalizableHandle weak_ref = nullptr; int peer = 0; { Dart_EnterScope(); Dart_Handle obj = NewString("new string"); EXPECT_VALID(obj); - weak_ref = Dart_NewFinalizableHandle(obj, &peer, 0, - FinalizableHandlePeerFinalizer); + Dart_NewFinalizableHandle(obj, &peer, 0, FinalizableHandlePeerFinalizer); EXPECT(peer == 0); Dart_ExitScope(); } @@ -3676,26 +3674,22 @@ TEST_CASE(DartAPI_FinalizableHandleExternalAllocationSize) { Heap* heap = Isolate::Current()->heap(); EXPECT(heap->ExternalInWords(Heap::kNew) == 0); EXPECT(heap->ExternalInWords(Heap::kOld) == 0); - Dart_FinalizableHandle weak1 = nullptr; static const intptr_t kWeak1ExternalSize = 1 * KB; { Dart_EnterScope(); Dart_Handle obj = NewString("weakly referenced string"); EXPECT_VALID(obj); - weak1 = Dart_NewFinalizableHandle(obj, nullptr, kWeak1ExternalSize, - NopCallback); + Dart_NewFinalizableHandle(obj, nullptr, kWeak1ExternalSize, NopCallback); Dart_ExitScope(); } Dart_PersistentHandle strong_ref = nullptr; - Dart_FinalizableHandle weak2 = nullptr; static const intptr_t kWeak2ExternalSize = 2 * KB; { Dart_EnterScope(); Dart_Handle obj = NewString("strongly referenced string"); EXPECT_VALID(obj); strong_ref = Dart_NewPersistentHandle(obj); - weak2 = Dart_NewFinalizableHandle(obj, nullptr, kWeak2ExternalSize, - NopCallback); + Dart_NewFinalizableHandle(obj, nullptr, kWeak2ExternalSize, NopCallback); EXPECT_VALID(AsHandle(strong_ref)); Dart_ExitScope(); } @@ -3810,7 +3804,6 @@ TEST_CASE(DartAPI_WeakPersistentHandleExternalAllocationSizeOldspaceGC) { Dart_Handle live = AllocateOldString("live"); EXPECT_VALID(live); Dart_WeakPersistentHandle weak = NULL; - Dart_WeakPersistentHandle weak2 = NULL; { TransitionNativeToVM transition(thread); GCTestHelper::WaitForGCTasks(); // Finalize GC for accurate live size. @@ -3834,8 +3827,7 @@ TEST_CASE(DartAPI_WeakPersistentHandleExternalAllocationSizeOldspaceGC) { } // Large enough to trigger GC in old space. Not actually allocated. const intptr_t kHugeExternalSize = (kWordSize == 4) ? 513 * MB : 1025 * MB; - weak2 = - Dart_NewWeakPersistentHandle(live, NULL, kHugeExternalSize, NopCallback); + Dart_NewWeakPersistentHandle(live, NULL, kHugeExternalSize, NopCallback); { TransitionNativeToVM transition(thread); GCTestHelper::WaitForGCTasks(); // Finalize GC for accurate live size. @@ -3852,7 +3844,6 @@ TEST_CASE(DartAPI_FinalizableHandleExternalAllocationSizeOldspaceGC) { Dart_EnterScope(); Dart_Handle live = AllocateOldString("live"); EXPECT_VALID(live); - Dart_FinalizableHandle weak = NULL; { TransitionNativeToVM transition(thread); GCTestHelper::WaitForGCTasks(); // Finalize GC for accurate live size. @@ -3863,8 +3854,7 @@ TEST_CASE(DartAPI_FinalizableHandleExternalAllocationSizeOldspaceGC) { Dart_EnterScope(); Dart_Handle dead = AllocateOldString("dead"); EXPECT_VALID(dead); - weak = Dart_NewFinalizableHandle(dead, nullptr, kSmallExternalSize, - NopCallback); + Dart_NewFinalizableHandle(dead, nullptr, kSmallExternalSize, NopCallback); Dart_ExitScope(); } { diff --git a/runtime/vm/heap/scavenger.cc b/runtime/vm/heap/scavenger.cc index cfed7d759a7..41f1f99f423 100644 --- a/runtime/vm/heap/scavenger.cc +++ b/runtime/vm/heap/scavenger.cc @@ -50,7 +50,8 @@ enum { // If the forwarded bit and pointer tag bit are the same, we can avoid a few // conversions. -COMPILE_ASSERT(kForwarded == kHeapObjectTag); +COMPILE_ASSERT(static_cast(kForwarded) == + static_cast(kHeapObjectTag)); static inline bool IsForwarding(uword header) { uword bits = header & kForwardingMask; diff --git a/runtime/vm/image_snapshot.cc b/runtime/vm/image_snapshot.cc index 7c8ba6a8753..3d52db564e0 100644 --- a/runtime/vm/image_snapshot.cc +++ b/runtime/vm/image_snapshot.cc @@ -259,7 +259,7 @@ void ImageWriter::GetTrampolineInfo(intptr_t* count, intptr_t* size) const { ASSERT(count != nullptr && size != nullptr); *count = 0; *size = 0; - for (auto const data : instructions_) { + for (auto const& data : instructions_) { if (data.trampoline_length != 0) { *count += 1; *size += data.trampoline_length; diff --git a/runtime/vm/kernel_isolate.cc b/runtime/vm/kernel_isolate.cc index 8fdc9d0b411..d2cdbb569d0 100644 --- a/runtime/vm/kernel_isolate.cc +++ b/runtime/vm/kernel_isolate.cc @@ -1055,17 +1055,11 @@ bool KernelIsolate::DetectNullSafety(const char* script_uri, const char* original_working_directory) { // Start the kernel Isolate if it is not already running. if (!Start()) { - Dart_KernelCompilationResult result = {}; - result.status = Dart_KernelCompilationStatus_Unknown; - result.error = Utils::StrDup("Error while starting Kernel isolate task"); return false; } // Wait for Kernel isolate to finish initialization. Dart_Port kernel_port = WaitForKernelPort(); if (kernel_port == ILLEGAL_PORT) { - Dart_KernelCompilationResult result = {}; - result.status = Dart_KernelCompilationStatus_Unknown; - result.error = Utils::StrDup("Error while initializing Kernel isolate"); return false; } KernelCompilationRequest request; diff --git a/runtime/vm/object.h b/runtime/vm/object.h index b14b8e9030d..22e28100afd 100644 --- a/runtime/vm/object.h +++ b/runtime/vm/object.h @@ -4923,8 +4923,8 @@ class Library : public Object { intptr_t index() const { return raw_ptr()->index_; } void set_index(intptr_t value) const { - ASSERT(value == -1 || - value >= 0 && value < std::numeric_limits::max()); + ASSERT((value == -1) || + ((value >= 0) && (value < std::numeric_limits::max()))); StoreNonPointer(&raw_ptr()->index_, value); }