[all-commits] [llvm/llvm-project] 39969c: [Sema][SVE] Reject sizeof and alignof for sizeless...

rsandifo-arm via All-commits all-commits at lists.llvm.org
Thu Mar 12 10:11:51 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 39969c7d3a6da8a60ac3ac7d10f471dea87cfca5
      https://github.com/llvm/llvm-project/commit/39969c7d3a6da8a60ac3ac7d10f471dea87cfca5
  Author: Richard Sandiford <richard.sandiford at arm.com>
  Date:   2020-03-12 (Thu, 12 Mar 2020)

  Changed paths:
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/include/clang/Sema/Sema.h
    M clang/lib/Sema/SemaExpr.cpp
    M clang/lib/Sema/SemaType.cpp
    M clang/test/Sema/aarch64-sve-types.c
    M clang/test/Sema/sizeless-1.c
    M clang/test/SemaCXX/sizeless-1.cpp

  Log Message:
  -----------
  [Sema][SVE] Reject sizeof and alignof for sizeless types

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.
However, the second function is invalid ACLE code and generates a
zero-length memcpy.  The point of this patch is to reject the use
of sizeof in the second case instead.

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.

Implementation-wise, the patch adds a new CompleteTypeKind enum
that controls whether RequireCompleteType & friends accept sizeless
built-in types.  For now the default is to maintain the status quo
and accept sizeless types.  However, the end of the series will flip
the default and remove the Default enum value.

The patch also adds new ...CompleteSized... wrappers that callers can
use if they explicitly want to reject sizeless types.  The callers then
use diagnostics that have an extra 0/1 parameter to indicats whether
the type is sizeless or not.

The idea is to have three cases:

1. calls that explicitly reject sizeless types, with a tweaked diagnostic
   for the sizeless case

2. calls that explicitly allow sizeless types

3. normal/old-style calls that don't make an explicit choice either way

Once the default is flipped, the 3. calls will conservatively reject
sizeless types, using the same diagnostic as for other incomplete types.

Differential Revision: https://reviews.llvm.org/D75572




More information about the All-commits mailing list