Skip to content

Commit 437fbfb

Browse files
committed
[Driver][AVR] Reject c/c++ compilation for avr1 devices
avr-gcc also rejects since these devices has no SRAM. Fixes #96881
1 parent 03229e7 commit 437fbfb

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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.
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->compare("avr1") == 0))
408+
D.Diag(diag::err_drv_opt_unsupported_input_type) << "avr1"
409+
<< "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: 'avr1' 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)