[clang] 0479c53 - [dllimport] Honor always_inline when deciding whether a dllimport function should be available for inlining (PR48925)
Hans Wennborg via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 2 01:34:14 PST 2021
Author: Hans Wennborg
Date: 2021-02-02T10:28:32+01:00
New Revision: 0479c53b6c5224c16bdc78cb014e76c0b0dbc6f9
URL: https://github.com/llvm/llvm-project/commit/0479c53b6c5224c16bdc78cb014e76c0b0dbc6f9
DIFF: https://github.com/llvm/llvm-project/commit/0479c53b6c5224c16bdc78cb014e76c0b0dbc6f9.diff
LOG: [dllimport] Honor always_inline when deciding whether a dllimport function should be available for inlining (PR48925)
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.
Differential revision: https://reviews.llvm.org/D95673
Added:
Modified:
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGenCXX/dllimport.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 31afbc6b4262..c9cf4076579b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3031,7 +3031,7 @@ bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
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));
diff --git a/clang/test/CodeGenCXX/dllimport.cpp b/clang/test/CodeGenCXX/dllimport.cpp
index 1aa5a23ec6ca..6113b28ed5c7 100644
--- a/clang/test/CodeGenCXX/dllimport.cpp
+++ b/clang/test/CodeGenCXX/dllimport.cpp
@@ -386,6 +386,13 @@ __declspec(dllimport) inline void FunctionWithNormalVar() { static int x = 42; }
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
More information about the cfe-commits
mailing list