aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2011-04-12 00:42:48 +0000
committerJohn McCall <rjmccall@apple.com>2011-04-12 00:42:48 +0000
commit755d8497e39071aa24acc173ff07083e3256b8f8 (patch)
tree47914f058b5de1a56c791ed102573f17d36f1d5a /lib/CodeGen
parent235c02f79e0ece9463490aa87eaaa02bad300dac (diff)
After some discussion with Doug, we decided that it made a lot more sense
for __unknown_anytype resolution to destructively modify the AST. So that's what it does now, which significantly simplifies some of the implementation. Normal member calls work pretty cleanly now, and I added support for propagating unknown-ness through &. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129331 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGCXXABI.cpp3
-rw-r--r--lib/CodeGen/CGCXXABI.h7
-rw-r--r--lib/CodeGen/CGExpr.cpp36
-rw-r--r--lib/CodeGen/CGExprAgg.cpp5
-rw-r--r--lib/CodeGen/CGExprConstant.cpp2
-rw-r--r--lib/CodeGen/CGExprScalar.cpp16
-rw-r--r--lib/CodeGen/CodeGenModule.cpp48
-rw-r--r--lib/CodeGen/CodeGenModule.h1
-rw-r--r--lib/CodeGen/ItaniumCXXABI.cpp35
9 files changed, 16 insertions, 137 deletions
diff --git a/lib/CodeGen/CGCXXABI.cpp b/lib/CodeGen/CGCXXABI.cpp
index e8b6f56724..92f1c63a38 100644
--- a/lib/CodeGen/CGCXXABI.cpp
+++ b/lib/CodeGen/CGCXXABI.cpp
@@ -99,8 +99,7 @@ CGCXXABI::EmitNullMemberPointer(const MemberPointerType *MPT) {
return GetBogusMemberPointer(CGM, QualType(MPT, 0));
}
-llvm::Constant *CGCXXABI::EmitMemberPointer(const CXXMethodDecl *MD,
- QualType unknownType) {
+llvm::Constant *CGCXXABI::EmitMemberPointer(const CXXMethodDecl *MD) {
return GetBogusMemberPointer(CGM,
CGM.getContext().getMemberPointerType(MD->getType(),
MD->getParent()->getTypeForDecl()));
diff --git a/lib/CodeGen/CGCXXABI.h b/lib/CodeGen/CGCXXABI.h
index a34ca9bcdc..de4df3dcbe 100644
--- a/lib/CodeGen/CGCXXABI.h
+++ b/lib/CodeGen/CGCXXABI.h
@@ -119,12 +119,7 @@ public:
virtual llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
/// Create a member pointer for the given method.
- ///
- /// \param unknownType - if non-null, use this type as the operand
- /// to CodeGenModule::getAddrOfUnknownAnyDecl instead of
- /// fetching the method's address in the normal way
- virtual llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD,
- QualType unknownType = QualType());
+ virtual llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD);
/// Create a member pointer for the given field.
virtual llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 496c3fc0aa..92e6a19c25 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -1792,35 +1792,6 @@ EmitConditionalOperatorLValue(const AbstractConditionalOperator *expr) {
return MakeAddrLValue(phi, expr->getType());
}
-static LValue emitUnknownAnyLValue(CodeGenFunction &CGF,
- const Expr *operand,
- QualType resolvedType) {
- const ValueDecl *decl;
- if (const DeclRefExpr *ref = dyn_cast<DeclRefExpr>(operand)) {
- decl = ref->getDecl();
- } else if (const MemberExpr *mem = dyn_cast<MemberExpr>(operand)) {
- decl = mem->getMemberDecl();
-
- // Emit (and ignore) the base.
- if (mem->isArrow())
- CGF.EmitScalarExpr(mem->getBase());
- else
- CGF.EmitLValue(mem->getBase());
- } else {
- llvm_unreachable("unexpected operand of unknown-any resolution!");
- decl = 0;
- }
- llvm::Value *addr = CGF.CGM.getAddrOfUnknownAnyDecl(decl, resolvedType);
-
- QualType type = resolvedType;
- if (const ReferenceType *ref = type->getAs<ReferenceType>()) {
- addr = CGF.Builder.CreateLoad(addr, "ref.value");
- type = ref->getPointeeType();
- }
-
- return CGF.MakeAddrLValue(addr, type);
-}
-
/// EmitCastLValue - Casts are never lvalues unless that cast is a dynamic_cast.
/// If the cast is a dynamic_cast, we can have the usual lvalue result,
/// otherwise if a cast is needed by the code generator in an lvalue context,
@@ -1959,13 +1930,6 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) {
ConvertType(ToType));
return MakeAddrLValue(V, E->getType());
}
- case CK_ResolveUnknownAnyType:
- return emitUnknownAnyLValue(*this, E->getSubExpr(), E->getType());
- case CK_ResolveUnknownAnyTypeToReference: {
- // l-value vs. r-value reference type shouldn't matter here.
- QualType type = getContext().getLValueReferenceType(E->getType());
- return emitUnknownAnyLValue(*this, E->getSubExpr(), type);
- }
}
llvm_unreachable("Unhandled lvalue cast kind?");
diff --git a/lib/CodeGen/CGExprAgg.cpp b/lib/CodeGen/CGExprAgg.cpp
index 5d22fc3304..177d0a4be7 100644
--- a/lib/CodeGen/CGExprAgg.cpp
+++ b/lib/CodeGen/CGExprAgg.cpp
@@ -310,11 +310,6 @@ void AggExprEmitter::VisitCastExpr(CastExpr *E) {
llvm_unreachable("should not be emitting lvalue bitcast as rvalue");
break;
- case CK_ResolveUnknownAnyType:
- case CK_ResolveUnknownAnyTypeToReference:
- EmitAggLoadOfLValue(E);
- break;
-
case CK_Dependent:
case CK_BitCast:
case CK_ArrayToPointerDecay:
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index b04ff0aefb..3a2fb9bd9d 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -552,8 +552,6 @@ public:
case CK_GetObjCProperty:
case CK_ToVoid:
case CK_Dynamic:
- case CK_ResolveUnknownAnyType:
- case CK_ResolveUnknownAnyTypeToReference:
return 0;
// These might need to be supported for constexpr.
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp
index f2ab0a2e06..a44c03ec11 100644
--- a/lib/CodeGen/CGExprScalar.cpp
+++ b/lib/CodeGen/CGExprScalar.cpp
@@ -1127,22 +1127,6 @@ Value *ScalarExprEmitter::EmitCastExpr(CastExpr *CE) {
return RV.getScalarVal();
}
- case CK_ResolveUnknownAnyType:
- // Special case: resolving a member pointer constant.
- if (const UnaryOperator *uo = dyn_cast<UnaryOperator>(E)) {
- DeclRefExpr *declRef = cast<DeclRefExpr>(uo->getSubExpr());
- const CXXMethodDecl *method = cast<CXXMethodDecl>(declRef->getDecl());
-
- const MemberPointerType *mpt = CE->getType()->castAs<MemberPointerType>();
- QualType resolvedType = mpt->getPointeeType();
-
- return CGF.CGM.getCXXABI().EmitMemberPointer(method, resolvedType);
- }
- // fallthrough
-
- case CK_ResolveUnknownAnyTypeToReference:
- return EmitLoadOfLValue(CE);
-
case CK_LValueToRValue:
assert(CGF.getContext().hasSameUnqualifiedType(E->getType(), DestTy));
assert(E->isGLValue() && "lvalue-to-rvalue applied to r-value!");
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 8f304ff580..944b24cbd3 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -1072,54 +1072,6 @@ llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D,
return GetOrCreateLLVMGlobal(MangledName, PTy, D);
}
-/// getAddrOfUnknownAnyDecl - Return an llvm::Constant for the address
-/// of a global which was declared with unknown type. It is possible
-/// for a VarDecl to end up getting resolved to have function type,
-/// which complicates this substantially; on the other hand, these are
-/// always external references, which does simplify the logic a lot.
-llvm::Constant *
-CodeGenModule::getAddrOfUnknownAnyDecl(const NamedDecl *decl, QualType type) {
- GlobalDecl global;
-
- // FunctionDecls will always end up with function types, but
- // VarDecls can end up with them too.
- if (isa<FunctionDecl>(decl))
- global = GlobalDecl(cast<FunctionDecl>(decl));
- else
- global = GlobalDecl(cast<VarDecl>(decl));
- llvm::StringRef mangledName = getMangledName(global);
-
- const llvm::Type *ty = getTypes().ConvertTypeForMem(type);
- const llvm::PointerType *pty =
- llvm::PointerType::get(ty, getContext().getTargetAddressSpace(type));
-
-
- // Check for an existing global value with this name.
- llvm::GlobalValue *entry = GetGlobalValue(mangledName);
- if (entry)
- return llvm::ConstantExpr::getBitCast(entry, pty);
-
- // If we're creating something with function type, go ahead and
- // create a function.
- if (const llvm::FunctionType *fnty = dyn_cast<llvm::FunctionType>(ty)) {
- llvm::Function *fn = llvm::Function::Create(fnty,
- llvm::Function::ExternalLinkage,
- mangledName, &getModule());
- return fn;
-
- // Otherwise, make a global variable.
- } else {
- llvm::GlobalVariable *var
- = new llvm::GlobalVariable(getModule(), ty, false,
- llvm::GlobalValue::ExternalLinkage,
- 0, mangledName, 0,
- false, pty->getAddressSpace());
- if (isa<VarDecl>(decl) && cast<VarDecl>(decl)->isThreadSpecified())
- var->setThreadLocal(true);
- return var;
- }
-}
-
/// CreateRuntimeVariable - Create a new runtime global variable with the
/// specified type and name.
llvm::Constant *
diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h
index b29437d962..99c973cce6 100644
--- a/lib/CodeGen/CodeGenModule.h
+++ b/lib/CodeGen/CodeGenModule.h
@@ -358,7 +358,6 @@ public:
llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D,
const llvm::Type *Ty = 0);
- llvm::Constant *getAddrOfUnknownAnyDecl(const NamedDecl *D, QualType type);
/// GetAddrOfFunction - Return the address of the given function. If Ty is
/// non-null, then this function will use the specified type if it has to
diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp
index 6c864ca7f4..ca3efb5913 100644
--- a/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/lib/CodeGen/ItaniumCXXABI.cpp
@@ -78,8 +78,7 @@ public:
llvm::Constant *EmitNullMemberPointer(const MemberPointerType *MPT);
- llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD,
- QualType unknownType);
+ llvm::Constant *EmitMemberPointer(const CXXMethodDecl *MD);
llvm::Constant *EmitMemberDataPointer(const MemberPointerType *MPT,
CharUnits offset);
@@ -503,8 +502,7 @@ ItaniumCXXABI::EmitMemberDataPointer(const MemberPointerType *MPT,
return llvm::ConstantInt::get(getPtrDiffTy(), offset.getQuantity());
}
-llvm::Constant *ItaniumCXXABI::EmitMemberPointer(const CXXMethodDecl *MD,
- QualType unknownType) {
+llvm::Constant *ItaniumCXXABI::EmitMemberPointer(const CXXMethodDecl *MD) {
assert(MD->isInstance() && "Member function must not be static!");
MD = MD->getCanonicalDecl();
@@ -539,25 +537,20 @@ llvm::Constant *ItaniumCXXABI::EmitMemberPointer(const CXXMethodDecl *MD,
MemPtr[1] = llvm::ConstantInt::get(ptrdiff_t, 0);
}
} else {
- llvm::Constant *addr;
- if (!unknownType.isNull()) {
- addr = CGM.getAddrOfUnknownAnyDecl(MD, unknownType);
+ QualType fnType = MD->getType();
+ const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>();
+ const llvm::Type *Ty;
+ // Check whether the function has a computable LLVM signature.
+ if (!CodeGenTypes::VerifyFuncTypeComplete(FPT)) {
+ // The function has a computable LLVM signature; use the correct type.
+ Ty = Types.GetFunctionType(Types.getFunctionInfo(MD),
+ FPT->isVariadic());
} else {
- QualType fnType = MD->getType();
- const FunctionProtoType *FPT = MD->getType()->castAs<FunctionProtoType>();
- const llvm::Type *Ty;
- // Check whether the function has a computable LLVM signature.
- if (!CodeGenTypes::VerifyFuncTypeComplete(FPT)) {
- // The function has a computable LLVM signature; use the correct type.
- Ty = Types.GetFunctionType(Types.getFunctionInfo(MD),
- FPT->isVariadic());
- } else {
- // Use an arbitrary non-function type to tell GetAddrOfFunction that the
- // function type is incomplete.
- Ty = ptrdiff_t;
- }
- addr = CGM.GetAddrOfFunction(MD, Ty);
+ // Use an arbitrary non-function type to tell GetAddrOfFunction that the
+ // function type is incomplete.
+ Ty = ptrdiff_t;
}
+ llvm::Constant *addr = CGM.GetAddrOfFunction(MD, Ty);
MemPtr[0] = llvm::ConstantExpr::getPtrToInt(addr, ptrdiff_t);
MemPtr[1] = llvm::ConstantInt::get(ptrdiff_t, 0);