[PATCH] D99299: Normalize interaction with boolean attributes

serge via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 13 13:22:51 PDT 2021


serge-sans-paille marked 2 inline comments as done.
serge-sans-paille added inline comments.


================
Comment at: llvm/lib/IR/Attributes.cpp:653
+bool AttributeImpl::getValueAsBool() const {
+  assert(getValueAsString().empty() || getValueAsString() == "false" || getValueAsString() == "true");
+  return getValueAsString() == "true";
----------------
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())
```



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

https://reviews.llvm.org/D99299



More information about the llvm-commits mailing list