
Currently evaluating an expression involving a global variable inside an inline namespace will fail to lookup said variable. This is because the `SymbolFileDWARF::FindGlobalVariables` discards from consideration all DIEs whose decl_context doesn't exactly match that of the lookup. This patch relaxes this restriction by checking whether C++ rules would permit the lookup. This is permitted by the DWARFv5 spec in chapter `3.2.2 Namespace Entries`: ``` A namespace may have a DW_AT_export_symbols attribute which is a flag which indicates that all member names defined within the namespace may be referenced as if they were defined within the containing namespace. ``` The motivation for this is evaluating `std::ranges` expressions, which heavily rely on global variables inside inline namespaces. E.g., `std::views::all(...)` is just an invocation of the `operator()` on `std::ranges::views::__cpo::all`. **Testing** * Added API tests Differential Revision: https://reviews.llvm.org/D143068
29 lines
485 B
C++
29 lines
485 B
C++
namespace A {
|
|
inline namespace B {
|
|
int f() { return 3; }
|
|
int global_var = 0;
|
|
|
|
namespace C {
|
|
int global_var = 1;
|
|
}
|
|
|
|
inline namespace D {
|
|
int nested_var = 2;
|
|
}
|
|
};
|
|
|
|
namespace E {
|
|
inline namespace F {
|
|
int other_var = 3;
|
|
}
|
|
} // namespace E
|
|
|
|
int global_var = 4;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
// Set break point at this line.
|
|
return A::f() + A::B::global_var + A::C::global_var + A::E::F::other_var +
|
|
A::B::D::nested_var;
|
|
}
|