Hello,
I'm submitting this patch to suppress the warning diagnostic that is reported in the bugs database as 25965. I work at Intel and we are compiling a spec test which enables -Wfloat-conversion when compiling on Linux in the gcc environment, -Werror causes the spec compilation to fail.
This patch adds a bit to Expression nodes "isCondition". This means that the expression occurs as a condition. clang knows that it is holding a condition, but as it gets deeper into the call tree, the fact that the expression is a condition gets lost and we no longer know the context.
The changes made to lib/Parse/ParseExpr.c are necessary to mark ternary expressions as conditions (i.e. the foo in: foo ? yes : no)
The 2nd set of changes to lib/Sema/SemaChecking is necessary for c++ compilations
The changes to lib/Sema/SemaStmt is necessary for do while(foo) expressions
The test case changes contain a question : should these conversion warnings be suppressed only for simple expressions, or OK to suppress generally? The patch submitted here suppresses generally for any float to bool conversion in the condition context.
This is my first patch submission, any and all comments welcome. Thanks and regards, Melanie Blower
Details
- Reviewers
majnemer erichkeane rsmith
Diff Detail
Event Timeline
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.
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.
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?