// uniqued. We can't do this in C, though, because there's no
// standard way to agree on which variables are the same (i.e.
// there's no mangling).
- if (getLangOpts().CPlusPlus)
- if (llvm::GlobalValue::isWeakForLinker(CurFn->getLinkage()))
- Linkage = CurFn->getLinkage();
+ if (getLangOpts().CPlusPlus) {
+ const Decl *D = CurCodeDecl;
+ while (true) {
+ if (isa<BlockDecl>(D)) {
+ // FIXME: Handle this case properly! (Should be similar to the
+ // way we handle lambdas in computeLVForDecl in Decl.cpp.)
+ break;
+ } else if (isa<CapturedDecl>(D)) {
+ D = cast<Decl>(cast<CapturedDecl>(D)->getParent());
+ } else {
+ break;
+ }
+ }
+ // FIXME: Do we really only care about FunctionDecls here?
+ if (D && isa<FunctionDecl>(D)) {
+ llvm::GlobalValue::LinkageTypes ParentLinkage =
+ CGM.getFunctionLinkage(cast<FunctionDecl>(D));
+ if (llvm::GlobalValue::isWeakForLinker(ParentLinkage))
+ Linkage = ParentLinkage;
+ }
+ }
return EmitStaticVarDecl(D, Linkage);
}
llvm::GlobalValue::LinkageTypes
CodeGenModule::getFunctionLinkage(GlobalDecl GD) {
- const FunctionDecl *D = cast<FunctionDecl>(GD.getDecl());
+ return getFunctionLinkage(cast<FunctionDecl>(GD.getDecl()));
+}
+
+llvm::GlobalValue::LinkageTypes
+CodeGenModule::getFunctionLinkage(const FunctionDecl *D) {
GVALinkage Linkage = getContext().GetGVALinkageForFunction(D);
if (Linkage == GVA_Internal)
void AddDependentLib(StringRef Lib);
llvm::GlobalVariable::LinkageTypes getFunctionLinkage(GlobalDecl GD);
+ llvm::GlobalVariable::LinkageTypes getFunctionLinkage(const FunctionDecl *D);
void setFunctionLinkage(GlobalDecl GD, llvm::GlobalValue *V) {
V->setLinkage(getFunctionLinkage(GD));
// RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-4
// RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-5
// RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-6
+// RUN: FileCheck %s -input-file=%t -check-prefix=CHECK-7
struct Foo {
int x;
// CHECK-6-NEXT: ret void
template_capture_lambda<int>();
}
+
+inline int test_captured_linkage() {
+ // CHECK-7: @_ZN21test_captured_linkage1iE = linkonce_odr global i32 0
+ int j;
+ #pragma clang __debug captured
+ {
+ static int i = 0;
+ j = ++i;
+ }
+ return j;
+}
+void call_test_captured_linkage() {
+ test_captured_linkage();
+}