[PS4][clang] Fix -funified-lto/-flto-unit default on PS4
authorMatthew Voss <matthew.voss@sony.com>
Wed, 12 Jul 2023 22:32:40 +0000 (15:32 -0700)
committerMatthew Voss <matthew.voss@sony.com>
Wed, 12 Jul 2023 22:32:40 +0000 (15:32 -0700)
If -funified-lto was specified but -flto was not, we would end up with a
situation where the driver thought that Unified LTO was enabled, but the
flag was not passed to the frontend. The check disabling -flto-unit for
PS4 should use the correct method to check for the target. This only
effects PS targets.

clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/lto-unit.c

index 7abd03a..ce0e3aa 100644 (file)
@@ -4776,10 +4776,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   // Select the appropriate action.
   RewriteKind rewriteKind = RK_None;
 
-  bool UnifiedLTO =  Triple.isPS();;
+  bool UnifiedLTO = false;
   if (IsUsingLTO) {
     UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
-                              options::OPT_fno_unified_lto, false);
+                              options::OPT_fno_unified_lto, Triple.isPS());
     if (UnifiedLTO)
       CmdArgs.push_back("-funified-lto");
   }
@@ -4930,7 +4930,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
             Twine("-flto=") + (LTOMode == LTOK_Thin ? "thin" : "full")));
         // PS4 uses the legacy LTO API, which does not support some of the
         // features enabled by -flto-unit.
-        if ((RawTriple.getOS() != llvm::Triple::PS4) ||
+        if (!RawTriple.isPS4() ||
             (D.getLTOMode() == LTOK_Full) || !UnifiedLTO)
           CmdArgs.push_back("-flto-unit");
       }
index 14eadaf..b2edb5e 100644 (file)
@@ -2,8 +2,8 @@
 // RUN: %clang --target=x86_64-unknown-linux -### %s -flto=thin 2>&1 | FileCheck --check-prefix=UNIT %s
 // RUN: %clang --target=x86_64-apple-darwin13.3.0 -### %s -flto=full 2>&1 | FileCheck --check-prefix=UNIT %s
 // RUN: %clang --target=x86_64-apple-darwin13.3.0 -### %s -flto=thin 2>&1 | FileCheck --check-prefix=UNIT %s
-// RUN: %clang --target=x86_64-scei-ps4 -### %s -flto=full 2>&1 | FileCheck --check-prefix=UNIT %s
-// RUN: %clang --target=x86_64-scei-ps4 -### %s -flto=thin 2>&1 | FileCheck --check-prefix=UNIT %s
+// RUN: %clang --target=x86_64-scei-ps4 -### %s -flto=full -fno-unified-lto 2>&1 | FileCheck --check-prefix=UNIT %s
+// RUN: %clang --target=x86_64-scei-ps4 -### %s -flto=thin -fno-unified-lto 2>&1 | FileCheck --check-prefix=UNIT %s
 // RUN: %clang --target=x86_64-scei-ps4 -### %s -flto=full -funified-lto 2>&1 | FileCheck --check-prefix=UNIT %s
 // RUN: %clang --target=x86_64-scei-ps4 -### %s -flto=thin -funified-lto 2>&1 | FileCheck --check-prefix=NOUNIT %s
 // RUN: %clang --target=x86_64-unknown-linux -### %s -flto=full -funified-lto 2>&1 | FileCheck --check-prefix=UNIT %s