Skip to content

Commit 4bf6e83

Browse files
authored
[clang][Driver][AVR] Reject c/c++ compilation for avr1 devices (llvm#111798)
avr-gcc also rejects since these devices has no SRAM. Fixes llvm#96881
1 parent 5af8cec commit 4bf6e83

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,8 @@ WebAssembly Support
633633
AVR Support
634634
^^^^^^^^^^^
635635

636+
- Reject C/C++ compilation for avr1 devices which have no SRAM.
637+
636638
DWARF Support in Clang
637639
----------------------
638640

clang/lib/Driver/ToolChains/AVR.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,14 @@ void AVRToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
400400
void AVRToolChain::addClangTargetOptions(
401401
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
402402
Action::OffloadKind DeviceOffloadKind) const {
403+
// Reject C/C++ compilation for avr1 devices since they have no SRAM.
404+
const Driver &D = getDriver();
405+
std::string CPU = getCPUName(D, DriverArgs, getTriple());
406+
std::optional<StringRef> FamilyName = GetMCUFamilyName(CPU);
407+
if (CPU == "avr1" || (FamilyName && *FamilyName == "avr1"))
408+
D.Diag(diag::err_drv_opt_unsupported_input_type)
409+
<< "-mmcu=" + CPU << "c/c++";
410+
403411
// By default, use `.ctors` (not `.init_array`), as required by libgcc, which
404412
// runs constructors/destructors on AVR.
405413
if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,

clang/test/Driver/avr-mmcu.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// A test for the propagation of the -mmcu option to -cc1 and -cc1as
22

3-
// RUN: %clang -### --target=avr -mmcu=attiny11 -save-temps %s 2>&1 | FileCheck -check-prefix=CHECK0 %s
4-
// CHECK0: "-cc1" {{.*}} "-target-cpu" "attiny11"
5-
// CHECK0: "-cc1as" {{.*}} "-target-cpu" "attiny11"
3+
// RUN: not %clang -### --target=avr -mmcu=attiny11 %s 2>&1 | FileCheck -check-prefix=CHECK0 %s
4+
// CHECK0: error: '-mmcu=attiny11' invalid for input of type c/c++
65

76
// RUN: %clang -### --target=avr -mmcu=at90s2313 -save-temps %s 2>&1 | FileCheck -check-prefix=CHECK1 %s
87
// CHECK1: "-cc1" {{.*}} "-target-cpu" "at90s2313"

0 commit comments

Comments
 (0)