This is an archive of the discontinued LLVM Phabricator instance.

patch for llvm/clang bug 25965, suppress warning diagnostic on float-to-bool conversion when in condition context
AbandonedPublic

Authored by mibintc on Nov 14 2016, 1:59 PM.

Details

Summary

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

Diff Detail

Event Timeline

mibintc updated this revision to Diff 77877.Nov 14 2016, 1:59 PM
mibintc retitled this revision from to patch for llvm/clang bug 25965, suppress warning diagnostic on float-to-bool conversion when in condition context.
mibintc updated this object.
mibintc added reviewers: rsmith, erichkeane.
mibintc set the repository for this revision to rL LLVM.
mibintc added a project: Restricted Project.
mibintc added a subscriber: Restricted Project.
mibintc updated this object.Nov 16 2016, 10:34 AM
mibintc added a reviewer: majnemer.
mibintc edited subscribers, added: cfe-commits; removed: Restricted Project.
mibintc updated this revision to Diff 78518.Nov 18 2016, 7:02 AM
mibintc removed rL LLVM as the repository for this revision.

I regenerated the diff using diff -x -U999999

joerg added a subscriber: joerg.Nov 18 2016, 8:16 AM

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.

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

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.

erichkeane edited edge metadata.Nov 22 2016, 8:50 AM

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?

mibintc abandoned this revision.Jul 25 2019, 9:17 AM