[PATCH] D75572: [Sema][SVE] Reject sizeof and alignof for sizeless types

Richard Sandiford via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 3 15:00:37 PST 2020


rsandifo-arm created this revision.
rsandifo-arm added reviewers: sdesmalen, efriedma, rovka, rjmccall.
Herald added subscribers: cfe-commits, psnobl, rkruppe, tschuett.
Herald added a reviewer: rengolin.
Herald added a project: clang.
rsandifo-arm added parent revisions: D75570: [AST][SVE] Add new Type queries for sizeless types, D75571: [Sema][SVE] Add tests for valid and invalid type usage.

clang current accepts:

  void foo1(__SVInt8_t *x, __SVInt8_t *y) { *x = *y; }
  void foo2(__SVInt8_t *x, __SVInt8_t *y) {
    memcpy(y, x, sizeof(__SVInt8_t));
  }

The first function is valid ACLE code and generates correct LLVM IR.
The second function is invalid ACLE code and generates a zero-length
memcpy.

The patch means that we diagnose the problem in the second case,
rather than silently generating incorrect code.

There's no similar wrong-code bug for alignof.  However, the SVE ACLE
conservatively treats alignof in the same way as sizeof, just as the
C++ standard does for incomplete types.  The idea is that layout of
sizeless types is an implementation property and isn't defined at
the language level.

We could relax the alignof rules in future if they turn out to be
too restrictive.  It would be harder to go the other way though,
and forbid alignof after previously treating it as valid.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75572

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/aarch64-sve-types.c
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75572.248042.patch
Type: text/x-patch
Size: 11428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200303/3ba49318/attachment-0001.bin>


More information about the cfe-commits mailing list