[clang] [clang] fix crash related to missing source locations for converted template arguments (PR #187352)
Chandler Carruth via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 30 22:17:34 PDT 2026
================
@@ -534,16 +557,43 @@ class TemplateArgumentLoc {
TemplateArgumentLoc(const TemplateArgument &Argument,
TemplateArgumentLocInfo Opaque)
- : Argument(Argument), LocInfo(Opaque) {}
+ : Argument(Argument), LocInfo(Opaque) {
+ switch (Argument.getKind()) {
+ case TemplateArgument::Null:
+ assert(Opaque.isNull());
+ return;
+ case TemplateArgument::Pack:
+ assert(Opaque.isTrivial());
+ return;
+ case TemplateArgument::NullPtr:
+ case TemplateArgument::Integral:
+ case TemplateArgument::Declaration:
+ case TemplateArgument::StructuralValue:
+ assert(Opaque.isTrivial() || Opaque.getAsExpr() != nullptr);
+ return;
+ case TemplateArgument::Expression:
+ assert(Opaque.getAsExpr() != nullptr);
+ return;
+ case TemplateArgument::Type:
+ assert(Opaque.getAsTypeSourceInfo() != nullptr);
+ return;
+ case TemplateArgument::Template:
+ case TemplateArgument::TemplateExpansion:
+ assert(Opaque.getTemplate() != nullptr);
----------------
chandlerc wrote:
All of these assertions seem to make it especially difficult to construct template arguments dynamically using the AST APIs, for example in a client like LLDB or in a frontend synthesizing interop with templates such as Swift, Crubit, or Carbon.
Would it be reasonable to accept null `LocInfo` in all of these cases rather than just when the argument kind itself is null? My understanding is that would allow everything downstream to continue working.
@zygoloid for visibility.
https://github.com/llvm/llvm-project/pull/187352
More information about the cfe-commits
mailing list