[Clang] reject bit-fields as instruction operands in Microsoft style inline asm blocks.
authorTom Honermann <tom.honermann@intel.com>
Fri, 7 Oct 2022 21:13:46 +0000 (14:13 -0700)
committerTom Honermann <tom@honermann.net>
Mon, 10 Oct 2022 19:45:02 +0000 (15:45 -0400)
commit0982db188b661d6744b06244fda64d43dd80206e
treef1a6644ad81d2f47eee0ea216330be2fce58bea8
parent2bb86b67447661077e30674eab7b8a27f8234b3f
[Clang] reject bit-fields as instruction operands in Microsoft style inline asm blocks.

MSVC allows bit-fields to be specified as instruction operands in inline asm
blocks. Such references are resolved to the address of the allocation unit that
the named bitfield is a part of. The result is that reads and writes of such
operands will read or mutate nearby bit-fields stored in the same allocation
unit. This is a surprising behavior for which MSVC issues warning C4401,
"'<identifier>': member is bit field". Intel's icc compiler also allows such
bit-field references, but does not issue a diagnostic.

Prior to this change, Clang fails the following assertion when a bit-field is
referenced in such instructions:
  clang/lib/CodeGen/CGValue.h:338: llvm::Value* clang::CodeGen::LValue::getPointer(clang::CodeGen::CodeGenFunction&) const: Assertion `isSimple()' failed.
In non-assert enabled builds, Clang's behavior appears to match the behavior
of the MSVC and icc compilers, though it is unknown if that is by design or
happenstance.

Following this change, attempts to use a bit-field as an instruction operand
in Microsoft style asm blocks is diagnosed as an error due to the risk of
unintentionally reading or writing nearby bit-fields.

Fixes https://github.com/llvm/llvm-project/issues/57791

Reviewed By: erichkeane, aaron.ballman

Differential Revision: https://reviews.llvm.org/D135500
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/lib/Sema/SemaStmtAsm.cpp
clang/test/Parser/ms-inline-asm.c