[llvm] [AsmPrinter] Don't compute Darwin triple on non-Darwin (PR #97069)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 28 08:08:43 PDT 2024


https://github.com/aengelke created https://github.com/llvm/llvm-project/pull/97069

There's no point in computing (=parsing) a triple on non-MachO/Darwin platforms.

>From 781de95f0d273a44ffe4c0173fad440612641b38 Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Fri, 28 Jun 2024 16:56:20 +0200
Subject: [PATCH] [AsmPrinter] Don't compute Darwin triple on non-Darwin

There's no point in computing (=parsing) a triple on non-MachO/Darwin
platforms.
---
 llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 2e787f4cd3db0..6d6ceed053fd0 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -478,11 +478,13 @@ bool AsmPrinter::doInitialization(Module &M) {
   // use the directive, where it would need the same conditionalization
   // anyway.
   const Triple &Target = TM.getTargetTriple();
-  Triple TVT(M.getDarwinTargetVariantTriple());
-  OutStreamer->emitVersionForTarget(
-      Target, M.getSDKVersion(),
-      M.getDarwinTargetVariantTriple().empty() ? nullptr : &TVT,
-      M.getDarwinTargetVariantSDKVersion());
+  if (Target.isOSBinFormatMachO() && Target.isOSDarwin()) {
+    Triple TVT(M.getDarwinTargetVariantTriple());
+    OutStreamer->emitVersionForTarget(
+        Target, M.getSDKVersion(),
+        M.getDarwinTargetVariantTriple().empty() ? nullptr : &TVT,
+        M.getDarwinTargetVariantSDKVersion());
+  }
 
   // Allow the target to emit any magic that it wants at the start of the file.
   emitStartOfAsmFile(M);



More information about the llvm-commits mailing list