[PATCH] D58920: [Modules][PR39287] Consolidate multiple std's

Brian Gesiak via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 4 12:41:51 PST 2019


modocache created this revision.
modocache added reviewers: rsmith, andrewjcg.
Herald added a project: clang.

This patch addresses https://bugs.llvm.org/show_bug.cgi?id=39287.

Clang creates a 'std' namespace in one of two ways: either it parses a
`namespace std { ... }` declaration, or it creates one implicitly.

One case in which Clang creates an implicit 'std' namespace is when it
encounters a virtual destructor in C++17, which results in the implicit
definition of operator new and delete overloads that take a
`std::align_val_t` argument (this behavior was added in rL282800 <https://reviews.llvm.org/rL282800>).

Unfortunately, when using Clang modules, further definitions of the
`std` namespace may or may not reconcile with previous definitions. For
example, consider the two test cases in this patch:

- `mod-virtual-destructor-bug` defines `std::type_info` within the main translation unit. When it does so, there are two 'std' namespaces available: the implicitly defined one that is returned by `Sema::getStdNamespace`, and the explicit one defined in the `a.h` module. The `std::type_info` definition ends up being attached to the module's `std` namespace, and so the subsequent lookup of `getStdNamespace`'s `type_info` member fails. To fix this case, this patch adds logic to ensure `Sema::ActOnNamespaceDef` finds the `getStdNamespace` namespace from the current translation unit.
- `mod-virtual-destructor-bug-two` defines `std::type_info` within a module. Later, the lookup of `std::type_info` finds the implicitly created `getStdNamespace`, which only defines `std::align_val_t`, not `std::type_info`. To fix this case, this patch adds logic that ensures external AST sources are loaded when looking up `std::type_info`.


Repository:
  rC Clang

https://reviews.llvm.org/D58920

Files:
  lib/Sema/SemaDeclCXX.cpp
  lib/Serialization/ASTReader.cpp
  test/Modules/Inputs/mod-virtual-destructor-bug-two/a.h
  test/Modules/Inputs/mod-virtual-destructor-bug-two/module.modulemap
  test/Modules/Inputs/mod-virtual-destructor-bug/a.h
  test/Modules/Inputs/mod-virtual-destructor-bug/module.modulemap
  test/Modules/mod-virtual-destructor-bug-two.cpp
  test/Modules/mod-virtual-destructor-bug.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58920.189191.patch
Type: text/x-patch
Size: 3717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190304/5f434177/attachment.bin>


More information about the cfe-commits mailing list