[llvm-branch-commits] [cfe-branch] r325500 - Merging r325375:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 19 06:07:28 PST 2018


Author: hans
Date: Mon Feb 19 06:07:28 2018
New Revision: 325500

URL: http://llvm.org/viewvc/llvm-project?rev=325500&view=rev
Log:
Merging r325375:
------------------------------------------------------------------------
r325375 | rnk | 2018-02-16 20:44:47 +0100 (Fri, 16 Feb 2018) | 11 lines

[MS] Make constexpr static data members implicitly inline

This handles them exactly the same way that we handle const integral
static data members with inline definitions, which is what MSVC does.

As a follow-up, now that we have a way to mark variables inline in the
AST, we should consider marking them implicitly inline there instead of
only treating them as inline in CodeGen. Unfortunately, this breaks a
lot of dllimport test cases, so that is future work for now.

Fixes PR36125.
------------------------------------------------------------------------

Modified:
    cfe/branches/release_60/   (props changed)
    cfe/branches/release_60/lib/AST/ASTContext.cpp
    cfe/branches/release_60/test/CodeGenCXX/static-data-member.cpp

Propchange: cfe/branches/release_60/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb 19 06:07:28 2018
@@ -1,4 +1,4 @@
 /cfe/branches/type-system-rewrite:134693-134817
-/cfe/trunk:321754,321771,321777,321779,321933,322018,322236,322245-322246,322350,322390,322405,322420,322518,322593,322813,322901,322904,322984,323008,323123,323155,323360,323485,323904,323935,323998,324059,324134,324246,324419,324439,324514,324537,324594
+/cfe/trunk:321754,321771,321777,321779,321933,322018,322236,322245-322246,322350,322390,322405,322420,322518,322593,322813,322901,322904,322984,323008,323123,323155,323360,323485,323904,323935,323998,324059,324134,324246,324419,324439,324514,324537,324594,325375
 /cfe/trunk/test:170344
 /cfe/trunk/test/SemaTemplate:126920

Modified: cfe/branches/release_60/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/lib/AST/ASTContext.cpp?rev=325500&r1=325499&r2=325500&view=diff
==============================================================================
--- cfe/branches/release_60/lib/AST/ASTContext.cpp (original)
+++ cfe/branches/release_60/lib/AST/ASTContext.cpp Mon Feb 19 06:07:28 2018
@@ -5854,7 +5854,7 @@ CharUnits ASTContext::getObjCEncodingTyp
 bool ASTContext::isMSStaticDataMemberInlineDefinition(const VarDecl *VD) const {
   return getTargetInfo().getCXXABI().isMicrosoft() &&
          VD->isStaticDataMember() &&
-         VD->getType()->isIntegralOrEnumerationType() &&
+         (VD->getType()->isIntegralOrEnumerationType() || VD->isConstexpr()) &&
          !VD->getFirstDecl()->isOutOfLine() && VD->getFirstDecl()->hasInit();
 }
 

Modified: cfe/branches/release_60/test/CodeGenCXX/static-data-member.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/release_60/test/CodeGenCXX/static-data-member.cpp?rev=325500&r1=325499&r2=325500&view=diff
==============================================================================
--- cfe/branches/release_60/test/CodeGenCXX/static-data-member.cpp (original)
+++ cfe/branches/release_60/test/CodeGenCXX/static-data-member.cpp Mon Feb 19 06:07:28 2018
@@ -1,6 +1,10 @@
-// RUN: %clang_cc1 -triple x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | \
-// RUN: FileCheck --check-prefix=MACHO %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux -std=c++14 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++14 -emit-llvm -o - %s \
+// RUN:     | FileCheck %s --check-prefix=MACHO
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -std=c++14 -emit-llvm -o - %s \
+// RUN:     | FileCheck %s --check-prefix=MSVC
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -std=c++17 -emit-llvm -o - %s \
+// RUN:     | FileCheck %s --check-prefix=MSVC
 
 // CHECK: @_ZN5test11A1aE = constant i32 10, align 4
 // CHECK: @_ZN5test212_GLOBAL__N_11AIiE1xE = internal global i32 0, align 4
@@ -9,12 +13,25 @@
 // MACHO: @_ZGVN5test31AIiE1xE = weak_odr global i64 0
 // MACHO-NOT: comdat
 
+// MSVC: @"\01?a at A@test1@@2HB" = linkonce_odr constant i32 10, comdat, align 4
+// MSVC: @"\01?i at S@test1@@2HA" = external global i32
+// MSVC: @"\01?x@?$A at H@?A at test2@@2HA" = internal global i32 0, align 4
+
 // CHECK: _ZN5test51U2k0E = global i32 0
 // CHECK: _ZN5test51U2k1E = global i32 0
 // CHECK: _ZN5test51U2k2E = constant i32 76
 // CHECK-NOT: test51U2k3E
 // CHECK-NOT: test51U2k4E
 
+// On Linux in C++14, neither of these are inline.
+// CHECK: @_ZN16inline_constexpr1A10just_constE = available_externally constant i32 42
+// CHECK: @_ZN16inline_constexpr1A10const_exprE = available_externally constant i32 43
+//
+// In MSVC, these are both implicitly inline regardless of the C++ standard
+// version.
+// MSVC: @"\01?just_const at A@inline_constexpr@@2HB" = linkonce_odr constant i32 42, comdat, align 4
+// MSVC: @"\01?const_expr at A@inline_constexpr@@2HB" = linkonce_odr constant i32 43, comdat, align 4
+
 // PR5564.
 namespace test1 {
   struct A {
@@ -28,7 +45,7 @@ namespace test1 {
   };
 
   void f() { 
-    int a = S::i;
+    int a = *&A::a + S::i;
   }
 }
 
@@ -50,6 +67,11 @@ namespace test2 {
   // CHECK:      [[TMP:%.*]] = call i32 @_ZN5test23fooEv()
   // CHECK-NEXT: store i32 [[TMP]], i32* @_ZN5test212_GLOBAL__N_11AIiE1xE, align 4
   // CHECK-NEXT: ret void
+
+  // MSVC-LABEL: define internal void @"\01??__Ex@?$A at H@?A at test2@@2HA at YAXXZ"()
+  // MSVC:      [[TMP:%.*]] = call i32 @"\01?foo at test2@@YAHXZ"()
+  // MSVC-NEXT: store i32 [[TMP]], i32* @"\01?x@?$A at H@?A at test2@@2HA", align 4
+  // MSVC-NEXT: ret void
 }
 
 // Test that we don't use threadsafe statics when initializing
@@ -108,3 +130,13 @@ namespace test5 {
   // CHECK: store i32 {{.*}}, i32* @_ZN5test51U2k1E
   // CHECK-NOT: store {{.*}} i32* @_ZN5test51U2k2E
 }
+
+// Test that MSVC mode static constexpr data members are always inline, even pre
+// C++17.
+namespace inline_constexpr {
+struct A {
+  static const int just_const = 42;
+  static constexpr int const_expr = 43;
+};
+int useit() { return *&A::just_const + *&A::const_expr; }
+}




More information about the llvm-branch-commits mailing list