mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:31:24 +01:00
return 0 from Run when it doesn't specify a return value (#7180)
https://carbon.compiler-explorer.com/z/88K9Kh5Wo shows the program exiting with a garbage value copied from uninitialized memory. This PR modifies `lower` to detect if the function lowered is the entry point and doesn't specify a return type. If so, it emits different LLVM IR to return int32 0, and modifies the lowered function signature to match the int32 return type.
This commit is contained in:
@@ -27,7 +27,9 @@ class FunctionContext {
|
||||
// be null (see members).
|
||||
explicit FunctionContext(
|
||||
FileContext& file_context, llvm::Function* function,
|
||||
FileContext& specific_file_context, SemIR::SpecificId specific_id,
|
||||
FileContext& specific_file_context,
|
||||
SemIR::FunctionId specific_sem_ir_function_id,
|
||||
SemIR::SpecificId specific_id,
|
||||
SpecificCoalescer::SpecificFunctionFingerprint* function_fingerprint,
|
||||
llvm::DISubprogram* di_subprogram, llvm::raw_ostream* vlog_stream);
|
||||
|
||||
@@ -242,6 +244,11 @@ class FunctionContext {
|
||||
auto specific_sem_ir() -> const SemIR::File& {
|
||||
return specific_file_context_->sem_ir();
|
||||
}
|
||||
|
||||
auto specific_sem_ir_function_id() -> SemIR::FunctionId {
|
||||
return specific_sem_ir_function_id_;
|
||||
}
|
||||
|
||||
// The specific ID for the function that is being lowered. Note that this is
|
||||
// an ID from `specific_sem_ir()`, not from `sem_ir()`.
|
||||
auto specific_id() -> SemIR::SpecificId { return specific_id_; }
|
||||
@@ -313,6 +320,9 @@ class FunctionContext {
|
||||
// defined in a different file.
|
||||
FileContext* specific_file_context_;
|
||||
|
||||
// The function id of the function we're lowering.
|
||||
SemIR::FunctionId specific_sem_ir_function_id_;
|
||||
|
||||
// The specific id, if the function is a specific.
|
||||
SemIR::SpecificId specific_id_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user