* [PATCH 1/2] Fix compilation with Clang
@ 2026-06-04 3:49 lockalsash
2026-06-04 3:49 ` [PATCH 2/2] Fix `-Werror,-Wtautological-constant-out-of-range-compare` build error lockalsash
2026-06-13 15:07 ` [PATCH 1/2] Fix compilation with Clang Frank Ch. Eigler
0 siblings, 2 replies; 3+ messages in thread
From: lockalsash @ 2026-06-04 3:49 UTC (permalink / raw)
To: systemtap; +Cc: Sv. Lockal
From: "Sv. Lockal" <lockalsash@gmail.com>
Clang-22 fails to compile with errors like:
```
bpfinterp.cxx:1098:18: error: case value is not a constant expression
1098 | case bpf::BPF_FUNC_str_concat:
| ^~~~~~~~~~~~~~~~~~~~~~~~
```
GCC accepts const variables, but Clang enforces the standard more
strictly. Using enum allows both compilers to accept the code, but
requires cast from bpf::(unnamed enum) to bpf_func_id.
Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
---
bpf-base.cxx | 2 +-
bpf-internal.h | 24 +++++++++++++-----------
bpf-translate.cxx | 10 +++++-----
3 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/bpf-base.cxx b/bpf-base.cxx
index 740e8da24..e3ec08dd0 100644
--- a/bpf-base.cxx
+++ b/bpf-base.cxx
@@ -402,7 +402,7 @@ void
init_bpf_helper_tables ()
{
#define __BPF_SET_FUNC_NAME(x) bpf_func_name_map[BPF_FUNC_ ## x] = #x
-#define __BPF_SET_FUNC_ID(x) bpf_func_id_map[#x] = BPF_FUNC_ ## x
+#define __BPF_SET_FUNC_ID(x) bpf_func_id_map[#x] = (bpf_func_id)(BPF_FUNC_ ## x)
__BPF_FUNC_MAPPER(__BPF_SET_FUNC_NAME)
__STAPBPF_FUNC_MAPPER(__BPF_SET_FUNC_NAME)
__BPF_FUNC_MAPPER(__BPF_SET_FUNC_ID)
diff --git a/bpf-internal.h b/bpf-internal.h
index c53bda4e2..7774f1c1d 100644
--- a/bpf-internal.h
+++ b/bpf-internal.h
@@ -224,17 +224,19 @@ const opcode BPF_LD_MAP = BPF_LD | BPF_IMM | BPF_DW | (BPF_PSEUDO_MAP_FD << 8);
FN(text_str), \
FN(string_quoted),
-const bpf_func_id BPF_FUNC_map_get_next_key = (bpf_func_id) -1;
-const bpf_func_id BPF_FUNC_sprintf = (bpf_func_id) -2;
-const bpf_func_id BPF_FUNC_stapbpf_stat_get = (bpf_func_id) -3;
-const bpf_func_id BPF_FUNC_gettimeofday_ns = (bpf_func_id) -4;
-const bpf_func_id BPF_FUNC_get_target = (bpf_func_id) -5;
-const bpf_func_id BPF_FUNC_set_procfs_value = (bpf_func_id) -6;
-const bpf_func_id BPF_FUNC_append_procfs_value = (bpf_func_id) -7;
-const bpf_func_id BPF_FUNC_get_procfs_value = (bpf_func_id) -8;
-const bpf_func_id BPF_FUNC_str_concat = (bpf_func_id) -9;
-const bpf_func_id BPF_FUNC_text_str = (bpf_func_id) -10;
-const bpf_func_id BPF_FUNC_string_quoted = (bpf_func_id) -11;
+enum {
+ BPF_FUNC_map_get_next_key = (bpf_func_id) -1,
+ BPF_FUNC_sprintf = (bpf_func_id) -2,
+ BPF_FUNC_stapbpf_stat_get = (bpf_func_id) -3,
+ BPF_FUNC_gettimeofday_ns = (bpf_func_id) -4,
+ BPF_FUNC_get_target = (bpf_func_id) -5,
+ BPF_FUNC_set_procfs_value = (bpf_func_id) -6,
+ BPF_FUNC_append_procfs_value = (bpf_func_id) -7,
+ BPF_FUNC_get_procfs_value = (bpf_func_id) -8,
+ BPF_FUNC_str_concat = (bpf_func_id) -9,
+ BPF_FUNC_text_str = (bpf_func_id) -10,
+ BPF_FUNC_string_quoted = (bpf_func_id) -11
+};
struct insn
{
diff --git a/bpf-translate.cxx b/bpf-translate.cxx
index b77ccd6eb..cd1eeaf03 100644
--- a/bpf-translate.cxx
+++ b/bpf-translate.cxx
@@ -2309,7 +2309,7 @@ bpf_unparser::visit_foreach_loop(foreach_loop* s)
frame, newkey_ofs);
this_prog.mk_mov (this_ins, this_prog.lookup_reg(BPF_REG_4), id);
this_prog.mk_mov (this_ins, this_prog.lookup_reg(BPF_REG_5), limit);
- this_prog.mk_call (this_ins, BPF_FUNC_map_get_next_key, 5);
+ this_prog.mk_call (this_ins, (bpf_func_id)BPF_FUNC_map_get_next_key, 5);
this_prog.mk_jcond (this_ins, NE, this_prog.lookup_reg(BPF_REG_0), i0,
join_block, load_block_1);
@@ -2333,7 +2333,7 @@ bpf_unparser::visit_foreach_loop(foreach_loop* s)
frame, newkey_ofs);
this_prog.mk_mov (this_ins, this_prog.lookup_reg(BPF_REG_4), id);
this_prog.mk_mov (this_ins, this_prog.lookup_reg(BPF_REG_5), limit);
- this_prog.mk_call (this_ins, BPF_FUNC_map_get_next_key, 5);
+ this_prog.mk_call (this_ins, (bpf_func_id)BPF_FUNC_map_get_next_key, 5);
this_prog.mk_jcond (this_ins, NE, this_prog.lookup_reg(BPF_REG_0), i0,
join_block, load_block_1);
@@ -2848,7 +2848,7 @@ bpf_unparser::visit_concatenation (concatenation* e)
this_prog.mk_mov(this_ins, this_prog.lookup_reg(BPF_REG_2), placeholder_next);
// Call function to concatenate.
- this_prog.mk_call(this_ins, BPF_FUNC_str_concat, 2);
+ this_prog.mk_call(this_ins, (bpf_func_id)BPF_FUNC_str_concat, 2);
result_str = this_prog.new_reg();
this_prog.mk_mov(this_ins, result_str, this_prog.lookup_reg(BPF_REG_0));
@@ -3948,7 +3948,7 @@ bpf_unparser::emit_print_format (const std::string& format,
for (size_t i = 0; i < nargs; ++i)
emit_mov(this_prog.lookup_reg(BPF_REG_3 + i), actual[i]);
- this_prog.mk_call(this_ins, BPF_FUNC_sprintf, nargs + 2);
+ this_prog.mk_call(this_ins, (bpf_func_id)BPF_FUNC_sprintf, nargs + 2);
return this_prog.lookup_reg(BPF_REG_0);
}
@@ -4172,7 +4172,7 @@ bpf_unparser::visit_stat_op (stat_op* e)
uint64_t sc_type = globals::intern_sc_type(e->ctype);
emit_mov(this_prog.lookup_reg(BPF_REG_3), this_prog.new_imm(sc_type));
- this_prog.mk_call (this_ins, BPF_FUNC_stapbpf_stat_get, 3);
+ this_prog.mk_call (this_ins, (bpf_func_id)BPF_FUNC_stapbpf_stat_get, 3);
result = this_prog.new_reg();
emit_mov(result, this_prog.lookup_reg(BPF_REG_0));
--
2.54.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] Fix `-Werror,-Wtautological-constant-out-of-range-compare` build error
2026-06-04 3:49 [PATCH 1/2] Fix compilation with Clang lockalsash
@ 2026-06-04 3:49 ` lockalsash
2026-06-13 15:07 ` [PATCH 1/2] Fix compilation with Clang Frank Ch. Eigler
1 sibling, 0 replies; 3+ messages in thread
From: lockalsash @ 2026-06-04 3:49 UTC (permalink / raw)
To: systemtap; +Cc: Sv. Lockal
From: "Sv. Lockal" <lockalsash@gmail.com>
Clang-22 fails to build with the following error:
```
stapbpf.cxx:2033:21: error: result of comparison of constant 2305843009213693951 with expression of
type 'unsigned int' is always false [-Werror,-Wtautological-constant-out-of-range-compare]
2033 | if (n_active_cpus > (size_t)-1 / sizeof(struct pollfd))
| ~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
as `n_active_cpus` is of type `unsigned` (32-bit), so it should be
compared against another `unsigned`.
Signed-off-by: Sv. Lockal <lockalsash@gmail.com>
---
stapbpf/stapbpf.cxx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/stapbpf/stapbpf.cxx b/stapbpf/stapbpf.cxx
index 0fca30f2b..ed6d67da4 100644
--- a/stapbpf/stapbpf.cxx
+++ b/stapbpf/stapbpf.cxx
@@ -2030,7 +2030,7 @@ perf_event_loop(pthread_t main_thread)
= map_attrs[bpf::globals::perf_event_map_idx].max_entries;
unsigned n_active_cpus
= count_active_cpus();
- if (n_active_cpus > (size_t)-1 / sizeof(struct pollfd))
+ if (n_active_cpus > (unsigned)-1 / sizeof(struct pollfd))
fatal("Too many active CPUs for pollfd allocation\n");
struct pollfd *pmu_fds
= (struct pollfd *)malloc(n_active_cpus * sizeof(struct pollfd));
--
2.54.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] Fix compilation with Clang
2026-06-04 3:49 [PATCH 1/2] Fix compilation with Clang lockalsash
2026-06-04 3:49 ` [PATCH 2/2] Fix `-Werror,-Wtautological-constant-out-of-range-compare` build error lockalsash
@ 2026-06-13 15:07 ` Frank Ch. Eigler
1 sibling, 0 replies; 3+ messages in thread
From: Frank Ch. Eigler @ 2026-06-13 15:07 UTC (permalink / raw)
To: lockalsash; +Cc: systemtap
lockalsash@gmail.com writes:
> From: "Sv. Lockal" <lockalsash@gmail.com>
>
> Clang-22 fails to compile with errors like: [...]
Thank you for your patches, they were merged.
- FChE
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-13 15:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-04 3:49 [PATCH 1/2] Fix compilation with Clang lockalsash
2026-06-04 3:49 ` [PATCH 2/2] Fix `-Werror,-Wtautological-constant-out-of-range-compare` build error lockalsash
2026-06-13 15:07 ` [PATCH 1/2] Fix compilation with Clang Frank Ch. Eigler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).