[PATCH] D26636: patch for llvm/clang bug 25965, suppress warning diagnostic on float-to-bool conversion when in condition context

2016-11-22 Thread Erich Keane via cfe-commits
erichkeane added a comment.

I believe that this is a good patch that solves an open Bug.  See : 
https://llvm.org/bugs/show_bug.cgi?id=25965

I think the SPEC case is much less compelling, but I think that using a float 
explicitly in a conditional is something I really wouldn't expect a warning on.

@rsmith You had commented on the bug initially suggesting suppressing the 
diagnostic entirely in this case.  Do you still feel that way?


https://reviews.llvm.org/D26636



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26636: patch for llvm/clang bug 25965, suppress warning diagnostic on float-to-bool conversion when in condition context

2016-11-22 Thread Melanie Blower via cfe-commits
mibintc added a comment.

BTW I tried a couple different approaches to suppress the message.

One of them was to call IgnoreParenImpCasts().  This worked great to suppress 
the unwanted diagnostic but the call also inhibited constant folding and dead 
code elimination, so there were many test failures.  I couldn't find any 
documentation about when and where a call to IgnoreParenImpCasts is 
appropriate.  Use with care.


https://reviews.llvm.org/D26636



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26636: patch for llvm/clang bug 25965, suppress warning diagnostic on float-to-bool conversion when in condition context

2016-11-21 Thread Melanie Blower via cfe-commits
mibintc added a comment.

Does anyone have time to do a code review for this patch?


https://reviews.llvm.org/D26636



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26636: patch for llvm/clang bug 25965, suppress warning diagnostic on float-to-bool conversion when in condition context

2016-11-18 Thread Joerg Sonnenberger via cfe-commits
joerg added a comment.

Besides "it triggers on SPEC", why should the warning be disabled here? I think 
it is perfectly sensible to have a warning for all six conditional contexts 
here.


https://reviews.llvm.org/D26636



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26636: patch for llvm/clang bug 25965, suppress warning diagnostic on float-to-bool conversion when in condition context

2016-11-18 Thread Melanie Blower via cfe-commits
mibintc removed rL LLVM as the repository for this revision.
mibintc updated this revision to Diff 78518.
mibintc added a comment.

I regenerated the diff using diff -x -U99


https://reviews.llvm.org/D26636

Files:
  include/clang/AST/Expr.h
  include/clang/AST/Stmt.h
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaStmt.cpp
  test/SemaCXX/warn-float-conversion.cpp

Index: test/SemaCXX/warn-float-conversion.cpp
===
--- test/SemaCXX/warn-float-conversion.cpp
+++ test/SemaCXX/warn-float-conversion.cpp
@@ -87,3 +87,29 @@
   char e = 1.0 / 0.0;  // expected-warning{{implicit conversion of out of range value from 'double' to 'char' changes value from +Inf to 127}}
 }
 #endif  // OVERFLOW
+
+int m(int argc)
+{
+  float f = argc;
+  // Test that float-to-bool conversion warnings are not issued
+  // for conditions.
+ 
+
+  if (f)  	
+return 1;
+  else  
+return f
+   ? 1 
+   : 0;
+
+  if (f+1)  	//Question: also suppress for this expresson?
+return 1;
+
+  while (f) ;
+
+  do ; while (f) ;
+
+  for (; f ; ) ;
+
+  return 0;
+}
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -1264,6 +1264,7 @@
   if (CondResult.isInvalid())
 return StmtError();
   Cond = CondResult.get();
+  Cond->setIsCondition();
 
   CondResult = ActOnFinishFullExpr(Cond, DoLoc);
   if (CondResult.isInvalid())
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14607,10 +14607,12 @@
   ExprResult Cond;
   switch (CK) {
   case ConditionKind::Boolean:
+SubExpr->setIsCondition();
 Cond = CheckBooleanCondition(Loc, SubExpr);
 break;
 
   case ConditionKind::ConstexprIf:
+SubExpr->setIsCondition();
 Cond = CheckBooleanCondition(Loc, SubExpr, true);
 break;
 
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -9020,6 +9020,10 @@
   if (S.SourceMgr.isInSystemMacro(CC))
 return;
 
+  // Suppress float-to-bool diagnostic in conditions.
+  if (TargetBT->isBooleanType() && E->isCondition())
+return;
+
   DiagnoseFloatingImpCast(S, E, T, CC);
 }
 
@@ -9222,7 +9226,10 @@
 /// of competing diagnostics here, -Wconversion and -Wsign-compare.
 void AnalyzeImplicitConversions(Sema , Expr *OrigE, SourceLocation CC) {
   QualType T = OrigE->getType();
+  bool isCondition = OrigE->isCondition();
   Expr *E = OrigE->IgnoreParenImpCasts();
+  if (isCondition)
+E->setIsCondition(isCondition);
 
   if (E->isTypeDependent() || E->isValueDependent())
 return;
Index: lib/Parse/ParseExpr.cpp
===
--- lib/Parse/ParseExpr.cpp
+++ lib/Parse/ParseExpr.cpp
@@ -309,6 +309,8 @@
 TernaryMiddle = nullptr;
 Diag(Tok, diag::ext_gnu_conditional_expr);
   }
+  if (!LHS.isInvalid()) 
+LHS.get()->setIsCondition();
 
   if (!TryConsumeToken(tok::colon, ColonLoc)) {
 // Otherwise, we're missing a ':'.  Assume that this was a typo that
Index: include/clang/AST/Stmt.h
===
--- include/clang/AST/Stmt.h
+++ include/clang/AST/Stmt.h
@@ -131,8 +131,9 @@
 unsigned ValueDependent : 1;
 unsigned InstantiationDependent : 1;
 unsigned ContainsUnexpandedParameterPack : 1;
+unsigned IsCondition : 1;
   };
-  enum { NumExprBits = 16 };
+  enum { NumExprBits = 17 };
 
   class CharacterLiteralBitfields {
 friend class CharacterLiteral;
Index: include/clang/AST/Expr.h
===
--- include/clang/AST/Expr.h
+++ include/clang/AST/Expr.h
@@ -116,6 +116,7 @@
 ExprBits.ValueKind = VK;
 ExprBits.ObjectKind = OK;
 ExprBits.ContainsUnexpandedParameterPack = ContainsUnexpandedParameterPack;
+ExprBits.IsCondition = 0;
 setType(T);
   }
 
@@ -219,6 +220,17 @@
 ExprBits.ContainsUnexpandedParameterPack = PP;
   }
 
+  /// \brief Whether this expression appears in condition expression context.
+  bool isCondition() const {
+return ExprBits.IsCondition;
+  }
+
+  /// \brief Set the bit that describes whether this expression
+  /// appears in condition context e.g.: if(expr) while(expr) ?: etc.
+  void setIsCondition(bool PP = true) {
+ExprBits.IsCondition = PP;
+  }
+
   /// getExprLoc - Return the preferred location for the arrow when diagnosing
   /// a problem with a generic expression.
   SourceLocation getExprLoc() const LLVM_READONLY;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits