[PATCH] D71707: clang-tidy: new bugprone-pointer-cast-widening
Jan Kratochvil via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 19 07:32:46 PST 2019
jankratochvil created this revision.
jankratochvil added reviewers: labath, alexfh, lebedev.ri.
jankratochvil added a project: clang-tools-extra.
Herald added subscribers: cfe-commits, kristof.beyls, mgorny.
Herald added a project: clang.
Check for cast of a pointer to wider (even unsigned) integer. This will sign-extend the pointer which happens on 32-bit hosts for 64-bit integers:
void *p=(void *)0x80000000;
printf( "%p" "\n", p ); // 0x80000000
printf("0x%" PRIxPTR "\n", (uintptr_t)p ); // 0x80000000
printf("0x%" PRIx64 "\n",
reinterpret_cast<uint64_t>(p)); // 0xffffffff80000000
printf("0x%" PRIx64 "\n", (uint64_t) p ); // 0xffffffff80000000
printf("0x%" PRIx64 "\n", (uint64_t)(uintptr_t)p ); // 0x80000000
It has caught a bug on ARM32: D71498 <https://reviews.llvm.org/D71498> (and D71514 <https://reviews.llvm.org/D71514>)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71707
Files:
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/clang-tidy/bugprone/PointerCastWideningCheck.cpp
clang-tools-extra/clang-tidy/bugprone/PointerCastWideningCheck.h
clang-tools-extra/test/clang-tidy/checkers/bugprone-pointer-cast-widening.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71707.234721.patch
Type: text/x-patch
Size: 6641 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191219/c1070338/attachment-0001.bin>
More information about the cfe-commits
mailing list