[PATCH] D64600: [ObjC] Add an attribute that "clamps" signed char BOOLs to {0,1}

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 18 11:37:40 PDT 2019


aaron.ballman added inline comments.


================
Comment at: clang/include/clang/Basic/Attr.td:3279
+def ObjCClampingBool : TypeAttr {
+  let Spellings = [Clang<"objc_clamping_bool">];
+  let Subjects = SubjectList<[TypedefName]>;
----------------
dexonsmith wrote:
> erik.pilkington wrote:
> > aaron.ballman wrote:
> > > Is there a desire for similar functionality for C's `_Bool` datatype, or other, custom datatypes (perhaps `BOOL` from the Win32 APIs)? It seems like this attribute could be generalized to apply to any typedef to an integral type.
> > Sure, I guess there isn't anything Objective-C specific about this. The new patches renames it to `clamping_integral_bool` (and permits it on any integral type).
> Given that "clamping" isn't exactly what's going on -- since `-1` becomes `1`, not `0` -- is there another word we can use here?
> Given that "clamping" isn't exactly what's going on -- since -1 becomes 1, not 0 -- is there another word we can use here?

`converting_integral_bool` is a bit closer to what it's doing. Or `mapping`. But neither of those names really strike me as more amazing than Erik's current name. `boolify`.


================
Comment at: clang/include/clang/Basic/AttrDocs.td:4153
+The ``clamping_integral_bool`` attribute appertains only to typedefs that alias
+an integral type. Its meant to be used to annotate custom boolean types in
+languages without a native bool type, namely (but not necessarily) in
----------------
Its -> It's or It is, your call.


================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2712
+def err_clamping_integral_bool_bad_type : Error<
+  "clamping_integral_bool attribute must appertain to an integral type">;
 
----------------
`"'clamping_integral_bool' attribute only applies to a typedef to an integral type"`


================
Comment at: clang/lib/CodeGen/CodeGenFunction.h:3400
+  /// Emit code to "clamp" an integer into {0,1}.
+  llvm::Value *EmitClampIntegerToBool(llvm::Value *);
+
----------------
Please give the parameter a name.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64600/new/

https://reviews.llvm.org/D64600





More information about the cfe-commits mailing list