https://bugs.kde.org/show_bug.cgi?id=528773
Bug ID: 528773
Summary: clazy-standalone: MS-style inline assembly fails with
"no targets are registered" (LLVM targets never
initialized)
Classification: Developer tools
Product: clazy
Version First unspecified
Reported In:
Platform: Other
OS: Microsoft Windows
Status: REPORTED
Severity: normal
Priority: NOR
Component: general
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
Target Milestone: ---
Created attachment 198413
--> https://bugs.kde.org/attachment.cgi?id=198413&action=edit
Minor Patch to enable inline assembly in standalone via LLVM
`clazy-standalone` never registers the LLVM targets. Any translation unit
containing
MS-style inline assembly fails to parse:
```
error: MS-style inline assembly is not available: Unable to find target for
this triple (no targets are registered)
```
clazy-standalone then exits with code 1, and the translation unit is only
partially analysed.
On Windows this affects every 32-bit (x86) translation unit that includes
`<windows.h>`,
because the Windows SDK header `winnt.h` contains `__asm` blocks. With SDK
10.0.26100.0 they
are at `winnt.h(1064)`, `(1080)` and `(1096)`. In our real-world Qt project, 2
of 49 files
were affected.
clang-tidy does not have this problem. `clangTidyMain()` in
`clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp` calls
`llvm::InitializeAllTargetInfos()`, `InitializeAllTargetMCs()` and
`InitializeAllAsmParsers()`.
clazy-standalone does not call them. The target libraries are already linked
through
`llvm-config --libs`, so only these three calls are missing.
## Minimal testcase
`ms-asm.cpp`:
```cpp
int f()
{
int r;
__asm mov eax, 1
__asm mov r, eax
return r;
}
```
```
clazy-standalone ms-asm.cpp -- --target=i686-pc-windows-msvc -fms-extensions
```
This also works on Linux; no Windows SDK is needed. Alternatively, in clang-cl
mode:
`-- --driver-mode=cl --target=i686-pc-windows-msvc`.
- **Actual:** `error: MS-style inline assembly is not available: Unable to find
target for this triple (no targets are registered)`, exit code 1
- **Expected:** no error, exit code 0, as with clang-tidy
## Environment
clazy v1.17.1, LLVM/Clang 19.1.5 (official Windows release archive), Windows
11, MSVC 2022 17.14,
clazy-standalone built against that LLVM.
## Proposed fix
See the attached `0001-clazy-standalone-register-llvm-targets.patch`. It adds
the include and
the three calls at the start of `main()`. We tested it with the testcase above,
with a 32-bit
`<windows.h>` translation unit, and with the clazy test examples in a
real-world project.
The other findings were unchanged, and the previously affected files are now
fully analysed.
--
You are receiving this mail because:
You are watching all bug changes.