I will file a bug report in a little bit (once I get a minimal test case) but I wanted to ask if anyone understands the problem I’m seeing.
Trying to include ntddk.h and compiling with clang-cl, I get the following message:
In file included from kbfiltr.c:19:
In file included from ./kbfiltr.h:28:
C:\WINDDK\3790.1830\inc\ddk\wxp\ntddk.h(7149,29) : error: unexpected type name
‘KPCR’: expected expression
__asm { movzx eax, _PCR KPCR.Number }
^
Assertion failed: End.getPointer() <= EndPtr && “frontend claimed part of a token?”, file …........\lib\Target\X86\AsmParser\X86AsmParser.cpp, line 1481
clang-cl.exe: error: clang frontend command failed with exit code 3 (use -v to s
ee invocation)
The assertion failure obviously results in a crash.
So my initial guess was some kind of Lexer issue, maybe because of no semicolon, or… who knows. But then, I rewrote that code to read:
int x = FIELD_OFFSET(KPCR, Number);
__asm { movzx eax, fs: }
Which compiles to the same code, and that actually did work with clang-cl. Can anyone tell me why one works and the other doesn’t? (My guess: MS not following standard Intel notation spec)
Parsing this involves Clang and llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp. It’s really tricky because C++ expressions can occur in lots of places, making it harder to parse the assembly.
It is, but you probably want to look for any RecordDecl to see if it’s possible to do a field access. You can use Decl->getAs() to look through typedefs automatically.
I don’t understand what you mean by that. By Decl, I assumed you meant the TypedefNameDecl created for the object “KPCR”, but as far as I can tell, only types have a getAs field.
For actually solving the problem, it seems that “fs:[0] 12” is equivalent to “fs:[12]”. I see that there are several calls to AsmRewrites->push_back… is there a way to amend the most recent thing you pushed onto that object?