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,16 +369,17 @@ : 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)) { - if (GCCInstallation.isValid()) { - GCCInstallPath = GCCInstallation.getInstallPath(); - std::string GCCParentPath(GCCInstallation.getParentLibPath()); - getProgramPaths().push_back(GCCParentPath + "/../bin"); - } else { - D.Diag(diag::warn_drv_avr_gcc_not_found); - } + !Args.hasArg(options::OPT_nodefaultlibs) && + GCCInstallation.isValid()) { + GCCInstallPath = GCCInstallation.getInstallPath(); + std::string GCCParentPath(GCCInstallation.getParentLibPath()); + getProgramPaths().push_back(GCCParentPath + "/../bin"); } } @@ -448,22 +449,22 @@ 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 { - Optional FamilyName = GetMCUFamilyName(CPU); - Optional AVRLibcRoot = TC.findAVRLibcInstallation(); + if (!CPU.empty()) { + Optional FamilyName = GetMCUFamilyName(CPU); + Optional AVRLibcRoot = TC.findAVRLibcInstallation(); if (!FamilyName) { // We do not have an entry for this CPU in the family // mapping table yet. D.Diag(diag::warn_drv_avr_family_linking_stdlibs_not_implemented) << CPU; + } else if (TC.getGCCInstallPath().empty()) { + // We can not link since there is no avr-ld. + D.Diag(diag::warn_drv_avr_gcc_not_found); } else if (!AVRLibcRoot) { // No avr-libc found and so no runtime linked. D.Diag(diag::warn_drv_avr_libc_not_found); - } else if (!TC.getGCCInstallPath().empty()) { + } else { std::string SubPath = GetMCUSubPath(CPU); CmdArgs.push_back( Args.MakeArgString(Twine("-L") + *AVRLibcRoot + "/lib/" + SubPath)); 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,25 @@ // 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 --sysroot=%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=WARN_STDLIB %s -// RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree -mmcu=atmega328 %s 2>&1 | FileCheck --check-prefix=NOWARN_STDLIB %s -// RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree -c %s 2>&1 | FileCheck --check-prefix=NOWARN_STDLIB %s - -// 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 --sysroot=%S/Inputs/basic_avr_tree -mmcu=atmega328 %s 2>&1 | FileCheck --check-prefix=NOWARN %s +// RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree -mmcu=atmega328 -S %s 2>&1 | FileCheck --check-prefix=NOWARN %s +// RUN: %clang -### --target=avr --sysroot=%S/Inputs/ -mmcu=atmega328 -S %s 2>&1 | FileCheck --check-prefix=NOWARN %s +// NOWARN-NOT: warning: + +// RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree -S %s 2>&1 | FileCheck --check-prefixes=NOMCU,LINKA %s +// RUN: %clang -### --target=avr --sysroot=%S/Inputs/ -S %s 2>&1 | FileCheck --check-prefixes=NOMCU,LINKA %s +// RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefixes=NOMCU,LINKB %s +// NOMCU: warning: no target microcontroller specified on command line, cannot link standard libraries, please pass -mmcu= +// LINKB: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked +// LINKB: warning: support for passing the data section address to the linker for microcontroller '' is not implemented +// NOMCU-NOT: warning: {{.*}} avr-gcc +// NOMCU-NOT: warning: {{.*}} avr-libc +// LINKA-NOT: warning: {{.*}} interrupt vector +// LINKA-NOT: warning: {{.*}} data section address + +// RUN: %clang -### --target=avr --sysroot=%S/Inputs/ -mmcu=atmega328 %s 2>&1 | FileCheck --check-prefixes=NOGCC %s +// NOGCC: warning: no avr-gcc installation can be found on the system, cannot link standard libraries +// NOGCC: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked +// NOGCC-NOT: warning: {{.*}} microcontroller +// NOGCC-NOT: warning: {{.*}} avr-libc +// NOGCC-NOT: warning: {{.*}} data section address