diff --git a/flow/layers/child_scene_layer.cc b/flow/layers/child_scene_layer.cc index 9ba5eff3c5021..858328a140b22 100644 --- a/flow/layers/child_scene_layer.cc +++ b/flow/layers/child_scene_layer.cc @@ -22,9 +22,7 @@ void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { CheckForChildLayerBelow(context); } -void ChildSceneLayer::Paint(PaintContext& context) const { - FML_NOTREACHED(); -} +void ChildSceneLayer::Paint(PaintContext& context) const {} void ChildSceneLayer::UpdateScene(SceneUpdateContext& context) { TRACE_EVENT0("flutter", "ChildSceneLayer::UpdateScene"); diff --git a/fml/BUILD.gn b/fml/BUILD.gn index 198d61c52c610..cf6af4e68a2e2 100644 --- a/fml/BUILD.gn +++ b/fml/BUILD.gn @@ -249,6 +249,7 @@ if (enable_unittests) { "command_line_unittest.cc", "file_unittest.cc", "hash_combine_unittests.cc", + "logging_unittests.cc", "memory/ref_counted_unittest.cc", "memory/task_runner_checker_unittest.cc", "memory/weak_ptr_unittest.cc", diff --git a/fml/logging.cc b/fml/logging.cc index d4273b9381da7..6530348e0ccac 100644 --- a/fml/logging.cc +++ b/fml/logging.cc @@ -93,7 +93,7 @@ LogMessage::~LogMessage() { #endif if (severity_ >= LOG_FATAL) { - abort(); + KillProcess(); } } @@ -105,4 +105,8 @@ bool ShouldCreateLogMessage(LogSeverity severity) { return severity >= GetMinLogLevel(); } +void KillProcess() { + abort(); +} + } // namespace fml diff --git a/fml/logging.h b/fml/logging.h index 20cb887cb20df..0b732ee818a0a 100644 --- a/fml/logging.h +++ b/fml/logging.h @@ -43,6 +43,8 @@ int GetVlogVerbosity(); // LOG_FATAL and above is always true. bool ShouldCreateLogMessage(LogSeverity severity); +[[noreturn]] void KillProcess(); + } // namespace fml #define FML_LOG_STREAM(severity) \ @@ -87,9 +89,10 @@ bool ShouldCreateLogMessage(LogSeverity severity); #define FML_DCHECK(condition) FML_EAT_STREAM_PARAMETERS(condition) #endif -#define FML_NOTREACHED() FML_DCHECK(false) - -#define FML_NOTIMPLEMENTED() \ - FML_LOG(ERROR) << "Not implemented in: " << __PRETTY_FUNCTION__ +#define FML_UNREACHABLE() \ + { \ + FML_LOG(ERROR) << "Reached unreachable code."; \ + ::fml::KillProcess(); \ + } #endif // FLUTTER_FML_LOGGING_H_ diff --git a/fml/logging_unittests.cc b/fml/logging_unittests.cc new file mode 100644 index 0000000000000..88b2ebee806df --- /dev/null +++ b/fml/logging_unittests.cc @@ -0,0 +1,32 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/fml/logging.h" +#include "gtest/gtest.h" + +namespace fml { +namespace testing { + +int UnreachableScopeWithoutReturnDoesNotMakeCompilerMad() { + KillProcess(); + // return 0; <--- Missing but compiler is fine. +} + +int UnreachableScopeWithMacroWithoutReturnDoesNotMakeCompilerMad() { + FML_UNREACHABLE(); + // return 0; <--- Missing but compiler is fine. +} + +TEST(LoggingTest, UnreachableKillProcess) { + ::testing::FLAGS_gtest_death_test_style = "threadsafe"; + ASSERT_DEATH(KillProcess(), ""); +} + +TEST(LoggingTest, UnreachableKillProcessWithMacro) { + ::testing::FLAGS_gtest_death_test_style = "threadsafe"; + ASSERT_DEATH({ FML_UNREACHABLE(); }, ""); +} + +} // namespace testing +} // namespace fml