[PATCH] D65127: Even more warnings utilizing gsl::Owner/gsl::Pointer annotations

Gábor Horváth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 24 09:49:00 PDT 2019


xazax.hun added a comment.

I have run this successfully on ~192 open source projects.

The results so far:

  1.
  https://github.com/ANTsX/ANTs/blob/master/Examples/sccan.cxx#L2899
  /home/tgahor/data/projects/ANTs/Examples/sccan.cxx:2899:34: warning: object backing the pointer will be destroyed at the end of the full-expression [-Wdangling]
          const char *longName = ( ( *it )->GetLongName() ).c_str();
                                   ^~~~~~~~~~~~~~~~~~~~~~
  This seems to be a true positive given how LongName is defined with this macro: https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Core/Common/include/itkMacro.h#L944
  Here: https://github.com/ANTsX/ANTs/blob/15f4e4013ed33b9d226c8d1b7d9509b2a8b19ba2/Utilities/antsCommandLineOption.h#L179
  This problem has also other instances in this project. True positives, yay!
  
  2.
  https://github.com/mgbellemare/Arcade-Learning-Environment/blob/master/ale_python_interface/ale_c_wrapper.h#L10
  In file included from /home/tgahor/data/projects/Arcade-Learning-Environment/ale_python_interface/ale_c_wrapper.cpp:1:
  /home/tgahor/data/projects/Arcade-Learning-Environment/ale_python_interface/ale_c_wrapper.h:10:68: warning: returning address of local temporary object [-Wreturn-stack-address]
    const char *getString(ALEInterface *ale, const char *key){return ale->getString(key).c_str();}
                                                                     ^~~~~~~~~~~~~~~~~~
  This also is a true positive!
  
  3.
  https://github.com/assimp/assimp/blob/master/code/Step/STEPFile.h#L910
  /home/tgahor/data/projects/assimp/./code/Step/STEPFile.h:910:26: warning: returning address of local temporary object [-Wreturn-stack-address]
                  return (*it).second;
                           ^~
  /home/tgahor/data/projects/assimp/./code/Step/STEPFile.h:908:45: note: via initialization of variable 'it' here
              const ObjectMap::const_iterator it = objects.find(id);
  
  This one seems to be a false positive, will look into what is the root cause. Very similar false positives appear on jsoncpp, bamtools, gtest, cppcheck, Urho3D projects.
  
  4.
  https://github.com/openscenegraph/OpenSceneGraph/blob/master/include/osg/io_utils#L69
  /home/tgahor/data/projects/OpenSceneGraph/include/osg/io_utils:69:51: warning: returning address of local temporary object [-Wreturn-stack-address]
          inline const char* c_str() const { return sstream.str().c_str(); }
                                                    ^~~~~~~~~~~~~
  This also is a true positive!

Conclusion: it does find true positives! All of the false positives should have the same root cause and I will look into fixing that soon. After the fix I will rerun this on even more projects, but I think this already starts to show the value of these warnings. I believe we will be able to find all the errors I reported and have 0 false positives.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65127/new/

https://reviews.llvm.org/D65127





More information about the cfe-commits mailing list