mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-02 22:02:51 +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:
+7
-6
@@ -34,10 +34,10 @@ fn Run() {
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nounwind
|
||||
// CHECK:STDOUT: define void @main() #1 !dbg !11 {
|
||||
// CHECK:STDOUT: define i32 @main() #1 !dbg !11 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: call void @_ZN1N3RunEv(), !dbg !14
|
||||
// CHECK:STDOUT: ret void, !dbg !15
|
||||
// CHECK:STDOUT: call void @_ZN1N3RunEv(), !dbg !15
|
||||
// CHECK:STDOUT: ret i32 0, !dbg !16
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: attributes #0 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
|
||||
@@ -60,6 +60,7 @@ fn Run() {
|
||||
// CHECK:STDOUT: !10 = !{!"Simple C++ TBAA"}
|
||||
// CHECK:STDOUT: !11 = distinct !DISubprogram(name: "Run", linkageName: "main", scope: null, file: !6, line: 8, type: !12, spFlags: DISPFlagDefinition, unit: !5)
|
||||
// CHECK:STDOUT: !12 = !DISubroutineType(types: !13)
|
||||
// CHECK:STDOUT: !13 = !{null}
|
||||
// CHECK:STDOUT: !14 = !DILocation(line: 9, column: 3, scope: !11)
|
||||
// CHECK:STDOUT: !15 = !DILocation(line: 8, column: 1, scope: !11)
|
||||
// CHECK:STDOUT: !13 = !{!14}
|
||||
// CHECK:STDOUT: !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
|
||||
// CHECK:STDOUT: !15 = !DILocation(line: 9, column: 3, scope: !11)
|
||||
// CHECK:STDOUT: !16 = !DILocation(line: 8, column: 1, scope: !11)
|
||||
|
||||
Reference in New Issue
Block a user