From 8c199f23fb6405e08d4f888dfdd141a895ee5413 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Mon, 15 May 2017 22:04:03 +0000 Subject: [PATCH] [Sema] Use CK_NoOp instead CK_Invalid in tryGCCVectorConvertAndSplat This fix UBSAN bots after r302935. Storing non-defined values in enum is undefined behavior. Other places, where "if (ScalarCast != CK_Invalid)" is used, never get to the "if" with CK_Invalid. tryGCCVectorConvertAndSplat can get to the "if" with CK_Invalid and it looks like expected case. So we have to use something other than CK_Invalid, e.g. CK_NoOp. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303121 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index fa64c4523f..14efc96720 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -8204,7 +8204,7 @@ static bool tryGCCVectorConvertAndSplat(Sema &S, ExprResult *Scalar, // The conversion to apply to the scalar before splatting it, // if necessary. - CastKind ScalarCast = CK_Invalid; + CastKind ScalarCast = CK_NoOp; // Accept cases where the vector elements are integers and the scalar is // an integer. @@ -8254,7 +8254,7 @@ static bool tryGCCVectorConvertAndSplat(Sema &S, ExprResult *Scalar, // Adjust scalar if desired. if (Scalar) { - if (ScalarCast != CK_Invalid) + if (ScalarCast != CK_NoOp) *Scalar = S.ImpCastExprToType(Scalar->get(), VectorEltTy, ScalarCast); *Scalar = S.ImpCastExprToType(Scalar->get(), VectorTy, CK_VectorSplat); } -- 2.40.0