[all-commits] [llvm/llvm-project] 044c51: Fix vector type scalar checking when the scalar op...

Erich Keane via All-commits all-commits at lists.llvm.org
Wed Mar 25 11:39:12 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 044c51d8d433da885438fcb141b15c80d7b62eda
      https://github.com/llvm/llvm-project/commit/044c51d8d433da885438fcb141b15c80d7b62eda
  Author: Erich Keane <erich.keane at intel.com>
  Date:   2020-03-25 (Wed, 25 Mar 2020)

  Changed paths:
    M clang/lib/Sema/SemaExpr.cpp
    M clang/test/SemaCXX/vector.cpp

  Log Message:
  -----------
  Fix vector type scalar checking when the scalar operand is dependent

As reported in PR45298 and PR45299, vector_size type checking would
crash when done in a situation where the scalar is dependent, such as
a member of the current instantiation.

This is because the scalar checking ensures that you can implicitly
convert a value to a vector-type as long as it doesn't require
truncation. It does this by using the constant evaluator to get the
value as a float. Unfortunately, if the scalar is dependent (such as a
member of the current instantiation), we would hit the assert in the
evaluator.

This patch suppresses the truncation- of-value check in the first phase
of translation. All values are properly errored upon instantiation. This
has one minor regression, in that previously in a non-asserts build,

template<typename T>
struct S {
  float4 f(float4 f) {
    return k + f;
  }
  static constexpr k = 1.1; // causes a truncation on conversion.
};

would error immediately. Because 'k' is value dependent (as a
member-of-the-current-instantiation), this would still be evaluatable
(despite normally asserting).  Due to this patch, this diagnostic is
delayed until instantiation time.




More information about the All-commits mailing list