[PATCH] D122748: [Sema] Don't check bounds for function pointer
Aleksandr Platonov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 30 10:21:22 PDT 2022
ArcsinX created this revision.
ArcsinX added reviewers: aaron.ballman, erichkeane, abhinavgaba, chrish_ericsson_atx.
Herald added a project: All.
ArcsinX requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Currently, clang crashes with i386 target on the following code:
void f() {
f + 0xdead000000000000UL;
}
This problem is similar to the problem fixed in D104424 <https://reviews.llvm.org/D104424>, but that fix can't handle function pointer case, because `getTypeSizeInCharsIfKnown()` says that size is known and equal to 0 for function type.
This patch prevents bounds checking for function pointer, thus fixes the crash.
Fixes https://github.com/llvm/llvm-project/issues/50463
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D122748
Files:
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/unbounded-array-bounds.c
Index: clang/test/Sema/unbounded-array-bounds.c
===================================================================
--- clang/test/Sema/unbounded-array-bounds.c
+++ clang/test/Sema/unbounded-array-bounds.c
@@ -80,3 +80,7 @@
(void *)0 + 0xdead000000000000UL;
// no array-bounds warning, and no crash
}
+
+void func() {
+ func + 0xdead000000000000UL; // no crash
+}
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15447,7 +15447,7 @@
const Type *BaseType =
ArrayTy == nullptr ? nullptr : ArrayTy->getElementType().getTypePtr();
bool IsUnboundedArray = (BaseType == nullptr);
- if (EffectiveType->isDependentType() ||
+ if (EffectiveType->isDependentType() || EffectiveType->isFunctionType() ||
(!IsUnboundedArray && BaseType->isDependentType()))
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122748.419209.patch
Type: text/x-patch
Size: 924 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220330/ca6d2173/attachment.bin>
More information about the cfe-commits
mailing list