llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Neha (nehaGautam07) <details> <summary>Changes</summary> Add checks in GetNameFromUnqualifiedId to handle invalid TemplateId cases safely. This avoids a crash when parsing malformed code like 'operator | <>' and allows normal error reporting to continue. Fixes #<!-- -->177549 --- Full diff: https://github.com/llvm/llvm-project/pull/181404.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaDecl.cpp (+10) - (added) clang/test/SemaCXX/crash-invalid-operator-template.cpp (+3) ``````````diff diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 7af6ce62d08dd..369a5f11ef5aa 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -6101,7 +6101,17 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) { } case UnqualifiedIdKind::IK_TemplateId: { + if (!Name.TemplateId) + return DeclarationNameInfo(); + + if (Name.TemplateId->isInvalid()) + return DeclarationNameInfo(); + TemplateName TName = Name.TemplateId->Template.get(); + + if (TName.isNull()) + return DeclarationNameInfo(); + SourceLocation TNameLoc = Name.TemplateId->TemplateNameLoc; return Context.getNameForTemplate(TName, TNameLoc); } diff --git a/clang/test/SemaCXX/crash-invalid-operator-template.cpp b/clang/test/SemaCXX/crash-invalid-operator-template.cpp new file mode 100644 index 0000000000000..d383b5f26d8e9 --- /dev/null +++ b/clang/test/SemaCXX/crash-invalid-operator-template.cpp @@ -0,0 +1,3 @@ +// RUN: not %clang_cc1 -fsyntax-only %s + +typedef(( operator | <> ) ) ( class { private: }); \ No newline at end of file `````````` </details> https://github.com/llvm/llvm-project/pull/181404 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
