[ubsan] Check implicit casts in ObjC for-in statements
authorVedant Kumar <vsk@apple.com>
Fri, 13 Dec 2019 20:59:40 +0000 (12:59 -0800)
committerVedant Kumar <vsk@apple.com>
Mon, 13 Jul 2020 22:11:18 +0000 (15:11 -0700)
commit8c4a65b9b2ca6961139beca92de37eea479f00fa
treeba11262a6769c2a2f052da316f66ee110b429e72
parent724afa5a331372ff1684f2bffa6976887490cbaf
[ubsan] Check implicit casts in ObjC for-in statements

Check that the implicit cast from `id` used to construct the element
variable in an ObjC for-in statement is valid.

This check is included as part of a new `objc-cast` sanitizer, outside
of the main 'undefined' group, as (IIUC) the behavior it's checking for
is not technically UB.

The check can be extended to cover other kinds of invalid casts in ObjC.

Partially addresses: rdar://12903059, rdar://9542496

Differential Revision: https://reviews.llvm.org/D71491
14 files changed:
clang/docs/UndefinedBehaviorSanitizer.rst
clang/include/clang/Basic/Sanitizers.def
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Driver/SanitizerArgs.cpp
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/CodeGenObjC/for-in.m
compiler-rt/lib/ubsan/ubsan_checks.inc
compiler-rt/lib/ubsan/ubsan_handlers.cpp
compiler-rt/lib/ubsan/ubsan_handlers.h
compiler-rt/lib/ubsan/ubsan_value.cpp
compiler-rt/lib/ubsan/ubsan_value.h
compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp
compiler-rt/test/ubsan/TestCases/Misc/objc-cast.m [new file with mode: 0644]