[PATCH] D122524: [clang][AVR] Eliminate link warnings when '-S' is specified
Ben Shi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 26 04:43:23 PDT 2022
benshi001 updated this revision to Diff 418387.
benshi001 added a comment.
1. If '-S'/'-c' is specified, do not generate link warnings;
2. If '-S'/'-c' is not specified, '-mmcu' is specified and there is valid GCC installation, do not generate link warnings;
3. If '-S'/'-c' is not specified, and '-mmcu' is not specified, genereate link warnings;
4. If '-S'/'-c' is not specified, and there is no valid GCC installation, genereate link warnings.
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
@@ -35,3 +35,30 @@
// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 -nostdinc | FileCheck --check-prefix=NOSTDINC %s
// 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 %s -### -target avr --sysroot %S/Inputs/basic_avr_tree -mmcu=atmega328 2>&1 | FileCheck --check-prefix=CHECK5 %s
+// CHECK5-NOT: warning: no target microcontroller specified on command line, cannot link standard libraries
+// CHECK5-NOT: warning: no avr-gcc installation can be found on the system, cannot link standard libraries
+// CHECK5-NOT: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked
+
+// RUN: %clang %s -### -target avr --sysroot %S/Inputs/ -mmcu=atmega328 2>&1 | FileCheck --check-prefix=CHECK6 %s
+// CHECK6-NOT: warning: no target microcontroller specified on command line, cannot link standard libraries
+// CHECK6: warning: no avr-gcc installation can be found on the system, cannot link standard libraries
+// CHECK6: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked
+
+// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree 2>&1 | FileCheck --check-prefix=CHECK7 %s
+// CHECK7: warning: no target microcontroller specified on command line, cannot link standard libraries
+// CHECK7-NOT: warning: no avr-gcc installation can be found on the system, cannot link standard libraries
+// CHECK7: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked
+
+// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree -c 2>&1 | FileCheck --check-prefix=CHECK8 %s
+// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree -S 2>&1 | FileCheck --check-prefix=CHECK8 %s
+// CHECK8: warning: no target microcontroller specified on command line, cannot link standard libraries
+// CHECK8-NOT: warning: no avr-gcc installation can be found on the system, cannot link standard libraries
+// CHECK8-NOT: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked
+
+// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree -mmcu=atmega328 -c 2>&1 | FileCheck --check-prefix=CHECK9 %s
+// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree -mmcu=atmega328 -S 2>&1 | FileCheck --check-prefix=CHECK9 %s
+// CHECK9-NOT: warning: no target microcontroller specified on command line, cannot link standard libraries
+// CHECK9-NOT: warning: no avr-gcc installation can be found on the system, cannot link standard libraries
+// CHECK9-NOT: warning: standard library not linked and so no interrupt vector table or compiler runtime routines will be linked
Index: clang/lib/Driver/ToolChains/AVR.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -369,16 +369,18 @@
: Generic_ELF(D, Triple, Args), LinkStdlib(false) {
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) &&
+ !Args.hasArg(options::OPT_S) &&
!Args.hasArg(options::OPT_c /* does not apply when not linking */)) {
- std::string CPU = getCPUName(D, Args, Triple);
- if (CPU.empty()) {
- // We cannot link any standard libraries without an MCU specified.
- D.Diag(diag::warn_drv_avr_mcu_not_specified);
- } else {
+ // We cannot link any standard libraries without an MCU specified.
+ if (!CPU.empty()) {
Optional<StringRef> FamilyName = GetMCUFamilyName(CPU);
Optional<std::string> AVRLibcRoot = findAVRLibcInstallation();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122524.418387.patch
Type: text/x-patch
Size: 4265 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220326/f78b3ce4/attachment.bin>
More information about the cfe-commits
mailing list