This is an archive of the discontinued LLVM Phabricator instance.

[C2x] Update 'nullptr' implementation based on CD comments
ClosedPublic

Authored by aaron.ballman on Apr 20 2023, 6:46 AM.

Details

Summary

We filed some CD ballot comments which WG14 considered during the ballot comment resolution meetings in Jan and Feb 2023, and this updates our implementation based on the decisions reached. Those decisions were (paraphrased for brevity):

US 9-034 (REJECTED) -- allow (void *)nullptr to be a null pointer constant
US 10-035 (ACCEPTED) -- accept the following code, as in C++: void func(nullptr_t); func(0);
US 22-058 (REJECTED) -- accept the following code, as in C++: nullptr_t val; (void)(1 ? val : 0); (void)(1 ? nullptr : 0);
US 23-062 (REJECTED) -- reject the following code, as in C++: nullptr_t val; bool b1 = val; bool b2 = nullptr;
US 24-061 (ACCEPTED) -- accept the following code, as in C++: nullptr_t val; val = 0;
US 21-068 (ACCEPTED) -- accept the following code, as in C++: (nullptr_t)nullptr;
GB-071 (ACCEPTED) -- accept the following code, as in C++: nullptr_t val; (void)(val == nullptr);

This patch updates the implementation as appropriate, but is primarily focused around US 10-035, US 24-061, and US 23-062 in terms of functional changes.

Diff Detail

Event Timeline

aaron.ballman created this revision.Apr 20 2023, 6:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2023, 6:46 AM
aaron.ballman requested review of this revision.Apr 20 2023, 6:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2023, 6:46 AM
efriedma added inline comments.May 2 2023, 3:30 PM
clang/lib/Sema/SemaExpr.cpp
10087

I'd like to see testcases for:

  • Codegen (LLVM IR emission)
  • Constant evaluation. (Is a cast like this allowed in an integer constant expression?)

Updated based on review feedback:

  • Changed CK_Noop to CK_NullToPointer to model the same as in C++
  • Added codegen tests
  • Added a constant expression test
  • Fixed some comments in the test file
This revision is now accepted and ready to land.May 3 2023, 10:51 AM
This revision was landed with ongoing or failed builds.May 3 2023, 11:50 AM
This revision was automatically updated to reflect the committed changes.