================
@@ -843,10 +844,40 @@ Register SPIRVGlobalRegistry::buildGlobalVariable(
   if (&GVBuilder.getMBB() != &EntryBB)
     GVBuilder.setInsertPt(EntryBB, EntryBB.getFirstTerminator());
 
-  auto MIB = GVBuilder.buildInstr(SPIRV::OpVariable)
+  // Pointers to opaque types stay typed even with the extension on, so emit 
the
+  // untyped variant only when the result is actually an untyped pointer.
+  const SPIRVSubtarget &Subtarget =
+      cast<SPIRVSubtarget>(MIRBuilder.getMF().getSubtarget());
+  const bool UseUntypedPointers =
+      BaseType->getOpcode() == SPIRV::OpTypeUntypedPointerKHR;
+  const unsigned VariableOpcode =
+      UseUntypedPointers ? SPIRV::OpUntypedVariableKHR : SPIRV::OpVariable;
+
+  auto MIB = GVBuilder.buildInstr(VariableOpcode)
                  .addDef(ResVReg)
-                 .addUse(getSPIRVTypeID(BaseType))
-                 .addImm(static_cast<uint32_t>(Storage));
+                 .addUse(getSPIRVTypeID(BaseType));
+
+  // Add storage class (comes before DataType for OpUntypedVariableKHR).
+  MIB.addImm(static_cast<uint32_t>(Storage));
----------------
MrSidims wrote:

Yeah, this is misleading leftover, reworded.

https://github.com/llvm/llvm-project/pull/201233
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to