aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2021-02-28 22:46:39 -0800
committerYonghong Song <yhs@fb.com>2021-03-01 10:23:24 -0800
commit283db5f0837d55f91242812003adf6e189ba743e (patch)
tree3fb0332c3504cc6472724bfaff223238b413c5ab /clang/lib/Sema/SemaChecking.cpp
parent52b8e10597315a96bc7cbc7cfe618e301c1e6e6c (diff)
downloadllvm-283db5f0837d55f91242812003adf6e189ba743e.zip
llvm-283db5f0837d55f91242812003adf6e189ba743e.tar.gz
llvm-283db5f0837d55f91242812003adf6e189ba743e.tar.bz2
BPF: fix enum value 0 issue for __builtin_preserve_enum_value()
Lorenz Bauer reported that the following code will have compilation error for bpf target: enum e { TWO }; bpf_core_enum_value_exists(enum e, TWO); The clang emitted the following error message: __builtin_preserve_enum_value argument 1 invalid In SemaChecking, an expression like "*(enum NAME)1" will have cast kind CK_IntegralToPointer, but "*(enum NAME)0" will have cast kind CK_NullToPointer. Current implementation only permits CK_IntegralToPointer, missing enum value 0 case. This patch permits CK_NullToPointer cast kind and the above test case can pass now. Differential Revision: https://reviews.llvm.org/D97659
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f67cba1..ccde2f3 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -2626,7 +2626,10 @@ static bool isValidBPFPreserveEnumValueArg(Expr *Arg) {
return false;
const auto *CE = dyn_cast<CStyleCastExpr>(UO->getSubExpr());
- if (!CE || CE->getCastKind() != CK_IntegralToPointer)
+ if (!CE)
+ return false;
+ if (CE->getCastKind() != CK_IntegralToPointer &&
+ CE->getCastKind() != CK_NullToPointer)
return false;
// The integer must be from an EnumConstantDecl.