diff --git a/clang/lib/Driver/ToolChains/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp --- a/clang/lib/Driver/ToolChains/AVR.cpp +++ b/clang/lib/Driver/ToolChains/AVR.cpp @@ -369,6 +369,10 @@ : Generic_ELF(D, Triple, Args) { GCCInstallation.init(Triple, Args); + std::string CPU = getCPUName(D, Args, Triple); + if (CPU.empty()) + D.Diag(diag::warn_drv_avr_mcu_not_specified); + // Only add default libraries if the user hasn't explicitly opted out. if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { @@ -448,10 +452,7 @@ bool LinkStdlib = false; if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { - if (CPU.empty()) { - // We cannot link any standard libraries without an MCU specified. - D.Diag(diag::warn_drv_avr_mcu_not_specified); - } else { + if (!CPU.empty()) { Optional FamilyName = GetMCUFamilyName(CPU); Optional AVRLibcRoot = TC.findAVRLibcInstallation(); diff --git a/clang/test/Driver/avr-toolchain.c b/clang/test/Driver/avr-toolchain.c --- a/clang/test/Driver/avr-toolchain.c +++ b/clang/test/Driver/avr-toolchain.c @@ -36,10 +36,38 @@ // RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 -nostdlibinc | FileCheck --check-prefix=NOSTDINC %s // NOSTDINC-NOT: "-internal-isystem" {{".*avr/include"}} -// RUN: %clang -### --target=avr %s 2>&1 | FileCheck --check-prefix=WARN_STDLIB %s -// RUN: %clang -### --target=avr -mmcu=atmega328 %s 2>&1 | FileCheck --check-prefix=NOWARN_STDLIB %s -// RUN: %clang -### --target=avr -c %s 2>&1 | FileCheck --check-prefix=NOWARN_STDLIB %s +// RUN: %clang -### --target=avr %s --sysroot %S/Inputs/basic_avr_tree -mmcu=atmega328 2>&1 | FileCheck --check-prefix=NOWARN %s +// RUN: %clang -### --target=avr %s --sysroot %S/Inputs/basic_avr_tree -mmcu=atmega328 -S 2>&1 | FileCheck --check-prefix=NOWARN %s +// NOWARN-NOT: warning: -// WARN_STDLIB: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu= -// WARN_STDLIB: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked -// NOWARN_STDLIB-NOT: warning: +// RUN: %clang -### --target=avr %s --sysroot %S/Inputs -S 2>&1 | FileCheck --check-prefixes=NOLINKA,NOLINK %s +// RUN: %clang -### --target=avr %s --sysroot %S/Inputs/basic_avr_tree -S 2>&1 | FileCheck --check-prefixes=NOLINKB,NOLINK %s +// RUN: %clang -### --target=avr %s --sysroot %S/Inputs -mmcu=atmega328 -S 2>&1 | FileCheck --check-prefixes=NOLINKC,NOLINK %s +// NOLINKA: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu= +// NOLINKA: warning: no avr-gcc installation can be found on the system, cannot link standard libraries +// NOLINKB: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu= +// NOLINKC: warning: no avr-gcc installation can be found on the system, cannot link standard libraries +// NOLINK-NOT: warning: {{.*}} avr-libc +// NOLINK-NOT: warning: {{.*}} interrupt vector +// NOLINK-NOT: warning: {{.*}} data section address +// NOLINKB-NOT: warning: {{.*}} microcontroller +// NOLINKC-NOT: warning: {{.*}} avr-gcc + +// RUN: %clang -### --target=avr %s --sysroot %S/Inputs 2>&1 | FileCheck --check-prefixes=LINKA1,LINKA %s +// RUN: %clang -### --target=avr %s --sysroot %S/Inputs/basic_avr_tree 2>&1 | FileCheck --check-prefixes=LINKA2,LINKA %s +// LINKA: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu= +// LINKA1: warning: no avr-gcc installation can be found on the system, cannot link standard libraries +// LINKA: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked +// LINKA: support for passing the data section address to the linker for microcontroller '' is not implemented +// LINKA2-NOT: warning: {{.*}} avr-gcc +// LINKA-NOT: warning: {{.*}} avr-libc + +// RUN: %clang -### --target=avr %s --sysroot %S/Inputs 2>&1 | FileCheck --check-prefixes=LINKB1,LINKB %s +// LINKB1: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu= +// LINKB: warning: no avr-gcc installation can be found on the system, cannot link standard libraries +// LINKB2: warning: no avr-libc installation can be found on the system, cannot link standard libraries +// LINKB: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked +// LINKB1: support for passing the data section address to the linker for microcontroller '' is not implemented +// LINKB2-NOT: warning: {{.*}} microcontroller +// LINKB1-NOT: warning: {{.*}} avr-libc +// LINKB2-NOT: warning: {{.*}} data section address