espindola created this revision.
espindola added reviewers: rnk, echristo, eli.friedman.

https://reviews.llvm.org/D44712

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCXX/ubsan-vtable-checks.cpp


Index: test/CodeGenCXX/ubsan-vtable-checks.cpp
===================================================================
--- test/CodeGenCXX/ubsan-vtable-checks.cpp
+++ test/CodeGenCXX/ubsan-vtable-checks.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux -emit-llvm 
-fsanitize=null %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-NULL --check-prefix=ITANIUM
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-windows -emit-llvm 
-fsanitize=null %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-NULL --check-prefix=MSABI
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux -emit-llvm 
-fsanitize=null,vptr %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-VPTR --check-prefix=ITANIUM
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-windows -emit-llvm 
-fsanitize=null,vptr %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-VPTR --check-prefix=MSABI
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-windows -emit-llvm 
-fsanitize=null,vptr %s -o - | FileCheck %s --check-prefix=CHECK 
--check-prefix=CHECK-VPTR --check-prefix=MSABI  --check-prefix=CHECK-VPTR-MS
 struct T {
   virtual ~T() {}
   virtual int v() { return 1; }
@@ -14,6 +14,8 @@
 
 U::~U() {}
 
+// CHECK-VPTR-MS: @__ubsan_vptr_type_cache = external dso_local
+
 // ITANIUM: define i32 @_Z5get_vP1T
 // MSABI: define dso_local i32 @"?get_v
 int get_v(T* t) {
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2953,7 +2953,10 @@
 llvm::Constant *
 CodeGenModule::CreateRuntimeVariable(llvm::Type *Ty,
                                      StringRef Name) {
-  return GetOrCreateLLVMGlobal(Name, llvm::PointerType::getUnqual(Ty), 
nullptr);
+  auto *Ret =
+      GetOrCreateLLVMGlobal(Name, llvm::PointerType::getUnqual(Ty), nullptr);
+  setDSOLocal(cast<llvm::GlobalValue>(Ret->stripPointerCasts()));
+  return Ret;
 }
 
 void CodeGenModule::EmitTentativeDefinition(const VarDecl *D) {


Index: test/CodeGenCXX/ubsan-vtable-checks.cpp
===================================================================
--- test/CodeGenCXX/ubsan-vtable-checks.cpp
+++ test/CodeGenCXX/ubsan-vtable-checks.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux -emit-llvm -fsanitize=null %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NULL --check-prefix=ITANIUM
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-windows -emit-llvm -fsanitize=null %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NULL --check-prefix=MSABI
 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-linux -emit-llvm -fsanitize=null,vptr %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-VPTR --check-prefix=ITANIUM
-// RUN: %clang_cc1 -std=c++11 -triple x86_64-windows -emit-llvm -fsanitize=null,vptr %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-VPTR --check-prefix=MSABI
+// RUN: %clang_cc1 -std=c++11 -triple x86_64-windows -emit-llvm -fsanitize=null,vptr %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-VPTR --check-prefix=MSABI  --check-prefix=CHECK-VPTR-MS
 struct T {
   virtual ~T() {}
   virtual int v() { return 1; }
@@ -14,6 +14,8 @@
 
 U::~U() {}
 
+// CHECK-VPTR-MS: @__ubsan_vptr_type_cache = external dso_local
+
 // ITANIUM: define i32 @_Z5get_vP1T
 // MSABI: define dso_local i32 @"?get_v
 int get_v(T* t) {
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2953,7 +2953,10 @@
 llvm::Constant *
 CodeGenModule::CreateRuntimeVariable(llvm::Type *Ty,
                                      StringRef Name) {
-  return GetOrCreateLLVMGlobal(Name, llvm::PointerType::getUnqual(Ty), nullptr);
+  auto *Ret =
+      GetOrCreateLLVMGlobal(Name, llvm::PointerType::getUnqual(Ty), nullptr);
+  setDSOLocal(cast<llvm::GlobalValue>(Ret->stripPointerCasts()));
+  return Ret;
 }
 
 void CodeGenModule::EmitTentativeDefinition(const VarDecl *D) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D44712: ... Rafael Avila de Espindola via Phabricator via cfe-commits

Reply via email to