================
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -triple bpf -debug-info-kind=limited -fsyntax-only
-verify=expected,reloc -Wswitch %s
+// RUN: %clang_cc1 -triple bpf -fsyntax-only -verify=expected,reloc -Wswitch %s
+// RUN: %clang_cc1 -triple bpf -debug-info-kind=limited -fsyntax-only -verify
-Wswitch \
+// RUN: -fbpf-no-enum-reloc=E %s
+
+// A relocated enumerator in a case label is not diagnosed by
+// -Wbpf-enum-not-relocated. The case labels are checked with the local values,
+// as with -fbpf-no-enum-reloc=.
+
+enum E { A = 1, B = 4, C = 8, D = 300 } __attribute__((preserve_access_index));
+
+int f(int i, char c, enum E e) {
+ switch (i) {
+ case A: // expected-note {{previous case defined here}}
+ return 1;
+ case 1: // expected-error {{duplicate case value: 'A' and '1' both equal
'1'}}
----------------
yonghong-song wrote:
Actually, we don't know. So we have the following rules:
```
With -g, the switch condition is compared with each relocated case value before
the switch, in source order, so a relocated case is taken if its value equals
the value of another case at load time.
```
In commit message and comments in the code. So at runtime, priority is for
relocated cases over non-relocated cases. For relocated cases, the source order
will be used.
gcc has similar rules like the above. See
https://gcc.gnu.org/pipermail/bpf/2026-November/000304.html (not merged yet but
seems they are working on this now.)
https://github.com/llvm/llvm-project/pull/243338
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits