[PATCH] D33366: Fix that global delete operator get's assigned to a submodule.

Richard Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 19 15:39:45 PDT 2017


rsmith added a comment.

This is supposed to be handled by `Sema::DeclareGlobalAllocationFunction`:

  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() == Params.size()) {
        llvm::SmallVector<QualType, 3> FuncParams;
        for (auto *P : Func->parameters())
          FuncParams.push_back(
              Context.getCanonicalType(P->getType().getUnqualifiedType()));
        if (llvm::makeArrayRef(FuncParams) == Params) {
          // 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;

... but it looks like we only get there once per compilation, which means that we won't unset the 'hidden' flag if we create the functions in one submodule and then need them from a second one, as in your testcase.

A better approach would be to call `Alloc->setHidden(false)` (and maybe also `Alloc->setLocalOwningModule(nullptr)`) after we create the implicit declaration in the `CreateAllocationFunctionDecl` lambda, rather than waiting until the second time we want it.


https://reviews.llvm.org/D33366





More information about the cfe-commits mailing list