Skip vptr when performing object initialization (#4490)

The cehck for vptr could be done differently (is this class dynamic and
its base class non-dynamic), and if we change the layout (to put the
vptr after any base) then this code will break (could add an assertion
that the vptr isn't present apart from at the start of the field list if
that'd seem worthwhile).

There's still later issues with lowering (if this patch causes crashes
in lowering, do they result in fuzz failures/need to be avoided before
this change is submitted?)
This commit is contained in:
David Blaikie
2024-11-06 18:27:40 +00:00
committed by GitHub
parent fcabeb6725
commit d79a374ad4
2 changed files with 21 additions and 12 deletions
+6 -8
View File
@@ -37,17 +37,13 @@ base class Derived {
extend base: Modifiers.Base;
}
// --- fail_todo_init.carbon
// --- init.carbon
package Init;
import Modifiers;
fn F() {
// TODO: The vptr shouldn't be counted for programmer-facing behavior.
// CHECK:STDERR: fail_todo_init.carbon:[[@LINE+3]]:27: error: cannot initialize class with 1 field from struct with 0 fields [StructInitElementCountMismatch]
// CHECK:STDERR: var v: Modifiers.Base = {};
// CHECK:STDERR: ^~
var v: Modifiers.Base = {};
}
@@ -190,7 +186,7 @@ fn F() {
// CHECK:STDOUT:
// CHECK:STDOUT: virtual fn @F();
// CHECK:STDOUT:
// CHECK:STDOUT: --- fail_todo_init.carbon
// CHECK:STDOUT: --- init.carbon
// CHECK:STDOUT:
// CHECK:STDOUT: constants {
// CHECK:STDOUT: %F.type: type = fn_type @F [template]
@@ -243,8 +239,10 @@ fn F() {
// CHECK:STDOUT: %Base.ref: type = name_ref Base, imports.%import_ref.1 [template = constants.%Base]
// CHECK:STDOUT: %v.var: ref %Base = var v
// CHECK:STDOUT: %v: ref %Base = bind_name v, %v.var
// CHECK:STDOUT: %.loc11: %.6 = struct_literal ()
// CHECK:STDOUT: assign %v.var, <error>
// CHECK:STDOUT: %.loc7_28.1: %.6 = struct_literal ()
// CHECK:STDOUT: %.loc7_28.2: init %Base = class_init (<error>), %v.var [template = <error>]
// CHECK:STDOUT: %.loc7_29: init %Base = converted %.loc7_28.1, %.loc7_28.2 [template = <error>]
// CHECK:STDOUT: assign %v.var, %.loc7_29
// CHECK:STDOUT: return
// CHECK:STDOUT: }
// CHECK:STDOUT: