diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-09 04:46:40 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-09 04:46:40 +0000 |
commit | a2d24e5b1055d27f421f0c9997c99622614cb9ed (patch) | |
tree | 77199b3d18697e73309654473d68259420322255 /lib | |
parent | 93a59cb72bf31746abc78bc779e235b1117f17cf (diff) | |
download | external_llvm-a2d24e5b1055d27f421f0c9997c99622614cb9ed.zip external_llvm-a2d24e5b1055d27f421f0c9997c99622614cb9ed.tar.gz external_llvm-a2d24e5b1055d27f421f0c9997c99622614cb9ed.tar.bz2 |
Fix PR3746 - Crash in isel with GEP of function pointer
by checking that the top-level type of a gep is sized. This
causes us to reject the example with:
llvm-as: t2.ll:2:16: invalid getelementptr indices
getelementptr i32()* null, i32 1
^
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66393 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VMCore/Instructions.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 1b5cfb1..90af9f1 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -1037,26 +1037,30 @@ GetElementPtrInst::GetElementPtrInst(Value *Ptr, Value *Idx, init(Ptr, Idx, Name); } -// getIndexedType - Returns the type of the element that would be loaded with -// a load instruction with the specified parameters. -// -// The Idxs pointer should point to a continuous piece of memory containing the -// indices, either as Value* or uint64_t. -// -// A null type is returned if the indices are invalid for the specified -// pointer type. -// +/// getIndexedType - Returns the type of the element that would be accessed with +/// a gep instruction with the specified parameters. +/// +/// The Idxs pointer should point to a continuous piece of memory containing the +/// indices, either as Value* or uint64_t. +/// +/// A null type is returned if the indices are invalid for the specified +/// pointer type. +/// template <typename IndexTy> -static const Type* getIndexedTypeInternal(const Type *Ptr, - IndexTy const *Idxs, - unsigned NumIdx) { +static const Type* getIndexedTypeInternal(const Type *Ptr, IndexTy const *Idxs, + unsigned NumIdx) { const PointerType *PTy = dyn_cast<PointerType>(Ptr); if (!PTy) return 0; // Type isn't a pointer type! const Type *Agg = PTy->getElementType(); - // Handle the special case of the empty set index set... + // Handle the special case of the empty set index set, which is always valid. if (NumIdx == 0) return Agg; + + // If there is at least one index, the top level type must be sized, otherwise + // it cannot be 'stepped over'. + if (!Agg->isSized()) + return 0; unsigned CurIdx = 1; for (; CurIdx != NumIdx; ++CurIdx) { |