Skip to content

Commit fcac153

Browse files
committed
Triple::normalize: Set OS for 3-component triple with none as middle
If the middle component of a 3-component triple fails to parse as known Arch/Vendor/OS/Env, it will fallback as Vendor. While for some cases, we may wish to recognize it as OS, such as `arm64-none-elf`. In this patch, we will set OS as `none`, if: 1) Arch is found; 2) Env is found; 3) OS is not found and thus is set as empty; 4) Vendor is not found while is set as "none", we will swap Component[2] and Component[3]. Fixes: #89582.
1 parent ec062f5 commit fcac153

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

llvm/lib/TargetParser/Triple.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,13 @@ std::string Triple::normalize(StringRef Str) {
11491149
}
11501150
}
11511151

1152+
// For 3-component triples, the middle component is used to set Vendor;
1153+
// while if it is "none", we'd prefer to set OS.
1154+
// This is for some baremetal cases, such as "arm-none-elf".
1155+
if (Found[0] && !Found[1] && !Found[2] && Found[3] &&
1156+
Components[1].equals("none") && Components[2].empty())
1157+
std::swap(Components[1], Components[2]);
1158+
11521159
// Replace empty components with "unknown" value.
11531160
for (StringRef &C : Components)
11541161
if (C.empty())

0 commit comments

Comments
 (0)