This is an archive of the discontinued LLVM Phabricator instance.

[OpenCL] NULL introduced prior to v2.0
ClosedPublic

Authored by Topotuna on Jul 14 2021, 8:15 AM.

Details

Summary

NULL macro maps to ((void*)0) for OpenCL versions earlier than 2.0

NULL was undefined in OpenCL prior to version 2.0. However, the
language specification states that `macro names defined by the C99
specification but not currently supported by OpenCL are reserved
for future use`. Therefore, application developers cannot redefine
NULL.

The change is supposed to resolve inconsistency between language
versions. Currently there is no apparent reason why NULL should
be kept undefined.

Fixes llvm.org/PR48102

Diff Detail

Event Timeline

Topotuna created this revision.Jul 14 2021, 8:15 AM
Topotuna requested review of this revision.Jul 14 2021, 8:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2021, 8:15 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

This seems reasonable.

clang/test/SemaOpenCL/null_literal.cl
1–5

I think we should remove this NULL definition but instead add -finclude-default-header -fdeclare-opencl-builtins to test the definition you are adding in the header.

Topotuna updated this revision to Diff 358625.Jul 14 2021, 8:57 AM

Added compile time flags

-finclude-default-header -fdeclare-opencl-builtins

instead of

#define NULL ((void*)0)
Topotuna updated this revision to Diff 358628.Jul 14 2021, 9:02 AM

Wrong diff file added previously

Topotuna marked an inline comment as done.Jul 14 2021, 9:06 AM
Anastasia added inline comments.Jul 15 2021, 3:37 AM
clang/lib/Headers/opencl-c-base.h
167

I think we should drop #if here since the condition now includes both OpenCL kernel languages that clang supports.

clang/test/SemaOpenCL/null_literal.cl
1–5

Ok, is this a full diff? https://llvm.org/docs/Phabricator.html#requesting-a-review-via-the-web-interface

Because the file appears to be incompletely displayed or something...

Topotuna updated this revision to Diff 358911.Jul 15 2021, 3:51 AM

Full diff now added. Redundant condition #if removed

Topotuna marked 2 inline comments as done.Jul 15 2021, 3:53 AM
Topotuna added inline comments.
clang/test/SemaOpenCL/null_literal.cl
1–5

Apologies. That was not a full diff. Should be fixed now.

Anastasia accepted this revision.Jul 15 2021, 3:31 PM

LGTM! Thanks

This revision is now accepted and ready to land.Jul 15 2021, 3:31 PM
This revision was landed with ongoing or failed builds.Jul 23 2021, 3:55 AM
This revision was automatically updated to reflect the committed changes.