[PATCH] [MSVC] Handle out-of-line definition of static data member correctly (fix for http://llvm.org/PR21164)
Reid Kleckner
rnk at google.com
Tue May 19 09:41:37 PDT 2015
REPOSITORY
rL LLVM
================
Comment at: lib/AST/ASTContext.cpp:4910
@@ -4910,1 +4909,3 @@
+ !VD->getFirstDecl()->isOutOfLine() && VD->getFirstDecl()->hasInit() &&
+ VD->getFirstDecl() == VD;
}
----------------
Can the last two lines be simplified to this?
VD->isFirstDecl() && VD->hasInit()
The first declaration of a static data member cannot be out of line, unless I'm mistaken.
================
Comment at: test/CodeGenCXX/dllexport-members.cpp:113-115
@@ -112,5 +112,5 @@
// MSC-DAG: @"\01?StaticConstField at ExportMembers@@2HB" = dllexport constant i32 1, align 4
- // MSC-DAG: @"\01?StaticConstFieldEqualInit at ExportMembers@@2HB" = weak_odr dllexport constant i32 1, comdat, align 4
- // MSC-DAG: @"\01?StaticConstFieldBraceInit at ExportMembers@@2HB" = weak_odr dllexport constant i32 1, comdat, align 4
- // MSC-DAG: @"\01?ConstexprField at ExportMembers@@2HB" = weak_odr dllexport constant i32 1, comdat, align 4
// GNU-DAG: @_ZN13ExportMembers11StaticFieldE = dllexport global i32 1, align 4
----------------
Can you add at least one test here that exercises the weak_odr linkage case? Do something like this, where the member is referenced but not defined outside the class:
struct A { static const int V = 42; };
int f() { return A::V; }
================
Comment at: test/CodeGenCXX/ms-integer-static-data-members.cpp:1-10
@@ -1,5 +1,11 @@
-// RUN: %clang_cc1 -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s
-// RUN: %clang_cc1 -DINLINE_INIT -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s --check-prefix=CHECK-INLINE
+// RUN: %clang_cc1 -DREFERENCED -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s
+
+// RUN: %clang_cc1 -DINLINE_INIT -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s --check-prefix=CHECK-INLINE-NODEF-NOTREF
+// RUN: %clang_cc1 -DINLINE_INIT -DREFERENCED -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s --check-prefix=CHECK-INLINE-NODEF-REF
+
+// RUN: %clang_cc1 -DINLINE_INIT -DREAL_DEFINITION -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s --check-prefix=CHECK-INLINE-DEF-NOTREF
+// RUN: %clang_cc1 -DINLINE_INIT -DREAL_DEFINITION -DREFERENCED -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s --check-prefix=CHECK-INLINE-DEF-REF
+
// RUN: %clang_cc1 -DREAL_DEFINITION -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s --check-prefix=CHECK-OUTOFLINE
-// RUN: %clang_cc1 -DINLINE_INIT -DREAL_DEFINITION -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s --check-prefix=CHECK-INLINE
+// RUN: %clang_cc1 -DREAL_DEFINITION -DREFERENCED -emit-llvm -triple=i386-pc-win32 -fms-compatibility %s -o - | FileCheck %s --check-prefix=CHECK-OUTOFLINE
----------------
I think the explosion in RUN lines here is getting out of hand. We can test all the cases in a single TU if we just have multiple static data members in S. Do you mind doing that cleanup?
http://reviews.llvm.org/D9850
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
More information about the cfe-commits
mailing list