r309635 - Re-apply r309622 with a fix for MSVC.
Peter Collingbourne via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 31 15:35:33 PDT 2017
Author: pcc
Date: Mon Jul 31 15:35:33 2017
New Revision: 309635
URL: http://llvm.org/viewvc/llvm-project?rev=309635&view=rev
Log:
Re-apply r309622 with a fix for MSVC.
Patch by Vlad Tsyrklevich!
Added:
cfe/trunk/test/CodeGenCXX/cfi-vcall-no-trap.cpp
Modified:
cfe/trunk/lib/CodeGen/CGClass.cpp
Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=309635&r1=309634&r2=309635&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Jul 31 15:35:33 2017
@@ -2523,8 +2523,10 @@ LeastDerivedClassWithSameLayout(const CX
void CodeGenFunction::EmitTypeMetadataCodeForVCall(const CXXRecordDecl *RD,
llvm::Value *VTable,
SourceLocation Loc) {
- if (CGM.getCodeGenOpts().WholeProgramVTables &&
- CGM.HasHiddenLTOVisibility(RD)) {
+ if (SanOpts.has(SanitizerKind::CFIVCall))
+ EmitVTablePtrCheckForCall(RD, VTable, CodeGenFunction::CFITCK_VCall, Loc);
+ else if (CGM.getCodeGenOpts().WholeProgramVTables &&
+ CGM.HasHiddenLTOVisibility(RD)) {
llvm::Metadata *MD =
CGM.CreateMetadataIdentifierForType(QualType(RD->getTypeForDecl(), 0));
llvm::Value *TypeId =
@@ -2536,9 +2538,6 @@ void CodeGenFunction::EmitTypeMetadataCo
{CastedVTable, TypeId});
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::assume), TypeTest);
}
-
- if (SanOpts.has(SanitizerKind::CFIVCall))
- EmitVTablePtrCheckForCall(RD, VTable, CodeGenFunction::CFITCK_VCall, Loc);
}
void CodeGenFunction::EmitVTablePtrCheckForCall(const CXXRecordDecl *RD,
Added: cfe/trunk/test/CodeGenCXX/cfi-vcall-no-trap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cfi-vcall-no-trap.cpp?rev=309635&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cfi-vcall-no-trap.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/cfi-vcall-no-trap.cpp Mon Jul 31 15:35:33 2017
@@ -0,0 +1,15 @@
+// Only output llvm.assume(llvm.type.test()) if cfi-vcall is disabled and whole-program-vtables is enabled
+// RUN: %clang_cc1 -flto -fvisibility hidden -fsanitize=cfi-vcall -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=CFI %s
+// RUN: %clang_cc1 -flto -fvisibility hidden -fwhole-program-vtables -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=NOCFI %s
+
+struct S1 {
+ virtual void f();
+};
+
+// CHECK: define{{.*}}s1f
+// CHECK: llvm.type.test
+// CFI-NOT: llvm.assume
+// NOCFI: llvm.assume
+void s1f(S1 *s1) {
+ s1->f();
+}
More information about the cfe-commits
mailing list