|
| 1 | +commit 0de60d8a276fa4cfff885cc332e41bf690517e51 |
| 2 | +Author: Kim Gräsman < [email protected]> |
| 3 | +Date: Wed Jul 14 12:30:10 2021 +0200 |
| 4 | + |
| 5 | + Initialize all LLVM targets on startup |
| 6 | + |
| 7 | + It used to be the case that the MS inline assembly parser in Clang crashed if an |
| 8 | + X86 target was not registered and initialized. |
| 9 | + |
| 10 | + The error handling there has been improved, so now Clang complains and says it |
| 11 | + needs X86 target support to continue, and raises an error. |
| 12 | + |
| 13 | + That's good news for IWYU, as the majority of code we analyze has no MS inline |
| 14 | + assembly (fingers crossed!). So instead of requiring an X86 target to be |
| 15 | + included, initialize _all_ registered LLVM targets and assume that X86 is |
| 16 | + available in any configuration intended for use with MS inline assembly. |
| 17 | + |
| 18 | + This makes it possible to build a fully non-X86 toolchain including IWYU. |
| 19 | + |
| 20 | +diff --git a/tools/clang/tools/include-what-you-use/iwyu.cc b/tools/clang/tools/include-what-you-use/iwyu.cc |
| 21 | +index bbf532f..df1a439 100644 |
| 22 | +--- a/tools/clang/tools/include-what-you-use/iwyu.cc |
| 23 | ++++ b/tools/clang/tools/include-what-you-use/iwyu.cc |
| 24 | +@@ -4171,7 +4171,6 @@ class IwyuAction : public ASTFrontendAction { |
| 25 | + |
| 26 | + #include "iwyu_driver.h" |
| 27 | + #include "clang/Frontend/FrontendAction.h" |
| 28 | +-#include "llvm/Support/ManagedStatic.h" |
| 29 | + #include "llvm/Support/TargetSelect.h" |
| 30 | + |
| 31 | + using include_what_you_use::OptionsParser; |
| 32 | +@@ -4179,12 +4178,11 @@ using include_what_you_use::IwyuAction; |
| 33 | + using include_what_you_use::CreateCompilerInstance; |
| 34 | + |
| 35 | + int main(int argc, char **argv) { |
| 36 | +- // Must initialize X86 target to be able to parse Microsoft inline |
| 37 | +- // assembly. We do this unconditionally, because it allows an IWYU |
| 38 | +- // built for non-X86 targets to parse MS inline asm without choking. |
| 39 | +- LLVMInitializeX86TargetInfo(); |
| 40 | +- LLVMInitializeX86TargetMC(); |
| 41 | +- LLVMInitializeX86AsmParser(); |
| 42 | ++ // X86 target is required to parse Microsoft inline assembly, so we hope it's |
| 43 | ++ // part of all targets. Clang parser will complain otherwise. |
| 44 | ++ llvm::InitializeAllTargetInfos(); |
| 45 | ++ llvm::InitializeAllTargetMCs(); |
| 46 | ++ llvm::InitializeAllAsmParsers(); |
| 47 | + |
| 48 | + // The command line should look like |
| 49 | + // path/to/iwyu -Xiwyu --verbose=4 [-Xiwyu --other_iwyu_flag]... CLANG_FLAGS... foo.cc |
0 commit comments