@@ -692,6 +692,9 @@ kprobe:f { $x = hist(1); }
692692)" );
693693 test_error (" kprobe:f { @x[hist(1)] = 1; }" , R"(
694694stdin:1:12-22: ERROR: hist() should be directly assigned to a map
695+ kprobe:f { @x[hist(1)] = 1; }
696+ ~~~~~~~~~~
697+ stdin:1:12-22: ERROR: hist_t cannot be used as a map key
695698kprobe:f { @x[hist(1)] = 1; }
696699 ~~~~~~~~~~
697700)" );
@@ -764,6 +767,9 @@ stdin:1:12-21: ERROR: lhist() should be directly assigned to a map
764767kprobe:f { @[lhist()] = 1; }
765768 ~~~~~~~~~
766769stdin:1:12-21: ERROR: lhist() requires 4 arguments (0 provided)
770+ kprobe:f { @[lhist()] = 1; }
771+ ~~~~~~~~~
772+ stdin:1:12-21: ERROR: lhist_t cannot be used as a map key
767773kprobe:f { @[lhist()] = 1; }
768774 ~~~~~~~~~
769775)" );
@@ -2556,6 +2562,33 @@ stdin:4:9-30: ERROR: Argument mismatch for @x: trying to access with arguments:
25562562)" );
25572563}
25582564
2565+ TEST (semantic_analyser, per_cpu_map_as_map_key)
2566+ {
2567+ test (" BEGIN { @x = count(); @y[@x] = 1; }" );
2568+ test (" BEGIN { @x = sum(10); @y[@x] = 1; }" );
2569+ test (" BEGIN { @x = min(1); @y[@x] = 1; }" );
2570+ test (" BEGIN { @x = max(1); @y[@x] = 1; }" );
2571+ test (" BEGIN { @x = avg(1); @y[@x] = 1; }" );
2572+
2573+ test_error (" BEGIN { @x = hist(10); @y[@x] = 1; }" , R"(
2574+ stdin:1:24-29: ERROR: hist_t cannot be used as a map key
2575+ BEGIN { @x = hist(10); @y[@x] = 1; }
2576+ ~~~~~
2577+ )" );
2578+
2579+ test_error (" BEGIN { @x = lhist(10, 0, 10, 1); @y[@x] = 1; }" , R"(
2580+ stdin:1:35-40: ERROR: lhist_t cannot be used as a map key
2581+ BEGIN { @x = lhist(10, 0, 10, 1); @y[@x] = 1; }
2582+ ~~~~~
2583+ )" );
2584+
2585+ test_error (" BEGIN { @x = stats(10); @y[@x] = 1; }" , R"(
2586+ stdin:1:25-30: ERROR: stats_t cannot be used as a map key
2587+ BEGIN { @x = stats(10); @y[@x] = 1; }
2588+ ~~~~~
2589+ )" );
2590+ }
2591+
25592592TEST (semantic_analyser, probe_short_name)
25602593{
25612594 test (" t:a:b { args }" );
0 commit comments