- 
                Notifications
    You must be signed in to change notification settings 
- Fork 15k
[clang][Driver] Fix triple config loading for clang-cl #111397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -1247,6 +1247,19 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) { | |
| CLOptions = std::make_unique<InputArgList>( | ||
| ParseArgStrings(ArgList.slice(1), /*UseDriverMode=*/true, ContainsError)); | ||
|  | ||
| // We want to determine the triple early so that we load the correct config. | ||
| if (IsCLMode()) { | ||
| // clang-cl targets MSVC-style Win32. | ||
| llvm::Triple T(TargetTriple); | ||
| T.setOS(llvm::Triple::Win32); | ||
| T.setVendor(llvm::Triple::PC); | ||
| T.setEnvironment(llvm::Triple::MSVC); | ||
| T.setObjectFormat(llvm::Triple::COFF); | ||
| if (CLOptions->hasArg(options::OPT__SLASH_arm64EC)) | ||
| T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec); | ||
| TargetTriple = T.str(); | ||
| } | ||
|  | ||
| // Try parsing configuration file. | ||
| if (!ContainsError) | ||
| ContainsError = loadConfigFiles(); | ||
|  | @@ -1286,6 +1299,16 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) { | |
| appendOneArg(Args, Opt, nullptr); | ||
| } | ||
| } | ||
|  | ||
| // The config file may have changed the architecture so apply it. | ||
| if (HasConfigFile && Args.hasArg(options::OPT__SLASH_arm64EC)) { | ||
| llvm::Triple T(TargetTriple); | ||
| if (T.getArch() != llvm::Triple::aarch64 || | ||
| T.getSubArch() != llvm::Triple::AArch64SubArch_arm64ec) { | ||
| T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec); | ||
| TargetTriple = T.str(); | ||
| 
      Comment on lines
    
      +1303
     to 
      +1309
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR description only mentions moving the default triple calculation earlier, but not this part. The config file can presumably change many things, so why does the target triple need special handling? Also what about flags that affect x86 vs. x86_64 (-m32 and -m64), do we need to handle those too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's two triple systems in the driver:  
 To be honest: I have no idea why there is two triples. It would be simpler if  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for explaining. I haven't looked at this code in a long time, and TargetTriple vs. computeTargetTriple() is pretty confusing. It seems  | ||
| } | ||
| } | ||
| } | ||
|  | ||
| // Check for working directory option before accessing any files | ||
|  | @@ -1336,17 +1359,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) { | |
|  | ||
| // FIXME: TargetTriple is used by the target-prefixed calls to as/ld | ||
| // and getToolChain is const. | ||
| if (IsCLMode()) { | ||
| // clang-cl targets MSVC-style Win32. | ||
| llvm::Triple T(TargetTriple); | ||
| T.setOS(llvm::Triple::Win32); | ||
| T.setVendor(llvm::Triple::PC); | ||
| T.setEnvironment(llvm::Triple::MSVC); | ||
| T.setObjectFormat(llvm::Triple::COFF); | ||
| if (Args.hasArg(options::OPT__SLASH_arm64EC)) | ||
| T.setArch(llvm::Triple::aarch64, llvm::Triple::AArch64SubArch_arm64ec); | ||
| TargetTriple = T.str(); | ||
| } else if (IsDXCMode()) { | ||
| if (IsDXCMode()) { | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this mode have the same issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does but it relies on argument parsing so is trickier to move and I didn't have a DXC build on hand. I can have a look again though and see if I can get a build going. I guess this is the same problem as above. It would be trivial to move this to  | ||
| // Build TargetTriple from target_profile option for clang-dxc. | ||
| if (const Arg *A = Args.getLastArg(options::OPT_target_profile)) { | ||
| StringRef TargetProfile = A->getValue(); | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /arm64EC | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought normally the arguments in the config file should get processed before the command-line arguments? What are the rules for this really?