[clang] 50de68b - [Driver][AVR] Emit proper warnings for different options
Ben Shi via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 28 21:05:34 PDT 2022
Author: Ben Shi
Date: 2022-03-29T12:05:21+08:00
New Revision: 50de68bc2ffc8f6825fb5445ec179a68aa6ad219
URL: https://github.com/llvm/llvm-project/commit/50de68bc2ffc8f6825fb5445ec179a68aa6ad219
DIFF: https://github.com/llvm/llvm-project/commit/50de68bc2ffc8f6825fb5445ec179a68aa6ad219.diff
LOG: [Driver][AVR] Emit proper warnings for different options
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D122524
Added:
Modified:
clang/lib/Driver/ToolChains/AVR.cpp
clang/test/Driver/avr-toolchain.c
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/AVR.cpp b/clang/lib/Driver/ToolChains/AVR.cpp
index 8ca8525e454b4..466fc3b20569e 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -369,16 +369,17 @@ AVRToolChain::AVRToolChain(const Driver &D, const llvm::Triple &Triple,
: 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 @@ void AVR::Linker::ConstructJob(Compilation &C, const JobAction &JA,
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<StringRef> FamilyName = GetMCUFamilyName(CPU);
- Optional<std::string> AVRLibcRoot = TC.findAVRLibcInstallation();
+ if (!CPU.empty()) {
+ Optional<StringRef> FamilyName = GetMCUFamilyName(CPU);
+ Optional<std::string> 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
index 8bd8f91192f28..89226a6bd929c 100644
--- 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=<mcu name>
-// 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=<mcu name>
+// 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
More information about the cfe-commits
mailing list