ChuanqiXu updated this revision to Diff 412886. ChuanqiXu added a comment. Address comments:
- File an issue and add a reference to it. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D120397/new/ https://reviews.llvm.org/D120397 Files: clang/lib/AST/Decl.cpp clang/test/CodeGenCXX/inconsistent-export-template.cpp clang/test/Modules/inconsist-export-template.cpp Index: clang/test/Modules/inconsist-export-template.cpp =================================================================== --- /dev/null +++ clang/test/Modules/inconsist-export-template.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -std=c++20 %s -fsyntax-only -verify +// expected-no-diagnostics +export module m; +export template <class T> +void f() { +} + +template <> +void f<int>() { +} + +template <class T> +void f1() { +} + +// FIXME: We should reject following specialization, +// since it tries to export a name which is already introduced. +// See https://llvm.org/PR54189 for details. +export template <> +void f1<int>() { +} + +export template <class T> +class C { +}; + +template <> +class C<int> { +public: + void M(){}; +}; + +void Use(C<int> &p) { p.M(); } Index: clang/test/CodeGenCXX/inconsistent-export-template.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/inconsistent-export-template.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -std=c++20 %s -S -emit-llvm -triple %itanium_abi_triple -disable-llvm-passes -o - | FileCheck %s + +export module m; +export template <class T> +void f() { +} + +// CHECK: void @_Z1fIiEvv +template <> +void f<int>() { +} Index: clang/lib/AST/Decl.cpp =================================================================== --- clang/lib/AST/Decl.cpp +++ clang/lib/AST/Decl.cpp @@ -391,11 +391,18 @@ bool considerVisibility = shouldConsiderTemplateVisibility(fn, specInfo); - // Merge information from the template parameters. FunctionTemplateDecl *temp = specInfo->getTemplate(); - LinkageInfo tempLV = - getLVForTemplateParameterList(temp->getTemplateParameters(), computation); - LV.mergeMaybeWithVisibility(tempLV, considerVisibility); + + // Merge information from the template declaration. + LinkageInfo tempLV = getLVForDecl(temp, computation); + // The linkage of the specialization should be consistent with the + // template declaration. + LV.setLinkage(tempLV.getLinkage()); + + // Merge information from the template parameters. + LinkageInfo paramsLV = + getLVForTemplateParameterList(temp->getTemplateParameters(), computation); + LV.mergeMaybeWithVisibility(paramsLV, considerVisibility); // Merge information from the template arguments. const TemplateArgumentList &templateArgs = *specInfo->TemplateArguments;
Index: clang/test/Modules/inconsist-export-template.cpp =================================================================== --- /dev/null +++ clang/test/Modules/inconsist-export-template.cpp @@ -0,0 +1,33 @@ +// RUN: %clang_cc1 -std=c++20 %s -fsyntax-only -verify +// expected-no-diagnostics +export module m; +export template <class T> +void f() { +} + +template <> +void f<int>() { +} + +template <class T> +void f1() { +} + +// FIXME: We should reject following specialization, +// since it tries to export a name which is already introduced. +// See https://llvm.org/PR54189 for details. +export template <> +void f1<int>() { +} + +export template <class T> +class C { +}; + +template <> +class C<int> { +public: + void M(){}; +}; + +void Use(C<int> &p) { p.M(); } Index: clang/test/CodeGenCXX/inconsistent-export-template.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenCXX/inconsistent-export-template.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -std=c++20 %s -S -emit-llvm -triple %itanium_abi_triple -disable-llvm-passes -o - | FileCheck %s + +export module m; +export template <class T> +void f() { +} + +// CHECK: void @_Z1fIiEvv +template <> +void f<int>() { +} Index: clang/lib/AST/Decl.cpp =================================================================== --- clang/lib/AST/Decl.cpp +++ clang/lib/AST/Decl.cpp @@ -391,11 +391,18 @@ bool considerVisibility = shouldConsiderTemplateVisibility(fn, specInfo); - // Merge information from the template parameters. FunctionTemplateDecl *temp = specInfo->getTemplate(); - LinkageInfo tempLV = - getLVForTemplateParameterList(temp->getTemplateParameters(), computation); - LV.mergeMaybeWithVisibility(tempLV, considerVisibility); + + // Merge information from the template declaration. + LinkageInfo tempLV = getLVForDecl(temp, computation); + // The linkage of the specialization should be consistent with the + // template declaration. + LV.setLinkage(tempLV.getLinkage()); + + // Merge information from the template parameters. + LinkageInfo paramsLV = + getLVForTemplateParameterList(temp->getTemplateParameters(), computation); + LV.mergeMaybeWithVisibility(paramsLV, considerVisibility); // Merge information from the template arguments. const TemplateArgumentList &templateArgs = *specInfo->TemplateArguments;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits