mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 22:02:52 +01:00
Made function and namespace nodes typed to remove a crash (#3285)
Bug found by fuzzing. Problem was untyped SemIR nodes had an invalid type id, which was retrieved by `HandlePrefixOperator` and then passed to `context.GetUnqualifiedType`, ultimately performing an invalid access in `semantics_ir_->GetNode`. We prefer to make a placeholder type for functions and namespaces to remove the need for checking for the untyped case everywhere. Eventually functions will have their own types, but this approach will be needed for namespaces (and perhaps other non-first-class entities like unbound methods and interface members) long term. Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
@@ -57,8 +57,9 @@ static auto BuildFunctionDeclaration(Context& context)
|
||||
.return_type_id = return_type_id,
|
||||
.return_slot_id = return_slot_id,
|
||||
.body_block_ids = {}});
|
||||
auto decl_id =
|
||||
context.AddNode(SemIR::FunctionDeclaration(fn_node, function_id));
|
||||
auto decl_id = context.AddNode(SemIR::FunctionDeclaration(
|
||||
fn_node, context.CanonicalizeType(SemIR::NodeId::BuiltinFunctionType),
|
||||
function_id));
|
||||
context.declaration_name_stack().AddNameToLookup(name_context, decl_id);
|
||||
|
||||
if (SemIR::IsEntryPoint(context.semantics_ir(), function_id)) {
|
||||
|
||||
Reference in New Issue
Block a user