@@ -406,6 +406,48 @@ map<u32, u64> tc_stats : HashMap(1024)
406406 | exn -> fail (" Error in " ^ prog_type ^ " test: " ^ Printexc. to_string exn )
407407 ) programs
408408
409+ (* * Test the fix for map access return bug *)
410+ let test_map_access_return_bug_fix () =
411+ let source = {|
412+ enum TestEnum {
413+ VALUE_A = 1 ,
414+ VALUE_B = 2
415+ }
416+
417+ map< u32, TestEnum > test_map : HashMap (64 )
418+
419+ @ helper
420+ fn get_value (key : u32 ) -> TestEnum {
421+ var result = test_map[key]
422+ if (result != none) {
423+ return result // This should return the dereferenced value, not pointer
424+ } else {
425+ return VALUE_A
426+ }
427+ }
428+
429+ @ xdp fn test_program (ctx : * xdp_md) -> xdp_action {
430+ var value = get_value(42 )
431+ return 2
432+ }
433+ |} in
434+
435+ (* Parse and compile *)
436+ let ast = parse_string source in
437+
438+ match compile_to_c_code ast with
439+ | Some c_code ->
440+ (* Check that the generated code contains the correct dereferencing pattern *)
441+ let has_deref_pattern = string_contains_substring c_code " __val" &&
442+ string_contains_substring c_code " *(ptr_" in
443+ let has_bad_pointer_return = string_contains_substring c_code " return ptr_" in
444+
445+ (* Verify the fix is applied: should have dereferencing but not direct pointer returns *)
446+ check bool " Map access return should be dereferenced" true has_deref_pattern;
447+ check bool " Should not return raw pointers" false has_bad_pointer_return
448+ | None ->
449+ fail " Failed to compile map access return test"
450+
409451let map_integration_tests = [
410452 " complete_map_compilation" , `Quick , test_complete_map_compilation;
411453 " multiple_map_types" , `Quick , test_multiple_map_types;
@@ -414,6 +456,7 @@ let map_integration_tests = [
414456 " map_operations_in_conditionals" , `Quick , test_map_operations_in_conditionals;
415457 " memory_safety" , `Quick , test_memory_safety;
416458 " different_context_types" , `Quick , test_different_context_types;
459+ " map_access_return_bug_fix" , `Quick , test_map_access_return_bug_fix;
417460]
418461
419462let () =
0 commit comments