This is an archive of the discontinued LLVM Phabricator instance.

BPF: fix enum value 0 issue for __builtin_preserve_enum_value()
ClosedPublic

Authored by yonghong-song on Feb 28 2021, 11:18 PM.

Details

Summary

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.

Diff Detail

Event Timeline

yonghong-song requested review of this revision.Feb 28 2021, 11:18 PM
yonghong-song created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 28 2021, 11:18 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
ast accepted this revision.Mar 1 2021, 10:04 AM
This revision is now accepted and ready to land.Mar 1 2021, 10:04 AM
This revision was landed with ongoing or failed builds.Mar 1 2021, 10:24 AM
This revision was automatically updated to reflect the committed changes.