From: Ted Kremenek Date: Mon, 29 Oct 2007 16:45:23 +0000 (+0000) Subject: For floating point equality check, we now ignore parentheses. e.g.: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e780f0db9b2d95265894227affe5211e747f9588;p=clang For floating point equality check, we now ignore parentheses. e.g.: (x) == x is the treated the same as x == x. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43448 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 59cff7cc7d..1156bd7d4d 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -1191,6 +1191,20 @@ inline QualType Sema::CheckShiftOperands( // C99 6.5.7 return QualType(); } +// Utility method to plow through parentheses to get the first nested +// non-ParenExpr expr. +static inline Expr* IgnoreParen(Expr* E) { + + while (true) { + if (ParenExpr* P = dyn_cast(E)) + E = P->getSubExpr(); + else + break; + } + + return E; +} + inline QualType Sema::CheckCompareOperands( // C99 6.5.8 Expr *&lex, Expr *&rex, SourceLocation loc, bool isRelational) { @@ -1212,8 +1226,8 @@ inline QualType Sema::CheckCompareOperands( // C99 6.5.8 // Special case: check for x == x (which is OK). bool EmitWarning = true; - if (DeclRefExpr* DRL = dyn_cast(lex)) - if (DeclRefExpr* DRR = dyn_cast(rex)) + if (DeclRefExpr* DRL = dyn_cast(IgnoreParen(lex))) + if (DeclRefExpr* DRR = dyn_cast(IgnoreParen(rex))) if (DRL->getDecl() == DRR->getDecl()) EmitWarning = false;