2
0
Эх сурвалжийг харах

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

Ehsan Nasiri 6 жил өмнө
parent
commit
1c82d05698

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

@@ -890,6 +890,8 @@ SpirvFunction *DeclResultIdMapper::getOrRegisterFn(const FunctionDecl *fn) {
   if (!isAlias || !isAKindOfStructuredOrByteBuffer(fn->getReturnType()))
     spirvFunction->setRValue();
 
+  spirvFunction->setConstainsAliasComponent(isAlias);
+
   astFunctionDecls[fn] = 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
   // so that we can get access chain from it.
   const bool needTempVar = base->isRValue();
+  SpirvInstruction *accessChainBase = base;
 
   if (needTempVar) {
     auto varName = getAstTypeName(baseType);
     const auto var = createTemporaryVar(baseType, varName, base);
     var->setLayoutRule(SpirvLayoutRule::Void);
     var->setStorageClass(spv::StorageClass::Function);
+    accessChainBase = var;
   }
 
   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:
   // If the base is originally a rvalue, the whole AST involving the base