From 68cb3f7eca7536d85301f92314dbb5db6757cd94 Mon Sep 17 00:00:00 2001 From: Mark Seaborn Date: Fri, 6 Sep 2013 14:56:16 -0700 Subject: PNaCl bitcode: Strip pointer types from intrinsic declarations' parameters Change the writer to strip pointer types from intrinsics' argument and return types, replacing them with i32. This simplifies the PNaCl bitcode format so that pointer types don't need to be represented here. Change the reader to restore the pointer types so that the intrinsic declarations pass the LLVM and PNaCl verifiers. BUG=https://code.google.com/p/nativeclient/issues/detail?id=3671 TEST=intrinsic tests in call-elide.ll + intrinsic-pointer-args.ll + run small_tests with bitcode v2 enabled Review URL: https://codereview.chromium.org/23793005 --- lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp') diff --git a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp index 64d7661415..42f78baa2a 100644 --- a/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp +++ b/lib/Bitcode/NaCl/Writer/NaClValueEnumerator.cpp @@ -298,7 +298,27 @@ void NaClValueEnumerator::EnumerateValue(const Value *VIn) { } +Type *NaClValueEnumerator::NormalizeParamType(Type *Ty) const { + // Strip pointer types. + if (Ty->isPointerTy() && PNaClVersion >= 2) + Ty = IntPtrType; + return Ty; +} + +Type *NaClValueEnumerator::NormalizeType(Type *Ty) const { + if (FunctionType *FTy = dyn_cast(Ty)) { + SmallVector ArgTypes; + for (unsigned I = 0, E = FTy->getNumParams(); I < E; ++I) + ArgTypes.push_back(NormalizeParamType(FTy->getParamType(I))); + Ty = FunctionType::get(NormalizeParamType(FTy->getReturnType()), + ArgTypes, false); + } + return Ty; +} + void NaClValueEnumerator::EnumerateType(Type *Ty, bool InsideOptimizeTypes) { + Ty = NormalizeType(Ty); + // The label type does not need to be given a type ID. if (Ty->isLabelTy()) return; -- cgit v1.2.3-70-g09d2