From 0393f324d73479feee10b60e7e30a087f53e2e08 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sat, 1 Aug 2015 22:52:12 +0000 Subject: [PATCH] Mark CompositeType::getTypeAtIndex as const. NFC llvm-svn: 243845 --- include/llvm/IR/DerivedTypes.h | 4 ++-- lib/IR/Type.cpp | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/llvm/IR/DerivedTypes.h b/include/llvm/IR/DerivedTypes.h index 96962da599f..d28847e4ff3 100644 --- a/include/llvm/IR/DerivedTypes.h +++ b/include/llvm/IR/DerivedTypes.h @@ -153,8 +153,8 @@ public: /// getTypeAtIndex - Given an index value into the type, return the type of /// the element. /// - Type *getTypeAtIndex(const Value *V); - Type *getTypeAtIndex(unsigned Idx); + Type *getTypeAtIndex(const Value *V) const; + Type *getTypeAtIndex(unsigned Idx) const; bool indexValid(const Value *V) const; bool indexValid(unsigned Idx) const; diff --git a/lib/IR/Type.cpp b/lib/IR/Type.cpp index 553fa93f585..1b46b7b01cb 100644 --- a/lib/IR/Type.cpp +++ b/lib/IR/Type.cpp @@ -620,8 +620,8 @@ StructType *Module::getTypeByName(StringRef Name) const { // CompositeType Implementation //===----------------------------------------------------------------------===// -Type *CompositeType::getTypeAtIndex(const Value *V) { - if (StructType *STy = dyn_cast(this)) { +Type *CompositeType::getTypeAtIndex(const Value *V) const { + if (auto *STy = dyn_cast(this)) { unsigned Idx = (unsigned)cast(V)->getUniqueInteger().getZExtValue(); assert(indexValid(Idx) && "Invalid structure index!"); @@ -630,14 +630,16 @@ Type *CompositeType::getTypeAtIndex(const Value *V) { return cast(this)->getElementType(); } -Type *CompositeType::getTypeAtIndex(unsigned Idx) { - if (StructType *STy = dyn_cast(this)) { + +Type *CompositeType::getTypeAtIndex(unsigned Idx) const{ + if (auto *STy = dyn_cast(this)) { assert(indexValid(Idx) && "Invalid structure index!"); return STy->getElementType(Idx); } - + return cast(this)->getElementType(); } + bool CompositeType::indexValid(const Value *V) const { if (auto *STy = dyn_cast(this)) { // Structure indexes require (vectors of) 32-bit integer constants. In the