diff options
author | Pierre Moreau <dev@pmoreau.org> | 2018-04-21 18:06:52 +0200 |
---|---|---|
committer | Karol Herbst <kherbst@redhat.com> | 2018-06-13 20:21:31 +0200 |
commit | a7e46a108c5c7e3d45c9abd8b4598c0b2f78fa44 (patch) | |
tree | fbd0eb1c52c790ef2cfb5a72239b191ae3df4070 | |
parent | 9ec367470f38c2bb1b8a6a01581ca9c2ac4ef4f5 (diff) |
Ensure a variable’s initialiser is not undefined
A variable initialiser has to be the result of a constant instruction or
be global variable; the result of OpUndef belongs to neither.
-rw-r--r-- | lib/SPIRV/SPIRVWriter.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp index 906a8a8..94f9e86 100644 --- a/lib/SPIRV/SPIRVWriter.cpp +++ b/lib/SPIRV/SPIRVWriter.cpp @@ -909,7 +909,8 @@ SPIRVValue *LLVMToSPIRV::transValueWithoutDecoration(Value *V, // Though variables with common linkage type are initialized by 0, // they can be represented in SPIR-V as uninitialized variables with // 'Export' linkage type, just as tentative definitions look in C - llvm::Value *Init = GV->hasInitializer() && !GV->hasCommonLinkage() + llvm::Value *Init = GV->hasInitializer() && !GV->hasCommonLinkage() && + !isa<UndefValue>(GV->getInitializer()) ? GV->getInitializer() : nullptr; StructType *ST = Init ? dyn_cast<StructType>(Init->getType()) : nullptr; |