From: Simon Pilgrim Date: Thu, 1 Jun 2017 20:13:34 +0000 (+0000) Subject: Don't assume that a store source is a vector type just because the destination is... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d3c869c889ad7c8fa419f9b4212de2290be83e0b;p=clang Don't assume that a store source is a vector type just because the destination is (PR26099) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304465 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 84ce896506..2aa0458792 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1487,9 +1487,9 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr, // Handle vectors differently to get better performance. if (Ty->isVectorType()) { llvm::Type *SrcTy = Value->getType(); - auto *VecTy = cast(SrcTy); + auto *VecTy = dyn_cast(SrcTy); // Handle vec3 special. - if (VecTy->getNumElements() == 3) { + if (VecTy && VecTy->getNumElements() == 3) { // Our source is a vec3, do a shuffle vector to make it a vec4. llvm::Constant *Mask[] = {Builder.getInt32(0), Builder.getInt32(1), Builder.getInt32(2), diff --git a/test/CodeGen/pr26099.c b/test/CodeGen/pr26099.c new file mode 100644 index 0000000000..15b73b832e --- /dev/null +++ b/test/CodeGen/pr26099.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -ffreestanding %s -triple=i686-apple-darwin -target-feature +mmx -emit-llvm -o - -Wall -Werror +// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +mmx -emit-llvm -o - -Wall -Werror +// REQUIRES: asserts + +#include + +int __attribute__ ((__vector_size__ (8))) b; + +void bar(int a) +{ + b = __builtin_ia32_vec_init_v2si (0, a); +} \ No newline at end of file