Index: include/llvm/Target/TargetMachine.h =================================================================== --- include/llvm/Target/TargetMachine.h +++ include/llvm/Target/TargetMachine.h @@ -133,6 +133,16 @@ /// Create a DataLayout. const DataLayout createDataLayout() const { return DL; } + /// Test if a DataLayout if compatible with the CodeGen for this target. + /// + /// The LLVM Module owns a DataLayout that is used for the target independent + /// optimizations and will be used for the CodeGen. This hook provide a target + /// specific check on the validity of this DataLayout. The default + /// implementation just check for an exact match but Targets can override it. + virtual bool isCompatibleDataLayout(const DataLayout &Candidate) const { + return DL == Candidate; + } + /// Get the pointer size for this target. /// /// This is the only time the DataLayout in the TargetMachine is used. Index: lib/CodeGen/MachineFunction.cpp =================================================================== --- lib/CodeGen/MachineFunction.cpp +++ lib/CodeGen/MachineFunction.cpp @@ -85,6 +85,10 @@ FunctionNumber = FunctionNum; JumpTableInfo = nullptr; + + assert(TM.isCompatibleDataLayout(getDataLayout()) && + "Can't create a MachineFunction using a Module with a " + "Target-incompatible DataLayout attached\n"); } MachineFunction::~MachineFunction() {