[PATCH] D122524: [clang][AVR] Emit proper warnings

Ben Shi via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 28 10:17:31 PDT 2022


benshi001 updated this revision to Diff 418634.
benshi001 marked an inline comment as done.
benshi001 retitled this revision from "[clang][AVR] Generate link warnings properly" to "[clang][AVR] Emit proper warnings".
benshi001 edited the summary of this revision.
benshi001 set the repository for this revision to rG LLVM Github Monorepo.

Repository:
  rG LLVM Github Monorepo

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,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=<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 %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=<mcu name>
+// 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=<mcu name>
+// 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=<mcu name>
+// 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=<mcu name>
+// 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
Index: clang/lib/Driver/ToolChains/AVR.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ 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<StringRef> FamilyName = GetMCUFamilyName(CPU);
       Optional<std::string> AVRLibcRoot = TC.findAVRLibcInstallation();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122524.418634.patch
Type: text/x-patch
Size: 5020 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220328/6b707ca2/attachment.bin>


More information about the cfe-commits mailing list