This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add '-target' CLI option to override target triple
AbandonedPublic

Authored by jubnzv on May 12 2021, 3:39 AM.

Details

Summary

The added option allows the user to specify the target for which clang-tidy checks will be executed. This is necessary for users who run the tool on project that compiles for a different target platform.

This option also makes it easier to test of clang-tidy and allows to run platform-specific tests on any host system.
This will fix the failed tests when they are run on a Windows host, but the toolchain is targeted a non-Windows platform. The problem is described here: https://reviews.llvm.org/D101259#2739466.

Diff Detail

Event Timeline

jubnzv created this revision.May 12 2021, 3:39 AM
jubnzv requested review of this revision.May 12 2021, 3:39 AM
jubnzv added reviewers: aaron.ballman, njames93.
jubnzv updated this revision to Diff 344758.May 12 2021, 4:08 AM
njames93 added a comment.EditedMay 12 2021, 5:08 AM

This change doesn't seem to accomplish anything. We can already set the target via the compile command.
This can be done in the compilation database directly or by using the extra-arg and extra-arg-before command line arguments.
If you're not using a compilation database, then you can pass the compile command to clang-tidy after an empty -- argument.

For the test case, this is sufficient to fix the issue:

// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-vararg %t -- --extra-arg=--target=x86_64-windows

EDIT:
For the test, the arch isn't needed --target=unknown-windows is more than sufficient.

jubnzv abandoned this revision.May 12 2021, 10:36 AM

Thank you, I didn't know that it is possible to set the target triple using --extra-arg. I created a new revision with this fix: https://reviews.llvm.org/D102337.
For some reasons, the --target=unknown-windows doesn't work for me with the following error: error: unknown target triple 'unknown-unknown-windows-msvc19.11.0', please use -triple or -arch [clang-diagnostic-error].
But --target=x86_64-windows works fine.