浏览代码

[spirv] Fix bug in turnIntoElementPtr (access chain base).

Ehsan Nasiri 6 年之前
父节点
当前提交
1c82d05698
共有 2 个文件被更改,包括 6 次插入2 次删除
  1. 2 0
      tools/clang/lib/SPIRV/DeclResultIdMapper.cpp
  2. 4 2
      tools/clang/lib/SPIRV/SPIRVEmitter.cpp

+ 2 - 0
tools/clang/lib/SPIRV/DeclResultIdMapper.cpp

@@ -890,6 +890,8 @@ SpirvFunction *DeclResultIdMapper::getOrRegisterFn(const FunctionDecl *fn) {
   if (!isAlias || !isAKindOfStructuredOrByteBuffer(fn->getReturnType()))
   if (!isAlias || !isAKindOfStructuredOrByteBuffer(fn->getReturnType()))
     spirvFunction->setRValue();
     spirvFunction->setRValue();
 
 
+  spirvFunction->setConstainsAliasComponent(isAlias);
+
   astFunctionDecls[fn] = spirvFunction;
   astFunctionDecls[fn] = spirvFunction;
   return spirvFunction;
   return spirvFunction;
 }
 }

+ 4 - 2
tools/clang/lib/SPIRV/SPIRVEmitter.cpp

@@ -6115,17 +6115,19 @@ SpirvInstruction *SPIRVEmitter::turnIntoElementPtr(
   // If this is a rvalue, we need a temporary object to hold it
   // If this is a rvalue, we need a temporary object to hold it
   // so that we can get access chain from it.
   // so that we can get access chain from it.
   const bool needTempVar = base->isRValue();
   const bool needTempVar = base->isRValue();
+  SpirvInstruction *accessChainBase = base;
 
 
   if (needTempVar) {
   if (needTempVar) {
     auto varName = getAstTypeName(baseType);
     auto varName = getAstTypeName(baseType);
     const auto var = createTemporaryVar(baseType, varName, base);
     const auto var = createTemporaryVar(baseType, varName, base);
     var->setLayoutRule(SpirvLayoutRule::Void);
     var->setLayoutRule(SpirvLayoutRule::Void);
     var->setStorageClass(spv::StorageClass::Function);
     var->setStorageClass(spv::StorageClass::Function);
+    accessChainBase = var;
   }
   }
 
 
   base = spvBuilder.createAccessChain(
   base = spvBuilder.createAccessChain(
-      spvContext.getPointerType(elemType, base->getStorageClass()), base,
-      indices);
+      spvContext.getPointerType(elemType, accessChainBase->getStorageClass()),
+      accessChainBase, indices);
 
 
   // Okay, this part seems weird, but it is intended:
   // Okay, this part seems weird, but it is intended:
   // If the base is originally a rvalue, the whole AST involving the base
   // If the base is originally a rvalue, the whole AST involving the base