[PATCH] D149514: Check if First argument in _builtin_assume_aligned_ is of pointer type
Rishabh Bali via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 29 22:40:58 PDT 2023
Ris-Bali updated this revision to Diff 518274.
Ris-Bali added a comment.
Herald added subscribers: carlosgalvezp, kbarton, nemanjai.
Herald added a project: clang-tools-extra.
Removed __builtin_assume_aligned from ignoredbuiltinstest() in clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D149514/new/
https://reviews.llvm.org/D149514
Files:
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
clang/docs/ReleaseNotes.rst
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,11 @@
return a[0];
}
+int test14(int *a, int b) {
+ a = (int *)__builtin_assume_aligned(b, 32); // expected-error {{passing 'int' to parameter of incompatible type 'int *'}}
+ return a[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
@@ -7981,6 +7981,14 @@
DefaultFunctionArrayLvalueConversion(FirstArg);
if (FirstArgResult.isInvalid())
return true;
+ QualType firstArgType = FirstArgResult.get()->getType();
+
+ if (!firstArgType->isAnyPointerType()) {
+ QualType expectedType = Context.getPointerType(firstArgType);
+ return Diag(FirstArg->getBeginLoc(),
+ diag::err_typecheck_convert_incompatible)
+ << firstArgType << expectedType << 1 << 0 << 0;
+ }
TheCall->setArg(0, FirstArgResult.get());
}
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,9 @@
- Fix crash when attempting to perform parenthesized initialization of an
aggregate with a base class with only non-public constructors.
(`#62296 <https://github.com/llvm/llvm-project/issues/62296>`_)
+- 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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-type-vararg.cpp
@@ -52,7 +52,6 @@
int my_vprintf(const char* format, va_list arg ); // OK to declare function taking va_list
void ignoredBuiltinsTest() {
- (void)__builtin_assume_aligned(0, 8);
(void)__builtin_constant_p(0);
(void)__builtin_fpclassify(0, 0, 0, 0, 0, 0.f);
(void)__builtin_isinf_sign(0.f);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149514.518274.patch
Type: text/x-patch
Size: 2843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230430/7c27465b/attachment.bin>
More information about the cfe-commits
mailing list