diff --git a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp --- a/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp +++ b/llvm/lib/Bitcode/Writer/ValueEnumerator.cpp @@ -364,22 +364,29 @@ UseListOrders = predictUseListOrder(M); // Enumerate the global variables. - for (const GlobalVariable &GV : M.globals()) + for (const GlobalVariable &GV : M.globals()) { EnumerateValue(&GV); + EnumerateType(GV.getValueType()); + } // Enumerate the functions. for (const Function & F : M) { EnumerateValue(&F); + EnumerateType(F.getValueType()); EnumerateAttributes(F.getAttributes()); } // Enumerate the aliases. - for (const GlobalAlias &GA : M.aliases()) + for (const GlobalAlias &GA : M.aliases()) { EnumerateValue(&GA); + EnumerateType(GA.getValueType()); + } // Enumerate the ifuncs. - for (const GlobalIFunc &GIF : M.ifuncs()) + for (const GlobalIFunc &GIF : M.ifuncs()) { EnumerateValue(&GIF); + EnumerateType(GIF.getValueType()); + } // Remember what is the cutoff between globalvalue's and other constants. unsigned FirstConstant = Values.size(); diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp --- a/llvm/lib/IR/Type.cpp +++ b/llvm/lib/IR/Type.cpp @@ -24,14 +24,20 @@ #include "llvm/IR/Module.h" #include "llvm/IR/Value.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Support/raw_ostream.h" #include "llvm/Support/TypeSize.h" +#include "llvm/Support/raw_ostream.h" #include #include using namespace llvm; +static cl::opt + ForceOpaquePointers("force-opaque-pointers", + cl::desc("Force all pointers to be opaque pointers"), + cl::init(false)); + //===----------------------------------------------------------------------===// // Type Class Implementation //===----------------------------------------------------------------------===// @@ -685,6 +691,9 @@ //===----------------------------------------------------------------------===// PointerType *PointerType::get(Type *EltTy, unsigned AddressSpace) { + if (ForceOpaquePointers) + return get(EltTy->getContext(), AddressSpace); + assert(EltTy && "Can't get a pointer to type!"); assert(isValidElementType(EltTy) && "Invalid type for pointer element!"); diff --git a/llvm/test/Other/force-opaque-ptrs.ll b/llvm/test/Other/force-opaque-ptrs.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Other/force-opaque-ptrs.ll @@ -0,0 +1,7 @@ +; RUN: llvm-as --force-opaque-pointers < %s | llvm-dis | FileCheck %s + +; CHECK: define ptr @f(ptr %a) +; CHECK: ret ptr %a +define i32* @f(i32* %a) { + ret i32* %a +}