[clang] af67deb - [OpenCL] Simplify InsertOCLBuiltinDeclarationsFromTable
Sven van Haastregt via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 9 03:55:31 PDT 2021
Author: Sven van Haastregt
Date: 2021-04-09T11:54:15+01:00
New Revision: af67deb005cae4e87109d8ad534446b300351483
URL: https://github.com/llvm/llvm-project/commit/af67deb005cae4e87109d8ad534446b300351483
DIFF: https://github.com/llvm/llvm-project/commit/af67deb005cae4e87109d8ad534446b300351483.diff
LOG: [OpenCL] Simplify InsertOCLBuiltinDeclarationsFromTable
- Use a range-based for loop. This will help a later patch to skip
prototypes that use an unavailable return type or argument type.
- Replace a dyn_cast with a cast, as we are only dealing with
FunctionProtoType Types here.
Added:
Modified:
clang/lib/Sema/SemaLookup.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index fef96b2eb11f..92efd427ba6c 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -850,28 +850,24 @@ static void InsertOCLBuiltinDeclarationsFromTable(Sema &S, LookupResult &LR,
DeclContext *Parent = Context.getTranslationUnitDecl();
FunctionDecl *NewOpenCLBuiltin;
- for (unsigned Index = 0; Index < GenTypeMaxCnt; Index++) {
+ for (const auto &FTy : FunctionList) {
NewOpenCLBuiltin = FunctionDecl::Create(
- Context, Parent, Loc, Loc, II, FunctionList[Index],
- /*TInfo=*/nullptr, SC_Extern, false,
- FunctionList[Index]->isFunctionProtoType());
+ Context, Parent, Loc, Loc, II, FTy, /*TInfo=*/nullptr, SC_Extern,
+ false, FTy->isFunctionProtoType());
NewOpenCLBuiltin->setImplicit();
// Create Decl objects for each parameter, adding them to the
// FunctionDecl.
- if (const FunctionProtoType *FP =
- dyn_cast<FunctionProtoType>(FunctionList[Index])) {
- SmallVector<ParmVarDecl *, 16> ParmList;
- for (unsigned IParm = 0, e = FP->getNumParams(); IParm != e; ++IParm) {
- ParmVarDecl *Parm = ParmVarDecl::Create(
- Context, NewOpenCLBuiltin, SourceLocation(), SourceLocation(),
- nullptr, FP->getParamType(IParm),
- /*TInfo=*/nullptr, SC_None, nullptr);
- Parm->setScopeInfo(0, IParm);
- ParmList.push_back(Parm);
- }
- NewOpenCLBuiltin->setParams(ParmList);
+ const auto *FP = cast<FunctionProtoType>(FTy);
+ SmallVector<ParmVarDecl *, 4> ParmList;
+ for (unsigned IParm = 0, e = FP->getNumParams(); IParm != e; ++IParm) {
+ ParmVarDecl *Parm = ParmVarDecl::Create(
+ Context, NewOpenCLBuiltin, SourceLocation(), SourceLocation(),
+ nullptr, FP->getParamType(IParm), nullptr, SC_None, nullptr);
+ Parm->setScopeInfo(0, IParm);
+ ParmList.push_back(Parm);
}
+ NewOpenCLBuiltin->setParams(ParmList);
// Add function attributes.
if (OpenCLBuiltin.IsPure)
More information about the cfe-commits
mailing list