Override the datalayout in a module with -triple.
This matches llc's behavior.
Before this patch clang would create a TargetInfo base on -triple but a llvm
CodeGen based on the triple in the module.
llvm-svn: 197837
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 047dc53..6fceabd 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -419,9 +419,18 @@
CI.getDiagnostics().Report(Loc, DiagID);
return;
}
+ const TargetOptions &TargetOpts = CI.getTargetOpts();
+ if (TheModule->getTargetTriple() != TargetOpts.Triple) {
+ unsigned DiagID = CI.getDiagnostics().getCustomDiagID(
+ DiagnosticsEngine::Warning,
+ "overriding the module target triple with %0");
+
+ CI.getDiagnostics().Report(SourceLocation(), DiagID) << TargetOpts.Triple;
+ TheModule->setTargetTriple(TargetOpts.Triple);
+ }
EmitBackendOutput(CI.getDiagnostics(), CI.getCodeGenOpts(),
- CI.getTargetOpts(), CI.getLangOpts(),
+ TargetOpts, CI.getLangOpts(),
TheModule.get(),
BA, OS);
return;