This is an archive of the discontinued LLVM Phabricator instance.

[preprocessor] Assertions on the inferrable null pointers in Preprocessor befere dereference
Needs ReviewPublic

Authored by OikawaKirie on Nov 16 2020, 6:36 AM.

Details

Summary

This patch asserts on some smart pointers that can be statically inferred to be null pointers. For a smart pointer, when its nullability is checked, and the null branch can reach a dereference, we think it is a potential null pointer dereference. In this patch, I added an assertion before each reported dereference.

  • clang/lib/Lex/PPDirectives.cpp:441, inferred from the loop body: e.g. line 481, check and continue
  • clang/lib/Lex/PPDirectives.cpp:1385, inferred from line 911: check CurLexer
  • clang/lib/Lex/PPDirectives.cpp:1723, inferred from line 911: check CurLexer
  • clang/lib/Lex/PPDirectives.cpp:2540, inferred from line 911: check CurLexer
  • clang/lib/Lex/PPLexerChange.cpp:320, inferred from line 311: check CurLexer
  • clang/lib/Lex/Preprocessor.cpp:1226, inferred from recomputeCurLexerKind line 383: check CurLexer

Besides, the analyzer also reports the dereference in function SkipTokensWhileUsingPCH and Lex. I think these two reported dereference cannot actually happen, but I also add the asserts to make sure the value is correct.

Diff Detail

Event Timeline

OikawaKirie created this revision.Nov 16 2020, 6:36 AM
OikawaKirie requested review of this revision.Nov 16 2020, 6:36 AM
dnsampaio resigned from this revision.Jan 13 2021, 11:31 AM