Skip to content

Commit

Permalink
[Support] Avoid normalization in sys::getDefaultTargetTriple
Browse files Browse the repository at this point in the history
The return value of sys::getDefaultTargetTriple, which is derived from
-DLLVM_DEFAULT_TRIPLE, is used to construct tool names, default target,
and in the future also to control the search path directly; as such it
should be used textually, without interpretation by LLVM.

Normalization of this value may lead to unexpected results, for example
if we configure LLVM with -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-linux-gnu,
normalization will transform that value to x86_64--linux-gnu. Driver will
use that value to search for tools prefixed with x86_64--linux-gnu- which
may be confusing. This is also inconsistent with the behavior of the
--target flag which is taken as-is without any normalization and overrides
the value of LLVM_DEFAULT_TARGET_TRIPLE.

Users of sys::getDefaultTargetTriple already perform their own
normalization as needed, so this change shouldn't impact existing logic.

Differential Revision: https://reviews.llvm.org/D47153

llvm-svn: 333307
  • Loading branch information
petrhosek committed May 25, 2018
1 parent f6311c6 commit f92ca01
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion clang/lib/Frontend/CompilerInvocation.cpp
Expand Up @@ -2930,10 +2930,11 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args,
Opts.FPMath = Args.getLastArgValue(OPT_mfpmath);
Opts.FeaturesAsWritten = Args.getAllArgValues(OPT_target_feature);
Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version);
Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
Opts.Triple = Args.getLastArgValue(OPT_triple);
// Use the default target triple if unspecified.
if (Opts.Triple.empty())
Opts.Triple = llvm::sys::getDefaultTargetTriple();
Opts.Triple = llvm::Triple::normalize(Opts.Triple);
Opts.OpenCLExtensionsAsWritten = Args.getAllArgValues(OPT_cl_ext_EQ);
Opts.ForceEnableInt128 = Args.hasArg(OPT_fforce_enable_int128);
Opts.NVPTXUseShortPointers = Args.hasFlag(
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Support/Unix/Host.inc
Expand Up @@ -64,5 +64,5 @@ std::string sys::getDefaultTargetTriple() {
TargetTripleString = EnvTriple;
#endif

return Triple::normalize(TargetTripleString);
return TargetTripleString;
}
2 changes: 1 addition & 1 deletion llvm/lib/Support/Windows/Host.inc
Expand Up @@ -30,5 +30,5 @@ std::string sys::getDefaultTargetTriple() {
Triple = EnvTriple;
#endif

return Triple::normalize(Triple);
return Triple;
}

0 comments on commit f92ca01

Please sign in to comment.