[clang] eabc885 - [BPF] make __BPF_FEATURE_MAY_GOTO available for cpuv1 (#108071)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 24 01:46:38 PDT 2024


Author: eddyz87
Date: 2024-09-24T11:46:33+03:00
New Revision: eabc8857e77c94a09624c12cc690753f68b87825

URL: https://github.com/llvm/llvm-project/commit/eabc8857e77c94a09624c12cc690753f68b87825
DIFF: https://github.com/llvm/llvm-project/commit/eabc8857e77c94a09624c12cc690753f68b87825.diff

LOG: [BPF] make __BPF_FEATURE_MAY_GOTO available for cpuv1 (#108071)

For some reason `__BPF_FEATURE_MAY_GOTO` is available for CPUs v{2,3,4}
but is not available for CPU v1. This limitation is arbitrary:
- the instruction is never produced by LLVM backend;
- on Linux Kernel side this instruction is available in kernels that
also support CPUv4.

Hence, it is more consistent to either always allow
`__BPF_FEATURE_MAY_GOTO` or only allow it for CPUv4.

Added: 
    

Modified: 
    clang/lib/Basic/Targets/BPF.cpp
    clang/test/Preprocessor/bpf-predefined-macros.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Basic/Targets/BPF.cpp b/clang/lib/Basic/Targets/BPF.cpp
index a94ceee5a6a5e7..931f407ecb0d7e 100644
--- a/clang/lib/Basic/Targets/BPF.cpp
+++ b/clang/lib/Basic/Targets/BPF.cpp
@@ -37,6 +37,7 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
   }
 
   Builder.defineMacro("__BPF_FEATURE_ADDR_SPACE_CAST");
+  Builder.defineMacro("__BPF_FEATURE_MAY_GOTO");
 
   if (CPU.empty())
     CPU = "v3";
@@ -48,7 +49,6 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
 
   std::string CpuVerNumStr = CPU.substr(1);
   Builder.defineMacro("__BPF_CPU_VERSION__", CpuVerNumStr);
-  Builder.defineMacro("__BPF_FEATURE_MAY_GOTO");
 
   int CpuVerNum = std::stoi(CpuVerNumStr);
   if (CpuVerNum >= 2)

diff  --git a/clang/test/Preprocessor/bpf-predefined-macros.c b/clang/test/Preprocessor/bpf-predefined-macros.c
index 360b9330b75fef..8c2143f767c40c 100644
--- a/clang/test/Preprocessor/bpf-predefined-macros.c
+++ b/clang/test/Preprocessor/bpf-predefined-macros.c
@@ -64,6 +64,9 @@ int s;
 #ifdef __BPF_FEATURE_ADDR_SPACE_CAST
 int t;
 #endif
+#ifdef __BPF_FEATURE_MAY_GOTO
+int u;
+#endif
 
 // CHECK: int b;
 // CHECK: int c;
@@ -98,6 +101,11 @@ int t;
 // CPU_V3: int t;
 // CPU_V4: int t;
 
+// CPU_V1: int u;
+// CPU_V2: int u;
+// CPU_V3: int u;
+// CPU_V4: int u;
+
 // CPU_GENERIC: int g;
 
 // CPU_PROBE: int f;


        


More information about the cfe-commits mailing list