From 6602ba5dcf226743a0f0d724e46eecfcb40862c2 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 14 Sep 2015 21:47:27 +0000 Subject: [PATCH] [opaque pointer types] Add an explicit value type to GlobalObject This is needed by all GlobalObjects (GlobalAlias, Function, GlobalVariable), see the GlobalObject::getValueType which is used in many places. If at some point that can be removed, then we can remove this member. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@247621 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/GlobalObject.h | 5 +---- include/llvm/IR/GlobalValue.h | 13 +++++++------ lib/IR/Globals.cpp | 4 ++-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/llvm/IR/GlobalObject.h b/include/llvm/IR/GlobalObject.h index 4b671da193d..ee111a046d7 100644 --- a/include/llvm/IR/GlobalObject.h +++ b/include/llvm/IR/GlobalObject.h @@ -27,13 +27,10 @@ class GlobalObject : public GlobalValue { GlobalObject(const GlobalObject &) = delete; protected: - GlobalObject(PointerType *Ty, ValueTy VTy, Use *Ops, unsigned NumOps, - LinkageTypes Linkage, const Twine &Name) = delete; GlobalObject(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps, LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace = 0) - : GlobalValue(PointerType::get(Ty, AddressSpace), VTy, Ops, NumOps, - Linkage, Name), + : GlobalValue(Ty, VTy, Ops, NumOps, Linkage, Name, AddressSpace), ObjComdat(nullptr) { setGlobalValueSubClassData(0); } diff --git a/include/llvm/IR/GlobalValue.h b/include/llvm/IR/GlobalValue.h index eb6af507816..2f9172648a2 100644 --- a/include/llvm/IR/GlobalValue.h +++ b/include/llvm/IR/GlobalValue.h @@ -65,15 +65,16 @@ public: }; protected: - GlobalValue(PointerType *Ty, ValueTy VTy, Use *Ops, unsigned NumOps, - LinkageTypes Linkage, const Twine &Name) - : Constant(Ty, VTy, Ops, NumOps), Linkage(Linkage), - Visibility(DefaultVisibility), UnnamedAddr(0), - DllStorageClass(DefaultStorageClass), + GlobalValue(Type *Ty, ValueTy VTy, Use *Ops, unsigned NumOps, + LinkageTypes Linkage, const Twine &Name, unsigned AddressSpace) + : Constant(PointerType::get(Ty, AddressSpace), VTy, Ops, NumOps), + ValueType(Ty), Linkage(Linkage), Visibility(DefaultVisibility), + UnnamedAddr(0), DllStorageClass(DefaultStorageClass), ThreadLocal(NotThreadLocal), IntID((Intrinsic::ID)0U), Parent(nullptr) { setName(Name); } + Type *ValueType; // Note: VC++ treats enums as signed, so an extra bit is required to prevent // Linkage and Visibility from turning into negative values. LinkageTypes Linkage : 5; // The linkage of this global @@ -184,7 +185,7 @@ public: /// Global values are always pointers. PointerType *getType() const { return cast(User::getType()); } - Type *getValueType() const { return getType()->getElementType(); } + Type *getValueType() const { return ValueType; } static LinkageTypes getLinkOnceLinkage(bool ODR) { return ODR ? LinkOnceODRLinkage : LinkOnceAnyLinkage; diff --git a/lib/IR/Globals.cpp b/lib/IR/Globals.cpp index 28f223593a8..11ece2ed1b1 100644 --- a/lib/IR/Globals.cpp +++ b/lib/IR/Globals.cpp @@ -234,8 +234,8 @@ void GlobalVariable::copyAttributesFrom(const GlobalValue *Src) { GlobalAlias::GlobalAlias(Type *Ty, unsigned AddressSpace, LinkageTypes Link, const Twine &Name, Constant *Aliasee, Module *ParentModule) - : GlobalValue(PointerType::get(Ty, AddressSpace), Value::GlobalAliasVal, - &Op<0>(), 1, Link, Name) { + : GlobalValue(Ty, Value::GlobalAliasVal, &Op<0>(), 1, Link, Name, + AddressSpace) { Op<0>() = Aliasee; if (ParentModule) -- 2.34.1