[all-commits] [llvm/llvm-project] 0982db: [Clang] reject bit-fields as instruction operands ...

Tom Honermann via All-commits all-commits at lists.llvm.org
Mon Oct 10 12:45:35 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 0982db188b661d6744b06244fda64d43dd80206e
      https://github.com/llvm/llvm-project/commit/0982db188b661d6744b06244fda64d43dd80206e
  Author: Tom Honermann <tom.honermann at intel.com>
  Date:   2022-10-10 (Mon, 10 Oct 2022)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Basic/DiagnosticCommonKinds.td
    M clang/lib/Sema/SemaStmtAsm.cpp
    M clang/test/Parser/ms-inline-asm.c

  Log Message:
  -----------
  [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




More information about the All-commits mailing list