[clang] f47b885 - [clang] Enable errors for undefined TARGET_OS_ macros in Darwin driver

Zixu Wang via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 6 14:52:33 PDT 2020


Author: Zixu Wang
Date: 2020-07-06T14:52:12-07:00
New Revision: f47b8851318d5ec2fa1e7867f3fdb86101cdc1da

URL: https://github.com/llvm/llvm-project/commit/f47b8851318d5ec2fa1e7867f3fdb86101cdc1da
DIFF: https://github.com/llvm/llvm-project/commit/f47b8851318d5ec2fa1e7867f3fdb86101cdc1da.diff

LOG: [clang] Enable errors for undefined TARGET_OS_ macros in Darwin driver

Add clang option `-Wundef-prefix=TARGET_OS_` and `-Werror=undef-prefix`
to Darwin driver.

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

Added: 
    clang/test/Driver/darwin-warning-options.c

Modified: 
    clang/lib/Driver/ToolChains/Darwin.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index ad3b3a955d42..6bf42e6029eb 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -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
index 000000000000..b0a591eac820
--- /dev/null
+++ b/clang/test/Driver/darwin-warning-options.c
@@ -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"


        


More information about the cfe-commits mailing list