[clang] Enable errors for undefined TARGET_OS_ macros in Darwin driver
authorZixu Wang <zixu_wang@apple.com>
Mon, 6 Jul 2020 21:52:12 +0000 (14:52 -0700)
committerZixu Wang <zixu_wang@apple.com>
Mon, 6 Jul 2020 21:52:12 +0000 (14:52 -0700)
Add clang option `-Wundef-prefix=TARGET_OS_` and `-Werror=undef-prefix`
to Darwin driver.

Differential Revision: https://reviews.llvm.org/D83250

clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/darwin-warning-options.c [new file with mode: 0644]

index ad3b3a9..6bf42e6 100644 (file)
@@ -954,6 +954,10 @@ DarwinClang::DarwinClang(const Driver &D, const llvm::Triple &Triple,
     : Darwin(D, Triple, Args) {}
 
 void DarwinClang::addClangWarningOptions(ArgStringList &CC1Args) const {
+  // Always error about undefined 'TARGET_OS_*' macros.
+  CC1Args.push_back("-Wundef-prefix=TARGET_OS_");
+  CC1Args.push_back("-Werror=undef-prefix");
+
   // For modern targets, promote certain warnings to errors.
   if (isTargetWatchOSBased() || getTriple().isArch64Bit()) {
     // Always enable -Wdeprecated-objc-isa-usage and promote it
diff --git a/clang/test/Driver/darwin-warning-options.c b/clang/test/Driver/darwin-warning-options.c
new file mode 100644 (file)
index 0000000..b0a591e
--- /dev/null
@@ -0,0 +1,7 @@
+// REQUIRES: system-darwin
+
+// Always error about undefined 'TARGET_OS_*' macros on Darwin.
+// RUN: %clang -### %s 2>&1 | FileCheck %s
+
+// CHECK-DAG: "-Wundef-prefix=TARGET_OS_"
+// CHECK-DAG: "-Werror=undef-prefix"