r200980 - [analyzer] Just silence all warnings coming out of std::basic_string.

David Blaikie dblaikie at gmail.com
Sun Feb 9 00:08:19 PST 2014


On Fri, Feb 7, 2014 at 9:35 AM, Jordan Rose <jordan_rose at apple.com> wrote:

> Author: jrose
> Date: Fri Feb  7 11:35:04 2014
> New Revision: 200980
>
> URL: http://llvm.org/viewvc/llvm-project?rev=200980&view=rev
> Log:
> [analyzer] Just silence all warnings coming out of std::basic_string.
>

This does seem like a rather rough heuristic - is there nothing better?
(more general - everything in the STL? What about every other string class
everyone and their monkey have written? And I assume this isn't about
strings, as such, but just a complexity problem with complex types and
string just happens to be a commonly used one?)


>
> This means always walking the whole call stack for the end path node, but
> we'll assume that's always fairly tractable.
>
> <rdar://problem/15952973>
>
> Modified:
>     cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
>     cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h
>     cfe/trunk/test/Analysis/inlining/stl.cpp
>
> Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=200980&r1=200979&r2=200980&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
> +++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Fri Feb  7
> 11:35:04 2014
> @@ -1558,25 +1558,18 @@ LikelyFalsePositiveSuppressionBRVisitor:
>        //   std::u16string s; s += u'a';
>        // because we cannot reason about the internal invariants of the
>        // datastructure.
> -      const LocationContext *LCtx = N->getLocationContext();
> -      do {
> +      for (const LocationContext *LCtx = N->getLocationContext(); LCtx;
> +           LCtx = LCtx->getParent()) {
>          const CXXMethodDecl *MD =
> dyn_cast<CXXMethodDecl>(LCtx->getDecl());
>          if (!MD)
> -          break;
> +          continue;
>
>          const CXXRecordDecl *CD = MD->getParent();
>          if (CD->getName() == "basic_string") {
>            BR.markInvalid(getTag(), 0);
>            return 0;
> -        } else if (CD->getName().find("allocator") == StringRef::npos) {
> -          // Only keep searching if the current method is in a class with
> the
> -          // word "allocator" in its name, e.g. std::allocator or
> -          // allocator_traits.
> -          break;
>          }
> -
> -        LCtx = LCtx->getParent();
> -      } while (LCtx);
> +      }
>      }
>    }
>
>
> Modified: cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h?rev=200980&r1=200979&r2=200980&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h (original)
> +++ cfe/trunk/test/Analysis/Inputs/system-header-simulator-cxx.h Fri Feb
>  7 11:35:04 2014
> @@ -155,11 +155,21 @@ namespace std {
>    // basic_string
>    template<class _CharT, class _Alloc = allocator<_CharT> >
>    class __attribute__ ((__type_visibility__("default"))) basic_string {
> -    _CharT localStorage[4];
> +    bool isLong;
> +    union {
> +      _CharT localStorage[4];
> +      _CharT *externalStorage;
> +
> +      void assignExternal(_CharT *newExternal) {
> +        externalStorage = newExternal;
> +      }
> +    } storage;
>
>      typedef allocator_traits<_Alloc> __alloc_traits;
>
>    public:
> +    basic_string();
> +
>      void push_back(int c) {
>        // Fake error trigger.
>        // No warning is expected as we are suppressing warning coming
> @@ -168,11 +178,24 @@ namespace std {
>        z = 5/z;
>      }
>
> +    _CharT *getBuffer() {
> +      return isLong ? storage.externalStorage : storage.localStorage;
> +    }
> +
>      basic_string &operator +=(int c) {
>        // Fake deallocate stack-based storage.
>        // No warning is expected as we are suppressing warnings within
> -      // allocators being used by std::basic_string.
> -      __alloc_traits::deallocate(&localStorage);
> +      // std::basic_string.
> +      __alloc_traits::deallocate(getBuffer());
> +    }
> +
> +    basic_string &operator =(const basic_string &other) {
> +      // Fake deallocate stack-based storage, then use the variable in the
> +      // same union.
> +      // No warning is expected as we are suppressing warnings within
> +      // std::basic_string.
> +      __alloc_traits::deallocate(getBuffer());
> +      storage.assignExternal(new _CharT[4]);
>      }
>    };
>  }
>
> Modified: cfe/trunk/test/Analysis/inlining/stl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/stl.cpp?rev=200980&r1=200979&r2=200980&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Analysis/inlining/stl.cpp (original)
> +++ cfe/trunk/test/Analysis/inlining/stl.cpp Fri Feb  7 11:35:04 2014
> @@ -42,3 +42,8 @@ void testBasicStringSuppression_append()
>    std::basic_string<char32_t> v;
>    v += 'c'; // no-warning
>  }
> +
> +void testBasicStringSuppression_assign(std::basic_string<char32_t> &v,
> +                                       const std::basic_string<char32_t>
> &v2) {
> +  v = v2;
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140209/a37b9009/attachment.html>


More information about the cfe-commits mailing list