Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

False positive: condition with const enum evaluates to true and then to false #19467

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR19468
Status NEW
Importance P normal
Reported by Petr Špaček (redhat@petr.spackovi.net)
Reported on 2014-04-17 12:02:33 -0700
Last modified on 2014-04-17 12:05:38 -0700
Version 3.4
Hardware PC Linux
CC llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments report.html (848140 bytes, text/html)
ldap_helper.c.preprocessed.xz (279000 bytes, application/x-xz)
Blocks
Blocked by
See also
Created attachment 12392
scan-build results

Version:
clang-analyzer-3.4-6.fc20.noarch
clang-3.4-6.fc20.x86_64

Problem:
Analyzer claims that the condition on the same variable evaluates to two
different results:

Please note that variable in question is "const isc_boolean_t new_zone".

1901    static isc_result_t ATTR_NONNULLS ATTR_CHECKRESULT
1902    zone_sync_apex(ldap_instance_t *inst, ldap_entry_t *entry, dns_name_t name,
1903    sync_state_t sync_state, const isc_boolean_t new_zone,
1904    dns_db_t *ldapdb, dns_db_t *rbtdb, dns_dbversion_t *version,
1905    dns_diff_t *diff, isc_uint32_t *new_serial,
1906    isc_boolean_t *ldap_writeback) {
...
1935    if (new_zone == ISC_FALSE)
    Assuming 'new_zone' is not equal to isc_boolean_false
    Taking false branch
1936        CHECK(dns_db_getsoaserial(rbtdb, version, &curr_serial));
1937
1938    /* Detect if SOA serial is affected by the update or not.
1939    * Always bump serial in case of re-synchronization. */
1940    CHECK(diff_analyze_serial(diff, &soa_tuple, &data_changed));
1941    if (new_zone == ISC_TRUE || data_changed == ISC_TRUE ||
    Assuming 'new_zone' is not equal to isc_boolean_true

It is interesting that the problem disappears if I change

1935    if (new_zone == ISC_FALSE)
to
1935    if (new_zone != ISC_TRUE)

Relevant definitions are:

typedef enum { isc_boolean_false = 0, isc_boolean_true = 1 } isc_boolean_t;

#define ISC_FALSE isc_boolean_false
#define ISC_TRUE isc_boolean_true
#define ISC_TF(x) ((x) ? ISC_TRUE : ISC_FALSE)

Maybe the analyzer assumes that the value can be something else than 0 or 1?
Quuxplusone commented 10 years ago

Attached report.html (848140 bytes, text/html): scan-build results

Quuxplusone commented 10 years ago

Attached ldap_helper.c.preprocessed.xz (279000 bytes, application/x-xz): preprocessed C file