diff options
author | Reid Kleckner <rnk@google.com> | 2017-10-27 22:48:41 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2017-10-27 22:48:41 +0000 |
commit | 2e87a21c7cac8931593bc281acf5a15f7cf591a0 (patch) | |
tree | be7ba16dc4c9c5d325f7ca4ce2c624e858c462e8 /clang/test/CodeGenCXX/microsoft-inaccessible-base.cpp | |
parent | e58044d4324a3431be93685071643914baa886d6 (diff) | |
download | bcm5719-llvm-2e87a21c7cac8931593bc281acf5a15f7cf591a0.tar.gz bcm5719-llvm-2e87a21c7cac8931593bc281acf5a15f7cf591a0.zip |
[MS] Allow access to ambiguous, inaccessible direct bases
Summary:
Clang typically warns that in the following class hierarchy, 'A' is
inaccessible because there is no series of casts that the user can
write to access it unambiguously:
struct A { };
struct B : A { };
struct C : A, B { };
MSVC allows the user to convert from C* to A*, though, and we've
encountered this issue in the latest Windows SDK headers.
This patch allows this conversion when -fms-compatibility is set and
adds a warning for it under -Wmicrosoft-inaccessible-base.
Reviewers: rsmith
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D39389
llvm-svn: 316807
Diffstat (limited to 'clang/test/CodeGenCXX/microsoft-inaccessible-base.cpp')
-rw-r--r-- | clang/test/CodeGenCXX/microsoft-inaccessible-base.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/microsoft-inaccessible-base.cpp b/clang/test/CodeGenCXX/microsoft-inaccessible-base.cpp new file mode 100644 index 00000000000..2c0d124eb01 --- /dev/null +++ b/clang/test/CodeGenCXX/microsoft-inaccessible-base.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fms-compatibility -triple x86_64-windows-msvc %s -emit-llvm -o - | FileCheck %s + +// Make sure we choose the *direct* base path when doing these conversions. + +// CHECK: %struct.C = type { %struct.A, %struct.B } +// CHECK: %struct.D = type { %struct.B, %struct.A } + +struct A { int a; }; +struct B : A { int b; }; + +struct C : A, B { }; +extern "C" A *a_from_c(C *p) { return p; } +// CHECK-LABEL: define %struct.A* @a_from_c(%struct.C* %{{.*}}) +// CHECK: bitcast %struct.C* %{{.*}} to %struct.A* + +struct D : B, A { }; +extern "C" A *a_from_d(D *p) { return p; } +// CHECK-LABEL: define %struct.A* @a_from_d(%struct.D* %{{.*}}) +// CHECK: %[[p_i8:[^ ]*]] = bitcast %struct.D* %{{.*}} to i8* +// CHECK: getelementptr inbounds i8, i8* %[[p_i8]], i64 8 |