r359310 - [BPF] do not generate predefined macro bpf

Yonghong Song via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 26 08:35:51 PDT 2019

Author: yhs
Date: Fri Apr 26 08:35:51 2019
New Revision: 359310

URL: http://llvm.org/viewvc/llvm-project?rev=359310&view=rev
[BPF] do not generate predefined macro bpf

"DefineStd(Builder, "bpf", Opts)" generates the following three
and the macro "bpf" is due to the fact that the target language
is C which allows GNU extensions.

The name "bpf" could be easily used as variable name or type
field name. For example, in current linux kernel, there are
four places where bpf is used as a field name. If the corresponding
types are included in bpf program, the compilation error will

This patch removed predefined macro "bpf" as well as "__bpf" which
is rarely used if used at all.

Signed-off-by: Yonghong Song <yhs at fb.com>

Differential Revision: https://reviews.llvm.org/D61173


Modified: cfe/trunk/lib/Basic/Targets/BPF.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/BPF.cpp?rev=359310&r1=359309&r2=359310&view=diff
--- cfe/trunk/lib/Basic/Targets/BPF.cpp (original)
+++ cfe/trunk/lib/Basic/Targets/BPF.cpp Fri Apr 26 08:35:51 2019
@@ -20,7 +20,7 @@ using namespace clang::targets;
 void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
                                      MacroBuilder &Builder) const {
-  DefineStd(Builder, "bpf", Opts);
+  Builder.defineMacro("__bpf__");

Added: cfe/trunk/test/Preprocessor/bpf-predefined-macros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/bpf-predefined-macros.c?rev=359310&view=auto
--- cfe/trunk/test/Preprocessor/bpf-predefined-macros.c (added)
+++ cfe/trunk/test/Preprocessor/bpf-predefined-macros.c Fri Apr 26 08:35:51 2019
@@ -0,0 +1,16 @@
+// RUN: %clang -E -target bpfel -x c -o - %s | FileCheck %s
+// RUN: %clang -E -target bpfeb -x c -o - %s | FileCheck %s
+#ifdef __bpf__
+int b;
+#ifdef __BPF__
+int c;
+#ifdef bpf
+int d;
+// CHECK: int b;
+// CHECK: int c;
+// CHECK-NOT: int d;

More information about the cfe-commits mailing list