This is an archive of the discontinued LLVM Phabricator instance.

[Coroutines] Find custom allocators in class scope
ClosedPublic

Authored by modocache on Mar 15 2018, 11:26 PM.

Details

Summary

https://reviews.llvm.org/rL325291 implemented Coroutines TS N4723
section [dcl.fct.def.coroutine]/7, but it performed lookup of allocator
functions within both the global and class scope, whereas the specified
behavior is to perform lookup for custom allocators within just the
class scope.

To fix, add parameters to the Sema::FindAllocationFunctions function
such that it can be used to lookup allocators in global scope,
class scope, or both (instead of just being able to look up in just global
scope or in both global and class scope). Then, use those parameters
from within the coroutine Sema.

This incorrect behavior had the unfortunate side-effect of causing the
bug https://bugs.llvm.org/show_bug.cgi?id=36578 (or at least the reports
of that bug in C++ programs). That bug would occur for any C++ user with
a coroutine frame that took a single pointer argument, since it would
then find the global placement form operator new, described in the
C++ standard 18.6.1.3.1. This patch prevents Clang from generating code
that triggers the LLVM assert described in that bug report.

Test Plan: check-clang

Diff Detail

Repository
rC Clang

Event Timeline

modocache created this revision.Mar 15 2018, 11:26 PM
GorNishanov accepted this revision.Mar 30 2018, 9:22 AM

LGTM with some stylistic suggestions

lib/Sema/SemaExprCXX.cpp
2355

drop else?

if (R.empty()) {
  if (NewScope == AFS_Class)
    return true;

  LookupQualifiedName(R, Context.getTranslationUnitDecl());
}
2406

drop else? so that it will read:

if (FoundDelete.empty()) {
  if (DeleteScope == AFS_Class)
    return true;

  DeclareGlobalNewDelete();
  LookupQualifiedName(FoundDelete, Context.getTranslationUnitDecl());
}
This revision is now accepted and ready to land.Mar 30 2018, 9:22 AM
This revision was automatically updated to reflect the committed changes.
modocache marked 2 inline comments as done.Apr 1 2018, 4:05 PM

Thanks for the review, @GorNishanov! I adopted your suggestions and made the commit.