[clang] [Clang][Sema] Fix crash in CheckNonTypeTemplateParameterType with invalid type (PR #186200)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 12 10:54:54 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Krystian Stasiowski (sdkrystian)
<details>
<summary>Changes</summary>
When a non-type template parameter has a type containing an undeduced placeholder type that is invalid (e.g., a function returning a function), `SubstAutoTypeSourceInfoDependent` can return null if the type is invalid. `CheckNonTypeTemplateParameterType` was not handling this case and would dereference the null pointer.
Fixes #<!-- -->177545
---
Full diff: https://github.com/llvm/llvm-project/pull/186200.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+1)
- (modified) clang/lib/Sema/SemaTemplate.cpp (+4-1)
- (modified) clang/test/SemaTemplate/deduction-crash.cpp (+5)
``````````diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3617786f09595..35e637e7290cc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -322,6 +322,7 @@ Bug Fixes in This Version
- Fixed a crash when parsing ``#pragma clang attribute`` arguments for attributes that forbid arguments. (#GH182122)
- Fixed a bug with multiple-include optimization (MIOpt) state not being preserved in some cases during lexing, which could suppress header-guard mismatch diagnostics and interfere with include-guard optimization. (#GH180155)
- Fixed a crash when normalizing constraints involving concept template parameters whose index coincided with non-concept template parameters in the same parameter mapping.
+- Fixed a crash when substituting into a non-type template parameter that has a type containing an undeduced placeholder type.
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 9b0bec20618a0..9194ee5e2bee9 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -1342,7 +1342,10 @@ QualType Sema::CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI,
// - an identifier associated by name lookup with a non-type
// template-parameter declared with a type that contains a
// placeholder type (7.1.7.4),
- TSI = SubstAutoTypeSourceInfoDependent(TSI);
+ TypeSourceInfo *NewTSI = SubstAutoTypeSourceInfoDependent(TSI);
+ if (!NewTSI)
+ return QualType();
+ TSI = NewTSI;
}
return CheckNonTypeTemplateParameterType(TSI->getType(), Loc);
diff --git a/clang/test/SemaTemplate/deduction-crash.cpp b/clang/test/SemaTemplate/deduction-crash.cpp
index 99ca0b365ff6f..7c3e92af068e9 100644
--- a/clang/test/SemaTemplate/deduction-crash.cpp
+++ b/clang/test/SemaTemplate/deduction-crash.cpp
@@ -172,3 +172,8 @@ namespace PR51872_part1 {
// expected-error at -1 {{no viable constructor or deduction guide for deduction of template arguments of 'T1'}}
// expected-note at -7 {{candidate template ignored: could not match 'PR51872_part1::T1<value-parameter-0-0>' against 'int'}}
}
+
+namespace GH177545 {
+ template<decltype(auto)()() volatile throw() -> char> // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}}
+ struct T2; // expected-error at -1 {{function cannot return function type 'auto () volatile throw() -> decltype(auto)'}}
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/186200
More information about the cfe-commits
mailing list