diff options
| author | Serge Pavlov <sepavloff@gmail.com> | 2013-09-14 12:00:01 +0000 |
|---|---|---|
| committer | Serge Pavlov <sepavloff@gmail.com> | 2013-09-14 12:00:01 +0000 |
| commit | d5489074e69ce6f66b4f714491f5a2c70fdce422 (patch) | |
| tree | 4d1e2f15b2325a99d53132fc27f87449e67b2215 /clang/lib | |
| parent | 042f10ce410b8da1e464458a8f2cad27615b8358 (diff) | |
| download | bcm5719-llvm-d5489074e69ce6f66b4f714491f5a2c70fdce422.tar.gz bcm5719-llvm-d5489074e69ce6f66b4f714491f5a2c70fdce422.zip | |
Avoid getting an argument of allocation function if it does not exist.
This is a fix to PR12778: in erroneous code an allocation function
can be declared with no arguments, quering the first argument in this case
causes assertion violation.
llvm-svn: 190751
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 9b703ed0988..f0417f72495 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -1948,22 +1948,23 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name, DeclContext *GlobalCtx = Context.getTranslationUnitDecl(); // Check if this function is already declared. - { - DeclContext::lookup_result R = GlobalCtx->lookup(Name); - for (DeclContext::lookup_iterator Alloc = R.begin(), AllocEnd = R.end(); - Alloc != AllocEnd; ++Alloc) { - // Only look at non-template functions, as it is the predefined, - // non-templated allocation function we are trying to declare here. - if (FunctionDecl *Func = dyn_cast<FunctionDecl>(*Alloc)) { + DeclContext::lookup_result R = GlobalCtx->lookup(Name); + for (DeclContext::lookup_iterator Alloc = R.begin(), AllocEnd = R.end(); + Alloc != AllocEnd; ++Alloc) { + // Only look at non-template functions, as it is the predefined, + // non-templated allocation function we are trying to declare here. + if (FunctionDecl *Func = dyn_cast<FunctionDecl>(*Alloc)) { + if (Func->getNumParams() == 1) { QualType InitialParamType = Context.getCanonicalType( Func->getParamDecl(0)->getType().getUnqualifiedType()); // FIXME: Do we need to check for default arguments here? - if (Func->getNumParams() == 1 && InitialParamType == Argument) { + if (InitialParamType == Argument) { if (AddMallocAttr && !Func->hasAttr<MallocAttr>()) - Func->addAttr(::new (Context) MallocAttr(SourceLocation(), Context)); - // Make the function visible to name lookup, even if we found it in an - // unimported module. It either is an implicitly-declared global + Func->addAttr(::new (Context) MallocAttr(SourceLocation(), + Context)); + // Make the function visible to name lookup, even if we found it in + // an unimported module. It either is an implicitly-declared global // allocation function, or is suppressing that function. Func->setHidden(false); return; |

