Index: lib/CodeGen/CodeGenModule.cpp =================================================================== --- lib/CodeGen/CodeGenModule.cpp +++ lib/CodeGen/CodeGenModule.cpp @@ -394,6 +394,22 @@ // Indicate that we want CodeView in the metadata. getModule().addModuleFlag(llvm::Module::Warning, "CodeView", 1); } + if (CodeGenOpts.OptimizationLevel > 0 && CodeGenOpts.StrictVTablePointers) { + // We don't support LTO with 2 with different StrictVTablePointers + // FIXME: we could support it by stripping all the information introduced + // by StrictVTablePointers. + + getModule().addModuleFlag(llvm::Module::Error, "StrictVTablePointers",1); + + llvm::Metadata *Ops[2] = { + llvm::MDString::get(VMContext, "StrictVTablePointers"), + llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( + llvm::Type::getInt32Ty(VMContext), 1))}; + + getModule().addModuleFlag(llvm::Module::Require, + "StrictVTablePointersRequirement", + llvm::MDNode::get(VMContext, Ops)); + } if (DebugInfo) // We support a single version in the linked module. The LLVM // parser will drop debug info with a different version number Index: test/CodeGenCXX/strict-vtable-pointers.cpp =================================================================== --- test/CodeGenCXX/strict-vtable-pointers.cpp +++ test/CodeGenCXX/strict-vtable-pointers.cpp @@ -2,6 +2,7 @@ // RUN: FileCheck --check-prefix=CHECK-CTORS %s < %t.ll // RUN: FileCheck --check-prefix=CHECK-NEW %s < %t.ll // RUN: FileCheck --check-prefix=CHECK-DTORS %s < %t.ll +// RUN: FileCheck --check-prefix=CHECK-LINK-REQ %s < %t.ll typedef __typeof__(sizeof(0)) size_t; void *operator new(size_t, void*) throw(); @@ -191,3 +192,11 @@ // CHECK-DTORS-LABEL: define linkonce_odr void @_ZN14DynamicDerivedD2Ev // CHECK-DTORS-NOT: call i8* @llvm.invariant.group.barrier( // CHECK-DTORS-LABEL: } + + +// CHECK-LINK-REQ: !llvm.module.flags = !{![[FIRST:.*]], ![[SEC:.*]]{{.*}}} + +// CHECK-LINK-REQ: ![[FIRST]] = !{i32 1, !"StrictVTablePointers", i32 1} +// CHECK-LINK-REQ: ![[SEC]] = !{i32 3, !"StrictVTablePointersRequirement", ![[META:.*]]} +// CHECK-LINK-REQ: ![[META]] = !{!"StrictVTablePointers", i32 1} +