]> granicus.if.org Git - clang/commitdiff
fix a bug handling right associative operators that Neil noticed, hopefully
authorChris Lattner <sabre@nondot.org>
Mon, 5 May 2008 04:10:51 +0000 (04:10 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 5 May 2008 04:10:51 +0000 (04:10 +0000)
the final part of PR2279

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50635 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPExpressions.cpp
test/Preprocessor/expr_liveness.c

index 9fda8b086241434cedfe1e3614c421452e58afb0..ff0578067cf06fd1582661a8aa23fb26747a8513 100644 (file)
@@ -294,19 +294,8 @@ static bool EvaluateValue(llvm::APSInt &Result, Token &PeekTok,
 /// getPrecedence - Return the precedence of the specified binary operator
 /// token.  This returns:
 ///   ~0 - Invalid token.
-///   14 - *,/,%
-///   13 - -,+
-///   12 - <<,>>
-///   11 - >=, <=, >, <
-///   10 - ==, !=
-///    9 - &
-///    8 - ^
-///    7 - |
-///    6 - &&
-///    5 - ||
-///    4 - ?
-///    3 - :
-///    0 - eom, )
+///   14 -> 3 - various operators.
+///    0 - 'eom' or ')'
 static unsigned getPrecedence(tok::TokenKind Kind) {
   switch (Kind) {
   default: return ~0U;
@@ -402,7 +391,8 @@ static bool EvaluateDirectiveSubExpr(llvm::APSInt &LHS, unsigned MinPrec,
     // more tightly with RHS than we do, evaluate it completely first.
     if (ThisPrec < PeekPrec ||
         (ThisPrec == PeekPrec && isRightAssoc)) {
-      if (EvaluateDirectiveSubExpr(RHS, ThisPrec+1, PeekTok, RHSIsLive, PP))
+      if (EvaluateDirectiveSubExpr(RHS, ThisPrec+!isRightAssoc, 
+                                   PeekTok, RHSIsLive, PP))
         return true;
       PeekPrec = getPrecedence(PeekTok.getKind());
     }
index 61c073204cadf3e5e6b98249a20c9158673a0b75..da30616284ccc22c2f196438b4a17a96217408b9 100644 (file)
@@ -26,6 +26,9 @@ bar
 #error
 #endif
 
+// PR2279
+#if 1 ? 2 ? 3 : 4 : 5
+#endif
 
 #else