In CodeGenCXX/visibility.cpp,
Match GCC for part of test51: Change explicit instantiation of a function
template to respect the instantiated-from template's VisibilityAttr.
For the implicit instantiation zed<&z>(), our behavior remains different from
GCC, as the template parameter type 'foo' (hidden) wins
(shouldConsiderTemplateVisibility returns true). This seems an extreme corner
case.
Match GCC for test71: For an implicit or explicit instantiation of a class
template, change its member template instantiation to respect the
instantiated-from member template's VisibilityAttr.
Fix https://github.com/llvm/llvm-project/issues/31462
Okay, this change seems wrong. A visibility attribute on an explicit specialization or instantiation should definitely override everything else. A visibility attribute on a template pattern should only override other visibility information that we would derive from that pattern, like the visibility of the template parameters; it should not override visibility from the template arguments. You probably need this function to return an enum with three cases: (1) factor in both template arguments and template parameters, (2) factor in only template arguments, and (3) factor in nothing.
Also, the bug here doesn't seem to be specific to function templates, and you should fix the code for all three paths (function templates, class templates, and variable templates). Basically we're universally mishandling visibility attributes on template patterns for templates with non-type template parameters with hidden visibility.