[PATCH] D99299: Normalize interaction with boolean attributes

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 13 13:25:35 PDT 2021


nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LGTM



================
Comment at: llvm/lib/IR/Attributes.cpp:653
+bool AttributeImpl::getValueAsBool() const {
+  assert(getValueAsString().empty() || getValueAsString() == "false" || getValueAsString() == "true");
+  return getValueAsString() == "true";
----------------
serge-sans-paille wrote:
> nikic wrote:
> > By the way, why is empty string allowed as a value here? Are there existing uses of empty string as false?
> Because that's how an attribute is return when it's asked for while not being specified. This avoid having to check for the attribute presence before asking for its value. See Below:
> 
> ```
> if (FnAttrs.hasFnAttribute("unsafe-fp-math") &&
>       F.getFnAttribute("unsafe-fp-math").getValueAsString() == "true")
> ```
> 
> becomes
> 
> ```
> if (F.getFnAttribute("unsafe-fp-math").getValueAsBool())
> ```
> 
Ah yes, that makes sense.


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

https://reviews.llvm.org/D99299



More information about the llvm-commits mailing list