This is an archive of the discontinued LLVM Phabricator instance.

Fix __is_signed builtin
ClosedPublic

Authored by zoecarver on Sep 22 2019, 4:26 PM.

Details

Summary

This patch fixes the __is_signed builtin type trait to work with floating point types. Now, the builtin will return true if it is passed a floating point type.

Event Timeline

zoecarver created this revision.Sep 22 2019, 4:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 22 2019, 4:26 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

But std::is_signed_v<float> needs to yield false. Isn't it cleaner to leave the compiler builtin matching the library type-trait, so that the library doesn't have to check for integral types separately?

Looks good, but please also update http://clang.llvm.org/docs/LanguageExtensions.html#type-trait-primitives

(Can I interest you in fixing the misbehaviour for enumeration types too?)

But std::is_signed_v<float> needs to yield false. Isn't it cleaner to leave the compiler builtin matching the library type-trait, so that the library doesn't have to check for integral types separately?

The idea is that these will match the standard. I don't see anywhere where the standard says that floating-point types yield false. The currently libc++ implementation also yields true for your example.

But std::is_signed_v<float> needs to yield false.

It should yield true; the spec says "If is_­arithmetic_­v<T> is true, the same result as T(-1) < T(0); otherwise, false".

But std::is_signed_v<float> needs to yield false.

It should yield true; the spec says "If is_­arithmetic_­v<T> is true, the same result as T(-1) < T(0); otherwise, false".

Whoops! Never mind me.

(Can I interest you in fixing the misbehaviour for enumeration types too?)

Certainly. You mean that __is_signed should return false for enumeration types?

zoecarver updated this revision to Diff 221247.Sep 22 2019, 8:21 PM
  • fix docs
rsmith accepted this revision.Sep 22 2019, 8:40 PM

(Can I interest you in fixing the misbehaviour for enumeration types too?)

Certainly. You mean that __is_signed should return false for enumeration types?

Yes, exactly.

clang/docs/LanguageExtensions.rst
1165 ↗(On Diff #221247)

I'd just drop the second half of this sentence, and keep the "likely to change" warning for the non-conformance for enumeration types until that's fixed. (We already have an introductory sentence that says we follow the standard-specified behavior for traits marked (C++) unless otherwise specified.)

This revision is now accepted and ready to land.Sep 22 2019, 8:40 PM
zoecarver updated this revision to Diff 221253.Sep 22 2019, 9:21 PM
  • fix behavior when passed an enumeration type

Thanks!

clang/docs/LanguageExtensions.rst
1165 ↗(On Diff #221247)

Now that this does the standard thing, you can delete this text entirely, or add a "before Clang 10, returned true for enumeration types if the underlying type was signed, and returned false for floating-point types".

zoecarver marked an inline comment as done.Sep 23 2019, 8:12 AM
zoecarver added inline comments.
clang/docs/LanguageExtensions.rst
1165 ↗(On Diff #221247)

I'll add that text before committing.

zoecarver closed this revision.Sep 23 2019, 8:46 AM

Resolved by rL372621.