mirror of https://github.com/grpc/grpc.git
Add test and mitigation for clang 11 compiler bug (#27073)
* Add test and mitigation for clang 11 compiler bug * document * document * Automated change: Fix sanity tests Co-authored-by: ctiller <ctiller@users.noreply.github.com>pull/27123/head
parent
df3a13a2a3
commit
46afdf9989
6 changed files with 168 additions and 0 deletions
@ -0,0 +1,31 @@ |
||||
# Copyright 2021 gRPC authors. |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
load("//bazel:grpc_build_system.bzl", "grpc_cc_test", "grpc_package") |
||||
|
||||
licenses(["notice"]) |
||||
|
||||
grpc_package(name = "test/core/compiler_bugs") |
||||
|
||||
grpc_cc_test( |
||||
name = "miscompile_with_no_unique_address_test", |
||||
srcs = ["miscompile_with_no_unique_address_test.cc"], |
||||
external_deps = ["gtest"], |
||||
language = "c++", |
||||
uses_polling = False, |
||||
deps = [ |
||||
"//:gpr_platform", |
||||
"//test/core/util:grpc_suppressions", |
||||
], |
||||
) |
@ -0,0 +1,58 @@ |
||||
// Copyright 2021 gRPC authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <grpc/impl/codegen/port_platform.h> |
||||
#include <gtest/gtest.h> |
||||
|
||||
// Make a template argument to test which bit pattern remains in A's destructor
|
||||
// to try and detect similar bugs in non-MSAN builds (none have been detected
|
||||
// yet thankfully)
|
||||
template <int kInit> |
||||
class A { |
||||
public: |
||||
~A() { EXPECT_EQ(a_, kInit); } |
||||
int a_ = kInit; |
||||
}; |
||||
template <class T, int kInit> |
||||
class P : A<kInit> { |
||||
public: |
||||
explicit P(T b) : b_(b) {} |
||||
// clang 11 with MSAN miscompiles this and marks A::a_ as uninitialized during
|
||||
// P::~P() if GPR_NO_UNIQUE_ADDRESS is [[no_unique_address]] - so this test
|
||||
// stands to ensure that we have a working definition for this compiler so
|
||||
// that we don't flag false negatives elsewhere in the codebase.
|
||||
GPR_NO_UNIQUE_ADDRESS T b_; |
||||
}; |
||||
|
||||
template <int kInit, class T> |
||||
void c(T a) { |
||||
P<T, kInit> _(a); |
||||
} |
||||
|
||||
TEST(Miscompile, Zero) { |
||||
c<0>([] {}); |
||||
} |
||||
|
||||
TEST(Miscompile, One) { |
||||
c<1>([] {}); |
||||
} |
||||
|
||||
TEST(Miscompile, MinusOne) { |
||||
c<-1>([] {}); |
||||
} |
||||
|
||||
int main(int argc, char** argv) { |
||||
::testing::InitGoogleTest(&argc, argv); |
||||
return RUN_ALL_TESTS(); |
||||
} |
Loading…
Reference in new issue