From 0877e1eabee040ae397a98b58643113b364f9e0c Mon Sep 17 00:00:00 2001
From: Sanjiv Gupta
Date: Sun, 26 Apr 2009 17:14:35 +0000
Subject: [PATCH] Any size of integral indices are allowed in gep for indexing
into sequential types. Also adding a test case to check the indices type
allowed into struct.
llvm-svn: 70134
---
docs/LangRef.html | 2 +-
lib/VMCore/Type.cpp | 5 ++---
test/Assembler/getelementptr_struct.ll | 12 ++++++++++++
3 files changed, 15 insertions(+), 4 deletions(-)
create mode 100644 test/Assembler/getelementptr_struct.ll
diff --git a/docs/LangRef.html b/docs/LangRef.html
index c07d0e0d592..313bf833471 100644
--- a/docs/LangRef.html
+++ b/docs/LangRef.html
@@ -3629,7 +3629,7 @@ the pointer before continuing calculation.
The type of each index argument depends on the type it is indexing into.
When indexing into a (packed) structure, only i32 integer
constants are allowed. When indexing into an array, pointer or vector,
-only integers of 16, 32 or 64 bits are allowed (also non-constants). 16-bit
+integers of any width are allowed (also non-constants). 16-bit
values will be sign extended to 32-bits if required, and 32-bit values
will be sign extended to 64-bits if required.
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index c85395f6201..4a53fcf6f83 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -1410,9 +1410,8 @@ void PointerType::typeBecameConcrete(const DerivedType *AbsTy) {
}
bool SequentialType::indexValid(const Value *V) const {
- if (const IntegerType *IT = dyn_cast(V->getType()))
- return IT->getBitWidth() == 16 || IT->getBitWidth() == 32 ||
- IT->getBitWidth() == 64;
+ if (isa(V->getType()))
+ return true;
return false;
}
diff --git a/test/Assembler/getelementptr_struct.ll b/test/Assembler/getelementptr_struct.ll
new file mode 100644
index 00000000000..c8779a64077
--- /dev/null
+++ b/test/Assembler/getelementptr_struct.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s >/dev/null |& grep {invalid getelementptr indices}
+; Test the case of a incorrect indices type into struct
+
+%RT = type { i8 , [10 x [20 x i32]], i8 }
+%ST = type { i32, double, %RT }
+
+define i32* @foo(%ST* %s) {
+entry:
+ %reg = getelementptr %ST* %s, i32 1, i64 2, i32 1, i32 5, i32 13
+ ret i32* %reg
+}
+