mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-23 07:52:06 +00:00
-fmodules-codegen should not emit extern templates
If a header contains 'extern template', then the template should be provided somewhere by an explicit instantiation, so it is not necessary to generate a copy. Worse, this can lead to an unresolved symbol, because the codegen's object file will not actually contain functions from such a template because of the GVA_AvailableExternally, but the object file for the explicit instantiation will not contain them either because it will be blocked by the information provided by the module. Differential Revision: https://reviews.llvm.org/D69779
This commit is contained in:
parent
f52d71736b
commit
729530f68f
@ -2437,11 +2437,12 @@ void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
9
clang/test/Modules/codegen-extern-template.cpp
Normal file
9
clang/test/Modules/codegen-extern-template.cpp
Normal file
@ -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
|
12
clang/test/Modules/codegen-extern-template.h
Normal file
12
clang/test/Modules/codegen-extern-template.h
Normal file
@ -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
|
1
clang/test/Modules/codegen-extern-template.modulemap
Normal file
1
clang/test/Modules/codegen-extern-template.modulemap
Normal file
@ -0,0 +1 @@
|
||||
module foo { header "codegen-extern-template.h" }
|
Loading…
Reference in New Issue
Block a user