[cfe-commits] r123954 - in /cfe/trunk: lib/CodeGen/CGExprCXX.cpp test/CodeGenCXX/apple-kext-indirect-call.C
Fariborz Jahanian
fjahanian at apple.com
Thu Jan 20 17:04:41 PST 2011
Author: fjahanian
Date: Thu Jan 20 19:04:41 2011
New Revision: 123954
URL: http://llvm.org/viewvc/llvm-project?rev=123954&view=rev
Log:
Move cheking of kext into canDevirtualizeMemberFunctionCalls().
Improve on test case. Per Doug's comment. wip.
Modified:
cfe/trunk/lib/CodeGen/CGExprCXX.cpp
cfe/trunk/test/CodeGenCXX/apple-kext-indirect-call.C
Modified: cfe/trunk/lib/CodeGen/CGExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprCXX.cpp?rev=123954&r1=123953&r2=123954&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprCXX.cpp Thu Jan 20 19:04:41 2011
@@ -55,9 +55,14 @@
/// canDevirtualizeMemberFunctionCalls - Checks whether virtual calls on given
/// expr can be devirtualized.
-static bool canDevirtualizeMemberFunctionCalls(const Expr *Base,
+static bool canDevirtualizeMemberFunctionCalls(ASTContext &Context,
+ const Expr *Base,
const CXXMethodDecl *MD) {
+ // Cannot divirtualize in kext mode.
+ if (Context.getLangOptions().AppleKext)
+ return false;
+
// If the member function has the "final" attribute, we know that it can't be
// overridden and can therefore devirtualize it.
if (MD->hasAttr<FinalAttr>())
@@ -173,12 +178,9 @@
// We also don't emit a virtual call if the base expression has a record type
// because then we know what the type is.
bool UseVirtualCall;
- if (!getContext().getLangOptions().AppleKext)
- UseVirtualCall = MD->isVirtual() && !ME->hasQualifier()
- && !canDevirtualizeMemberFunctionCalls(ME->getBase(), MD);
- else
- UseVirtualCall = MD->isVirtual();
-
+ UseVirtualCall = MD->isVirtual() && !ME->hasQualifier()
+ && !canDevirtualizeMemberFunctionCalls(getContext(),
+ ME->getBase(), MD);
llvm::Value *Callee;
if (const CXXDestructorDecl *Dtor = dyn_cast<CXXDestructorDecl>(MD)) {
if (UseVirtualCall) {
@@ -190,14 +192,13 @@
dyn_cast<CXXConstructorDecl>(MD)) {
Callee = CGM.GetAddrOfFunction(GlobalDecl(Ctor, Ctor_Complete), Ty);
} else if (UseVirtualCall) {
- if (getContext().getLangOptions().AppleKext &&
- ME->hasQualifier()) {
- Callee = BuildAppleKextVirtualCall(MD, ME->getQualifier(), This, Ty);
- }
- else
Callee = BuildVirtualCall(MD, This, Ty);
} else {
- Callee = CGM.GetAddrOfFunction(MD, Ty);
+ if (getContext().getLangOptions().AppleKext &&
+ ME->hasQualifier())
+ Callee = BuildAppleKextVirtualCall(MD, ME->getQualifier(), This, Ty);
+ else
+ Callee = CGM.GetAddrOfFunction(MD, Ty);
}
return EmitCXXMemberCall(MD, Callee, ReturnValue, This, /*VTT=*/0,
@@ -277,8 +278,8 @@
FPT->isVariadic());
llvm::Value *Callee;
if (MD->isVirtual() &&
- (getContext().getLangOptions().AppleKext ||
- !canDevirtualizeMemberFunctionCalls(E->getArg(0), MD)))
+ !canDevirtualizeMemberFunctionCalls(getContext(),
+ E->getArg(0), MD))
Callee = BuildVirtualCall(MD, This, Ty);
else
Callee = CGM.GetAddrOfFunction(MD, Ty);
Modified: cfe/trunk/test/CodeGenCXX/apple-kext-indirect-call.C
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/apple-kext-indirect-call.C?rev=123954&r1=123953&r2=123954&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/apple-kext-indirect-call.C (original)
+++ cfe/trunk/test/CodeGenCXX/apple-kext-indirect-call.C Thu Jan 20 19:04:41 2011
@@ -1,8 +1,6 @@
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fapple-kext -emit-llvm -o - %s | FileCheck %s
struct Base {
- virtual void abc1(void) const;
- virtual void abc2(void) const;
virtual void abc(void) const;
};
@@ -12,4 +10,5 @@
p->Base::abc();
}
+// CHECK: getelementptr inbounds (void (%struct.Base*)** bitcast ([3 x i8*]* @_ZTV4Base to void (%struct.Base*)**), i64 2)
// CHECK-NOT: call void @_ZNK4Base3abcEv
More information about the cfe-commits
mailing list