Skip to content

[IRGen] Use the lexical decl context for VarDecls. #33306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/IRGen/GenClangDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ void IRGenModule::emitClangDecl(const clang::Decl *decl) {
refFinder.TraverseDecl(executableDecl);
next = executableDecl;
}

if (auto var = dyn_cast<clang::VarDecl>(next))
if (!var->isFileVarDecl())
continue;

ClangCodeGen->HandleTopLevelDecl(clang::DeclGroupRef(next));
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/IRGen/Inputs/local_extern.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
static inline int _no_prior_var() {
extern int var;
return var;
}

static inline int _no_prior_func() {
extern int func();
return func();
}

static int prior_var = 1;
static inline int _prior_var() {
extern int prior_var;
return prior_var;
}

static inline int prior_func() { return 1; }
static inline int _prior_func() {
extern int prior_func();
return prior_func();
}
10 changes: 10 additions & 0 deletions test/IRGen/local_extern.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: %target-swift-frontend -import-objc-header %S/Inputs/local_extern.h %s -emit-ir | %FileCheck %s
// CHECK: @var = external global i32
// CHECK: @prior_var = internal global i32
// CHECK: declare i32 @func
// CHECK: define internal i32 @prior_func

print("\(_no_prior_var())")
print("\(_no_prior_func())")
print("\(_prior_var())")
print("\(_prior_func())")