aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaCodeComplete.cpp
diff options
context:
space:
mode:
authorsmanna12 <soumi.manna@intel.com>2024-05-02 06:22:20 -0700
committerGitHub <noreply@github.com>2024-05-02 08:22:20 -0500
commita2f97974e670379b28f7ad4701233fc162a46867 (patch)
treeb9ef65f88b5c7acf4113028abf66f854a2f3758c /clang/lib/Sema/SemaCodeComplete.cpp
parent7925525d330a46480b0c3b136e5f47948c5cb741 (diff)
downloadllvm-a2f97974e670379b28f7ad4701233fc162a46867.zip
llvm-a2f97974e670379b28f7ad4701233fc162a46867.tar.gz
llvm-a2f97974e670379b28f7ad4701233fc162a46867.tar.bz2
[Clang] Prevent null pointer dereference in Sema::​CodeCompleteQualifiedId() (#90490)
The null pointer dereference issue seems happening with in the expression NNS->getAsType(). Although dyn_cast_or_null<TemplateTypeParmType>() correctly handles null pointers, it doesn’t prevent the subsequent dereferencing operation. The fix ensures that NNS pointer is not null before calling the getAsType() method, thus preventing potential runtime errors caused by attempting to access a null pointer.
Diffstat (limited to 'clang/lib/Sema/SemaCodeComplete.cpp')
-rw-r--r--clang/lib/Sema/SemaCodeComplete.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index c335017..3f0ab10 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -6714,14 +6714,16 @@ void Sema::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
// If the scope is a concept-constrained type parameter, infer nested
// members based on the constraints.
- if (const auto *TTPT =
- dyn_cast_or_null<TemplateTypeParmType>(NNS->getAsType())) {
- for (const auto &R : ConceptInfo(*TTPT, S).members()) {
- if (R.Operator != ConceptInfo::Member::Colons)
- continue;
- Results.AddResult(CodeCompletionResult(
- R.render(*this, CodeCompleter->getAllocator(),
- CodeCompleter->getCodeCompletionTUInfo())));
+ if (NNS) {
+ if (const auto *TTPT =
+ dyn_cast_or_null<TemplateTypeParmType>(NNS->getAsType())) {
+ for (const auto &R : ConceptInfo(*TTPT, S).members()) {
+ if (R.Operator != ConceptInfo::Member::Colons)
+ continue;
+ Results.AddResult(CodeCompletionResult(
+ R.render(*this, CodeCompleter->getAllocator(),
+ CodeCompleter->getCodeCompletionTUInfo())));
+ }
}
}