[all-commits] [llvm/llvm-project] 010005: [Sema][SVE] Reject subscripts on pointers to sizel...
rsandifo-arm via All-commits
all-commits at lists.llvm.org
Tue Mar 17 04:27:46 PDT 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: 010005f0774e13475c321f78b89bdc79eb78d5a5
https://github.com/llvm/llvm-project/commit/010005f0774e13475c321f78b89bdc79eb78d5a5
Author: Richard Sandiford <richard.sandiford at arm.com>
Date: 2020-03-17 (Tue, 17 Mar 2020)
Changed paths:
M clang/include/clang/Basic/DiagnosticSemaKinds.td
M clang/lib/Sema/SemaExpr.cpp
M clang/test/Sema/sizeless-1.c
M clang/test/SemaCXX/sizeless-1.cpp
Log Message:
-----------
[Sema][SVE] Reject subscripts on pointers to sizeless types
clang currently accepts:
__SVInt8_t &foo1(__SVInt8_t *x) { return *x; }
__SVInt8_t &foo2(__SVInt8_t *x) { return x[1]; }
The first function is valid ACLE code and generates correct LLVM IR
(and assembly code). But the second function is invalid for the
same reason that arrays of sizeless types are. Trying to code-generate
the function leads to:
llvm/include/llvm/Support/TypeSize.h:126: uint64_t llvm::TypeSize::getFixedSize() const: Assertion `!IsScalable && "Request for a fixed size on a s
calable object"' failed.
Another problem is that:
template<typename T>
constexpr __SIZE_TYPE__ f(T *x) { return &x[1] - x; }
typedef int arr1[f((int *)0) - 1];
typedef int arr2[f((__SVInt8_t *)0) - 1];
produces:
a.cpp:2:48: warning: subtraction of pointers to type '__SVInt8_t' of zero size has undefined behavior [-Wpointer-arith]
constexpr __SIZE_TYPE__ f(T *x) { return &x[1] - x; }
~~~~~ ^ ~
a.cpp:4:18: note: in instantiation of function template specialization 'f<__SVInt8_t>' requested here
typedef int arr2[f((__SVInt8_t *)0) - 1];
This patch reports an appropriate diagnostic instead.
Differential Revision: https://reviews.llvm.org/D76084
More information about the All-commits
mailing list