summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2016-11-03 18:55:18 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2016-11-03 18:55:18 +0000
commit018ac39f942585a32d4809bb5b014af4c3c60dea (patch)
treefab0332b9c58d1cba86f98081f94edf04d77613c /clang/test
parentf9fb2abb01ea82a43b5938e3a24de9d8c6790e46 (diff)
downloadbcm5719-llvm-018ac39f942585a32d4809bb5b014af4c3c60dea.tar.gz
bcm5719-llvm-018ac39f942585a32d4809bb5b014af4c3c60dea.zip
Improve obvious-most-derived-type devirtualization:
* if the base is produced by a series of derived-to-base conversions, check the expression inside them when looking for an expression with a known dynamic type * step past MaterializeTemporaryExprs when checking for a known dynamic type * when checking for a known dynamic type, treat all class prvalues as having a known dynamic type after skipping all relevant rvalue subobject adjustments * treat callees formed by pointer-to-member access for a non-reference member type like callees formed by member access. llvm-svn: 285954
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp63
1 files changed, 62 insertions, 1 deletions
diff --git a/clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp b/clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
index 911ddeedd23..f2dc9789725 100644
--- a/clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
+++ b/clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp
@@ -1,8 +1,11 @@
-// RUN: %clang_cc1 %s -triple armv7-none-eabi -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++98 %s -triple armv7-none-eabi -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 %s -triple armv7-none-eabi -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -std=c++1z %s -triple armv7-none-eabi -emit-llvm -o - | FileCheck %s
struct A {
virtual void f();
virtual void f_const() const;
+ virtual void g();
A h();
};
@@ -37,6 +40,64 @@ void f(A a, A *ap, A& ar) {
(a).f();
}
+struct D : A { virtual void g(); };
+struct XD { D d; };
+
+D gd();
+
+void fd(D d, XD xd, D *p) {
+ // CHECK: call void @_ZN1A1fEv(%struct.A*
+ d.f();
+
+ // CHECK: call void @_ZN1D1gEv(%struct.D*
+ d.g();
+
+ // CHECK: call void @_ZN1A1fEv
+ D().f();
+
+ // CHECK: call void @_ZN1D1gEv
+ D().g();
+
+ // CHECK: call void @_ZN1A1fEv
+ gd().f();
+
+ // CHECK: call void @_ZNK1A7f_constEv
+ d.f_const();
+
+ // CHECK: call void @_ZN1A1fEv
+ (d).f();
+
+ // CHECK: call void @_ZN1A1fEv
+ (true, d).f();
+
+ // CHECK: call void @_ZN1D1gEv
+ (true, d).g();
+
+ // CHECK: call void @_ZN1A1fEv
+ xd.d.f();
+
+ // CHECK: call void @_ZN1A1fEv
+ XD().d.f();
+
+ // CHECK: call void @_ZN1A1fEv
+ D XD::*mp;
+ (xd.*mp).f();
+
+ // CHECK: call void @_ZN1D1gEv
+ (xd.*mp).g();
+
+ // Can't devirtualize this; we have no guarantee that p points to a D here,
+ // due to the "single object is considered to be an array of one element"
+ // rule.
+ // CHECK: call void %
+ p[0].f();
+
+ // FIXME: We can devirtualize this, by C++1z [expr.add]/6 (if the array
+ // element type and the pointee type are not similar, behavior is undefined).
+ // CHECK: call void %
+ p[1].f();
+}
+
struct B {
virtual void f();
~B();
OpenPOWER on IntegriCloud