[clang] 4bf6e83 - [clang][Driver][AVR] Reject c/c++ compilation for avr1 devices (#111798)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 14 04:09:02 PDT 2024
Author: Ben Shi
Date: 2024-10-14T19:08:58+08:00
New Revision: 4bf6e831d554b7a075a5f1c4c34a38b05e20ec3b
URL: https://github.com/llvm/llvm-project/commit/4bf6e831d554b7a075a5f1c4c34a38b05e20ec3b
DIFF: https://github.com/llvm/llvm-project/commit/4bf6e831d554b7a075a5f1c4c34a38b05e20ec3b.diff
LOG: [clang][Driver][AVR] Reject c/c++ compilation for avr1 devices (#111798)
avr-gcc also rejects since these devices has no SRAM.
Fixes https://github.com/llvm/llvm-project/issues/96881
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Driver/ToolChains/AVR.cpp
clang/test/Driver/avr-mmcu.c
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 202c3ee98ed2be..36cf1d8a14db9f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -633,6 +633,8 @@ WebAssembly Support
AVR Support
^^^^^^^^^^^
+- Reject C/C++ compilation for avr1 devices which have no SRAM.
+
DWARF Support in Clang
----------------------
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp
index bb5c0e6db9978e..08e906ac9e8067 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 since they have no SRAM.
+ const Driver &D = getDriver();
+ std::string CPU = getCPUName(D, DriverArgs, getTriple());
+ std::optional<StringRef> FamilyName = GetMCUFamilyName(CPU);
+ if (CPU == "avr1" || (FamilyName && *FamilyName == "avr1"))
+ D.Diag(diag::err_drv_opt_unsupported_input_type)
+ << "-mmcu=" + CPU << "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..0edb05dad136ab 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: '-mmcu=attiny11' 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