[clang] 2edc21e - Fix altivec regression caused by D115670 in Vec Const Eval
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 4 09:53:31 PST 2022
Author: Erich Keane
Date: 2022-01-04T09:53:26-08:00
New Revision: 2edc21e8566be8fa9b20e0bb71a83af90ec9aa97
URL: https://github.com/llvm/llvm-project/commit/2edc21e8566be8fa9b20e0bb71a83af90ec9aa97
DIFF: https://github.com/llvm/llvm-project/commit/2edc21e8566be8fa9b20e0bb71a83af90ec9aa97.diff
LOG: Fix altivec regression caused by D115670 in Vec Const Eval
The Vector Constant Evaluator assumes that all the types of its
sub-expressions are going to be Vector APValues, which holds for most
situations. However, in the 1 examples of Altivec C compilation of
operator ++ (not allowed for other vector types), the result is an
LValue.
Since the operator isn't supported for constant evaluation anyway, this
patch just fails-out of constant eval if we are in a situation where the
operand to the unary operator causes an LValue.
Added:
Modified:
clang/lib/AST/ExprConstant.cpp
clang/test/Sema/altivec-init.c
Removed:
################################################################################
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 3bf205d8cb064..9412aba42dfb7 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -10434,6 +10434,15 @@ bool VectorExprEvaluator::VisitUnaryOperator(const UnaryOperator *E) {
if (!Evaluate(SubExprValue, Info, SubExpr))
return false;
+ // FIXME: This vector evaluator someday needs to be changed to be LValue
+ // aware/keep LValue information around, rather than dealing with just vector
+ // types directly. Until then, we cannot handle cases where the operand to
+ // these unary operators is an LValue. The only case I've been able to see
+ // cause this is operator++ assigning to a member expression (only valid in
+ // altivec compilations) in C mode, so this shouldn't limit us too much.
+ if (SubExprValue.isLValue())
+ return false;
+
assert(SubExprValue.getVectorLength() == VD->getNumElements() &&
"Vector length doesn't match type?");
diff --git a/clang/test/Sema/altivec-init.c b/clang/test/Sema/altivec-init.c
index 1c20450a6d015..ee38e70706714 100644
--- a/clang/test/Sema/altivec-init.c
+++ b/clang/test/Sema/altivec-init.c
@@ -45,3 +45,16 @@ void test()
int res = vGCC > vAltiVec;
vAltiVec = 0 ? vGCC : vGCC;
}
+
+typedef struct VecMem {
+ vector signed vec;
+} VecMem;
+
+// The following should not assert. See qiongsiwu1's comment here:
+// https://reviews.llvm.org/D115670
+void test2() {
+ vector signed local_vec = {1, 2, 3, 4};
+ VecMem VM;
+ VM.vec = ++local_vec;
+}
+
More information about the cfe-commits
mailing list