[PATCH] D95673: [dllimport] Honor always_inline when deciding whether a dllimport function should be available for inlining (PR48925)
Hans Wennborg via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 29 02:11:51 PST 2021
hans created this revision.
hans added a reviewer: rnk.
hans requested review of this revision.
Herald added a project: clang.
Normally, Clang will not make dllimport functions available for inlining if they reference non-imported symbols, as this can lead to confusing link errors. But if the function is marked always_inline, the user presumably knows what they're doing and the attribute should be honored.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D95673
Files:
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCXX/dllimport.cpp
Index: clang/test/CodeGenCXX/dllimport.cpp
===================================================================
--- clang/test/CodeGenCXX/dllimport.cpp
+++ clang/test/CodeGenCXX/dllimport.cpp
@@ -386,6 +386,13 @@
USE(FunctionWithTLSVar)
USE(FunctionWithNormalVar)
+// always_inline and __force_inline take precedence.
+__declspec(dllimport) inline int ReferencingNonImportedFuncAlwaysInline() __attribute__((always_inline)) { return NonImportedFunc(); }
+USE(ReferencingNonImportedFuncAlwaysInline)
+// MO1-DAG: define available_externally dllimport i32 @"?ReferencingNonImportedFuncAlwaysInline@@YAHXZ"
+__declspec(dllimport) __forceinline int ReferencingNonImportedFuncForceInline() { return NonImportedFunc(); }
+USE(ReferencingNonImportedFuncForceInline)
+// MO1-DAG: define available_externally dllimport i32 @"?ReferencingNonImportedFuncForceInline@@YAHXZ"
//===----------------------------------------------------------------------===//
// Function templates
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3031,7 +3031,7 @@
if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr<AlwaysInlineAttr>())
return false;
- if (F->hasAttr<DLLImportAttr>()) {
+ if (F->hasAttr<DLLImportAttr>() && !F->hasAttr<AlwaysInlineAttr>()) {
// Check whether it would be safe to inline this dllimport function.
DLLImportFunctionVisitor Visitor;
Visitor.TraverseFunctionDecl(const_cast<FunctionDecl*>(F));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95673.320079.patch
Type: text/x-patch
Size: 1574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210129/0715da06/attachment.bin>
More information about the cfe-commits
mailing list