Skip to content

Commit 32999cb

Browse files
svenvhvmaksimo
authored andcommitted
Conditionalize translation of llvm.global_ctors/dtors
Do not translate the llvm.global_ctors and llvm.global_dtors variables to SPIR-V when the function pointers extension is not enabled, because we currently cannot represent the variable without the function pointers extension.
1 parent a329579 commit 32999cb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,14 @@ bool LLVMToSPIRV::transGlobalVariables() {
27022702
for (auto I = M->global_begin(), E = M->global_end(); I != E; ++I) {
27032703
if ((*I).getName() == "llvm.global.annotations")
27042704
transGlobalAnnotation(&(*I));
2705-
else if (MDNode *IO = ((*I).getMetadata("io_pipe_id")))
2705+
else if ((I->getName() == "llvm.global_ctors" ||
2706+
I->getName() == "llvm.global_dtors") &&
2707+
!BM->isAllowedToUseExtension(
2708+
ExtensionID::SPV_INTEL_function_pointers)) {
2709+
// Function pointers are required to represent structor lists; do not
2710+
// translate the variable if function pointers are not available.
2711+
continue;
2712+
} else if (MDNode *IO = ((*I).getMetadata("io_pipe_id")))
27062713
transGlobalIOPipeStorage(&(*I), IO);
27072714
else if (!transValue(&(*I), nullptr))
27082715
return false;

0 commit comments

Comments
 (0)