[PATCH] D93787: [analyzer] Fix crash caused by accessing empty map

Vince Bridgers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 23 17:29:41 PST 2020


vabridgers created this revision.
vabridgers added a reviewer: Szelethus.
Herald added subscribers: steakhal, ASDenysPetrov, martong, Charusso, dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun, whisperity.
vabridgers requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change attempts to address
https://bugs.llvm.org/show_bug.cgi?id=48588.

In certain cases, it appears that __VA_ARGS__ is not in PrevParamMap
before it's accessed using at(). This change simply skips injectRange()
if __VA_ARGS__ is not found in PrevParamMap.

The crash seen is described below, the case this was discovered in was
distilled into a reproducer inserted into the LIT tests for this module.

terminate called after throwing an instance of 'std::out_of_range'

  what():  map::at
  
  #0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
      <base>/llvm/lib/Support/Unix/Signals.inc:563:22

...

#11 std::__throw_out_of_range(char const*)

  <base>/libstdc++-v3/src/c++11/functexcept.cc:82:5

#12 std::map<clang::IdentifierInfo const*,

    llvm::SmallVector<clang::Token, 2u>, std::less<clang::IdentifierInfo
    const*>, std::allocator<std::pair<clang::IdentifierInfo const* const,
    llvm::SmallVector<clang::Token, 2u> > > >::at(clang::IdentifierInfo
    const* const&) const
  <base>/gcc/9.3.0/include/c++/9.3.0/bits/stl_map.h:549:10

#13 getMacroExpansionInfo((anonymous namespace)::MacroParamMap const&,

    clang::SourceLocation, clang::Preprocessor const&)
  <base>/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp:1242:66

...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93787

Files:
  clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
  clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
  clang/test/Analysis/plist-macros-with-expansion.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93787.313632.patch
Type: text/x-patch
Size: 6479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201224/219beac4/attachment.bin>


More information about the cfe-commits mailing list