tejohnson updated this revision to Diff 240395.
tejohnson added a comment.

Improve test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73418/new/

https://reviews.llvm.org/D73418

Files:
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp


Index: clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
===================================================================
--- clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
+++ clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm 
-fvirtual-function-elimination -fwhole-program-vtables -o - %s | FileCheck %s 
--check-prefix=CHECK --check-prefix=CHECK-VFE
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm 
-fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-NOVFE
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -emit-llvm 
-fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK-MS 
--check-prefix=CHECK-NOVFE
 
 // Check that in ThinLTO we also get vcall_visibility summary entries in the 
bitcode
 // RUN: %clang_cc1 -flto=thin -flto-unit -triple x86_64-unknown-linux 
-emit-llvm-bc -fwhole-program-vtables -o - %s | llvm-dis -o - | FileCheck %s 
--check-prefix=CHECK --check-prefix=CHECK-NOVFE --check-prefix=CHECK-SUMMARY
@@ -8,6 +9,7 @@
 // Anonymous namespace.
 namespace {
 // CHECK: @_ZTVN12_GLOBAL__N_11AE = {{.*}} !vcall_visibility [[VIS_TU:![0-9]+]]
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant 
{{.*}}struct.(anonymous namespace)::A{{.*}} !vcall_visibility [[VIS_TU:![0-9]+]]
 struct A {
   A() {}
   virtual int f() { return 1; }
@@ -20,6 +22,7 @@
 
 // Hidden visibility.
 // CHECK: @_ZTV1B = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.B{{.*}} 
!vcall_visibility [[VIS_DSO:![0-9]+]]
 struct __attribute__((visibility("hidden"))) B {
   B() {}
   virtual int f() { return 1; }
@@ -31,6 +34,8 @@
 
 // Default visibility.
 // CHECK-NOT: @_ZTV1C = {{.*}} !vcall_visibility
+// On MS default is hidden
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.C{{.*}} 
!vcall_visibility [[VIS_DSO]]
 struct __attribute__((visibility("default"))) C {
   C() {}
   virtual int f() { return 1; }
@@ -42,6 +47,7 @@
 
 // Hidden visibility, public LTO visibility.
 // CHECK-NOT: @_ZTV1D = {{.*}} !vcall_visibility
+// CHECK-MS-NOT: @anon.{{.*}} = private unnamed_addr constant 
{{.*}}struct.D{{.*}} !vcall_visibility
 struct __attribute__((visibility("hidden"))) [[clang::lto_visibility_public]] 
D {
   D() {}
   virtual int f() { return 1; }
@@ -53,6 +59,8 @@
 
 // Hidden visibility, but inherits from class with default visibility.
 // CHECK-NOT: @_ZTV1E = {{.*}} !vcall_visibility
+// On MS default is hidden
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.E{{.*}} 
!vcall_visibility [[VIS_DSO]]
 struct __attribute__((visibility("hidden"))) E : C {
   E() {}
   virtual int f() { return 1; }
@@ -64,6 +72,8 @@
 
 // Anonymous namespace, but inherits from class with default visibility.
 // CHECK-NOT: @_ZTVN12_GLOBAL__N_11FE = {{.*}} !vcall_visibility
+// On MS default is hidden
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant 
{{.*}}struct.(anonymous namespace)::F{{.*}} !vcall_visibility [[VIS_DSO]]
 namespace {
 struct __attribute__((visibility("hidden"))) F : C {
   F() {}
@@ -77,6 +87,7 @@
 
 // Anonymous namespace, but inherits from class with hidden visibility.
 // CHECK: @_ZTVN12_GLOBAL__N_11GE = {{.*}} !vcall_visibility 
[[VIS_DSO:![0-9]+]]
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant 
{{.*}}struct.(anonymous namespace)::G{{.*}} !vcall_visibility [[VIS_DSO]]
 namespace {
 struct __attribute__((visibility("hidden"))) G : B {
   G() {}
@@ -87,6 +98,8 @@
   return new G();
 }
 
+// CHECK-MS-DAG: [[VIS_DSO]] = !{i64 1}
+// CHECK-MS-DAG: [[VIS_TU]] = !{i64 2}
 // CHECK-DAG: [[VIS_DSO]] = !{i64 1}
 // CHECK-DAG: [[VIS_TU]] = !{i64 2}
 // CHECK-VFE-DAG: !{i32 1, !"Virtual Function Elim", i32 1}
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===================================================================
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1621,6 +1621,15 @@
   if (!CGM.getCodeGenOpts().LTOUnit)
     return;
 
+  // TODO: Should VirtualFunctionElimination also be supported here?
+  // See similar handling in CodeGenModule::EmitVTableTypeMetadata.
+  if (CGM.getCodeGenOpts().WholeProgramVTables) {
+    llvm::GlobalObject::VCallVisibility TypeVis =
+        CGM.GetVCallVisibilityLevel(RD);
+    if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
+      VTable->setVCallVisibilityMetadata(TypeVis);
+  }
+
   // The location of the first virtual function pointer in the virtual table,
   // aka the "address point" on Itanium. This is at offset 0 if RTTI is
   // disabled, or sizeof(void*) if RTTI is enabled.


Index: clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
===================================================================
--- clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
+++ clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm -fvirtual-function-elimination -fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-VFE
 // RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm -fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOVFE
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-pc-windows-msvc -emit-llvm -fwhole-program-vtables -o - %s | FileCheck %s --check-prefix=CHECK-MS --check-prefix=CHECK-NOVFE
 
 // Check that in ThinLTO we also get vcall_visibility summary entries in the bitcode
 // RUN: %clang_cc1 -flto=thin -flto-unit -triple x86_64-unknown-linux -emit-llvm-bc -fwhole-program-vtables -o - %s | llvm-dis -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOVFE --check-prefix=CHECK-SUMMARY
@@ -8,6 +9,7 @@
 // Anonymous namespace.
 namespace {
 // CHECK: @_ZTVN12_GLOBAL__N_11AE = {{.*}} !vcall_visibility [[VIS_TU:![0-9]+]]
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.(anonymous namespace)::A{{.*}} !vcall_visibility [[VIS_TU:![0-9]+]]
 struct A {
   A() {}
   virtual int f() { return 1; }
@@ -20,6 +22,7 @@
 
 // Hidden visibility.
 // CHECK: @_ZTV1B = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.B{{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
 struct __attribute__((visibility("hidden"))) B {
   B() {}
   virtual int f() { return 1; }
@@ -31,6 +34,8 @@
 
 // Default visibility.
 // CHECK-NOT: @_ZTV1C = {{.*}} !vcall_visibility
+// On MS default is hidden
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.C{{.*}} !vcall_visibility [[VIS_DSO]]
 struct __attribute__((visibility("default"))) C {
   C() {}
   virtual int f() { return 1; }
@@ -42,6 +47,7 @@
 
 // Hidden visibility, public LTO visibility.
 // CHECK-NOT: @_ZTV1D = {{.*}} !vcall_visibility
+// CHECK-MS-NOT: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.D{{.*}} !vcall_visibility
 struct __attribute__((visibility("hidden"))) [[clang::lto_visibility_public]] D {
   D() {}
   virtual int f() { return 1; }
@@ -53,6 +59,8 @@
 
 // Hidden visibility, but inherits from class with default visibility.
 // CHECK-NOT: @_ZTV1E = {{.*}} !vcall_visibility
+// On MS default is hidden
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.E{{.*}} !vcall_visibility [[VIS_DSO]]
 struct __attribute__((visibility("hidden"))) E : C {
   E() {}
   virtual int f() { return 1; }
@@ -64,6 +72,8 @@
 
 // Anonymous namespace, but inherits from class with default visibility.
 // CHECK-NOT: @_ZTVN12_GLOBAL__N_11FE = {{.*}} !vcall_visibility
+// On MS default is hidden
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.(anonymous namespace)::F{{.*}} !vcall_visibility [[VIS_DSO]]
 namespace {
 struct __attribute__((visibility("hidden"))) F : C {
   F() {}
@@ -77,6 +87,7 @@
 
 // Anonymous namespace, but inherits from class with hidden visibility.
 // CHECK: @_ZTVN12_GLOBAL__N_11GE = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
+// CHECK-MS: @anon.{{.*}} = private unnamed_addr constant {{.*}}struct.(anonymous namespace)::G{{.*}} !vcall_visibility [[VIS_DSO]]
 namespace {
 struct __attribute__((visibility("hidden"))) G : B {
   G() {}
@@ -87,6 +98,8 @@
   return new G();
 }
 
+// CHECK-MS-DAG: [[VIS_DSO]] = !{i64 1}
+// CHECK-MS-DAG: [[VIS_TU]] = !{i64 2}
 // CHECK-DAG: [[VIS_DSO]] = !{i64 1}
 // CHECK-DAG: [[VIS_TU]] = !{i64 2}
 // CHECK-VFE-DAG: !{i32 1, !"Virtual Function Elim", i32 1}
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===================================================================
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1621,6 +1621,15 @@
   if (!CGM.getCodeGenOpts().LTOUnit)
     return;
 
+  // TODO: Should VirtualFunctionElimination also be supported here?
+  // See similar handling in CodeGenModule::EmitVTableTypeMetadata.
+  if (CGM.getCodeGenOpts().WholeProgramVTables) {
+    llvm::GlobalObject::VCallVisibility TypeVis =
+        CGM.GetVCallVisibilityLevel(RD);
+    if (TypeVis != llvm::GlobalObject::VCallVisibilityPublic)
+      VTable->setVCallVisibilityMetadata(TypeVis);
+  }
+
   // The location of the first virtual function pointer in the virtual table,
   // aka the "address point" on Itanium. This is at offset 0 if RTTI is
   // disabled, or sizeof(void*) if RTTI is enabled.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to