File tree Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Expand file tree Collapse file tree 3 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -50,9 +50,18 @@ void IRGenModule::emitClangDecl(const clang::Decl *decl) {
5050 stack.push_back (decl);
5151
5252 ClangDeclRefFinder refFinder ([&](const clang::DeclRefExpr *DRE) {
53- const clang::ValueDecl *D = DRE->getDecl ();
54- if (!D->hasLinkage () || D->isExternallyVisible ())
55- return ;
53+ const clang::Decl *D = DRE->getDecl ();
54+ // Check that this is a file-level declaration and not inside a function.
55+ // If it's a member of a file-level decl, like a C++ static member variable,
56+ // we want to add the entire file-level declaration because Clang doesn't
57+ // expect to see members directly here.
58+ for (auto *DC = D->getDeclContext ();; DC = DC->getParent ()) {
59+ if (DC->isFunctionOrMethod ())
60+ return ;
61+ if (DC->isFileContext ())
62+ break ;
63+ D = cast<const clang::Decl>(DC);
64+ }
5665 if (!GlobalClangDecls.insert (D->getCanonicalDecl ()).second )
5766 return ;
5867 stack.push_back (D);
Original file line number Diff line number Diff line change 22
33void overloaded (void ) __attribute__((overloadable ));
44void overloaded (int ) __attribute__((overloadable ));
5+
6+ extern void use (const char * );
7+
8+ static inline void test_my_log () {
9+ __attribute__((internal_linkage )) static const char fmt [] = "foobar" ;
10+ use (fmt );
11+ }
Original file line number Diff line number Diff line change @@ -9,4 +9,6 @@ func testOverloaded() {
99 overloaded ( )
1010 // CHECK: call void @_Z10overloadedi(i32{{( signext)?}} 42)
1111 overloaded ( 42 )
12+ // CHECK: call void @{{.*}}test_my_log
13+ test_my_log ( )
1214} // CHECK: {{^}$}}
You can’t perform that action at this time.
0 commit comments