Skip to content

Commit

Permalink
stage1: Fix other OS target
Browse files Browse the repository at this point in the history
PR ziglang#7827 added some new `std.Target.Os.Tag` before `other`.
The corresponding enum in stage1.h was not updated, which caused a
mismatch in the underlying integer values. While attempting to target
`other`, I encountered crashes.

This PR updates the stage1.h enum to include the added OS tags.
The new tags also had to be added to various switch cases to fix
compiler warnings, but have not been tested in any way.
  • Loading branch information
jayschwa committed May 5, 2021
1 parent 785a6c1 commit 5fa5f2e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/stage1/stage1.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ enum TargetSubsystem {


// ABI warning
// Synchronize with target.cpp::os_list
// Synchronize with std.Target.Os.Tag and target.cpp::os_list
enum Os {
OsFreestanding,
OsAnanas,
Expand Down Expand Up @@ -94,6 +94,9 @@ enum Os {
OsWASI,
OsEmscripten,
OsUefi,
OsOpenCL,
OsGLSL450,
OsVulkan,
OsOther,
};

Expand Down
16 changes: 16 additions & 0 deletions src/stage1/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ static const Os os_list[] = {
OsWASI,
OsEmscripten,
OsUefi,
OsOpenCL,
OsGLSL450,
OsVulkan,
OsOther,
};

Expand Down Expand Up @@ -213,6 +216,9 @@ Os target_os_enum(size_t index) {
ZigLLVM_OSType get_llvm_os_type(Os os_type) {
switch (os_type) {
case OsFreestanding:
case OsOpenCL:
case OsGLSL450:
case OsVulkan:
case OsOther:
return ZigLLVM_UnknownOS;
case OsAnanas:
Expand Down Expand Up @@ -330,6 +336,9 @@ const char *target_os_name(Os os_type) {
case OsHurd:
case OsWASI:
case OsEmscripten:
case OsOpenCL:
case OsGLSL450:
case OsVulkan:
return ZigLLVMGetOSTypeName(get_llvm_os_type(os_type));
}
zig_unreachable();
Expand Down Expand Up @@ -733,6 +742,9 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
case OsAMDPAL:
case OsHermitCore:
case OsHurd:
case OsOpenCL:
case OsGLSL450:
case OsVulkan:
zig_panic("TODO c type size in bits for this target");
}
zig_unreachable();
Expand Down Expand Up @@ -999,6 +1011,10 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
case OsWASI:
case OsEmscripten:
return ZigLLVM_Musl;
case OsOpenCL:
case OsGLSL450:
case OsVulkan:
return ZigLLVM_UnknownEnvironment;
}
zig_unreachable();
}
Expand Down

0 comments on commit 5fa5f2e

Please sign in to comment.