Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions flow/layers/child_scene_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions fml/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion fml/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ LogMessage::~LogMessage() {
#endif

if (severity_ >= LOG_FATAL) {
abort();
KillProcess();
}
}

Expand All @@ -105,4 +105,8 @@ bool ShouldCreateLogMessage(LogSeverity severity) {
return severity >= GetMinLogLevel();
}

void KillProcess() {
abort();
}

} // namespace fml
11 changes: 7 additions & 4 deletions fml/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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_
32 changes: 32 additions & 0 deletions fml/logging_unittests.cc
Original file line number Diff line number Diff line change
@@ -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