benshi001 updated this revision to Diff 418481.

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
@@ -1,7 +1,7 @@
 // UNSUPPORTED: system-windows
 // A basic clang -cc1 command-line.
 
-// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree -resource-dir=%S/Inputs/resource_dir 2>&1 | FileCheck --check-prefix=CHECK1 %s
+// RUN: %clang %s -### --target=avr --sysroot %S/Inputs/basic_avr_tree -resource-dir=%S/Inputs/resource_dir 2>&1 | FileCheck --check-prefix=CHECK1 %s
 // CHECK1: clang{{.*}} "-cc1" "-triple" "avr"
 // CHECK1-SAME: "-resource-dir" "[[RESOURCE:[^"]+]]"
 // CHECK1-SAME: "-isysroot" "[[SYSROOT:[^"]+/basic_avr_tree]]"
@@ -12,26 +12,57 @@
 // CHECK1-SAME: "-o" "a.out"
 // CHECK1-SAME: {{^}} "--gc-sections"
 
-// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree_2/opt/local -S 2>&1 | FileCheck --check-prefix=CHECK2 %s
+// RUN: %clang %s -### --target=avr --sysroot %S/Inputs/basic_avr_tree_2/opt/local -S 2>&1 | FileCheck --check-prefix=CHECK2 %s
 // CHECK2: clang{{.*}} "-cc1" "-triple" "avr"
 // CHECK2-SAME: "-isysroot" "[[SYSROOT:[^"]+/basic_avr_tree_2/opt/local]]"
 // CHECK2-SAME: "-internal-isystem"
 // CHECK2-SAME: {{^}} "[[SYSROOT]]/lib/gcc/avr/10.3.0/../../../../avr/include"
 
-// RUN: %clang %s -### -target avr --sysroot %S/Inputs/basic_avr_tree_2 -S 2>&1 | FileCheck --check-prefix=CHECK3 %s
+// RUN: %clang %s -### --target=avr --sysroot %S/Inputs/basic_avr_tree_2 -S 2>&1 | FileCheck --check-prefix=CHECK3 %s
 // CHECK3: clang{{.*}} "-cc1" "-triple" "avr"
 // CHECK3-SAME: "-isysroot" "[[SYSROOT:[^"]+/basic_avr_tree_2]]"
 // CHECK3-SAME: "-internal-isystem"
 // CHECK3-SAME: {{^}} "[[SYSROOT]]/usr/avr/include"
 
-// RUN: %clang %s -### -target avr 2>&1 | FileCheck -check-prefix=CC1 %s
+// RUN: %clang %s -### --target=avr 2>&1 | FileCheck -check-prefix=CC1 %s
 // CC1: clang{{.*}} "-cc1" "-triple" "avr" {{.*}} "-fno-use-init-array" "-fno-use-cxa-atexit"
 
-// RUN: %clang %s -### -target avr -fuse-init-array -fuse-cxa-atexit 2>&1 | FileCheck -check-prefix=CHECK4 %s
+// RUN: %clang %s -### --target=avr -fuse-init-array -fuse-cxa-atexit 2>&1 | FileCheck -check-prefix=CHECK4 %s
 // CHECK4: clang{{.*}} "-cc1" "-triple" "avr"
 // CHECK4-NOT: "-fno-use-init-array"
 // CHECK4-NOT: "-fno-use-cxa-atexit"
 
-// 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
+// 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 {{.*}} microcontroller
+// CHECK5-NOT: warning: no avr-gcc
+// CHECK5-NOT: warning: {{.*}} library not linked
+
+// RUN: %clang %s -### --target=avr --sysroot %S/Inputs/ -mmcu=atmega328 2>&1 | FileCheck --check-prefix=CHECK6 %s
+// CHECK6-NOT: warning: no {{.*}} microcontroller
+// 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
+// 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
+// RUN: %clang %s -### --target=avr --sysroot %S/Inputs/basic_avr_tree -E 2>&1 | FileCheck --check-prefix=CHECK8 %s
+// RUN: %clang %s -### --target=avr --sysroot %S/Inputs/basic_avr_tree -fsyntax-only 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
+// CHECK8-NOT: warning: {{.*}} library not 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
+// RUN: %clang %s -### --target=avr --sysroot %S/Inputs/basic_avr_tree -mmcu=atmega328 -E 2>&1 | FileCheck --check-prefix=CHECK9 %s
+// RUN: %clang %s -### --target=avr --sysroot %S/Inputs/basic_avr_tree -mmcu=atmega328 -fsyntax-only 2>&1 | FileCheck --check-prefix=CHECK9 %s
+// CHECK9-NOT: warning: no {{.*}} target microcontroller
+// CHECK9-NOT: warning: no avr-gcc
+// CHECK9-NOT: warning: {{.*}} library not linked
Index: clang/lib/Driver/ToolChains/AVR.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AVR.cpp
+++ clang/lib/Driver/ToolChains/AVR.cpp
@@ -369,16 +369,19 @@
     : 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_E) &&
+      !Args.hasArg(options::OPT_fsyntax_only) &&
       !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();
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to