[PATCH] D97512: [clang] removes check against integral-to-pointer conversion...
Christopher Di Bella via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 25 16:13:39 PST 2021
cjdb created this revision.
cjdb added a reviewer: aaron.ballman.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
... unless it's a literal
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97512
Files:
clang/lib/Sema/SemaChecking.cpp
clang/test/Analysis/free.c
clang/test/Analysis/free.cpp
Index: clang/test/Analysis/free.cpp
===================================================================
--- clang/test/Analysis/free.cpp
+++ clang/test/Analysis/free.cpp
@@ -208,3 +208,15 @@
// Unknown value
std::free(x[offset]); // no-warning
}
+
+struct S {
+ const char* p;
+};
+
+void t18a (S s) {
+ free((void*)(unsigned long long)s.p); // no warning
+}
+
+void t18b (S s) {
+ std::free((void*)(unsigned long long)s.p); // no warning
+}
Index: clang/test/Analysis/free.c
===================================================================
--- clang/test/Analysis/free.c
+++ clang/test/Analysis/free.c
@@ -108,3 +108,11 @@
// expected-warning at -1{{Argument to free() is the address of the function 'iptr', which is not memory allocated by malloc()}}
// expected-warning at -2{{attempt to call free on non-heap object 'iptr'}}
}
+
+struct S {
+ const char* p;
+};
+
+void t18 (struct S s) {
+ free((void*)(unsigned long long)s.p); // no warning
+}
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -10316,11 +10316,18 @@
const CastExpr *Cast) {
SmallString<128> SizeString;
llvm::raw_svector_ostream OS(SizeString);
+
+ const clang::CastKind Kind = Cast->getCastKind();
+ if (Kind == clang::CK_BitCast &&
+ !Cast->getSubExpr()->getType()->isFunctionPointerType())
+ return;
+ if (Kind == clang::CK_IntegralToPointer &&
+ !isa<IntegerLiteral>(
+ Cast->getSubExpr()->IgnoreImplicitAsWritten()->IgnoreParens()))
+ return;
+
switch (Cast->getCastKind()) {
case clang::CK_BitCast:
- if (!Cast->getSubExpr()->getType()->isFunctionPointerType())
- return;
- [[clang::fallthrough]];
case clang::CK_IntegralToPointer:
case clang::CK_FunctionToPointerDecay:
OS << '\'';
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97512.326549.patch
Type: text/x-patch
Size: 1901 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210226/c30a5850/attachment-0001.bin>
More information about the cfe-commits
mailing list