Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/codex_review_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Codex PR review

on:
push:
branches:
- 'codex/review-pr-28368'
workflow_dispatch:

permissions:
contents: read

jobs:
review-pr-28368:
runs-on: ubuntu-24.04
timeout-minutes: 45
steps:
- uses: actions/checkout@v7
- name: Build V
run: make -j4
- name: Run new fixtures with supported C compilers
run: |
set -euo pipefail
for cc in tcc gcc clang; do
test "$(./v1_fallback -cc "$cc" run vlib/v/gen/c/testdata/alias_c_struct_field.vv)" = '42'
test "$(./v1_fallback -cc "$cc" run vlib/v/gen/c/testdata/alias_of_explicit_enum.vv)" = '0'
done
- name: Run C-output regression suite
run: ./v1_fallback vlib/v/gen/c/coutput_test.v
- name: Run checker tests
run: ./v1_fallback test vlib/v/checker
2 changes: 1 addition & 1 deletion vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -3137,7 +3137,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
}
}
field_name := node.field_name
mut sym := c.table.sym(typ)
mut sym := c.table.final_sym(typ)
mut final_sym := c.table.final_sym(typ)
if (typ.has_flag(.variadic) || final_sym.kind == .array_fixed) && field_name == 'len' {
node.typ = ast.int_type
Expand Down
35 changes: 32 additions & 3 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -9500,6 +9500,26 @@ fn (mut g Gen) debugger_stmt(node ast.DebuggerStmt) {
g.write('}')
}

fn (g &Gen) is_enum_type_used(enum_typ ast.Type) bool {
if !g.pref.skip_unused || enum_typ.idx() in g.table.used_features.used_syms {
return true
}
for sym in g.table.type_symbols {
if sym.kind != .alias || sym.idx !in g.table.used_features.used_syms {
continue
}
match sym.info {
ast.Alias {
if g.table.final_sym(sym.info.parent_type).idx == enum_typ.idx() {
return true
}
}
else {}
}
}
return false
}

fn (mut g Gen) enum_decl(node ast.EnumDecl) {
enum_name := util.no_dots(node.name)
is_flag := node.is_flag
Expand Down Expand Up @@ -9530,10 +9550,19 @@ fn (mut g Gen) enum_decl(node ast.EnumDecl) {
}
// Explicit-size enums are emitted as typedef + defines, so all C compilers
// (including tinyc) respect the selected storage size.
if g.is_cc_msvc || node.typ != ast.int_type {
mut needs_define_style := g.is_cc_msvc || node.typ != ast.int_type
if !needs_define_style {
for field in node.fields {
if field.has_expr && g.expr_string(field.expr).contains('v__') {
needs_define_style = true
break
}
}
}
if needs_define_style {
mut last_value := '0'
enum_typ_name := g.table.get_type_name(node.typ)
if g.pref.skip_unused && node.enum_typ !in g.table.used_features.used_syms {
if !g.is_enum_type_used(node.enum_typ) {
return
}
g.enum_typedefs.writeln('')
Expand All @@ -9556,7 +9585,7 @@ fn (mut g Gen) enum_decl(node ast.EnumDecl) {
}
return
}
if g.pref.skip_unused && node.enum_typ !in g.table.used_features.used_syms {
if !g.is_enum_type_used(node.enum_typ) {
return
}
g.enum_typedefs.writeln('')
Expand Down
1 change: 1 addition & 0 deletions vlib/v/gen/c/testdata/alias_c_struct_field.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
42
12 changes: 12 additions & 0 deletions vlib/v/gen/c/testdata/alias_c_struct_field.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
struct C.NativeConfig {
value int
}

type NativeConfig = C.NativeConfig

fn main() {
config := NativeConfig{
value: 42
}
println(config.value)
}
1 change: 1 addition & 0 deletions vlib/v/gen/c/testdata/alias_of_explicit_enum.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
15 changes: 15 additions & 0 deletions vlib/v/gen/c/testdata/alias_of_explicit_enum.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
enum RasterizationMode as u32 {
default = 0
max_enum = max_int
}

type RasterizationModeExt = RasterizationMode

struct Config {
mode RasterizationModeExt
}

fn main() {
config := Config{}
println(u32(config.mode))
}
Loading