[PATCH] D142734: Updated CheckAddressOfOperand

Christopher Bazley via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 27 08:46:16 PST 2023


chrisbazley created this revision.
Herald added a project: All.
chrisbazley requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The semantics of the unary & operator are modified
so that if its  operand has type "type" then its
result has type "pointer to type", with the omission
of any _Optional qualifier of the pointed-to type.

Also added a new helper method,
ASTContext::getNonOptionalType.

Rationale:

A new idiom &* is proposed to allow removal of the
_Optional qualifier from a pointee whilst allowing
static analyzers to check the validity of such
conversions. This is merely the simplest expression
that incorporates a semantic dereference without
actually accessing the pointed-to object.

There is only one way to get the address of an object
(excepting arithmetic), whereas there are many ways
to dereference a pointer. This is why the semantics
of & are modified rather than modifying *, [] and ->.
The operand of  & is already treated specially, being
exempt from implicit conversion of an array type into
a pointer, for example.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142734

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/Sema/SemaExpr.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142734.492780.patch
Type: text/x-patch
Size: 4837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230127/938941fd/attachment-0001.bin>


More information about the cfe-commits mailing list