yonghong-song created this revision.
yonghong-song added a reviewer: ast.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

"DefineStd(Builder, "bpf", Opts)" generates the following three macros:

  bpf
  __bpf
  __bpf__

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
occur.

This patch removed predefined macro "bpf".


Repository:
  rC Clang

https://reviews.llvm.org/D61173

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


Index: test/Preprocessor/bpf-predefined-macros.c
===================================================================
--- /dev/null
+++ test/Preprocessor/bpf-predefined-macros.c
@@ -0,0 +1,20 @@
+// 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 a;
+#endif
+#ifdef __bpf__
+int b;
+#endif
+#ifdef __BPF__
+int c;
+#endif
+#ifdef bpf
+int d;
+#endif
+
+// CHECK: int a;
+// CHECK: int b;
+// CHECK: int c;
+// CHECK-NOT: int d;
Index: lib/Basic/Targets/BPF.cpp
===================================================================
--- lib/Basic/Targets/BPF.cpp
+++ lib/Basic/Targets/BPF.cpp
@@ -20,7 +20,8 @@
 
 void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
                                      MacroBuilder &Builder) const {
-  DefineStd(Builder, "bpf", Opts);
+  Builder.defineMacro("__bpf");
+  Builder.defineMacro("__bpf__");
   Builder.defineMacro("__BPF__");
 }
 


Index: test/Preprocessor/bpf-predefined-macros.c
===================================================================
--- /dev/null
+++ test/Preprocessor/bpf-predefined-macros.c
@@ -0,0 +1,20 @@
+// 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 a;
+#endif
+#ifdef __bpf__
+int b;
+#endif
+#ifdef __BPF__
+int c;
+#endif
+#ifdef bpf
+int d;
+#endif
+
+// CHECK: int a;
+// CHECK: int b;
+// CHECK: int c;
+// CHECK-NOT: int d;
Index: lib/Basic/Targets/BPF.cpp
===================================================================
--- lib/Basic/Targets/BPF.cpp
+++ lib/Basic/Targets/BPF.cpp
@@ -20,7 +20,8 @@
 
 void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
                                      MacroBuilder &Builder) const {
-  DefineStd(Builder, "bpf", Opts);
+  Builder.defineMacro("__bpf");
+  Builder.defineMacro("__bpf__");
   Builder.defineMacro("__BPF__");
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to