This is an archive of the discontinued LLVM Phabricator instance.

[clang] Implement constexpr evaluation for `__builtin_{add,sub}c`
AbandonedPublic

Authored by BertalanD on Jul 24 2023, 11:03 AM.

Details

Summary

GCC has gained support for these multiprecision arithmetic builtins in
r14-1896-g2b4e0415ad6, and although they aren't explicitly specified
as such in the documentation, they are usable in a constexpr context.

This commit adds constexpr evaluation support to Clang to match GCC's
behavior. The implementation mirrors how the builtins are lowered to a
pair of u{add,sub}.with.overflow operations and the carryout is set to
1 if either of those result in an overflow.

Diff Detail

Event Timeline

BertalanD created this revision.Jul 24 2023, 11:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2023, 11:03 AM
BertalanD requested review of this revision.Jul 24 2023, 11:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2023, 11:03 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
BertalanD edited the summary of this revision. (Show Details)Jul 24 2023, 11:03 AM

Thank you for this! The code changes themselves look good to me, but there's a few minor things left to do. You should also update the documentation somewhere near https://github.com/llvm/llvm-project/blob/118f95b394655d9dd425575025eafc6b79c3d84c/clang/docs/LanguageExtensions.rst?plain=1#L2467 to make it clear that we support these builtins and that they are allowed in a constant expression (we're trying to improve our implementation-defined documentation as we update stuff). And you should also add a release note to clang/docs/ReleaseNotes.rst as well.

clang/test/SemaCXX/builtins-multiprecision.cpp
1

Adding this just to be sure that the include below picks up the limits.h from the compiler and not the limits.h from the test system itself.