Index: include/llvm/IR/TypeBuilder.h =================================================================== --- include/llvm/IR/TypeBuilder.h +++ include/llvm/IR/TypeBuilder.h @@ -252,156 +252,25 @@ template<> class TypeBuilder : public TypeBuilder*, false> {}; -template class TypeBuilder { +template +class TypeBuilder { public: static FunctionType *get(LLVMContext &Context) { - return FunctionType::get(TypeBuilder::get(Context), false); - } -}; -template class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, false); - } -}; -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, false); - } -}; -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, false); - } -}; - -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, false); - } -}; - -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; return FunctionType::get(TypeBuilder::get(Context), - params, false); + {TypeBuilder::get(Context)...}, false); } }; -template class TypeBuilder { +template +class TypeBuilder { public: static FunctionType *get(LLVMContext &Context) { - return FunctionType::get(TypeBuilder::get(Context), true); - } -}; -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), params, true); - } -}; -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; return FunctionType::get(TypeBuilder::get(Context), - params, true); - } -}; -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, true); - } -}; - -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, true); + {TypeBuilder::get(Context)...}, true); } }; -template -class TypeBuilder { -public: - static FunctionType *get(LLVMContext &Context) { - Type *params[] = { - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - TypeBuilder::get(Context), - }; - return FunctionType::get(TypeBuilder::get(Context), - params, true); - } -}; } // namespace llvm #endif Index: unittests/IR/TypeBuilderTest.cpp =================================================================== --- unittests/IR/TypeBuilderTest.cpp +++ unittests/IR/TypeBuilderTest.cpp @@ -152,8 +152,30 @@ EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), (TypeBuilder::get(getGlobalContext()))); + params.push_back(TypeBuilder::get(getGlobalContext())); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), + (TypeBuilder::get(getGlobalContext()))); + params.push_back(TypeBuilder::get(getGlobalContext())); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), + (TypeBuilder::get(getGlobalContext()))); + params.push_back(TypeBuilder::get(getGlobalContext())); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, false), + (TypeBuilder::get(getGlobalContext()))); + EXPECT_EQ(FunctionType::get(Type::getInt8Ty(getGlobalContext()), params, true), + (TypeBuilder::get(getGlobalContext()))); + } TEST(TypeBuilderTest, Context) { // We used to cache TypeBuilder results in static local variables. This // produced the same type for different contexts, which of course broke