Skip to content

Commit

Permalink
[clang][Driver][AVR] Reject c/c++ compilation for avr1 devices (llvm#…
Browse files Browse the repository at this point in the history
…111798)

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

Fixes llvm#96881
  • Loading branch information
benshi001 authored Oct 14, 2024
1 parent 5af8cec commit 4bf6e83
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ WebAssembly Support
AVR Support
^^^^^^^^^^^

- Reject C/C++ compilation for avr1 devices which have no SRAM.

DWARF Support in Clang
----------------------

Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Driver/ToolChains/AVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions clang/test/Driver/avr-mmcu.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 4bf6e83

Please sign in to comment.