[PATCH] D122524: [Driver][AVR] Emit proper warnings for different options
Ben Shi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 28 19:56:22 PDT 2022
benshi001 updated this revision to Diff 418764.
benshi001 retitled this revision from "[clang][AVR] Emit proper warnings" to "[Driver][AVR] Emit proper warnings for different options".
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D122524/new/
https://reviews.llvm.org/D122524
Files:
clang/lib/Driver/ToolChains/AVR.cpp
clang/test/Driver/avr-toolchain.c
Index: clang/test/Driver/avr-toolchain.c
===================================================================
--- clang/test/Driver/avr-toolchain.c
+++ 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
Index: clang/lib/Driver/ToolChains/AVR.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ 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,10 +449,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<StringRef> FamilyName = GetMCUFamilyName(CPU);
Optional<std::string> AVRLibcRoot = TC.findAVRLibcInstallation();
@@ -460,10 +458,13 @@
// 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));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122524.418764.patch
Type: text/x-patch
Size: 5207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220329/a346c416/attachment.bin>
More information about the cfe-commits
mailing list