[LLVMbugs] [Bug 9122] New: -Wuninitialized false positive due to control dependency.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Feb 1 22:39:06 PST 2011


http://llvm.org/bugs/show_bug.cgi?id=9122

           Summary: -Wuninitialized false positive due to control
                    dependency.
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
        AssignedTo: kremenek at apple.com
        ReportedBy: nicolasweber at gmx.de
                CC: llvmbugs at cs.uiuc.edu


Spun off from http://llvm.org/bugs/show_bug.cgi?id=9063#c11 (see there for
attachment):

 Here's another example that looks fairly similar that I
still see with your patch.

Compile like this:
 ~/src/llvm-svn/Release+Asserts/bin/clang -arch i386 -c repro.ii
-Wuninitialized

Warnings:
In file included from
/Volumes/MacintoshHD2/src/chrome-git/src/chrome/common/common_param_traits.cc:1:
/Volumes/MacintoshHD2/src/chrome-git/src/chrome/common/common_param_traits.cc:662:3:
warning: use of uninitialized variable 'last_accessed' [-Wuninitialized]
  double last_accessed;
  ^~~~~~~~~~~~~~~~~~~~
/Volumes/MacintoshHD2/src/chrome-git/src/chrome/common/common_param_traits.cc:672:48:
note: variable 'last_accessed' is possibly uninitialized when used here
    p->last_accessed = base::Time::FromDoubleT(last_accessed);
                                               ^~~~~~~~~~~~~
/Volumes/MacintoshHD2/src/chrome-git/src/chrome/common/common_param_traits.cc:662:23:
note: add initialization to silence this warning
  double last_accessed;
                      ^
                       = 0.0
/Volumes/MacintoshHD2/src/chrome-git/src/chrome/common/common_param_traits.cc:661:3:
warning: use of uninitialized variable 'last_modified' [-Wuninitialized]
  double last_modified;
  ^~~~~~~~~~~~~~~~~~~~
/Volumes/MacintoshHD2/src/chrome-git/src/chrome/common/common_param_traits.cc:671:48:
note: variable 'last_modified' is possibly uninitialized when used here
    p->last_modified = base::Time::FromDoubleT(last_modified);
                                               ^~~~~~~~~~~~~
/Volumes/MacintoshHD2/src/chrome-git/src/chrome/common/common_param_traits.cc:661:23:
note: add initialization to silence this warning
  double last_modified;
                      ^
                       = 0.0
/Volumes/MacintoshHD2/src/chrome-git/src/chrome/common/common_param_traits.cc:663:3:
warning: use of uninitialized variable 'creation_time' [-Wuninitialized]
  double creation_time;
  ^~~~~~~~~~~~~~~~~~~~
/Volumes/MacintoshHD2/src/chrome-git/src/chrome/common/common_param_traits.cc:673:48:
note: variable 'creation_time' is possibly uninitialized when used here
    p->creation_time = base::Time::FromDoubleT(creation_time);
                                               ^~~~~~~~~~~~~
/Volumes/MacintoshHD2/src/chrome-git/src/chrome/common/common_param_traits.cc:663:23:
note: add initialization to silence this warning
  double creation_time;
                      ^
                       = 0.0
3 warnings generated.



Relevant code:
bool ParamTraits<base::PlatformFileInfo>::Read(
    const Message* m, void** iter, param_type* p) {
  double last_modified;
  double last_accessed;
  double creation_time;
  bool result =
      ReadParam(m, iter, &p->size) &&
      ReadParam(m, iter, &p->is_directory) &&
      ReadParam(m, iter, &last_modified) &&
      ReadParam(m, iter, &last_accessed) &&
      ReadParam(m, iter, &creation_time);
  if (result) {
    p->last_modified = base::Time::FromDoubleT(last_modified);
    p->last_accessed = base::Time::FromDoubleT(last_accessed);
    p->creation_time = base::Time::FromDoubleT(creation_time);
  }
  return result;
}




This example is much harder because it involves tracking a control-dependency,
e.g.:

 bool result = ...
 ...
 if (result) {
   ...
 }

The static analyzer handles this easily, but I'm not certain how much
control-dependencies like this we should attempt (if any) to model with
-Wuninitialized.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list