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.
clang-format: please reformat the code