llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.79k stars 11.9k forks source link

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

Open llvmbot opened 10 years ago

llvmbot commented 10 years ago
Bugzilla Link 19468
Version 3.4
OS Linux
Attachments scan-build results, preprocessed C file
Reporter LLVM Bugzilla Contributor

Extended Description

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?

llvmbot commented 10 years ago

assigned to @tkremenek