Browse Source

[spirv] Fix bug for OpMemberDecorate for member 0.

Ehsan 6 years ago
parent
commit
8a9f49c685

+ 1 - 1
tools/clang/include/clang/SPIRV/EmitVisitor.h

@@ -60,7 +60,7 @@ public:
   // parameters.
   void emitDecoration(uint32_t typeResultId, spv::Decoration,
                       llvm::ArrayRef<uint32_t> decorationParams,
-                      uint32_t memberIndex = 0);
+                      llvm::Optional<uint32_t> memberIndex = llvm::None);
 
   // Emits the instruction for the given type into the typeConstantBinary and
   // returns the result-id for the type.

+ 5 - 4
tools/clang/lib/SPIRV/EmitVisitor.cpp

@@ -1591,14 +1591,15 @@ void EmitTypeHandler::emitLayoutDecorations(const StructType *structType,
 void EmitTypeHandler::emitDecoration(uint32_t typeResultId,
                                      spv::Decoration decoration,
                                      llvm::ArrayRef<uint32_t> decorationParams,
-                                     uint32_t memberIndex) {
+                                     llvm::Optional<uint32_t> memberIndex) {
 
-  spv::Op op = memberIndex ? spv::Op::OpMemberDecorate : spv::Op::OpDecorate;
+  spv::Op op =
+      memberIndex.hasValue() ? spv::Op::OpMemberDecorate : spv::Op::OpDecorate;
   assert(curDecorationInst.empty());
   curDecorationInst.push_back(static_cast<uint32_t>(op));
   curDecorationInst.push_back(typeResultId);
-  if (memberIndex)
-    curDecorationInst.push_back(memberIndex);
+  if (memberIndex.hasValue())
+    curDecorationInst.push_back(memberIndex.getValue());
   curDecorationInst.push_back(static_cast<uint32_t>(decoration));
   for (auto param : decorationParams)
     curDecorationInst.push_back(param);