[PATCH] D149514: Check if First argument in _builtin_assume_aligned_ is of pointer type
Aaron Ballman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 5 10:13:03 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0b3d73787704: Check if First argument in _builtin_assume_aligned_ is of pointer type (authored by Ris-Bali, committed by aaron.ballman).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149514/new/
https://reviews.llvm.org/D149514
Files:
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/builtin-assume-aligned.c
Index: clang/test/Sema/builtin-assume-aligned.c
===================================================================
--- clang/test/Sema/builtin-assume-aligned.c
+++ clang/test/Sema/builtin-assume-aligned.c
@@ -71,6 +71,25 @@
return a[0];
}
+int test14(int *a, int b) {
+ a = (int *)__builtin_assume_aligned(b, 32); // expected-error {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *}}
+}
+
+int test15(int *b) {
+ int arr[3] = {1, 2, 3};
+ b = (int *)__builtin_assume_aligned(arr, 32);
+ return b[0];
+}
+
+int val(int x) {
+ return x;
+}
+
+int test16(int *b) {
+ b = (int *)__builtin_assume_aligned(val, 32);
+ return b[0];
+}
+
void test_void_assume_aligned(void) __attribute__((assume_aligned(32))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
int test_int_assume_aligned(void) __attribute__((assume_aligned(16))); // expected-warning {{'assume_aligned' attribute only applies to return values that are pointers}}
void *test_ptr_assume_aligned(void) __attribute__((assume_aligned(64))); // no-warning
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -8100,8 +8100,9 @@
{
ExprResult FirstArgResult =
DefaultFunctionArrayLvalueConversion(FirstArg);
- if (FirstArgResult.isInvalid())
+ if (checkBuiltinArgument(*this, TheCall, 0))
return true;
+ /// In-place updation of FirstArg by checkBuiltinArgument is ignored.
TheCall->setArg(0, FirstArgResult.get());
}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -2829,8 +2829,6 @@
case Builtin::BI__builtin_assume_aligned: {
const Expr *Ptr = E->getArg(0);
Value *PtrValue = EmitScalarExpr(Ptr);
- if (PtrValue->getType() != VoidPtrTy)
- PtrValue = EmitCastToVoidPtr(PtrValue);
Value *OffsetValue =
(E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : nullptr;
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -368,6 +368,9 @@
(`#62207 <https://github.com/llvm/llvm-project/issues/62207>`_)
- Fix lambdas and other anonymous function names not respecting ``-fdebug-prefix-map``
(`#62192 <https://github.com/llvm/llvm-project/issues/62192>`_)
+- Fix crash when attempting to pass a non-pointer type as first argument of
+ ``__builtin_assume_aligned``.
+ (`#62305 <https://github.com/llvm/llvm-project/issues/62305>`_)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149514.519918.patch
Type: text/x-patch
Size: 2823 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230505/81a8b02b/attachment.bin>
More information about the cfe-commits
mailing list