https://github.com/Prabhuk updated 
https://github.com/llvm/llvm-project/pull/124824

>From 270c260ba8160c71c6602fcb91a635368ee09a88 Mon Sep 17 00:00:00 2001
From: Prabhu Karthikeyan Rajasekaran <prabh...@google.com>
Date: Tue, 28 Jan 2025 19:07:06 +0000
Subject: [PATCH 1/5] [clang] Abort on unsupported uefi triples.

The only architecture currently being supported (still a WIP) is
x86_64. Other UEFI triples targeting other architectures will now
report an error.
---
 clang/lib/Driver/Driver.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 87855fdb799710..f1cd6353234a90 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6677,6 +6677,8 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
       TC = std::make_unique<toolchains::AMDGPUToolChain>(*this, Target, Args);
       break;
     case llvm::Triple::UEFI:
+      if(Target.getArch() != llvm::Triple::x86_64)        
+        llvm::report_fatal_error("Currently the only architecture supported by 
*-uefi triples are x86_64.");
       TC = std::make_unique<toolchains::UEFI>(*this, Target, Args);
       break;
     case llvm::Triple::Win32:

>From 8b5cdb310d299e362ec3191941065876d26c5475 Mon Sep 17 00:00:00 2001
From: prabhukr <prabh...@google.com>
Date: Tue, 28 Jan 2025 19:22:49 +0000
Subject: [PATCH 2/5] Fix formatting

---
 clang/lib/Driver/Driver.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f1cd6353234a90..07362e852d4d9b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6677,8 +6677,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
       TC = std::make_unique<toolchains::AMDGPUToolChain>(*this, Target, Args);
       break;
     case llvm::Triple::UEFI:
-      if(Target.getArch() != llvm::Triple::x86_64)        
-        llvm::report_fatal_error("Currently the only architecture supported by 
*-uefi triples are x86_64.");
+      if (Target.getArch() != llvm::Triple::x86_64)
+        llvm::report_fatal_error("Currently the only architecture supported by 
"
+                                 "*-uefi triples are x86_64.");
       TC = std::make_unique<toolchains::UEFI>(*this, Target, Args);
       break;
     case llvm::Triple::Win32:

>From 4ad52946c35a879e3ef0f6dbf3704fadc7912ca5 Mon Sep 17 00:00:00 2001
From: prabhukr <prabh...@google.com>
Date: Tue, 28 Jan 2025 23:22:01 +0000
Subject: [PATCH 3/5] Replace fatal error with diagnostic error message

---
 clang/lib/Driver/Driver.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 07362e852d4d9b..69981e7b9ca8a0 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -637,6 +637,10 @@ static llvm::Triple computeTargetTriple(const Driver &D,
     }
   }
 
+  // Currently the only architecture supported by *-uefi triples are x86_64.
+  if(Target.isUEFI() && Target.getArch() != llvm::Triple::x86_64)
+    D.Diag(diag::err_target_unknown_triple) << Target.str();
+
   // The `-maix[32|64]` flags are only valid for AIX targets.
   if (Arg *A = Args.getLastArgNoClaim(options::OPT_maix32, 
options::OPT_maix64);
       A && !Target.isOSAIX())
@@ -6677,9 +6681,6 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
       TC = std::make_unique<toolchains::AMDGPUToolChain>(*this, Target, Args);
       break;
     case llvm::Triple::UEFI:
-      if (Target.getArch() != llvm::Triple::x86_64)
-        llvm::report_fatal_error("Currently the only architecture supported by 
"
-                                 "*-uefi triples are x86_64.");
       TC = std::make_unique<toolchains::UEFI>(*this, Target, Args);
       break;
     case llvm::Triple::Win32:

>From aaed75898373c3283fd0c17c88ae7d32e1367dc0 Mon Sep 17 00:00:00 2001
From: prabhukr <prabh...@google.com>
Date: Wed, 29 Jan 2025 14:30:31 +0000
Subject: [PATCH 4/5] fix formatting

---
 clang/lib/Driver/Driver.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 69981e7b9ca8a0..684f7715bf45d2 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -638,7 +638,7 @@ static llvm::Triple computeTargetTriple(const Driver &D,
   }
 
   // Currently the only architecture supported by *-uefi triples are x86_64.
-  if(Target.isUEFI() && Target.getArch() != llvm::Triple::x86_64)
+  if (Target.isUEFI() && Target.getArch() != llvm::Triple::x86_64)
     D.Diag(diag::err_target_unknown_triple) << Target.str();
 
   // The `-maix[32|64]` flags are only valid for AIX targets.

>From cb22bb6ecfa48b41b661aeeaddd6423009260aab Mon Sep 17 00:00:00 2001
From: prabhukr <prabh...@google.com>
Date: Wed, 29 Jan 2025 18:23:39 +0000
Subject: [PATCH 5/5] Add tests

---
 clang/test/Driver/uefi-unsupported-triples.c | 8 ++++++++
 1 file changed, 8 insertions(+)
 create mode 100644 clang/test/Driver/uefi-unsupported-triples.c

diff --git a/clang/test/Driver/uefi-unsupported-triples.c 
b/clang/test/Driver/uefi-unsupported-triples.c
new file mode 100644
index 00000000000000..c315196352a711
--- /dev/null
+++ b/clang/test/Driver/uefi-unsupported-triples.c
@@ -0,0 +1,8 @@
+// RUN: not %clang_cl --target=aarch64-unknown-uefi < %s 2>&1 | FileCheck 
-check-prefixes=CHECK-AARCH64 %s
+// CHECK-AARCH64: error: unknown target triple 'aarch64-unknown-uefi'
+
+// RUN: not %clang_cl --target=arm-unknown-uefi < %s 2>&1 | FileCheck 
-check-prefixes=CHECK-ARM %s
+// CHECK-ARM: error: unknown target triple 'arm-unknown-uefi'
+
+// RUN: not %clang_cl --target=x86-unknown-uefi < %s 2>&1 | FileCheck 
-check-prefixes=CHECK-x86 %s
+// CHECK-x86: error: unknown target triple 'x86-unknown-uefi'

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to