fzakaria created this revision. Herald added a project: All. fzakaria requested review of this revision. Herald added subscribers: cfe-commits, wangpc. Herald added a project: clang.
I noticed during the build that GCC would emit a ton of nonnull warnings. Example: /usr/local/google/home/fmzakari/code/github.com/llvm/llvm-project/clang/include/clang/AST/ExternalASTSource.h:378:54: warning: ‘this’ pointer is null [-Wnonnull] 378 | Ptr = reinterpret_cast<uint64_t>((Source->*Get)(Ptr >> 1)); | ~~~~~~~~~~~~~~^~~~~~~~~~ Upon investigation there are actually valid places where we are passing null as source such as: return cast_or_null<FriendDecl>(NextFriend.get(nullptr)); if (!Bases.isOffset()) return Bases.get(nullptr); There is an assertion to catch this but that is only in debug builds. Added a new if protection branch and kept the assertion to keep the code change very minimal. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D155857 Files: clang/include/clang/AST/ExternalASTSource.h Index: clang/include/clang/AST/ExternalASTSource.h =================================================================== --- clang/include/clang/AST/ExternalASTSource.h +++ clang/include/clang/AST/ExternalASTSource.h @@ -375,7 +375,9 @@ if (isOffset()) { assert(Source && "Cannot deserialize a lazy pointer without an AST source"); - Ptr = reinterpret_cast<uint64_t>((Source->*Get)(Ptr >> 1)); + if (Source != nullptr) { + Ptr = reinterpret_cast<uint64_t>((Source->*Get)(Ptr >> 1)); + } } return reinterpret_cast<T*>(Ptr); }
Index: clang/include/clang/AST/ExternalASTSource.h =================================================================== --- clang/include/clang/AST/ExternalASTSource.h +++ clang/include/clang/AST/ExternalASTSource.h @@ -375,7 +375,9 @@ if (isOffset()) { assert(Source && "Cannot deserialize a lazy pointer without an AST source"); - Ptr = reinterpret_cast<uint64_t>((Source->*Get)(Ptr >> 1)); + if (Source != nullptr) { + Ptr = reinterpret_cast<uint64_t>((Source->*Get)(Ptr >> 1)); + } } return reinterpret_cast<T*>(Ptr); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits