LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 39938 - Warning inconsistently reported on dead code
Summary: Warning inconsistently reported on dead code
Status: RESOLVED INVALID
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: 7.0
Hardware: PC Linux
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-12-10 11:22 PST by sguelton
Modified: 2018-12-11 23:37 PST (History)
6 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sguelton 2018-12-10 11:22:00 PST
When compiled with -Wall, the following code reports a warning only on the live path, as showcased in https://godbolt.org/z/3PD-eF

int case0(int num) {
    if(0)
        return num / 0; << no warning
    else
        return 1;
}
int case1(int num) {
    if(num)
        return num / 0; << warning
    else
        return 1;
}


Yet, when the following code is compiled with -Wall -Wdouble-conversion, we have a warning even in the dead path, as showcased in https://godbolt.org/z/58Q5oA


double foo(double);

int case0(float num) {
    if(0)
        return foo(num); << warning
    else
        return 1;
}
int case1(float num) {
    if(num)
        return foo(num); << warning
    else
        return 1;
}
Comment 1 George Burgess 2018-12-11 11:15:08 PST
Thanks for reporting this!

I don't see how a consistency argument applies here: one warning is about a potentially undesired implicit conversion, whereas the other is about trivially obvious undefined behavior. If our other implicit conversion warnings take path liveness into account, then I think there's a great case to make this consistent with those. Picking an arbitrary (but similar in spirit) implicit conversion warning, this doesn't appear to be the case: https://godbolt.org/z/bp8tlg
Comment 2 sguelton 2018-12-11 23:37:56 PST
You argumentation makes sense to me. I still have difficulties to understand in which situation a warning on trivially dead code may be useful, but that's another story.