Fix https://github.com/llvm/llvm-project/issues/16561
Fix https://github.com/llvm/llvm-project/issues/31462
Modify the behavior from 7f90b7d4c29d560b57f6026f886adbf4d7ab4382 (2012) to
clone VisibilityAttr for functions. I think that commit fixed a behavior
but made us more difficult to align with GCC.
The new behavior aligns better with GCC. Specifically, an instantiated
FunctionTemplateDecl/CXXMethodDecl now inherits the original visibility
attribute (test51 and test71 in visibility.cpp).
The cloned VisibilityAttr is set to implicit. This is important for
template void HIDDEN zed<&y>(); to override the original VisibilityAttr (test51),
not getting an err_mismatched_visibility error.
For now, it's important not to clone VisibilityAttr for non-FunctionDecl as that
would break test38 (and change test35 in another way to be incompatible
with GCC).