Don't use std::initializer_list for array views.
The team debated whether this was legal or not at the time.
It seems that at least one of Android's compilers generates code that stomps the list data after the `std::initializer_list` is declared and before it is used.
Switch to using regular C arrays with constexpr / std::array.
Fixes: b/149235682
Change-Id: Ief95dc4c6b4aee0c181bbe34aff19aa95f5fac8c
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/41051
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index 4246880..0fe5b09 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -423,18 +423,20 @@
case spv::OpExtInstImport:
{
- auto const extensionsByName = std::initializer_list<std::pair<const char *, Extension::Name>>{
+ static constexpr std::pair<const char *, Extension::Name> extensionsByName[] = {
{ "GLSL.std.450", Extension::GLSLstd450 },
{ "OpenCL.DebugInfo.100", Extension::OpenCLDebugInfo100 },
};
+ static constexpr auto extensionCount = sizeof(extensionsByName) / sizeof(extensionsByName[0]);
+
auto id = Extension::ID(insn.word(1));
auto name = insn.string(2);
auto ext = Extension{ Extension::Unknown };
- for(auto it : extensionsByName)
+ for(size_t i = 0; i < extensionCount; i++)
{
- if(0 == strcmp(name, it.first))
+ if(0 == strcmp(name, extensionsByName[i].first))
{
- ext = Extension{ it.second };
+ ext = Extension{ extensionsByName[i].second };
break;
}
}
diff --git a/src/Reactor/SubzeroReactor.cpp b/src/Reactor/SubzeroReactor.cpp
index 4624064..7efeb5b 100644
--- a/src/Reactor/SubzeroReactor.cpp
+++ b/src/Reactor/SubzeroReactor.cpp
@@ -45,6 +45,7 @@
# include <Windows.h>
#endif
+#include <array>
#include <iostream>
#include <limits>
#include <mutex>
@@ -159,7 +160,7 @@
ret = function->makeVariable(retTy);
}
- std::initializer_list<Ice::Variable *> iceArgs = { std::forward<RArgs>(args)... };
+ std::array<Ice::Variable *, sizeof...(args)> iceArgs {{ std::forward<RArgs>(args)... }};
auto call = Ice::InstCall::create(function, iceArgs.size(), ret, getConstantPointer(function->getContext(), reinterpret_cast<void const *>(fptr)), false);
for(auto arg : iceArgs)