Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf expr: Allow NaN to be a valid number

Currently only floating point numbers can be parsed, add a special
case for NaN.

Signed-off-by: Ian Rogers <irogers@google.com>
Reviewed-by: Kan Liang <kan.liang@linux.intel.com>
Cc: K Prateek Nayak <kprateek.nayak@amd.com>
Cc: James Clark <james.clark@arm.com>
Cc: Kaige Ye <ye@kaige.org>
Cc: John Garry <john.g.garry@oracle.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240209204947.3873294-2-irogers@google.com

authored by

Ian Rogers and committed by
Namhyung Kim
4ea7d944 923e4616

+9
+9
tools/perf/util/expr.l
··· 94 94 } 95 95 return LITERAL; 96 96 } 97 + 98 + static int nan_value(yyscan_t scanner) 99 + { 100 + YYSTYPE *yylval = expr_get_lval(scanner); 101 + 102 + yylval->num = NAN; 103 + return NUMBER; 104 + } 97 105 %} 98 106 99 107 number ([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)(e-?[0-9]+)? ··· 123 115 source_count { return SOURCE_COUNT; } 124 116 has_event { return HAS_EVENT; } 125 117 strcmp_cpuid_str { return STRCMP_CPUID_STR; } 118 + NaN { return nan_value(yyscanner); } 126 119 {literal} { return literal(yyscanner, sctx); } 127 120 {number} { return value(yyscanner); } 128 121 {symbol} { return str(yyscanner, ID, sctx->runtime); }