[clang] [Driver][AVR] Reject c/c++ compilation for avr1 devices (PR #111798)

Ben Shi via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 10 00:37:41 PDT 2024


https://github.com/benshi001 updated https://github.com/llvm/llvm-project/pull/111798

>From 437fbfb157882469ffa576a023f39399fc82f69c Mon Sep 17 00:00:00 2001
From: Ben Shi <bennshi at tencent.com>
Date: Thu, 10 Oct 2024 15:31:19 +0800
Subject: [PATCH] [Driver][AVR] Reject c/c++ compilation for avr1 devices

avr-gcc also rejects since these devices has no SRAM.

Fixes https://github.com/llvm/llvm-project/issues/96881
---
 clang/lib/Driver/ToolChains/AVR.cpp | 8 ++++++++
 clang/test/Driver/avr-mmcu.c        | 5 ++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp
index bb5c0e6db9978e..83a756b07056ca 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -400,6 +400,14 @@ void AVRToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
 void AVRToolChain::addClangTargetOptions(
     const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
     Action::OffloadKind DeviceOffloadKind) const {
+  // Reject C/C++ compilation for avr1 devices.
+  const Driver &D = getDriver();
+  std::string CPU = getCPUName(D, DriverArgs, getTriple());
+  std::optional<StringRef> FamilyName = GetMCUFamilyName(CPU);
+  if (CPU == "avr1" || (FamilyName && FamilyName->compare("avr1") == 0))
+    D.Diag(diag::err_drv_opt_unsupported_input_type) << "avr1"
+                                                     << "c/c++";
+
   // By default, use `.ctors` (not `.init_array`), as required by libgcc, which
   // runs constructors/destructors on AVR.
   if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
diff --git a/clang/test/Driver/avr-mmcu.c b/clang/test/Driver/avr-mmcu.c
index 6c13ab5b68d3b9..e354917ae9ab1d 100644
--- a/clang/test/Driver/avr-mmcu.c
+++ b/clang/test/Driver/avr-mmcu.c
@@ -1,8 +1,7 @@
 // A test for the propagation of the -mmcu option to -cc1 and -cc1as
 
-// RUN: %clang -### --target=avr -mmcu=attiny11 -save-temps %s 2>&1 | FileCheck -check-prefix=CHECK0 %s
-// CHECK0: "-cc1" {{.*}} "-target-cpu" "attiny11"
-// CHECK0: "-cc1as" {{.*}} "-target-cpu" "attiny11"
+// RUN: not %clang -### --target=avr -mmcu=attiny11 %s 2>&1 | FileCheck -check-prefix=CHECK0 %s
+// CHECK0: error: 'avr1' invalid for input of type c/c++
 
 // RUN: %clang -### --target=avr -mmcu=at90s2313 -save-temps %s 2>&1 | FileCheck -check-prefix=CHECK1 %s
 // CHECK1: "-cc1" {{.*}} "-target-cpu" "at90s2313"



More information about the cfe-commits mailing list