[PATCH] D76031: [mlir][CRunnerUtils] Enable compilation with C++11 toolchain on microcontroller platforms.

Nicolas Vasilache via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 12 07:35:55 PDT 2020


nicolasvasilache marked 2 inline comments as done.
nicolasvasilache added inline comments.


================
Comment at: mlir/include/mlir/ExecutionEngine/CRunnerUtils.h:48
 constexpr unsigned nextPowerOf2(int N) {
-  if (N <= 1)
-    return 1;
-  return isPowerOf2(N) ? N : 2 * nextPowerOf2((N + 1) / 2);
+  return (N <= 1) ? 1 : (isPowerOf2(N) ? N : 2 * nextPowerOf2((N + 1) / 2));
 }
----------------
nicolasvasilache wrote:
> flaub wrote:
> > aartbik wrote:
> > > perhaps use () on the part after : too for readability
> > > (assuming this does not violate some llvm brevity rule I don't know yet :-)
> > Chaining multiple ternary operations just seems less readable than the original.
> I agree but I have recollections from olden days that strict C++11 can only deduce the type if the body is a single line return statement.
> The person who submitted this internally has a strict C++11 toolchain.
> I found a few places that mention this limit (e.g. grep "single line" in https://en.cppreference.com/w/cpp/language/constexpr)
> But I didn't go and dig into the standard for a 1-line readability regression.
>  
> 
@flaub 

I can confirm that with the CMake change to force C++11 I get the following error on the old code:
```
/usr/local/google/home/ntv/work/github/llvm-project/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h:48:3: error: use of this statement in a constexpr function is a C++14 extension [-Werror,-Wc++14-extensions]
  if (N <= 1) return 1;
  ^
/usr/local/google/home/ntv/work/github/llvm-project/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h:49:3: error: multiple return statements in constexpr function is a C++14 extension [-Werror,-Wc++14-extensions]
  return (isPowerOf2(N) ? N : 2 * nextPowerOf2((N + 1) / 2));
  ^
/usr/local/google/home/ntv/work/github/llvm-project/mlir/include/mlir/ExecutionEngine/CRunnerUtils.h:48:15: note: previous return statement is here
  if (N <= 1) return 1;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76031





More information about the llvm-commits mailing list