protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Debug builds do not pass Clang's -Winvalid-noreturn warning

Open davidben opened this issue 3 years ago • 2 comments

What version of protobuf and what language are you using? Version: main Language: C++

What operating system (Linux, Windows, ...) and version? gLinux

What runtime / compiler are you using (e.g., python version or gcc version) Debian clang version 13.0.1-3

Also reproducible with Chromium's clang

What did you do? Steps to reproduce the behavior:

git clone https://github.com/protocolbuffers/protobuf.git
cd protobuf
git submodule update --init --recursive
./autogen.sh
./configure CXX=clang++ CXXFLAGS="-Werror -Winvalid-noreturn"
make -j20

What did you expect to see The build passes

What did you see instead? The build fails with:

In file included from google/protobuf/generated_message_tctable_lite.cc:36:
./google/protobuf/generated_message_tctable_impl.h:256:1: error: function declared 'noreturn' should not return [-Werror,-Winvalid-noreturn]
}
^
google/protobuf/generated_message_tctable_lite.cc:57:15: note: in instantiation of function template specialization 'google::protobuf::internal::AlignFail<4UL>' requested here
template void AlignFail<4>(uintptr_t);
              ^
In file included from google/protobuf/generated_message_tctable_lite.cc:36:
./google/protobuf/generated_message_tctable_impl.h:256:1: error: function declared 'noreturn' should not return [-Werror,-Winvalid-noreturn]
}
^
google/protobuf/generated_message_tctable_lite.cc:58:15: note: in instantiation of function template specialization 'google::protobuf::internal::AlignFail<8UL>' requested here
template void AlignFail<8>(uintptr_t);

The issue seems to be that AlignFail calls GOOGLE_LOG(FATAL), but GOOGLE_LOG(FATAL) is not obviously a [[noreturn]] function. The abort is deep inside LogFinisher::operator= -> LogMessage::Finish -> a check on level_. Instead, I think the macro needs to do the token concatenation trick so that it can call a different function marked [[noreturn]]. For instance, move the abort to LogFinisher::operator= and then use a different FatalLogFinisher type whose operator= is marked [[noreturn]].

Anything else we should know about your project / environment This impacts the update to Chromium's copy of protobuf, since this is one of the warnings we enable.

davidben avatar Apr 20 '22 21:04 davidben

This is still the case with 3.21.1 and bleeds outside of protobuf into consumer code, forcing people to disable the warning or add boilerplate code.

Curiously the one compiler that appears to be fine with this construct being noreturn is also the one compiler that does not get that function declared noreturn.

https://godbolt.org/z/13n59aM8s

Sil3ntStorm avatar Jul 22 '22 19:07 Sil3ntStorm

This has actually been fixed in main by #10188 Any hint on which protobuf release will actually contain the fix?

Sil3ntStorm avatar Jul 22 '22 19:07 Sil3ntStorm

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

github-actions[bot] avatar Jan 22 '24 10:01 github-actions[bot]

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

github-actions[bot] avatar Feb 06 '24 10:02 github-actions[bot]