From 14dfa1b9eed07524b44b841bf1fe46f38b4ad271 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Mon, 4 May 2020 21:15:27 +0000 Subject: [PATCH] [vm] Fix gcc build. Change-Id: I6634dc10fdc8d7523562c0fcc20e3561eb580acf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/146023 Commit-Queue: Ryan Macnak Reviewed-by: Alexander Aprelev Reviewed-by: Alexander Markov Reviewed-by: Martin Kustermann --- build/config/compiler/BUILD.gn | 3 +++ runtime/bin/directory.cc | 2 +- runtime/platform/globals.h | 5 ++--- runtime/vm/class_id.h | 2 +- runtime/vm/clustered_snapshot.cc | 14 ++++++------- .../assembler/assembler_arm64_test.cc | 15 ++++++++----- runtime/vm/compiler/backend/il.h | 21 +++++++++++-------- .../compiler/ffi/native_calling_convention.cc | 1 + runtime/vm/compiler/ffi/native_location.cc | 2 ++ runtime/vm/compiler/ffi/native_type.cc | 6 ++++-- runtime/vm/compiler/runtime_api.cc | 2 +- runtime/vm/dart_api_impl_test.cc | 1 + runtime/vm/field_table.cc | 12 ++++++++--- runtime/vm/os_test.cc | 7 ------- runtime/vm/profiler.cc | 7 ++++--- runtime/vm/profiler_service.cc | 5 ++--- runtime/vm/snapshot.cc | 2 +- runtime/vm/uri.cc | 5 +---- runtime/vm/v8_snapshot_writer.cc | 2 +- 19 files changed, 62 insertions(+), 52 deletions(-) diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index 7548761294e..b5a49ba9f1a 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -538,6 +538,9 @@ if (is_win) { if (is_clang) { default_warning_flags += [ "-Wno-tautological-constant-compare" ] + } else { + default_warning_flags += + [ "-Wno-ignored-qualifiers" ] # Warnings in BoringSSL headers } if (is_mac) { diff --git a/runtime/bin/directory.cc b/runtime/bin/directory.cc index 6b3ce6653c4..cb6f8829054 100644 --- a/runtime/bin/directory.cc +++ b/runtime/bin/directory.cc @@ -453,7 +453,7 @@ bool AsyncDirectoryListing::AddFileSystemEntityToResponse(Response type, size_t len = strlen(arg); Dart_CObject* io_buffer = CObject::NewIOBuffer(len); uint8_t* data = io_buffer->value.as_external_typed_data.data; - strncpy(reinterpret_cast(data), arg, len); + memmove(reinterpret_cast(data), arg, len); CObjectExternalUint8Array* external_array = new CObjectExternalUint8Array(io_buffer); diff --git a/runtime/platform/globals.h b/runtime/platform/globals.h index e2a35ca79ab..ac995f4ea1c 100644 --- a/runtime/platform/globals.h +++ b/runtime/platform/globals.h @@ -613,9 +613,8 @@ static inline void USE(T) {} // type to another thus avoiding the warning. template inline D bit_cast(const S& source) { - // Compile time assertion: sizeof(D) == sizeof(S). A compile error - // here means your D and S have different sizes. - DART_UNUSED typedef char VerifySizesAreEqual[sizeof(D) == sizeof(S) ? 1 : -1]; + static_assert(sizeof(D) == sizeof(S), + "Source and destination must have the same size"); D destination; // This use of memcpy is safe: source and destination cannot overlap. diff --git a/runtime/vm/class_id.h b/runtime/vm/class_id.h index 4a79fa760bb..40f6897da79 100644 --- a/runtime/vm/class_id.h +++ b/runtime/vm/class_id.h @@ -178,7 +178,7 @@ namespace dart { V(Object) \ CLASS_LIST_NO_OBJECT(V) -enum ClassId { +enum ClassId : intptr_t { // Illegal class id. kIllegalCid = 0, diff --git a/runtime/vm/clustered_snapshot.cc b/runtime/vm/clustered_snapshot.cc index 5804c376409..16baa7a2f4e 100644 --- a/runtime/vm/clustered_snapshot.cc +++ b/runtime/vm/clustered_snapshot.cc @@ -121,11 +121,10 @@ void SerializationCluster::WriteAndMeasureAlloc(Serializer* serializer) { intptr_t stop_data = serializer->GetDataSize(); intptr_t stop_objects = serializer->next_ref_index(); if (FLAG_print_cluster_information) { - const int hex_size = kWordSize * 2; - OS::PrintErr("Snapshot 0x%0*.*" Px " (%" Pd "), ", hex_size, hex_size, - start_size, stop_size - start_size); - OS::PrintErr("Data 0x%0*.*" Px " (%" Pd "): ", hex_size, hex_size, - start_data, stop_data - start_data); + OS::PrintErr("Snapshot 0x%" Pp " (%" Pd "), ", start_size, + stop_size - start_size); + OS::PrintErr("Data 0x%" Pp " (%" Pd "): ", start_data, + stop_data - start_data); OS::PrintErr("Alloc %s (%" Pd ")\n", name(), stop_objects - start_objects); } size_ += (stop_size - start_size) + (stop_data - start_data); @@ -137,9 +136,8 @@ void SerializationCluster::WriteAndMeasureFill(Serializer* serializer) { WriteFill(serializer); intptr_t stop = serializer->bytes_written(); if (FLAG_print_cluster_information) { - const int hex_size = kWordSize * 2; - OS::PrintErr("Snapshot 0x%0*.*" Px " (%" Pd "): Fill %s\n", hex_size, - hex_size, start, stop - start, name()); + OS::PrintErr("Snapshot 0x%" Pp " (%" Pd "): Fill %s\n", start, stop - start, + name()); } size_ += (stop - start); } diff --git a/runtime/vm/compiler/assembler/assembler_arm64_test.cc b/runtime/vm/compiler/assembler/assembler_arm64_test.cc index e9fc68ca49f..e133f9f095d 100644 --- a/runtime/vm/compiler/assembler/assembler_arm64_test.cc +++ b/runtime/vm/compiler/assembler/assembler_arm64_test.cc @@ -2551,7 +2551,8 @@ ASSEMBLER_TEST_GENERATE(LoadObjectNull, assembler) { } ASSEMBLER_TEST_RUN(LoadObjectNull, test) { - EXPECT_EQ(Object::null(), test->InvokeWithCodeAndThread()); + EXPECT_EQ(static_cast(Object::null()), + test->InvokeWithCodeAndThread()); } // PushObject null. @@ -2566,7 +2567,8 @@ ASSEMBLER_TEST_GENERATE(PushObjectNull, assembler) { } ASSEMBLER_TEST_RUN(PushObjectNull, test) { - EXPECT_EQ(Object::null(), test->InvokeWithCodeAndThread()); + EXPECT_EQ(static_cast(Object::null()), + test->InvokeWithCodeAndThread()); } // CompareObject null. @@ -2584,7 +2586,8 @@ ASSEMBLER_TEST_GENERATE(CompareObjectNull, assembler) { } ASSEMBLER_TEST_RUN(CompareObjectNull, test) { - EXPECT_EQ(Bool::True().raw(), test->InvokeWithCodeAndThread()); + EXPECT_EQ(static_cast(Bool::True().raw()), + test->InvokeWithCodeAndThread()); } ASSEMBLER_TEST_GENERATE(LoadObjectTrue, assembler) { @@ -2597,7 +2600,8 @@ ASSEMBLER_TEST_GENERATE(LoadObjectTrue, assembler) { } ASSEMBLER_TEST_RUN(LoadObjectTrue, test) { - EXPECT_EQ(Bool::True().raw(), test->InvokeWithCodeAndThread()); + EXPECT_EQ(static_cast(Bool::True().raw()), + test->InvokeWithCodeAndThread()); } ASSEMBLER_TEST_GENERATE(LoadObjectFalse, assembler) { @@ -2610,7 +2614,8 @@ ASSEMBLER_TEST_GENERATE(LoadObjectFalse, assembler) { } ASSEMBLER_TEST_RUN(LoadObjectFalse, test) { - EXPECT_EQ(Bool::False().raw(), test->InvokeWithCodeAndThread()); + EXPECT_EQ(static_cast(Bool::False().raw()), + test->InvokeWithCodeAndThread()); } ASSEMBLER_TEST_GENERATE(CSelTrue, assembler) { diff --git a/runtime/vm/compiler/backend/il.h b/runtime/vm/compiler/backend/il.h index 4612792a37e..63a8bf0679b 100644 --- a/runtime/vm/compiler/backend/il.h +++ b/runtime/vm/compiler/backend/il.h @@ -3726,15 +3726,7 @@ class TemplateDartCall : public Definition { } } - StringPtr Selector() { - if (auto static_call = this->AsStaticCall()) { - return static_call->function().name(); - } else if (auto instance_call = this->AsInstanceCall()) { - return instance_call->function_name().raw(); - } else { - UNREACHABLE(); - } - } + inline StringPtr Selector(); virtual bool MayThrow() const { return true; } virtual bool CanCallDart() const { return true; } @@ -9196,6 +9188,17 @@ class FlowGraphVisitor : public ValueObject { } \ void Name::EmitNativeCode(FlowGraphCompiler* compiler) { UNIMPLEMENTED(); } +template +StringPtr TemplateDartCall::Selector() { + if (auto static_call = this->AsStaticCall()) { + return static_call->function().name(); + } else if (auto instance_call = this->AsInstanceCall()) { + return instance_call->function_name().raw(); + } else { + UNREACHABLE(); + } +} + } // namespace dart #endif // RUNTIME_VM_COMPILER_BACKEND_IL_H_ diff --git a/runtime/vm/compiler/ffi/native_calling_convention.cc b/runtime/vm/compiler/ffi/native_calling_convention.cc index fa6f4eb98c0..56e4690e77e 100644 --- a/runtime/vm/compiler/ffi/native_calling_convention.cc +++ b/runtime/vm/compiler/ffi/native_calling_convention.cc @@ -131,6 +131,7 @@ class ArgumentAllocator : public ValueObject { } Register AllocateCpuRegister() { + RELEASE_ASSERT(cpu_regs_used >= 0); // Avoids -Werror=array-bounds in GCC. ASSERT(cpu_regs_used < CallingConventions::kNumArgRegs); const auto result = CallingConventions::ArgumentRegisters[cpu_regs_used]; diff --git a/runtime/vm/compiler/ffi/native_location.cc b/runtime/vm/compiler/ffi/native_location.cc index 27c0388da53..0c7fb1687d4 100644 --- a/runtime/vm/compiler/ffi/native_location.cc +++ b/runtime/vm/compiler/ffi/native_location.cc @@ -305,6 +305,7 @@ DRegister NativeFpuRegistersLocation::fpu_as_d_reg() const { case kSingleFpuReg: return DRegisterOf(fpu_s_reg()); } + UNREACHABLE(); } SRegister NativeFpuRegistersLocation::fpu_as_s_reg() const { @@ -316,6 +317,7 @@ SRegister NativeFpuRegistersLocation::fpu_as_s_reg() const { case kSingleFpuReg: return fpu_s_reg(); } + UNREACHABLE(); } bool NativeFpuRegistersLocation::IsLowestBits() const { diff --git a/runtime/vm/compiler/ffi/native_type.cc b/runtime/vm/compiler/ffi/native_type.cc index adcc57ab5b1..d06d73f929e 100644 --- a/runtime/vm/compiler/ffi/native_type.cc +++ b/runtime/vm/compiler/ffi/native_type.cc @@ -103,8 +103,9 @@ intptr_t NativeFundamentalType::AlignmentInBytesStack() const { case kAlignedToValueSize: // iOS on arm64 only aligns to size. return SizeInBytes(); + default: + UNREACHABLE(); } - UNREACHABLE(); } intptr_t NativeFundamentalType::AlignmentInBytesField() const { @@ -120,8 +121,9 @@ intptr_t NativeFundamentalType::AlignmentInBytesField() const { } return SizeInBytes(); } + default: + UNREACHABLE(); } - UNREACHABLE(); } #if !defined(DART_PRECOMPILED_RUNTIME) diff --git a/runtime/vm/compiler/runtime_api.cc b/runtime/vm/compiler/runtime_api.cc index 7c9f60aa25c..ca41bd534e5 100644 --- a/runtime/vm/compiler/runtime_api.cc +++ b/runtime/vm/compiler/runtime_api.cc @@ -375,7 +375,7 @@ static uword GetInstanceSizeImpl(const dart::Class& handle) { } } FATAL3("Unsupported class for size translation: %s (id=%" Pd - ", kNumPredefinedCids=%d)\n", + ", kNumPredefinedCids=%" Pd ")\n", handle.ToCString(), handle.id(), kNumPredefinedCids); return -1; } diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index 6106c7c1c36..4f1551d22b1 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -3373,6 +3373,7 @@ TEST_CASE(DartAPI_WeakPersistentHandleExternalAllocationSize) { weak2 = Dart_NewWeakPersistentHandle(obj, NULL, kWeak2ExternalSize, NopCallback); EXPECT_VALID(AsHandle(strong_ref)); + EXPECT_VALID(AsHandle(weak2)); Dart_ExitScope(); } { diff --git a/runtime/vm/field_table.cc b/runtime/vm/field_table.cc index 8ff6f034afe..495d7a0a0ad 100644 --- a/runtime/vm/field_table.cc +++ b/runtime/vm/field_table.cc @@ -82,12 +82,18 @@ void FieldTable::AllocateIndex(intptr_t index) { void FieldTable::Grow(intptr_t new_capacity) { ASSERT(new_capacity > capacity_); + auto old_table = table_; auto new_table = static_cast( malloc(new_capacity * sizeof(InstancePtr))); // NOLINT - memmove(new_table, table_, top_ * sizeof(InstancePtr)); - memset(new_table + top_, 0, (new_capacity - top_) * sizeof(InstancePtr)); + intptr_t i; + for (i = 0; i < top_; i++) { + new_table[i] = old_table[i]; + } + for (; i < new_capacity; i++) { + new_table[i] = InstancePtr(); + } capacity_ = new_capacity; - old_tables_->Add(table_); + old_tables_->Add(old_table); // Ensure that new_table_ is populated before it is published // via store to table_. std::atomic_thread_fence(std::memory_order_release); diff --git a/runtime/vm/os_test.cc b/runtime/vm/os_test.cc index 331b3d2a823..d1b7791c414 100644 --- a/runtime/vm/os_test.cc +++ b/runtime/vm/os_test.cc @@ -26,13 +26,6 @@ VM_UNIT_TEST_CASE(SNPrint) { EXPECT_EQ(3, length); } -// This test is expected to crash when it runs. -VM_UNIT_TEST_CASE_WITH_EXPECTATION(SNPrint_BadArgs, "Crash") { - int width = kMaxInt32; - int num = 7; - Utils::SNPrint(NULL, 0, "%*d%*d", width, num, width, num); -} - VM_UNIT_TEST_CASE(OsFuncs) { EXPECT(Utils::IsPowerOfTwo(OS::ActivationFrameAlignment())); int procs = OS::NumberOfAvailableProcessors(); diff --git a/runtime/vm/profiler.cc b/runtime/vm/profiler.cc index 43cd2d0d6cc..f4741fdf27b 100644 --- a/runtime/vm/profiler.cc +++ b/runtime/vm/profiler.cc @@ -1132,12 +1132,13 @@ void Profiler::DumpStackTrace(uword sp, uword fp, uword pc, bool for_crash) { } } + OS::PrintErr("version=%s\n", Version::String()); OSThread* os_thread = OSThread::Current(); ASSERT(os_thread != NULL); Isolate* isolate = Isolate::Current(); - const char* name = isolate == NULL ? NULL : isolate->name(); - OS::PrintErr("version=%s\npid=%" Pd ", thread=%" Pd ", isolate=%s(%p)\n", - Version::String(), OS::ProcessId(), + const char* name = isolate == NULL ? "(nil)" : isolate->name(); + OS::PrintErr("pid=%" Pd ", thread=%" Pd ", isolate=%s(%p)\n", + static_cast(OS::ProcessId()), OSThread::ThreadIdToIntPtr(os_thread->trace_id()), name, isolate); const IsolateGroupSource* source = diff --git a/runtime/vm/profiler_service.cc b/runtime/vm/profiler_service.cc index 7fe9b39ec5e..3c910490701 100644 --- a/runtime/vm/profiler_service.cc +++ b/runtime/vm/profiler_service.cc @@ -345,10 +345,9 @@ void ProfileCode::SetName(const char* name) { if (name == NULL) { name_ = NULL; } - intptr_t len = strlen(name); - name_ = Thread::Current()->zone()->Alloc(len + 1); + intptr_t len = strlen(name) + 1; + name_ = Thread::Current()->zone()->Alloc(len); strncpy(name_, name, len); - name_[len] = '\0'; } void ProfileCode::GenerateAndSetSymbolName(const char* prefix) { diff --git a/runtime/vm/snapshot.cc b/runtime/vm/snapshot.cc index 7f100bb0f0f..08196405f9f 100644 --- a/runtime/vm/snapshot.cc +++ b/runtime/vm/snapshot.cc @@ -259,7 +259,7 @@ const Snapshot* Snapshot::SetupFromBuffer(const void* raw_memory) { } SmiPtr BaseReader::ReadAsSmi() { - SmiPtr value = Read(); + SmiPtr value = static_cast(Read()); ASSERT((static_cast(value) & kSmiTagMask) == kSmiTag); return value; } diff --git a/runtime/vm/uri.cc b/runtime/vm/uri.cc index 5e75ef185a4..74046e94e60 100644 --- a/runtime/vm/uri.cc +++ b/runtime/vm/uri.cc @@ -369,10 +369,7 @@ static const char* MergePaths(const char* base_path, const char* ref_path) { buffer[truncated_base_len] = '/'; // Copy the ref_path. - strncpy((buffer + truncated_base_len + 1), ref_path, ref_path_len); - - // Add the trailing '\0'. - buffer[len] = '\0'; + strncpy((buffer + truncated_base_len + 1), ref_path, ref_path_len + 1); return buffer; } diff --git a/runtime/vm/v8_snapshot_writer.cc b/runtime/vm/v8_snapshot_writer.cc index 1a79e0cb344..7d22307a518 100644 --- a/runtime/vm/v8_snapshot_writer.cc +++ b/runtime/vm/v8_snapshot_writer.cc @@ -53,7 +53,7 @@ void V8SnapshotProfileWriter::SetObjectTypeAndName(ObjectId object_id, info->name = EnsureString(name); } else { info->name = - EnsureString(OS::SCreate(zone_, "Unnamed [%s] %s", type, name)); + EnsureString(OS::SCreate(zone_, "Unnamed [%s] %s", type, "(nil)")); } }