[PATCH] D61173: [BPF] do not generate predefined macro bpf
Yonghong Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 25 22:55:41 PDT 2019
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__");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61173.196797.patch
Type: text/x-patch
Size: 975 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190426/53ea6e53/attachment.bin>
More information about the cfe-commits
mailing list