[PATCH] D69779: -fmodules-codegen should not emit extern templates
Luboš Luňák via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 14 14:45:59 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG729530f68fe1: -fmodules-codegen should not emit extern templates (authored by llunak).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69779/new/
https://reviews.llvm.org/D69779
Files:
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/Modules/codegen-extern-template.cpp
clang/test/Modules/codegen-extern-template.h
clang/test/Modules/codegen-extern-template.modulemap
Index: clang/test/Modules/codegen-extern-template.modulemap
===================================================================
--- /dev/null
+++ clang/test/Modules/codegen-extern-template.modulemap
@@ -0,0 +1 @@
+module foo { header "codegen-extern-template.h" }
Index: clang/test/Modules/codegen-extern-template.h
===================================================================
--- /dev/null
+++ clang/test/Modules/codegen-extern-template.h
@@ -0,0 +1,12 @@
+// header for codegen-extern-template.cpp
+#ifndef CODEGEN_EXTERN_TEMPLATE_H
+#define CODEGEN_EXTERN_TEMPLATE_H
+
+template <typename T>
+inline T foo() { return 10; }
+
+extern template int foo<int>();
+
+inline int bar() { return foo<int>(); }
+
+#endif
Index: clang/test/Modules/codegen-extern-template.cpp
===================================================================
--- /dev/null
+++ clang/test/Modules/codegen-extern-template.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules -fmodules-codegen -emit-module -fmodule-name=foo %S/codegen-extern-template.modulemap -x c++ -o %t.pcm
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -fmodules -fmodule-file=%t.pcm %s -emit-llvm -o - | FileCheck %s
+// expected-no-diagnostics
+
+#include "codegen-extern-template.h"
+
+template int foo<int>();
+
+// CHECK: define weak_odr i32 @_Z3fooIiET_v
Index: clang/lib/Serialization/ASTWriterDecl.cpp
===================================================================
--- clang/lib/Serialization/ASTWriterDecl.cpp
+++ clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2437,11 +2437,12 @@
}
if (Writer->Context->getLangOpts().ModulesCodegen) {
// Under -fmodules-codegen, codegen is performed for all non-internal,
- // non-always_inline functions.
+ // non-always_inline functions, unless they are available elsewhere.
if (!FD->hasAttr<AlwaysInlineAttr>()) {
if (!Linkage)
Linkage = Writer->Context->GetGVALinkageForFunction(FD);
- ModulesCodegen = *Linkage != GVA_Internal;
+ ModulesCodegen =
+ *Linkage != GVA_Internal && *Linkage != GVA_AvailableExternally;
}
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69779.238110.patch
Type: text/x-patch
Size: 2141 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200114/8a4f28d6/attachment.bin>
More information about the cfe-commits
mailing list