From 0d05e31d2016e3b4e294b1b4cfd34938159457c1 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Tue, 13 Sep 2016 22:51:42 +0000 Subject: [PATCH] Also don't inline dllimport functions referring to non-dllimport constructors. The AST walker wasn't visiting CXXConstructExprs before. This is a follow-up to r281395. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@281413 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 6 ++++++ test/CodeGenCXX/PR26569.cpp | 6 +++--- test/CodeGenCXX/dllimport.cpp | 6 +++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 085482b652..8614a00da6 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1693,6 +1693,8 @@ namespace { : public RecursiveASTVisitor { bool SafeToInline = true; + bool shouldVisitImplicitCode() const { return true; } + bool VisitVarDecl(VarDecl *VD) { // A thread-local variable cannot be imported. SafeToInline = !VD->getTLSKind(); @@ -1708,6 +1710,10 @@ namespace { SafeToInline = !V->hasGlobalStorage() || V->hasAttr(); return SafeToInline; } + bool VisitCXXConstructExpr(CXXConstructExpr *E) { + SafeToInline = E->getConstructor()->hasAttr(); + return SafeToInline; + } bool VisitCXXDeleteExpr(CXXDeleteExpr *E) { SafeToInline = E->getOperatorDelete()->hasAttr(); return SafeToInline; diff --git a/test/CodeGenCXX/PR26569.cpp b/test/CodeGenCXX/PR26569.cpp index 3e2d2ffeba..f00b831dd4 100644 --- a/test/CodeGenCXX/PR26569.cpp +++ b/test/CodeGenCXX/PR26569.cpp @@ -1,6 +1,6 @@ // RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -emit-llvm -O1 -disable-llvm-optzns %s -o - | FileCheck %s -class A { +class __declspec(dllimport) A { virtual void m_fn1(); }; template @@ -11,10 +11,10 @@ class __declspec(dllexport) C : B {}; // CHECK-DAG: @[[VTABLE_C:.*]] = private unnamed_addr constant [2 x i8*] [i8* bitcast (%rtti.CompleteObjectLocator* @"\01??_R4C@@6B@" to i8*), i8* bitcast (void (%class.A*)* @"\01?m_fn1@A@@EAEXXZ" to i8*)] // CHECK-DAG: @[[VTABLE_B:.*]] = private unnamed_addr constant [2 x i8*] [i8* bitcast (%rtti.CompleteObjectLocator* @"\01??_R4?$B@H@@6B@" to i8*), i8* bitcast (void (%class.A*)* @"\01?m_fn1@A@@EAEXXZ" to i8*)], comdat($"\01??_S?$B@H@@6B@") -// CHECK-DAG: @[[VTABLE_A:.*]] = private unnamed_addr constant [2 x i8*] [i8* bitcast (%rtti.CompleteObjectLocator* @"\01??_R4A@@6B@" to i8*), i8* bitcast (void (%class.A*)* @"\01?m_fn1@A@@EAEXXZ" to i8*)], comdat($"\01??_7A@@6B@") +// CHECK-DAG: @[[VTABLE_A:.*]] = private unnamed_addr constant [2 x i8*] [i8* bitcast (%rtti.CompleteObjectLocator* @"\01??_R4A@@6B@" to i8*), i8* bitcast (void (%class.A*)* @"\01?m_fn1@A@@EAEXXZ" to i8*)], comdat($"\01??_SA@@6B@") // CHECK-DAG: @"\01??_7C@@6B@" = dllexport unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* @[[VTABLE_C]], i32 0, i32 1) // CHECK-DAG: @"\01??_S?$B@H@@6B@" = unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* @[[VTABLE_B]], i32 0, i32 1) -// CHECK-DAG: @"\01??_7A@@6B@" = unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* @[[VTABLE_A]], i32 0, i32 1) +// CHECK-DAG: @"\01??_SA@@6B@" = unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* @[[VTABLE_A]], i32 0, i32 1) // CHECK-DAG: @"\01??_8?$B@H@@7B@" = available_externally dllimport unnamed_addr constant [2 x i32] [i32 0, i32 4] diff --git a/test/CodeGenCXX/dllimport.cpp b/test/CodeGenCXX/dllimport.cpp index 1a24e34318..ec5c68aadf 100644 --- a/test/CodeGenCXX/dllimport.cpp +++ b/test/CodeGenCXX/dllimport.cpp @@ -354,6 +354,10 @@ USECLASS(ClassWithNonDllImportField); USECLASS(ClassWithNonDllImportBase); // MO1-DAG: declare dllimport x86_thiscallcc void @"\01??1ClassWithNonDllImportBase@@QAE@XZ"(%struct.ClassWithNonDllImportBase*) // MO1-DAG: declare dllimport x86_thiscallcc void @"\01??1ClassWithNonDllImportField@@QAE@XZ"(%struct.ClassWithNonDllImportField*) +struct ClassWithCtor { ClassWithCtor() {} }; +struct __declspec(dllimport) ClassWithNonDllImportFieldWithCtor { ClassWithCtor t; }; +USECLASS(ClassWithNonDllImportFieldWithCtor); +// MO1-DAG: declare dllimport x86_thiscallcc %struct.ClassWithNonDllImportFieldWithCtor* @"\01??0ClassWithNonDllImportFieldWithCtor@@QAE@XZ"(%struct.ClassWithNonDllImportFieldWithCtor* returned) // A dllimport function with a TLS variable must not be available_externally. __declspec(dllimport) inline void FunctionWithTLSVar() { static __thread int x = 42; } @@ -665,7 +669,7 @@ namespace Vtordisp { // Don't dllimport the vtordisp. // MO1-DAG: define linkonce_odr x86_thiscallcc void @"\01?f@?$C@H@Vtordisp@@$4PPPPPPPM@A@AEXXZ" - class Base { + class __declspec(dllimport) Base { virtual void f() {} }; template -- 2.40.0