From 4d2d04e9fb136e5f9530f4aa298f31e4c40c5ada Mon Sep 17 00:00:00 2001
From: Chris Lattner <sabre@nondot.org>
Date: Sun, 18 Jan 2009 21:18:58 +0000
Subject: [PATCH] fix rdar://6505352 - Bogus warning with -WUndef, a case
 Anders noticed.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62472 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Lex/PPExpressions.cpp         | 3 ++-
 test/Preprocessor/expr_liveness.c | 8 +++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp
index 168c9d08adf..86f93e407a4 100644
--- a/lib/Lex/PPExpressions.cpp
+++ b/lib/Lex/PPExpressions.cpp
@@ -91,7 +91,8 @@ static bool EvaluateValue(PPValue &Result, Token &PeekTok, DefinedTracker &DT,
     // into a simple 0, unless it is the C++ keyword "true", in which case it
     // turns into "1".
     if (II->getPPKeywordID() != tok::pp_defined) {
-      PP.Diag(PeekTok, diag::warn_pp_undef_identifier) << II;
+      if (ValueLive)
+        PP.Diag(PeekTok, diag::warn_pp_undef_identifier) << II;
       Result.Val = II->getTokenID() == tok::kw_true;
       Result.Val.setIsUnsigned(false);  // "0" is signed intmax_t 0.
       Result.setRange(PeekTok.getLocation());
diff --git a/test/Preprocessor/expr_liveness.c b/test/Preprocessor/expr_liveness.c
index 3f4003ea3af..d9e5d7cb25f 100644
--- a/test/Preprocessor/expr_liveness.c
+++ b/test/Preprocessor/expr_liveness.c
@@ -1,4 +1,4 @@
-/* RUN: clang -E %s -DNO_ERRORS &&
+/* RUN: clang -E %s -DNO_ERRORS -Werror -Wundef &&
    RUN: not clang -E %s
  */
 
@@ -44,3 +44,9 @@ baz
 
 
 #endif
+
+// rdar://6505352
+// -Wundef should not warn about use of undefined identifier if not live.
+#if (!defined(XXX) || XXX > 42)
+#endif
+
-- 
GitLab