From 276b4e7f86499fe84998342d76d0db521ca7f0aa Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Fri, 26 Apr 2019 15:35:51 +0000 Subject: [PATCH] [BPF] do not generate predefined macro bpf "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" as well as "__bpf" which is rarely used if used at all. Signed-off-by: Yonghong Song Differential Revision: https://reviews.llvm.org/D61173 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359310 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets/BPF.cpp | 2 +- test/Preprocessor/bpf-predefined-macros.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/Preprocessor/bpf-predefined-macros.c diff --git a/lib/Basic/Targets/BPF.cpp b/lib/Basic/Targets/BPF.cpp index e0527db59c..0cf55a58a9 100644 --- a/lib/Basic/Targets/BPF.cpp +++ b/lib/Basic/Targets/BPF.cpp @@ -20,7 +20,7 @@ using namespace clang::targets; void BPFTargetInfo::getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const { - DefineStd(Builder, "bpf", Opts); + Builder.defineMacro("__bpf__"); Builder.defineMacro("__BPF__"); } diff --git a/test/Preprocessor/bpf-predefined-macros.c b/test/Preprocessor/bpf-predefined-macros.c new file mode 100644 index 0000000000..bcb985f954 --- /dev/null +++ b/test/Preprocessor/bpf-predefined-macros.c @@ -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; +#endif +#ifdef __BPF__ +int c; +#endif +#ifdef bpf +int d; +#endif + +// CHECK: int b; +// CHECK: int c; +// CHECK-NOT: int d; -- 2.50.1